diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-08-15 09:58:38 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-08-15 13:29:28 +1000 |
| commit | 2ef04795681837153df7613192305a2ddbf13497 (patch) | |
| tree | 63ba7232dcbada3c9e175f7083118f3cba0e1748 /compiler/rustc_parse/src/parser/mod.rs | |
| parent | 1e8497351d7cb15eddd9db2f88866294bab27a21 (diff) | |
| download | rust-2ef04795681837153df7613192305a2ddbf13497.tar.gz rust-2ef04795681837153df7613192305a2ddbf13497.zip | |
Simplify attribute handling in `parse_bottom_expr`.
`Parser::parse_bottom_expr` currently constructs an empty `attrs` and then passes it to a large number of other functions. This makes the code harder to read than it should be, because it's not clear that many `attrs` arguments are always empty. This commit removes `attrs` and the passing, simplifying a lot of functions. The commit also renames `Parser::mk_expr` (which takes an `attrs` argument) as `mk_expr_with_attrs`, and introduces a new `mk_expr` which creates an expression with no attributes, which is the more common case.
Diffstat (limited to 'compiler/rustc_parse/src/parser/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index c088b6e1e0e..d61da7b6cc0 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1116,10 +1116,14 @@ impl<'a> Parser<'a> { let (attrs, blk) = self.parse_inner_attrs_and_block()?; let anon_const = AnonConst { id: DUMMY_NODE_ID, - value: self.mk_expr(blk.span, ExprKind::Block(blk, None), AttrVec::new()), + value: self.mk_expr(blk.span, ExprKind::Block(blk, None)), }; let blk_span = anon_const.value.span; - Ok(self.mk_expr(span.to(blk_span), ExprKind::ConstBlock(anon_const), AttrVec::from(attrs))) + Ok(self.mk_expr_with_attrs( + span.to(blk_span), + ExprKind::ConstBlock(anon_const), + AttrVec::from(attrs), + )) } /// Parses mutability (`mut` or nothing). |
