Skip to content

Commit d5642ac

Browse files
committed
Add test for #98539
1 parent 3e51277 commit d5642ac

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
struct Victim<'a, T: Perpetrator + ?Sized>
2+
where
3+
Self: Sized
4+
{
5+
value: u8,
6+
perp: &'a T,
7+
}
8+
9+
trait VictimTrait {
10+
type Ret;
11+
fn get(self) -> Self::Ret;
12+
}
13+
14+
// Actual fix is here
15+
impl<'a, T: Perpetrator /*+ ?Sized*/> VictimTrait for Victim<'a, T> {
16+
type Ret = u8;
17+
fn get(self) -> Self::Ret {
18+
self.value
19+
}
20+
}
21+
22+
trait Perpetrator {
23+
fn getter<'a>(&'a self) -> Victim<'a, Self> {
24+
Victim {
25+
value: 0,
26+
perp: self,
27+
}
28+
}
29+
30+
fn trigger(&self) {
31+
self.getter().get();
32+
//~^ ERROR the method `get` exists for struct `Victim<'_, Self>`, but its trait bounds were not satisfied
33+
}
34+
}
35+
36+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0599]: the method `get` exists for struct `Victim<'_, Self>`, but its trait bounds were not satisfied
2+
--> $DIR/impl-derived-implicit-sized-bound.rs:31:19
3+
|
4+
LL | / struct Victim<'a, T: Perpetrator + ?Sized>
5+
LL | | where
6+
LL | | Self: Sized
7+
LL | | {
8+
LL | | value: u8,
9+
LL | | perp: &'a T,
10+
LL | | }
11+
| | -
12+
| | |
13+
| |_method `get` not found for this
14+
| doesn't satisfy `Victim<'_, Self>: VictimTrait`
15+
...
16+
LL | self.getter().get();
17+
| ^^^ method cannot be called on `Victim<'_, Self>` due to unsatisfied trait bounds
18+
|
19+
note: trait bound `Self: Sized` was not satisfied
20+
--> $DIR/impl-derived-implicit-sized-bound.rs:15:10
21+
|
22+
LL | impl<'a, T: Perpetrator /*+ ?Sized*/> VictimTrait for Victim<'a, T> {
23+
| ^ ----------- -------------
24+
| |
25+
| unsatisfied trait bound introduced here
26+
help: consider restricting the type parameter to satisfy the trait bound
27+
|
28+
LL | Self: Sized, Self: Sized
29+
| +++++++++++++
30+
31+
error: aborting due to previous error
32+
33+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)