about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_analysis/src/collect/predicates_of.rs6
-rw-r--r--compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs144
-rw-r--r--compiler/rustc_lint/src/multiple_supertrait_upcastable.rs3
-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
8 files changed, 155 insertions, 333 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
index b59dc4bd132..126ffabd448 100644
--- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
+++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
@@ -174,12 +174,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
         }
     };
 
-    if let Node::TraitItem(item) = node {
-        let mut bounds = Vec::new();
-        icx.lowerer().add_default_trait_item_bounds(item, &mut bounds);
-        predicates.extend(bounds);
-    }
-
     let generics = tcx.generics_of(def_id);
 
     // Below we'll consider the bounds on the type parameters (including `Self`)
diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
index d14aef8ace4..99dc8e6e522 100644
--- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
+++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
@@ -1,12 +1,13 @@
+use std::assert_matches::assert_matches;
 use std::ops::ControlFlow;
 
 use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
 use rustc_errors::codes::*;
 use rustc_errors::struct_span_code_err;
 use rustc_hir as hir;
+use rustc_hir::PolyTraitRef;
 use rustc_hir::def::{DefKind, Res};
 use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
-use rustc_hir::{AmbigArg, PolyTraitRef};
 use rustc_middle::bug;
 use rustc_middle::ty::{
     self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
@@ -230,122 +231,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
         }
     }
 
