-
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.
When trying to set the value of a shadowed associated type, the error message was confusing, as it simply said that there is a missing type. Now the compiler notifies the user about the shadow, and suggests renaming as a fix
- Loading branch information
1 parent
9c8a269
commit 6d8c642
Showing
4 changed files
with
110 additions
and
1 deletion.
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
19 changes: 19 additions & 0 deletions
19
tests/ui/associated-types/associated-type-shadowed-from-supertrait.rs
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 @@ | ||
// Test Setting the value of an associated type | ||
// that is shadowed from a supertrait | ||
|
||
pub trait Super { | ||
type X; | ||
} | ||
|
||
pub trait Sub: Super { | ||
type X; | ||
} | ||
|
||
impl<T> Clone for Box<dyn Sub<X = T>> { | ||
//~^ ERROR associated type `X` in `Super` must be specified | ||
fn clone(&self) -> Self { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
pub fn main() {} |
26 changes: 26 additions & 0 deletions
26
tests/ui/associated-types/associated-type-shadowed-from-supertrait.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error[E0191]: the value of the associated type `X` in `Super` must be specified | ||
--> $DIR/associated-type-shadowed-from-supertrait.rs:12:27 | ||
| | ||
LL | type X; | ||
| ------ `Super::X` defined here | ||
... | ||
LL | type X; | ||
| ------ `Super::X` shadowed here | ||
... | ||
LL | impl<T> Clone for Box<dyn Sub<X = T>> { | ||
| ^^^^^^^^^^ associated type `X` must be specified | ||
| | ||
help: consider renaming this associated type | ||
--> $DIR/associated-type-shadowed-from-supertrait.rs:5:5 | ||
| | ||
LL | type X; | ||
| ^^^^^^ | ||
help: consider renaming this associated type | ||
--> $DIR/associated-type-shadowed-from-supertrait.rs:9:5 | ||
| | ||
LL | type X; | ||
| ^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0191`. |