about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2022-07-01 16:33:35 -0700
committerEsteban Küber <esteban@kuber.com.ar>2022-07-07 11:24:03 -0700
commitd5642acfe689ca704b8572ea8ca88e43aeb70a11 (patch)
treea13bc8ffb3aea49c06ca2827ed549b8ff9014fe4
parent3e51277fe638dc0c8ceb6d1d3acc5aa247277c29 (diff)
downloadrust-d5642acfe689ca704b8572ea8ca88e43aeb70a11.tar.gz
rust-d5642acfe689ca704b8572ea8ca88e43aeb70a11.zip
Add test for #98539
-rw-r--r--src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.rs36
-rw-r--r--src/test/ui/trait-bounds/impl-derived-implicit-sized-bound.stderr33
2 files changed, 69 insertions, 0 deletions
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`.