Specify when type parameter shadows primitive type
When a type parameter shadows a primitive type, the error message
was non obvious. For example, given the file `file.rs`:
```rust
trait Parser<T> {
fn parse(text: &str) -> Option<T>;
}
impl<bool> Parser<bool> for bool {
fn parse(text: &str) -> Option<bool> {
Some(true)
}
}
fn main() {
println!("{}", bool::parse("ok").unwrap_or(false));
}
```
The output was:
```bash
% rustc file.rs
error[E0308]: mismatched types
--> file.rs:7:14
|
7 | Some(true)
| ^^^^ expected type parameter, found bool
|
= note: expected type `bool`
= note: found type `bool`
error: aborting due to previous error
```
We now show extra information about the type:
```bash
% rustc file.rs
error[E0308]: mismatched types
--> file.rs:7:14
|
7 | Some(true)
| ^^^^ expected type parameter, found bool
|
= note: expected type `bool` (type parameter)
= note: found type `bool` (bool)
error: aborting due to previous error
```
Fixes #35030
This commit is contained in:
parent
c87ba3f122
commit
68e8624d05
5 changed files with 63 additions and 5 deletions
25
src/test/ui/mismatched_types/issue-35030.rs
Normal file
25
src/test/ui/mismatched_types/issue-35030.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// rustc-env:RUST_NEW_ERROR_FORMAT
|
||||
|
||||
trait Parser<T> {
|
||||
fn parse(text: &str) -> Option<T>;
|
||||
}
|
||||
|
||||
impl<bool> Parser<bool> for bool {
|
||||
fn parse(text: &str) -> Option<bool> {
|
||||
Some(true)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", bool::parse("ok").unwrap_or(false));
|
||||
}
|
||||
11
src/test/ui/mismatched_types/issue-35030.stderr
Normal file
11
src/test/ui/mismatched_types/issue-35030.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-35030.rs:19:14
|
||||
|
|
||||
19 | Some(true)
|
||||
| ^^^^ expected type parameter, found bool
|
||||
|
|
||||
= note: expected type `bool` (type parameter)
|
||||
= note: found type `bool` (bool)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue