Skip to content

Formatting stops working with specific code structure #5348

Closed as not planned
@l3utterfly

Description

@l3utterfly

VS Code
rustlang.rust v0.3.1051

The following code does not format (using the format command has no effect).

Removing the println line completely seems to make the code format again.

Is this a bug within rustfmt?

use std::thread;

enum Switch1 {
    Option1,
    Option2,
}

enum MassiveSwitch {
    Cmd1,
}

struct Worker {
    id: i32,
}

impl Worker {
    pub fn start(self) {
        let switch: MassiveSwitch = MassiveSwitch::Cmd1;
        let switch1 = Switch1::Option1;

        let _ = thread::Builder::new()
            .name(format!("Worker {}", self.id))
            .spawn(move || {
                if true {
                    match switch1 {
                        Switch1::Option1 => match switch {
                            MassiveSwitch::Cmd1 => {







                                // TODO: the white lines here should be deleted by rustfmt on save (or format command)
                                // TODO: removing this line causes rustfmt to work again. Commenting it out doesn't work, have to delete the line complete to get rust fmt to work
                                println!("Shard worker {}: received shutdown signal, exiting loop...", 5);

                                let test = "test";
                            }
                        },
                        Switch1::Option2 => todo!(),
                    }
                }
            })
            .expect("Can't spawn");
    }
}

fn main() {
    let worker = Worker { id: 3 };

    worker.start();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions