rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.05k stars 1.56k forks source link

MBE template parsing fails with `///` #7423

Open lnicola opened 3 years ago

lnicola commented 3 years ago
macro_rules! features {
        {
            $(
                $name:ident {
                    ///
                }
            ),+
            ,
        } => {};
        {} => {}
}

features! {
    NEON { },
}

fn main() {}

Adapted from ring.

edwin0cheng commented 3 years ago

This part in rustc is quite ambitious :

This one works:

macro_rules! m{
    {{
       #[doc=r"abcde"]
    }
    } => { }
}
m!({/**abcde*/});
fn main() {}

This one doesn't works:

macro_rules! m{
    {{
       /**abcde*/
    }
    } => { }
}

m!({/**abcde*/});
fn main() {}

This one works:

macro_rules! m{
    {{
       /***/
    }
    } => { }
}

m!({/***/});
fn main() {}

This one doesn't work:

macro_rules! m{
    {{
       ///
    }
    } => { }
}

m!({
    ///
});

fn main() {}

(ノಠ益ಠ)ノ彡┻━┻

lnicola commented 3 years ago

Might be worth asking in #t-compiler.

lnicola commented 3 years ago

I didn't realize that features! {} actually works with my updated example.

And we also seem to expose the #[doc] desugaring:

image

edwin0cheng commented 3 years ago

I didn't realize that features! {} actually works with my updated example.

The second branch couldn't be matched because of the "NEON" and the comma.

And we also seem to expose the #[doc] desugaring:

Yes, we desugar all doc comment in mbe included empty one, and that's why we failed because we expect a doc comment in macro invocation.

bjorn3 commented 3 years ago
This one doesn't work: ``` macro_rules! m{ {{ /// } } => { } } m!({ /// }); fn main() {} ```

I did guess that rustc doesn't desugar /// into #[doc = "..."] inside the macro rules matcher.