summaryrefslogtreecommitdiffstats
path: root/tests/ui/specialization
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
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')
-rw-r--r--tests/ui/specialization/const_trait_impl.rs3
-rw-r--r--tests/ui/specialization/const_trait_impl.stderr20
-rw-r--r--tests/ui/specialization/issue-111232.rs11
-rw-r--r--tests/ui/specialization/issue-111232.stderr11
-rw-r--r--tests/ui/specialization/issue-40582.rs35
-rw-r--r--tests/ui/specialization/min_specialization/specialize-associated-type.rs37
-rw-r--r--tests/ui/specialization/min_specialization/specialize_nothing.rs14
-rw-r--r--tests/ui/specialization/min_specialization/specialize_nothing.stderr14
-rw-r--r--tests/ui/specialization/min_specialization/specialize_on_type_error.rs33
-rw-r--r--tests/ui/specialization/min_specialization/specialize_on_type_error.stderr12
-rw-r--r--tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.rs50
-rw-r--r--tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.stderr27
-rw-r--r--tests/ui/specialization/specialization-default-items-drop-coherence.rs30
13 files changed, 296 insertions, 1 deletions
diff --git a/tests/ui/specialization/const_trait_impl.rs b/tests/ui/specialization/const_trait_impl.rs
index 05ba4c8d4..b1ec58c3d 100644
--- a/tests/ui/specialization/const_trait_impl.rs
+++ b/tests/ui/specialization/const_trait_impl.rs
@@ -1,4 +1,5 @@
-// check-pass
+// known-bug: #110395
+
#![feature(const_trait_impl, min_specialization, rustc_attrs)]
#[rustc_specialization_trait]
diff --git a/tests/ui/specialization/const_trait_impl.stderr b/tests/ui/specialization/const_trait_impl.stderr
new file mode 100644
index 000000000..d13cd8f55
--- /dev/null
+++ b/tests/ui/specialization/const_trait_impl.stderr
@@ -0,0 +1,20 @@
+error: ~const can only be applied to `#[const_trait]` traits
+ --> $DIR/const_trait_impl.rs:34:16
+ |
+LL | impl<T: ~const Default> const A for T {
+ | ^^^^^^^
+
+error: ~const can only be applied to `#[const_trait]` traits
+ --> $DIR/const_trait_impl.rs:40:16
+ |
+LL | impl<T: ~const Default + ~const Sup> const A for T {
+ | ^^^^^^^
+
+error: ~const can only be applied to `#[const_trait]` traits
+ --> $DIR/const_trait_impl.rs:46:16
+ |
+LL | impl<T: ~const Default + ~const Sub> const A for T {
+ | ^^^^^^^
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/specialization/issue-111232.rs b/tests/ui/specialization/issue-111232.rs
new file mode 100644
index 000000000..3ed3c580e
--- /dev/null
+++ b/tests/ui/specialization/issue-111232.rs
@@ -0,0 +1,11 @@
+#![feature(min_specialization)]
+
+struct S;
+
+impl From<S> for S {
+ fn from(s: S) -> S { //~ ERROR `from` specializes an item from a parent `impl`, but that item is not marked `default`
+ s
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/specialization/issue-111232.stderr b/tests/ui/specialization/issue-111232.stderr
new file mode 100644
index 000000000..27ee42fc0
--- /dev/null
+++ b/tests/ui/specialization/issue-111232.stderr
@@ -0,0 +1,11 @@
+error[E0520]: `from` specializes an item from a parent `impl`, but that item is not marked `default`
+ --> $DIR/issue-111232.rs:6:5
+ |
+LL | fn from(s: S) -> S {
+ | ^^^^^^^^^^^^^^^^^^
+ |
+ = note: parent implementation is in crate `core`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0520`.
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()));
+}
diff --git a/tests/ui/specialization/min_specialization/specialize-associated-type.rs b/tests/ui/specialization/min_specialization/specialize-associated-type.rs
new file mode 100644
index 000000000..c4960b0c2
--- /dev/null
+++ b/tests/ui/specialization/min_specialization/specialize-associated-type.rs
@@ -0,0 +1,37 @@
+// Another regression test for #109815.
+
+// check-pass
+
+#![feature(min_specialization)]
+#![feature(rustc_attrs)]
+
+#[rustc_specialization_trait]
+trait X {}
+trait Z {
+ type Assoc: X;
+}
+struct A<T>(T);
+
+impl X for () {}
+
+impl<T: X> Z for A<T> {
+ type Assoc = ();
+}
+
+trait MyFrom<T> {
+ fn from(other: T) -> Self;
+}
+
+impl<T> MyFrom<()> for T {
+ default fn from(other: ()) -> T {
+ panic!();
+ }
+}
+
+impl<T: X> MyFrom<<A<T> as Z>::Assoc> for T {
+ fn from(other: ()) -> T {
+ panic!();
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/specialization/min_specialization/specialize_nothing.rs b/tests/ui/specialization/min_specialization/specialize_nothing.rs
new file mode 100644
index 000000000..ef92254d4
--- /dev/null
+++ b/tests/ui/specialization/min_specialization/specialize_nothing.rs
@@ -0,0 +1,14 @@
+#![feature(min_specialization)]
+
+trait Special {
+ fn be_special();
+}
+
+impl<T> Special for T {
+ fn be_special() {}
+}
+
+impl Special for usize {}
+//~^ ERROR specialization impl does not specialize any associated items
+
+fn main() {}
diff --git a/tests/ui/specialization/min_specialization/specialize_nothing.stderr b/tests/ui/specialization/min_specialization/specialize_nothing.stderr
new file mode 100644
index 000000000..65f73781c
--- /dev/null
+++ b/tests/ui/specialization/min_specialization/specialize_nothing.stderr
@@ -0,0 +1,14 @@
+error: specialization impl does not specialize any associated items
+ --> $DIR/specialize_nothing.rs:11:1
+ |
+LL | impl Special for usize {}
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: impl is a specialization of this impl
+ --> $DIR/specialize_nothing.rs:7:1
+ |
+LL | impl<T> Special for T {
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/specialization/min_specialization/specialize_on_type_error.rs b/tests/ui/specialization/min_specialization/specialize_on_type_error.rs
new file mode 100644
index 000000000..24e92a0ab
--- /dev/null
+++ b/tests/ui/specialization/min_specialization/specialize_on_type_error.rs
@@ -0,0 +1,33 @@
+// A regression test for #109815.
+
+#![feature(min_specialization)]
+#![feature(rustc_attrs)]
+
+#[rustc_specialization_trait]
+trait X {}
+trait Y: X {}
+trait Z {
+ type Assoc: Y;
+}
+struct A<T>(T);
+
+impl<T: X> Z for A<T> {}
+//~^ ERROR not all trait items implemented
+
+trait MyFrom<T> {
+ fn from(other: T) -> Self;
+}
+
+impl<T> MyFrom<T> for T {
+ default fn from(other: T) -> T {
+ other
+ }
+}
+
+impl<T: X> MyFrom<<A<T> as Z>::Assoc> for T {
+ fn from(other: <A<T> as Z>::Assoc) -> T {
+ other
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/specialization/min_specialization/specialize_on_type_error.stderr b/tests/ui/specialization/min_specialization/specialize_on_type_error.stderr
new file mode 100644
index 000000000..cc12302bd
--- /dev/null
+++ b/tests/ui/specialization/min_specialization/specialize_on_type_error.stderr
@@ -0,0 +1,12 @@
+error[E0046]: not all trait items implemented, missing: `Assoc`
+ --> $DIR/specialize_on_type_error.rs:14:1
+ |
+LL | type Assoc: Y;
+ | ------------- `Assoc` from trait
+...
+LL | impl<T: X> Z for A<T> {}
+ | ^^^^^^^^^^^^^^^^^^^^^ missing `Assoc` in implementation
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0046`.
diff --git a/tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.rs b/tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.rs
new file mode 100644
index 000000000..d90b81f71
--- /dev/null
+++ b/tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.rs
@@ -0,0 +1,50 @@
+// Regression test for #79457.
+
+#![feature(min_specialization)]
+
+use std::any::Any;
+
+pub trait Tr {
+ fn method(self) -> Box<dyn Any + 'static>;
+ fn other(self);
+}
+
+impl<T: Any + 'static> Tr for T {
+ default fn method(self) -> Box<dyn Any + 'static> {
+ Box::new(self)
+ }
+
+ default fn other(self) {}
+}
+
+impl<'a> Tr for &'a i32 {
+ //~^ ERROR does not fulfill the required lifetime
+ fn other(self) {}
+}
+
+fn promote_to_static<'a>(i: &'a i32) -> &'static i32 {
+ *i.method().downcast().unwrap()
+}
+
+struct Wrapper<'a>(&'a i32);
+
+impl<'a> Tr for Wrapper<'a> {
+ //~^ ERROR does not fulfill the required lifetime
+ fn other(self) {}
+}
+
+fn promote_to_static_2<'a>(w: Wrapper<'a>) -> Wrapper<'static> {
+ *w.method().downcast().unwrap()
+}
+
+fn main() {
+ let i = Box::new(100_i32);
+ let static_i: &'static i32 = promote_to_static(&*i);
+ drop(i);
+ println!("{}", *static_i);
+
+ let j = Box::new(200_i32);
+ let static_w: Wrapper<'static> = promote_to_static_2(Wrapper(&*j));
+ drop(j);
+ println!("{}", *static_w.0);
+}
diff --git a/tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.stderr b/tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.stderr
new file mode 100644
index 000000000..2af75876d
--- /dev/null
+++ b/tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.stderr
@@ -0,0 +1,27 @@
+error[E0477]: the type `&'a i32` does not fulfill the required lifetime
+ --> $DIR/specialize_with_generalize_lifetimes.rs:20:1
+ |
+LL | impl<'a> Tr for &'a i32 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: type must satisfy the static lifetime as required by this binding
+ --> $DIR/specialize_with_generalize_lifetimes.rs:12:15
+ |
+LL | impl<T: Any + 'static> Tr for T {
+ | ^^^^^^^
+
+error[E0477]: the type `Wrapper<'a>` does not fulfill the required lifetime
+ --> $DIR/specialize_with_generalize_lifetimes.rs:31:1
+ |
+LL | impl<'a> Tr for Wrapper<'a> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: type must satisfy the static lifetime as required by this binding
+ --> $DIR/specialize_with_generalize_lifetimes.rs:12:15
+ |
+LL | impl<T: Any + 'static> Tr for T {
+ | ^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0477`.
diff --git a/tests/ui/specialization/specialization-default-items-drop-coherence.rs b/tests/ui/specialization/specialization-default-items-drop-coherence.rs
new file mode 100644
index 000000000..16ad942d5
--- /dev/null
+++ b/tests/ui/specialization/specialization-default-items-drop-coherence.rs
@@ -0,0 +1,30 @@
+// check-pass
+// known-bug: #105782
+
+// Should fail. Default items completely drop candidates instead of ambiguity,
+// which is unsound during coherence, since coherence requires completeness.
+
+#![feature(specialization)]
+#![allow(incomplete_features)]
+
+trait Default {
+ type Id;
+}
+
+impl<T> Default for T {
+ default type Id = T;
+}
+
+trait Overlap {
+ type Assoc;
+}
+
+impl Overlap for u32 {
+ type Assoc = usize;
+}
+
+impl Overlap for <u32 as Default>::Id {
+ type Assoc = Box<usize>;
+}
+
+fn main() {}