diff options
| author | bors <bors@rust-lang.org> | 2021-05-03 10:56:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-05-03 10:56:15 +0000 |
| commit | c825bc431ee5b815847b9bab693c59c43986fc4b (patch) | |
| tree | cf73ba71c11ff4aafcc88db6efb49209cf564cbf /compiler/rustc_parse/src/parser/expr.rs | |
| parent | e327a823d8b64e294e490efeca7829f383aa119d (diff) | |
| parent | 1443c7646d37eb69c434268ec8b27cd0cf82d9f2 (diff) | |
| download | rust-c825bc431ee5b815847b9bab693c59c43986fc4b.tar.gz rust-c825bc431ee5b815847b9bab693c59c43986fc4b.zip | |
Auto merge of #83312 - petrochenkov:noinner, r=Aaron1011
parser: Remove support for inner attributes on non-block expressions
Remove support for attributes like
```rust
fn attrs() {
(#![print_target_and_args(fifth)] 1, 2);
[#![print_target_and_args(sixth)] 1 , 2];
[#![print_target_and_args(seventh)] true ; 5];
match 0 {
#![print_target_and_args(eighth)]
_ => {}
}
MyStruct { #![print_target_and_args(ninth)] field: true };
}
```
They are
- useless
- unstable (modulo holes like https://github.com/rust-lang/rust/issues/65860)
- pessimize compiler performance, namely token collection for macros (cc https://github.com/rust-lang/rust/pull/82608)
I still want to run crater on this to check whether the stability holes are exploited in practice, and whether such attributes are used at all.
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index e155b3fa773..56c97b59476 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1216,10 +1216,9 @@ impl<'a> Parser<'a> { } } - fn parse_tuple_parens_expr(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> { + fn parse_tuple_parens_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> { let lo = self.token.span; self.expect(&token::OpenDelim(token::Paren))?; - attrs.extend(self.parse_inner_attributes()?); // `(#![foo] a, b, ...)` is OK. let (es, trailing_comma) = match self.parse_seq_to_end( &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), @@ -1239,12 +1238,10 @@ impl<'a> Parser<'a> { self.maybe_recover_from_bad_qpath(expr, true) } - fn parse_array_or_repeat_expr(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> { + fn parse_array_or_repeat_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> { let lo = self.token.span; self.bump(); // `[` - attrs.extend(self.parse_inner_attributes()?); - let close = &token::CloseDelim(token::Bracket); let kind = if self.eat(close) { // Empty vector @@ -1950,7 +1947,7 @@ impl<'a> Parser<'a> { } /// Parses a `match ... { ... }` expression (`match` token already eaten). - fn parse_match_expr(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> { + fn parse_match_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> { let match_span = self.prev_token.span; let lo = self.prev_token.span; let scrutinee = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?; @@ -1965,7 +1962,6 @@ impl<'a> Parser<'a> { } return Err(e); } - attrs.extend(self.parse_inner_attributes()?); let mut arms: Vec<Arm> = Vec::new(); while self.token != token::CloseDelim(token::Brace) { @@ -2293,15 +2289,13 @@ impl<'a> Parser<'a> { pub(super) fn parse_struct_expr( &mut self, pth: ast::Path, - mut attrs: AttrVec, + attrs: AttrVec, recover: bool, ) -> PResult<'a, P<Expr>> { let mut fields = Vec::new(); let mut base = ast::StructRest::None; let mut recover_async = false; - attrs.extend(self.parse_inner_attributes()?); - let mut async_block_err = |e: &mut DiagnosticBuilder<'_>, span: Span| { recover_async = true; e.span_label(span, "`async` blocks are only allowed in Rust 2018 or later"); |
