@@ -8,7 +8,7 @@ use rustc_ast::{
8
8
} ;
9
9
pub use rustc_ast:: {
10
10
BinOp , BinOpKind , BindingMode , BorrowKind , BoundConstness , BoundPolarity , ByRef , CaptureBy ,
11
- ImplPolarity , IsAuto , Movability , Mutability , UnOp ,
11
+ ImplPolarity , IsAuto , Movability , Mutability , UnOp , UnsafeBinderCastKind ,
12
12
} ;
13
13
use rustc_data_structures:: fingerprint:: Fingerprint ;
14
14
use rustc_data_structures:: sorted_map:: SortedMap ;
@@ -1740,6 +1740,7 @@ impl Expr<'_> {
1740
1740
| ExprKind :: Struct ( ..)
1741
1741
| ExprKind :: Tup ( _)
1742
1742
| ExprKind :: Type ( ..)
1743
+ | ExprKind :: UnsafeBinderCast ( ..)
1743
1744
| ExprKind :: Err ( _) => ExprPrecedence :: Unambiguous ,
1744
1745
1745
1746
ExprKind :: DropTemps ( ref expr, ..) => expr. precedence ( ) ,
@@ -1769,6 +1770,9 @@ impl Expr<'_> {
1769
1770
// https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md#type-ascription-and-temporaries
1770
1771
ExprKind :: Type ( ref e, _) => e. is_place_expr ( allow_projections_from) ,
1771
1772
1773
+ // Unsafe binder cast preserves place-ness of the sub-expression.
1774
+ ExprKind :: UnsafeBinderCast ( _, e, _) => e. is_place_expr ( allow_projections_from) ,
1775
+
1772
1776
ExprKind :: Unary ( UnOp :: Deref , _) => true ,
1773
1777
1774
1778
ExprKind :: Field ( ref base, _) | ExprKind :: Index ( ref base, _, _) => {
@@ -1850,7 +1854,8 @@ impl Expr<'_> {
1850
1854
| ExprKind :: Field ( base, _)
1851
1855
| ExprKind :: Index ( base, _, _)
1852
1856
| ExprKind :: AddrOf ( .., base)
1853
- | ExprKind :: Cast ( base, _) => {
1857
+ | ExprKind :: Cast ( base, _)
1858
+ | ExprKind :: UnsafeBinderCast ( _, base, _) => {
1854
1859
// This isn't exactly true for `Index` and all `Unary`, but we are using this
1855
1860
// method exclusively for diagnostics and there's a *cultural* pressure against
1856
1861
// them being used only for its side-effects.
@@ -2144,6 +2149,10 @@ pub enum ExprKind<'hir> {
2144
2149
/// A suspension point for coroutines (i.e., `yield <expr>`).
2145
2150
Yield ( & ' hir Expr < ' hir > , YieldSource ) ,
2146
2151
2152
+ /// Operators which can be used to interconvert `unsafe` binder types.
2153
+ /// e.g. `unsafe<'a> &'a i32` <=> `&i32`.
2154
+ UnsafeBinderCast ( UnsafeBinderCastKind , & ' hir Expr < ' hir > , Option < & ' hir Ty < ' hir > > ) ,
2155
+
2147
2156
/// A placeholder for an expression that wasn't syntactically well formed in some way.
2148
2157
Err ( rustc_span:: ErrorGuaranteed ) ,
2149
2158
}
@@ -2780,6 +2789,12 @@ pub struct BareFnTy<'hir> {
2780
2789
pub param_names : & ' hir [ Ident ] ,
2781
2790
}
2782
2791
2792
+ #[ derive( Debug , Clone , Copy , HashStable_Generic ) ]
2793
+ pub struct UnsafeBinderTy < ' hir > {
2794
+ pub generic_params : & ' hir [ GenericParam < ' hir > ] ,
2795
+ pub inner_ty : & ' hir Ty < ' hir > ,
2796
+ }
2797
+
2783
2798
#[ derive( Debug , Clone , Copy , HashStable_Generic ) ]
2784
2799
pub struct OpaqueTy < ' hir > {
2785
2800
pub hir_id : HirId ,
@@ -2878,6 +2893,8 @@ pub enum TyKind<'hir> {
2878
2893
Ref ( & ' hir Lifetime , MutTy < ' hir > ) ,
2879
2894
/// A bare function (e.g., `fn(usize) -> bool`).
2880
2895
BareFn ( & ' hir BareFnTy < ' hir > ) ,
2896
+ /// An unsafe binder type (e.g. `unsafe<'a> Foo<'a>`).
2897
+ UnsafeBinder ( & ' hir UnsafeBinderTy < ' hir > ) ,
2881
2898
/// The never type (`!`).
2882
2899
Never ,
2883
2900
/// A tuple (`(A, B, C, D, ...)`).
0 commit comments