about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorwhtahy <whtahy@users.noreply.github.com>2023-04-26 20:37:42 -0400
committerwhtahy <whtahy@users.noreply.github.com>2023-04-26 22:34:29 -0400
commitbfdd1c4e351f1a30f445c33efdfb946c0eae81ba (patch)
tree76441bf79d7d4cfa8e85404c19dea86a99538717 /tests
parentcb9aa8c9c19236f09667dc0bddbe6daee638696c (diff)
downloadrust-bfdd1c4e351f1a30f445c33efdfb946c0eae81ba.tar.gz
rust-bfdd1c4e351f1a30f445c33efdfb946c0eae81ba.zip
add known-bug test for unsound issue 40582
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/specialization/issue-40582.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/ui/specialization/issue-40582.rs b/tests/ui/specialization/issue-40582.rs
new file mode 100644
index 00000000000..9805933553d
--- /dev/null
+++ b/tests/ui/specialization/issue-40582.rs
@@ -0,0 +1,35 @@
+// check-pass
+// known-bug: #40582
+
+// Should fail. Should not be possible to implement `make_static`.
+
+#![feature(specialization)]
+#![allow(incomplete_features)]
+
+trait FromRef<'a, T: ?Sized> {
+    fn from_ref(r: &'a T) -> Self;
+}
+
+impl<'a, T: ?Sized> FromRef<'a, T> for &'a T {
+    fn from_ref(r: &'a T) -> Self {
+        r
+    }
+}
+
+impl<'a, T: ?Sized, R> FromRef<'a, T> for R {
+    default fn from_ref(_: &'a T) -> Self {
+        unimplemented!()
+    }
+}
+
+fn make_static<T: ?Sized>(data: &T) -> &'static T {
+    fn helper<T: ?Sized, R>(data: &T) -> R {
+        R::from_ref(data)
+    }
+    helper(data)
+}
+
+fn main() {
+    let s = "specialization".to_owned();
+    println!("{:?}", make_static(s.as_str()));
+}