about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorBryanskiy <ivakin.kir@gmail.com>2025-08-19 21:34:33 +0300
committerBryanskiy <ivakin.kir@gmail.com>2025-09-10 15:08:06 +0300
commitbd089e1e6e52256c0535f19f58b4b6fe9609b70c (patch)
tree1b9f8a41f2e7ce7bd3a50a22fe41425e001fb78d /tests
parent7ad23f43a225546c095123de52cc07d8719f8e2b (diff)
downloadrust-bd089e1e6e52256c0535f19f58b4b6fe9609b70c.tar.gz
rust-bd089e1e6e52256c0535f19f58b4b6fe9609b70c.zip
Default auto traits: revert to the default supertraits
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/traits/default_auto_traits/backward-compatible-lazy-bounds-pass.rs31
-rw-r--r--tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.rs80
-rw-r--r--tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.stderr66
-rw-r--r--tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.rs78
-rw-r--r--tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.stderr80
5 files changed, 138 insertions, 197 deletions
diff --git a/tests/ui/traits/default_auto_traits/backward-compatible-lazy-bounds-pass.rs b/tests/ui/traits/default_auto_traits/backward-compatible-lazy-bounds-pass.rs
deleted file mode 100644
index 745b6ee9bc5..00000000000
--- a/tests/ui/traits/default_auto_traits/backward-compatible-lazy-bounds-pass.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-//@ check-pass
-//@ compile-flags: -Zexperimental-default-bounds
-
-#![feature(auto_traits, lang_items, no_core, rustc_attrs, trait_alias)]
-#![no_std]
-#![no_core]
-
-#[lang = "pointee_sized"]
-trait PointeeSized {}
-
-#[lang = "meta_sized"]
-trait MetaSized: PointeeSized {}
-
-#[lang = "sized"]
-trait Sized: MetaSized {}
-
-#[lang = "default_trait1"]
-auto trait DefaultTrait1 {}
-
-#[lang = "default_trait2"]
-auto trait DefaultTrait2 {}
-
-trait Trait<Rhs: ?Sized = Self> {}
-trait Trait1 : Trait {}
-
-trait Trait2 {
-    type Type;
-}
-trait Trait3<T> = Trait2<Type = T>;
-
-fn main() {}
diff --git a/tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.rs b/tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.rs
index e7cca41a47e..2e1a5d2424b 100644
--- a/tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.rs
+++ b/tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.rs
@@ -13,32 +13,37 @@
 #![no_core]
 
 #[lang = "pointee_sized"]
-trait PointeeSized {}
+trait PointeeSized: ?Leak {}
 
 #[lang = "meta_sized"]
-trait MetaSized: PointeeSized {}
+trait MetaSized: PointeeSized + ?Leak {}
 
 #[lang = "sized"]
-trait Sized: MetaSized {}
+trait Sized: MetaSized + ?Leak {}
 
 #[lang = "copy"]
-pub trait Copy {}
+pub trait Copy: ?Leak {}
 impl<'a, T: ?Sized> Copy for &'a T {}
 
 #[lang = "legacy_receiver"]
-trait Receiver {}
+trait Receiver: ?Leak {}
 impl<T: ?Sized + ?Leak> Receiver for &T {}
+impl<T: ?Sized + ?Leak> Receiver for &mut T {}
 
 #[lang = "unsize"]
-trait Unsize<T: ?Sized + ?Leak> {}
+trait Unsize<T: ?Sized + ?Leak>: ?Leak {}
 
 #[lang = "coerce_unsized"]
-trait CoerceUnsized<T: ?Leak + ?Sized> {}
+trait CoerceUnsized<T: ?Leak + ?Sized>: ?Leak {}
 impl<'a, 'b: 'a, T: ?Sized + ?Leak + Unsize<U>, U: ?Sized + ?Leak> CoerceUnsized<&'a U> for &'b T {}
+// Omit `T: ?Leak` and `U: ?Leak`.
+impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'b mut T {}
 
 #[lang = "dispatch_from_dyn"]
-trait DispatchFromDyn<T: ?Leak> {}
+trait DispatchFromDyn<T: ?Leak>: ?Leak {}
 impl<'a, T: ?Sized + ?Leak + Unsize<U>, U: ?Sized + ?Leak> DispatchFromDyn<&'a U> for &'a T {}
