diff options
| author | bors <bors@rust-lang.org> | 2019-11-25 01:20:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-25 01:20:38 +0000 |
| commit | c9bacb70f0b19d324a548bd7942692ab18d159a4 (patch) | |
| tree | 66f7ee078e270f46163da47516b38139204476bb /src/libsyntax | |
| parent | 388ffd9df83cfac20b3fbf7128eb44d5b1526f8c (diff) | |
| parent | f4efc5de8a91c8322f83fe07ced5ab119a457ade (diff) | |
Auto merge of #66671 - matthewjasper:ast-address-of, r=Centril
Ast address-of This is the parts of #64588 that don't affect MIR. If an address-of expression makes it to MIR lowering we error and lower to the best currently expressible approximation to limit further errors. r? @Centril
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate/active.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate/check.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/mut_visit.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 37 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 2 |
6 files changed, 45 insertions, 23 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 14243076941..dc26929100a 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -754,6 +754,21 @@ impl Mutability { } } +/// The kind of borrow in an `AddrOf` expression, +/// e.g., `&place` or `&raw const place`. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)] +pub enum BorrowKind { + /// A raw borrow, `&raw const $expr` or `&raw mut $expr`. + /// The resulting type is either `*const T` or `*mut T` + /// where `T = typeof($expr)`. + Ref, + /// A normal borrow, `&$expr` or `&mut $expr`. + /// The resulting type is either `&'a T` or `&'a mut T` + /// where `T = typeof($expr)` and `'a` is some lifetime. + Raw, +} + #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] pub enum BinOpKind { /// The `+` operator (addition) @@ -1071,7 +1086,7 @@ impl Expr { ExprKind::Paren(expr) => expr.to_ty().map(TyKind::Paren)?, - ExprKind::AddrOf(mutbl, expr) => expr + ExprKind::AddrOf(BorrowKind::Ref, mutbl, expr) => expr .to_ty() .map(|ty| TyKind::Rptr(None, MutTy { ty, mutbl: *mutbl }))?, @@ -1262,8 +1277,8 @@ pub enum ExprKind { /// Optionally "qualified" (e.g., `<Vec<T> as SomeTrait>::SomeType`). Path(Option<QSelf>, Path), - /// A referencing operation (`&a` or `&mut a`). - AddrOf(Mutability, P<Expr>), + /// A referencing operation (`&a`, `&mut a`, `&raw const a` or `&raw mut a`). + AddrOf(BorrowKind, Mutability, P<Expr>), /// A `break`, with an optional label to break, and an optional expression. Break(Option<Label>, Option<P<Expr>>), /// A `continue`, with an optional label. diff --git a/src/libsyntax/feature_gate/active.rs b/src/libsyntax/feature_gate/active.rs index fa0ab90c702..b04b30aa6bc 100644 --- a/src/libsyntax/feature_gate/active.rs +++ b/src/libsyntax/feature_gate/active.rs @@ -520,13 +520,16 @@ declare_features! ( /// Allows using the `efiapi` ABI. (active, abi_efiapi, "1.40.0", Some(65815), None), + /// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions. + (active, raw_ref_op, "1.41.0", Some(64490), None), + /// Allows diverging expressions to fall back to `!` rather than `()`. (active, never_type_fallback, "1.41.0", Some(65992), None), /// Allows using the `#[register_attr]` attribute. (active, register_attr, "1.41.0", Some(66080), None), - /// Allows using the `#[register_attr]` attribute. + /// Allows using the `#[register_tool]` attribute. (active, register_tool, "1.41.0", Some(66079), None), /// Allows the use of `if` and `match` in constants. diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index f966850254f..846508bd0cd 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -866,6 +866,7 @@ pub fn check_crate(krate: &ast::Crate, gate_all!(generators, "yield syntax is experimental"); gate_all!(or_patterns, "or-patterns syntax is experimental"); gate_all!(const_extern_fn, "`const extern fn` definitions are unstable"); + gate_all!(raw_ref_op, "raw address of syntax is experimental"); // All uses of `gate_all!` below this point were added in #65742, // and subsequently disabled (with the non-early gating readded). diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index a7bd587ac9b..fbe28215a56 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -1128,7 +1128,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { kind, id, span, attrs }: &mut Expr, vis.visit_expr(expr); vis.visit_ty(ty); } - ExprKind::AddrOf(_m, ohs) => vis.visit_expr(ohs), + ExprKind::AddrOf(_, _, ohs) => vis.visit_expr(ohs), ExprKind::Let(pat, scrutinee) => { vis.visit_pat(pat); vis.visit_expr(scrutinee); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 17a7cbddff9..0d2e8dddce6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -984,16 +984,12 @@ impl<'a> State<'a> { } ast::TyKind::Ptr(ref mt) => { self.s.word("*"); - match mt.mutbl { - ast::Mutability::Mutable => self.word_nbsp("mut"), - ast::Mutability::Immutable => self.word_nbsp("const"), - } - self.print_type(&mt.ty); + self.print_mt(mt, true); } ast::TyKind::Rptr(ref lifetime, ref mt) => { self.s.word("&"); self.print_opt_lifetime(lifetime); - self.print_mt(mt); + self.print_mt(mt, false); } ast::TyKind::Never => { self.s.word("!"); @@ -1974,10 +1970,17 @@ impl<'a> State<'a> { } fn print_expr_addr_of(&mut self, + kind: ast::BorrowKind, mutability: ast::Mutability, expr: &ast::Expr) { self.s.word("&"); - self.print_mutability(mutability); + match kind { + ast::BorrowKind::Ref => self.print_mutability(mutability, false), + ast::BorrowKind::Raw => { + self.word_nbsp("raw"); + self.print_mutability(mutability, true); + } + } self.print_expr_maybe_paren(expr, parser::PREC_PREFIX) } @@ -2028,8 +2031,8 @@ impl<'a> State<'a> { ast::ExprKind::Unary(op, ref expr) => { self.print_expr_unary(op, expr); } - ast::ExprKind::AddrOf(m, ref expr) => { - self.print_expr_addr_of(m, expr); + ast::ExprKind::AddrOf(k, m, ref expr) => { + self.print_expr_addr_of(k, m, expr); } ast::ExprKind::Lit(ref lit) => { self.print_literal(lit); @@ -2361,7 +2364,7 @@ impl<'a> State<'a> { match binding_mode { ast::BindingMode::ByRef(mutbl) => { self.word_nbsp("ref"); - self.print_mutability(mutbl); + self.print_mutability(mutbl, false); } ast::BindingMode::ByValue(ast::Mutability::Immutable) => {} ast::BindingMode::ByValue(ast::Mutability::Mutable) => { @@ -2504,17 +2507,17 @@ impl<'a> State<'a> { fn print_explicit_self(&mut self, explicit_self: &ast::ExplicitSelf) { match explicit_self.node { SelfKind::Value(m) => { - self.print_mutability(m); + self.print_mutability(m, false); self.s.word("self") } SelfKind::Region(ref lt, m) => { self.s.word("&"); self.print_opt_lifetime(lt); - self.print_mutability(m); + self.print_mutability(m, false); self.s.word("self") } SelfKind::Explicit(ref typ, m) => { - self.print_mutability(m); + self.print_mutability(m, false); self.s.word("self"); self.word_space(":"); self.print_type(typ) @@ -2746,15 +2749,15 @@ impl<'a> State<'a> { } } - pub fn print_mutability(&mut self, mutbl: ast::Mutability) { + pub fn print_mutability(&mut self, mutbl: ast::Mutability, print_const: bool) { match mutbl { ast::Mutability::Mutable => self.word_nbsp("mut"), - ast::Mutability::Immutable => {}, + ast::Mutability::Immutable => if print_const { self.word_nbsp("const"); }, } } - crate fn print_mt(&mut self, mt: &ast::MutTy) { - self.print_mutability(mt.mutbl); + crate fn print_mt(&mut self, mt: &ast::MutTy, print_const: bool) { + self.print_mutability(mt.mutbl, print_const); self.print_type(&mt.ty) } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index f7b06c55a3a..5ff337fb60e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -708,7 +708,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { visitor.visit_expr(left_expression); visitor.visit_expr(right_expression) } - ExprKind::AddrOf(_, ref subexpression) | ExprKind::Unary(_, ref subexpression) => { + ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => { visitor.visit_expr(subexpression) } ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => { |
