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

Fix raw identifiers usage in Display/Debug derives (#431) #434

Merged
merged 9 commits into from
Jan 16, 2025

Conversation

tyranron
Copy link
Collaborator

@tyranron tyranron commented Jan 7, 2025

Resolves #431

Synopsis

See #431 (comment):

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> {
  |                ++++++++++++++++++++++

Solution

Consider field with raw identifiers correctly in transparency checks and dereferencing.

Checklist

  • Documentation is updated (not required)
  • Tests are added/updated
  • CHANGELOG entry is added

@tyranron tyranron added this to the 2.0.0 milestone Jan 7, 2025
@tyranron tyranron self-assigned this Jan 7, 2025
@tyranron tyranron changed the title Fix raw identifiers usage in derive(Display) (#431) Fix raw identifiers usage in Display/Debug derives (#431) Jan 7, 2025
@tyranron tyranron marked this pull request as ready for review January 7, 2025 13:43
@tyranron tyranron enabled auto-merge (squash) January 7, 2025 13:49
@tyranron tyranron requested a review from JelteF January 7, 2025 13:49
@tyranron
Copy link
Collaborator Author

ping @JelteF

@tyranron tyranron requested a review from JelteF January 15, 2025 13:51
@tyranron
Copy link
Collaborator Author

@JelteF done!

@tyranron tyranron merged commit f14c7a7 into master Jan 16, 2025
17 checks passed
@tyranron tyranron deleted the 431-fix-display-raw-ident-generic branch January 16, 2025 08:11
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raw identifiers do not work inside generic types
2 participants