From 91425d0ef8bfdfb7f11b7528d026d1a245743c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 26 Dec 2024 01:35:43 +0000 Subject: [PATCH] Avoid duplicated note --- .../src/thir/pattern/const_to_pat.rs | 14 ++++++++------ .../non_structural_with_escaping_bounds.stderr | 1 - 2 files changed, 8 insertions(+), 7 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 a1d9b9024ab32..814da66ff0a91 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 @@ -381,10 +381,10 @@ fn extend_type_not_partial_eq<'tcx>( adts_without_partialeq: FxHashSet, /// The user has written `impl PartialEq for Ty` which means it's non-structual, /// but we don't have a span to point at, so we'll just add them as a `note`. - manual: Vec>, + manual: FxHashSet>, /// 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: Vec>, + without: FxHashSet>, } impl<'tcx> TypeVisitor> for UsedParamsNeedInstantiationVisitor<'tcx> { @@ -408,10 +408,10 @@ fn extend_type_not_partial_eq<'tcx>( self.adts_without_partialeq.insert(ty_def_span); } (true, false, _, _) => { - self.manual.push(ty); + self.manual.insert(ty); } (false, _, _, _) => { - self.without.push(ty); + self.without.insert(ty); } _ => {} }; @@ -424,8 +424,8 @@ fn extend_type_not_partial_eq<'tcx>( typing_env, adts_with_manual_partialeq: FxHashSet::default(), adts_without_partialeq: FxHashSet::default(), - manual: vec![], - without: vec![], + manual: FxHashSet::default(), + without: FxHashSet::default(), }; v.visit_ty(ty); #[allow(rustc::potential_query_instability)] // Span labels will be sorted by the rendering @@ -439,11 +439,13 @@ fn extend_type_not_partial_eq<'tcx>( "must be annotated with `#[derive(PartialEq)]` to be usable in patterns", ); } + #[allow(rustc::potential_query_instability)] // Span labels will be sorted by the rendering for ty in v.manual { err.note(format!( "`{ty}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details" )); } + #[allow(rustc::potential_query_instability)] // Span labels will be sorted by the rendering for ty in v.without { err.note(format!( "`{ty}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns" 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 47378569084a4..5ec6ecc3070fd 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 @@ -9,7 +9,6 @@ LL | C => (), | = 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 - = note: `std::alloc::Global` must be annotated with `#[derive(PartialEq)]` to be usable in patterns error: aborting due to 1 previous error