-
Notifications
You must be signed in to change notification settings - Fork 13k
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 #87775 - Kobzol:single-associated-item-hint, r=oli-obk
Add hint for unresolved associated trait items if the trait has a single item This PR introduces a special-cased hint for unresolved trait items paths. It is shown if: - the path was not resolved to any existing trait item - and no existing trait item's name was reasonably close with regard to edit distance - and the trait only has a single item in the corresponding namespace I didn't know where I should put tests, therefore so far I just managed to bless two existing tests. I would be glad for hints where should tests for a hint like this be created, how should they be named (with reference to the original issue?) and what tests should I create (is it enough to test it just for types? or create separate tests also for functions and constants?). It could also be turned into a machine applicable suggestion I suppose. This is my first `rustc` PR, so please go easy on me :) Fixes: #87638
- Loading branch information
Showing
7 changed files
with
172 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// run-rustfix | ||
|
||
trait Trait { | ||
const FOO: usize; | ||
|
||
type Target; | ||
} | ||
|
||
struct S; | ||
|
||
impl Trait for S { | ||
const FOO: usize = 0; | ||
type Target = (); | ||
} | ||
|
||
fn main() { | ||
let _: <S as Trait>::Target; //~ ERROR cannot find associated type `Output` in trait `Trait` | ||
//~^ HELP maybe you meant this associated type | ||
|
||
let _ = <S as Trait>::FOO; //~ ERROR cannot find method or associated constant `BAR` in trait `Trait` | ||
//~^ HELP maybe you meant this associated constant | ||
} |
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,22 @@ | ||
// run-rustfix | ||
|
||
trait Trait { | ||
const FOO: usize; | ||
|
||
type Target; | ||
} | ||
|
||
struct S; | ||
|
||
impl Trait for S { | ||
const FOO: usize = 0; | ||
type Target = (); | ||
} | ||
|
||
fn main() { | ||
let _: <S as Trait>::Output; //~ ERROR cannot find associated type `Output` in trait `Trait` | ||
//~^ HELP maybe you meant this associated type | ||
|
||
let _ = <S as Trait>::BAR; //~ ERROR cannot find method or associated constant `BAR` in trait `Trait` | ||
//~^ HELP maybe you meant this associated constant | ||
} |
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,27 @@ | ||
error[E0576]: cannot find associated type `Output` in trait `Trait` | ||
--> $DIR/issue-87638.rs:17:26 | ||
| | ||
LL | type Target; | ||
| ------------ associated type `Target` defined here | ||
... | ||
LL | let _: <S as Trait>::Output; | ||
| ^^^^^^ | ||
| | | ||
| not found in `Trait` | ||
| help: maybe you meant this associated type: `Target` | ||
|
||
error[E0576]: cannot find method or associated constant `BAR` in trait `Trait` | ||
--> $DIR/issue-87638.rs:20:27 | ||
| | ||
LL | const FOO: usize; | ||
| ----------------- associated constant `FOO` defined here | ||
... | ||
LL | let _ = <S as Trait>::BAR; | ||
| ^^^ | ||
| | | ||
| not found in `Trait` | ||
| help: maybe you meant this associated constant: `FOO` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0576`. |
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