-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #79639 - sasurau4:feature/add-long-explanation-E0212,…
… r=GuillaumeGomez Add long explanation for E0212 Helps with #61137
- Loading branch information
Showing
11 changed files
with
58 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Cannot use the associated type of | ||
a trait with uninferred generic parameters. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0212 | ||
pub trait Foo<T> { | ||
type A; | ||
fn get(&self, t: T) -> Self::A; | ||
} | ||
fn foo2<I : for<'x> Foo<&'x isize>>( | ||
field: I::A) {} // error! | ||
``` | ||
|
||
In this example, we have to instantiate `'x`, and | ||
we don't know what lifetime to instantiate it with. | ||
To fix this, spell out the precise lifetimes involved. | ||
Example: | ||
|
||
``` | ||
pub trait Foo<T> { | ||
type A; | ||
fn get(&self, t: T) -> Self::A; | ||
} | ||
fn foo3<I : for<'x> Foo<&'x isize>>( | ||
x: <I as Foo<&isize>>::A) {} // ok! | ||
fn foo4<'a, I : for<'x> Foo<&'x isize>>( | ||
x: <I as Foo<&'a isize>>::A) {} // ok! | ||
``` |
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
3 changes: 2 additions & 1 deletion
3
src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context | ||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters | ||
--> $DIR/associated-types-project-from-hrtb-in-fn.rs:13:8 | ||
| | ||
LL | x: I::A) | ||
| ^^^^ help: use a fully qualified path with inferred lifetimes: `<I as Foo<&isize>>::A` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0212`. |
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
5 changes: 3 additions & 2 deletions
5
src/test/ui/associated-types/associated-types-project-from-hrtb-in-trait-method.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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context | ||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters | ||
--> $DIR/associated-types-project-from-hrtb-in-trait-method.rs:13:32 | ||
| | ||
LL | fn some_method(&self, arg: I::A); | ||
| ^^^^ help: use a fully qualified path with inferred lifetimes: `<I as Foo<&isize>>::A` | ||
|
||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context | ||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters | ||
--> $DIR/associated-types-project-from-hrtb-in-trait-method.rs:32:24 | ||
| | ||
LL | fn mango(&self) -> X::Assoc { | ||
| ^^^^^^^^ help: use a fully qualified path with inferred lifetimes: `<X as Banana<'_>>::Assoc` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0212`. |