make non-PartialEq-typed consts as patterns a hard error
This commit is contained in:
parent
e9f9594913
commit
5b7786cd1d
8 changed files with 27 additions and 112 deletions
|
@ -767,6 +767,14 @@ pub struct TypeNotStructural<'tcx> {
|
|||
pub non_sm_ty: Ty<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(mir_build_non_partial_eq_match)]
|
||||
pub struct TypeNotPartialEq<'tcx> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub non_peq_ty: Ty<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(mir_build_invalid_pattern)]
|
||||
pub struct InvalidPattern<'tcx> {
|
||||
|
@ -822,12 +830,6 @@ 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(Diagnostic)]
|
||||
#[diag(mir_build_pattern_not_covered, code = E0005)]
|
||||
pub(crate) struct PatternNotCovered<'s, 'tcx> {
|
||||
|
|
|
@ -16,7 +16,7 @@ use std::cell::Cell;
|
|||
|
||||
use super::PatCtxt;
|
||||
use crate::errors::{
|
||||
IndirectStructuralMatch, InvalidPattern, NaNPattern, NonPartialEqMatch, PointerPattern,
|
||||
IndirectStructuralMatch, InvalidPattern, NaNPattern, PointerPattern, TypeNotPartialEq,
|
||||
TypeNotStructural, UnionPattern, UnsizedPattern,
|
||||
};
|
||||
|
||||
|
@ -208,15 +208,12 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Always check for `PartialEq` if we had no other errors yet.
|
||||
if !self.type_has_partial_eq_impl(cv.ty()) {
|
||||
self.tcx().emit_node_span_lint(
|
||||
lint::builtin::CONST_PATTERNS_WITHOUT_PARTIAL_EQ,
|
||||
self.id,
|
||||
self.span,
|
||||
NonPartialEqMatch { non_peq_ty: cv.ty() },
|
||||
);
|
||||
let err = TypeNotPartialEq { span: self.span, non_peq_ty: cv.ty() };
|
||||
let e = self.tcx().dcx().emit_err(err);
|
||||
let kind = PatKind::Error(e);
|
||||
return Box::new(Pat { span: self.span, ty: cv.ty(), kind });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue