Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0a15bfb

Browse files
committedFeb 19, 2025
simplify fallback-to-outer condition on old editions
1 parent 0e758c4 commit 0a15bfb

File tree

1 file changed

+7
-11
lines changed
  • compiler/rustc_hir_typeck/src

1 file changed

+7
-11
lines changed
 

‎compiler/rustc_hir_typeck/src/pat.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -2403,17 +2403,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24032403

24042404
if let ty::Ref(_, inner_ty, _) = *expected.kind() {
24052405
// 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.
24172413
self.check_pat(inner, inner_ty, pat_info);
24182414
return expected;
24192415
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.