Skip to content

Commit

Permalink
Avoid duplicated note
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 11, 2025
1 parent 05c3943 commit 91425d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 8 additions & 6 deletions compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ fn extend_type_not_partial_eq<'tcx>(
adts_without_partialeq: FxHashSet<Span>,
/// 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<Ty<'tcx>>,
manual: FxHashSet<Ty<'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: Vec<Ty<'tcx>>,
without: FxHashSet<Ty<'tcx>>,
}

impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedInstantiationVisitor<'tcx> {
Expand All @@ -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);
}
_ => {}
};
Expand All @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 91425d0

Please sign in to comment.