Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --Nightly only, since it depends on the feature gate. Without the feature gate, the code compiles without an ICE. is the first nightly with the ICE. Still occurs on the latest nightly ( at the time of writing). ICE still occurs when is substituted with , e.g. <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: : <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details
cc
can you take a look please
I started looking into the issue and I think it spans from failing to resolve the upvars when the feature is enabled: fails which leads to the field of the Candidate to not be assigned as the assignment of this field is being done
The underlying issue is that currently the compiler does not realize, for the above example, that the discriminant should be read. We incorrectly assumed that would only be of type when they could be of other types like we should be looking at the when we actually want to look at Working on a fix

Discussion:
| PatKind::Path(..) | PatKind::Struct(..) | PatKind::Tuple(..) => { <del> // If the PatKind is a TupleStruct, Struct or Tuple then we want to check </del> <ins> // If the PatKind is a TupleStruct, Path, Struct or Tuple then we want to check </ins> // whether the Variant is a MultiVariant or a SingleVariant. We only want // to borrow discr if it is a MultiVariant. // If it is a SingleVariant and creates a binding we will handle that when // this callback gets called again. <del> if let ty::Adt(def, _) = place.place.base_ty.kind() { </del> <ins> // Get the type of the Place after all projections have been applied let place_ty = place.place.ty(); if let ty::Adt(def, _) = place_ty.kind() { </ins> if def.variants.len() > 1 { needs_to_be_read = true; }

<ins> // run-pass // edition:2021 enum Variant { A, B, //~ WARNING: variant is never constructed: `B` } struct A { field: Variant, } fn discriminant_is_a_ref() { let here = A { field: Variant::A }; let out_ref = &here.field; || match out_ref { //~ WARNING: unused closure that must be used Variant::A => (), Variant::B => (), }; } fn discriminant_is_a_field() { let here = A { field: Variant::A }; || match here.field { //~ WARNING: unused closure that must be used Variant::A => (), Variant::B => (), }; } fn main() { discriminant_is_a_ref(); discriminant_is_a_field(); } </ins>

<ins> warning: variant is never constructed: `B` --> $DIR/issue-87097.rs:6:5 | LL |     B, |     ^ | = note: `#[warn(dead_code)]` on by default warning: unused closure that must be used --> $DIR/issue-87097.rs:17:5 | LL | /     || match out_ref { LL | |         Variant::A => (), LL | |         Variant::B => (), LL | |     }; | |______^ | = note: `#[warn(unused_must_use)]` on by default = note: closures are lazy and do nothing unless called warning: unused closure that must be used --> $DIR/issue-87097.rs:26:5 | LL | /     || match here.field { LL | |         Variant::A => (), LL | |         Variant::B => (), LL | |     }; | |______^ | = note: closures are lazy and do nothing unless called warning: 3 warnings emitted </ins>