@@ -985,7 +985,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
985985 // of the pattern, as this just looks confusing, instead use the span
986986 // of the discriminant.
987987 match bm. 0 {
988- hir:: ByRef :: Yes ( m) => {
988+ hir:: ByRef :: Yes ( _ , m) => {
989989 let bk = ty:: BorrowKind :: from_mutbl ( m) ;
990990 self . delegate . borrow_mut ( ) . borrow ( place, discr_place. hir_id , bk) ;
991991 }
@@ -1003,7 +1003,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
10031003 // Deref patterns on boxes don't borrow, so we ignore them here.
10041004 // HACK: this could be a fake pattern corresponding to a deref inserted by match
10051005 // ergonomics, in which case `pat.hir_id` will be the id of the subpattern.
1006- if let hir:: ByRef :: Yes ( mutability) =
1006+ if let hir:: ByRef :: Yes ( _ , mutability) =
10071007 self . cx . typeck_results ( ) . deref_pat_borrow_mode ( place. place . ty ( ) , subpattern)
10081008 {
10091009 let bk = ty:: BorrowKind :: from_mutbl ( mutability) ;
@@ -1255,15 +1255,23 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
12551255 . get ( pat. hir_id )
12561256 . expect ( "missing binding mode" ) ;
12571257
1258- if matches ! ( bm. 0 , hir:: ByRef :: Yes ( _) ) {
1258+ if let hir:: ByRef :: Yes ( pinnedness, _) = bm. 0 {
1259+ let base_ty = if pinnedness. is_pinned ( ) {
1260+ base_ty. pinned_ty ( ) . ok_or_else ( || {
1261+ debug ! ( "By-pin-ref binding of non-`Pin` type: {base_ty:?}" ) ;
1262+ self . cx . report_bug ( pat. span , "by-pin-ref binding of non-`Pin` type" )
1263+ } ) ?
1264+ } else {
1265+ base_ty
1266+ } ;
12591267 // a bind-by-ref means that the base_ty will be the type of the ident itself,
12601268 // but what we want here is the type of the underlying value being borrowed.
12611269 // So peel off one-level, turning the &T into T.
12621270 match self . cx . structurally_resolve_type ( pat. span , base_ty) . builtin_deref ( false )
12631271 {
12641272 Some ( ty) => Ok ( ty) ,
12651273 None => {
1266- debug ! ( "By-ref binding of non-derefable type" ) ;
1274+ debug ! ( "By-ref binding of non-derefable type: {base_ty:?} " ) ;
12671275 Err ( self
12681276 . cx
12691277 . report_bug ( pat. span , "by-ref binding of non-derefable type" ) )
@@ -1696,6 +1704,18 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
16961704 } ;
16971705 self . pat_deref_place ( pat. hir_id , place_with_id, pat, target_ty) ?
16981706 }
1707+ adjustment:: PatAdjust :: PinDeref => {
1708+ debug ! ( "`PinDeref` of non-pinned-reference type: {:?}" , adjust. source) ;
1709+ let target_ty = adjust. source . pinned_ty ( ) . ok_or_else ( || {
1710+ self . cx . report_bug (
1711+ self . cx . tcx ( ) . hir_span ( pat. hir_id ) ,
1712+ "`PinDeref` of non-pinned-reference type" ,
1713+ )
1714+ } ) ?;
1715+ let kind = ProjectionKind :: Field ( FieldIdx :: ZERO , FIRST_VARIANT ) ;
1716+ place_with_id = self . cat_projection ( pat. hir_id , place_with_id, target_ty, kind) ;
1717+ self . cat_deref ( pat. hir_id , place_with_id) ?
1718+ }
16991719 } ;
17001720 }
17011721 drop ( typeck_results) ; // explicitly release borrow of typeck results, just in case.
@@ -1867,7 +1887,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
18671887 // Deref patterns on boxes are lowered using a built-in deref.
18681888 hir:: ByRef :: No => self . cat_deref ( hir_id, base_place) ,
18691889 // For other types, we create a temporary to match on.
1870- hir:: ByRef :: Yes ( mutability) => {
1890+ hir:: ByRef :: Yes ( _ , mutability) => {
18711891 let re_erased = self . cx . tcx ( ) . lifetimes . re_erased ;
18721892 let ty = Ty :: new_ref ( self . cx . tcx ( ) , re_erased, target_ty, mutability) ;
18731893 // A deref pattern stores the result of `Deref::deref` or `DerefMut::deref_mut` ...
0 commit comments