@@ -985,7 +985,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
985
985
// of the pattern, as this just looks confusing, instead use the span
986
986
// of the discriminant.
987
987
match bm. 0 {
988
- hir:: ByRef :: Yes ( m) => {
988
+ hir:: ByRef :: Yes ( _ , m) => {
989
989
let bk = ty:: BorrowKind :: from_mutbl ( m) ;
990
990
self . delegate . borrow_mut ( ) . borrow ( place, discr_place. hir_id , bk) ;
991
991
}
@@ -1003,7 +1003,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1003
1003
// Deref patterns on boxes don't borrow, so we ignore them here.
1004
1004
// HACK: this could be a fake pattern corresponding to a deref inserted by match
1005
1005
// 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) =
1007
1007
self . cx . typeck_results ( ) . deref_pat_borrow_mode ( place. place . ty ( ) , subpattern)
1008
1008
{
1009
1009
let bk = ty:: BorrowKind :: from_mutbl ( mutability) ;
@@ -1255,22 +1255,34 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1255
1255
. get ( pat. hir_id )
1256
1256
. expect ( "missing binding mode" ) ;
1257
1257
1258
- if matches ! ( bm. 0 , hir:: ByRef :: Yes ( _) ) {
1259
- // a bind-by-ref means that the base_ty will be the type of the ident itself,
1260
- // but what we want here is the type of the underlying value being borrowed.
1261
- // So peel off one-level, turning the &T into T.
1262
- match self . cx . structurally_resolve_type ( pat. span , base_ty) . builtin_deref ( false )
1263
- {
1264
- Some ( ty) => Ok ( ty) ,
1265
- None => {
1266
- debug ! ( "By-ref binding of non-derefable type" ) ;
1267
- Err ( self
1268
- . cx
1269
- . report_bug ( pat. span , "by-ref binding of non-derefable type" ) )
1258
+ match bm. 0 {
1259
+ hir:: ByRef :: Yes ( pinnedness, _) => {
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" ) ;
1263
+ self . cx . report_bug ( pat. span , "by-pin-ref binding of non-`Pin` type" )
1264
+ } ) ?
1265
+ } else {
1266
+ base_ty
1267
+ } ;
1268
+ // a bind-by-ref means that the base_ty will be the type of the ident itself,
1269
+ // but what we want here is the type of the underlying value being borrowed.
1270
+ // So peel off one-level, turning the &T into T.
1271
+ match self
1272
+ . cx
1273
+ . structurally_resolve_type ( pat. span , base_ty)
1274
+ . builtin_deref ( false )
1275
+ {
1276
+ Some ( ty) => Ok ( ty) ,
1277
+ None => {
1278
+ debug ! ( "By-ref binding of non-derefable type" ) ;
1279
+ Err ( self
1280
+ . cx
1281
+ . report_bug ( pat. span , "by-ref binding of non-derefable type" ) )
1282
+ }
1270
1283
}
1271
1284
}
1272
- } else {
1273
- Ok ( base_ty)
1285
+ _ => Ok ( base_ty) ,
1274
1286
}
1275
1287
}
1276
1288
_ => Ok ( base_ty) ,
@@ -1696,6 +1708,16 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1696
1708
} ;
1697
1709
self . pat_deref_place ( pat. hir_id , place_with_id, pat, target_ty) ?
1698
1710
}
1711
+ adjustment:: PatAdjust :: PinDeref => {
1712
+ let target_ty = match adjusts. peek ( ) {
1713
+ Some ( & & next_adjust) => next_adjust. source ,
1714
+ // At the end of the deref chain, we get `pat`'s scrutinee.
1715
+ None => self . pat_ty_unadjusted ( pat) ?,
1716
+ } ;
1717
+ let kind = ProjectionKind :: Field ( FieldIdx :: ZERO , FIRST_VARIANT ) ;
1718
+ place_with_id = self . cat_projection ( pat. hir_id , place_with_id, target_ty, kind) ;
1719
+ self . cat_deref ( pat. hir_id , place_with_id) ?
1720
+ }
1699
1721
} ;
1700
1722
}
1701
1723
drop ( typeck_results) ; // explicitly release borrow of typeck results, just in case.
@@ -1867,7 +1889,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
1867
1889
// Deref patterns on boxes are lowered using a built-in deref.
1868
1890
hir:: ByRef :: No => self . cat_deref ( hir_id, base_place) ,
1869
1891
// For other types, we create a temporary to match on.
1870
- hir:: ByRef :: Yes ( mutability) => {
1892
+ hir:: ByRef :: Yes ( _ , mutability) => {
1871
1893
let re_erased = self . cx . tcx ( ) . lifetimes . re_erased ;
1872
1894
let ty = Ty :: new_ref ( self . cx . tcx ( ) , re_erased, target_ty, mutability) ;
1873
1895
// A deref pattern stores the result of `Deref::deref` or `DerefMut::deref_mut` ...
0 commit comments