Repository: rust
Issue: macros: elided-lifetimes-in-paths adds same lifetime twice if applied with cargo fix
Labels: A-diagnostics,T-compiler,D-invalid-suggestion

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.

If you cannot produce a minimal reproduction case (something that would work in
isolation), please provide the steps or even link to a repository that causes
the problematic output to occur.
-->

Given the following code: <!-- Please provide a link to play.rust-lang.org -->

```rust
macro_rules! define_mask {
    { $(#[$attr:meta])* struct $name:ident($type:ty); } => {
        $(#[$attr])*
        #[allow(non_camel_case_types)]
        #[derive(Copy, Clone, Default, PartialEq, PartialOrd, Eq, Ord, Hash)]
        #[repr(transparent)]
        pub struct $name(pub(crate) $type);

        impl $name {
            /// Construct a mask from the given value.
            pub const fn new(value: bool) -> Self {
                if value {
                    Self(!0)
                } else {
                    Self(0)
                }
            }

            /// Test if the mask is set.
            pub const fn test(&self) -> bool {
                self.0 != 0
            }
        }

        impl core::convert::From<bool> for $name {
            fn from(value: bool) -> Self {
                Self::new(value)
            }
        }

        impl core::convert::From<$name> for bool {
            fn from(mask: $name) -> Self {
                mask.test()
            }
        }

        impl core::fmt::Debug for $name {
            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
                self.test().fmt(f)
            }
        }
    }
}



define_mask! {
    #[doc = "128-bit mask"]
    struct mask128(i128);
}

define_mask! {
    #[doc = "`isize`-wide mask"]
    struct masksize(isize);
}

pub fn main() {}
```

The current output is:
`RUSTFLAGS="-Welided-lifetimes-in-paths" cargo fix`
```
The following errors were reported:
error: expected parameter name, found `>`
  --> src/main.rs:38:62
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_>) -> core::fmt::Result {
   |                                                                ^ expected parameter name
...
47 | / define_mask! {
48 | |     #[doc = "128-bit mask"]
49 | |     struct mask128(i128);
50 | | }
   | |_- in this macro invocation
   |
   = note: this error originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add `'` to close the char literal
   |
38 |             fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_'>) -> core::fmt::Result {
   |                                                              +

error: expected one of `:` or `|`, found `>`
  --> src/main.rs:38:62
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_>) -> core::fmt::Result {
   |                                                                ^ expected one of `:` or `|`
...
47 | / define_mask! {
48 | |     #[doc = "128-bit mask"]
49 | |     struct mask128(i128);
50 | | }
   | |_- in this macro invocation
   |
   = note: this error originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected one of `!`, `)`, `,`, or `::`, found `<`
  --> src/main.rs:38:59
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_>) -> core::fmt::Result {
   |                                                             ^
   |                                                             |
   |                                                             expected one of `!`, `)`, `,`, or `::`
   |                                                             help: missing `,`
...
47 | / define_mask! {
48 | |     #[doc = "128-bit mask"]
49 | |     struct mask128(i128);
50 | | }
   | |_- in this macro invocation
   |
   = note: this error originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected parameter name, found `>`
  --> src/main.rs:38:62
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_>) -> core::fmt::Result {
   |                                                                ^ expected parameter name
...
52 | / define_mask! {
53 | |     #[doc = "`isize`-wide mask"]
54 | |     struct masksize(isize);
55 | | }
   | |_- in this macro invocation
   |
   = note: this error originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add `'` to close the char literal
   |
38 |             fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_'>) -> core::fmt::Result {
   |                                                              +

error: expected one of `:` or `|`, found `>`
  --> src/main.rs:38:62
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_>) -> core::fmt::Result {
   |                                                                ^ expected one of `:` or `|`
...
52 | / define_mask! {
53 | |     #[doc = "`isize`-wide mask"]
54 | |     struct masksize(isize);
55 | | }
   | |_- in this macro invocation
   |
   = note: this error originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected one of `!`, `)`, `,`, or `::`, found `<`
  --> src/main.rs:38:59
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_>) -> core::fmt::Result {
   |                                                             ^
   |                                                             |
   |                                                             expected one of `!`, `)`, `,`, or `::`
   |                                                             help: missing `,`
...
52 | / define_mask! {
53 | |     #[doc = "`isize`-wide mask"]
54 | |     struct masksize(isize);
55 | | }
   | |_- in this macro invocation
   |
   = note: this error originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0050]: method `fmt` has 3 parameters but the declaration in trait `std::fmt::Debug::fmt` has 2
  --> src/main.rs:38:20
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_>) -> core::fmt::Result {
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 2 parameters, found 3
...
47 | / define_mask! {
48 | |     #[doc = "128-bit mask"]
49 | |     struct mask128(i128);
50 | | }
   | |_- in this macro invocation
   |
   = note: `fmt` from trait: `fn(&Self, &mut Formatter<'_>) -> Result<(), std::fmt::Error>`
   = note: this error originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0050]: method `fmt` has 3 parameters but the declaration in trait `std::fmt::Debug::fmt` has 2
  --> src/main.rs:38:20
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter<'_><'_>) -> core::fmt::Result {
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 2 parameters, found 3
...
52 | / define_mask! {
53 | |     #[doc = "`isize`-wide mask"]
54 | |     struct masksize(isize);
55 | | }
   | |_- in this macro invocation
   |
   = note: `fmt` from trait: `fn(&Self, &mut Formatter<'_>) -> Result<(), std::fmt::Error>`
   = note: this error originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 8 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/main.rs:38:46
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
   |                                     -----------^^^^^^^^^
   |                                     |
   |                                     expected lifetime parameter
...
47 | / define_mask! {
48 | |     #[doc = "128-bit mask"]
49 | |     struct mask128(i128);
50 | | }
   | |_- in this macro invocation
   |
   = note: requested on the command line with `-W elided-lifetimes-in-paths`
   = note: this warning originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)
help: indicate the anonymous lifetime
   |
38 |             fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
   |                                                       ++++

warning: hidden lifetime parameters in types are deprecated
  --> src/main.rs:38:46
   |
38 |               fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
   |                                     -----------^^^^^^^^^
   |                                     |
   |                                     expected lifetime parameter
...
52 | / define_mask! {
53 | |     #[doc = "`isize`-wide mask"]
54 | |     struct masksize(isize);
55 | | }
   | |_- in this macro invocation
   |
   = note: this warning originates in the macro `define_mask` (in Nightly builds, run with -Z macro-backtrace for more info)
help: indicate the anonymous lifetime
   |
38 |             fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
   |                                                       ++++

warning: `imcrate` (bin "imcrate" test) generated 2 warnings (2 duplicates)
warning: `imcrate` (bin "imcrate") generated 2 warnings (run `cargo fix --bin "imcrate"` to apply 2 suggestions)
```