From d5642acfe689ca704b8572ea8ca88e43aeb70a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 1 Jul 2022 16:33:35 -0700 Subject: [PATCH] Add test for #98539 --- .../impl-derived-implicit-sized-bound.rs | 36 +++++++++++++++++++ .../impl-derived-implicit-sized-bound.stderr | 33 +++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.rs create mode 100644 src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr diff --git a/src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.rs b/src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.rs new file mode 100644 index 00000000000..28da41a0ca5 --- /dev/null +++ b/src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.rs @@ -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() {} diff --git a/src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr b/src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr new file mode 100644 index 00000000000..aa3c211fa39 --- /dev/null +++ b/src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr @@ -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`.