@@ -176,17 +176,19 @@ enum AdjustMode<'tcx> {
176
176
/// Restrictions on what types to peel when adjusting the expected type and binding mode.
177
177
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
178
178
enum PeelKind < ' tcx > {
179
- /// Only peel reference types. This is used for explicit deref patterns.
180
- RefOnly ,
181
- /// If `deref_patterns` is enabled, this also peels library-defined smart pointer ADTs, except
182
- /// for `until_adt` if the pattern is a constructor. Otherwise this is the same as `RefOnly`.
183
- /// See [`ResolvedPat`] for more information.
184
- Overloaded { until_adt : Option < AdtDef < ' tcx > > } ,
179
+ /// Only peel reference types. This is used for explicit `deref!(_)` patterns, which dereference
180
+ /// any number of `&`/`&mut` references, plus a single smart pointer.
181
+ ExplicitDerefPat ,
182
+ /// Implicitly peel any number of references, and if `deref_patterns` is enabled, smart pointer
183
+ /// ADTs. In order to peel only as much as necessary for the pattern to match, the `until_adt`
184
+ /// field contains the ADT def that the pattern is a constructor for, if applicable, so that we
185
+ /// don't peel it. See [`ResolvedPat`] for more information.
186
+ Implicit { until_adt : Option < AdtDef < ' tcx > > } ,
185
187
}
186
188
187
189
impl < ' tcx > AdjustMode < ' tcx > {
188
190
const fn peel_until_adt ( opt_adt_def : Option < AdtDef < ' tcx > > ) -> AdjustMode < ' tcx > {
189
- AdjustMode :: Peel { kind : PeelKind :: Overloaded { until_adt : opt_adt_def } }
191
+ AdjustMode :: Peel { kind : PeelKind :: Implicit { until_adt : opt_adt_def } }
190
192
}
191
193
const fn peel_all ( ) -> AdjustMode < ' tcx > {
192
194
AdjustMode :: peel_until_adt ( None )
@@ -585,7 +587,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
585
587
// FIXME(deref_patterns): If box patterns and deref patterns need to coexist, box
586
588
// patterns may want `PeelKind::Overloaded`, stopping on encountering a box.
587
589
| PatKind :: Box ( _)
588
- | PatKind :: Deref ( _) => AdjustMode :: Peel { kind : PeelKind :: RefOnly } ,
590
+ | PatKind :: Deref ( _) => AdjustMode :: Peel { kind : PeelKind :: ExplicitDerefPat } ,
589
591
// A never pattern behaves somewhat like a literal or unit variant.
590
592
PatKind :: Never => AdjustMode :: peel_all ( ) ,
591
593
// For patterns with paths, how we peel the scrutinee depends on the path's resolution.
@@ -651,7 +653,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
651
653
//
652
654
// For each ampersand peeled off, update the binding mode and push the original
653
655
// type into the adjustments vector.
654
- // When peeling a library-defined type , the default binding mode is not updated.
656
+ // When peeling a smart pointer , the default binding mode is not updated.
655
657
//
656
658
// See the examples in `tests/ui/rfcs/rfc-2005-default-binding-mode/` and
657
659
// `tests/ui/pattern/deref-patterns/`.
@@ -670,7 +672,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
670
672
} ) ;
671
673
inner_ty
672
674
} else if deref_patterns
673
- && let PeelKind :: Overloaded { until_adt } = peel_kind
675
+ && let PeelKind :: Implicit { until_adt } = peel_kind
674
676
// For simplicity, only apply overloaded derefs if `expected` is a known ADT.
675
677
// FIXME(deref_patterns): we'll get better diagnostics for users trying to
676
678
// implicitly deref generics if we allow them here, but primitives, tuples, and
0 commit comments