diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2020-11-26 23:46:48 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-03-09 19:23:05 +0100 |
| commit | 96788df68c3a781ddcc7c3cc2e81371283570327 (patch) | |
| tree | 21cd6506f8164bddf1d0d99f421f34a6d2646150 /compiler/rustc_hir_pretty/src | |
| parent | a987bbb97c12235b4abb9d4fa742ab1f40401df5 (diff) | |
| download | rust-96788df68c3a781ddcc7c3cc2e81371283570327.tar.gz rust-96788df68c3a781ddcc7c3cc2e81371283570327.zip | |
Remove hir::Arm::attrs.
Diffstat (limited to 'compiler/rustc_hir_pretty/src')
| -rw-r--r-- | compiler/rustc_hir_pretty/src/lib.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 0eb1dc742ba..837aae909c1 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -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 { |
