Skip to content

Commit 686de87

Browse files
Rollup merge of #55777 - nnethercote:less-P-in-ast, r=petrochenkov
Use `Lit` rather than `P<Lit>` in `ast::ExprKind`. Because it results in fewer allocations and small speedups on some benchmarks.
2 parents 7125b8f + 706c2ad commit 686de87

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3705,7 +3705,7 @@ impl<'a> LoweringContext<'a> {
37053705
let ohs = P(self.lower_expr(ohs));
37063706
hir::ExprKind::Unary(op, ohs)
37073707
}
3708-
ExprKind::Lit(ref l) => hir::ExprKind::Lit(P((**l).clone())),
3708+
ExprKind::Lit(ref l) => hir::ExprKind::Lit(P((*l).clone())),
37093709
ExprKind::Cast(ref expr, ref ty) => {
37103710
let expr = P(self.lower_expr(expr));
37113711
hir::ExprKind::Cast(expr, self.lower_ty(ty, ImplTraitContext::disallowed()))

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ pub enum ExprKind {
10861086
/// A unary operation (For example: `!x`, `*x`)
10871087
Unary(UnOp, P<Expr>),
10881088
/// A literal (For example: `1`, `"foo"`)
1089-
Lit(P<Lit>),
1089+
Lit(Lit),
10901090
/// A cast (`foo as f64`)
10911091
Cast(P<Expr>, P<Ty>),
10921092
Type(P<Expr>, P<Ty>),

src/libsyntax/ext/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ impl DummyResult {
491491
pub fn raw_expr(sp: Span) -> P<ast::Expr> {
492492
P(ast::Expr {
493493
id: ast::DUMMY_NODE_ID,
494-
node: ast::ExprKind::Lit(P(source_map::respan(sp, ast::LitKind::Bool(false)))),
494+
node: ast::ExprKind::Lit(source_map::respan(sp, ast::LitKind::Bool(false))),
495495
span: sp,
496496
attrs: ThinVec::new(),
497497
})

src/libsyntax/ext/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
695695
}
696696

697697
fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P<ast::Expr> {
698-
self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit))))
698+
self.expr(sp, ast::ExprKind::Lit(respan(sp, lit)))
699699
}
700700
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
701701
self.expr_lit(span, ast::LitKind::Int(i as u128,

src/libsyntax/ext/quote.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub mod rt {
274274
// FIXME: This is wrong
275275
P(ast::Expr {
276276
id: ast::DUMMY_NODE_ID,
277-
node: ast::ExprKind::Lit(P(self.clone())),
277+
node: ast::ExprKind::Lit(self.clone()),
278278
span: DUMMY_SP,
279279
attrs: ThinVec::new(),
280280
}).to_tokens(cx)
@@ -305,7 +305,7 @@ pub mod rt {
305305
let lit = ast::LitKind::Int(val as u128, ast::LitIntType::Signed($tag));
306306
let lit = P(ast::Expr {
307307
id: ast::DUMMY_NODE_ID,
308-
node: ast::ExprKind::Lit(P(dummy_spanned(lit))),
308+
node: ast::ExprKind::Lit(dummy_spanned(lit)),
309309
span: DUMMY_SP,
310310
attrs: ThinVec::new(),
311311
});

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ impl<'a> Parser<'a> {
19891989
let minus_lo = self.span;
19901990
let minus_present = self.eat(&token::BinOp(token::Minus));
19911991
let lo = self.span;
1992-
let literal = P(self.parse_lit()?);
1992+
let literal = self.parse_lit()?;
19931993
let hi = self.prev_span;
19941994
let expr = self.mk_expr(lo.to(hi), ExprKind::Lit(literal), ThinVec::new());
19951995

0 commit comments

Comments
 (0)