@@ -5,7 +5,7 @@ use rustc_ast::{
5
5
self as ast, BareFnTy , BoundAsyncness , BoundConstness , BoundPolarity , DUMMY_NODE_ID , FnRetTy ,
6
6
GenericBound , GenericBounds , GenericParam , Generics , Lifetime , MacCall , MutTy , Mutability ,
7
7
Pinnedness , PolyTraitRef , PreciseCapturingArg , TraitBoundModifiers , TraitObjectSyntax , Ty ,
8
- TyKind ,
8
+ TyKind , UnsafeBinderTy ,
9
9
} ;
10
10
use rustc_errors:: { Applicability , PResult } ;
11
11
use rustc_span:: symbol:: { Ident , kw, sym} ;
@@ -348,6 +348,8 @@ impl<'a> Parser<'a> {
348
348
TyKind :: Err ( guar)
349
349
}
350
350
}
351
+ } else if self . check_keyword ( kw:: Unsafe ) {
352
+ self . parse_unsafe_binder_ty ( ) ?
351
353
} else {
352
354
let msg = format ! ( "expected type, found {}" , super :: token_descr( & self . token) ) ;
353
355
let mut err = self . dcx ( ) . struct_span_err ( lo, msg) ;
@@ -369,6 +371,19 @@ impl<'a> Parser<'a> {
369
371
if allow_qpath_recovery { self . maybe_recover_from_bad_qpath ( ty) } else { Ok ( ty) }
370
372
}
371
373
374
+ fn parse_unsafe_binder_ty ( & mut self ) -> PResult < ' a , TyKind > {
375
+ let lo = self . token . span ;
376
+ assert ! ( self . eat_keyword( kw:: Unsafe ) ) ;
377
+ self . expect_lt ( ) ?;
378
+ let generic_params = self . parse_generic_params ( ) ?;
379
+ self . expect_gt ( ) ?;
380
+ let inner_ty = self . parse_ty ( ) ?;
381
+ let span = lo. to ( self . prev_token . span ) ;
382
+ self . psess . gated_spans . gate ( sym:: unsafe_binders, span) ;
383
+
384
+ Ok ( TyKind :: UnsafeBinder ( P ( UnsafeBinderTy { generic_params, inner_ty } ) ) )
385
+ }
386
+
372
387
/// Parses either:
373
388
/// - `(TYPE)`, a parenthesized type.
374
389
/// - `(TYPE,)`, a tuple with a single field of type TYPE.
0 commit comments