Skip to content

Wrong suggestion for explicit_outlives_requirements in macro, part 2 #106063

Closed
@lukas-code

Description

@lukas-code

Given the following code: clicky

#![warn(explicit_outlives_requirements)]
#![allow(dead_code)]

macro_rules! make_baz {
    ($a:lifetime, $b:lifetime) => {
        struct Baz<$a, $b: $a> where (): Sized, $b: $a {
            baz: &$a &$b (),
        }
    };
}

make_baz!{ 'a, 'b }

The current output is:

warning: outlives requirements can be inferred
  --> src/lib.rs:6:49
   |
6  |         struct Baz<$a, $b: $a> where (): Sized, $b: $a {
   |                                                 ^
...
12 | make_baz!{ 'a, 'b }
   | -----------^^^^^^-- in this macro invocation
   |
note: the lint level is defined here
  --> src/lib.rs:1:9
   |
1  | #![warn(explicit_outlives_requirements)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this warning originates in the macro `make_baz` (in Nightly builds, run with -Z macro-backtrace for more info)
help: remove these bounds
   |
6  ~         struct Baz<$a, $b: $a> where (): Sized, $b: $a {
7  |             baz: &$a &$b (),
 ...
11 | 
12 ~ make_baz!{  }
   |

warning: `rust-test` (lib) generated 1 warning (run `cargo fix --lib -p rust-test` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.20s

Notice the invalid machine applicable suggestion.

Ideally the output should look like: Probably no warning at all?

related to #106044

@rustbot label A-suggestion-diagnostics A-lifetimes D-invalid-suggestion

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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