diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2020-11-27 17:41:05 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-03-09 19:27:58 +0100 |
| commit | fb753cced827a6e54defc1895e18e5dfbd95fbb5 (patch) | |
| tree | 420b0861e00a323f72eca3e09d0f8903f948be55 /compiler/rustc_ast_lowering/src | |
| parent | c701872a6cd9c3c5b0ef766dc237ff93bc3cc8d9 (diff) | |
| download | rust-fb753cced827a6e54defc1895e18e5dfbd95fbb5.tar.gz rust-fb753cced827a6e54defc1895e18e5dfbd95fbb5.zip | |
Remove hir::Expr::attrs.
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 36 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 4 |
2 files changed, 16 insertions, 24 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 8e3ed595b38..18ac884c7cb 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -258,10 +258,12 @@ impl<'hir> LoweringContext<'_, 'hir> { ex.span = e.span; } // Merge attributes into the inner expression. - let mut attrs: Vec<_> = e.attrs.iter().map(|a| self.lower_attr(a)).collect(); - attrs.extend::<Vec<_>>(ex.attrs.into()); - self.attrs[ex.hir_id] = &*self.arena.alloc_from_iter(attrs.iter().cloned()); - ex.attrs = attrs.into(); + self.attrs[ex.hir_id] = &*self.arena.alloc_from_iter( + e.attrs + .iter() + .map(|a| self.lower_attr(a)) + .chain(self.attrs[ex.hir_id].iter().cloned()), + ); return ex; } @@ -274,9 +276,8 @@ impl<'hir> LoweringContext<'_, 'hir> { }; let hir_id = self.lower_node_id(e.id); - let attrs = e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>(); - self.attrs.push_sparse(hir_id, &*self.arena.alloc_from_iter(attrs.iter().cloned())); - hir::Expr { hir_id, kind, span: e.span, attrs: attrs.into() } + self.lower_attrs(hir_id, &e.attrs); + hir::Expr { hir_id, kind, span: e.span } }) } @@ -684,12 +685,8 @@ impl<'hir> LoweringContext<'_, 'hir> { span, Some(hir::Movability::Static), ); - let generator = hir::Expr { - hir_id: self.lower_node_id(closure_node_id), - kind: generator_kind, - span, - attrs: ThinVec::new(), - }; + let generator = + hir::Expr { hir_id: self.lower_node_id(closure_node_id), kind: generator_kind, span }; // `future::from_generator`: let unstable_span = @@ -843,7 +840,6 @@ impl<'hir> LoweringContext<'_, 'hir> { hir_id: loop_hir_id, kind: hir::ExprKind::Loop(loop_block, None, hir::LoopSource::Loop, span), span, - attrs: ThinVec::new(), }); // mut pinned => loop { ... } @@ -1813,12 +1809,8 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::LoopSource::ForLoop, e.span.with_hi(orig_head_span.hi()), ); - let loop_expr = self.arena.alloc(hir::Expr { - hir_id: self.lower_node_id(e.id), - kind, - span: e.span, - attrs: ThinVec::new(), - }); + let loop_expr = + self.arena.alloc(hir::Expr { hir_id: self.lower_node_id(e.id), kind, span: e.span }); // `mut iter => { ... }` let iter_arm = self.arm(iter_pat, loop_expr); @@ -2154,8 +2146,8 @@ impl<'hir> LoweringContext<'_, 'hir> { attrs: AttrVec, ) -> hir::Expr<'hir> { let hir_id = self.next_id(); - self.attrs.push_sparse(hir_id, &*self.arena.alloc_from_iter(attrs.iter().cloned())); - hir::Expr { hir_id, kind, span, attrs } + self.lower_attrs(hir_id, &attrs); + hir::Expr { hir_id, kind, span } } fn field(&mut self, ident: Ident, expr: &'hir hir::Expr<'hir>, span: Span) -> hir::Field<'hir> { diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 209e845f70f..10ee3f156ed 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -979,7 +979,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { 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 // 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. @@ -999,7 +999,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { 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 { MacArgs::Empty => MacArgs::Empty, MacArgs::Delimited(dspan, delim, ref tokens) => { |
