-
Notifications
You must be signed in to change notification settings - Fork 123
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
Comments
That's definitely an unintended side effect of that commit. One thing that
definitely helps in fixing things like this is if you modify the currently
generated code to to create the intended effect.
You can get the currently generated using cargo expand (for Display derives
it might not be great though, since write! is also a macro and will thus be
expanded as well). The reason for this is that generating the correct code
is much easier once you know what the correct code actually is.
…On Fri, 15 Nov 2019, 23:44 troiganto, ***@***.***> wrote:
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
<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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#107?email_source=notifications&email_token=AAI3YJTITVV4FY7SSSVRC5LQT4Q45A5CNFSM4JOBV6X2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZXORUQ>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAI3YJR6VVH6EGK6IKWHTKTQT4Q45ANCNFSM4JOBV6XQ>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
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.
The text was updated successfully, but these errors were encountered: