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

bug: Dropping semicolons for macros in non-let positions #77

Open
jkelleyrtp opened this issue Jul 30, 2024 · 0 comments
Open

bug: Dropping semicolons for macros in non-let positions #77

jkelleyrtp opened this issue Jul 30, 2024 · 0 comments

Comments

@jkelleyrtp
Copy link

jkelleyrtp commented Jul 30, 2024

This input:

#[test]
fn weird_macro() {
    let contents = r##"
    fn main() {
        move |_| {
            drop_macro_semi! {
                "something_very_long_something_very_long_something_very_long_something_very_long"
            }; // <--- semicolon here
            let _ = drop_macro_semi! {
                "something_very_long_something_very_long_something_very_long_something_very_long"
            };
            drop_macro_semi! {
                "something_very_long_something_very_long_something_very_long_something_very_long"
            };
        };
    }
"##;

    let expr: File = syn::parse_file(contents).unwrap();
    let out = unparse(&expr);
    println!("{}", out);
}

Returns

fn main() {
    move |_| {
        drop_macro_semi! {
            "something_very_long_something_very_long_something_very_long_something_very_long"
        } // <--- no semicolon here
        let _ = drop_macro_semi! {
            "something_very_long_something_very_long_something_very_long_something_very_long"
        };
        drop_macro_semi! {
            "something_very_long_something_very_long_something_very_long_something_very_long"
        }
    };
}

Dropping the semicolon on the first macro leads to semantically different code and thus compile errors.

This is likely because we're dropping the semicolon explicitly depending on the delimiter which just seems wrong to me - can't a macro have any delimiter without its semantic meaning changing?

https://github.com/dtolnay/prettyplease/blob/master/src/mac.rs#L46C17-L46C31

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

1 participant