diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2019-11-23 14:15:49 +0000 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2019-11-24 18:06:13 +0000 |
| commit | a8efd31f2b97a043d73db2131dddfedd65485d50 (patch) | |
| tree | d5eef5952391f5bf162f3ce4a4470255157843f0 /src/libsyntax/print | |
| parent | 9420ff4c0ebea44b167d530bb59f9d5721d8ff0b (diff) | |
| download | rust-a8efd31f2b97a043d73db2131dddfedd65485d50.tar.gz rust-a8efd31f2b97a043d73db2131dddfedd65485d50.zip | |
Add raw address of expressions to the AST and HIR
Diffstat (limited to 'src/libsyntax/print')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 37 |
1 files changed, 20 insertions, 17 deletions
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) } |