+// Omit `T: ?Leak` and `U: ?Leak`.
+impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
 
 #[lang = "default_trait1"]
 auto trait Leak {}
@@ -47,25 +52,52 @@ struct NonLeakS;
 impl !Leak for NonLeakS {}
 struct LeakS;
 
-trait Trait {
-    fn leak_foo(&self) {}
-    fn maybe_leak_foo(&self) where Self: ?Leak {}
+fn bounds_check() {
+    trait LeakTr {}
+
+    trait MaybeLeakTr: ?Leak {}
+
+    impl MaybeLeakTr for NonLeakS {}
+
+    impl LeakTr for LeakS {}
+    impl MaybeLeakTr for LeakS {}
+
+    let _: &dyn LeakTr = &NonLeakS;
+    //~^ ERROR  the trait bound `NonLeakS: bounds_check::LeakTr` is not satisfied
+    let _: &dyn LeakTr = &LeakS;
+
+    let _: &(dyn LeakTr + ?Leak) = &NonLeakS;
+    let _: &(dyn LeakTr + ?Leak) = &LeakS;
+
+    let _: &dyn MaybeLeakTr = &NonLeakS;
+    let _: &dyn MaybeLeakTr = &LeakS;
 }
 
-impl Trait for NonLeakS {}
-impl Trait for LeakS {}
-
-fn main() {
-    let _: &dyn Trait = &NonLeakS;
-    //~^ ERROR the trait bound `NonLeakS: Leak` is not satisfied
-    let _: &dyn Trait = &LeakS;
-    let _: &(dyn Trait + ?Leak) = &LeakS;
-    let x: &(dyn Trait + ?Leak) = &NonLeakS;
-    x.leak_foo();
-    //~^ ERROR the trait bound `dyn Trait: Leak` is not satisfied
-    x.maybe_leak_foo();
+fn dyn_compat_check() {
+    trait DynCompatCheck1: ?Leak {
+        fn foo(&self) {}
+    }
+
+    trait DynCompatCheck2: ?Leak {
+        fn mut_foo(&mut self) {}
+    }
+
+    impl DynCompatCheck1 for NonLeakS {}
+    impl DynCompatCheck2 for NonLeakS {}
+
+    let _: &(dyn DynCompatCheck1 + ?Leak) = &NonLeakS;
+    // There is no `?Leak` bound on corresponding `DispatchFromDyn` impl.
+    let _: &dyn DynCompatCheck2 = &NonLeakS;
+    //~^ ERROR the trait `DynCompatCheck2` is not dyn compatible
+}
+
+fn args_check() {
+    trait LeakTr {}
+
     // Ensure that we validate the generic args of relaxed bounds in trait object types.
-    let _: dyn Trait + ?Leak<(), Undefined = ()>;
+    let _: dyn LeakTr + ?Leak<(), Undefined = ()>;
     //~^ ERROR trait takes 0 generic arguments but 1 generic argument was supplied
     //~| ERROR associated type `Undefined` not found for `Leak`
 }
+
+fn main() {}
diff --git a/tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.stderr b/tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.stderr
index b19c082a1b8..b96a2915c33 100644
--- a/tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.stderr
+++ b/tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.stderr
@@ -1,49 +1,57 @@
-error[E0277]: the trait bound `NonLeakS: Leak` is not satisfied
-  --> $DIR/maybe-bounds-in-dyn-traits.rs:59:25
+error[E0277]: the trait bound `NonLeakS: bounds_check::LeakTr` is not satisfied
+  --> $DIR/maybe-bounds-in-dyn-traits.rs:65:26
    |
-LL |     let _: &dyn Trait = &NonLeakS;
-   |                         ^^^^^^^^^ unsatisfied trait bound
+LL |     let _: &dyn LeakTr = &NonLeakS;
+   |                          ^^^^^^^^^ unsatisfied trait bound
    |
-help: the trait `Leak` is not implemented for `NonLeakS`
-  --> $DIR/maybe-bounds-in-dyn-traits.rs:46:1
+help: the trait `bounds_check::LeakTr` is not implemented for `NonLeakS`
+  --> $DIR/maybe-bounds-in-dyn-traits.rs:51:1
    |
 LL | struct NonLeakS;
    | ^^^^^^^^^^^^^^^
-   = note: required for the cast from `&NonLeakS` to `&dyn Trait + Leak`
+   = help: the trait `bounds_check::LeakTr` is implemented for `LeakS`
+   = note: required for the cast from `&NonLeakS` to `&dyn bounds_check::LeakTr + Leak`
 
-error[E0277]: the trait bound `dyn Trait: Leak` is not satisfied
-  --> $DIR/maybe-bounds-in-dyn-traits.rs:64:7
-   |
-LL |     x.leak_foo();
-   |       ^^^^^^^^ the trait `Leak` is not implemented for `dyn Trait`
-   |
-note: required by a bound in `Trait::leak_foo`
-  --> $DIR/maybe-bounds-in-dyn-traits.rs:51:5
-   |
-LL |     fn leak_foo(&self) {}
-   |     ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait::leak_foo`
+error[E0038]: the trait `DynCompatCheck2` is not dyn compatible
+  --> $DIR/maybe-bounds-in-dyn-traits.rs:90:17
+   |
+LL |         fn mut_foo(&mut self) {}
+   |                    --------- help: consider changing method `mut_foo`'s `self` parameter to be `&self`: `&Self`
+...
+LL |     let _: &dyn DynCompatCheck2 = &NonLeakS;
+   |                 ^^^^^^^^^^^^^^^ `DynCompatCheck2` is not dyn compatible
+   |
+note: for a trait to be dyn compatible it needs to allow building a vtable
+      for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
+  --> $DIR/maybe-bounds-in-dyn-traits.rs:82:20
+   |
+LL |     trait DynCompatCheck2: ?Leak {
+   |           --------------- this trait is not dyn compatible...
+LL |         fn mut_foo(&mut self) {}
+   |                    ^^^^^^^^^ ...because method `mut_foo`'s `self` parameter cannot be dispatched on
+   = help: only type `NonLeakS` implements `DynCompatCheck2`; consider using it directly instead.
 
 error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
-  --> $DIR/maybe-bounds-in-dyn-traits.rs:68:25
+  --> $DIR/maybe-bounds-in-dyn-traits.rs:98:26
    |
-LL |     let _: dyn Trait + ?Leak<(), Undefined = ()>;
-   |                         ^^^^-------------------- help: remove the unnecessary generics
-   |                         |
-   |                         expected 0 generic arguments
+LL |     let _: dyn LeakTr + ?Leak<(), Undefined = ()>;
+   |                          ^^^^-------------------- help: remove the unnecessary generics
+   |                          |
+   |                          expected 0 generic arguments
    |
 note: trait defined here, with 0 generic parameters
-  --> $DIR/maybe-bounds-in-dyn-traits.rs:44:12
+  --> $DIR/maybe-bounds-in-dyn-traits.rs:49:12
    |
 LL | auto trait Leak {}
    |            ^^^^
 
 error[E0220]: associated type `Undefined` not found for `Leak`
-  --> $DIR/maybe-bounds-in-dyn-traits.rs:68:34
+  --> $DIR/maybe-bounds-in-dyn-traits.rs:98:35
    |
-LL |     let _: dyn Trait + ?Leak<(), Undefined = ()>;
-   |                                  ^^^^^^^^^ associated type `Undefined` not found
+LL |     let _: dyn LeakTr + ?Leak<(), Undefined = ()>;
+   |                                   ^^^^^^^^^ associated type `Undefined` not found
 
 error: aborting due to 4 previous errors
 
-Some errors have detailed explanations: E0107, E0220, E0277.
-For more information about an error, try `rustc --explain E0107`.
+Some errors have detailed explanations: E0038, E0107, E0220, E0277.
+For more information about an error, try `rustc --explain E0038`.
diff --git a/tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.rs b/tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.rs
index b3801baaf70..820132b4e54 100644
--- a/tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.rs
+++ b/tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.rs
@@ -14,18 +14,22 @@
 #![no_std]
 #![no_core]
 
+#[lang = "copy"]
+pub trait Copy: ?Leak {}
+
 #[lang = "pointee_sized"]
-trait PointeeSized {}
+trait PointeeSized: ?Leak {}
 
 #[lang = "meta_sized"]
-trait MetaSized: PointeeSized {}
+trait MetaSized: PointeeSized + ?Leak {}
 
 #[lang = "sized"]
-trait Sized: MetaSized {}
+trait Sized: MetaSized + ?Leak {}
 
 #[lang = "legacy_receiver"]
-trait LegacyReceiver {}
+trait LegacyReceiver: ?Leak {}
 impl<T: ?Sized + ?Leak> LegacyReceiver for &T {}
+// Omit `T: ?Leak`.
 impl<T: ?Sized> LegacyReceiver for &mut T {}
 
 #[lang = "default_trait1"]
@@ -43,78 +47,38 @@ mod supertraits {
 
     impl MaybeLeakT1 for NonLeakS {}
     impl MaybeLeakT2 for NonLeakS {}
+
+    trait LeakT {}
+    impl LeakT for NonLeakS {}
+    //~^ ERROR the trait bound `NonLeakS: Leak` is not satisfied
 }
 
-mod maybe_self_assoc_type {
+mod assoc_type_maybe_bounds {
     use crate::*;
 
-    trait TestBase1<T: ?Sized> {}
-    trait TestBase2<T: ?Leak + ?Sized> {}
-
-    trait Test1<T> {
-        type MaybeLeakSelf: TestBase1<Self> where Self: ?Leak;
-        //~^ ERROR the trait bound `Self: Leak` is not satisfied
-        type LeakSelf: TestBase1<Self>;
-    }
-
-    trait Test2<T> {
-        type MaybeLeakSelf: TestBase2<Self> where Self: ?Leak;
-        type LeakSelf: TestBase2<Self>;
-    }
-
-    trait Test3 {
+    trait Test1 {
         type Leak1 = LeakS;
         type Leak2 = NonLeakS;
         //~^ ERROR the trait bound `NonLeakS: Leak` is not satisfied
     }
 
-    trait Test4 {
+    trait Test2 {
         type MaybeLeak1: ?Leak = LeakS;
         type MaybeLeak2: ?Leak = NonLeakS;
     }
-
-    trait Test5: ?Leak {
-        // ok, because assoc types have implicit where Self: Leak
-        type MaybeLeakSelf1: TestBase1<Self>;
-        type MaybeLeakSelf2: TestBase2<Self>;
-    }
-}
-
-mod maybe_self_assoc_const {
-    use crate::*;
-
-    const fn size_of<T: ?Sized>() -> usize {
-        0
-    }
-
-    trait Trait {
-        const CLeak: usize = size_of::<Self>();
-        const CNonLeak: usize = size_of::<Self>() where Self: ?Leak;
-        //~^ ERROR the trait bound `Self: Leak` is not satisfied
-    }
 }
 
 mod methods {
     use crate::*;
 
-    trait Trait {
-        fn leak_foo(&self) {}
-        fn maybe_leak_foo(&self) where Self: ?Leak {}
-        fn mut_leak_foo(&mut self) {}
-        // there is no relax bound on corresponding Receiver impl
-        fn mut_maybe_leak_foo(&mut self) where Self: ?Leak {}
-        //~^ ERROR `&mut Self` cannot be used as the type of `self` without the `arbitrary_self_types`
+    trait ReceiveCheck1: ?Leak {
+        fn foo(&self) {}
     }
 
-    impl Trait for NonLeakS {}
-    impl Trait for LeakS {}
-
-    fn foo() {
-        LeakS.leak_foo();
-        LeakS.maybe_leak_foo();
-        NonLeakS.leak_foo();
-        //~^ ERROR the trait bound `NonLeakS: Leak` is not satisfied
-        NonLeakS.maybe_leak_foo();
+    trait ReceiveCheck2: ?Leak {
+        // There is no `?Leak` bound on corresponding `LegacyReceiver` impl.
+        fn mut_foo(&mut self) {}
+        //~^ ERROR `&mut Self` cannot be used as the type of `self` without the `arbitrary_self_types`
     }
 }
 
diff --git a/tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.stderr b/tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.stderr
index 372bf817600..95c77b1756c 100644
--- a/tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.stderr
+++ b/tests/ui/traits/default_auto_traits/maybe-bounds-in-traits.stderr
@@ -1,81 +1,49 @@
 error[E0277]: the trait bound `NonLeakS: Leak` is not satisfied
-  --> $DIR/maybe-bounds-in-traits.rs:67:22
+  --> $DIR/maybe-bounds-in-traits.rs:52:20
    |
-LL |         type Leak2 = NonLeakS;
-   |                      ^^^^^^^^ unsatisfied trait bound
+LL |     impl LeakT for NonLeakS {}
+   |                    ^^^^^^^^ unsatisfied trait bound
    |
 help: the trait `Leak` is not implemented for `NonLeakS`
-  --> $DIR/maybe-bounds-in-traits.rs:34:1
+  --> $DIR/maybe-bounds-in-traits.rs:38:1
    |
 LL | struct NonLeakS;
    | ^^^^^^^^^^^^^^^
-note: required by a bound in `Test3::Leak2`
-  --> $DIR/maybe-bounds-in-traits.rs:67:9
+note: required by a bound in `LeakT`
+  --> $DIR/maybe-bounds-in-traits.rs:51:5
    |
-LL |         type Leak2 = NonLeakS;
-   |         ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Test3::Leak2`
+LL |     trait LeakT {}
+   |     ^^^^^^^^^^^^^^ required by this bound in `LeakT`
 
-error[E0277]: the trait bound `Self: Leak` is not satisfied
-  --> $DIR/maybe-bounds-in-traits.rs:55:29
+error[E0277]: the trait bound `NonLeakS: Leak` is not satisfied
+  --> $DIR/maybe-bounds-in-traits.rs:61:22
    |
-LL |         type MaybeLeakSelf: TestBase1<Self> where Self: ?Leak;
-   |                             ^^^^^^^^^^^^^^^ the trait `Leak` is not implemented for `Self`
+LL |         type Leak2 = NonLeakS;
+   |                      ^^^^^^^^ unsatisfied trait bound
    |
-note: required by a bound in `TestBase1`
-  --> $DIR/maybe-bounds-in-traits.rs:51:21
+help: the trait `Leak` is not implemented for `NonLeakS`
+  --> $DIR/maybe-bounds-in-traits.rs:38:1
    |
-LL |     trait TestBase1<T: ?Sized> {}
-   |                     ^ required by this bound in `TestBase1`
-help: consider further restricting `Self`
+LL | struct NonLeakS;
+   | ^^^^^^^^^^^^^^^
+note: required by a bound in `Test1::Leak2`
+  --> $DIR/maybe-bounds-in-traits.rs:61:9
    |
-LL |     trait Test1<T>: Leak {
-   |                   ++++++
+LL |         type Leak2 = NonLeakS;
+   |         ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Test1::Leak2`
 
 error[E0658]: `&mut Self` cannot be used as the type of `self` without the `arbitrary_self_types` feature
-  --> $DIR/maybe-bounds-in-traits.rs:105:31
+  --> $DIR/maybe-bounds-in-traits.rs:80:20
    |
-LL |         fn mut_maybe_leak_foo(&mut self) where Self: ?Leak {}
-   |                               ^^^^^^^^^
+LL |         fn mut_foo(&mut self) {}
+   |                    ^^^^^^^^^
    |
    = note: see issue #44874 <https://github.com/rust-lang/rust/issues/44874> for more information
    = help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
    = help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
 
-error[E0277]: the trait bound `Self: Leak` is not satisfied
-  --> $DIR/maybe-bounds-in-traits.rs:92:43
-   |
-LL |         const CNonLeak: usize = size_of::<Self>() where Self: ?Leak;
-   |                                           ^^^^ the trait `Leak` is not implemented for `Self`
-   |
-note: required by a bound in `size_of`
-  --> $DIR/maybe-bounds-in-traits.rs:86:22
-   |
-LL |     const fn size_of<T: ?Sized>() -> usize {
-   |                      ^ required by this bound in `size_of`
-help: consider further restricting `Self`
-   |
-LL |     trait Trait: Leak {
-   |                ++++++
-
-error[E0277]: the trait bound `NonLeakS: Leak` is not satisfied
-  --> $DIR/maybe-bounds-in-traits.rs:115:18
-   |
-LL |         NonLeakS.leak_foo();
-   |                  ^^^^^^^^ unsatisfied trait bound
-   |
-help: the trait `Leak` is not implemented for `NonLeakS`
-  --> $DIR/maybe-bounds-in-traits.rs:34:1
-   |
-LL | struct NonLeakS;
-   | ^^^^^^^^^^^^^^^
-note: required by a bound in `methods::Trait::leak_foo`
-  --> $DIR/maybe-bounds-in-traits.rs:101:9
-   |
-LL |         fn leak_foo(&self) {}
-   |         ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait::leak_foo`
-
-error: aborting due to 5 previous errors
+error: aborting due to 3 previous errors
 
 Some errors have detailed explanations: E0277, E0658.
 For more information about an error, try `rustc --explain E0277`.