@@ -2125,46 +2125,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2125
2125
mut expected : Ty < ' tcx > ,
2126
2126
mut pat_info : PatInfo < ' tcx , ' _ > ,
2127
2127
) -> 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 ;
2144
2130
2145
- let mut inherited_ref_mutbl_match = false ;
2146
- if match_ergonomics_mode != MatchErgonomicsMode :: Legacy {
2131
+ if new_match_ergonomics {
2147
2132
if pat_mutbl == Mutability :: Not {
2148
2133
// Prevent the inner pattern from binding with `ref mut`.
2149
2134
pat_info. max_ref_mutbl = pat_info. max_ref_mutbl . cap_to_weakly_not (
2150
2135
inner. span . find_ancestor_inside ( pat. span ) . map ( |end| pat. span . until ( end) ) ,
2151
2136
) ;
2152
2137
}
2153
2138
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
2167
2141
{
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 {
2168
2147
// `&mut` patterns pell off `&` references
2169
2148
let ( new_expected, new_bm, max_ref_mutbl) = self . peel_off_references (
2170
2149
pat,
@@ -2204,33 +2183,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2204
2183
// the bad interactions of the given hack detailed in (note_1).
2205
2184
debug ! ( "check_pat_ref: expected={:?}" , expected) ;
2206
2185
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 {
2211
2188
pat_info. max_ref_mutbl = MutblCap :: Not ;
2212
2189
}
2213
2190
2214
2191
( expected, r_ty)
2215
2192
}
2216
2193
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) ,
2234
2195
2235
2196
_ => {
2236
2197
let inner_ty = self . next_ty_var ( inner. span ) ;
0 commit comments