Enable parsing of attributes inside a match block

We allow invalid inner attributes to be parsed, e.g. inner attributes that are
not directly after the opening brace of the match block.

Instead we run validation on `MatchArmList` to allow better reporting of errors.
This commit is contained in:
Ville Penttinen 2019-02-17 19:08:34 +02:00
parent 982f72c022
commit 1c97c1ac11
16 changed files with 589 additions and 1 deletions

View file

@ -313,11 +313,44 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
assert!(p.at(L_CURLY));
let m = p.start();
p.eat(L_CURLY);
// test match_arms_inner_attribute
// fn foo() {
// match () {
// #![doc("Inner attribute")]
// #![doc("Can be")]
// #![doc("Stacked")]
// _ => (),
// }
// }
attributes::inner_attributes(p);
while !p.at(EOF) && !p.at(R_CURLY) {
if p.at(L_CURLY) {
error_block(p, "expected match arm");
continue;
}
// This may result in invalid attributes
// if there are inner attributes mixed in together
// with the outer attributes, but we allow parsing
// those so we can run validation and report better errors
// test match_arms_outer_attributes
// fn foo() {
// match () {
// #[cfg(feature = "some")]
// _ => (),
// #[cfg(feature = "other")]
// _ => (),
// #[cfg(feature = "many")]
// #[cfg(feature = "attributes")]
// #[cfg(feature = "before")]
// _ => (),
// }
// }
attributes::all_attributes(p);
// test match_arms_commas
// fn foo() {
// match () {