@@ -2403,17 +2403,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2403
2403
2404
2404
if let ty:: Ref ( _, inner_ty, _) = * expected. kind ( ) {
2405
2405
// Consume both the inherited and inner references.
2406
- if inh_mut. is_mut ( ) {
2407
- // If the expected type is a reference type (of any mutability) and the
2408
- // inherited ref is mutable, we'll be able to match, since we can fall
2409
- // back to matching the inherited ref if the real reference isn't
2410
- // mutable enough for our pattern. We handle that here to avoid adding
2411
- // fallback-to-outer to the common logic below.
2412
- // NB: This way of phrasing the logic will catch more cases than those
2413
- // that need to fall back to matching the inherited reference. However,
2414
- // as long as `&` patterns can match mutable (inherited) references
2415
- // (RFC 3627, Rule 5) this should be sound.
2416
- debug_assert ! ( ref_pat_matches_mut_ref) ;
2406
+ if pat_mutbl. is_mut ( ) && inh_mut. is_mut ( ) {
2407
+ // As a special case, a `&mut` reference pattern will be able to match
2408
+ // against a reference type of any mutability if the inherited ref is
2409
+ // mutable. Since this allows us to match against a shared reference
2410
+ // type, we refer to this as "falling back" to matching the inherited
2411
+ // reference, though we consume the real reference as well. We handle
2412
+ // this here to avoid adding this case to the common logic below.
2417
2413
self . check_pat ( inner, inner_ty, pat_info) ;
2418
2414
return expected;
2419
2415
} else {
0 commit comments