From 837b550238aa671a591ccf282dddeab29cadb206 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:42 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/specialization/const_trait_impl.rs | 3 +- tests/ui/specialization/const_trait_impl.stderr | 20 +++++++++ tests/ui/specialization/issue-111232.rs | 11 +++++ tests/ui/specialization/issue-111232.stderr | 11 +++++ tests/ui/specialization/issue-40582.rs | 35 +++++++++++++++ .../specialize-associated-type.rs | 37 ++++++++++++++++ .../min_specialization/specialize_nothing.rs | 14 ++++++ .../min_specialization/specialize_nothing.stderr | 14 ++++++ .../min_specialization/specialize_on_type_error.rs | 33 ++++++++++++++ .../specialize_on_type_error.stderr | 12 ++++++ .../specialize_with_generalize_lifetimes.rs | 50 ++++++++++++++++++++++ .../specialize_with_generalize_lifetimes.stderr | 27 ++++++++++++ .../specialization-default-items-drop-coherence.rs | 30 +++++++++++++ 13 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 tests/ui/specialization/const_trait_impl.stderr create mode 100644 tests/ui/specialization/issue-111232.rs create mode 100644 tests/ui/specialization/issue-111232.stderr create mode 100644 tests/ui/specialization/issue-40582.rs create mode 100644 tests/ui/specialization/min_specialization/specialize-associated-type.rs create mode 100644 tests/ui/specialization/min_specialization/specialize_nothing.rs create mode 100644 tests/ui/specialization/min_specialization/specialize_nothing.stderr create mode 100644 tests/ui/specialization/min_specialization/specialize_on_type_error.rs create mode 100644 tests/ui/specialization/min_specialization/specialize_on_type_error.stderr create mode 100644 tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.rs create mode 100644 tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.stderr create mode 100644 tests/ui/specialization/specialization-default-items-drop-coherence.rs (limited to 'tests/ui/specialization') 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 const A for T { + | ^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const_trait_impl.rs:40:16 + | +LL | impl const A for T { + | ^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const_trait_impl.rs:46:16 + | +LL | impl 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 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(data: &T) -> &'static T { + fn helper(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); + +impl X for () {} + +impl Z for A { + type Assoc = (); +} + +trait MyFrom { + fn from(other: T) -> Self; +} + +impl MyFrom<()> for T { + default fn from(other: ()) -> T { + panic!(); + } +} + +impl MyFrom< 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 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 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); + +impl Z for A {} +//~^ ERROR not all trait items implemented + +trait MyFrom { + fn from(other: T) -> Self; +} + +impl MyFrom for T { + default fn from(other: T) -> T { + other + } +} + +impl MyFrom< as Z>::Assoc> for T { + fn from(other: 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 Z for A {} + | ^^^^^^^^^^^^^^^^^^^^^ 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; + fn other(self); +} + +impl Tr for T { + default fn method(self) -> Box { + 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 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 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 Default for T { + default type Id = T; +} + +trait Overlap { + type Assoc; +} + +impl Overlap for u32 { + type Assoc = usize; +} + +impl Overlap for ::Id { + type Assoc = Box; +} + +fn main() {} -- cgit v1.2.3