about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs12
-rw-r--r--tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr1
2 files changed, 9 insertions, 4 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
index 814da66ff0a..b53099b0abb 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
@@ -385,13 +385,15 @@ fn extend_type_not_partial_eq<'tcx>(
         /// The type has no `PartialEq` implementation, neither manual or derived, but
         /// we don't have a span to point at, so we'll just add them as a `note`.
         without: FxHashSet<Ty<'tcx>>,
+        /// If any of the subtypes has escaping bounds (`for<'a>`), we won't emit a note.
+        has_escaping_bound_vars: bool,
     }
 
     impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedInstantiationVisitor<'tcx> {
         fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
-            if let ty::Adt(def, _args) = ty.kind()
-                && !ty.has_escaping_bound_vars()
-            {
+            if ty.has_escaping_bound_vars() {
+                self.has_escaping_bound_vars = true;
+            } else if let ty::Adt(def, _args) = ty.kind() {
                 let ty_def_id = def.did();
                 let ty_def_span = self.tcx.def_span(ty_def_id);
                 let (impls_partial_eq, derived, structural, impl_def_id) =
@@ -426,8 +428,12 @@ fn extend_type_not_partial_eq<'tcx>(
         adts_without_partialeq: FxHashSet::default(),
         manual: FxHashSet::default(),
         without: FxHashSet::default(),
+        has_escaping_bound_vars: false,
     };
     v.visit_ty(ty);
+    if v.has_escaping_bound_vars {
+        return;
+    }
     #[allow(rustc::potential_query_instability)] // Span labels will be sorted by the rendering
     for span in v.adts_with_manual_partialeq {
         err.span_note(span, "the `PartialEq` trait must be derived, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details");
diff --git a/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr
index 5ec6ecc3070..371be9982f7 100644
--- a/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr
+++ b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr
@@ -8,7 +8,6 @@ LL |         C => (),
    |         ^ constant of non-structural type
    |
    = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
-   = note: `std::alloc::Global` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
 
 error: aborting due to 1 previous error