diff --git a/compiler/rustc_mir_build/src/build/matches/util.rs b/compiler/rustc_mir_build/src/build/matches/util.rs index d77d296f20653..b854ba47f8f61 100644 --- a/compiler/rustc_mir_build/src/build/matches/util.rs +++ b/compiler/rustc_mir_build/src/build/matches/util.rs @@ -106,6 +106,9 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> { let mut place = match place.try_upvars_resolved(cx) { Ok(val) | Err(val) => val, }; + + // Only add the OpaqueCast projection if the given place is an opaque type and the + // expected type from the pattern is not. let may_need_cast = match place.base() { PlaceBase::Local(local) => { let ty = Place::ty_from(local, place.projection(), &cx.local_decls, cx.tcx).ty;