forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#101664 - mejrs:similarity, r=fee1-dead
Note if mismatched types have a similar name If users get a type error between similarly named types, it will point out that these are actually different types, and where they were defined.
- Loading branch information
Showing
11 changed files
with
274 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub mod blah { | ||
pub mod baz { | ||
pub struct Foo; | ||
} | ||
} | ||
|
||
pub mod meh { | ||
pub struct Foo; | ||
} | ||
|
||
pub type Foo = blah::baz::Foo; | ||
|
||
fn foo() -> Foo { | ||
meh::Foo | ||
//~^ ERROR mismatched types [E0308] | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/show_module.rs:14:5 | ||
| | ||
LL | fn foo() -> Foo { | ||
| --- expected `baz::Foo` because of return type | ||
LL | meh::Foo | ||
| ^^^^^^^^ expected struct `baz::Foo`, found struct `meh::Foo` | ||
| | ||
= note: struct `meh::Foo` and struct `baz::Foo` have similar names, but are actually distinct types | ||
note: struct `meh::Foo` is defined in module `crate::meh` of the current crate | ||
--> $DIR/show_module.rs:8:5 | ||
| | ||
LL | pub struct Foo; | ||
| ^^^^^^^^^^^^^^ | ||
note: struct `baz::Foo` is defined in module `crate::blah::baz` of the current crate | ||
--> $DIR/show_module.rs:3:9 | ||
| | ||
LL | pub struct Foo; | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
enum Option<T> { | ||
Some(T), | ||
None, | ||
} | ||
|
||
pub fn foo() -> Option<u8> { | ||
Some(42_u8) | ||
//~^ ERROR mismatched types [E0308] | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/similar_paths.rs:7:5 | ||
| | ||
LL | pub fn foo() -> Option<u8> { | ||
| ---------- expected `Option<u8>` because of return type | ||
LL | Some(42_u8) | ||
| ^^^^^^^^^^^ expected enum `Option`, found enum `std::option::Option` | ||
| | ||
= note: enum `std::option::Option` and enum `Option` have similar names, but are actually distinct types | ||
note: enum `std::option::Option` is defined in crate `core` | ||
--> $SRC_DIR/core/src/option.rs:LL:COL | ||
| | ||
LL | pub enum Option<T> { | ||
| ^^^^^^^^^^^^^^^^^^ | ||
note: enum `Option` is defined in the current crate | ||
--> $DIR/similar_paths.rs:1:1 | ||
| | ||
LL | enum Option<T> { | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![allow(non_camel_case_types)] | ||
|
||
struct bool; | ||
|
||
fn foo(_: bool) {} | ||
|
||
fn main() { | ||
foo(true); | ||
//~^ ERROR mismatched types [E0308] | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/mismatched_types/similar_paths_primitive.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/similar_paths_primitive.rs:8:9 | ||
| | ||
LL | foo(true); | ||
| --- ^^^^ expected struct `bool`, found `bool` | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: bool and struct `bool` have similar names, but are actually distinct types | ||
= note: bool is a primitive defined by the language | ||
note: struct `bool` is defined in the current crate | ||
--> $DIR/similar_paths_primitive.rs:3:1 | ||
| | ||
LL | struct bool; | ||
| ^^^^^^^^^^^ | ||
note: function defined here | ||
--> $DIR/similar_paths_primitive.rs:5:4 | ||
| | ||
LL | fn foo(_: bool) {} | ||
| ^^^ ------- | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters