From a8efd31f2b97a043d73db2131dddfedd65485d50 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 23 Nov 2019 14:15:49 +0000 Subject: Add raw address of expressions to the AST and HIR --- src/libsyntax/ast.rs | 21 ++++++++++++++++++--- src/libsyntax/mut_visit.rs | 2 +- src/libsyntax/print/pprust.rs | 37 ++++++++++++++++++++----------------- src/libsyntax/visit.rs | 2 +- 4 files changed, 40 insertions(+), 22 deletions(-) (limited to 'src/libsyntax') 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., ` as SomeTrait>::SomeType`). Path(Option, Path), - /// A referencing operation (`&a` or `&mut a`). - AddrOf(Mutability, P), + /// A referencing operation (`&a`, `&mut a`, `&raw const a` or `&raw mut a`). + AddrOf(BorrowKind, Mutability, P), /// A `break`, with an optional label to break, and an optional expression. Break(Option