Remove hir::Arm::attrs.

This commit is contained in:
Camille GILLOT 2020-11-26 23:46:48 +01:00
parent a987bbb97c
commit 96788df68c
5 changed files with 23 additions and 25 deletions

View File

@ -618,14 +618,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
});
let hir_id = self.next_id();
hir::Arm {
hir_id,
attrs: self.lower_attrs(hir_id, &arm.attrs),
pat,
guard,
body: self.lower_expr(&arm.body),
span: arm.span,
}
self.lower_attrs(hir_id, &arm.attrs);
hir::Arm { hir_id, pat, guard, body: self.lower_expr(&arm.body), span: arm.span }
}
/// Lower an `async` construct to a generator that is then wrapped so it implements `Future`.
@ -2169,13 +2163,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
fn arm(&mut self, pat: &'hir hir::Pat<'hir>, expr: &'hir hir::Expr<'hir>) -> hir::Arm<'hir> {
hir::Arm {
hir_id: self.next_id(),
attrs: &[],
pat,
guard: None,
span: expr.span,
body: expr,
}
hir::Arm { hir_id: self.next_id(), pat, guard: None, span: expr.span, body: expr }
}
}

View File

@ -1188,7 +1188,6 @@ pub struct Arm<'hir> {
#[stable_hasher(ignore)]
pub hir_id: HirId,
pub span: Span,
pub attrs: &'hir [Attribute],
/// If this pattern and the optional guard matches, then `body` is evaluated.
pub pat: &'hir Pat<'hir>,
/// Optional guard clause.

View File

@ -82,6 +82,7 @@ impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> {
pub struct State<'a> {
pub s: pp::Printer,
comments: Option<Comments<'a>>,
attrs: &'a hir::HirIdVec<&'a [ast::Attribute]>,
ann: &'a (dyn PpAnn + 'a),
}
@ -163,7 +164,7 @@ pub fn print_crate<'a>(
input: String,
ann: &'a dyn PpAnn,
) -> String {
let mut s = State::new_from_input(sm, filename, input, ann);
let mut s = State::new_from_input(sm, filename, input, &krate.attrs, ann);
// When printing the AST, we sometimes need to inject `#[no_std]` here.
// Since you can't compile the HIR, it's not necessary.
@ -178,9 +179,19 @@ impl<'a> State<'a> {
sm: &'a SourceMap,
filename: FileName,
input: String,
attrs: &'a hir::HirIdVec<&[ast::Attribute]>,
ann: &'a dyn PpAnn,
) -> State<'a> {
State { s: pp::mk_printer(), comments: Some(Comments::new(sm, filename, input)), ann }
State {
s: pp::mk_printer(),
comments: Some(Comments::new(sm, filename, input)),
attrs,
ann,
}
}
fn attrs(&self, id: hir::HirId) -> &'a [ast::Attribute] {
self.attrs.get(id).map_or(&[], |la| *la)
}
}
@ -188,7 +199,8 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
where
F: FnOnce(&mut State<'_>),
{
let mut printer = State { s: pp::mk_printer(), comments: None, ann };
let mut printer =
State { s: pp::mk_printer(), comments: None, attrs: &hir::HirIdVec::default(), ann };
f(&mut printer);
printer.s.eof()
}
@ -2027,13 +2039,13 @@ impl<'a> State<'a> {
pub fn print_arm(&mut self, arm: &hir::Arm<'_>) {
// I have no idea why this check is necessary, but here it
// is :(
if arm.attrs.is_empty() {
if self.attrs(arm.hir_id).is_empty() {
self.s.space();
}
self.cbox(INDENT_UNIT);
self.ann.pre(self, AnnNode::Arm(arm));
self.ibox(0);
self.print_outer_attributes(&arm.attrs);
self.print_outer_attributes(&self.attrs(arm.hir_id));
self.print_pat(&arm.pat);
self.s.space();
if let Some(ref g) = arm.guard {

View File

@ -1207,11 +1207,11 @@ fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr
if b0 != b1;
let if_guard = &b0_arms[0].guard;
if if_guard.is_none() || b0_arms.len() == 1;
if b0_arms[0].attrs.is_empty();
if cx.tcx.hir().attrs(b0_arms[0].hir_id).is_empty();
if b0_arms[1..].iter()
.all(|arm| {
find_bool_lit(&arm.body.kind, desugared).map_or(false, |b| b == b0) &&
arm.guard.is_none() && arm.attrs.is_empty()
arm.guard.is_none() && cx.tcx.hir().attrs(arm.hir_id).is_empty()
});
then {
// The suggestion may be incorrect, because some arms can have `cfg` attributes

View File

@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
}
fn check_arm(&mut self, cx: &LateContext<'tcx>, arm: &'tcx hir::Arm<'_>) {
if !has_attr(cx.sess(), &arm.attrs) {
if !has_attr(cx.sess(), cx.tcx.hir().attrs(arm.hir_id)) {
return;
}
print_pat(cx, &arm.pat, 1);