Skip to content

Commit 96788df

Browse files
committed
Remove hir::Arm::attrs.
1 parent a987bbb commit 96788df

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
618618
}
619619
});
620620
let hir_id = self.next_id();
621-
hir::Arm {
622-
hir_id,
623-
attrs: self.lower_attrs(hir_id, &arm.attrs),
624-
pat,
625-
guard,
626-
body: self.lower_expr(&arm.body),
627-
span: arm.span,
628-
}
621+
self.lower_attrs(hir_id, &arm.attrs);
622+
hir::Arm { hir_id, pat, guard, body: self.lower_expr(&arm.body), span: arm.span }
629623
}
630624

631625
/// Lower an `async` construct to a generator that is then wrapped so it implements `Future`.
@@ -2169,13 +2163,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
21692163
}
21702164

21712165
fn arm(&mut self, pat: &'hir hir::Pat<'hir>, expr: &'hir hir::Expr<'hir>) -> hir::Arm<'hir> {
2172-
hir::Arm {
2173-
hir_id: self.next_id(),
2174-
attrs: &[],
2175-
pat,
2176-
guard: None,
2177-
span: expr.span,
2178-
body: expr,
2179-
}
2166+
hir::Arm { hir_id: self.next_id(), pat, guard: None, span: expr.span, body: expr }
21802167
}
21812168
}

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,6 @@ pub struct Arm<'hir> {
11881188
#[stable_hasher(ignore)]
11891189
pub hir_id: HirId,
11901190
pub span: Span,
1191-
pub attrs: &'hir [Attribute],
11921191
/// If this pattern and the optional guard matches, then `body` is evaluated.
11931192
pub pat: &'hir Pat<'hir>,
11941193
/// Optional guard clause.

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> {
8282
pub struct State<'a> {
8383
pub s: pp::Printer,
8484
comments: Option<Comments<'a>>,
85+
attrs: &'a hir::HirIdVec<&'a [ast::Attribute]>,
8586
ann: &'a (dyn PpAnn + 'a),
8687
}
8788

@@ -163,7 +164,7 @@ pub fn print_crate<'a>(
163164
input: String,
164165
ann: &'a dyn PpAnn,
165166
) -> String {
166-
let mut s = State::new_from_input(sm, filename, input, ann);
167+
let mut s = State::new_from_input(sm, filename, input, &krate.attrs, ann);
167168

168169
// When printing the AST, we sometimes need to inject `#[no_std]` here.
169170
// Since you can't compile the HIR, it's not necessary.
@@ -178,17 +179,28 @@ impl<'a> State<'a> {
178179
sm: &'a SourceMap,
179180
filename: FileName,
180181
input: String,
182+
attrs: &'a hir::HirIdVec<&[ast::Attribute]>,
181183
ann: &'a dyn PpAnn,
182184
) -> State<'a> {
183-
State { s: pp::mk_printer(), comments: Some(Comments::new(sm, filename, input)), ann }
185+
State {
186+
s: pp::mk_printer(),
187+
comments: Some(Comments::new(sm, filename, input)),
188+
attrs,
189+
ann,
190+
}
191+
}
192+
193+
fn attrs(&self, id: hir::HirId) -> &'a [ast::Attribute] {
194+
self.attrs.get(id).map_or(&[], |la| *la)
184195
}
185196
}
186197

187198
pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
188199
where
189200
F: FnOnce(&mut State<'_>),
190201
{
191-
let mut printer = State { s: pp::mk_printer(), comments: None, ann };
202+
let mut printer =
203+
State { s: pp::mk_printer(), comments: None, attrs: &hir::HirIdVec::default(), ann };
192204
f(&mut printer);
193205
printer.s.eof()
194206
}
@@ -2027,13 +2039,13 @@ impl<'a> State<'a> {
20272039
pub fn print_arm(&mut self, arm: &hir::Arm<'_>) {
20282040
// I have no idea why this check is necessary, but here it
20292041
// is :(
2030-
if arm.attrs.is_empty() {
2042+
if self.attrs(arm.hir_id).is_empty() {
20312043
self.s.space();
20322044
}
20332045
self.cbox(INDENT_UNIT);
20342046
self.ann.pre(self, AnnNode::Arm(arm));
20352047
self.ibox(0);
2036-
self.print_outer_attributes(&arm.attrs);
2048+
self.print_outer_attributes(&self.attrs(arm.hir_id));
20372049
self.print_pat(&arm.pat);
20382050
self.s.space();
20392051
if let Some(ref g) = arm.guard {

src/tools/clippy/clippy_lints/src/matches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,11 +1207,11 @@ fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr
12071207
if b0 != b1;
12081208
let if_guard = &b0_arms[0].guard;
12091209
if if_guard.is_none() || b0_arms.len() == 1;
1210-
if b0_arms[0].attrs.is_empty();
1210+
if cx.tcx.hir().attrs(b0_arms[0].hir_id).is_empty();
12111211
if b0_arms[1..].iter()
12121212
.all(|arm| {
12131213
find_bool_lit(&arm.body.kind, desugared).map_or(false, |b| b == b0) &&
1214-
arm.guard.is_none() && arm.attrs.is_empty()
1214+
arm.guard.is_none() && cx.tcx.hir().attrs(arm.hir_id).is_empty()
12151215
});
12161216
then {
12171217
// The suggestion may be incorrect, because some arms can have `cfg` attributes

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
9696
}
9797

9898
fn check_arm(&mut self, cx: &LateContext<'tcx>, arm: &'tcx hir::Arm<'_>) {
99-
if !has_attr(cx.sess(), &arm.attrs) {
99+
if !has_attr(cx.sess(), cx.tcx.hir().attrs(arm.hir_id)) {
100100
return;
101101
}
102102
print_pat(cx, &arm.pat, 1);

0 commit comments

Comments
 (0)