work towards rejecting consts in patterns that do not implement PartialEq
This commit is contained in:
parent
19c65022fc
commit
c5fccb98ea
8 changed files with 123 additions and 4 deletions
|
@ -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]
|
||||
|
|
|
@ -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() },
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue