@@ -176,17 +176,19 @@ enum AdjustMode<'tcx> {
176176/// Restrictions on what types to peel when adjusting the expected type and binding mode.
177177#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
178178enum 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 > > } ,
185187}
186188
187189impl < ' tcx > AdjustMode < ' tcx > {
188190 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 } }
190192 }
191193 const fn peel_all ( ) -> AdjustMode < ' tcx > {
192194 AdjustMode :: peel_until_adt ( None )
@@ -585,7 +587,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
585587 // FIXME(deref_patterns): If box patterns and deref patterns need to coexist, box
586588 // patterns may want `PeelKind::Overloaded`, stopping on encountering a box.
587589 | PatKind :: Box ( _)
588- | PatKind :: Deref ( _) => AdjustMode :: Peel { kind : PeelKind :: RefOnly } ,
590+ | PatKind :: Deref ( _) => AdjustMode :: Peel { kind : PeelKind :: ExplicitDerefPat } ,
589591 // A never pattern behaves somewhat like a literal or unit variant.
590592 PatKind :: Never => AdjustMode :: peel_all ( ) ,
591593 // 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> {
651653 //
652654 // For each ampersand peeled off, update the binding mode and push the original
653655 // 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.
655657 //
656658 // See the examples in `tests/ui/rfcs/rfc-2005-default-binding-mode/` and
657659 // `tests/ui/pattern/deref-patterns/`.
@@ -670,7 +672,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
670672 } ) ;
671673 inner_ty
672674 } else if deref_patterns
673- && let PeelKind :: Overloaded { until_adt } = peel_kind
675+ && let PeelKind :: Implicit { until_adt } = peel_kind
674676 // For simplicity, only apply overloaded derefs if `expected` is a known ADT.
675677 // FIXME(deref_patterns): we'll get better diagnostics for users trying to
676678 // implicitly deref generics if we allow them here, but primitives, tuples, and
0 commit comments