forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.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,36 @@ | ||
struct Victim<'a, T: Perpetrator + ?Sized> | ||
where | ||
Self: Sized | ||
{ | ||
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(); | ||
//~^ ERROR the method `get` exists for struct `Victim<'_, Self>`, but its trait bounds were not satisfied | ||
} | ||
} | ||
|
||
fn main() {} |
33 changes: 33 additions & 0 deletions
33
src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.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,33 @@ | ||
error[E0599]: the method `get` exists for struct `Victim<'_, Self>`, but its trait bounds were not satisfied | ||
--> $DIR/impl-derived-implicit-sized-bound.rs:31:19 | ||
| | ||
LL | / struct Victim<'a, T: Perpetrator + ?Sized> | ||
LL | | where | ||
LL | | Self: Sized | ||
LL | | { | ||
LL | | value: u8, | ||
LL | | perp: &'a T, | ||
LL | | } | ||
| | - | ||
| | | | ||
| |_method `get` not found for this | ||
| doesn't satisfy `Victim<'_, Self>: VictimTrait` | ||
... | ||
LL | self.getter().get(); | ||
| ^^^ method cannot be called on `Victim<'_, Self>` due to unsatisfied trait bounds | ||
| | ||
note: trait bound `Self: Sized` was not satisfied | ||
--> $DIR/impl-derived-implicit-sized-bound.rs:15:10 | ||
| | ||
LL | 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 | ||
| | ||
LL | Self: Sized, Self: Sized | ||
| +++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |