Skip to content

Commit 75d6293

Browse files
committed
Re-add support for parsing (and pretty-printing) inner-attributes within body of a match.
In other words, we can do `match EXPR { #![inner_attr] ARM_1 ARM_2 ... }` again. I believe this unbreaks the only four crates that crater flagged as broken by PR 83312. (I am putting this up so that the lang-team can check it out and decide whether it changes their mind about what to do regarding PR 83312.)
1 parent 2bafe96 commit 75d6293

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+5
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
366366
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
367367
}
368368

369+
fn print_inner_attributes_no_trailing_hardbreak(&mut self, attrs: &[ast::Attribute]) {
370+
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, false)
371+
}
372+
369373
fn print_outer_attributes(&mut self, attrs: &[ast::Attribute]) {
370374
self.print_either_attributes(attrs, ast::AttrStyle::Outer, false, true)
371375
}
@@ -1940,6 +1944,7 @@ impl<'a> State<'a> {
19401944
self.print_expr_as_cond(expr);
19411945
self.s.space();
19421946
self.bopen();
1947+
self.print_inner_attributes_no_trailing_hardbreak(attrs);
19431948
for arm in arms {
19441949
self.print_arm(arm);
19451950
}

compiler/rustc_parse/src/parser/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,7 @@ impl<'a> Parser<'a> {
19471947
}
19481948

19491949
/// Parses a `match ... { ... }` expression (`match` token already eaten).
1950-
fn parse_match_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
1950+
fn parse_match_expr(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
19511951
let match_span = self.prev_token.span;
19521952
let lo = self.prev_token.span;
19531953
let scrutinee = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
@@ -1962,6 +1962,7 @@ impl<'a> Parser<'a> {
19621962
}
19631963
return Err(e);
19641964
}
1965+
attrs.extend(self.parse_inner_attributes()?);
19651966

19661967
let mut arms: Vec<Arm> = Vec::new();
19671968
while self.token != token::CloseDelim(token::Brace) {

0 commit comments

Comments
 (0)