-    /// Checks whether `Self: DefaultAutoTrait` bounds should be added on trait super bounds
-    /// or associated items.
-    ///
-    /// To keep backward compatibility with existing code, `experimental_default_bounds` bounds
-    /// should be added everywhere, including super bounds. However this causes a huge performance
-    /// costs. For optimization purposes instead of adding default supertraits, bounds
-    /// are added to the associated items:
-    ///
-    /// ```ignore(illustrative)
-    /// // Default bounds are generated in the following way:
-    /// trait Trait {
-    ///     fn foo(&self) where Self: Leak {}
-    /// }
-    ///
-    /// // instead of this:
-    /// trait Trait: Leak {
-    ///     fn foo(&self) {}
-    /// }
-    /// ```
-    /// It is not always possible to do this because of backward compatibility:
-    ///
-    /// ```ignore(illustrative)
-    /// pub trait Trait<Rhs = Self> {}
-    /// pub trait Trait1 : Trait {}
-    /// //~^ ERROR: `Rhs` requires `DefaultAutoTrait`, but `Self` is not `DefaultAutoTrait`
-    /// ```
-    ///
-    /// or:
-    ///
-    /// ```ignore(illustrative)
-    /// trait Trait {
-    ///     type Type where Self: Sized;
-    /// }
-    /// trait Trait2<T> : Trait<Type = T> {}
-    /// //~^ ERROR: `DefaultAutoTrait` required for `Trait2`, by implicit  `Self: DefaultAutoTrait` in `Trait::Type`
-    /// ```
-    ///
-    /// Therefore, `experimental_default_bounds` are still being added to supertraits if
-    /// the `SelfTyParam` or `AssocItemConstraint` were found in a trait header.
-    fn requires_default_supertraits(
-        &self,
-        hir_bounds: &'tcx [hir::GenericBound<'tcx>],
-        hir_generics: &'tcx hir::Generics<'tcx>,
-    ) -> bool {
-        struct TraitInfoCollector;
-
-        impl<'tcx> hir::intravisit::Visitor<'tcx> for TraitInfoCollector {
-            type Result = ControlFlow<()>;
-
-            fn visit_assoc_item_constraint(
-                &mut self,
-                _constraint: &'tcx hir::AssocItemConstraint<'tcx>,
-            ) -> Self::Result {
-                ControlFlow::Break(())
-            }
-
-            fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx, AmbigArg>) -> Self::Result {
-                if matches!(
-                    &t.kind,
-                    hir::TyKind::Path(hir::QPath::Resolved(
-                        _,
-                        hir::Path { res: hir::def::Res::SelfTyParam { .. }, .. },
-                    ))
-                ) {
-                    return ControlFlow::Break(());
-                }
-                hir::intravisit::walk_ty(self, t)
-            }
-        }
-
-        let mut found = false;
-        for bound in hir_bounds {
-            found |= hir::intravisit::walk_param_bound(&mut TraitInfoCollector, bound).is_break();
-        }
-        found |= hir::intravisit::walk_generics(&mut TraitInfoCollector, hir_generics).is_break();
-        found
-    }
-
-    /// Implicitly add `Self: DefaultAutoTrait` clauses on trait associated items if
-    /// they are not added as super trait bounds to the trait itself. See
-    /// `requires_default_supertraits` for more information.
-    pub(crate) fn add_default_trait_item_bounds(
-        &self,
-        trait_item: &hir::TraitItem<'tcx>,
-        bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
-    ) {
-        let tcx = self.tcx();
-        if !tcx.sess.opts.unstable_opts.experimental_default_bounds {
-            return;
-        }
-
-        let parent = tcx.local_parent(trait_item.hir_id().owner.def_id);
-        let hir::Node::Item(parent_trait) = tcx.hir_node_by_def_id(parent) else {
-            unreachable!();
-        };
-
-        let (trait_generics, trait_bounds) = match parent_trait.kind {
-            hir::ItemKind::Trait(_, _, _, _, generics, supertraits, _) => (generics, supertraits),
-            hir::ItemKind::TraitAlias(_, generics, supertraits) => (generics, supertraits),
-            _ => unreachable!(),
-        };
-
-        if !self.requires_default_supertraits(trait_bounds, trait_generics) {
-            let self_ty_where_predicates = (parent, trait_item.generics.predicates);
-            self.add_default_traits(
-                bounds,
-                tcx.types.self_param,
-                &[],
-                Some(self_ty_where_predicates),
-                trait_item.span,
-            );
-        }
-    }
-
-    /// Lazily sets `experimental_default_bounds` to true on trait super bounds.
-    /// See `requires_default_supertraits` for more information.
+    /// Adds `experimental_default_bounds` bounds to the supertrait bounds.
     pub(crate) fn add_default_super_traits(
         &self,
         trait_def_id: LocalDefId,
@@ -354,21 +240,21 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
         hir_generics: &'tcx hir::Generics<'tcx>,
         span: Span,
     ) {
-        if !self.tcx().sess.opts.unstable_opts.experimental_default_bounds {
+        assert_matches!(self.tcx().def_kind(trait_def_id), DefKind::Trait | DefKind::TraitAlias);
+
+        // Supertraits for auto trait are unsound according to the unstable book:
+        // https://doc.rust-lang.org/beta/unstable-book/language-features/auto-traits.html#supertraits
+        if self.tcx().trait_is_auto(trait_def_id.to_def_id()) {
             return;
         }
 
-        assert!(matches!(self.tcx().def_kind(trait_def_id), DefKind::Trait | DefKind::TraitAlias));
-        if self.requires_default_supertraits(hir_bounds, hir_generics) {
-            let self_ty_where_predicates = (trait_def_id, hir_generics.predicates);
-            self.add_default_traits(
-                bounds,
-                self.tcx().types.self_param,
-                hir_bounds,
-                Some(self_ty_where_predicates),
-                span,
-            );
-        }
+        self.add_default_traits(
+            bounds,
+            self.tcx().types.self_param,
+            hir_bounds,
+            Some((trait_def_id, hir_generics.predicates)),
+            span,
+        );
     }
 
     pub(crate) fn add_default_traits(
diff --git a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs
index 5513c703f1d..93f067d0983 100644
--- a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs
+++ b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs
@@ -47,7 +47,8 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable {
                 .explicit_super_predicates_of(def_id)
                 .iter_identity_copied()
                 .filter_map(|(pred, _)| pred.as_trait_clause())
-                .filter(|pred| !cx.tcx.is_lang_item(pred.def_id(), hir::LangItem::MetaSized));
+                .filter(|pred| !cx.tcx.is_lang_item(pred.def_id(), hir::LangItem::MetaSized))
+                .filter(|pred| !cx.tcx.is_default_trait(pred.def_id()));
             if direct_super_traits_iter.count() > 1 {
                 cx.emit_span_lint(
                     MULTIPLE_SUPERTRAIT_UPCASTABLE,
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`.