@@ -2125,46 +2125,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21252125 mut expected : Ty < ' tcx > ,
21262126 mut pat_info : PatInfo < ' tcx , ' _ > ,
21272127 ) -> Ty < ' tcx > {
2128- // FIXME: repace with `bool` once final decision on 1 vs 2 layers is made
2129- #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
2130- enum MatchErgonomicsMode {
2131- EatOneLayer ,
2132- EatTwoLayers ,
2133- Legacy ,
2134- }
2135-
2136- let match_ergonomics_mode =
2137- if pat. span . at_least_rust_2024 ( ) && self . tcx . features ( ) . ref_pat_eat_one_layer_2024 {
2138- MatchErgonomicsMode :: EatOneLayer
2139- } else if self . tcx . features ( ) . ref_pat_everywhere {
2140- MatchErgonomicsMode :: EatTwoLayers
2141- } else {
2142- MatchErgonomicsMode :: Legacy
2143- } ;
2128+ let new_match_ergonomics =
2129+ pat. span . at_least_rust_2024 ( ) && self . tcx . features ( ) . ref_pat_eat_one_layer_2024 ;
21442130
2145- let mut inherited_ref_mutbl_match = false ;
2146- if match_ergonomics_mode != MatchErgonomicsMode :: Legacy {
2131+ if new_match_ergonomics {
21472132 if pat_mutbl == Mutability :: Not {
21482133 // Prevent the inner pattern from binding with `ref mut`.
21492134 pat_info. max_ref_mutbl = pat_info. max_ref_mutbl . cap_to_weakly_not (
21502135 inner. span . find_ancestor_inside ( pat. span ) . map ( |end| pat. span . until ( end) ) ,
21512136 ) ;
21522137 }
21532138
2154- if let ByRef :: Yes ( inh_mut) = pat_info. binding_mode {
2155- inherited_ref_mutbl_match = pat_mutbl <= inh_mut;
2156- }
2157-
2158- if inherited_ref_mutbl_match {
2159- pat_info. binding_mode = ByRef :: No ;
2160- if match_ergonomics_mode == MatchErgonomicsMode :: EatOneLayer {
2161- self . typeck_results . borrow_mut ( ) . skipped_ref_pats_mut ( ) . insert ( pat. hir_id ) ;
2162- self . check_pat ( inner, expected, pat_info) ;
2163- return expected;
2164- }
2165- } else if match_ergonomics_mode == MatchErgonomicsMode :: EatOneLayer
2166- && pat_mutbl == Mutability :: Mut
2139+ if let ByRef :: Yes ( inh_mut) = pat_info. binding_mode
2140+ && pat_mutbl <= inh_mut
21672141 {
2142+ pat_info. binding_mode = ByRef :: No ;
2143+ self . typeck_results . borrow_mut ( ) . skipped_ref_pats_mut ( ) . insert ( pat. hir_id ) ;
2144+ self . check_pat ( inner, expected, pat_info) ;
2145+ return expected;
2146+ } else if pat_mutbl == Mutability :: Mut {
21682147 // `&mut` patterns pell off `&` references
21692148 let ( new_expected, new_bm, max_ref_mutbl) = self . peel_off_references (
21702149 pat,
@@ -2204,33 +2183,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22042183 // the bad interactions of the given hack detailed in (note_1).
22052184 debug ! ( "check_pat_ref: expected={:?}" , expected) ;
22062185 match * expected. kind ( ) {
2207- ty:: Ref ( _, r_ty, r_mutbl) if r_mutbl == pat_mutbl => {
2208- if r_mutbl == Mutability :: Not
2209- && match_ergonomics_mode != MatchErgonomicsMode :: Legacy
2210- {
2186+ ty:: Ref ( _, r_ty, r_mutbl) if r_mutbl >= pat_mutbl && new_match_ergonomics => {
2187+ if r_mutbl == Mutability :: Not {
22112188 pat_info. max_ref_mutbl = MutblCap :: Not ;
22122189 }
22132190
22142191 ( expected, r_ty)
22152192 }
22162193
2217- // `&` pattern eats `&mut` reference
2218- ty:: Ref ( _, r_ty, Mutability :: Mut )
2219- if pat_mutbl == Mutability :: Not
2220- && match_ergonomics_mode != MatchErgonomicsMode :: Legacy =>
2221- {
2222- ( expected, r_ty)
2223- }
2224-
2225- _ if inherited_ref_mutbl_match
2226- && match_ergonomics_mode == MatchErgonomicsMode :: EatTwoLayers =>
2227- {
2228- // We already matched against a match-ergonmics inserted reference,
2229- // so we don't need to match against a reference from the original type.
2230- // Save this info for use in lowering later
2231- self . typeck_results . borrow_mut ( ) . skipped_ref_pats_mut ( ) . insert ( pat. hir_id ) ;
2232- ( expected, expected)
2233- }
2194+ ty:: Ref ( _, r_ty, r_mutbl) if r_mutbl == pat_mutbl => ( expected, r_ty) ,
22342195
22352196 _ => {
22362197 let inner_ty = self . next_ty_var ( inner. span ) ;
0 commit comments