diff options
| author | Ralf Jung <post@ralfj.de> | 2023-09-16 14:15:48 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-09-24 16:36:26 +0200 |
| commit | c5fccb98ea8d853b7d332e077c3ed86401b160c7 (patch) | |
| tree | 7f74a32a6dc4f7d209579049000da784550e1c26 /compiler/rustc_mir_build/src/thir | |
| parent | 19c65022fc1ad9cc3d3dcf50a0bdf50e4ab572ab (diff) | |
| download | rust-c5fccb98ea8d853b7d332e077c3ed86401b160c7.tar.gz rust-c5fccb98ea8d853b7d332e077c3ed86401b160c7.zip | |
work towards rejecting consts in patterns that do not implement PartialEq
Diffstat (limited to 'compiler/rustc_mir_build/src/thir')
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index 00d9fe72cfc..41f31beff77 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -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() }, + ); + } _ => {} } } |
