Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are doc comments parsed as raw string? #771

Closed
magurotuna opened this issue Feb 24, 2020 · 3 comments
Closed

Why are doc comments parsed as raw string? #771

magurotuna opened this issue Feb 24, 2020 · 3 comments

Comments

@magurotuna
Copy link

Hi. I have a question.

https://github.com/dtolnay/syn/blob/master/src/attr.rs#L119-L150
The above code tells me that doc comments like /// foobar are transformed into #[doc = r"foobar"].

However, The Rust Reference says:

/// Foo turns into #[doc="Foo"] and /** Bar */ turns into #[doc="Bar"].

Why does this crate parse doc comments as raw string, unlike the rust compiler?

@dtolnay
Copy link
Owner

dtolnay commented Feb 24, 2020

The reference is wrong. ;)

@dtolnay
Copy link
Owner

dtolnay commented Feb 24, 2020

Here is how to see rustc's parse:

macro_rules! m {
    (#[doc = $tt:tt]) => { stringify!($tt) };
}

fn main() {
    println!(m! {
        ///test
    });
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=072e5762ca130412b992b55d4e87ccb8

@magurotuna
Copy link
Author

Thanks for the quick reply with a great example!
I've never thought the reference is wrong. The playground output is exactly raw string.
My question have been completely solved, so I close it.

kraktus added a commit to kraktus/reference that referenced this issue Dec 27, 2022
kraktus added a commit to kraktus/rust that referenced this issue Dec 27, 2022
This can actually make a difference for the user if they rely on unicode formating.

Prompted by dtolnay/syn#771
compiler-errors added a commit to compiler-errors/rust that referenced this issue Dec 27, 2022
Fix doc comment parsing description in book

This can actually make a difference for the user if they rely on unicode formating.

Prompted by dtolnay/syn#771
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants