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

macros: elided-lifetimes-in-paths adds same lifetime twice if applied with cargo fix #105148

Open
matthiaskrgr opened this issue Dec 1, 2022 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

@matthiaskrgr
Copy link
Member

Given the following code:

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)
@matthiaskrgr matthiaskrgr 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. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Dec 1, 2022
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 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

1 participant