@@ -986,7 +986,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
986
986
// of the pattern, as this just looks confusing, instead use the span
987
987
// of the discriminant.
988
988
match bm. 0 {
989
- hir:: ByRef :: Yes ( m) => {
989
+ hir:: ByRef :: Yes ( _ , m) => {
990
990
let bk = ty:: BorrowKind :: from_mutbl ( m) ;
991
991
self . delegate . borrow_mut ( ) . borrow ( place, discr_place. hir_id , bk) ;
992
992
}
@@ -1004,7 +1004,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1004
1004
// Deref patterns on boxes don't borrow, so we ignore them here.
1005
1005
// HACK: this could be a fake pattern corresponding to a deref inserted by match
1006
1006
// ergonomics, in which case `pat.hir_id` will be the id of the subpattern.
1007
- if let hir:: ByRef :: Yes ( mutability) =
1007
+ if let hir:: ByRef :: Yes ( _ , mutability) =
1008
1008
self . cx . typeck_results ( ) . deref_pat_borrow_mode ( place. place . ty ( ) , subpattern)
1009
1009
{
1010
1010
let bk = ty:: BorrowKind :: from_mutbl ( mutability) ;
@@ -1256,15 +1256,23 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1256
1256
. get ( pat. hir_id )
1257
1257
. expect ( "missing binding mode" ) ;
1258
1258
1259
- if matches ! ( bm. 0 , hir:: ByRef :: Yes ( _) ) {
1259
+ if let hir:: ByRef :: Yes ( pinnedness, _) = bm. 0 {
1260
+ let base_ty = if pinnedness. is_pinned ( ) {
1261
+ base_ty. pinned_ty ( ) . ok_or_else ( || {
1262
+ debug ! ( "By-pin-ref binding of non-`Pin` type: {base_ty:?}" ) ;
1263
+ self . cx . report_bug ( pat. span , "by-pin-ref binding of non-`Pin` type" )
1264
+ } ) ?
1265
+ } else {
1266
+ base_ty
1267
+ } ;
1260
1268
// a bind-by-ref means that the base_ty will be the type of the ident itself,
1261
1269
// but what we want here is the type of the underlying value being borrowed.
1262
1270
// So peel off one-level, turning the &T into T.
1263
1271
match self . cx . structurally_resolve_type ( pat. span , base_ty) . builtin_deref ( false )
1264
1272
{
1265
1273
Some ( ty) => Ok ( ty) ,
1266
1274
None => {
1267
- debug ! ( "By-ref binding of non-derefable type" ) ;
1275
+ debug ! ( "By-ref binding of non-derefable type: {base_ty:?} " ) ;
1268
1276
Err ( self
1269
1277
. cx
1270
1278
. report_bug ( pat. span , "by-ref binding of non-derefable type" ) )
@@ -1706,6 +1714,18 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1706
1714
} ;
1707
1715
self . pat_deref_place ( pat. hir_id , place_with_id, pat, target_ty) ?
1708
1716
}
1717
+ adjustment:: PatAdjust :: PinDeref => {
1718
+ debug ! ( "`PinDeref` of non-pinned-reference type: {:?}" , adjust. source) ;
1719
+ let target_ty = adjust. source . pinned_ty ( ) . ok_or_else ( || {
1720
+ self . cx . report_bug (
1721
+ self . cx . tcx ( ) . hir_span ( pat. hir_id ) ,
1722
+ "`PinDeref` of non-pinned-reference type" ,
1723
+ )
1724
+ } ) ?;
1725
+ let kind = ProjectionKind :: Field ( FieldIdx :: ZERO , FIRST_VARIANT ) ;
1726
+ place_with_id = self . cat_projection ( pat. hir_id , place_with_id, target_ty, kind) ;
1727
+ self . cat_deref ( pat. hir_id , place_with_id) ?
1728
+ }
1709
1729
} ;
1710
1730
}
1711
1731
drop ( typeck_results) ; // explicitly release borrow of typeck results, just in case.
@@ -1877,7 +1897,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1877
1897
// Deref patterns on boxes are lowered using a built-in deref.
1878
1898
hir:: ByRef :: No => self . cat_deref ( hir_id, base_place) ,
1879
1899
// For other types, we create a temporary to match on.
1880
- hir:: ByRef :: Yes ( mutability) => {
1900
+ hir:: ByRef :: Yes ( _ , mutability) => {
1881
1901
let re_erased = self . cx . tcx ( ) . lifetimes . re_erased ;
1882
1902
let ty = Ty :: new_ref ( self . cx . tcx ( ) , re_erased, target_ty, mutability) ;
1883
1903
// A deref pattern stores the result of `Deref::deref` or `DerefMut::deref_mut` ...
0 commit comments