Add test for #98539

This commit is contained in:
Esteban Küber 2022-07-01 16:33:35 -07:00
parent 3e51277fe6
commit d5642acfe6
2 changed files with 69 additions and 0 deletions

View File

@ -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() {}

View File

@ -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`.