@@ -5,7 +5,7 @@ use rustc_ast::{
55 self as ast, BareFnTy , BoundAsyncness , BoundConstness , BoundPolarity , DUMMY_NODE_ID , FnRetTy ,
66 GenericBound , GenericBounds , GenericParam , Generics , Lifetime , MacCall , MutTy , Mutability ,
77 Pinnedness , PolyTraitRef , PreciseCapturingArg , TraitBoundModifiers , TraitObjectSyntax , Ty ,
8- TyKind ,
8+ TyKind , UnsafeBinderTy ,
99} ;
1010use rustc_errors:: { Applicability , PResult } ;
1111use rustc_span:: symbol:: { Ident , kw, sym} ;
@@ -348,6 +348,8 @@ impl<'a> Parser<'a> {
348348 TyKind :: Err ( guar)
349349 }
350350 }
351+ } else if self . check_keyword ( kw:: Unsafe ) {
352+ self . parse_unsafe_binder_ty ( ) ?
351353 } else {
352354 let msg = format ! ( "expected type, found {}" , super :: token_descr( & self . token) ) ;
353355 let mut err = self . dcx ( ) . struct_span_err ( lo, msg) ;
@@ -369,6 +371,19 @@ impl<'a> Parser<'a> {
369371 if allow_qpath_recovery { self . maybe_recover_from_bad_qpath ( ty) } else { Ok ( ty) }
370372 }
371373
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+
372387 /// Parses either:
373388 /// - `(TYPE)`, a parenthesized type.
374389 /// - `(TYPE,)`, a tuple with a single field of type TYPE.
0 commit comments