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

Macro expansion moves comments around. #75332

Open
steffahn opened this issue Aug 9, 2020 · 1 comment
Open

Macro expansion moves comments around. #75332

steffahn opened this issue Aug 9, 2020 · 1 comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`)

Comments

@steffahn
Copy link
Member

steffahn commented Aug 9, 2020

pub fn bar() {
    println!("Hello, World!");
}


// hello...

pub fn foo() {
    /*
    some
    comment
    */
}

// ...world!

(Playground)

Macro Expansion:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
pub fn bar() {


    // hello...

    /*
    some
    comment
    */

    // ...world!
    {
        ::std::io::_print(::core::fmt::Arguments::new_v1(&["Hello, World!\n"],
                                                         &match () {
                                                              () => [],
                                                          }));
    };
}
pub fn foo() { }
@petrochenkov
Copy link
Contributor

petrochenkov commented Aug 9, 2020

I first thought this would be about doc comments, then it would be a duplicate of #67839.

But this is about regular comments that are not parsed into AST and don't participate in expansion at all.
Pretty-printing used by --pretty=expanded then tries its best to put comments into their old places based on spans, but there aren't any guarantees.

@petrochenkov petrochenkov added the A-pretty Area: Pretty printing (including `-Z unpretty`) label Aug 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`)
Projects
None yet
Development

No branches or pull requests

2 participants