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

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

Closed
reuvenpo opened this issue Jun 29, 2018 · 1 comment
Labels
A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@reuvenpo
Copy link

reuvenpo commented Jun 29, 2018

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.

@reuvenpo reuvenpo changed the title println!(), derive(Debug), derive(Clone), and probably many other macros break when using elided_lifetimes_in_paths println!(), derive(Debug), derive(Clone), and probably many other macros break when using the elided_lifetimes_in_paths lint Jun 29, 2018
@stokhos stokhos added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-lifetimes Area: Lifetimes / regions labels Jun 29, 2018
@jkordish jkordish added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 11, 2018
@zackmdavis
Copy link
Member

The lint was rewritten in #52069. With some borrow-checker fixes (and {:?} instead of {}), the example now works:

#![deny(elided_lifetimes_in_paths)]

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

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

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

fn main() {
    let foo = Foo { a: 1, b: 2 };
    fun(&foo);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

4 participants