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

formatting removes part of qualified path inside macro #5005

Closed
jsen- opened this issue Sep 26, 2021 · 2 comments · Fixed by #5008
Closed

formatting removes part of qualified path inside macro #5005

jsen- opened this issue Sep 26, 2021 · 2 comments · Fixed by #5008
Labels
2x-port:pending a-macros good first issue Issues up for grabs, also good candidates for new rustfmt contributors help wanted

Comments

@jsen-
Copy link

jsen- commented Sep 26, 2021

Pretty niche use case, but running rustfmt makes the code no longer compile.

#![feature(more_qualified_paths)]
macro_rules! show {
    ($ty:ty, $ex:expr) => {
        match $ex {
            <$ty>::A(_val) => println!("got a"), // formatting removes <$ty>::
            <$ty>::B => println!("got b"),
        }
    };
}

#[derive(Debug)]
pub enum Enum1 {
    A(u8),
    B,
}

fn main() {
    show!(Enum1, Enum1::B);
}
$ rustfmt --version
rustfmt 1.4.37-nightly (addb4da 2021-09-25)
@calebcartwright
Copy link
Member

Thanks for the report!

We actually just recently addressed this for the struct pattern variant, but obviously need to tackle that for the tuple struct variant too. Should be an easy fix for anyone that wants to work on it, and would be great if anyone wants to get a PR in within the next couple days so that I can pull it into the next release.

Fix would be to pull in the qself field, and then update the corresponding call(s) and fn signature(s) accordingly to take that in and include in the emitted formatting:

rustfmt/src/patterns.rs

Lines 229 to 232 in cb144c3

PatKind::TupleStruct(_, ref path, ref pat_vec) => {
let path_str = rewrite_path(context, PathContext::Expr, None, path, shape)?;
rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape)
}

#4964 was the PR that fixed this for the other variant, and should serve as a good reference

@jsen-
Copy link
Author

jsen- commented Sep 28, 2021

you guys rock 🤟
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2x-port:pending a-macros good first issue Issues up for grabs, also good candidates for new rustfmt contributors help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants