-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove importing suggestions when there is a shadowed typo candidate #120966
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use std::io::Read; | ||
|
||
fn f<T: Read, U, Read>() {} //~ ERROR expected trait, found type parameter `Read` | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0404]: expected trait, found type parameter `Read` | ||
--> $DIR/issue-120559.rs:3:9 | ||
| | ||
LL | use std::io::Read; | ||
| ---- you might have meant to refer to this trait | ||
LL | | ||
LL | fn f<T: Read, U, Read>() {} | ||
| ^^^^ ---- found this type parameter | ||
| | | ||
| not a trait | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0404`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,6 @@ LL | impl<T: Clone, Add> Add for Foo<T> { | |
| --- ^^^ not a trait | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An aside: I'm realizing now, looking at the code in question (and confirmed by the first line of the description of issue #35987): impl<T: Clone, Add> Add for Foo<T> { ... } that the most likely explanation for what has happened is that someone was trying to put both the In an ideal world, with full LLM linguistic modelling of the user's intent, we might hope to provide a hint that the comma, while syntatically correct, could instead have been a (I know that Vadim already pointed out that the compiler "can't" complain about the comma in all cases, since it is syntactically correct there. I'm just saying to potentially give to the developer.) |
||
| | | ||
| found this type parameter | ||
| | ||
help: consider importing this trait instead | ||
| | ||
LL + use std::ops::Add; | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|
||
|
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.
We could suggest explicitly qualifying
Read
here if feasible:T: std::io::Read
or evenT: self::Read
to pick up the otherwise unused import item. cc #109950 (comment)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.
seems it's hard to give a detailed suggestion to fix the code, for this case all these 3 scenarios will compile successfully:
or
or