Remove hir::Expr::attrs.
This commit is contained in:
parent
c701872a6c
commit
fb753cced8
|
@ -258,10 +258,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
ex.span = e.span;
|
ex.span = e.span;
|
||||||
}
|
}
|
||||||
// Merge attributes into the inner expression.
|
// Merge attributes into the inner expression.
|
||||||
let mut attrs: Vec<_> = e.attrs.iter().map(|a| self.lower_attr(a)).collect();
|
self.attrs[ex.hir_id] = &*self.arena.alloc_from_iter(
|
||||||
attrs.extend::<Vec<_>>(ex.attrs.into());
|
e.attrs
|
||||||
self.attrs[ex.hir_id] = &*self.arena.alloc_from_iter(attrs.iter().cloned());
|
.iter()
|
||||||
ex.attrs = attrs.into();
|
.map(|a| self.lower_attr(a))
|
||||||
|
.chain(self.attrs[ex.hir_id].iter().cloned()),
|
||||||
|
);
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,9 +276,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let hir_id = self.lower_node_id(e.id);
|
let hir_id = self.lower_node_id(e.id);
|
||||||
let attrs = e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>();
|
self.lower_attrs(hir_id, &e.attrs);
|
||||||
self.attrs.push_sparse(hir_id, &*self.arena.alloc_from_iter(attrs.iter().cloned()));
|
hir::Expr { hir_id, kind, span: e.span }
|
||||||
hir::Expr { hir_id, kind, span: e.span, attrs: attrs.into() }
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,12 +685,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
span,
|
span,
|
||||||
Some(hir::Movability::Static),
|
Some(hir::Movability::Static),
|
||||||
);
|
);
|
||||||
let generator = hir::Expr {
|
let generator =
|
||||||
hir_id: self.lower_node_id(closure_node_id),
|
hir::Expr { hir_id: self.lower_node_id(closure_node_id), kind: generator_kind, span };
|
||||||
kind: generator_kind,
|
|
||||||
span,
|
|
||||||
attrs: ThinVec::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// `future::from_generator`:
|
// `future::from_generator`:
|
||||||
let unstable_span =
|
let unstable_span =
|
||||||
|
@ -843,7 +840,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
hir_id: loop_hir_id,
|
hir_id: loop_hir_id,
|
||||||
kind: hir::ExprKind::Loop(loop_block, None, hir::LoopSource::Loop, span),
|
kind: hir::ExprKind::Loop(loop_block, None, hir::LoopSource::Loop, span),
|
||||||
span,
|
span,
|
||||||
attrs: ThinVec::new(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// mut pinned => loop { ... }
|
// mut pinned => loop { ... }
|
||||||
|
@ -1813,12 +1809,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
hir::LoopSource::ForLoop,
|
hir::LoopSource::ForLoop,
|
||||||
e.span.with_hi(orig_head_span.hi()),
|
e.span.with_hi(orig_head_span.hi()),
|
||||||
);
|
);
|
||||||
let loop_expr = self.arena.alloc(hir::Expr {
|
let loop_expr =
|
||||||
hir_id: self.lower_node_id(e.id),
|
self.arena.alloc(hir::Expr { hir_id: self.lower_node_id(e.id), kind, span: e.span });
|
||||||
kind,
|
|
||||||
span: e.span,
|
|
||||||
attrs: ThinVec::new(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// `mut iter => { ... }`
|
// `mut iter => { ... }`
|
||||||
let iter_arm = self.arm(iter_pat, loop_expr);
|
let iter_arm = self.arm(iter_pat, loop_expr);
|
||||||
|
@ -2154,8 +2146,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
attrs: AttrVec,
|
attrs: AttrVec,
|
||||||
) -> hir::Expr<'hir> {
|
) -> hir::Expr<'hir> {
|
||||||
let hir_id = self.next_id();
|
let hir_id = self.next_id();
|
||||||
self.attrs.push_sparse(hir_id, &*self.arena.alloc_from_iter(attrs.iter().cloned()));
|
self.lower_attrs(hir_id, &attrs);
|
||||||
hir::Expr { hir_id, kind, span, attrs }
|
hir::Expr { hir_id, kind, span }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn field(&mut self, ident: Ident, expr: &'hir hir::Expr<'hir>, span: Span) -> hir::Field<'hir> {
|
fn field(&mut self, ident: Ident, expr: &'hir hir::Expr<'hir>, span: Span) -> hir::Field<'hir> {
|
||||||
|
|
|
@ -979,7 +979,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
|
fn lower_attr(&self, attr: &Attribute) -> Attribute {
|
||||||
// Note that we explicitly do not walk the path. Since we don't really
|
// Note that we explicitly do not walk the path. Since we don't really
|
||||||
// lower attributes (we use the AST version) there is nowhere to keep
|
// lower attributes (we use the AST version) there is nowhere to keep
|
||||||
// the `HirId`s. We don't actually need HIR version of attributes anyway.
|
// the `HirId`s. We don't actually need HIR version of attributes anyway.
|
||||||
|
@ -999,7 +999,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
Attribute { kind, id: attr.id, style: attr.style, span: attr.span }
|
Attribute { kind, id: attr.id, style: attr.style, span: attr.span }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_mac_args(&mut self, args: &MacArgs) -> MacArgs {
|
fn lower_mac_args(&self, args: &MacArgs) -> MacArgs {
|
||||||
match *args {
|
match *args {
|
||||||
MacArgs::Empty => MacArgs::Empty,
|
MacArgs::Empty => MacArgs::Empty,
|
||||||
MacArgs::Delimited(dspan, delim, ref tokens) => {
|
MacArgs::Delimited(dspan, delim, ref tokens) => {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::{itemlikevisit, HirIdVec, LangItem};
|
||||||
|
|
||||||
use rustc_ast::util::parser::ExprPrecedence;
|
use rustc_ast::util::parser::ExprPrecedence;
|
||||||
use rustc_ast::{self as ast, CrateSugar, LlvmAsmDialect};
|
use rustc_ast::{self as ast, CrateSugar, LlvmAsmDialect};
|
||||||
use rustc_ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
|
use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
|
||||||
pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
|
pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
|
||||||
pub use rustc_ast::{CaptureBy, Movability, Mutability};
|
pub use rustc_ast::{CaptureBy, Movability, Mutability};
|
||||||
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||||
|
@ -1446,7 +1446,6 @@ pub struct AnonConst {
|
||||||
pub struct Expr<'hir> {
|
pub struct Expr<'hir> {
|
||||||
pub hir_id: HirId,
|
pub hir_id: HirId,
|
||||||
pub kind: ExprKind<'hir>,
|
pub kind: ExprKind<'hir>,
|
||||||
pub attrs: AttrVec,
|
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3071,7 +3070,7 @@ impl<'hir> Node<'hir> {
|
||||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||||
mod size_asserts {
|
mod size_asserts {
|
||||||
rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
|
rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
|
||||||
rustc_data_structures::static_assert_size!(super::Expr<'static>, 72);
|
rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
|
||||||
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
|
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
|
||||||
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
|
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
|
||||||
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
|
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
|
||||||
|
|
|
@ -1334,7 +1334,7 @@ impl<'a> State<'a> {
|
||||||
|
|
||||||
pub fn print_expr(&mut self, expr: &hir::Expr<'_>) {
|
pub fn print_expr(&mut self, expr: &hir::Expr<'_>) {
|
||||||
self.maybe_print_comment(expr.span.lo());
|
self.maybe_print_comment(expr.span.lo());
|
||||||
self.print_outer_attributes(&expr.attrs);
|
self.print_outer_attributes(self.attrs(expr.hir_id));
|
||||||
self.ibox(INDENT_UNIT);
|
self.ibox(INDENT_UNIT);
|
||||||
self.ann.pre(self, AnnNode::Expr(expr));
|
self.ann.pre(self, AnnNode::Expr(expr));
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
|
|
|
@ -66,11 +66,10 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
|
||||||
|
|
||||||
fn hash_hir_expr(&mut self, expr: &hir::Expr<'_>, hasher: &mut StableHasher) {
|
fn hash_hir_expr(&mut self, expr: &hir::Expr<'_>, hasher: &mut StableHasher) {
|
||||||
self.while_hashing_hir_bodies(true, |hcx| {
|
self.while_hashing_hir_bodies(true, |hcx| {
|
||||||
let hir::Expr { hir_id: _, ref span, ref kind, ref attrs } = *expr;
|
let hir::Expr { hir_id: _, ref span, ref kind } = *expr;
|
||||||
|
|
||||||
span.hash_stable(hcx, hasher);
|
span.hash_stable(hcx, hasher);
|
||||||
kind.hash_stable(hcx, hasher);
|
kind.hash_stable(hcx, hasher);
|
||||||
attrs.hash_stable(hcx, hasher);
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,8 @@ fn check_final_expr<'tcx>(
|
||||||
// simple return is always "bad"
|
// simple return is always "bad"
|
||||||
ExprKind::Ret(ref inner) => {
|
ExprKind::Ret(ref inner) => {
|
||||||
// allow `#[cfg(a)] return a; #[cfg(b)] return b;`
|
// allow `#[cfg(a)] return a; #[cfg(b)] return b;`
|
||||||
if !expr.attrs.iter().any(attr_is_cfg) {
|
let attrs = cx.tcx.hir().attrs(expr.hir_id);
|
||||||
|
if !attrs.iter().any(attr_is_cfg) {
|
||||||
let borrows = inner.map_or(false, |inner| last_statement_borrows(cx, inner));
|
let borrows = inner.map_or(false, |inner| last_statement_borrows(cx, inner));
|
||||||
if !borrows {
|
if !borrows {
|
||||||
emit_return_lint(
|
emit_return_lint(
|
||||||
|
|
|
@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
|
||||||
//
|
//
|
||||||
|
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||||
if !has_attr(cx.sess(), &expr.attrs) {
|
if !has_attr(cx.sess(), cx.tcx.hir().attrs(expr.hir_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
print_expr(cx, expr, 0);
|
print_expr(cx, expr, 0);
|
||||||
|
|
Loading…
Reference in New Issue