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

Broken suggestion for lint "hidden lifetime parameters in types" #65615

Closed
tesuji opened this issue Oct 20, 2019 · 4 comments
Closed

Broken suggestion for lint "hidden lifetime parameters in types" #65615

tesuji opened this issue Oct 20, 2019 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented Oct 20, 2019

Consider this code:

macro_rules! hash_impl {
    ($size:ty) => {
        use std::fmt;
        use std::any;

        pub struct Hash { size: $size }

        impl Hash {
            pub fn new(size: $size) -> Self { Self { size } }
        }

        impl fmt::Debug for Hash {
            fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
                f.debug_struct(any::type_name::<Self>()).field("size", &self.size).finish()
            }
        }
    }
}

pub mod foo { hash_impl!(u32); }
pub mod bar { hash_impl!(u64); }

When I run cargo fix --edition-idioms, I got:

The following errors were reported:
error: expected one of `!`, `)`, `,`, or `::`, found `<`
  --> src/lib.rs:13:53
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter<'_><'_>) -> Result<(), fmt::Error> {
   |                                                     ^ expected one of `!`, `)`, `,`, or `::` here
...
20 | pub mod foo { hash_impl!(u32); }
   |               ---------------- in this macro invocation

error: expected parameter name, found `'_`
  --> src/lib.rs:13:54
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter<'_><'_>) -> Result<(), fmt::Error> {
   |                                                      ^^ expected parameter name
...
20 | pub mod foo { hash_impl!(u32); }
   |               ---------------- in this macro invocation

error: expected one of `!`, `)`, `,`, or `::`, found `<`
  --> src/lib.rs:13:53
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter<'_><'_>) -> Result<(), fmt::Error> {
   |                                                     ^ expected one of `!`, `)`, `,`, or `::` here
...
21 | pub mod bar { hash_impl!(u64); }
   |               ---------------- in this macro invocation

error: expected parameter name, found `'_`
  --> src/lib.rs:13:54
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter<'_><'_>) -> Result<(), fmt::Error> {
   |                                                      ^^ expected parameter name
...
21 | pub mod bar { hash_impl!(u64); }
   |               ---------------- in this macro invocation

error[E0050]: method `fmt` has 3 parameters but the declaration in trait `std::fmt::Debug::fmt` has 2
  --> src/lib.rs:13:20
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter<'_><'_>) -> Result<(), fmt::Error> {
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 2 parameters, found 3
...
20 | pub mod foo { hash_impl!(u32); }
   |               ---------------- in this macro invocation
   |
   = note: `fmt` from trait: `fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>`

error[E0050]: method `fmt` has 3 parameters but the declaration in trait `std::fmt::Debug::fmt` has 2
  --> src/lib.rs:13:20
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter<'_><'_>) -> Result<(), fmt::Error> {
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 2 parameters, found 3
...
21 | pub mod bar { hash_impl!(u64); }
   |               ---------------- in this macro invocation
   |
   = note: `fmt` from trait: `fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>`

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0050`.
Original diagnostics will follow.

warning: hidden lifetime parameters in types are deprecated
  --> src/lib.rs:13:35
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
   |                                   ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
...
20 | pub mod foo { hash_impl!(u32); }
   |               ---------------- in this macro invocation
   |
   = note: `-W elided-lifetimes-in-paths` implied by `-W rust-2018-idioms`

warning: hidden lifetime parameters in types are deprecated
  --> src/lib.rs:13:35
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
   |                                   ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
...
21 | pub mod bar { hash_impl!(u64); }
   |               ---------------- in this macro invocation

warning: hidden lifetime parameters in types are deprecated
  --> src/lib.rs:13:35
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
   |                                   ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
...
20 | pub mod foo { hash_impl!(u32); }
   |               ---------------- in this macro invocation
   |
   = note: `-W elided-lifetimes-in-paths` implied by `-W rust-2018-idioms`

warning: hidden lifetime parameters in types are deprecated
  --> src/lib.rs:13:35
   |
13 |             fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
   |                                   ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
...
21 | pub mod bar { hash_impl!(u64); }
   |               ---------------- in this macro invocation

    Finished dev [unoptimized + debuginfo] target(s) in 0.35s

Meta

  • rustc 1.40.0-nightly (c23a7aa 2019-10-19)
  • cargo 1.40.0-nightly (3a9abe3f0 2019-10-15)
@tesuji
Copy link
Contributor Author

tesuji commented Oct 20, 2019

cc @petrochenkov (for macro part)

@tesuji
Copy link
Contributor Author

tesuji commented Oct 20, 2019

cc @zackmdavis (you wrote this lint)

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-lifetimes Area: Lifetimes / regions labels Oct 20, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Oct 20, 2019
@zackmdavis
Copy link
Member

Thanks for the report. This is a duplicate of #55768.

@tesuji
Copy link
Contributor Author

tesuji commented Oct 21, 2019

So is it.

@tesuji tesuji closed this as completed Oct 21, 2019
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 A-lifetimes Area: Lifetimes / regions A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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