Skip to content

Commit fb753cc

Browse files
committed
Remove hir::Expr::attrs.
1 parent c701872 commit fb753cc

File tree

7 files changed

+23
-32
lines changed

7 files changed

+23
-32
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
258258
ex.span = e.span;
259259
}
260260
// Merge attributes into the inner expression.
261-
let mut attrs: Vec<_> = e.attrs.iter().map(|a| self.lower_attr(a)).collect();
262-
attrs.extend::<Vec<_>>(ex.attrs.into());
263-
self.attrs[ex.hir_id] = &*self.arena.alloc_from_iter(attrs.iter().cloned());
264-
ex.attrs = attrs.into();
261+
self.attrs[ex.hir_id] = &*self.arena.alloc_from_iter(
262+
e.attrs
263+
.iter()
264+
.map(|a| self.lower_attr(a))
265+
.chain(self.attrs[ex.hir_id].iter().cloned()),
266+
);
265267
return ex;
266268
}
267269

@@ -274,9 +276,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
274276
};
275277

276278
let hir_id = self.lower_node_id(e.id);
277-
let attrs = e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>();
278-
self.attrs.push_sparse(hir_id, &*self.arena.alloc_from_iter(attrs.iter().cloned()));
279-
hir::Expr { hir_id, kind, span: e.span, attrs: attrs.into() }
279+
self.lower_attrs(hir_id, &e.attrs);
280+
hir::Expr { hir_id, kind, span: e.span }
280281
})
281282
}
282283

@@ -684,12 +685,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
684685
span,
685686
Some(hir::Movability::Static),
686687
);
687-
let generator = hir::Expr {
688-
hir_id: self.lower_node_id(closure_node_id),
689-
kind: generator_kind,
690-
span,
691-
attrs: ThinVec::new(),
692-
};
688+
let generator =
689+
hir::Expr { hir_id: self.lower_node_id(closure_node_id), kind: generator_kind, span };
693690

694691
// `future::from_generator`:
695692
let unstable_span =
@@ -843,7 +840,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
843840
hir_id: loop_hir_id,
844841
kind: hir::ExprKind::Loop(loop_block, None, hir::LoopSource::Loop, span),
845842
span,
846-
attrs: ThinVec::new(),
847843
});
848844

849845
// mut pinned => loop { ... }
@@ -1813,12 +1809,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
18131809
hir::LoopSource::ForLoop,
18141810
e.span.with_hi(orig_head_span.hi()),
18151811
);
1816-
let loop_expr = self.arena.alloc(hir::Expr {
1817-
hir_id: self.lower_node_id(e.id),
1818-
kind,
1819-
span: e.span,
1820-
attrs: ThinVec::new(),
1821-
});
1812+
let loop_expr =
1813+
self.arena.alloc(hir::Expr { hir_id: self.lower_node_id(e.id), kind, span: e.span });
18221814

18231815
// `mut iter => { ... }`
18241816
let iter_arm = self.arm(iter_pat, loop_expr);
@@ -2154,8 +2146,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
21542146
attrs: AttrVec,
21552147
) -> hir::Expr<'hir> {
21562148
let hir_id = self.next_id();
2157-
self.attrs.push_sparse(hir_id, &*self.arena.alloc_from_iter(attrs.iter().cloned()));
2158-
hir::Expr { hir_id, kind, span, attrs }
2149+
self.lower_attrs(hir_id, &attrs);
2150+
hir::Expr { hir_id, kind, span }
21592151
}
21602152

21612153
fn field(&mut self, ident: Ident, expr: &'hir hir::Expr<'hir>, span: Span) -> hir::Field<'hir> {

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
979979
ret
980980
}
981981

982-
fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
982+
fn lower_attr(&self, attr: &Attribute) -> Attribute {
983983
// Note that we explicitly do not walk the path. Since we don't really
984984
// lower attributes (we use the AST version) there is nowhere to keep
985985
// the `HirId`s. We don't actually need HIR version of attributes anyway.
@@ -999,7 +999,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
999999
Attribute { kind, id: attr.id, style: attr.style, span: attr.span }
10001000
}
10011001

1002-
fn lower_mac_args(&mut self, args: &MacArgs) -> MacArgs {
1002+
fn lower_mac_args(&self, args: &MacArgs) -> MacArgs {
10031003
match *args {
10041004
MacArgs::Empty => MacArgs::Empty,
10051005
MacArgs::Delimited(dspan, delim, ref tokens) => {

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{itemlikevisit, HirIdVec, LangItem};
66

77
use rustc_ast::util::parser::ExprPrecedence;
88
use rustc_ast::{self as ast, CrateSugar, LlvmAsmDialect};
9-
use rustc_ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
9+
use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
1010
pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
1111
pub use rustc_ast::{CaptureBy, Movability, Mutability};
1212
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
@@ -1446,7 +1446,6 @@ pub struct AnonConst {
14461446
pub struct Expr<'hir> {
14471447
pub hir_id: HirId,
14481448
pub kind: ExprKind<'hir>,
1449-
pub attrs: AttrVec,
14501449
pub span: Span,
14511450
}
14521451

@@ -3071,7 +3070,7 @@ impl<'hir> Node<'hir> {
30713070
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
30723071
mod size_asserts {
30733072
rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
3074-
rustc_data_structures::static_assert_size!(super::Expr<'static>, 72);
3073+
rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
30753074
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
30763075
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
30773076
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ impl<'a> State<'a> {
13341334

13351335
pub fn print_expr(&mut self, expr: &hir::Expr<'_>) {
13361336
self.maybe_print_comment(expr.span.lo());
1337-
self.print_outer_attributes(&expr.attrs);
1337+
self.print_outer_attributes(self.attrs(expr.hir_id));
13381338
self.ibox(INDENT_UNIT);
13391339
self.ann.pre(self, AnnNode::Expr(expr));
13401340
match expr.kind {

compiler/rustc_middle/src/ich/impls_hir.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
6666

6767
fn hash_hir_expr(&mut self, expr: &hir::Expr<'_>, hasher: &mut StableHasher) {
6868
self.while_hashing_hir_bodies(true, |hcx| {
69-
let hir::Expr { hir_id: _, ref span, ref kind, ref attrs } = *expr;
69+
let hir::Expr { hir_id: _, ref span, ref kind } = *expr;
7070

7171
span.hash_stable(hcx, hasher);
7272
kind.hash_stable(hcx, hasher);
73-
attrs.hash_stable(hcx, hasher);
7473
})
7574
}
7675

src/tools/clippy/clippy_lints/src/returns.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ fn check_final_expr<'tcx>(
177177
// simple return is always "bad"
178178
ExprKind::Ret(ref inner) => {
179179
// allow `#[cfg(a)] return a; #[cfg(b)] return b;`
180-
if !expr.attrs.iter().any(attr_is_cfg) {
180+
let attrs = cx.tcx.hir().attrs(expr.hir_id);
181+
if !attrs.iter().any(attr_is_cfg) {
181182
let borrows = inner.map_or(false, |inner| last_statement_borrows(cx, inner));
182183
if !borrows {
183184
emit_return_lint(

src/tools/clippy/clippy_lints/src/utils/inspector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
8989
//
9090

9191
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
92-
if !has_attr(cx.sess(), &expr.attrs) {
92+
if !has_attr(cx.sess(), cx.tcx.hir().attrs(expr.hir_id)) {
9393
return;
9494
}
9595
print_expr(cx, expr, 0);

0 commit comments

Comments
 (0)