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.
This commit is contained in:
Mark Rousskov 2018-11-08 18:15:19 -07:00 committed by GitHub
commit 686de87d2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 7 additions and 7 deletions

View 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()))

View 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>),

View 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(),
})

View 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,

View 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(),
});

View 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());