Skip to content

println!(), derive(Debug), derive(Clone), and probably many other macros break when using the elided_lifetimes_in_paths lint #51903

Closed
@reuvenpo

Description

@reuvenpo

in the latest stable compiler(1.27) (and probably earlier ones too) this snippet won't compile:

#![deny(elided_lifetimes_in_paths)]


#[derive(Debug)]
struct Foo {
    a: i32,
    b: i32,
}

#[derive(Debug)]
struct Bar<'a> {
    a: &'a Foo,
}

fn fun<'a>() {
    let foo = Foo {a: 1, b: 2};
    let bar = Bar::<'a> {a: &foo};
    println!("{}", bar);
}

fn main() {
    fun();
}

The issue is that the code is perfectly fine. The compilation errors come from the macros used:

error: hidden lifetime parameters are deprecated, try `Foo<'_>`
  --> src/main.rs:18:5
   |
18 |     println!("{}", bar);
   |     ^^^^^^^^^^^^^^^^^^^^
   |
note: lint level defined here
  --> src/main.rs:1:9
   |
1  | #![deny(elided_lifetimes_in_paths)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: hidden lifetime parameters are deprecated, try `Foo<'_>`
  --> src/main.rs:18:5
   |
18 |     println!("{}", bar);
   |     ^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: hidden lifetime parameters are deprecated, try `Foo<'_>`
 --> src/main.rs:4:10
  |
4 | #[derive(Debug)]
  |          ^^^^^

error: hidden lifetime parameters are deprecated, try `Foo<'_>`
  --> src/main.rs:10:10
   |
10 | #[derive(Debug)]
   |          ^^^^^

error: hidden lifetime parameters are deprecated, try `Foo<'_>`

error: aborting due to 5 previous errors

The user of these macros + lint can't do anything to fix the errors. It seems as though at least some macro definitions in the standard library aren't ready for this lint yet.

See also #51902.

Note, the lint is still useful (actually helped me figure out some issues i had), but can't be left on because of these bugs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions