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

can't format let chains #5456

Closed
matthiaskrgr opened this issue Jul 20, 2022 · 1 comment
Closed

can't format let chains #5456

matthiaskrgr opened this issue Jul 20, 2022 · 1 comment

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jul 20, 2022

let chains got stabilized recently but it seems that rustfmt has absolutely no idea how to format them rust-lang/rust#94927

sample code, nothing will be reformatted in this code:

pub enum Color {
    Blue,
    Red,
    Violet,
}

pub enum Flower {
    Rose,
    Tulip,
    Violet,
}

pub fn roses_are_red_violets_are_blue_printer(
    (first_flower, first_flower_color): (Flower, Color),
    (second_flower, second_flower_color): (Flower, Color),
    pick_up_lines: &[&str],
) {
    // I messed up the formatting here a bit
    if let Flower::Rose = first_flower
        && let Color::Red = first_flower_color &&
      let Flower::Violet = second_flower
        && let Color::Blue =
        second_flower_color
        && let &[first_pick_up_line, ..] = pick_up_lines
      {
 println!("Roses are red, violets are blue, {}", first_pick_up_line);
    }
}

fn main() {
    roses_are_red_violets_are_blue_printer(
        (Flower::Rose, Color::Red),
        (Flower::Violet, Color::Blue),
        &["sugar is sweet and so are you"],
    );
}
@calebcartwright
Copy link
Member

Thanks but going to close as a duplicate of #4955.

tl;dr, rustfmt doesn't format let expressions because there isn't any specification yet for how they should be formatted, even more so in chains - rust-lang/style-team#169

@calebcartwright calebcartwright closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants