Skip to content

Commit

Permalink
make sure we always emit the no-PartialEq lint, even if there were ot…
Browse files Browse the repository at this point in the history
…her lints
  • Loading branch information
RalfJung committed Sep 17, 2023
1 parent dc85202 commit 6ca2a35
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ impl<'tcx> ConstToPat<'tcx> {
};

if !self.saw_const_match_error.get() {
// If we were able to successfully convert the const to some pat,
// double-check that all types in the const implement `Structural`.
// If we were able to successfully convert the const to some pat (possibly with some
// lints, but no errors), double-check that all types in the const implement
// `Structural` and `PartialEq`.

let structural =
traits::search_for_structural_match_violation(self.span, self.tcx(), cv.ty());
Expand Down Expand Up @@ -192,8 +193,10 @@ impl<'tcx> ConstToPat<'tcx> {
} else {
let err = InvalidPattern { span: self.span, non_sm_ty };
self.tcx().sess.emit_err(err);
return Box::new(Pat { span: self.span, ty: cv.ty(), kind: PatKind::Wild });
}
// All branches above emitted an error. Don't print any more lints.
// The pattern we return is irrelevant since we errored.
return Box::new(Pat { span: self.span, ty: cv.ty(), kind: PatKind::Wild });
} else if !self.saw_const_match_lint.get() {
if let Some(mir_structural_match_violation) = mir_structural_match_violation {
match non_sm_ty.kind() {
Expand Down Expand Up @@ -235,19 +238,21 @@ impl<'tcx> ConstToPat<'tcx> {
PointerPattern,
);
}
_ if !self.type_may_have_partial_eq_impl(cv.ty()) => {
// Value is structural-match but the type doesn't even implement `PartialEq`...
self.saw_const_match_lint.set(true);
self.tcx().emit_spanned_lint(
lint::builtin::MATCH_WITHOUT_PARTIAL_EQ,
self.id,
self.span,
NonPartialEqMatch { non_peq_ty: cv.ty() },
);
}
_ => {}
}
}

// Always check for `PartialEq`, even if we emitted other lints. (But not if there were
// any errors.) This ensures it shows up in cargo's future-compat reports as well.
if !self.type_may_have_partial_eq_impl(cv.ty()) {
self.saw_const_match_lint.set(true);
self.tcx().emit_spanned_lint(
lint::builtin::MATCH_WITHOUT_PARTIAL_EQ,
self.id,
self.span,
NonPartialEqMatch { non_peq_ty: cv.ty() },
);
}
}

inlined_const_as_pat
Expand Down

0 comments on commit 6ca2a35

Please sign in to comment.