diff --git a/compiler/rustc_codegen_cranelift/example/issue-72793.rs b/compiler/rustc_codegen_cranelift/example/issue-72793.rs
index 166b006004385..2e08fbca8ef27 100644
--- a/compiler/rustc_codegen_cranelift/example/issue-72793.rs
+++ b/compiler/rustc_codegen_cranelift/example/issue-72793.rs
@@ -2,20 +2,23 @@
 
 #![feature(type_alias_impl_trait)]
 
-trait T {
-    type Item;
-}
+mod helper {
+    pub trait T {
+        type Item;
+    }
 
-type Alias<'a> = impl T<Item = &'a ()>;
+    pub type Alias<'a> = impl T<Item = &'a ()>;
 
-struct S;
-impl<'a> T for &'a S {
-    type Item = &'a ();
-}
+    struct S;
+    impl<'a> T for &'a S {
+        type Item = &'a ();
+    }
 
-fn filter_positive<'a>() -> Alias<'a> {
-    &S
+    pub fn filter_positive<'a>() -> Alias<'a> {
+        &S
+    }
 }
+use helper::*;
 
 fn with_positive(fun: impl Fn(Alias<'_>)) {
     fun(filter_positive());
diff --git a/compiler/rustc_data_structures/src/obligation_forest/mod.rs b/compiler/rustc_data_structures/src/obligation_forest/mod.rs
index d477b86da74e8..3883b0736db07 100644
--- a/compiler/rustc_data_structures/src/obligation_forest/mod.rs
+++ b/compiler/rustc_data_structures/src/obligation_forest/mod.rs
@@ -146,8 +146,6 @@ pub enum ProcessResult<O, E> {
 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
 struct ObligationTreeId(usize);
 
-type ObligationTreeIdGenerator = impl Iterator<Item = ObligationTreeId>;
-
 pub struct ObligationForest<O: ForestObligation> {
     /// The list of obligations. In between calls to [Self::process_obligations],
     /// this list only contains nodes in the `Pending` or `Waiting` state.
@@ -310,18 +308,25 @@ pub struct Error<O, E> {
     pub backtrace: Vec<O>,
 }
 
-impl<O: ForestObligation> ObligationForest<O> {
-    pub fn new() -> ObligationForest<O> {
-        ObligationForest {
-            nodes: vec![],
-            done_cache: Default::default(),
-            active_cache: Default::default(),
-            reused_node_vec: vec![],
-            obligation_tree_id_generator: (0..).map(ObligationTreeId),
-            error_cache: Default::default(),
+mod helper {
+    use super::*;
+    pub type ObligationTreeIdGenerator = impl Iterator<Item = ObligationTreeId>;
+    impl<O: ForestObligation> ObligationForest<O> {
+        pub fn new() -> ObligationForest<O> {
+            ObligationForest {
+                nodes: vec![],
+                done_cache: Default::default(),
+                active_cache: Default::default(),
+                reused_node_vec: vec![],
+                obligation_tree_id_generator: (0..).map(ObligationTreeId),
+                error_cache: Default::default(),
+            }
         }
     }
+}
+use helper::*;
 
+impl<O: ForestObligation> ObligationForest<O> {
     /// Returns the total number of nodes in the forest that have not
     /// yet been fully resolved.
     pub fn len(&self) -> usize {
diff --git a/compiler/rustc_error_codes/src/error_codes/E0792.md b/compiler/rustc_error_codes/src/error_codes/E0792.md
index bad2b5abfe4d7..5e3dcc4aa7277 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0792.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0792.md
@@ -39,6 +39,8 @@ type Foo<T> = impl std::fmt::Debug;
 fn foo<U>() -> Foo<U> {
     5u32
 }
+
+fn main() {}
 ```
 
 This means that no matter the generic parameter to `foo`,
@@ -57,4 +59,6 @@ type Foo<T: Debug> = impl Debug;
 fn foo<U: Debug>() -> Foo<U> {
     Vec::<U>::new()
 }
+
+fn main() {}
 ```
diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl
index 67959d9dfede0..f697d331aa612 100644
--- a/compiler/rustc_hir_analysis/messages.ftl
+++ b/compiler/rustc_hir_analysis/messages.ftl
@@ -460,6 +460,10 @@ hir_analysis_static_specialize = cannot specialize on `'static` lifetime
 hir_analysis_tait_forward_compat = item constrains opaque type that is not in its signature
     .note = this item must mention the opaque type in its signature in order to be able to register hidden types
 
+hir_analysis_tait_forward_compat2 = item does not constrain `{$opaque_type}`, but has it in its signature
+    .note = consider moving the opaque type's declaration and defining uses into a separate module
+    .opaque = this opaque type is in the signature
+
 hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[target_feature]`
 
 hir_analysis_too_large_static = extern static is too large for the current architecture
diff --git a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
index 1bec8c496ad1e..2b2f07001d2f4 100644
--- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
+++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
@@ -8,7 +8,7 @@ use rustc_middle::hir::nested_filter;
 use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
 use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
 
-use crate::errors::{TaitForwardCompat, TypeOf, UnconstrainedOpaqueType};
+use crate::errors::{TaitForwardCompat, TaitForwardCompat2, TypeOf, UnconstrainedOpaqueType};
 
 pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
     let mut res = Ok(());
@@ -229,13 +229,14 @@ impl TaitConstraintLocator<'_> {
             return;
         }
 
+        let opaque_types_defined_by = self.tcx.opaque_types_defined_by(item_def_id);
+
         let mut constrained = false;
         for (&opaque_type_key, &hidden_type) in &tables.concrete_opaque_types {
             if opaque_type_key.def_id != self.def_id {
                 continue;
             }
             constrained = true;
-            let opaque_types_defined_by = self.tcx.opaque_types_defined_by(item_def_id);
 
             if !opaque_types_defined_by.contains(&self.def_id) {
                 self.tcx.dcx().emit_err(TaitForwardCompat {
@@ -259,6 +260,16 @@ impl TaitConstraintLocator<'_> {
 
         if !constrained {
             debug!("no constraints in typeck results");
+            if opaque_types_defined_by.contains(&self.def_id) {
+                self.tcx.dcx().emit_err(TaitForwardCompat2 {
+                    span: self
+                        .tcx
+                        .def_ident_span(item_def_id)
+                        .unwrap_or_else(|| self.tcx.def_span(item_def_id)),
+                    opaque_type_span: self.tcx.def_span(self.def_id),
+                    opaque_type: self.tcx.def_path_str(self.def_id),
+                });
+            }
             return;
         };
 
diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs
index 8a9d4cd4ac701..50e0e37229523 100644
--- a/compiler/rustc_hir_analysis/src/errors.rs
+++ b/compiler/rustc_hir_analysis/src/errors.rs
@@ -390,6 +390,17 @@ pub struct TaitForwardCompat {
     pub item_span: Span,
 }
 
+#[derive(Diagnostic)]
+#[diag(hir_analysis_tait_forward_compat2)]
+#[note]
+pub struct TaitForwardCompat2 {
+    #[primary_span]
+    pub span: Span,
+    #[note(hir_analysis_opaque)]
+    pub opaque_type_span: Span,
+    pub opaque_type: String,
+}
+
 pub struct MissingTypeParams {
     pub span: Span,
     pub def_span: Span,
diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
index 6098da990c043..7aef6321eeb5d 100644
--- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
+++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
@@ -46,6 +46,8 @@ declare_lint! {
     /// fn test() -> impl Trait<Assoc = Tait> {
     ///     42
     /// }
+    ///
+    /// fn main() {}
     /// ```
     ///
     /// {{produces}}
diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs
index f95afb199f7f9..c8c12e205e118 100644
--- a/compiler/rustc_middle/src/mir/terminator.rs
+++ b/compiler/rustc_middle/src/mir/terminator.rs
@@ -377,9 +377,6 @@ pub struct Terminator<'tcx> {
     pub kind: TerminatorKind<'tcx>,
 }
 
-pub type Successors<'a> = impl DoubleEndedIterator<Item = BasicBlock> + 'a;
-pub type SuccessorsMut<'a> = impl DoubleEndedIterator<Item = &'a mut BasicBlock> + 'a;
-
 impl<'tcx> Terminator<'tcx> {
     #[inline]
     pub fn successors(&self) -> Successors<'_> {
@@ -407,81 +404,95 @@ impl<'tcx> TerminatorKind<'tcx> {
     pub fn if_(cond: Operand<'tcx>, t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> {
         TerminatorKind::SwitchInt { discr: cond, targets: SwitchTargets::static_if(0, f, t) }
     }
+}
 
-    #[inline]
-    pub fn successors(&self) -> Successors<'_> {
-        use self::TerminatorKind::*;
-        match *self {
-            Call { target: Some(ref t), unwind: UnwindAction::Cleanup(u), .. }
-            | Yield { resume: ref t, drop: Some(u), .. }
-            | Drop { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
-            | Assert { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
-            | FalseUnwind { real_target: ref t, unwind: UnwindAction::Cleanup(u) } => {
-                slice::from_ref(t).into_iter().copied().chain(Some(u))
-            }
-            Goto { target: ref t }
-            | Call { target: None, unwind: UnwindAction::Cleanup(ref t), .. }
-            | Call { target: Some(ref t), unwind: _, .. }
-            | Yield { resume: ref t, drop: None, .. }
-            | Drop { target: ref t, unwind: _, .. }
-            | Assert { target: ref t, unwind: _, .. }
-            | FalseUnwind { real_target: ref t, unwind: _ } => {
-                slice::from_ref(t).into_iter().copied().chain(None)
-            }
-            UnwindResume
-            | UnwindTerminate(_)
-            | CoroutineDrop
-            | Return
-            | Unreachable
-            | Call { target: None, unwind: _, .. } => (&[]).into_iter().copied().chain(None),
-            InlineAsm { ref targets, unwind: UnwindAction::Cleanup(u), .. } => {
-                targets.iter().copied().chain(Some(u))
-            }
-            InlineAsm { ref targets, unwind: _, .. } => targets.iter().copied().chain(None),
-            SwitchInt { ref targets, .. } => targets.targets.iter().copied().chain(None),
-            FalseEdge { ref real_target, imaginary_target } => {
-                slice::from_ref(real_target).into_iter().copied().chain(Some(imaginary_target))
+pub use helper::*;
+
+mod helper {
+    use super::*;
+    pub type Successors<'a> = impl DoubleEndedIterator<Item = BasicBlock> + 'a;
+    pub type SuccessorsMut<'a> = impl DoubleEndedIterator<Item = &'a mut BasicBlock> + 'a;
+    impl<'tcx> TerminatorKind<'tcx> {
+        #[inline]
+        pub fn successors(&self) -> Successors<'_> {
+            use self::TerminatorKind::*;
+            match *self {
+                Call { target: Some(ref t), unwind: UnwindAction::Cleanup(u), .. }
+                | Yield { resume: ref t, drop: Some(u), .. }
+                | Drop { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
+                | Assert { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
+                | FalseUnwind { real_target: ref t, unwind: UnwindAction::Cleanup(u) } => {
+                    slice::from_ref(t).into_iter().copied().chain(Some(u))
+                }
+                Goto { target: ref t }
+                | Call { target: None, unwind: UnwindAction::Cleanup(ref t), .. }
+                | Call { target: Some(ref t), unwind: _, .. }
+                | Yield { resume: ref t, drop: None, .. }
+                | Drop { target: ref t, unwind: _, .. }
+                | Assert { target: ref t, unwind: _, .. }
+                | FalseUnwind { real_target: ref t, unwind: _ } => {
+                    slice::from_ref(t).into_iter().copied().chain(None)
+                }
+                UnwindResume
+                | UnwindTerminate(_)
+                | CoroutineDrop
+                | Return
+                | Unreachable
+                | Call { target: None, unwind: _, .. } => (&[]).into_iter().copied().chain(None),
+                InlineAsm { ref targets, unwind: UnwindAction::Cleanup(u), .. } => {
+                    targets.iter().copied().chain(Some(u))
+                }
+                InlineAsm { ref targets, unwind: _, .. } => targets.iter().copied().chain(None),
+                SwitchInt { ref targets, .. } => targets.targets.iter().copied().chain(None),
+                FalseEdge { ref real_target, imaginary_target } => {
+                    slice::from_ref(real_target).into_iter().copied().chain(Some(imaginary_target))
+                }
             }
         }
-    }
 
-    #[inline]
-    pub fn successors_mut(&mut self) -> SuccessorsMut<'_> {
-        use self::TerminatorKind::*;
-        match *self {
-            Call { target: Some(ref mut t), unwind: UnwindAction::Cleanup(ref mut u), .. }
-            | Yield { resume: ref mut t, drop: Some(ref mut u), .. }
-            | Drop { target: ref mut t, unwind: UnwindAction::Cleanup(ref mut u), .. }
-            | Assert { target: ref mut t, unwind: UnwindAction::Cleanup(ref mut u), .. }
-            | FalseUnwind { real_target: ref mut t, unwind: UnwindAction::Cleanup(ref mut u) } => {
-                slice::from_mut(t).into_iter().chain(Some(u))
-            }
-            Goto { target: ref mut t }
-            | Call { target: None, unwind: UnwindAction::Cleanup(ref mut t), .. }
-            | Call { target: Some(ref mut t), unwind: _, .. }
-            | Yield { resume: ref mut t, drop: None, .. }
-            | Drop { target: ref mut t, unwind: _, .. }
-            | Assert { target: ref mut t, unwind: _, .. }
-            | FalseUnwind { real_target: ref mut t, unwind: _ } => {
-                slice::from_mut(t).into_iter().chain(None)
-            }
-            UnwindResume
-            | UnwindTerminate(_)
-            | CoroutineDrop
-            | Return
-            | Unreachable
-            | Call { target: None, unwind: _, .. } => (&mut []).into_iter().chain(None),
-            InlineAsm { ref mut targets, unwind: UnwindAction::Cleanup(ref mut u), .. } => {
-                targets.iter_mut().chain(Some(u))
-            }
-            InlineAsm { ref mut targets, unwind: _, .. } => targets.iter_mut().chain(None),
-            SwitchInt { ref mut targets, .. } => targets.targets.iter_mut().chain(None),
-            FalseEdge { ref mut real_target, ref mut imaginary_target } => {
-                slice::from_mut(real_target).into_iter().chain(Some(imaginary_target))
+        #[inline]
+        pub fn successors_mut(&mut self) -> SuccessorsMut<'_> {
+            use self::TerminatorKind::*;
+            match *self {
+                Call {
+                    target: Some(ref mut t), unwind: UnwindAction::Cleanup(ref mut u), ..
+                }
+                | Yield { resume: ref mut t, drop: Some(ref mut u), .. }
+                | Drop { target: ref mut t, unwind: UnwindAction::Cleanup(ref mut u), .. }
+                | Assert { target: ref mut t, unwind: UnwindAction::Cleanup(ref mut u), .. }
+                | FalseUnwind {
+                    real_target: ref mut t,
+                    unwind: UnwindAction::Cleanup(ref mut u),
+                } => slice::from_mut(t).into_iter().chain(Some(u)),
+                Goto { target: ref mut t }
+                | Call { target: None, unwind: UnwindAction::Cleanup(ref mut t), .. }
+                | Call { target: Some(ref mut t), unwind: _, .. }
+                | Yield { resume: ref mut t, drop: None, .. }
+                | Drop { target: ref mut t, unwind: _, .. }
+                | Assert { target: ref mut t, unwind: _, .. }
+                | FalseUnwind { real_target: ref mut t, unwind: _ } => {
+                    slice::from_mut(t).into_iter().chain(None)
+                }
+                UnwindResume
+                | UnwindTerminate(_)
+                | CoroutineDrop
+                | Return
+                | Unreachable
+                | Call { target: None, unwind: _, .. } => (&mut []).into_iter().chain(None),
+                InlineAsm { ref mut targets, unwind: UnwindAction::Cleanup(ref mut u), .. } => {
+                    targets.iter_mut().chain(Some(u))
+                }
+                InlineAsm { ref mut targets, unwind: _, .. } => targets.iter_mut().chain(None),
+                SwitchInt { ref mut targets, .. } => targets.targets.iter_mut().chain(None),
+                FalseEdge { ref mut real_target, ref mut imaginary_target } => {
+                    slice::from_mut(real_target).into_iter().chain(Some(imaginary_target))
+                }
             }
         }
     }
+}
 
+impl<'tcx> TerminatorKind<'tcx> {
     #[inline]
     pub fn unwind(&self) -> Option<&UnwindAction> {
         match *self {
diff --git a/library/core/src/internal_macros.rs b/library/core/src/internal_macros.rs
index d3a4d6aff2d8b..bf53b2245ac59 100644
--- a/library/core/src/internal_macros.rs
+++ b/library/core/src/internal_macros.rs
@@ -80,6 +80,47 @@ macro_rules! forward_ref_op_assign {
     }
 }
 
+/// Create a zero-size type similar to a closure type, but named.
+macro_rules! impl_fn_for_zst {
+    ($(
+        $( #[$attr: meta] )*
+        struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn =
+            |$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty
+            $body: block;
+    )+) => {
+        $(
+            $( #[$attr] )*
+            struct $Name;
+
+            impl $( <$( $lifetime ),+> )? Fn<($( $ArgTy, )*)> for $Name {
+                #[inline]
+                extern "rust-call" fn call(&self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
+                    $body
+                }
+            }
+
+            impl $( <$( $lifetime ),+> )? FnMut<($( $ArgTy, )*)> for $Name {
+                #[inline]
+                extern "rust-call" fn call_mut(
+                    &mut self,
+                    ($( $arg, )*): ($( $ArgTy, )*)
+                ) -> $ReturnTy {
+                    Fn::call(&*self, ($( $arg, )*))
+                }
+            }
+
+            impl $( <$( $lifetime ),+> )? FnOnce<($( $ArgTy, )*)> for $Name {
+                type Output = $ReturnTy;
+
+                #[inline]
+                extern "rust-call" fn call_once(self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
+                    Fn::call(&self, ($( $arg, )*))
+                }
+            }
+        )+
+    }
+}
+
 /// A macro for defining `#[cfg]` if-else statements.
 ///
 /// `cfg_if` is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index 89642d6226a24..ef28bc99c4fc8 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -255,7 +255,6 @@
 #![feature(trait_alias)]
 #![feature(transparent_unions)]
 #![feature(try_blocks)]
-#![feature(type_alias_impl_trait)]
 #![feature(unboxed_closures)]
 #![feature(unsized_fn_params)]
 #![feature(with_negative_coherence)]
diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs
index 19c91ba2eb988..8ad045275adec 100644
--- a/library/core/src/slice/ascii.rs
+++ b/library/core/src/slice/ascii.rs
@@ -108,7 +108,7 @@ impl [u8] {
                   without modifying the original"]
     #[stable(feature = "inherent_ascii_escape", since = "1.60.0")]
     pub fn escape_ascii(&self) -> EscapeAscii<'_> {
-        EscapeAscii { inner: self.iter().flat_map(|byte| byte.escape_ascii()) }
+        EscapeAscii { inner: self.iter().flat_map(EscapeByte) }
     }
 
     /// Returns a byte slice with leading ASCII whitespace bytes removed.
@@ -190,7 +190,12 @@ impl [u8] {
     }
 }
 
-type EscapeByte = impl (Fn(&u8) -> ascii::EscapeDefault) + Copy;
+impl_fn_for_zst! {
+    #[derive(Clone)]
+    struct EscapeByte impl Fn = |byte: &u8| -> ascii::EscapeDefault {
+        ascii::escape_default(*byte)
+    };
+}
 
 /// An iterator over the escaped version of a byte slice.
 ///
diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs
index d61f04102e5e5..19627f28e64f8 100644
--- a/library/core/src/str/iter.rs
+++ b/library/core/src/str/iter.rs
@@ -1274,10 +1274,8 @@ pub struct SplitWhitespace<'a> {
 #[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
 #[derive(Clone, Debug)]
 pub struct SplitAsciiWhitespace<'a> {
-    pub(super) inner: Map<
-        Filter<SliceSplit<'a, u8, IsAsciiWhitespace>, BytesIsNotEmpty<'a>>,
-        UnsafeBytesToStr<'a>,
-    >,
+    pub(super) inner:
+        Map<Filter<SliceSplit<'a, u8, IsAsciiWhitespace>, BytesIsNotEmpty>, UnsafeBytesToStr>,
 }
 
 /// An iterator over the substrings of a string,
diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs
index edda4d1b68703..669cdc92e3586 100644
--- a/library/core/src/str/mod.rs
+++ b/library/core/src/str/mod.rs
@@ -983,7 +983,7 @@ impl str {
     #[cfg_attr(not(test), rustc_diagnostic_item = "str_split_whitespace")]
     #[inline]
     pub fn split_whitespace(&self) -> SplitWhitespace<'_> {
-        SplitWhitespace { inner: self.split(char::is_whitespace).filter(|s| !s.is_empty()) }
+        SplitWhitespace { inner: self.split(IsWhitespace).filter(IsNotEmpty) }
     }
 
     /// Splits a string slice by ASCII whitespace.
@@ -1032,13 +1032,8 @@ impl str {
     #[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
     #[inline]
     pub fn split_ascii_whitespace(&self) -> SplitAsciiWhitespace<'_> {
-        let inner = self
-            .as_bytes()
-            .split(u8::is_ascii_whitespace)
-            .filter(|s| !s.is_empty())
-            // SAFETY: the byte slice came from a string and was only split
-            // along character boundaries, so the resulting slices are strings.
-            .map(|bytes| unsafe { from_utf8_unchecked(bytes) });
+        let inner =
+            self.as_bytes().split(IsAsciiWhitespace).filter(BytesIsNotEmpty).map(UnsafeBytesToStr);
         SplitAsciiWhitespace { inner }
     }
 
@@ -1090,11 +1085,7 @@ impl str {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
     pub fn lines(&self) -> Lines<'_> {
-        Lines(self.split_inclusive('\n').map(|line| {
-            let Some(line) = line.strip_suffix('\n') else { return line };
-            let Some(line) = line.strip_suffix('\r') else { return line };
-            line
-        }))
+        Lines(self.split_inclusive('\n').map(LinesMap))
     }
 
     /// An iterator over the lines of a string.
@@ -2645,19 +2636,14 @@ impl str {
     #[stable(feature = "str_escape", since = "1.34.0")]
     pub fn escape_debug(&self) -> EscapeDebug<'_> {
         let mut chars = self.chars();
-        let first = chars
-            .next()
-            .map(|first| first.escape_debug_ext(EscapeDebugExtArgs::ESCAPE_ALL))
-            .into_iter()
-            .flatten();
-        let inner = first.chain(chars.flat_map(|c| {
-            c.escape_debug_ext(EscapeDebugExtArgs {
-                escape_grapheme_extended: false,
-                escape_single_quote: true,
-                escape_double_quote: true,
-            })
-        }));
-        EscapeDebug { inner }
+        EscapeDebug {
+            inner: chars
+                .next()
+                .map(|first| first.escape_debug_ext(EscapeDebugExtArgs::ESCAPE_ALL))
+                .into_iter()
+                .flatten()
+                .chain(chars.flat_map(CharEscapeDebugContinue)),
+        }
     }
 
     /// Return an iterator that escapes each char in `self` with [`char::escape_default`].
@@ -2695,7 +2681,7 @@ impl str {
                   without modifying the original"]
     #[stable(feature = "str_escape", since = "1.34.0")]
     pub fn escape_default(&self) -> EscapeDefault<'_> {
-        EscapeDefault { inner: self.chars().flat_map(char::escape_default) }
+        EscapeDefault { inner: self.chars().flat_map(CharEscapeDefault) }
     }
 
     /// Return an iterator that escapes each char in `self` with [`char::escape_unicode`].
@@ -2733,7 +2719,7 @@ impl str {
                   without modifying the original"]
     #[stable(feature = "str_escape", since = "1.34.0")]
     pub fn escape_unicode(&self) -> EscapeUnicode<'_> {
-        EscapeUnicode { inner: self.chars().flat_map(char::escape_unicode) }
+        EscapeUnicode { inner: self.chars().flat_map(CharEscapeUnicode) }
     }
 }
 
@@ -2764,15 +2750,59 @@ impl Default for &mut str {
     }
 }
 
-type LinesMap = impl (Fn(&str) -> &str) + Copy;
-type CharEscapeDebugContinue = impl (FnMut(char) -> char::EscapeDebug) + Copy;
-type CharEscapeUnicode = impl (Fn(char) -> char::EscapeUnicode) + Copy;
-type CharEscapeDefault = impl (Fn(char) -> char::EscapeDefault) + Copy;
-type IsWhitespace = impl (Fn(char) -> bool) + Copy;
-type IsAsciiWhitespace = impl (Fn(&u8) -> bool) + Copy;
-type IsNotEmpty = impl (Fn(&&str) -> bool) + Copy;
-type BytesIsNotEmpty<'a> = impl (FnMut(&&'a [u8]) -> bool) + Copy;
-type UnsafeBytesToStr<'a> = impl (FnMut(&'a [u8]) -> &'a str) + Copy;
+impl_fn_for_zst! {
+    /// A nameable, cloneable fn type
+    #[derive(Clone)]
+    struct LinesMap impl<'a> Fn = |line: &'a str| -> &'a str {
+        let Some(line) = line.strip_suffix('\n') else { return line };
+        let Some(line) = line.strip_suffix('\r') else { return line };
+        line
+    };
+
+    #[derive(Clone)]
+    struct CharEscapeDebugContinue impl Fn = |c: char| -> char::EscapeDebug {
+        c.escape_debug_ext(EscapeDebugExtArgs {
+            escape_grapheme_extended: false,
+            escape_single_quote: true,
+            escape_double_quote: true
+        })
+    };
+
+    #[derive(Clone)]
+    struct CharEscapeUnicode impl Fn = |c: char| -> char::EscapeUnicode {
+        c.escape_unicode()
+    };
+    #[derive(Clone)]
+    struct CharEscapeDefault impl Fn = |c: char| -> char::EscapeDefault {
+        c.escape_default()
+    };
+
+    #[derive(Clone)]
+    struct IsWhitespace impl Fn = |c: char| -> bool {
+        c.is_whitespace()
+    };
+
+    #[derive(Clone)]
+    struct IsAsciiWhitespace impl Fn = |byte: &u8| -> bool {
+        byte.is_ascii_whitespace()
+    };
+
+    #[derive(Clone)]
+    struct IsNotEmpty impl<'a, 'b> Fn = |s: &'a &'b str| -> bool {
+        !s.is_empty()
+    };
+
+    #[derive(Clone)]
+    struct BytesIsNotEmpty impl<'a, 'b> Fn = |s: &'a &'b [u8]| -> bool {
+        !s.is_empty()
+    };
+
+    #[derive(Clone)]
+    struct UnsafeBytesToStr impl<'a> Fn = |bytes: &'a [u8]| -> &'a str {
+        // SAFETY: not safe
+        unsafe { from_utf8_unchecked(bytes) }
+    };
+}
 
 // This is required to make `impl From<&str> for Box<dyn Error>` and `impl<E> From<E> for Box<dyn Error>` not overlap.
 #[stable(feature = "rust1", since = "1.0.0")]
diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs
index 475b3e7eb9312..e3e0cde8afead 100644
--- a/library/std/src/backtrace.rs
+++ b/library/std/src/backtrace.rs
@@ -428,39 +428,43 @@ impl fmt::Display for Backtrace {
     }
 }
 
-type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe;
-
-fn lazy_resolve(mut capture: Capture) -> LazyResolve {
-    move || {
-        // Use the global backtrace lock to synchronize this as it's a
-        // requirement of the `backtrace` crate, and then actually resolve
-        // everything.
-        let _lock = lock();
-        for frame in capture.frames.iter_mut() {
-            let symbols = &mut frame.symbols;
-            let frame = match &frame.frame {
-                RawFrame::Actual(frame) => frame,
-                #[cfg(test)]
-                RawFrame::Fake => unimplemented!(),
-            };
-            unsafe {
-                backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| {
-                    symbols.push(BacktraceSymbol {
-                        name: symbol.name().map(|m| m.as_bytes().to_vec()),
-                        filename: symbol.filename_raw().map(|b| match b {
-                            BytesOrWideString::Bytes(b) => BytesOrWide::Bytes(b.to_owned()),
-                            BytesOrWideString::Wide(b) => BytesOrWide::Wide(b.to_owned()),
-                        }),
-                        lineno: symbol.lineno(),
-                        colno: symbol.colno(),
+mod helper {
+    use super::*;
+    pub(super) type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe;
+
+    pub(super) fn lazy_resolve(mut capture: Capture) -> LazyResolve {
+        move || {
+            // Use the global backtrace lock to synchronize this as it's a
+            // requirement of the `backtrace` crate, and then actually resolve
+            // everything.
+            let _lock = lock();
+            for frame in capture.frames.iter_mut() {
+                let symbols = &mut frame.symbols;
+                let frame = match &frame.frame {
+                    RawFrame::Actual(frame) => frame,
+                    #[cfg(test)]
+                    RawFrame::Fake => unimplemented!(),
+                };
+                unsafe {
+                    backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| {
+                        symbols.push(BacktraceSymbol {
+                            name: symbol.name().map(|m| m.as_bytes().to_vec()),
+                            filename: symbol.filename_raw().map(|b| match b {
+                                BytesOrWideString::Bytes(b) => BytesOrWide::Bytes(b.to_owned()),
+                                BytesOrWideString::Wide(b) => BytesOrWide::Wide(b.to_owned()),
+                            }),
+                            lineno: symbol.lineno(),
+                            colno: symbol.colno(),
+                        });
                     });
-                });
+                }
             }
-        }
 
-        capture
+            capture
+        }
     }
 }
+use helper::*;
 
 impl RawFrame {
     fn ip(&self) -> *mut c_void {
diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs
index 25dba97962ae5..3edc68e134740 100644
--- a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs
+++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs
@@ -9,15 +9,18 @@
 
 extern crate core;
 
-pub type Type1 = impl Send;
+mod defining_module {
+    pub type Type1 = impl Send;
 
-pub fn foo()
-where
-    Type1: 'static,
-{
-    pub struct Foo<T, const N: usize>([T; N]);
-    let _: Type1 = Foo([0; 32]);
+    pub fn foo()
+    where
+        Type1: 'static,
+    {
+        pub struct Foo<T, const N: usize>([T; N]);
+        let _: Type1 = Foo([0; 32]);
+    }
 }
+use defining_module::*;
 
 pub fn foo1(_: Type1) {}
 // CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
@@ -26,6 +29,6 @@ pub fn foo2(_: Type1, _: Type1) {}
 pub fn foo3(_: Type1, _: Type1, _: Type1) {}
 // CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
 
-// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo3FooIu3i32Lu5usize32EEE"}
-// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo3FooIu3i32Lu5usize32EES2_E"}
-// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo3FooIu3i32Lu5usize32EES2_S2_E"}
+// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo3FooIu3i32Lu5usize32EEE"}
+// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo3FooIu3i32Lu5usize32EES2_E"}
+// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo3FooIu3i32Lu5usize32EES2_S2_E"}
diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs
index 3ef119fd905af..09cfd2e10d6e7 100644
--- a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs
+++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs
@@ -9,17 +9,22 @@
 
 extern crate core;
 
-pub type Type1 = impl Send;
+mod defining_module {
 
-pub fn foo<'a>()
-where
-    Type1: 'static,
-{
-    pub struct Foo<'a>(&'a i32);
-    pub struct Bar<'a, 'b>(&'a i32, &'b Foo<'b>);
-    let _: Type1 = Bar;
+    pub type Type1 = impl Send;
+
+    pub fn foo<'a>()
+    where
+        Type1: 'static,
+    {
+        pub struct Foo<'a>(&'a i32);
+        pub struct Bar<'a, 'b>(&'a i32, &'b Foo<'b>);
+        let _: Type1 = Bar;
+    }
 }
 
+use defining_module::*;
+
 pub fn foo1(_: Type1) {}
 // CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
 pub fn foo2(_: Type1, _: Type1) {}
diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs
index 9870ecc69baf6..ffbfe021ba3eb 100644
--- a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs
+++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs
@@ -9,45 +9,47 @@
 
 extern crate core;
 
-pub type Type1 = impl Send;
-pub type Type2 = impl Send;
-pub type Type3 = impl Send;
-pub type Type4 = impl Send;
+mod defining_module {
+    pub type Type1 = impl Send;
+    pub type Type2 = impl Send;
+    pub type Type3 = impl Send;
+    pub type Type4 = impl Send;
 
-pub fn foo()
-where
-    Type1: 'static,
-    Type2: 'static,
-    Type3: 'static,
-    Type4: 'static,
-{
-    // Type in extern path
-    extern "C" {
-        fn bar();
-    }
-    let _: Type1 = bar;
+    pub fn foo()
+    where
+        Type1: 'static,
+        Type2: 'static,
+        Type4: 'static,
+    {
+        // Type in extern path
+        extern "C" {
+            fn bar();
+        }
+        let _: Type1 = bar;
 
-    // Type in closure path
-    || {
-        pub struct Foo;
-        let _: Type2 = Foo;
-    };
+        // Type in closure path
+        || {
+            pub struct Foo;
+            let _: Type2 = Foo;
+        };
 
-    // Type in const path
-    const {
-        pub struct Foo;
-        fn bar() -> Type3 {
-            Foo
-        }
-    };
+        // Type in const path
+        const {
+            pub struct Foo;
+            fn bar() -> Type3 {
+                Foo
+            }
+        };
 
-    // Type in impl path
-    struct Foo;
-    impl Foo {
-        fn bar(&self) {}
+        // Type in impl path
+        struct Foo;
+        impl Foo {
+            fn bar(&self) {}
+        }
+        let _: Type4 = <Foo>::bar;
     }
-    let _: Type4 = <Foo>::bar;
 }
+use defining_module::*;
 
 // Force arguments to be passed by using a reference. Otherwise, they may end up PassMode::Ignore
 
@@ -76,15 +78,15 @@ pub fn foo11(_: &Type4, _: &Type4) {}
 pub fn foo12(_: &Type4, _: &Type4, _: &Type4) {}
 // CHECK: define{{.*}}5foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
 
-// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo10{{[{}][{}]}}extern{{[}][}]}}3barEE"}
-// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo10{{[{}][{}]}}extern{{[}][}]}}3barES0_E"}
-// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo10{{[{}][{}]}}extern{{[}][}]}}3barES0_S0_E"}
-// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooEE"}
-// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_E"}
-// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_S0_E"}
-// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooEE"}
-// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_E"}
-// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_S0_E"}
-// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barEE"}
-// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_E"}
-// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_S0_E"}
+// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNFNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo10{{[{}][{}]}}extern{{[}][}]}}3barEE"}
+// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNFNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo10{{[{}][{}]}}extern{{[}][}]}}3barES0_E"}
+// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNFNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo10{{[{}][{}]}}extern{{[}][}]}}3barES0_S0_E"}
+// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo11{{[{}][{}]}}closure{{[}][}]}}3FooEE"}
+// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_E"}
+// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_S0_E"}
+// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo12{{[{}][{}]}}constant{{[}][}]}}3FooEE"}
+// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_E"}
+// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_S0_E"}
+// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo8{{[{}][{}]}}impl{{[}][}]}}3barEE"}
+// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_E"}
+// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvNtC{{[[:print:]]+}}_{{[[:print:]]+}}15defining_module3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_S0_E"}
diff --git a/tests/ui/const-generics/opaque_types.rs b/tests/ui/const-generics/opaque_types.rs
index ccf70f4fb37b0..2c7170c889fb3 100644
--- a/tests/ui/const-generics/opaque_types.rs
+++ b/tests/ui/const-generics/opaque_types.rs
@@ -6,6 +6,7 @@ type Foo = impl Sized;
 
 fn foo<const C: Foo>() {}
 //~^ ERROR: `Foo` is forbidden as the type of a const generic parameter
+//~| ERROR: item does not constrain
 
 fn main() {
     foo::<42>();
diff --git a/tests/ui/const-generics/opaque_types.stderr b/tests/ui/const-generics/opaque_types.stderr
index f03bca69a8bbf..2c7384984c694 100644
--- a/tests/ui/const-generics/opaque_types.stderr
+++ b/tests/ui/const-generics/opaque_types.stderr
@@ -1,5 +1,18 @@
+error: item does not constrain `Foo::{opaque#0}`, but has it in its signature
+  --> $DIR/opaque_types.rs:7:4
+   |
+LL | fn foo<const C: Foo>() {}
+   |    ^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/opaque_types.rs:3:12
+   |
+LL | type Foo = impl Sized;
+   |            ^^^^^^^^^^
+
 error[E0308]: mismatched types
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL | type Foo = impl Sized;
    |            ---------- the expected opaque type
@@ -22,27 +35,27 @@ note: ...which requires computing type of opaque `Foo::{opaque#0}`...
 LL | type Foo = impl Sized;
    |            ^^^^^^^^^^
 note: ...which requires type-checking `main`...
-  --> $DIR/opaque_types.rs:10:1
+  --> $DIR/opaque_types.rs:11:1
    |
 LL | fn main() {
    | ^^^^^^^^^
 note: ...which requires evaluating type-level constant...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
 note: ...which requires const-evaluating + checking `main::{constant#0}`...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
 note: ...which requires caching mir of `main::{constant#0}` for CTFE...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
 note: ...which requires elaborating drops for `main::{constant#0}`...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
@@ -70,42 +83,42 @@ LL | type Foo = impl Sized;
    |            ^^^^^^^^^^
    |
 note: ...which requires type-checking `main`...
-  --> $DIR/opaque_types.rs:10:1
+  --> $DIR/opaque_types.rs:11:1
    |
 LL | fn main() {
    | ^^^^^^^^^
 note: ...which requires evaluating type-level constant...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
 note: ...which requires const-evaluating + checking `main::{constant#0}`...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
 note: ...which requires caching mir of `main::{constant#0}` for CTFE...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
 note: ...which requires elaborating drops for `main::{constant#0}`...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
 note: ...which requires borrow-checking `main::{constant#0}`...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
 note: ...which requires promoting constants in MIR for `main::{constant#0}`...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
 note: ...which requires const checking `main::{constant#0}`...
-  --> $DIR/opaque_types.rs:11:11
+  --> $DIR/opaque_types.rs:12:11
    |
 LL |     foo::<42>();
    |           ^^
@@ -119,7 +132,7 @@ LL | type Foo = impl Sized;
    |            ^^^^^^^^^^
    = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
 
-error: aborting due to 4 previous errors
+error: aborting due to 5 previous errors
 
 Some errors have detailed explanations: E0308, E0391.
 For more information about an error, try `rustc --explain E0308`.
diff --git a/tests/ui/consts/const-fn-cycle.rs b/tests/ui/consts/const-fn-cycle.rs
new file mode 100644
index 0000000000000..5175296a53e5b
--- /dev/null
+++ b/tests/ui/consts/const-fn-cycle.rs
@@ -0,0 +1,28 @@
+/// Discovered in https://github.com/rust-lang/rust/issues/112602.
+/// This caused a cycle error, which made no sense.
+/// Removing the `const` part of the `many` function would make the
+/// test pass again.
+/// The issue was that we were running const qualif checks on
+/// `const fn`s, but never using them. During const qualif checks we tend
+/// to end up revealing opaque types (the RPIT in `many`'s return type),
+/// which can quickly lead to cycles.
+
+pub struct Parser<H>(H);
+
+impl<H, T> Parser<H>
+where
+    H: for<'a> Fn(&'a str) -> T,
+{
+    pub const fn new(handler: H) -> Parser<H> {
+        Parser(handler)
+    }
+
+    pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> {
+        //~^ ERROR: cycle detected
+        Parser::new(|_| unimplemented!())
+    }
+}
+
+fn main() {
+    println!("Hello, world!");
+}
diff --git a/tests/ui/consts/const-fn-cycle.stderr b/tests/ui/consts/const-fn-cycle.stderr
new file mode 100644
index 0000000000000..c851f7342be9c
--- /dev/null
+++ b/tests/ui/consts/const-fn-cycle.stderr
@@ -0,0 +1,34 @@
+error[E0391]: cycle detected when computing type of opaque `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}`
+  --> $DIR/const-fn-cycle.rs:20:47
+   |
+LL |     pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> {
+   |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: ...which requires borrow-checking `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many`...
+  --> $DIR/const-fn-cycle.rs:20:5
+   |
+LL |     pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: ...which requires promoting constants in MIR for `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many`...
+  --> $DIR/const-fn-cycle.rs:20:5
+   |
+LL |     pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: ...which requires const checking `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many`...
+  --> $DIR/const-fn-cycle.rs:20:5
+   |
+LL |     pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = note: ...which requires computing whether `Parser<<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}>` is freeze...
+   = note: ...which requires evaluating trait selection obligation `Parser<<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}>: core::marker::Freeze`...
+   = note: ...which again requires computing type of opaque `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}`, completing the cycle
+note: cycle used when computing type of `<impl at $DIR/const-fn-cycle.rs:12:1: 14:33>::many::{opaque#0}`
+  --> $DIR/const-fn-cycle.rs:20:47
+   |
+LL |     pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> {
+   |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0391`.
diff --git a/tests/ui/consts/const-promoted-opaque.atomic.stderr b/tests/ui/consts/const-promoted-opaque.atomic.stderr
new file mode 100644
index 0000000000000..a0459f4040ec6
--- /dev/null
+++ b/tests/ui/consts/const-promoted-opaque.atomic.stderr
@@ -0,0 +1,71 @@
+error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
+  --> $DIR/const-promoted-opaque.rs:29:25
+   |
+LL |     let _: &'static _ = &FOO;
+   |                         ^^^^
+   |
+   = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
+   = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time
+  --> $DIR/const-promoted-opaque.rs:29:26
+   |
+LL |     let _: &'static _ = &FOO;
+   |                          ^^^ the destructor for this type cannot be evaluated in constants
+...
+LL | };
+   | - value is dropped here
+
+error[E0492]: constants cannot refer to interior mutable data
+  --> $DIR/const-promoted-opaque.rs:34:19
+   |
+LL | const BAZ: &Foo = &FOO;
+   |                   ^^^^ this borrow of an interior mutable value may end up in the final value
+
+error[E0716]: temporary value dropped while borrowed
+  --> $DIR/const-promoted-opaque.rs:38:26
+   |
+LL |     let _: &'static _ = &FOO;
+   |            ----------    ^^^ creates a temporary value which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
+LL |
+LL | }
+   | - temporary value is freed at the end of this statement
+
+error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}`
+  --> $DIR/const-promoted-opaque.rs:14:20
+   |
+LL |     pub type Foo = impl Sized;
+   |                    ^^^^^^^^^^
+   |
+note: ...which requires borrow-checking `helper::FOO`...
+  --> $DIR/const-promoted-opaque.rs:21:5
+   |
+LL |     pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
+   |     ^^^^^^^^^^^^^^^^^^
+note: ...which requires promoting constants in MIR for `helper::FOO`...
+  --> $DIR/const-promoted-opaque.rs:21:5
+   |
+LL |     pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
+   |     ^^^^^^^^^^^^^^^^^^
+note: ...which requires const checking `helper::FOO`...
+  --> $DIR/const-promoted-opaque.rs:21:5
+   |
+LL |     pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
+   |     ^^^^^^^^^^^^^^^^^^
+   = note: ...which requires computing whether `helper::Foo` is freeze...
+   = note: ...which requires evaluating trait selection obligation `helper::Foo: core::marker::Freeze`...
+   = note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle
+note: cycle used when computing type of `helper::Foo::{opaque#0}`
+  --> $DIR/const-promoted-opaque.rs:14:20
+   |
+LL |     pub type Foo = impl Sized;
+   |                    ^^^^^^^^^^
+   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0391, E0492, E0493, E0658, E0716.
+For more information about an error, try `rustc --explain E0391`.
diff --git a/tests/ui/consts/const-promoted-opaque.rs b/tests/ui/consts/const-promoted-opaque.rs
new file mode 100644
index 0000000000000..e20823527f48b
--- /dev/null
+++ b/tests/ui/consts/const-promoted-opaque.rs
@@ -0,0 +1,40 @@
+//@revisions: string unit atomic
+#![feature(type_alias_impl_trait)]
+
+//! Check that we do not cause cycle errors when trying to
+//! obtain information about interior mutability of an opaque type.
+//! This used to happen, because when the body-analysis failed, we
+//! checked the type instead, but the constant was also defining the
+//! hidden type of the opaque type. Thus we ended up relying on the
+//! result of our analysis to compute the result of our analysis.
+
+//@[unit] check-pass
+
+mod helper {
+    pub type Foo = impl Sized;
+    //[string,atomic]~^ ERROR cycle detected
+
+    #[cfg(string)]
+    pub const FOO: Foo = String::new();
+
+    #[cfg(atomic)]
+    pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
+
+    #[cfg(unit)]
+    pub const FOO: Foo = ();
+}
+use helper::*;
+
+const BAR: () = {
+    let _: &'static _ = &FOO;
+    //[string,atomic]~^ ERROR: destructor of `helper::Foo` cannot be evaluated at compile-time
+    //[string,atomic]~| ERROR: cannot borrow here
+};
+
+const BAZ: &Foo = &FOO;
+//[string,atomic]~^ ERROR: constants cannot refer to interior mutable data
+
+fn main() {
+    let _: &'static _ = &FOO;
+    //[string,atomic]~^ ERROR: temporary value dropped while borrowed
+}
diff --git a/tests/ui/consts/const-promoted-opaque.string.stderr b/tests/ui/consts/const-promoted-opaque.string.stderr
new file mode 100644
index 0000000000000..a613d517e68ef
--- /dev/null
+++ b/tests/ui/consts/const-promoted-opaque.string.stderr
@@ -0,0 +1,71 @@
+error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
+  --> $DIR/const-promoted-opaque.rs:29:25
+   |
+LL |     let _: &'static _ = &FOO;
+   |                         ^^^^
+   |
+   = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
+   = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time
+  --> $DIR/const-promoted-opaque.rs:29:26
+   |
+LL |     let _: &'static _ = &FOO;
+   |                          ^^^ the destructor for this type cannot be evaluated in constants
+...
+LL | };
+   | - value is dropped here
+
+error[E0492]: constants cannot refer to interior mutable data
+  --> $DIR/const-promoted-opaque.rs:34:19
+   |
+LL | const BAZ: &Foo = &FOO;
+   |                   ^^^^ this borrow of an interior mutable value may end up in the final value
+
+error[E0716]: temporary value dropped while borrowed
+  --> $DIR/const-promoted-opaque.rs:38:26
+   |
+LL |     let _: &'static _ = &FOO;
+   |            ----------    ^^^ creates a temporary value which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
+LL |
+LL | }
+   | - temporary value is freed at the end of this statement
+
+error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}`
+  --> $DIR/const-promoted-opaque.rs:14:20
+   |
+LL |     pub type Foo = impl Sized;
+   |                    ^^^^^^^^^^
+   |
+note: ...which requires borrow-checking `helper::FOO`...
+  --> $DIR/const-promoted-opaque.rs:18:5
+   |
+LL |     pub const FOO: Foo = String::new();
+   |     ^^^^^^^^^^^^^^^^^^
+note: ...which requires promoting constants in MIR for `helper::FOO`...
+  --> $DIR/const-promoted-opaque.rs:18:5
+   |
+LL |     pub const FOO: Foo = String::new();
+   |     ^^^^^^^^^^^^^^^^^^
+note: ...which requires const checking `helper::FOO`...
+  --> $DIR/const-promoted-opaque.rs:18:5
+   |
+LL |     pub const FOO: Foo = String::new();
+   |     ^^^^^^^^^^^^^^^^^^
+   = note: ...which requires computing whether `helper::Foo` is freeze...
+   = note: ...which requires evaluating trait selection obligation `helper::Foo: core::marker::Freeze`...
+   = note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle
+note: cycle used when computing type of `helper::Foo::{opaque#0}`
+  --> $DIR/const-promoted-opaque.rs:14:20
+   |
+LL |     pub type Foo = impl Sized;
+   |                    ^^^^^^^^^^
+   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0391, E0492, E0493, E0658, E0716.
+For more information about an error, try `rustc --explain E0391`.
diff --git a/tests/ui/coroutine/layout-error.rs b/tests/ui/coroutine/layout-error.rs
index 70a0248eabcc2..3e26cf17d29ec 100644
--- a/tests/ui/coroutine/layout-error.rs
+++ b/tests/ui/coroutine/layout-error.rs
@@ -16,13 +16,22 @@ impl<F: Future> Task<F> {
     }
 }
 
-fn main() {
-    async fn cb() {
-        let a = Foo; //~ ERROR cannot find value `Foo` in this scope
-    }
+mod helper {
+    use super::*;
+    pub type F = impl Future;
+    fn foo()
+    where
+        F:,
+    {
+        async fn cb() {
+            let a = Foo; //~ ERROR cannot find value `Foo` in this scope
+        }
 
-    type F = impl Future;
-    // Check that statics are inhabited computes they layout.
-    static POOL: Task<F> = Task::new();
-    Task::spawn(&POOL, || cb());
+        Task::spawn(&POOL, || cb());
+    }
 }
+
+// Check that statics are inhabited computes they layout.
+static POOL: Task<helper::F> = Task::new();
+
+fn main() {}
diff --git a/tests/ui/coroutine/layout-error.stderr b/tests/ui/coroutine/layout-error.stderr
index 249a99e9b85c6..ceadb62c99988 100644
--- a/tests/ui/coroutine/layout-error.stderr
+++ b/tests/ui/coroutine/layout-error.stderr
@@ -1,8 +1,8 @@
 error[E0425]: cannot find value `Foo` in this scope
-  --> $DIR/layout-error.rs:21:17
+  --> $DIR/layout-error.rs:27:21
    |
-LL |         let a = Foo;
-   |                 ^^^ not found in this scope
+LL |             let a = Foo;
+   |                     ^^^ not found in this scope
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/coroutine/metadata-sufficient-for-layout.rs b/tests/ui/coroutine/metadata-sufficient-for-layout.rs
index 23937e12c5218..9c3a7e4378e39 100644
--- a/tests/ui/coroutine/metadata-sufficient-for-layout.rs
+++ b/tests/ui/coroutine/metadata-sufficient-for-layout.rs
@@ -4,22 +4,23 @@
 // Regression test for #80998.
 //
 //@ aux-build:metadata-sufficient-for-layout.rs
+//@ check-pass
 
 #![feature(type_alias_impl_trait, rustc_attrs)]
 #![feature(coroutine_trait)]
 
 extern crate metadata_sufficient_for_layout;
 
-use std::ops::Coroutine;
+mod helper {
+    use std::ops::Coroutine;
+    pub type F = impl Coroutine<(), Yield = (), Return = ()>;
 
-type F = impl Coroutine<(), Yield = (), Return = ()>;
+    fn f() -> F {
+        metadata_sufficient_for_layout::g()
+    }
+}
 
 // Static queries the layout of the coroutine.
-static A: Option<F> = None;
-
-fn f() -> F {
-    metadata_sufficient_for_layout::g()
-}
+static A: Option<helper::F> = None;
 
-#[rustc_error]
-fn main() {} //~ ERROR
+fn main() {}
diff --git a/tests/ui/coroutine/metadata-sufficient-for-layout.stderr b/tests/ui/coroutine/metadata-sufficient-for-layout.stderr
deleted file mode 100644
index c7860fde2a9f7..0000000000000
--- a/tests/ui/coroutine/metadata-sufficient-for-layout.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-error: fatal error triggered by #[rustc_error]
-  --> $DIR/metadata-sufficient-for-layout.rs:25:1
-   |
-LL | fn main() {}
-   | ^^^^^^^^^
-
-error: aborting due to 1 previous error
-
diff --git a/tests/ui/impl-trait/future-no-bound-vars-ice-112347.rs b/tests/ui/impl-trait/future-no-bound-vars-ice-112347.rs
index dc4dc9e220d51..af623dc7cd9d1 100644
--- a/tests/ui/impl-trait/future-no-bound-vars-ice-112347.rs
+++ b/tests/ui/impl-trait/future-no-bound-vars-ice-112347.rs
@@ -7,11 +7,15 @@
 
 use std::future::Future;
 
-type Fut<'a> = impl Future<Output = ()> + 'a;
+mod foo {
+    use std::future::Future;
+    pub type Fut<'a> = impl Future<Output = ()> + 'a;
 
-fn foo<'a>(_: &()) -> Fut<'_> {
-    async {}
+    fn foo<'a>(_: &()) -> Fut<'_> {
+        async {}
+    }
 }
+use foo::*;
 
 trait Test {
     fn hello();
diff --git a/tests/ui/impl-trait/issue-108592.rs b/tests/ui/impl-trait/issue-108592.rs
index 624bb79006ea3..7db2e31549c09 100644
--- a/tests/ui/impl-trait/issue-108592.rs
+++ b/tests/ui/impl-trait/issue-108592.rs
@@ -11,9 +11,13 @@ fn test_closure() {
     closure(&opaque());
 }
 
-type Opaque2 = impl Sized;
-type Opaque<'a> = Opaque2;
-fn define<'a>() -> Opaque<'a> {}
+mod helper {
+    pub type Opaque2 = impl Sized;
+    pub type Opaque<'a> = Opaque2;
+    fn define<'a>() -> Opaque<'a> {}
+}
+
+use helper::*;
 
 fn test_tait(_: &Opaque<'_>) {
     None::<&'static Opaque<'_>>;
diff --git a/tests/ui/impl-trait/issues/issue-70877.rs b/tests/ui/impl-trait/issues/issue-70877.rs
index df7722986744d..6ced0bbba8b36 100644
--- a/tests/ui/impl-trait/issues/issue-70877.rs
+++ b/tests/ui/impl-trait/issues/issue-70877.rs
@@ -1,10 +1,8 @@
 #![feature(type_alias_impl_trait)]
 
 type FooArg<'a> = &'a dyn ToString;
-type FooRet = impl std::fmt::Debug;
 
 type FooItem = Box<dyn Fn(FooArg) -> FooRet>;
-type Foo = impl Iterator<Item = FooItem>;
 
 #[repr(C)]
 struct Bar(u8);
@@ -17,19 +15,26 @@ impl Iterator for Bar {
     }
 }
 
-fn quux(st: FooArg) -> FooRet {
-    Some(st.to_string())
-}
-
-fn ham() -> Foo {
-    Bar(1)
+mod ret {
+    pub type FooRet = impl std::fmt::Debug;
+    pub fn quux(st: super::FooArg) -> FooRet {
+        Some(st.to_string())
+    }
 }
-
-fn oof(_: Foo) -> impl std::fmt::Debug {
-    let mut bar = ham();
-    let func = bar.next().unwrap();
-    return func(&"oof"); //~ ERROR opaque type's hidden type cannot be another opaque type
+use ret::*;
+mod foo {
+    pub type Foo = impl Iterator<Item = super::FooItem>;
+    pub fn ham() -> Foo {
+        super::Bar(1)
+    }
+    pub fn oof(_: Foo) -> impl std::fmt::Debug {
+        //~^ ERROR: item does not constrain `Foo::{opaque#0}`, but has it in its signature
+        let mut bar = ham();
+        let func = bar.next().unwrap();
+        return func(&"oof");
+    }
 }
+use foo::*;
 
 fn main() {
     let _ = oof(ham());
diff --git a/tests/ui/impl-trait/issues/issue-70877.stderr b/tests/ui/impl-trait/issues/issue-70877.stderr
index 274139f01d087..4b23a02aaee3f 100644
--- a/tests/ui/impl-trait/issues/issue-70877.stderr
+++ b/tests/ui/impl-trait/issues/issue-70877.stderr
@@ -1,19 +1,15 @@
-error: opaque type's hidden type cannot be another opaque type from the same scope
-  --> $DIR/issue-70877.rs:31:12
+error: item does not constrain `Foo::{opaque#0}`, but has it in its signature
+  --> $DIR/issue-70877.rs:30:12
    |
-LL |     return func(&"oof");
-   |            ^^^^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope
+LL |     pub fn oof(_: Foo) -> impl std::fmt::Debug {
+   |            ^^^
    |
-note: opaque type whose hidden type is being assigned
-  --> $DIR/issue-70877.rs:28:19
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/issue-70877.rs:26:20
    |
-LL | fn oof(_: Foo) -> impl std::fmt::Debug {
-   |                   ^^^^^^^^^^^^^^^^^^^^
-note: opaque type being used as hidden type
-  --> $DIR/issue-70877.rs:4:15
-   |
-LL | type FooRet = impl std::fmt::Debug;
-   |               ^^^^^^^^^^^^^^^^^^^^
+LL |     pub type Foo = impl Iterator<Item = super::FooItem>;
+   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/impl-trait/issues/issue-77987.rs b/tests/ui/impl-trait/issues/issue-77987.rs
index b77f993effce1..a7e7b067d5ff8 100644
--- a/tests/ui/impl-trait/issues/issue-77987.rs
+++ b/tests/ui/impl-trait/issues/issue-77987.rs
@@ -2,19 +2,20 @@
 
 //@ check-pass
 
-trait Foo<T> {}
+pub trait Foo<T> {}
 impl<T, U> Foo<T> for U {}
 
-type Scope = impl Foo<()>;
+mod scope {
+    pub type Scope = impl super::Foo<()>;
 
-#[allow(unused)]
-fn infer_scope() -> Scope {
-    ()
+    #[allow(unused)]
+    fn infer_scope() -> Scope {
+        ()
+    }
 }
 
 #[allow(unused)]
-fn ice() -> impl Foo<Scope>
-{
+fn ice() -> impl Foo<scope::Scope> {
     loop {}
 }
 
diff --git a/tests/ui/impl-trait/issues/issue-86800.rs b/tests/ui/impl-trait/issues/issue-86800.rs
index 172ab04f58df4..5a6959ad7e6f2 100644
--- a/tests/ui/impl-trait/issues/issue-86800.rs
+++ b/tests/ui/impl-trait/issues/issue-86800.rs
@@ -26,6 +26,7 @@ type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>
 //~^ ERROR unconstrained opaque type
 
 fn execute_transaction_fut<'f, F, O>(
+    //~^ ERROR: item does not constrain
     f: F,
 ) -> impl FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O>
 where
@@ -37,10 +38,12 @@ where
 
 impl Context {
     async fn do_transaction<O>(
+        //~^ ERROR: item does not constrain
         &self, f: impl FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O>
     ) -> TransactionResult<O>
     {
         //~^ ERROR expected generic lifetime parameter, found `'_`
+        //~| ERROR: item does not constrain
         let mut conn = Connection {};
         let mut transaction = TestTransaction { conn: &mut conn };
         f(&mut transaction).await
diff --git a/tests/ui/impl-trait/issues/issue-86800.stderr b/tests/ui/impl-trait/issues/issue-86800.stderr
index 146d2f67942be..095f648143ca7 100644
--- a/tests/ui/impl-trait/issues/issue-86800.stderr
+++ b/tests/ui/impl-trait/issues/issue-86800.stderr
@@ -1,3 +1,48 @@
+error: item does not constrain `TransactionFuture::{opaque#0}`, but has it in its signature
+  --> $DIR/issue-86800.rs:28:4
+   |
+LL | fn execute_transaction_fut<'f, F, O>(
+   |    ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/issue-86800.rs:25:34
+   |
+LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
+   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: item does not constrain `TransactionFuture::{opaque#0}`, but has it in its signature
+  --> $DIR/issue-86800.rs:40:14
+   |
+LL |     async fn do_transaction<O>(
+   |              ^^^^^^^^^^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/issue-86800.rs:25:34
+   |
+LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
+   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: item does not constrain `TransactionFuture::{opaque#0}`, but has it in its signature
+  --> $DIR/issue-86800.rs:44:5
+   |
+LL | /     {
+LL | |
+LL | |
+LL | |         let mut conn = Connection {};
+LL | |         let mut transaction = TestTransaction { conn: &mut conn };
+LL | |         f(&mut transaction).await
+LL | |     }
+   | |_____^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/issue-86800.rs:25:34
+   |
+LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
+   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
 error: unconstrained opaque type
   --> $DIR/issue-86800.rs:25:34
    |
@@ -7,7 +52,7 @@ LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResu
    = note: `TransactionFuture` must be used in combination with a concrete type within the same module
 
 error[E0792]: expected generic lifetime parameter, found `'_`
-  --> $DIR/issue-86800.rs:34:5
+  --> $DIR/issue-86800.rs:35:5
    |
 LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
    |                        --- this generic parameter must be used with a generic lifetime parameter
@@ -16,19 +61,20 @@ LL |     f
    |     ^
 
 error[E0792]: expected generic lifetime parameter, found `'_`
-  --> $DIR/issue-86800.rs:42:5
+  --> $DIR/issue-86800.rs:44:5
    |
 LL |   type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
    |                          --- this generic parameter must be used with a generic lifetime parameter
 ...
 LL | /     {
 LL | |
+LL | |
 LL | |         let mut conn = Connection {};
 LL | |         let mut transaction = TestTransaction { conn: &mut conn };
 LL | |         f(&mut transaction).await
 LL | |     }
    | |_____^
 
-error: aborting due to 3 previous errors
+error: aborting due to 6 previous errors
 
 For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/impl-trait/issues/issue-89312.rs b/tests/ui/impl-trait/issues/issue-89312.rs
index 4304e3bc1b4e5..3b0e976780beb 100644
--- a/tests/ui/impl-trait/issues/issue-89312.rs
+++ b/tests/ui/impl-trait/issues/issue-89312.rs
@@ -2,18 +2,23 @@
 
 //@ check-pass
 
-trait T { type Item; }
+mod helper {
+    pub trait T {
+        type Item;
+    }
 
-type Alias<'a> = impl T<Item = &'a ()>;
+    pub type Alias<'a> = impl T<Item = &'a ()>;
 
-struct S;
-impl<'a> T for &'a S {
-    type Item = &'a ();
-}
+    struct S;
+    impl<'a> T for &'a S {
+        type Item = &'a ();
+    }
 
-fn filter_positive<'a>() -> Alias<'a> {
-    &S
+    pub fn filter_positive<'a>() -> Alias<'a> {
+        &S
+    }
 }
+use helper::*;
 
 fn with_positive(fun: impl Fn(Alias<'_>)) {
     fun(filter_positive());
diff --git a/tests/ui/impl-trait/normalize-tait-in-const.rs b/tests/ui/impl-trait/normalize-tait-in-const.rs
index 422c2e439cf0b..fc90139d64095 100644
--- a/tests/ui/impl-trait/normalize-tait-in-const.rs
+++ b/tests/ui/impl-trait/normalize-tait-in-const.rs
@@ -6,20 +6,23 @@
 
 use std::marker::Destruct;
 
-trait T {
-    type Item;
-}
+mod foo {
+    trait T {
+        type Item;
+    }
 
-type Alias<'a> = impl T<Item = &'a ()>;
+    pub type Alias<'a> = impl T<Item = &'a ()>;
 
-struct S;
-impl<'a> T for &'a S {
-    type Item = &'a ();
-}
+    struct S;
+    impl<'a> T for &'a S {
+        type Item = &'a ();
+    }
 
-const fn filter_positive<'a>() -> &'a Alias<'a> {
-    &&S
+    pub const fn filter_positive<'a>() -> &'a Alias<'a> {
+        &&S
+    }
 }
+use foo::*;
 
 const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
     fun(filter_positive());
diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr
index 9ea4ff7cc70a3..5e3c0ea054bdd 100644
--- a/tests/ui/impl-trait/normalize-tait-in-const.stderr
+++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr
@@ -1,11 +1,11 @@
 error: `~const` can only be applied to `#[const_trait]` traits
-  --> $DIR/normalize-tait-in-const.rs:24:42
+  --> $DIR/normalize-tait-in-const.rs:27:42
    |
 LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
    |                                          ^^^^^^^^^^^^^^^^^
 
 error[E0015]: cannot call non-const closure in constant functions
-  --> $DIR/normalize-tait-in-const.rs:25:5
+  --> $DIR/normalize-tait-in-const.rs:28:5
    |
 LL |     fun(filter_positive());
    |     ^^^^^^^^^^^^^^^^^^^^^^
@@ -13,15 +13,15 @@ LL |     fun(filter_positive());
    = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
 help: consider further restricting this bound
    |
-LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct + ~const Fn(&Alias<'_>)>(fun: F) {
-   |                                                                              +++++++++++++++++++++++
+LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct + ~const Fn(&foo::Alias<'_>)>(fun: F) {
+   |                                                                              ++++++++++++++++++++++++++++
 help: add `#![feature(effects)]` to the crate attributes to enable
    |
 LL + #![feature(effects)]
    |
 
 error[E0493]: destructor of `F` cannot be evaluated at compile-time
-  --> $DIR/normalize-tait-in-const.rs:24:79
+  --> $DIR/normalize-tait-in-const.rs:27:79
    |
 LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
    |                                                                               ^^^ the destructor for this type cannot be evaluated in constant functions
diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs
index b369544782c77..0b29af5df5b58 100644
--- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs
+++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs
@@ -2,7 +2,14 @@
 
 //@ check-pass
 
-type Foo = impl PartialEq<(Foo, i32)>;
+mod foo {
+    pub type Foo = impl PartialEq<(Foo, i32)>;
+
+    fn foo() -> Foo {
+        super::Bar
+    }
+}
+use foo::Foo;
 
 struct Bar;
 
@@ -12,8 +19,4 @@ impl PartialEq<(Foo, i32)> for Bar {
     }
 }
 
-fn foo() -> Foo {
-    Bar
-}
-
 fn main() {}
diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs
index 91f1ed48133f5..dc9424c3ca7ab 100644
--- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs
+++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs
@@ -9,6 +9,7 @@ mod a {
     impl PartialEq<(Bar, i32)> for Bar {
         fn eq(&self, _other: &(Foo, i32)) -> bool {
             //~^ ERROR: `eq` has an incompatible type for trait
+            //~| ERROR: item does not constrain `a::Foo::{opaque#0}`
             true
         }
     }
diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr
index 07ac1a37e75ce..4352af1c0df76 100644
--- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr
+++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr
@@ -1,3 +1,16 @@
+error: item does not constrain `a::Foo::{opaque#0}`, but has it in its signature
+  --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:10:12
+   |
+LL |         fn eq(&self, _other: &(Foo, i32)) -> bool {
+   |            ^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:4:16
+   |
+LL |     type Foo = impl PartialEq<(Foo, i32)>;
+   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
 error: unconstrained opaque type
   --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:4:16
    |
@@ -22,7 +35,7 @@ LL |         fn eq(&self, _other: &(Foo, i32)) -> bool {
               found signature `fn(&a::Bar, &(a::Foo, _)) -> _`
 
 error: unconstrained opaque type
-  --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:18:16
+  --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:19:16
    |
 LL |     type Foo = impl PartialEq<(Foo, i32)>;
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -30,7 +43,7 @@ LL |     type Foo = impl PartialEq<(Foo, i32)>;
    = note: `Foo` must be used in combination with a concrete type within the same module
 
 error[E0053]: method `eq` has an incompatible type for trait
-  --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:24:30
+  --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:25:30
    |
 LL |     type Foo = impl PartialEq<(Foo, i32)>;
    |                -------------------------- the expected opaque type
@@ -44,11 +57,11 @@ LL |         fn eq(&self, _other: &(Bar, i32)) -> bool {
    = note: expected signature `fn(&b::Bar, &(b::Foo, _)) -> _`
               found signature `fn(&b::Bar, &(b::Bar, _)) -> _`
 note: this item must have the opaque type in its signature in order to be able to register hidden types
-  --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:24:12
+  --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:25:12
    |
 LL |         fn eq(&self, _other: &(Bar, i32)) -> bool {
    |            ^^
 
-error: aborting due to 4 previous errors
+error: aborting due to 5 previous errors
 
 For more information about this error, try `rustc --explain E0053`.
diff --git a/tests/ui/impl-trait/two_tait_defining_each_other2.current.stderr b/tests/ui/impl-trait/two_tait_defining_each_other2.current.stderr
index 6f2b2d9ca0426..b70676ece0e2c 100644
--- a/tests/ui/impl-trait/two_tait_defining_each_other2.current.stderr
+++ b/tests/ui/impl-trait/two_tait_defining_each_other2.current.stderr
@@ -1,3 +1,16 @@
+error: item does not constrain `A::{opaque#0}`, but has it in its signature
+  --> $DIR/two_tait_defining_each_other2.rs:11:4
+   |
+LL | fn muh(x: A) -> B {
+   |    ^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/two_tait_defining_each_other2.rs:6:10
+   |
+LL | type A = impl Foo;
+   |          ^^^^^^^^
+
 error: unconstrained opaque type
   --> $DIR/two_tait_defining_each_other2.rs:6:10
    |
@@ -7,7 +20,7 @@ LL | type A = impl Foo;
    = note: `A` must be used in combination with a concrete type within the same module
 
 error: opaque type's hidden type cannot be another opaque type from the same scope
-  --> $DIR/two_tait_defining_each_other2.rs:13:5
+  --> $DIR/two_tait_defining_each_other2.rs:14:5
    |
 LL |     x // B's hidden type is A (opaquely)
    |     ^ one of the two opaque types used here has to be outside its defining scope
@@ -23,5 +36,5 @@ note: opaque type being used as hidden type
 LL | type A = impl Foo;
    |          ^^^^^^^^
 
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
 
diff --git a/tests/ui/impl-trait/two_tait_defining_each_other2.rs b/tests/ui/impl-trait/two_tait_defining_each_other2.rs
index e850736fdfaf2..3311c55656810 100644
--- a/tests/ui/impl-trait/two_tait_defining_each_other2.rs
+++ b/tests/ui/impl-trait/two_tait_defining_each_other2.rs
@@ -9,7 +9,8 @@ type B = impl Foo;
 trait Foo {}
 
 fn muh(x: A) -> B {
-    //[next]~^ ERROR type annotations needed: cannot satisfy `_ == A`
+    //[current]~^ ERROR: item does not constrain `A::{opaque#0}`
+    //[next]~^^ ERROR: cannot satisfy `_ == A`
     x // B's hidden type is A (opaquely)
     //[current]~^ ERROR opaque type's hidden type cannot be another opaque type
 }
diff --git a/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs b/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs
index 9269983158092..4879d2db40b81 100644
--- a/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs
+++ b/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs
@@ -1,10 +1,12 @@
-//@ build-pass (FIXME(62277): could be check-pass?)
+//! Test that it is basically not possible to declare *and opaquely use* opaque types
+//! in function bodies. This will work again once we have a `#[defines]` attribute
 
 #![feature(type_alias_impl_trait)]
 
 use std::fmt::Debug;
 
 fn main() {
+    //~^ ERROR: item does not constrain
     type Existential = impl Debug;
 
     fn f() -> Existential {}
diff --git a/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.stderr b/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.stderr
new file mode 100644
index 0000000000000..7744fa2f2ae66
--- /dev/null
+++ b/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.stderr
@@ -0,0 +1,15 @@
+error: item does not constrain `Existential::{opaque#0}`, but has it in its signature
+  --> $DIR/type-alias-impl-trait-in-fn-body.rs:8:4
+   |
+LL | fn main() {
+   |    ^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/type-alias-impl-trait-in-fn-body.rs:10:24
+   |
+LL |     type Existential = impl Debug;
+   |                        ^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/mir/issue-75053.rs b/tests/ui/mir/issue-75053.rs
index e2ec4076b4996..38684f3548f29 100644
--- a/tests/ui/mir/issue-75053.rs
+++ b/tests/ui/mir/issue-75053.rs
@@ -13,10 +13,13 @@ trait MyFrom<T>: Sized {
     fn my_from(value: T) -> Result<Self, Self::Error>;
 }
 
-trait F {}
-impl F for () {}
-type DummyT<T> = impl F;
-fn _dummy_t<T>() -> DummyT<T> {}
+mod f {
+    pub trait F {}
+    impl F for () {}
+    pub type DummyT<T> = impl F;
+    fn _dummy_t<T>() -> DummyT<T> {}
+}
+use f::*;
 
 struct Phantom1<T>(PhantomData<T>);
 struct Phantom2<T>(PhantomData<T>);
diff --git a/tests/ui/mir/issue-75053.stderr b/tests/ui/mir/issue-75053.stderr
index bd37f0c92ad82..a464d3266f4eb 100644
--- a/tests/ui/mir/issue-75053.stderr
+++ b/tests/ui/mir/issue-75053.stderr
@@ -1,5 +1,5 @@
 error: fatal error triggered by #[rustc_error]
-  --> $DIR/issue-75053.rs:46:1
+  --> $DIR/issue-75053.rs:49:1
    |
 LL | fn main() {
    | ^^^^^^^^^
diff --git a/tests/ui/self/arbitrary-self-opaque.rs b/tests/ui/self/arbitrary-self-opaque.rs
index 3331b037b0514..3c2e2d9db727e 100644
--- a/tests/ui/self/arbitrary-self-opaque.rs
+++ b/tests/ui/self/arbitrary-self-opaque.rs
@@ -7,6 +7,7 @@ type Bar = impl Sized;
 impl Foo {
     fn foo(self: Bar) {}
     //~^ ERROR: invalid `self` parameter type: `Bar`
+    //~| ERROR: item does not constrain
 }
 
 fn main() {}
diff --git a/tests/ui/self/arbitrary-self-opaque.stderr b/tests/ui/self/arbitrary-self-opaque.stderr
index 0cbe22afac31c..5ccc076bfaf6c 100644
--- a/tests/ui/self/arbitrary-self-opaque.stderr
+++ b/tests/ui/self/arbitrary-self-opaque.stderr
@@ -1,3 +1,16 @@
+error: item does not constrain `Bar::{opaque#0}`, but has it in its signature
+  --> $DIR/arbitrary-self-opaque.rs:8:8
+   |
+LL |     fn foo(self: Bar) {}
+   |        ^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/arbitrary-self-opaque.rs:4:12
+   |
+LL | type Bar = impl Sized;
+   |            ^^^^^^^^^^
+
 error: unconstrained opaque type
   --> $DIR/arbitrary-self-opaque.rs:4:12
    |
@@ -15,6 +28,6 @@ LL |     fn foo(self: Bar) {}
    = note: type of `self` must be `Self` or a type that dereferences to it
    = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
 
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0307`.
diff --git a/tests/ui/type-alias-impl-trait/argument-types.rs b/tests/ui/type-alias-impl-trait/argument-types.rs
index 9e4a8bb8dda45..7382d4c78c7df 100644
--- a/tests/ui/type-alias-impl-trait/argument-types.rs
+++ b/tests/ui/type-alias-impl-trait/argument-types.rs
@@ -1,13 +1,21 @@
 #![feature(type_alias_impl_trait)]
 #![allow(dead_code)]
 //@ check-pass
-use std::fmt::Debug;
 
-type Foo = impl Debug;
+mod foo {
+    use std::fmt::Debug;
 
-fn foo1(mut x: Foo) {
-    x = 22_u32;
+    pub type Foo = impl Debug;
+
+    fn foo1(mut x: Foo) {
+        x = 22_u32;
+    }
+
+    pub fn foo_value() -> Foo {
+        11_u32
+    }
 }
+use foo::*;
 
 fn foo2(mut x: Foo) {
     // no constraint on x
@@ -17,10 +25,6 @@ fn foo3(x: Foo) {
     println!("{:?}", x);
 }
 
-fn foo_value() -> Foo {
-    11_u32
-}
-
 fn main() {
     foo3(foo_value());
 }
diff --git a/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs b/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs
index 761402582e241..9dcbc75db3f12 100644
--- a/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs
+++ b/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs
@@ -2,18 +2,23 @@
 
 //@ build-pass
 
-trait T { type Item; }
+mod helper {
+    pub trait T {
+        type Item;
+    }
 
-type Alias<'a> = impl T<Item = &'a ()>;
+    pub type Alias<'a> = impl T<Item = &'a ()>;
 
-struct S;
-impl<'a> T for &'a S {
-    type Item = &'a ();
-}
+    struct S;
+    impl<'a> T for &'a S {
+        type Item = &'a ();
+    }
 
-fn filter_positive<'a>() -> Alias<'a> {
-    &S
+    pub fn filter_positive<'a>() -> Alias<'a> {
+        &S
+    }
 }
+use helper::*;
 
 fn with_positive(fun: impl Fn(Alias<'_>)) {
     fun(filter_positive());
diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs
index 55b4dc8dc232b..45f54266014d6 100644
--- a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs
+++ b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs
@@ -3,12 +3,15 @@
 
 #![feature(type_alias_impl_trait)]
 
-type X<T> = impl Clone;
+mod foo {
+    pub type X<T> = impl Clone;
 
-fn f<T: Clone>(t: T) -> X<T> {
-    t
-    //~^ ERROR the trait bound `T: Clone` is not satisfied
+    fn f<T: Clone>(t: T) -> X<T> {
+        t
+        //~^ ERROR the trait bound `T: Clone` is not satisfied
+    }
 }
+use foo::X;
 
 fn g<T>(o: Option<X<T>>) -> Option<X<T>> {
     o.clone()
diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr
index 20e478160c61b..0c937f9225380 100644
--- a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr
+++ b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr
@@ -1,13 +1,13 @@
 error[E0277]: the trait bound `T: Clone` is not satisfied
-  --> $DIR/bounds-are-checked-2.rs:9:5
+  --> $DIR/bounds-are-checked-2.rs:10:9
    |
-LL |     t
-   |     ^ the trait `Clone` is not implemented for `T`
+LL |         t
+   |         ^ the trait `Clone` is not implemented for `T`
    |
 help: consider restricting type parameter `T`
    |
-LL | type X<T: std::clone::Clone> = impl Clone;
-   |         +++++++++++++++++++
+LL |     pub type X<T: std::clone::Clone> = impl Clone;
+   |                 +++++++++++++++++++
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/type-alias-impl-trait/closure-normalization-ice-109020.rs b/tests/ui/type-alias-impl-trait/closure-normalization-ice-109020.rs
index c5ee46024f987..0dfa1f40ae6c2 100644
--- a/tests/ui/type-alias-impl-trait/closure-normalization-ice-109020.rs
+++ b/tests/ui/type-alias-impl-trait/closure-normalization-ice-109020.rs
@@ -6,7 +6,14 @@
 
 use std::marker::PhantomData;
 
-type WithEmplacableForFn<'a> = impl EmplacableFn + 'a;
+mod foo {
+    pub type WithEmplacableForFn<'a> = impl super::EmplacableFn + 'a;
+
+    fn _constrain(_: &mut ()) -> WithEmplacableForFn<'_> {
+        ()
+    }
+}
+use foo::*;
 
 fn with_emplacable_for<'a, F, R>(mut f: F) -> R
 where
@@ -16,9 +23,6 @@ where
         _: &'a (),
         _: &mut dyn FnMut(Emplacable<WithEmplacableForFn<'a>>) -> R,
     ) -> R {
-        fn _constrain(_: &mut ()) -> WithEmplacableForFn<'_> {
-            ()
-        }
         loop {}
     }
 
diff --git a/tests/ui/type-alias-impl-trait/closure_args.rs b/tests/ui/type-alias-impl-trait/closure_args.rs
index eb5ab9d67f720..0141a01aad026 100644
--- a/tests/ui/type-alias-impl-trait/closure_args.rs
+++ b/tests/ui/type-alias-impl-trait/closure_args.rs
@@ -4,20 +4,24 @@
 
 #![feature(type_alias_impl_trait)]
 
-trait Anything {}
-impl<T> Anything for T {}
-type Input = impl Anything;
-fn run<F: FnOnce(Input) -> ()>(f: F, i: Input) {
-    f(i);
+mod foo {
+    pub trait Anything {}
+    impl<T> Anything for T {}
+    pub type Input = impl Anything;
+
+    fn bop(_: Input) {
+        super::run(
+            |x: u32| {
+                println!("{x}");
+            },
+            0,
+        );
+    }
 }
+use foo::Input;
 
-fn bop(_: Input) {
-    run(
-        |x: u32| {
-            println!("{x}");
-        },
-        0,
-    );
+fn run<F: FnOnce(Input) -> ()>(f: F, i: Input) {
+    f(i);
 }
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/closure_args2.rs b/tests/ui/type-alias-impl-trait/closure_args2.rs
index 329596b19e9b9..13ac3d31d838a 100644
--- a/tests/ui/type-alias-impl-trait/closure_args2.rs
+++ b/tests/ui/type-alias-impl-trait/closure_args2.rs
@@ -2,20 +2,28 @@
 
 #![feature(type_alias_impl_trait)]
 
-trait Foo {
-    // This was reachable in https://github.com/rust-lang/rust/issues/100800
-    fn foo(&self) {
-        unreachable!()
+mod foo {
+    pub trait Foo {
+        // This was reachable in https://github.com/rust-lang/rust/issues/100800
+        fn foo(&self) {
+            unreachable!()
+        }
     }
-}
-impl<T> Foo for T {}
+    impl<T> Foo for T {}
 
-struct B;
-impl B {
-    fn foo(&self) {}
+    pub struct B;
+    impl B {
+        fn foo(&self) {}
+    }
+    pub type Input = impl Foo;
+    fn bop() -> Input {
+        super::run1(|x: B| x.foo(), B);
+        super::run2(|x: B| x.foo(), B);
+        panic!()
+    }
 }
+use foo::*;
 
-type Input = impl Foo;
 fn run1<F: FnOnce(Input)>(f: F, i: Input) {
     f(i)
 }
@@ -23,10 +31,4 @@ fn run2<F: FnOnce(B)>(f: F, i: B) {
     f(i)
 }
 
-fn bop() -> Input {
-    run1(|x: B| x.foo(), B);
-    run2(|x: B| x.foo(), B);
-    panic!()
-}
-
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/const_generic_type.no_infer.stderr b/tests/ui/type-alias-impl-trait/const_generic_type.no_infer.stderr
index 56a1020165148..55a5a3d20006b 100644
--- a/tests/ui/type-alias-impl-trait/const_generic_type.no_infer.stderr
+++ b/tests/ui/type-alias-impl-trait/const_generic_type.no_infer.stderr
@@ -1,3 +1,36 @@
+error: item does not constrain `Bar::{opaque#0}`, but has it in its signature
+  --> $DIR/const_generic_type.rs:8:10
+   |
+LL | async fn test<const N: crate::Bar>() {
+   |          ^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/const_generic_type.rs:5:12
+   |
+LL | type Bar = impl std::fmt::Display;
+   |            ^^^^^^^^^^^^^^^^^^^^^^
+
+error: item does not constrain `Bar::{opaque#0}`, but has it in its signature
+  --> $DIR/const_generic_type.rs:8:38
+   |
+LL |   async fn test<const N: crate::Bar>() {
+   |  ______________________________________^
+LL | |
+LL | |
+LL | |
+LL | |     #[cfg(infer)]
+LL | |     let x: u32 = N;
+LL | | }
+   | |_^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/const_generic_type.rs:5:12
+   |
+LL | type Bar = impl std::fmt::Display;
+   |            ^^^^^^^^^^^^^^^^^^^^^^
+
 error: unconstrained opaque type
   --> $DIR/const_generic_type.rs:5:12
    |
@@ -14,5 +47,5 @@ LL | async fn test<const N: crate::Bar>() {
    |
    = note: the only supported types are integers, `bool` and `char`
 
-error: aborting due to 2 previous errors
+error: aborting due to 4 previous errors
 
diff --git a/tests/ui/type-alias-impl-trait/const_generic_type.rs b/tests/ui/type-alias-impl-trait/const_generic_type.rs
index bfd06826f00cc..de493d04f8119 100644
--- a/tests/ui/type-alias-impl-trait/const_generic_type.rs
+++ b/tests/ui/type-alias-impl-trait/const_generic_type.rs
@@ -7,6 +7,8 @@ type Bar = impl std::fmt::Display;
 
 async fn test<const N: crate::Bar>() {
     //~^ ERROR: `Bar` is forbidden as the type of a const generic parameter
+    //[no_infer]~^^ ERROR item does not constrain
+    //[no_infer]~| ERROR item does not constrain
     #[cfg(infer)]
     let x: u32 = N;
 }
diff --git a/tests/ui/type-alias-impl-trait/constrain_inputs.rs b/tests/ui/type-alias-impl-trait/constrain_inputs.rs
index 03fb64b7b94d7..1391a2036b2e1 100644
--- a/tests/ui/type-alias-impl-trait/constrain_inputs.rs
+++ b/tests/ui/type-alias-impl-trait/constrain_inputs.rs
@@ -5,6 +5,7 @@ mod lifetime_params {
     fn defining(s: &str) -> Ty<'_> { s }
     fn execute(ty: Ty<'_>) -> &str { todo!() }
     //~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types
+    //~| ERROR item does not constrain
 
     type BadFnSig = fn(Ty<'_>) -> &str;
     //~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types
@@ -17,6 +18,7 @@ mod lifetime_params_2 {
     fn defining(s: &str) -> Ty<'_> { move || s }
     fn execute(ty: Ty<'_>) -> &str { ty() }
     //~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types
+    //~| ERROR item does not constrain
 }
 
 // regression test for https://github.com/rust-lang/rust/issues/97104
diff --git a/tests/ui/type-alias-impl-trait/constrain_inputs.stderr b/tests/ui/type-alias-impl-trait/constrain_inputs.stderr
index 93953fd06d1fd..2468fb7480b07 100644
--- a/tests/ui/type-alias-impl-trait/constrain_inputs.stderr
+++ b/tests/ui/type-alias-impl-trait/constrain_inputs.stderr
@@ -7,8 +7,21 @@ LL |     fn execute(ty: Ty<'_>) -> &str { todo!() }
    = note: lifetimes appearing in an associated or opaque type are not considered constrained
    = note: consider introducing a named lifetime parameter
 
+error: item does not constrain `lifetime_params::Ty::{opaque#0}`, but has it in its signature
+  --> $DIR/constrain_inputs.rs:6:8
+   |
+LL |     fn execute(ty: Ty<'_>) -> &str { todo!() }
+   |        ^^^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/constrain_inputs.rs:4:19
+   |
+LL |     type Ty<'a> = impl Sized;
+   |                   ^^^^^^^^^^
+
 error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
-  --> $DIR/constrain_inputs.rs:9:35
+  --> $DIR/constrain_inputs.rs:10:35
    |
 LL |     type BadFnSig = fn(Ty<'_>) -> &str;
    |                                   ^^^^
@@ -17,7 +30,7 @@ LL |     type BadFnSig = fn(Ty<'_>) -> &str;
    = note: consider introducing a named lifetime parameter
 
 error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types
-  --> $DIR/constrain_inputs.rs:11:42
+  --> $DIR/constrain_inputs.rs:12:42
    |
 LL |     type BadTraitRef = dyn Fn(Ty<'_>) -> &str;
    |                                          ^^^^
@@ -26,7 +39,7 @@ LL |     type BadTraitRef = dyn Fn(Ty<'_>) -> &str;
    = note: consider introducing a named lifetime parameter
 
 error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
-  --> $DIR/constrain_inputs.rs:18:31
+  --> $DIR/constrain_inputs.rs:19:31
    |
 LL |     fn execute(ty: Ty<'_>) -> &str { ty() }
    |                               ^^^^
@@ -34,8 +47,21 @@ LL |     fn execute(ty: Ty<'_>) -> &str { ty() }
    = note: lifetimes appearing in an associated or opaque type are not considered constrained
    = note: consider introducing a named lifetime parameter
 
+error: item does not constrain `lifetime_params_2::Ty::{opaque#0}`, but has it in its signature
+  --> $DIR/constrain_inputs.rs:19:8
+   |
+LL |     fn execute(ty: Ty<'_>) -> &str { ty() }
+   |        ^^^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/constrain_inputs.rs:17:19
+   |
+LL |     type Ty<'a> = impl FnOnce() -> &'a str;
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^^
+
 error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
-  --> $DIR/constrain_inputs.rs:27:37
+  --> $DIR/constrain_inputs.rs:29:37
    |
 LL |     type BadFnSig = fn(Ty<&str>) -> &str;
    |                                     ^^^^
@@ -44,7 +70,7 @@ LL |     type BadFnSig = fn(Ty<&str>) -> &str;
    = note: consider introducing a named lifetime parameter
 
 error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types
-  --> $DIR/constrain_inputs.rs:29:44
+  --> $DIR/constrain_inputs.rs:31:44
    |
 LL |     type BadTraitRef = dyn Fn(Ty<&str>) -> &str;
    |                                            ^^^^
@@ -52,7 +78,7 @@ LL |     type BadTraitRef = dyn Fn(Ty<&str>) -> &str;
    = note: lifetimes appearing in an associated or opaque type are not considered constrained
    = note: consider introducing a named lifetime parameter
 
-error: aborting due to 6 previous errors
+error: aborting due to 8 previous errors
 
 Some errors have detailed explanations: E0581, E0582.
 For more information about an error, try `rustc --explain E0581`.
diff --git a/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs b/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs
index 7e743fc09dd5f..db9c2cc096ab3 100644
--- a/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs
+++ b/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs
@@ -3,10 +3,12 @@
 
 #![feature(type_alias_impl_trait)]
 
-type Debuggable = impl core::fmt::Debug;
+mod bar {
+    pub type Debuggable = impl core::fmt::Debug;
+    fn foo() -> Debuggable {
+        0u32
+    }
+}
+use bar::Debuggable;
 
 static mut TEST: Option<Debuggable> = None;
-
-fn foo() -> Debuggable {
-    0u32
-}
diff --git a/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.rs b/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.rs
index 023991c29d090..9ed010f2293ec 100644
--- a/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.rs
+++ b/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.rs
@@ -23,9 +23,11 @@ impl<F: for<'a> Fn(&'a ()) -> StateWidget<'a>> Widget<()> for StatefulWidget<F>
     type State = ();
 
     fn make_state(&self) -> Self::State {}
+    //~^ ERROR item does not constrain
 }
 
 fn new_stateful_widget<F: for<'a> Fn(&'a ()) -> StateWidget<'a>>(build: F) -> impl Widget<()> {
+    //~^ ERROR item does not constrain
     StatefulWidget(build)
     //~^ ERROR expected generic lifetime parameter, found `'a`
 }
diff --git a/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.stderr b/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.stderr
index 0c76feae198ba..9a3f4ae4c1c31 100644
--- a/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.stderr
+++ b/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.stderr
@@ -1,5 +1,31 @@
+error: item does not constrain `StateWidget::{opaque#0}`, but has it in its signature
+  --> $DIR/failed-to-normalize-ice-99945.rs:25:8
+   |
+LL |     fn make_state(&self) -> Self::State {}
+   |        ^^^^^^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/failed-to-normalize-ice-99945.rs:20:24
+   |
+LL | type StateWidget<'a> = impl Widget<&'a ()>;
+   |                        ^^^^^^^^^^^^^^^^^^^
+
+error: item does not constrain `StateWidget::{opaque#0}`, but has it in its signature
+  --> $DIR/failed-to-normalize-ice-99945.rs:29:4
+   |
+LL | fn new_stateful_widget<F: for<'a> Fn(&'a ()) -> StateWidget<'a>>(build: F) -> impl Widget<()> {
+   |    ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/failed-to-normalize-ice-99945.rs:20:24
+   |
+LL | type StateWidget<'a> = impl Widget<&'a ()>;
+   |                        ^^^^^^^^^^^^^^^^^^^
+
 error[E0308]: mismatched types
-  --> $DIR/failed-to-normalize-ice-99945.rs:34:29
+  --> $DIR/failed-to-normalize-ice-99945.rs:36:29
    |
 LL | type StateWidget<'a> = impl Widget<&'a ()>;
    |                        ------------------- the expected opaque type
@@ -11,7 +37,7 @@ LL |     new_stateful_widget(|_| ()).make_state();
                 found unit type `()`
 
 error[E0792]: expected generic lifetime parameter, found `'a`
-  --> $DIR/failed-to-normalize-ice-99945.rs:29:5
+  --> $DIR/failed-to-normalize-ice-99945.rs:31:5
    |
 LL | type StateWidget<'a> = impl Widget<&'a ()>;
    |                  -- this generic parameter must be used with a generic lifetime parameter
@@ -19,7 +45,7 @@ LL | type StateWidget<'a> = impl Widget<&'a ()>;
 LL |     StatefulWidget(build)
    |     ^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 2 previous errors
+error: aborting due to 4 previous errors
 
 Some errors have detailed explanations: E0308, E0792.
 For more information about an error, try `rustc --explain E0308`.
diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs b/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs
index 3b54fb7ea999f..96c905ef3a903 100644
--- a/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs
+++ b/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs
@@ -17,10 +17,12 @@ async fn operation(_: &mut ()) -> () {
 }
 
 async fn call<F>(_f: F)
+//~^ ERROR item does not constrain
 where
     for<'any> F: FnMut(&'any mut ()) -> FutNothing<'any>,
 {
     //~^ ERROR: expected generic lifetime parameter, found `'any`
+    //~| ERROR item does not constrain
 }
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr b/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr
index c41ed0642a46c..7df1a08bc883d 100644
--- a/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr
+++ b/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr
@@ -1,3 +1,32 @@
+error: item does not constrain `FutNothing::{opaque#0}`, but has it in its signature
+  --> $DIR/hkl_forbidden4.rs:19:10
+   |
+LL | async fn call<F>(_f: F)
+   |          ^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/hkl_forbidden4.rs:10:23
+   |
+LL | type FutNothing<'a> = impl 'a + Future<Output = ()>;
+   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: item does not constrain `FutNothing::{opaque#0}`, but has it in its signature
+  --> $DIR/hkl_forbidden4.rs:23:1
+   |
+LL | / {
+LL | |
+LL | |
+LL | | }
+   | |_^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/hkl_forbidden4.rs:10:23
+   |
+LL | type FutNothing<'a> = impl 'a + Future<Output = ()>;
+   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
 error: unconstrained opaque type
   --> $DIR/hkl_forbidden4.rs:10:23
    |
@@ -16,13 +45,14 @@ LL |     call(operation).await
    |     ^^^^^^^^^^^^^^^
 
 error[E0792]: expected generic lifetime parameter, found `'any`
-  --> $DIR/hkl_forbidden4.rs:22:1
+  --> $DIR/hkl_forbidden4.rs:23:1
    |
 LL |   type FutNothing<'a> = impl 'a + Future<Output = ()>;
    |                   -- this generic parameter must be used with a generic lifetime parameter
 ...
 LL | / {
 LL | |
+LL | |
 LL | | }
    | |_^
 
@@ -38,6 +68,6 @@ note: previous use here
 LL |     call(operation).await
    |     ^^^^^^^^^^^^^^^
 
-error: aborting due to 4 previous errors
+error: aborting due to 6 previous errors
 
 For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs
index fc71d0d61ff14..0ee188d825f0d 100644
--- a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs
+++ b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs
@@ -6,7 +6,6 @@
 
 use std::marker::PhantomData;
 
-
 trait MyIndex<T> {
     type O;
     fn my_index(self) -> Self::O;
@@ -16,7 +15,6 @@ trait MyFrom<T>: Sized {
     fn my_from(value: T) -> Result<Self, Self::Error>;
 }
 
-
 trait F {}
 impl F for () {}
 type DummyT<T> = impl F;
@@ -28,6 +26,7 @@ struct Scope<T>(Phantom2<DummyT<T>>);
 
 impl<T> Scope<T> {
     fn new() -> Self {
+        //~^ ERROR item does not constrain
         unimplemented!()
     }
 }
@@ -43,6 +42,7 @@ impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<DummyT<T>> for Scope<U> {
     //~^ ERROR the type parameter `T` is not constrained by the impl
     type O = T;
     fn my_index(self) -> Self::O {
+        //~^ ERROR item does not constrain
         MyFrom::my_from(self.0).ok().unwrap()
     }
 }
diff --git a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr
index a39f77ce17f61..22c776e171c2f 100644
--- a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr
+++ b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr
@@ -1,9 +1,35 @@
+error: item does not constrain `DummyT::{opaque#0}`, but has it in its signature
+  --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:28:8
+   |
+LL |     fn new() -> Self {
+   |        ^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:20:18
+   |
+LL | type DummyT<T> = impl F;
+   |                  ^^^^^^
+
+error: item does not constrain `DummyT::{opaque#0}`, but has it in its signature
+  --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:44:8
+   |
+LL |     fn my_index(self) -> Self::O {
+   |        ^^^^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:20:18
+   |
+LL | type DummyT<T> = impl F;
+   |                  ^^^^^^
+
 error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:42:6
+  --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:41:6
    |
 LL | impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<DummyT<T>> for Scope<U> {
    |      ^ unconstrained type parameter
 
-error: aborting due to 1 previous error
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0207`.
diff --git a/tests/ui/type-alias-impl-trait/implied_bounds.rs b/tests/ui/type-alias-impl-trait/implied_bounds.rs
index 53cbf8d229006..269c0eff025d2 100644
--- a/tests/ui/type-alias-impl-trait/implied_bounds.rs
+++ b/tests/ui/type-alias-impl-trait/implied_bounds.rs
@@ -1,7 +1,11 @@
 #![feature(type_alias_impl_trait)]
 
-type WithLifetime<'a> = impl Equals<SelfType = ()>;
-fn _defining_use<'a>() -> WithLifetime<'a> {}
+mod foo {
+    use super::Equals;
+    pub type WithLifetime<'a> = impl Equals<SelfType = ()>;
+    fn _defining_use<'a>() -> WithLifetime<'a> {}
+}
+use foo::WithLifetime;
 
 trait Convert<'a> {
     type Witness;
diff --git a/tests/ui/type-alias-impl-trait/implied_bounds.stderr b/tests/ui/type-alias-impl-trait/implied_bounds.stderr
index 64a203fe4658e..23f1141e54447 100644
--- a/tests/ui/type-alias-impl-trait/implied_bounds.stderr
+++ b/tests/ui/type-alias-impl-trait/implied_bounds.stderr
@@ -1,5 +1,5 @@
 error: lifetime may not live long enough
-  --> $DIR/implied_bounds.rs:17:9
+  --> $DIR/implied_bounds.rs:21:9
    |
 LL | impl<'a> Convert<'a> for () {
    |      -- lifetime `'a` defined here
diff --git a/tests/ui/type-alias-impl-trait/implied_bounds2.rs b/tests/ui/type-alias-impl-trait/implied_bounds2.rs
index effedb954c359..845476ef97419 100644
--- a/tests/ui/type-alias-impl-trait/implied_bounds2.rs
+++ b/tests/ui/type-alias-impl-trait/implied_bounds2.rs
@@ -2,9 +2,17 @@
 
 #![feature(type_alias_impl_trait)]
 
-type Ty<'a, A> = impl Sized + 'a;
-fn defining<'a, A>() -> Ty<'a, A> {}
-fn assert_static<T: 'static>() {}
-fn test<'a, A>() where Ty<'a, A>: 'static, { assert_static::<Ty<'a, A>>() }
+mod helper {
+    pub type Ty<'a, A> = impl Sized + 'a;
+    fn defining<'a, A>() -> Ty<'a, A> {}
+    pub fn assert_static<T: 'static>() {}
+}
+use helper::*;
+fn test<'a, A>()
+where
+    Ty<'a, A>: 'static,
+{
+    assert_static::<Ty<'a, A>>()
+}
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/implied_bounds_from_types.rs b/tests/ui/type-alias-impl-trait/implied_bounds_from_types.rs
index 239fcc6a5e6f3..76a63741e18e5 100644
--- a/tests/ui/type-alias-impl-trait/implied_bounds_from_types.rs
+++ b/tests/ui/type-alias-impl-trait/implied_bounds_from_types.rs
@@ -1,7 +1,11 @@
 #![feature(type_alias_impl_trait)]
 
-type WithLifetime<T> = impl Equals<SelfType = ()>;
-fn _defining_use<T>() -> WithLifetime<T> {}
+mod foo {
+    use super::Equals;
+    pub type WithLifetime<T> = impl Equals<SelfType = ()>;
+    fn _defining_use<T>() -> WithLifetime<T> {}
+}
+use foo::WithLifetime;
 
 trait Convert<'a> {
     type Witness;
@@ -12,7 +16,6 @@ impl<'a> Convert<'a> for () {
     type Witness = WithLifetime<&'a ()>;
 
     fn convert<'b, T: ?Sized>(_proof: &'b WithLifetime<&'a ()>, x: &'a T) -> &'b T {
-        //~^ ERROR non-defining opaque type use
         // compiler used to think it gets to assume 'a: 'b here because
         // of the `&'b WithLifetime<&'a ()>` argument
         x
diff --git a/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr b/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr
index 23dbf0e8f60c3..391a8a75786af 100644
--- a/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr
+++ b/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr
@@ -1,17 +1,5 @@
-error[E0792]: non-defining opaque type use in defining scope
-  --> $DIR/implied_bounds_from_types.rs:14:39
-   |
-LL |     fn convert<'b, T: ?Sized>(_proof: &'b WithLifetime<&'a ()>, x: &'a T) -> &'b T {
-   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^ argument `&'a ()` is not a generic parameter
-   |
-note: for this opaque type
-  --> $DIR/implied_bounds_from_types.rs:3:24
-   |
-LL | type WithLifetime<T> = impl Equals<SelfType = ()>;
-   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
-
 error: lifetime may not live long enough
-  --> $DIR/implied_bounds_from_types.rs:18:9
+  --> $DIR/implied_bounds_from_types.rs:21:9
    |
 LL | impl<'a> Convert<'a> for () {
    |      -- lifetime `'a` defined here
@@ -24,6 +12,5 @@ LL |         x
    |
    = help: consider adding the following bound: `'a: 'b`
 
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs
index 469a493b0b353..fb251e9bde155 100644
--- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs
+++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs
@@ -1,40 +1,68 @@
 #![feature(type_alias_impl_trait)]
 
 mod test_lifetime_param {
-    type Ty<'a> = impl Sized;
-    fn defining(a: &str) -> Ty<'_> { a }
-    fn assert_static<'a: 'static>() {}
-    fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
+    pub type Ty<'a> = impl Sized;
+    fn defining(a: &str) -> Ty<'_> {
+        a
+    }
+    pub fn assert_static<'a: 'static>() {}
+}
+fn test_lifetime_param_test<'a>()
+where
+    test_lifetime_param::Ty<'a>: 'static,
+{
+    test_lifetime_param::assert_static::<'a>()
     //~^ ERROR: lifetime may not live long enough
 }
 
 mod test_higher_kinded_lifetime_param {
-    type Ty<'a> = impl Sized;
-    fn defining(a: &str) -> Ty<'_> { a }
-    fn assert_static<'a: 'static>() {}
-    fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
+    pub type Ty<'a> = impl Sized + 'a;
+    fn defining(a: &str) -> Ty<'_> {
+        a
+    }
+    pub fn assert_static<'a: 'static>() {}
+}
+fn test_higher_kinded_lifetime_param_test<'a>()
+where
+    for<'b> test_higher_kinded_lifetime_param::Ty<'b>: 'a,
+{
+    test_higher_kinded_lifetime_param::assert_static::<'a>()
     //~^ ERROR: lifetime may not live long enough
 }
 
 mod test_higher_kinded_lifetime_param2 {
     fn assert_static<'a: 'static>() {}
-    fn test<'a>() { assert_static::<'a>() }
-    //~^ ERROR: lifetime may not live long enough
+    fn test<'a>() {
+        assert_static::<'a>()
+        //~^ ERROR: lifetime may not live long enough
+    }
 }
 
 mod test_type_param {
-    type Ty<A> = impl Sized;
-    fn defining<A>(s: A) -> Ty<A> { s }
-    fn assert_static<A: 'static>() {}
-    fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
+    pub type Ty<A> = impl Sized;
+    fn defining<A>(s: A) -> Ty<A> {
+        s
+    }
+    pub fn assert_static<A: 'static>() {}
+}
+fn test_type_param_test<A>()
+where
+    test_type_param::Ty<A>: 'static,
+{
+    test_type_param::assert_static::<A>()
     //~^ ERROR: parameter type `A` may not live long enough
 }
 
 mod test_implied_from_fn_sig {
-    type Opaque<T: 'static> = impl Sized;
-    fn defining<T: 'static>() -> Opaque<T> {}
+    mod foo {
+        pub type Opaque<T: 'static> = impl Sized;
+        fn defining<T: 'static>() -> Opaque<T> {}
+    }
     fn assert_static<T: 'static>() {}
-    fn test<T>(_: Opaque<T>) { assert_static::<T>(); }
+
+    fn test<T>(_: foo::Opaque<T>) {
+        assert_static::<T>();
+    }
 }
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr
index d6dd20739b7af..b7c9c131c7d1a 100644
--- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr
+++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr
@@ -1,36 +1,42 @@
 error: lifetime may not live long enough
-  --> $DIR/implied_lifetime_wf_check3.rs:7:43
+  --> $DIR/implied_lifetime_wf_check3.rs:14:5
    |
-LL |     fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
-   |             -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
+LL | fn test_lifetime_param_test<'a>()
+   |                             -- lifetime `'a` defined here
+...
+LL |     test_lifetime_param::assert_static::<'a>()
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
 
 error: lifetime may not live long enough
-  --> $DIR/implied_lifetime_wf_check3.rs:15:46
+  --> $DIR/implied_lifetime_wf_check3.rs:29:5
    |
-LL |     fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
-   |             -- lifetime `'a` defined here    ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
+LL | fn test_higher_kinded_lifetime_param_test<'a>()
+   |                                           -- lifetime `'a` defined here
+...
+LL |     test_higher_kinded_lifetime_param::assert_static::<'a>()
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
 
 error: lifetime may not live long enough
-  --> $DIR/implied_lifetime_wf_check3.rs:21:21
+  --> $DIR/implied_lifetime_wf_check3.rs:36:9
    |
-LL |     fn test<'a>() { assert_static::<'a>() }
-   |             --      ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
-   |             |
-   |             lifetime `'a` defined here
+LL |     fn test<'a>() {
+   |             -- lifetime `'a` defined here
+LL |         assert_static::<'a>()
+   |         ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
 
 error[E0310]: the parameter type `A` may not live long enough
-  --> $DIR/implied_lifetime_wf_check3.rs:29:41
+  --> $DIR/implied_lifetime_wf_check3.rs:52:5
    |
-LL |     fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
-   |                                         ^^^^^^^^^^^^^^^^^^
-   |                                         |
-   |                                         the parameter type `A` must be valid for the static lifetime...
-   |                                         ...so that the type `A` will meet its required lifetime bounds
+LL |     test_type_param::assert_static::<A>()
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |     |
+   |     the parameter type `A` must be valid for the static lifetime...
+   |     ...so that the type `A` will meet its required lifetime bounds
    |
 help: consider adding an explicit lifetime bound
    |
-LL |     fn test<A: 'static>() where Ty<A>: 'static { assert_static::<A>() }
-   |              +++++++++
+LL | fn test_type_param_test<A: 'static>()
+   |                          +++++++++
 
 error: aborting due to 4 previous errors
 
diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs
index 1a5daa13458c6..f8b09814caac3 100644
--- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs
+++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs
@@ -1,11 +1,20 @@
 #![feature(type_alias_impl_trait)]
 
 mod test_type_param_static {
-    type Ty<A> = impl Sized + 'static;
+    pub type Ty<A> = impl Sized + 'static;
     //~^ ERROR: the parameter type `A` may not live long enough
-    fn defining<A: 'static>(s: A) -> Ty<A> { s }
-    fn assert_static<A: 'static>() {}
-    fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
+    fn defining<A: 'static>(s: A) -> Ty<A> {
+        s
+    }
+    pub fn assert_static<A: 'static>() {}
+}
+use test_type_param_static::*;
+
+fn test<A>()
+where
+    Ty<A>: 'static,
+{
+    assert_static::<A>()
     //~^ ERROR: the parameter type `A` may not live long enough
 }
 
diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr
index d1c06330c15e0..f2e5e95b96f04 100644
--- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr
+++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr
@@ -1,30 +1,30 @@
 error[E0310]: the parameter type `A` may not live long enough
-  --> $DIR/implied_lifetime_wf_check4_static.rs:4:18
+  --> $DIR/implied_lifetime_wf_check4_static.rs:4:22
    |
-LL |     type Ty<A> = impl Sized + 'static;
-   |                  ^^^^^^^^^^^^^^^^^^^^
-   |                  |
-   |                  the parameter type `A` must be valid for the static lifetime...
-   |                  ...so that the type `A` will meet its required lifetime bounds
+LL |     pub type Ty<A> = impl Sized + 'static;
+   |                      ^^^^^^^^^^^^^^^^^^^^
+   |                      |
+   |                      the parameter type `A` must be valid for the static lifetime...
+   |                      ...so that the type `A` will meet its required lifetime bounds
    |
 help: consider adding an explicit lifetime bound
    |
-LL |     type Ty<A: 'static> = impl Sized + 'static;
-   |              +++++++++
+LL |     pub type Ty<A: 'static> = impl Sized + 'static;
+   |                  +++++++++
 
 error[E0310]: the parameter type `A` may not live long enough
-  --> $DIR/implied_lifetime_wf_check4_static.rs:8:41
+  --> $DIR/implied_lifetime_wf_check4_static.rs:17:5
    |
-LL |     fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
-   |                                         ^^^^^^^^^^^^^^^^^^
-   |                                         |
-   |                                         the parameter type `A` must be valid for the static lifetime...
-   |                                         ...so that the type `A` will meet its required lifetime bounds
+LL |     assert_static::<A>()
+   |     ^^^^^^^^^^^^^^^^^^
+   |     |
+   |     the parameter type `A` must be valid for the static lifetime...
+   |     ...so that the type `A` will meet its required lifetime bounds
    |
 help: consider adding an explicit lifetime bound
    |
-LL |     fn test<A: 'static>() where Ty<A>: 'static { assert_static::<A>() }
-   |              +++++++++
+LL | fn test<A: 'static>()
+   |          +++++++++
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/type-alias-impl-trait/issue-101750.rs b/tests/ui/type-alias-impl-trait/issue-101750.rs
index 1c5261b7a791a..9367be8ca07fd 100644
--- a/tests/ui/type-alias-impl-trait/issue-101750.rs
+++ b/tests/ui/type-alias-impl-trait/issue-101750.rs
@@ -2,17 +2,21 @@
 
 //@ check-pass
 
-trait Trait {}
+mod foo {
+    pub trait Trait {}
 
-type TAIT = impl Trait;
+    pub type TAIT = impl Trait;
 
-struct Concrete;
-impl Trait for Concrete {}
+    pub struct Concrete;
+    impl Trait for Concrete {}
 
-fn tait() -> TAIT {
-    Concrete
+    pub fn tait() -> TAIT {
+        Concrete
+    }
 }
 
+use foo::*;
+
 trait OuterTrait {
     type Item;
 }
@@ -24,9 +28,7 @@ impl<T> OuterTrait for Dummy<T> {
 }
 
 fn tait_and_impl_trait() -> impl OuterTrait<Item = (TAIT, impl Trait)> {
-    Dummy {
-        t: (tait(), Concrete),
-    }
+    Dummy { t: (tait(), Concrete) }
 }
 
 fn tait_and_dyn_trait() -> impl OuterTrait<Item = (TAIT, Box<dyn Trait>)> {
diff --git a/tests/ui/type-alias-impl-trait/issue-109054.rs b/tests/ui/type-alias-impl-trait/issue-109054.rs
index 51f30779cd948..d3eb652159346 100644
--- a/tests/ui/type-alias-impl-trait/issue-109054.rs
+++ b/tests/ui/type-alias-impl-trait/issue-109054.rs
@@ -11,6 +11,7 @@ impl std::ops::Deref for CallMe {
     type Target = FnType;
 
     fn deref(&self) -> &Self::Target {
+        //~^ ERROR: item does not constrain `ReturnType
         fn inner(val: &u32) -> ReturnType {
             async move { *val * 2 }
         }
diff --git a/tests/ui/type-alias-impl-trait/issue-109054.stderr b/tests/ui/type-alias-impl-trait/issue-109054.stderr
index a099b7d8b8a63..2a4aa63bb8ca1 100644
--- a/tests/ui/type-alias-impl-trait/issue-109054.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-109054.stderr
@@ -1,5 +1,18 @@
+error: item does not constrain `ReturnType::{opaque#0}`, but has it in its signature
+  --> $DIR/issue-109054.rs:13:8
+   |
+LL |     fn deref(&self) -> &Self::Target {
+   |        ^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/issue-109054.rs:7:23
+   |
+LL | type ReturnType<'a> = impl std::future::Future<Output = u32> + 'a;
+   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
 error[E0792]: expected generic lifetime parameter, found `'_`
-  --> $DIR/issue-109054.rs:18:9
+  --> $DIR/issue-109054.rs:19:9
    |
 LL | type ReturnType<'a> = impl std::future::Future<Output = u32> + 'a;
    |                 -- this generic parameter must be used with a generic lifetime parameter
@@ -7,6 +20,6 @@ LL | type ReturnType<'a> = impl std::future::Future<Output = u32> + 'a;
 LL |         &inner
    |         ^^^^^^
 
-error: aborting due to 1 previous error
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/issue-53092.rs b/tests/ui/type-alias-impl-trait/issue-53092.rs
index 34bab02608852..83b51227aaae9 100644
--- a/tests/ui/type-alias-impl-trait/issue-53092.rs
+++ b/tests/ui/type-alias-impl-trait/issue-53092.rs
@@ -1,7 +1,14 @@
 #![feature(type_alias_impl_trait)]
 #![allow(dead_code)]
 
-type Bug<T, U> = impl Fn(T) -> U + Copy;
+mod bug {
+    pub type Bug<T, U> = impl Fn(T) -> U + Copy;
+
+    fn make_bug<T, U: From<T>>() -> Bug<T, U> {
+        |x| x.into() //~ ERROR the trait bound `U: From<T>` is not satisfied
+    }
+}
+use bug::Bug;
 
 union Moo {
     x: Bug<u8, ()>,
@@ -9,11 +16,6 @@ union Moo {
 }
 
 const CONST_BUG: Bug<u8, ()> = unsafe { Moo { y: () }.x };
-//~^ ERROR non-defining opaque type use
-
-fn make_bug<T, U: From<T>>() -> Bug<T, U> {
-    |x| x.into() //~ ERROR the trait bound `U: From<T>` is not satisfied
-}
 
 fn main() {
     CONST_BUG(0);
diff --git a/tests/ui/type-alias-impl-trait/issue-53092.stderr b/tests/ui/type-alias-impl-trait/issue-53092.stderr
index 0c4cacd665503..f04750866c762 100644
--- a/tests/ui/type-alias-impl-trait/issue-53092.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-53092.stderr
@@ -1,32 +1,19 @@
-error[E0792]: non-defining opaque type use in defining scope
-  --> $DIR/issue-53092.rs:11:18
-   |
-LL | const CONST_BUG: Bug<u8, ()> = unsafe { Moo { y: () }.x };
-   |                  ^^^^^^^^^^^ argument `u8` is not a generic parameter
-   |
-note: for this opaque type
-  --> $DIR/issue-53092.rs:4:18
-   |
-LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
-   |                  ^^^^^^^^^^^^^^^^^^^^^^
-
 error[E0277]: the trait bound `U: From<T>` is not satisfied
-  --> $DIR/issue-53092.rs:15:5
+  --> $DIR/issue-53092.rs:8:9
    |
-LL |     |x| x.into()
-   |     ^^^^^^^^^^^^ the trait `From<T>` is not implemented for `U`
+LL |         |x| x.into()
+   |         ^^^^^^^^^^^^ the trait `From<T>` is not implemented for `U`
    |
 note: required by a bound in `make_bug`
-  --> $DIR/issue-53092.rs:14:19
+  --> $DIR/issue-53092.rs:7:23
    |
-LL | fn make_bug<T, U: From<T>>() -> Bug<T, U> {
-   |                   ^^^^^^^ required by this bound in `make_bug`
+LL |     fn make_bug<T, U: From<T>>() -> Bug<T, U> {
+   |                       ^^^^^^^ required by this bound in `make_bug`
 help: consider restricting type parameter `U`
    |
-LL | type Bug<T, U: std::convert::From<T>> = impl Fn(T) -> U + Copy;
-   |              +++++++++++++++++++++++
+LL |     pub type Bug<T, U: std::convert::From<T>> = impl Fn(T) -> U + Copy;
+   |                      +++++++++++++++++++++++
 
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
 
-Some errors have detailed explanations: E0277, E0792.
-For more information about an error, try `rustc --explain E0277`.
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/type-alias-impl-trait/issue-53096.rs b/tests/ui/type-alias-impl-trait/issue-53096.rs
index 007dcf3bcb680..590fce84fc9f1 100644
--- a/tests/ui/type-alias-impl-trait/issue-53096.rs
+++ b/tests/ui/type-alias-impl-trait/issue-53096.rs
@@ -1,10 +1,13 @@
 #![feature(rustc_attrs)]
 #![feature(type_alias_impl_trait)]
 
-type Foo = impl Fn() -> usize;
-const fn bar() -> Foo {
-    || 0usize
+mod foo {
+    pub type Foo = impl Fn() -> usize;
+    pub const fn bar() -> Foo {
+        || 0usize
+    }
 }
+use foo::*;
 const BAZR: Foo = bar();
 
 #[rustc_error]
diff --git a/tests/ui/type-alias-impl-trait/issue-53096.stderr b/tests/ui/type-alias-impl-trait/issue-53096.stderr
index fba1802efd202..0a744e7be9cbd 100644
--- a/tests/ui/type-alias-impl-trait/issue-53096.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-53096.stderr
@@ -1,5 +1,5 @@
 error: fatal error triggered by #[rustc_error]
-  --> $DIR/issue-53096.rs:11:1
+  --> $DIR/issue-53096.rs:14:1
    |
 LL | fn main() {}
    | ^^^^^^^^^
diff --git a/tests/ui/type-alias-impl-trait/issue-58951.rs b/tests/ui/type-alias-impl-trait/issue-58951.rs
index 8a9e586eb25b2..b9f27b031c72f 100644
--- a/tests/ui/type-alias-impl-trait/issue-58951.rs
+++ b/tests/ui/type-alias-impl-trait/issue-58951.rs
@@ -2,14 +2,16 @@
 
 #![feature(type_alias_impl_trait)]
 
-type A = impl Iterator;
+mod helper {
+    pub type A = impl Iterator;
 
-fn def_a() -> A {
-    0..1
+    pub fn def_a() -> A {
+        0..1
+    }
 }
 
 pub fn use_a() {
-    def_a().map(|x| x);
+    helper::def_a().map(|x| x);
 }
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-60407.rs b/tests/ui/type-alias-impl-trait/issue-60407.rs
index b833429c76922..6c7c76b5ac728 100644
--- a/tests/ui/type-alias-impl-trait/issue-60407.rs
+++ b/tests/ui/type-alias-impl-trait/issue-60407.rs
@@ -1,6 +1,13 @@
 #![feature(type_alias_impl_trait, rustc_attrs)]
 
-type Debuggable = impl core::fmt::Debug;
+mod bar {
+    pub type Debuggable = impl core::fmt::Debug;
+
+    pub fn foo() -> Debuggable {
+        0u32
+    }
+}
+use bar::*;
 
 static mut TEST: Option<Debuggable> = None;
 
@@ -9,7 +16,3 @@ fn main() {
     //~^ ERROR
     unsafe { TEST = Some(foo()) }
 }
-
-fn foo() -> Debuggable {
-    0u32
-}
diff --git a/tests/ui/type-alias-impl-trait/issue-60407.stderr b/tests/ui/type-alias-impl-trait/issue-60407.stderr
index 583156b9f7cb6..bba9092e97756 100644
--- a/tests/ui/type-alias-impl-trait/issue-60407.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-60407.stderr
@@ -1,5 +1,5 @@
 error: fatal error triggered by #[rustc_error]
-  --> $DIR/issue-60407.rs:8:1
+  --> $DIR/issue-60407.rs:15:1
    |
 LL | fn main() {
    | ^^^^^^^^^
diff --git a/tests/ui/type-alias-impl-trait/issue-63355.rs b/tests/ui/type-alias-impl-trait/issue-63355.rs
index 0c977b3099490..a0d0355b5af5c 100644
--- a/tests/ui/type-alias-impl-trait/issue-63355.rs
+++ b/tests/ui/type-alias-impl-trait/issue-63355.rs
@@ -1,5 +1,4 @@
 #![feature(type_alias_impl_trait)]
-//@ check-pass
 
 pub trait Foo {}
 
@@ -39,6 +38,7 @@ impl Baz for () {
     }
 
     fn bar() -> Self::Bar {
+        //~^ ERROR: item does not constrain `FooImpl::{opaque#0}`
         ()
     }
 }
diff --git a/tests/ui/type-alias-impl-trait/issue-63355.stderr b/tests/ui/type-alias-impl-trait/issue-63355.stderr
new file mode 100644
index 0000000000000..6755c03805607
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/issue-63355.stderr
@@ -0,0 +1,15 @@
+error: item does not constrain `FooImpl::{opaque#0}`, but has it in its signature
+  --> $DIR/issue-63355.rs:40:8
+   |
+LL |     fn bar() -> Self::Bar {
+   |        ^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/issue-63355.rs:29:20
+   |
+LL | pub type FooImpl = impl Foo;
+   |                    ^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs b/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
index 61251d7f6da91..f98ce4a426c46 100644
--- a/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
+++ b/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
@@ -1,19 +1,21 @@
 //@ check-pass
 
 #![feature(type_alias_impl_trait, rustc_attrs)]
+mod foo {
+    pub type T = impl Sized;
+    // The concrete type referred by impl-trait-type-alias(`T`) is guaranteed
+    // to be the same as where it occurs, whereas `impl Trait`'s instance is location sensitive;
+    // so difference assertion should not be declared on impl-trait-type-alias's instances.
+    // for details, check RFC-2515:
+    // https://github.com/rust-lang/rfcs/blob/master/text/2515-type_alias_impl_trait.md
 
-type T = impl Sized;
-// The concrete type referred by impl-trait-type-alias(`T`) is guaranteed
-// to be the same as where it occurs, whereas `impl Trait`'s instance is location sensitive;
-// so difference assertion should not be declared on impl-trait-type-alias's instances.
-// for details, check RFC-2515:
-// https://github.com/rust-lang/rfcs/blob/master/text/2515-type_alias_impl_trait.md
+    fn bop(_: T) {
+        super::take(|| {});
+        super::take(|| {});
+    }
+}
+use foo::*;
 
 fn take(_: fn() -> T) {}
 
-fn bop(_: T) {
-    take(|| {});
-    take(|| {});
-}
-
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-65918.rs b/tests/ui/type-alias-impl-trait/issue-65918.rs
index c81650876c8ad..275b9717cef33 100644
--- a/tests/ui/type-alias-impl-trait/issue-65918.rs
+++ b/tests/ui/type-alias-impl-trait/issue-65918.rs
@@ -15,10 +15,13 @@ trait MyFrom<T>: Sized {
 }
 
 /* MCVE starts here */
-trait F {}
-impl F for () {}
-type DummyT<T> = impl F;
-fn _dummy_t<T>() -> DummyT<T> {}
+mod f {
+    pub trait F {}
+    impl F for () {}
+    pub type DummyT<T> = impl F;
+    fn _dummy_t<T>() -> DummyT<T> {}
+}
+use f::DummyT;
 
 struct Phantom1<T>(PhantomData<T>);
 struct Phantom2<T>(PhantomData<T>);
diff --git a/tests/ui/type-alias-impl-trait/issue-72793.rs b/tests/ui/type-alias-impl-trait/issue-72793.rs
index 9389517e37bde..0353b7f3787bc 100644
--- a/tests/ui/type-alias-impl-trait/issue-72793.rs
+++ b/tests/ui/type-alias-impl-trait/issue-72793.rs
@@ -3,19 +3,25 @@
 
 #![feature(type_alias_impl_trait)]
 
-trait T { type Item; }
+mod foo {
+    pub trait T {
+        type Item;
+    }
 
-type Alias<'a> = impl T<Item = &'a ()>;
+    pub type Alias<'a> = impl T<Item = &'a ()>;
 
-struct S;
-impl<'a> T for &'a S {
-    type Item = &'a ();
-}
+    struct S;
+    impl<'a> T for &'a S {
+        type Item = &'a ();
+    }
 
-fn filter_positive<'a>() -> Alias<'a> {
-    &S
+    pub fn filter_positive<'a>() -> Alias<'a> {
+        &S
+    }
 }
 
+use foo::*;
+
 fn with_positive(fun: impl Fn(Alias<'_>)) {
     fun(filter_positive());
 }
diff --git a/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs b/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs
index 9ceef0139f05f..90ab4fd8d9773 100644
--- a/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs
+++ b/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs
@@ -7,11 +7,18 @@
 //@ check-pass
 #![feature(type_alias_impl_trait)]
 
+mod g {
+    pub trait Dummy {}
+    impl Dummy for () {}
+    pub type F = impl Dummy;
+    pub fn f() -> F {}
+}
+use g::*;
+
 trait Test {
     fn test(self);
 }
 
-
 impl Test for define::F {
     fn test(self) {}
 }
diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr
index a7ff097e8bf38..2b064dcfc31a5 100644
--- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr
@@ -1,5 +1,18 @@
+error: item does not constrain `Bar::{opaque#0}`, but has it in its signature
+  --> $DIR/issue-84660-unsoundness.rs:22:8
+   |
+LL |     fn convert(_i: In) -> Self::Out {
+   |        ^^^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/issue-84660-unsoundness.rs:12:12
+   |
+LL | type Bar = impl Foo;
+   |            ^^^^^^^^
+
 error[E0119]: conflicting implementations of trait `Trait<Bar, _>`
-  --> $DIR/issue-84660-unsoundness.rs:28:1
+  --> $DIR/issue-84660-unsoundness.rs:29:1
    |
 LL | impl<In, Out> Trait<Bar, In> for Out {
    | ------------------------------------ first implementation here
@@ -7,6 +20,6 @@ LL | impl<In, Out> Trait<Bar, In> for Out {
 LL | impl<In, Out> Trait<(), In> for Out {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
 
-error: aborting due to 1 previous error
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0119`.
diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr
index 607f0b062abd7..4c8a25edfedbe 100644
--- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr
@@ -4,12 +4,13 @@ error[E0284]: type annotations needed: cannot satisfy `<Out as Trait<Bar, In>>::
 LL |       fn convert(_i: In) -> Self::Out {
    |  _____________________________________^
 LL | |
+LL | |
 LL | |         unreachable!();
 LL | |     }
    | |_____^ cannot satisfy `<Out as Trait<Bar, In>>::Out == ()`
 
 error[E0119]: conflicting implementations of trait `Trait<Bar, _>`
-  --> $DIR/issue-84660-unsoundness.rs:28:1
+  --> $DIR/issue-84660-unsoundness.rs:29:1
    |
 LL | impl<In, Out> Trait<Bar, In> for Out {
    | ------------------------------------ first implementation here
diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs
index fd1f3c6353c6d..73c8deb3a4d97 100644
--- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs
+++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs
@@ -21,6 +21,7 @@ impl<In, Out> Trait<Bar, In> for Out {
     type Out = Out;
     fn convert(_i: In) -> Self::Out {
         //[next]~^  ERROR: cannot satisfy `<Out as Trait<Bar, In>>::Out == ()`
+        //[current]~^^ ERROR: item does not constrain `Bar::{opaque#0}`, but has it in its signature
         unreachable!();
     }
 }
diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs b/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs
index b0ebdd1bfab7d..a7d824c5a6a0b 100644
--- a/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs
+++ b/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs
@@ -6,12 +6,13 @@ use std::fmt::Debug;
 type FooX = impl Debug;
 //~^ ERROR unconstrained opaque type
 
-trait Foo<A> { }
+trait Foo<A> {}
 
-impl Foo<FooX> for () { }
+impl Foo<FooX> for () {}
 
 fn foo() -> impl Foo<FooX> {
+    //~^ ERROR: item does not constrain
     ()
 }
 
-fn main() { }
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr
index ce5d303705347..9ccd954489633 100644
--- a/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr
+++ b/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr
@@ -1,3 +1,16 @@
+error: item does not constrain `FooX::{opaque#0}`, but has it in its signature
+  --> $DIR/nested-tait-inference3.rs:13:4
+   |
+LL | fn foo() -> impl Foo<FooX> {
+   |    ^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/nested-tait-inference3.rs:6:13
+   |
+LL | type FooX = impl Debug;
+   |             ^^^^^^^^^^
+
 error: unconstrained opaque type
   --> $DIR/nested-tait-inference3.rs:6:13
    |
@@ -6,5 +19,5 @@ LL | type FooX = impl Debug;
    |
    = note: `FooX` must be used in combination with a concrete type within the same module
 
-error: aborting due to 1 previous error
+error: aborting due to 2 previous errors
 
diff --git a/tests/ui/type-alias-impl-trait/nested.rs b/tests/ui/type-alias-impl-trait/nested.rs
index 6b866be7d173f..524703939f1dc 100644
--- a/tests/ui/type-alias-impl-trait/nested.rs
+++ b/tests/ui/type-alias-impl-trait/nested.rs
@@ -8,6 +8,7 @@ trait Trait<T> {}
 impl<T, U> Trait<T> for U {}
 
 fn bar() -> Bar {
+    //~^ ERROR: item does not constrain
     42
 }
 
diff --git a/tests/ui/type-alias-impl-trait/nested.stderr b/tests/ui/type-alias-impl-trait/nested.stderr
index a19d4c4eb7164..ca1cf6058ea95 100644
--- a/tests/ui/type-alias-impl-trait/nested.stderr
+++ b/tests/ui/type-alias-impl-trait/nested.stderr
@@ -1,5 +1,18 @@
+error: item does not constrain `Foo::{opaque#0}`, but has it in its signature
+  --> $DIR/nested.rs:10:4
+   |
+LL | fn bar() -> Bar {
+   |    ^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/nested.rs:3:12
+   |
+LL | type Foo = impl std::fmt::Debug;
+   |            ^^^^^^^^^^^^^^^^^^^^
+
 error[E0277]: `Bar` doesn't implement `Debug`
-  --> $DIR/nested.rs:15:22
+  --> $DIR/nested.rs:16:22
    |
 LL |     println!("{:?}", bar());
    |                      ^^^^^ `Bar` cannot be formatted using `{:?}` because it doesn't implement `Debug`
@@ -7,6 +20,6 @@ LL |     println!("{:?}", bar());
    = help: the trait `Debug` is not implemented for `Bar`
    = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: aborting due to 1 previous error
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs
index 07607516cc4bc..4def8948708fc 100644
--- a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs
+++ b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs
@@ -11,6 +11,7 @@ mod my_mod {
     }
 
     pub fn get_foot(_: Foo) -> Foot {
+        //~^ ERROR: item does not constrain `Foo::{opaque#0}`, but has it in its signature
         get_foo() //~ ERROR opaque type's hidden type cannot be another opaque type
     }
 }
diff --git a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.stderr b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.stderr
index 3e67a162f0f0f..889cff1ba09eb 100644
--- a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.stderr
+++ b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.stderr
@@ -1,5 +1,18 @@
+error: item does not constrain `Foo::{opaque#0}`, but has it in its signature
+  --> $DIR/nested_type_alias_impl_trait.rs:13:12
+   |
+LL |     pub fn get_foot(_: Foo) -> Foot {
+   |            ^^^^^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/nested_type_alias_impl_trait.rs:6:20
+   |
+LL |     pub type Foo = impl Debug;
+   |                    ^^^^^^^^^^
+
 error: opaque type's hidden type cannot be another opaque type from the same scope
-  --> $DIR/nested_type_alias_impl_trait.rs:14:9
+  --> $DIR/nested_type_alias_impl_trait.rs:15:9
    |
 LL |         get_foo()
    |         ^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope
@@ -15,5 +28,5 @@ note: opaque type being used as hidden type
 LL |     pub type Foo = impl Debug;
    |                    ^^^^^^^^^^
 
-error: aborting due to 1 previous error
+error: aborting due to 2 previous errors
 
diff --git a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs
index 6431cf37df7ab..3954672500b48 100644
--- a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs
+++ b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs
@@ -9,6 +9,7 @@ mod foo {
 
     // make compiler happy about using 'Foo'
     pub fn bar(x: Foo) -> Foo {
+        //~^ ERROR: item does not constrain `Foo::{opaque#0}`
         x
     }
 }
diff --git a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr
index fabc80c0a4f24..d95a4a8a727ad 100644
--- a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr
+++ b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr
@@ -1,3 +1,16 @@
+error: item does not constrain `Foo::{opaque#0}`, but has it in its signature
+  --> $DIR/no_inferrable_concrete_type.rs:11:12
+   |
+LL |     pub fn bar(x: Foo) -> Foo {
+   |            ^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/no_inferrable_concrete_type.rs:7:20
+   |
+LL |     pub type Foo = impl Copy;
+   |                    ^^^^^^^^^
+
 error: unconstrained opaque type
   --> $DIR/no_inferrable_concrete_type.rs:7:20
    |
@@ -6,5 +19,5 @@ LL |     pub type Foo = impl Copy;
    |
    = note: `Foo` must be used in combination with a concrete type within the same module
 
-error: aborting due to 1 previous error
+error: aborting due to 2 previous errors
 
diff --git a/tests/ui/type-alias-impl-trait/normalize-alias-type.rs b/tests/ui/type-alias-impl-trait/normalize-alias-type.rs
index 605799260385f..9fcf42e188c78 100644
--- a/tests/ui/type-alias-impl-trait/normalize-alias-type.rs
+++ b/tests/ui/type-alias-impl-trait/normalize-alias-type.rs
@@ -8,25 +8,32 @@ pub trait Tr {
 
 impl Tr for (u32,) {
     #[inline]
-    fn get(&self) -> u32 { self.0 }
+    fn get(&self) -> u32 {
+        self.0
+    }
 }
 
 pub fn tr1() -> impl Tr {
     (32,)
 }
 
-pub fn tr2() -> impl Tr {
-    struct Inner {
-        x: X,
-    }
-    type X = impl Tr;
-    impl Tr for Inner {
-        fn get(&self) -> u32 {
-            self.x.get()
-        }
+struct Inner {
+    x: helper::X,
+}
+impl Tr for Inner {
+    fn get(&self) -> u32 {
+        self.x.get()
     }
+}
+
+mod helper {
+    pub use super::*;
+    pub type X = impl Tr;
 
-    Inner {
-        x: tr1(),
+    pub fn tr2() -> impl Tr
+    where
+        X:,
+    {
+        Inner { x: tr1() }
     }
 }
diff --git a/tests/ui/type-alias-impl-trait/outlives-bound-var.rs b/tests/ui/type-alias-impl-trait/outlives-bound-var.rs
index 0ae2c9600ce36..2c6f44d5416e4 100644
--- a/tests/ui/type-alias-impl-trait/outlives-bound-var.rs
+++ b/tests/ui/type-alias-impl-trait/outlives-bound-var.rs
@@ -5,8 +5,11 @@
 //@ check-pass
 #![feature(type_alias_impl_trait)]
 
-type Ty<'a> = impl Sized + 'a;
-fn define<'a>() -> Ty<'a> {}
+mod tait {
+    pub type Ty<'a> = impl Sized + 'a;
+    fn define<'a>() -> Ty<'a> {}
+}
+use tait::Ty;
 
 // Ty<'^0>: 'static
 fn test1(_: &'static fn(Ty<'_>)) {}
@@ -15,4 +18,4 @@ fn test2() {
     None::<&fn(Ty<'_>)>;
 }
 
-fn main() { }
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs
index e221f4f3f55c8..38fb493b49893 100644
--- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs
+++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs
@@ -9,26 +9,29 @@ struct A;
 impl Test for A {}
 
 struct B<T> {
-  inner: T,
+    inner: T,
 }
 
 impl<T: Test> Test for B<T> {}
 
-type TestImpl = impl Test;
+mod helper {
+    use super::*;
+    pub type TestImpl = impl Test;
 
-fn test() -> TestImpl {
-  A
-}
+    pub fn test() -> TestImpl {
+        A
+    }
 
-fn make_option() -> Option<TestImpl> {
-  Some(test())
-}
+    fn make_option2() -> Option<TestImpl> {
+        let inner = make_option().unwrap();
 
-fn make_option2() -> Option<TestImpl> {
-  let inner = make_option().unwrap();
+        Some(B { inner })
+        //~^ ERROR concrete type differs from previous defining opaque type use
+    }
+}
 
-  Some(B { inner })
-  //~^ ERROR concrete type differs from previous defining opaque type use
+fn make_option() -> Option<helper::TestImpl> {
+    Some(helper::test())
 }
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr
index 05825e6862591..252c5d7dfa760 100644
--- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr
+++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr
@@ -1,14 +1,14 @@
 error: concrete type differs from previous defining opaque type use
-  --> $DIR/recursive-tait-conflicting-defn.rs:30:3
+  --> $DIR/recursive-tait-conflicting-defn.rs:28:9
    |
-LL |   Some(B { inner })
-   |   ^^^^^^^^^^^^^^^^^ expected `A`, got `B<TestImpl>`
+LL |         Some(B { inner })
+   |         ^^^^^^^^^^^^^^^^^ expected `A`, got `B<TestImpl>`
    |
 note: previous use here
-  --> $DIR/recursive-tait-conflicting-defn.rs:20:3
+  --> $DIR/recursive-tait-conflicting-defn.rs:22:9
    |
-LL |   A
-   |   ^
+LL |         A
+   |         ^
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs
index 6f50703aca24d..37d84feee4b86 100644
--- a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs
+++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs
@@ -12,15 +12,19 @@
 
 #![feature(type_alias_impl_trait)]
 
-type Opaque = impl Sized;
+mod helper {
+    pub type Opaque = impl Sized;
 
-fn get_rpit() -> impl Clone {}
+    pub fn get_rpit() -> impl Clone {}
 
-fn query(_: impl FnOnce() -> Opaque) {}
-
-fn test() -> Opaque {
-    query(get_rpit);
-    get_rpit()
+    fn test() -> Opaque {
+        super::query(get_rpit);
+        get_rpit()
+    }
 }
 
+use helper::*;
+
+fn query(_: impl FnOnce() -> Opaque) {}
+
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs
index 9cb0316b7a38e..80f1b1502d3b5 100644
--- a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs
+++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs
@@ -5,14 +5,17 @@
 
 #![feature(type_alias_impl_trait)]
 
-type Opaque = impl Sized;
+mod helper {
+    pub type Opaque = impl Sized;
 
-fn get_rpit() -> impl Sized {}
+    pub fn get_rpit() -> impl Sized {}
 
-fn query(_: impl FnOnce() -> Opaque) {}
-
-fn test(_: Opaque) {
-    query(get_rpit);
+    fn test(_: Opaque) {
+        super::query(get_rpit);
+    }
 }
+use helper::*;
+
+fn query(_: impl FnOnce() -> Opaque) {}
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/self_implication.rs b/tests/ui/type-alias-impl-trait/self_implication.rs
index eed13933a037c..56464af96ed8d 100644
--- a/tests/ui/type-alias-impl-trait/self_implication.rs
+++ b/tests/ui/type-alias-impl-trait/self_implication.rs
@@ -16,17 +16,18 @@ fn foo() {
     let _b = z; // this should *not* check that `'a` in the type `Foo<'a>::foo::opaque` is live
 }
 
-fn bar() {
-    struct Foo<'a> {
-        x: &'a mut u8,
-    }
-
-    // desugared
-    type FooX = impl Sized;
-    impl<'a> Foo<'a> {
-        fn foo(&self) -> FooX {}
+struct Foo<'a> {
+    x: &'a mut u8,
+}
+// desugared
+mod foo {
+    pub type FooX = impl Sized;
+    impl<'a> super::Foo<'a> {
+        pub fn foo(&self) -> FooX {}
     }
+}
 
+fn bar() {
     // use site
     let mut x = 5;
     let y = Foo { x: &mut x };
diff --git a/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs b/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs
index c2ab6a9d10aa6..27f5799c38043 100644
--- a/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs
+++ b/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs
@@ -1,13 +1,15 @@
 #![feature(type_alias_impl_trait)]
 
-type Bar = impl Send;
+mod bar {
+    pub type Bar = impl Send;
 
-// While i32 is structural-match, we do not want to leak this information.
-// (See https://github.com/rust-lang/rust/issues/72156)
-const fn leak_free() -> Bar {
-    7i32
+    // While i32 is structural-match, we do not want to leak this information.
+    // (See https://github.com/rust-lang/rust/issues/72156)
+    pub const fn leak_free() -> Bar {
+        7i32
+    }
 }
-const LEAK_FREE: Bar = leak_free();
+const LEAK_FREE: bar::Bar = bar::leak_free();
 
 fn leak_free_test() {
     match LEAK_FREE {
diff --git a/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr b/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr
index b1ccd5cc402d7..98d71aa9a17dc 100644
--- a/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr
+++ b/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr
@@ -1,5 +1,5 @@
 error: `Bar` cannot be used in patterns
-  --> $DIR/structural-match-no-leak.rs:14:9
+  --> $DIR/structural-match-no-leak.rs:16:9
    |
 LL |         LEAK_FREE => (),
    |         ^^^^^^^^^
diff --git a/tests/ui/type-alias-impl-trait/structural-match.rs b/tests/ui/type-alias-impl-trait/structural-match.rs
index 7cc9ccaabdca4..5025959153976 100644
--- a/tests/ui/type-alias-impl-trait/structural-match.rs
+++ b/tests/ui/type-alias-impl-trait/structural-match.rs
@@ -1,19 +1,22 @@
 #![feature(type_alias_impl_trait)]
 
-type Foo = impl Send;
+mod foo {
+    pub type Foo = impl Send;
 
-// This is not structural-match
-struct A;
+    // This is not structural-match
+    struct A;
 
-const fn value() -> Foo {
-    A
+    pub const fn value() -> Foo {
+        A
+    }
 }
+use foo::*;
 const VALUE: Foo = value();
 
 fn test() {
     match VALUE {
         VALUE => (),
-        //~^ `Foo` cannot be used in patterns
+        //~^ `foo::Foo` cannot be used in patterns
         _ => (),
     }
 }
diff --git a/tests/ui/type-alias-impl-trait/structural-match.stderr b/tests/ui/type-alias-impl-trait/structural-match.stderr
index b0415db0e55c4..c7478b0a135e5 100644
--- a/tests/ui/type-alias-impl-trait/structural-match.stderr
+++ b/tests/ui/type-alias-impl-trait/structural-match.stderr
@@ -1,5 +1,5 @@
-error: `Foo` cannot be used in patterns
-  --> $DIR/structural-match.rs:15:9
+error: `foo::Foo` cannot be used in patterns
+  --> $DIR/structural-match.rs:18:9
    |
 LL |         VALUE => (),
    |         ^^^^^
diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs
index bd580a78984a1..cbd91066c49da 100644
--- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs
+++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs
@@ -1,5 +1,3 @@
-//@ check-pass
-
 #![feature(type_alias_impl_trait)]
 
 // Regression test for issue #61863
@@ -18,6 +16,7 @@ fn bla() -> TE {
 }
 
 fn bla2() -> TE {
+    //~^ ERROR: item does not constrain `TE::{opaque#0}`, but has it in its signature
     bla()
 }
 
diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr
new file mode 100644
index 0000000000000..819bde0218368
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr
@@ -0,0 +1,15 @@
+error: item does not constrain `TE::{opaque#0}`, but has it in its signature
+  --> $DIR/type-alias-impl-trait-fns.rs:18:4
+   |
+LL | fn bla2() -> TE {
+   |    ^^^^
+   |
+   = note: consider moving the opaque type's declaration and defining uses into a separate module
+note: this opaque type is in the signature
+  --> $DIR/type-alias-impl-trait-fns.rs:23:11
+   |
+LL | type TE = impl MyTrait;
+   |           ^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.next.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.next.stderr
deleted file mode 100644
index 036ab66f79d1a..0000000000000
--- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.next.stderr
+++ /dev/null
@@ -1,15 +0,0 @@
-error[E0284]: type annotations needed: cannot satisfy `Foo == _`
-  --> $DIR/type-alias-impl-trait-tuple.rs:22:24
-   |
-LL |         Blah { my_foo: make_foo(), my_u8: 12 }
-   |                        ^^^^^^^^^^ cannot satisfy `Foo == _`
-
-error[E0284]: type annotations needed: cannot satisfy `Foo == _`
-  --> $DIR/type-alias-impl-trait-tuple.rs:26:10
-   |
-LL |         (self.my_foo, self.my_u8, make_foo())
-   |          ^^^^^^^^^^^ cannot satisfy `Foo == _`
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0284`.
diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs
index fadb92ab4401b..8e90f96995324 100644
--- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs
+++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs
@@ -1,16 +1,24 @@
 //@ revisions: current next
 //@ ignore-compare-mode-next-solver (explicit revisions)
 //@[next] compile-flags: -Znext-solver
-//@[current] check-pass
+//@ check-pass
 
 #![feature(type_alias_impl_trait)]
 #![allow(dead_code)]
 
-pub trait MyTrait {}
+mod foo {
+    pub trait MyTrait {}
 
-impl MyTrait for bool {}
+    impl MyTrait for bool {}
 
-type Foo = impl MyTrait;
+    pub type Foo = impl MyTrait;
+
+    pub fn make_foo() -> Foo {
+        true
+    }
+}
+
+use foo::*;
 
 struct Blah {
     my_foo: Foo,
@@ -20,16 +28,10 @@ struct Blah {
 impl Blah {
     fn new() -> Blah {
         Blah { my_foo: make_foo(), my_u8: 12 }
-        //[next]~^ ERROR type annotations needed: cannot satisfy `Foo == _`
     }
     fn into_inner(self) -> (Foo, u8, Foo) {
         (self.my_foo, self.my_u8, make_foo())
-        //[next]~^ ERROR type annotations needed: cannot satisfy `Foo == _`
     }
 }
 
-fn make_foo() -> Foo {
-    true
-}
-
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs b/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs
index 03afec859d272..09ff006acbddb 100644
--- a/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs
+++ b/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs
@@ -1,10 +1,15 @@
 //@ check-pass
 
 #![feature(type_alias_impl_trait)]
-type Opaque<T> = impl Sized;
-fn defining<T>() -> Opaque<T> {}
-struct Ss<'a, T>(&'a Opaque<T>);
 
+mod opaque {
+    pub type Opaque<T> = impl Sized;
+    fn defining<T>() -> Opaque<T> {}
+}
+
+use opaque::Opaque;
+
+struct Ss<'a, T>(&'a Opaque<T>);
 
 fn test<'a, T>(_: Ss<'a, T>) {
     // test that we have an implied bound `Opaque<T>: 'a` from fn signature
diff --git a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs
index 37e0d89efc752..56d975355c3e7 100644
--- a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs
+++ b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs
@@ -1,16 +1,21 @@
 // test for ICE #121472 index out of bounds un_derefer.rs
 #![feature(type_alias_impl_trait)]
 
-trait T {}
+mod foo {
+    pub trait T {}
 
-type Alias<'a> = impl T;
+    pub type Alias<'a> = impl T;
+    fn bar() {
+        super::with_positive(|&n| ());
+        //~^ ERROR mismatched types
+    }
+}
+
+use foo::*;
 
 struct S;
 impl<'a> T for &'a S {}
 
 fn with_positive(fun: impl Fn(Alias<'_>)) {}
 
-fn main() {
-    with_positive(|&n| ());
-    //~^ ERROR mismatched types
-}
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr
index a224bab0705ef..279bd3bca5abe 100644
--- a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr
+++ b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr
@@ -1,21 +1,21 @@
 error[E0308]: mismatched types
-  --> $DIR/underef-index-out-of-bounds-121472.rs:14:20
+  --> $DIR/underef-index-out-of-bounds-121472.rs:9:31
    |
-LL | type Alias<'a> = impl T;
-   |                  ------ the expected opaque type
-...
-LL |     with_positive(|&n| ());
-   |                    ^^
-   |                    |
-   |                    expected opaque type, found `&_`
-   |                    expected due to this
+LL |     pub type Alias<'a> = impl T;
+   |                          ------ the expected opaque type
+LL |     fn bar() {
+LL |         super::with_positive(|&n| ());
+   |                               ^^
+   |                               |
+   |                               expected opaque type, found `&_`
+   |                               expected due to this
    |
-   = note: expected opaque type `Alias<'_>`
+   = note: expected opaque type `foo::Alias<'_>`
                 found reference `&_`
 help: consider removing `&` from the pattern
    |
-LL -     with_positive(|&n| ());
-LL +     with_positive(|n| ());
+LL -         super::with_positive(|&n| ());
+LL +         super::with_positive(|n| ());
    |
 
 error: aborting due to 1 previous error
diff --git a/tests/ui/type-alias-impl-trait/unnameable_type.rs b/tests/ui/type-alias-impl-trait/unnameable_type.rs
index 1739ab0063fa9..5813f529dea19 100644
--- a/tests/ui/type-alias-impl-trait/unnameable_type.rs
+++ b/tests/ui/type-alias-impl-trait/unnameable_type.rs
@@ -15,10 +15,11 @@ use private::Trait;
 
 // downstream
 type MyPrivate = impl Sized;
-//~^ ERROR: unconstrained opaque type
 impl Trait for u32 {
-    fn dont_define_this(_private: MyPrivate) {}
-    //~^ ERROR: incompatible type for trait
+    fn dont_define_this(private: MyPrivate) {
+        //~^ ERROR: incompatible type for trait
+        let _: () = private;
+    }
 }
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/unnameable_type.stderr b/tests/ui/type-alias-impl-trait/unnameable_type.stderr
index e9032433494a6..f567b01d29a1b 100644
--- a/tests/ui/type-alias-impl-trait/unnameable_type.stderr
+++ b/tests/ui/type-alias-impl-trait/unnameable_type.stderr
@@ -1,22 +1,14 @@
-error: unconstrained opaque type
-  --> $DIR/unnameable_type.rs:17:18
-   |
-LL | type MyPrivate = impl Sized;
-   |                  ^^^^^^^^^^
-   |
-   = note: `MyPrivate` must be used in combination with a concrete type within the same module
-
 error[E0053]: method `dont_define_this` has an incompatible type for trait
-  --> $DIR/unnameable_type.rs:20:35
+  --> $DIR/unnameable_type.rs:19:34
    |
 LL | type MyPrivate = impl Sized;
    |                  ---------- the found opaque type
-...
-LL |     fn dont_define_this(_private: MyPrivate) {}
-   |                                   ^^^^^^^^^
-   |                                   |
-   |                                   expected `Private`, found opaque type
-   |                                   help: change the parameter type to match the trait: `Private`
+LL | impl Trait for u32 {
+LL |     fn dont_define_this(private: MyPrivate) {
+   |                                  ^^^^^^^^^
+   |                                  |
+   |                                  expected `Private`, found opaque type
+   |                                  help: change the parameter type to match the trait: `Private`
    |
 note: type in trait
   --> $DIR/unnameable_type.rs:10:39
@@ -26,6 +18,6 @@ LL |         fn dont_define_this(_private: Private) {}
    = note: expected signature `fn(Private)`
               found signature `fn(MyPrivate)`
 
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
 
 For more information about this error, try `rustc --explain E0053`.