Skip to content

regression processing c-style doc comments in proc macros between 1.46 and 1.47 #80545

Open
@ahl

Description

When a proc macro is applied to an item that has an associated c-style doc comment the contents of the TokenStream changed between 1.46 and 1.47. In particular the surrounding * and newlines were previously elided (mostly), but as of 1.47 they are not.

Code

Here's a little repo I put together to demonstrate and reproduce the issue: https://github.com/ahl/cdoc_regression. It contains a proc macro that looks like this:

#[proc_macro_attribute]
pub fn return_as_is(_attr: TokenStream, item: TokenStream) -> TokenStream {
    for token in item.clone() {
        match token {
            TokenTree::Group(group) if group.delimiter() == Delimiter::Bracket => {
                println!("{:}", group)
            }
            _ => {}
        }
    }
    item
}

Here's the output:

$ cargo +1.46.0 run --example test
   Compiling fun v0.1.0 (/Users/ahl/src/cdoc_regression)
[doc = " This is a multi-"]
[doc = " line comment."]
[doc = " This is another multi-\n line comment."]
    Finished dev [unoptimized + debuginfo] target(s) in 0.30s
     Running `target/debug/examples/test`
$ cargo +1.47.0 run --example test
   Compiling fun v0.1.0 (/Users/ahl/src/cdoc_regression)
[doc = " This is a multi-"]
[doc = " line comment."]
[doc = "\n * This is another multi-\n * line comment.\n "]
    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/examples/test`

In both cases, the first multiline comment is for a ///-style comment and the second is for a /**-style comment.

Version it worked on

rustc 1.46.0 (04488afe3 2020-08-24)
binary: rustc
commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
commit-date: 2020-08-24
host: x86_64-apple-darwin
release: 1.46.0
LLVM version: 10.0

Version with regression

rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-apple-darwin
release: 1.47.0
LLVM version: 11.0

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The parsing of Rust source code to an ASTA-proc-macrosArea: Procedural macrosE-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions