about summary refs log tree commit diff
diff options
context:
space:
mode:
authorwhtahy <whtahy@users.noreply.github.com>2023-04-19 00:44:07 -0400
committerwhtahy <whtahy@users.noreply.github.com>2023-04-22 00:47:07 -0400
commitbe68c69e7123fbe513c1f5689f61018e3f94220e (patch)
treec902b5fa6bb8e55eceb565cb3999f4c604a90e37
parentcac62ab2dde20adca6e1a9070211afbc784c1d64 (diff)
downloadrust-be68c69e7123fbe513c1f5689f61018e3f94220e.tar.gz
rust-be68c69e7123fbe513c1f5689f61018e3f94220e.zip
add known-bug test for unsound issue 84591
-rw-r--r--tests/ui/implied-bounds/implied-bounds-on-trait-hierarchy.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/implied-bounds/implied-bounds-on-trait-hierarchy.rs b/tests/ui/implied-bounds/implied-bounds-on-trait-hierarchy.rs
new file mode 100644
index 00000000000..9c26cd59d10
--- /dev/null
+++ b/tests/ui/implied-bounds/implied-bounds-on-trait-hierarchy.rs
@@ -0,0 +1,39 @@
+// check-pass
+// known-bug: #84591
+
+// Should fail. Subtrait can incorrectly extend supertrait lifetimes even when
+// supertrait has weaker implied bounds than subtrait. Strongly related to
+// issue #25860.
+
+trait Subtrait<T>: Supertrait {}
+trait Supertrait {
+    fn action(self);
+}
+
+fn subs_to_soup<T, U>(x: T)
+where
+    T: Subtrait<U>,
+{
+    soup(x)
+}
+
+fn soup<T: Supertrait>(x: T) {
+    x.action();
+}
+
+impl<'a, 'b: 'a> Supertrait for (&'b str, &mut &'a str) {
+    fn action(self) {
+        *self.1 = self.0;
+    }
+}
+
+impl<'a, 'b> Subtrait<&'a &'b str> for (&'b str, &mut &'a str) {}
+
+fn main() {
+    let mut d = "hi";
+    {
+        let x = "Hello World".to_string();
+        subs_to_soup((x.as_str(), &mut d));
+    }
+    println!("{}", d);
+}