1
Fork 0

work towards rejecting consts in patterns that do not implement PartialEq

This commit is contained in:
Ralf Jung 2023-09-16 14:15:48 +02:00
parent 19c65022fc
commit c5fccb98ea
8 changed files with 123 additions and 4 deletions

View file

@ -748,6 +748,12 @@ pub struct NontrivialStructuralMatch<'tcx> {
pub non_sm_ty: Ty<'tcx>,
}
#[derive(LintDiagnostic)]
#[diag(mir_build_non_partial_eq_match)]
pub struct NonPartialEqMatch<'tcx> {
pub non_peq_ty: Ty<'tcx>,
}
#[derive(LintDiagnostic)]
#[diag(mir_build_overlapping_range_endpoints)]
#[note]

View file

@ -16,8 +16,8 @@ use std::cell::Cell;
use super::PatCtxt;
use crate::errors::{
FloatPattern, IndirectStructuralMatch, InvalidPattern, NontrivialStructuralMatch,
PointerPattern, TypeNotStructural, UnionPattern, UnsizedPattern,
FloatPattern, IndirectStructuralMatch, InvalidPattern, NonPartialEqMatch,
NontrivialStructuralMatch, PointerPattern, TypeNotStructural, UnionPattern, UnsizedPattern,
};
impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
@ -235,6 +235,16 @@ 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() },
);
}
_ => {}
}
}