-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Description
Summary
Although creating a doc attribute directly from a stringify! (or concat!) does not work, i.e.,
#[doc = stringify!(Fails)]
pub enum Fails {}fails with
error: unexpected token: `stringify`
it is possible to use a macro in some situations. For example, this code compiles correctly
macro_rules! working {
($doc:expr, $id:ident) => {
#[doc = $doc]
pub enum $id {}
}
}
working!(stringify!(Working), Working);
fn main() { }and rustdoc creates the correct documentation.
Code demonstrating the issue
macro_rules! bug_helper {
(#[$attr:meta] $id:ident) => {
#[$attr]
pub enum $id {}
}
}
macro_rules! bug {
($doc:expr, $id:ident) => {
bug_helper! { #[doc = $doc] $id }
}
}
bug!(stringify!(Bug), Bug);
fn main() { }The error message is similar to the one at the top of this report.
error: unexpected token: `stringify!(Bug)`
If the stringify!(Bug) is replaced with "Bug", the code compiles correctly.
All of the above holds true if you replace stringify! with concat!.
Expectation
I'd expect the second and third code samples above to either both produce an error message or neither. (Preferably, neither.)
Versions
Both stable (rustc 1.27.2 (58cc626 2018-07-18)) and nightly (rustc 1.29.0-nightly (874dec2 2018-07-21)) have the same behavior.
gabbyzhat, LukasKalbertodt, Lokathor, JameeKim, adamcrume and 14 more
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)