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

Eliminate 'de lifetime from visitors of const generic unit struct #2501

Closed
wants to merge 1 commit into from

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Jul 10, 2023

In #2500 I was trying to figure out whether the two PhantomData in __Visitor are necessary i.e. if there is any case that compiles with them and breaks without them. I came up with this one:

#[derive(Deserialize)]
#[serde(bound(deserialize = "[&'de str; N]: Copy"))]
struct GenericUnitStruct<const N: usize>;
error[E0401]: can't use generic parameters from outer item
 --> src/main.rs:4:29
  |
3 | #[derive(Deserialize)]
  |          ----------- lifetime parameter from outer item
4 | #[serde(bound(deserialize = "[&'de str; N]: Copy"))]
  |                             ^^^^^^^^^^^^^^^^^^^^^ use of generic parameter from outer item
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'de` lifetime
  |
4 | #[serde(bound(deserialize = for<'de> "[&'de str; N]: Copy"))]
  |                             ++++++++
help: consider introducing lifetime `'de` here
  |
5 | struct GenericUnitStruct<'de, const N: usize>;
  |                          ++++

error: impl method assumes more implied bounds than the corresponding trait method
 --> src/main.rs:3:10
  |
3 | #[derive(Deserialize)]
  |          ^^^^^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #105572 <https://github.com/rust-lang/rust/issues/105572>
  = note: `#[deny(implied_bounds_entailment)]` on by default
  = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

@dtolnay dtolnay closed this in 662fc38 Jul 10, 2023
@dtolnay dtolnay deleted the genericunit branch July 10, 2023 01:01
@Baptistemontan
Copy link
Contributor

For #2500 I reused as much code as I could from the code for "normal" struct (not unit, not tuple, not newtype), I not that much confident in my variance skills so I left the lifetime untouched.

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

Successfully merging this pull request may close these issues.

2 participants