forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#116257 - estebank:issue-101351, r=b-naber Suggest trait bounds for used associated type on type param Fix rust-lang#101351. When an associated type on a type parameter is used, and the type parameter isn't constrained by the correct trait, suggest the appropriate trait bound: ``` error[E0220]: associated type `Associated` not found for `T` --> file.rs:6:15 | 6 | field: T::Associated, | ^^^^^^^^^^ there is a similarly named associated type `Associated` in the trait `Foo` | help: consider restricting type parameter `T` | 5 | struct Generic<T: Foo> { | +++++ ``` When an associated type on a type parameter has a typo, suggest fixing it: ``` error[E0220]: associated type `Baa` not found for `T` --> $DIR/issue-55673.rs:9:8 | LL | T::Baa: std::fmt::Debug, | ^^^ there is a similarly named associated type `Bar` in the trait `Foo` | help: change the associated type name to use `Bar` from `Foo` | LL | T::Bar: std::fmt::Debug, | ~~~ ```
- Loading branch information
Showing
12 changed files
with
152 additions
and
23 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
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,21 @@ | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
trait Foo { | ||
type Bar; | ||
} | ||
|
||
fn foo<T: Foo>() | ||
where | ||
T::Bar: std::fmt::Debug, | ||
//~^ ERROR associated type `Baa` not found for `T` | ||
{ | ||
} | ||
|
||
fn bar<T>() | ||
where | ||
T::Bar: std::fmt::Debug, T: Foo | ||
//~^ ERROR associated type `Baa` not found for `T` | ||
{ | ||
} | ||
|
||
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
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 |
---|---|---|
@@ -1,9 +1,29 @@ | ||
error[E0220]: associated type `Baa` not found for `T` | ||
--> $DIR/issue-55673.rs:7:8 | ||
--> $DIR/issue-55673.rs:9:8 | ||
| | ||
LL | T::Baa: std::fmt::Debug, | ||
| ^^^ there is a similarly named associated type `Bar` in the trait `Foo` | ||
| | ||
help: change the associated type name to use `Bar` from `Foo` | ||
| | ||
LL | T::Bar: std::fmt::Debug, | ||
| ~~~ | ||
|
||
error[E0220]: associated type `Baa` not found for `T` | ||
--> $DIR/issue-55673.rs:16:8 | ||
| | ||
LL | T::Baa: std::fmt::Debug, | ||
| ^^^ there is a similarly named associated type `Bar` in the trait `Foo` | ||
| | ||
help: consider further restricting type parameter `T` | ||
| | ||
LL | T::Baa: std::fmt::Debug, T: Foo | ||
| ~~~~~~~~ | ||
help: and also change the associated type name | ||
| | ||
LL | T::Bar: std::fmt::Debug, | ||
| ~~~ | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0220`. |
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,19 @@ | ||
// run-rustfix | ||
#![feature(type_alias_impl_trait)] | ||
#![allow(dead_code)] | ||
|
||
fn main() {} | ||
|
||
trait TraitWithAssoc { | ||
type Assoc; | ||
} | ||
|
||
type Foo<V: TraitWithAssoc> = impl Trait<V::Assoc>; //~ associated type `Assoc` not found for `V` | ||
|
||
trait Trait<U> {} | ||
|
||
impl<W> Trait<W> for () {} | ||
|
||
fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T> { | ||
() | ||
} |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
// run-rustfix | ||
#![feature(type_alias_impl_trait)] | ||
#![allow(dead_code)] | ||
|
||
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