]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #55777 - nnethercote:less-P-in-ast, r=petrochenkov
authorMark Rousskov <mark.simulacrum@gmail.com>
Fri, 9 Nov 2018 01:15:19 +0000 (18:15 -0700)
committerGitHub <noreply@github.com>
Fri, 9 Nov 2018 01:15:19 +0000 (18:15 -0700)
Use `Lit` rather than `P<Lit>` in `ast::ExprKind`.

Because it results in fewer allocations and small speedups on some
benchmarks.

src/librustc/hir/lowering.rs
src/libsyntax/ast.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/build.rs
src/libsyntax/ext/quote.rs
src/libsyntax/parse/parser.rs

index e558d945516713d2f690d4b698cbadc6a3c6a886..dd5d4b8f6afff546875f9d0d29e4aad19e103f3a 100644 (file)
@@ -3705,7 +3705,7 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
                 let ohs = P(self.lower_expr(ohs));
                 hir::ExprKind::Unary(op, ohs)
             }
-            ExprKind::Lit(ref l) => hir::ExprKind::Lit(P((**l).clone())),
+            ExprKind::Lit(ref l) => hir::ExprKind::Lit(P((*l).clone())),
             ExprKind::Cast(ref expr, ref ty) => {
                 let expr = P(self.lower_expr(expr));
                 hir::ExprKind::Cast(expr, self.lower_ty(ty, ImplTraitContext::disallowed()))
index cfedda18a7e22886e2e972cc30d82a36157976a5..2f17bc0548cad75c77fa58445fff0e92e99ffea5 100644 (file)
@@ -1086,7 +1086,7 @@ pub enum ExprKind {
     /// A unary operation (For example: `!x`, `*x`)
     Unary(UnOp, P<Expr>),
     /// A literal (For example: `1`, `"foo"`)
-    Lit(P<Lit>),
+    Lit(Lit),
     /// A cast (`foo as f64`)
     Cast(P<Expr>, P<Ty>),
     Type(P<Expr>, P<Ty>),
index 1701c8da2c5bdc6283b491a97c45d3b516ca046f..88ee80e60888f93a2d8cace0b01a332e29443aa5 100644 (file)
@@ -491,7 +491,7 @@ pub fn expr(sp: Span) -> Box<dyn MacResult+'static> {
     pub fn raw_expr(sp: Span) -> P<ast::Expr> {
         P(ast::Expr {
             id: ast::DUMMY_NODE_ID,
-            node: ast::ExprKind::Lit(P(source_map::respan(sp, ast::LitKind::Bool(false)))),
+            node: ast::ExprKind::Lit(source_map::respan(sp, ast::LitKind::Bool(false))),
             span: sp,
             attrs: ThinVec::new(),
         })
index 7928ec1606b1d5b986db8f9a7df31474016d851d..cacec867cf198053cc6b187d4bf9cba2db551dcb 100644 (file)
@@ -695,7 +695,7 @@ fn expr_struct_ident(&self, span: Span,
     }
 
     fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P<ast::Expr> {
-        self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit))))
+        self.expr(sp, ast::ExprKind::Lit(respan(sp, lit)))
     }
     fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
         self.expr_lit(span, ast::LitKind::Int(i as u128,
index 37800a334c6daf7ca4d54efe97e76ef9fb902426..c6e0adbb5a43e087a73b867cd13843dcc1db37a5 100644 (file)
@@ -274,7 +274,7 @@ fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
             // FIXME: This is wrong
             P(ast::Expr {
                 id: ast::DUMMY_NODE_ID,
-                node: ast::ExprKind::Lit(P(self.clone())),
+                node: ast::ExprKind::Lit(self.clone()),
                 span: DUMMY_SP,
                 attrs: ThinVec::new(),
             }).to_tokens(cx)
@@ -305,7 +305,7 @@ fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
                     let lit = ast::LitKind::Int(val as u128, ast::LitIntType::Signed($tag));
                     let lit = P(ast::Expr {
                         id: ast::DUMMY_NODE_ID,
-                        node: ast::ExprKind::Lit(P(dummy_spanned(lit))),
+                        node: ast::ExprKind::Lit(dummy_spanned(lit)),
                         span: DUMMY_SP,
                         attrs: ThinVec::new(),
                     });
index c8a686da179fbbcba51d828313dcced3743ee9fc..68e7e40c43efe4a1b74c035905c376c629e5662f 100644 (file)
@@ -1989,7 +1989,7 @@ fn parse_lit_token(&mut self) -> PResult<'a, LitKind> {
         let minus_lo = self.span;
         let minus_present = self.eat(&token::BinOp(token::Minus));
         let lo = self.span;
-        let literal = P(self.parse_lit()?);
+        let literal = self.parse_lit()?;
         let hi = self.prev_span;
         let expr = self.mk_expr(lo.to(hi), ExprKind::Lit(literal), ThinVec::new());