diff options
| author | Ralf Jung <post@ralfj.de> | 2025-01-03 10:55:15 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-01-03 16:08:29 +0100 |
| commit | b806dccdc41274152f91d1efb421f2e50b4ab463 (patch) | |
| tree | 13b0da32b21bf612cff3312760b95185d220b0cb /compiler | |
| parent | c528b8c67895bfe7fdcdfeb56ec5bf6ef928dcd7 (diff) | |
| download | rust-b806dccdc41274152f91d1efb421f2e50b4ab463.tar.gz rust-b806dccdc41274152f91d1efb421f2e50b4ab463.zip | |
const-in-pattern: test that the PartialEq impl does not need to be const
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs | 4 |
1 files changed, 4 insertions, 0 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 aed00aecefc..2b3c98db966 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 @@ -491,6 +491,10 @@ fn type_has_partial_eq_impl<'tcx>( // `PartialEq` for some lifetime but *not* for `'static`? If this ever becomes a problem // we'll need to leave some sort of trace of this requirement in the MIR so that borrowck // can ensure that the type really implements `PartialEq`. + // We also do *not* require `const PartialEq`, not even in `const fn`. This violates the model + // that patterns can only do things that the code could also do without patterns, but it is + // needed for backwards compatibility. The actual pattern matching compares primitive values, + // `PartialEq::eq` never gets invoked, so there's no risk of us running non-const code. ( infcx.predicate_must_hold_modulo_regions(&partial_eq_obligation), automatically_derived, |
