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

derive(Display) does not propagate the alternate flag #107

Closed
troiganto opened this issue Nov 15, 2019 · 1 comment · Fixed by #108
Closed

derive(Display) does not propagate the alternate flag #107

troiganto opened this issue Nov 15, 2019 · 1 comment · Fixed by #108

Comments

@troiganto
Copy link
Contributor

In some of my code, I've been using the alternate flag {:#} to modify some formatting. I've been relying on the fact that deriving Display on an enum would propagate this flag downwards. (same for Binary, Octal, LowerHex, UpperHex, LowerExp, UpperExp, Pointer)

However, sometime betwee versions 0.15.0 and 0.99.1, this seems to have changed. (A quick bisect has led me to the commit d8de4b8.)

Minimal reproduction:

use derive_more::{Display, Binary, Octal};

#[derive(Display, Binary, Octal)]
struct MyInt(u32);

#[test]
fn check_display() {
    assert_eq!(format!("{:b}", MyInt(9)), "1001");
    assert_eq!(format!("{:#b}", MyInt(9)), "0b1001");
}

Using the current master, the second line currently fails because MyInt(9) gets formatted as "1001" instead.

Has this change been made on purpose? If not, what would be the best way to solve this issue? I don't have a lot of experience with proc-macros, but I'm sure with a few pointers, I could put together a PR.

@JelteF
Copy link
Owner

JelteF commented Nov 16, 2019 via email

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

Successfully merging a pull request may close this issue.

2 participants