File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
compiler/rustc_mir_build/src/thir/pattern Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -2477,7 +2477,24 @@ fn specialize_one_pattern<'p, 'tcx>(
24772477
24782478 if let Opaque = constructor {
24792479 // Only a wildcard pattern can match an opaque constant, unless we're specializing the
2480- // value against its own constructor.
2480+ // value against its own constructor. That happens when we call
2481+ // `v.specialize_constructor(ctor)` with `ctor` obtained from `pat_constructor(v.head())`.
2482+ // For example, in the following match, when we are dealing with the third branch, we will
2483+ // specialize with an `Opaque` ctor. We want to ignore the second branch because opaque
2484+ // constants should not be inspected, but we don't want to ignore the current (third)
2485+ // branch, as that would cause us to always conclude that such a branch is unreachable.
2486+ // ```rust
2487+ // #[derive(PartialEq)]
2488+ // struct Foo(i32);
2489+ // impl Eq for Foo {}
2490+ // const FOO: Foo = Foo(42);
2491+ //
2492+ // match (Foo(0), true) {
2493+ // (_, true) => {}
2494+ // (FOO, true) => {}
2495+ // (FOO, false) => {}
2496+ // }
2497+ // ```
24812498 if is_its_own_ctor || pat. is_wildcard ( ) {
24822499 return Some ( Fields :: empty ( ) ) ;
24832500 } else {
You can’t perform that action at this time.
0 commit comments