:vis matcher can't parse EOF

a196854
Opened by Masaki Hara at 2023-09-14 17:19:43

Observed behavior

The code below leads to parse error in rustc 1.19.0-nightly (e40beb3af 2017-05-11).

#![feature(macro_vis_matcher)]
macro_rules! foo {
    ($v:vis) => {}
}
fn main() {
    foo!(); //~ ERROR unexpected end of macro invocation
    foo!(pub(in self));
}

Expected behavior

foo!() is expanded correctly.

  1. Triage: Interesting. :vis (stable since Rust 1.30) is optional, but not by itself. Not sure if the current behavior is a bug or a feature.

    Playground:

    macro_rules! optional_vis {
        ($v:vis const) => {}
    }
    
    macro_rules! not_optional_vis {
        ($v:vis) => {}
    }
    
    fn main() {
        optional_vis!(pub const);
        optional_vis!(const); // OK!
    
        not_optional_vis!(pub);
        not_optional_vis!(); //~ ERROR unexpected end of macro invocation
    
    }
    

    Martin Nordholts at 2023-09-14 17:19:34