Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Raw identifiers do not work inside generic types #431

Closed
dtolnay opened this issue Dec 27, 2024 · 1 comment · Fixed by #434
Closed

Raw identifiers do not work inside generic types #431

dtolnay opened this issue Dec 27, 2024 · 1 comment · Fixed by #434
Assignees
Labels
Milestone

Comments

@dtolnay
Copy link

dtolnay commented Dec 27, 2024

Both of the following generate a working impl:

#[derive(Display)]
#[display("{thing}")]
struct Struct<T> {
    thing: T,  // generic
}
#[derive(Display)]
#[display("{thing}")]
struct Struct {
    r#thing: i32,  // raw
}

but this generates an impl that does not compile.

#[derive(Display)]
#[display("{thing}")]
struct Struct<T> {
    r#thing: T,  // raw, generic
}
error[E0277]: `T` doesn't implement `derive_more::Display`
 --> src/main.rs:3:10
  |
3 | #[derive(Display)]
  |          ^^^^^^^ `T` cannot be formatted with the default formatter
  |
  = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
  = note: required for `&T` to implement `derive_more::Display`
  = note: this error originates in the derive macro `Display` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T` with trait `Display`
  |
5 | struct Struct<T: derive_more::Display> {
  |                ++++++++++++++++++++++
@JelteF
Copy link
Owner

JelteF commented Feb 1, 2025

Thanks for reporting!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants