Skip to content

Commit 3f94559

Browse files
pnkfelixcuviper
authored andcommitted
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.) (cherry picked from commit 75d6293)
1 parent 075fd93 commit 3f94559

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
369369
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
370370
}
371371

372+
fn print_inner_attributes_no_trailing_hardbreak(&mut self, attrs: &[ast::Attribute]) {
373+
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, false)
374+
}
375+
372376
fn print_outer_attributes(&mut self, attrs: &[ast::Attribute]) {
373377
self.print_either_attributes(attrs, ast::AttrStyle::Outer, false, true)
374378
}
@@ -1960,6 +1964,7 @@ impl<'a> State<'a> {
19601964
self.print_expr_as_cond(expr);
19611965
self.s.space();
19621966
self.bopen();
1967+
self.print_inner_attributes_no_trailing_hardbreak(attrs);
19631968
for arm in arms {
19641969
self.print_arm(arm);
19651970
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ impl<'a> Parser<'a> {
19451945
}
19461946

19471947
/// Parses a `match ... { ... }` expression (`match` token already eaten).
1948-
fn parse_match_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
1948+
fn parse_match_expr(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
19491949
let match_span = self.prev_token.span;
19501950
let lo = self.prev_token.span;
19511951
let scrutinee = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
@@ -1960,6 +1960,7 @@ impl<'a> Parser<'a> {
19601960
}
19611961
return Err(e);
19621962
}
1963+
attrs.extend(self.parse_inner_attributes()?);
19631964

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

0 commit comments

Comments
 (0)