-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
struct Victim<'a, T: Perpetrator + ?Sized>
where
Self: Sized // rustc suggests adding this trait bound, even if it already exists, however this is absolutely not needed
{
value: u8,
perp: &'a T,
}
trait VictimTrait {
type Ret;
fn get(self) -> Self::Ret;
}
// Actual fix is here
impl<'a, T: Perpetrator /*+ ?Sized*/> VictimTrait for Victim<'a, T> {
type Ret = u8;
fn get(self) -> Self::Ret {
self.value
}
}
trait Perpetrator {
fn getter<'a>(&'a self) -> Victim<'a, Self> {
Victim {
value: 0,
perp: self,
}
}
fn trigger(&self) {
self.getter().get();
}
}
This does not compile with the following error message:
error[[E0599]](https://doc.rust-lang.org/stable/error-index.html#E0599): the method `get` exists for struct `Victim<'_, Self>`, but its trait bounds were not satisfied
--> src/main.rs:31:19
|
1 | / struct Victim<'a, T: Perpetrator + ?Sized>
2 | | where
3 | | Self: Sized // rustc sugests adding this trait bound, even if it already exists
4 | | {
5 | | value: u8,
6 | | perp: &'a T,
7 | | }
| | -
| | |
| |_method `get` not found for this
| doesn't satisfy `Victim<'_, Self>: VictimTrait`
...
31 | self.getter().get();
| ^^^ method cannot be called on `Victim<'_, Self>` due to unsatisfied trait bounds
|
note: trait bound `Self: Sized` was not satisfied
--> src/main.rs:15:10
|
15 | impl<'a, T: Perpetrator /*+ ?Sized*/> VictimTrait for Victim<'a, T> {
| ^ ----------- -------------
| |
| unsatisfied trait bound introduced here
help: consider restricting the type parameter to satisfy the trait bound
|
3 | Self: Sized, Self: Sized // rustc sugests adding this trait bound, even if it already exists
| +++++++++++++
For more information about this error, try `rustc --explain E0599`.
This message is misleading, instruction you to add an (possibly) already existing trait bound instead of the actual fix, which is commented out in the code
Meta
This bug currently exists both in stable 1.61.0 and nightly 1.64.0-nightly(2022-06-25 20a6f3a).
TaKO8Ki, estebank, TimJentzsch, Kobzol and jieyouxu
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.