Skip to content

Commit b589976

Browse files
committed
use a must_hold variant for checking PartialEq
1 parent c3ed0c4 commit b589976

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Diff for: compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'tcx> ConstToPat<'tcx> {
179179
}
180180

181181
if let Some(non_sm_ty) = structural {
182-
if !self.type_may_have_partial_eq_impl(cv.ty()) {
182+
if !self.type_has_partial_eq_impl(cv.ty()) {
183183
if let ty::Adt(def, ..) = non_sm_ty.kind() {
184184
if def.is_union() {
185185
let err = UnionPattern { span: self.span };
@@ -244,7 +244,7 @@ impl<'tcx> ConstToPat<'tcx> {
244244

245245
// Always check for `PartialEq`, even if we emitted other lints. (But not if there were
246246
// any errors.) This ensures it shows up in cargo's future-compat reports as well.
247-
if !self.type_may_have_partial_eq_impl(cv.ty()) {
247+
if !self.type_has_partial_eq_impl(cv.ty()) {
248248
self.tcx().emit_spanned_lint(
249249
lint::builtin::MATCH_WITHOUT_PARTIAL_EQ,
250250
self.id,
@@ -258,7 +258,7 @@ impl<'tcx> ConstToPat<'tcx> {
258258
}
259259

260260
#[instrument(level = "trace", skip(self), ret)]
261-
fn type_may_have_partial_eq_impl(&self, ty: Ty<'tcx>) -> bool {
261+
fn type_has_partial_eq_impl(&self, ty: Ty<'tcx>) -> bool {
262262
// double-check there even *is* a semantic `PartialEq` to dispatch to.
263263
//
264264
// (If there isn't, then we can safely issue a hard
@@ -273,8 +273,13 @@ impl<'tcx> ConstToPat<'tcx> {
273273
ty::TraitRef::new(self.tcx(), partial_eq_trait_id, [ty, ty]),
274274
);
275275

276-
// FIXME: should this call a `predicate_must_hold` variant instead?
277-
self.infcx.predicate_may_hold(&partial_eq_obligation)
276+
// This *could* accept a type that isn't actually `PartialEq`, because region bounds get
277+
// ignored. However that should be pretty much impossible since consts that do not depend on
278+
// generics can only mention the `'static` lifetime, and how would one have a type that's
279+
// `PartialEq` for some lifetime but *not* for `'static`? If this ever becomes a problem
280+
// we'll need to leave some sort of trace of this requirement in the MIR so that borrowck
281+
// can ensure that the type really implements `PartialEq`.
282+
self.infcx.predicate_must_hold_modulo_regions(&partial_eq_obligation)
278283
}
279284

280285
fn field_pats(

0 commit comments

Comments
 (0)