Skip to content

Wrong suggestion for explicit_outlives_requirements in macro, part 2 #106063

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

Closed
lukas-code opened this issue Dec 22, 2022 · 0 comments · Fixed by #106064
Closed

Wrong suggestion for explicit_outlives_requirements in macro, part 2 #106063

lukas-code opened this issue Dec 22, 2022 · 0 comments · Fixed by #106064
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` 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

@lukas-code
Copy link
Member

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

@lukas-code lukas-code 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. labels Dec 22, 2022
@rustbot rustbot added A-lifetimes Area: Lifetimes / regions A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Dec 22, 2022
@bors bors closed this as completed in 18bf19c Dec 28, 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 A-lifetimes Area: Lifetimes / regions 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants