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_more::Display seems to handle special case for enum incorrectly #442

Closed
stepancheg opened this issue Jan 22, 2025 · 1 comment · Fixed by #395
Closed

derive_more::Display seems to handle special case for enum incorrectly #442

stepancheg opened this issue Jan 22, 2025 · 1 comment · Fixed by #395
Assignees
Labels
Milestone

Comments

@stepancheg
Copy link

This works correctly:

#[derive(derive_more::Display)]
#[display("x{}", self.command())]
enum Foo {
    Y,
}

impl Foo {
    fn command(&self) -> &'static str {
        "AAAAAA"
    }
}

#[test]
fn test() {
    assert_eq!("xAAAAAA", Foo::Y.to_string());
}

Now get rid of x prefix:

#[derive(derive_more::Display)]
#[display("{}", self.command())]
enum Foo {
    Y,
}

impl Foo {
    fn command(&self) -> &'static str {
        "AAAAAA"
    }
}

#[test]
fn test() {
    assert_eq!("AAAAAA", Foo::Y.to_string());
}

Now test fails:

assertion `left == right` failed
  left: "AAAAAA"
 right: "Y"

Version 1.0.0.

@tyranron tyranron self-assigned this Jan 23, 2025
@tyranron tyranron added the bug label Jan 23, 2025
@tyranron tyranron added this to the 2.0.0 milestone Jan 23, 2025
@tyranron
Copy link
Collaborator

@stepancheg this should already be fixed by #395 (at least the similar case is covered in tests, and I've also re-check your example on latest master), and will be released in 2.0.0 (hopefully, soon, since it's only #440 left to cut it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants