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

Formatted print doesn't work as expected with debug + enum #55749

Closed
macabeus opened this issue Nov 7, 2018 · 2 comments
Closed

Formatted print doesn't work as expected with debug + enum #55749

macabeus opened this issue Nov 7, 2018 · 2 comments

Comments

@macabeus
Copy link

macabeus commented Nov 7, 2018

If you use the debug print and a formatter such as {: <3?} with a enum to print the case name, the code does not work as expected.

#[derive(Debug)]
enum MyEnum {
    AB,
}

fn main() {
    let value = MyEnum::AB;
    println!("[{: <3?}]", value); // The result is `[AB]`
                                  // while I expected that the result is `[AB ]`.
}

It's only work if the enum has a value:

#[derive(Debug)]
enum MyEnum {
    AB(i32),
}

fn main() {
    let value = MyEnum::AB(42);
    println!("[{:<3?}]", value); // The result is `[42 ]`
}

Maybe we should fix this behaviour?

Also, I've open a question at Stackoverflow about this behaviour.

@macabeus macabeus changed the title Formatted print not work as expected with debug + enum Formatted print doesn't work as expected with debug + enum Nov 7, 2018
@hellow554
Copy link
Contributor

As already said on Stackoverflow, this might be related to #55584

@estebank
Copy link
Contributor

Closing as duplicate of #55584.

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

3 participants