-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Note if mismatched types have a similar name #101664
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @fee1-dead (or someone else) soon. Please see the contribution instructions for more information. |
let found_name = values.found.sort_string(self.tcx); | ||
let expected_name = values.expected.sort_string(self.tcx); | ||
|
||
diag.note(format!("{found_name} and {expected_name} have similar names, but are actually distinct types")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this interact with the existing "help: maybe two different crates are being used?" message? IMO we should probably only show one or the other; it would be nice to add a test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shows both; see src/test/ui/type/type-mismatch-same-crate-name
. Its output got updated with this PR.
@rustbot author |
@rustbot ready |
src/test/ui/fully-qualified-type/fully-qualified-type-name2.stderr
Outdated
Show resolved
Hide resolved
☔ The latest upstream changes (presumably #101938) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
@rustbot ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few nits. Should be good to go after reviews are addressed. Sorry for the late review!
let primitive_sym = |kind: &_| match kind { | ||
ty::Bool => Some(sym::bool), | ||
ty::Char => Some(sym::char), | ||
ty::Float(f) => match f { | ||
ty::FloatTy::F32 => Some(sym::f32), | ||
ty::FloatTy::F64 => Some(sym::f64), | ||
}, | ||
ty::Int(f) => match f { | ||
ty::IntTy::Isize => Some(sym::isize), | ||
ty::IntTy::I8 => Some(sym::i8), | ||
ty::IntTy::I16 => Some(sym::i16), | ||
ty::IntTy::I32 => Some(sym::i32), | ||
ty::IntTy::I64 => Some(sym::i64), | ||
ty::IntTy::I128 => Some(sym::i128), | ||
}, | ||
ty::Uint(f) => match f { | ||
ty::UintTy::Usize => Some(sym::usize), | ||
ty::UintTy::U8 => Some(sym::u8), | ||
ty::UintTy::U16 => Some(sym::u16), | ||
ty::UintTy::U32 => Some(sym::u32), | ||
ty::UintTy::U64 => Some(sym::u64), | ||
ty::UintTy::U128 => Some(sym::u128), | ||
}, | ||
_ => None, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an associated function for TyKind
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it can be an associated function on TyKind (or Symbol for that matter) because that leads to cyclic dependencies. But I'm happy to make it a free function/trait somewhere, or an associated function on rustc_middle::ty::Ty
match (fk, ek) { | ||
( | ||
ty::Adt(adt, _), | ||
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use is_primitive
instead.
None | ||
} | ||
( | ||
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same above. I think you can also use an if-let
guard to extract the primitive sym in this match statement directly.
enum Option<T>{ | ||
Some(T), | ||
None, | ||
} | ||
|
||
pub fn foo() -> Option<u8>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum Option<T>{ | |
Some(T), | |
None, | |
} | |
pub fn foo() -> Option<u8>{ | |
enum Option<T> { | |
Some(T), | |
None, | |
} | |
pub fn foo() -> Option<u8> { |
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(){} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(){} | |
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() {} |
Thank you for the review. I have:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks
@bors r+ |
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.
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#100734 (Split out async_fn_in_trait into a separate feature) - rust-lang#101664 (Note if mismatched types have a similar name) - rust-lang#101815 (Migrated the rustc_passes annotation without effect diagnostic infrastructure) - rust-lang#102042 (Distribute rust-docs-json via rustup.) - rust-lang#102066 (rustdoc: remove unnecessary `max-width` on headers) - rust-lang#102095 (Deduplicate two functions that would soon have been three) - rust-lang#102104 (Set 'exec-env:RUST_BACKTRACE=0' in const-eval-select tests) - rust-lang#102112 (Allow full relro on powerpc64-unknown-linux-gnu) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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.