@@ -2126,46 +2126,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2126
2126
mut expected : Ty < ' tcx > ,
2127
2127
mut pat_info : PatInfo < ' tcx , ' _ > ,
2128
2128
) -> Ty < ' tcx > {
2129
- // FIXME: repace with `bool` once final decision on 1 vs 2 layers is made
2130
- #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
2131
- enum MatchErgonomicsMode {
2132
- EatOneLayer ,
2133
- EatTwoLayers ,
2134
- Legacy ,
2135
- }
2136
-
2137
- let match_ergonomics_mode =
2138
- if pat. span . at_least_rust_2024 ( ) && self . tcx . features ( ) . ref_pat_eat_one_layer_2024 {
2139
- MatchErgonomicsMode :: EatOneLayer
2140
- } else if self . tcx . features ( ) . ref_pat_everywhere {
2141
- MatchErgonomicsMode :: EatTwoLayers
2142
- } else {
2143
- MatchErgonomicsMode :: Legacy
2144
- } ;
2129
+ let new_match_ergonomics =
2130
+ pat. span . at_least_rust_2024 ( ) && self . tcx . features ( ) . ref_pat_eat_one_layer_2024 ;
2145
2131
2146
- let mut inherited_ref_mutbl_match = false ;
2147
- if match_ergonomics_mode != MatchErgonomicsMode :: Legacy {
2132
+ if new_match_ergonomics {
2148
2133
if pat_mutbl == Mutability :: Not {
2149
2134
// Prevent the inner pattern from binding with `ref mut`.
2150
2135
pat_info. max_ref_mutbl = pat_info. max_ref_mutbl . cap_to_weakly_not (
2151
2136
inner. span . find_ancestor_inside ( pat. span ) . map ( |end| pat. span . until ( end) ) ,
2152
2137
) ;
2153
2138
}
2154
2139
2155
- if let ByRef :: Yes ( inh_mut) = pat_info. binding_mode {
2156
- inherited_ref_mutbl_match = pat_mutbl <= inh_mut;
2157
- }
2158
-
2159
- if inherited_ref_mutbl_match {
2160
- pat_info. binding_mode = ByRef :: No ;
2161
- if match_ergonomics_mode == MatchErgonomicsMode :: EatOneLayer {
2162
- self . typeck_results . borrow_mut ( ) . skipped_ref_pats_mut ( ) . insert ( pat. hir_id ) ;
2163
- self . check_pat ( inner, expected, pat_info) ;
2164
- return expected;
2165
- }
2166
- } else if match_ergonomics_mode == MatchErgonomicsMode :: EatOneLayer
2167
- && pat_mutbl == Mutability :: Mut
2140
+ if let ByRef :: Yes ( inh_mut) = pat_info. binding_mode
2141
+ && pat_mutbl <= inh_mut
2168
2142
{
2143
+ pat_info. binding_mode = ByRef :: No ;
2144
+ self . typeck_results . borrow_mut ( ) . skipped_ref_pats_mut ( ) . insert ( pat. hir_id ) ;
2145
+ self . check_pat ( inner, expected, pat_info) ;
2146
+ return expected;
2147
+ } else if pat_mutbl == Mutability :: Mut {
2169
2148
// `&mut` patterns pell off `&` references
2170
2149
let ( new_expected, new_bm, max_ref_mutbl) = self . peel_off_references (
2171
2150
pat,
@@ -2205,33 +2184,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2205
2184
// the bad interactions of the given hack detailed in (note_1).
2206
2185
debug ! ( "check_pat_ref: expected={:?}" , expected) ;
2207
2186
match * expected. kind ( ) {
2208
- ty:: Ref ( _, r_ty, r_mutbl) if r_mutbl == pat_mutbl => {
2209
- if r_mutbl == Mutability :: Not
2210
- && match_ergonomics_mode != MatchErgonomicsMode :: Legacy
2211
- {
2187
+ ty:: Ref ( _, r_ty, r_mutbl) if r_mutbl >= pat_mutbl && new_match_ergonomics => {
2188
+ if r_mutbl == Mutability :: Not {
2212
2189
pat_info. max_ref_mutbl = MutblCap :: Not ;
2213
2190
}
2214
2191
2215
2192
( expected, r_ty)
2216
2193
}
2217
2194
2218
- // `&` pattern eats `&mut` reference
2219
- ty:: Ref ( _, r_ty, Mutability :: Mut )
2220
- if pat_mutbl == Mutability :: Not
2221
- && match_ergonomics_mode != MatchErgonomicsMode :: Legacy =>
2222
- {
2223
- ( expected, r_ty)
2224
- }
2225
-
2226
- _ if inherited_ref_mutbl_match
2227
- && match_ergonomics_mode == MatchErgonomicsMode :: EatTwoLayers =>
2228
- {
2229
- // We already matched against a match-ergonmics inserted reference,
2230
- // so we don't need to match against a reference from the original type.
2231
- // Save this info for use in lowering later
2232
- self . typeck_results . borrow_mut ( ) . skipped_ref_pats_mut ( ) . insert ( pat. hir_id ) ;
2233
- ( expected, expected)
2234
- }
2195
+ ty:: Ref ( _, r_ty, r_mutbl) if r_mutbl == pat_mutbl => ( expected, r_ty) ,
2235
2196
2236
2197
_ => {
2237
2198
let inner_ty = self . next_ty_var ( inner. span ) ;
0 commit comments