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

Inappropriate inferred trait bounds when format var name overlaps with field name #345

Closed
dtolnay opened this issue Nov 4, 2024 · 0 comments · Fixed by #353
Closed

Inappropriate inferred trait bounds when format var name overlaps with field name #345

dtolnay opened this issue Nov 4, 2024 · 0 comments · Fixed by #353

Comments

@dtolnay
Copy link
Owner

dtolnay commented Nov 4, 2024

This code expands very sensibly to impl<T: Display> Display for Error<T>:

#[derive(Error, Debug)]
#[error("{thing}")]
pub struct Error<T> {
    thing: T,
}

This one expands to impl<T> Display for Error<T> with no inferred bound on T:

#[derive(Error, Debug)]
#[error("{var}", var = "...")]
pub struct Error<T> {
    thing: T,
}

But this one does not make sense. It expands to impl<T: Display> Display for Error<T> even though self.thing is not used in the error message and T does not need to be bound with Display.

#[derive(Error, Debug)]
#[error("{thing}", thing = "...")]
pub struct Error<T> {
    thing: T,
}
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.

1 participant