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

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raw identifiers do not work inside generic types
1 participant