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

Incorrect compiler suggestion for adding lifetime bounds to derive macros #107694

Open
Mingun opened this issue Feb 5, 2023 · 1 comment
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Mingun
Copy link

Mingun commented Feb 5, 2023

Code

use serde::Deserialize; // 1.0.152

#[derive(Deserialize)]
struct Nested {
    float: f64,
}

#[derive(Deserialize)]
#[serde(tag = "tag")]
enum InternallyTagged {
    Flatten {
        #[serde(flatten)]
        nested: Nested,
        string: &'static str,
    },
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0261]: use of undeclared lifetime name `'de`
 --> src/lib.rs:8:10
  |
8 | #[derive(Deserialize)]
  |          ^^^^^^^^^^^
  |          |
  |          undeclared lifetime
  |          lifetime `'de` is missing in item created through this procedural macro
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
  = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider making the bound lifetime-generic with a new `'de` lifetime
  |
8 | #[derive(for<'de> Deserialize)]
  |          ++++++++
help: consider making the bound lifetime-generic with a new `'de` lifetime
  |
8 | #[derive(for<'de> Deserialize)]
  |          ++++++++
help: consider introducing lifetime `'de` here
  |
8 | #[derive(Deserialize<'de>)]
  |                     +++++

For more information about this error, try `rustc --explain E0261`.
error: could not compile `playground` due to previous error

Desired output

No response

Rationale and extra context

The error on playground.

The compiler suggest incorrect corrections to add lifetimes where they cannot appear. The reproduction of this bug depends on the serde bug serde-rs/serde#2371, which should not be fixed.

Other cases

No response

Anything else?

No response

@Mingun Mingun added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 5, 2023
@Mingun Mingun changed the title Incorrect compiler suggestion for adding lifitime bounds to derive macros Incorrect compiler suggestion for adding lifetime bounds to derive macros Feb 5, 2023
@lukas-code
Copy link
Member

related: #106720

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants