summaryrefslogtreecommitdiffstats
path: root/tests/ui/specialization/issue-40582.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /tests/ui/specialization/issue-40582.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/specialization/issue-40582.rs')
-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 000000000..980593355
--- /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()));
+}