Skip to content

Commit

Permalink
Add test for rust-lang#98539
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jul 7, 2022
1 parent 3e51277 commit d5642ac
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.rs
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 src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr
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`.

0 comments on commit d5642ac

Please sign in to comment.