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

2018 idioms: duplicate suggestion for anonymous lifetime #55768

Closed
alexcrichton opened this issue Nov 7, 2018 · 1 comment · Fixed by #90446
Closed

2018 idioms: duplicate suggestion for anonymous lifetime #55768

alexcrichton opened this issue Nov 7, 2018 · 1 comment · Fixed by #90446
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. 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. L-elided_lifetimes_in_paths Lint: elided_lifetimes_in_paths T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

First reported here this code:

#![warn(rust_2018_idioms)]

macro_rules! foo {
    ($name:ident) => {
        pub struct $name;
        impl ::std::fmt::Debug for $name {
            fn fmt(&self, _fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
                Ok(())
            }
        }
    }
}

foo!(One);
foo!(Two);

fn main() {}

when compiled yields two warnings to insert anonymous lifetimes. While we as humans can figure this out pretty well, Cargo as a merciless program can't figure this out and cargo fix attempts to apply the fix twice, creating invalid <'_><'_> syntax.

It's not clear whether it's best to fix this in cargo fix or fix this in the compiler itself. I figure it's easiest to track all idiom-lint related issues in this repository though, so I've opted to move it over here.

@zackmdavis
Copy link
Member

I think we could use the session's one-time diagnostics functionality to de-duplicate just the suggestion? (I assume this would require stripping expansion info from the spans.) If this is a good idea, it might also generalize to other lints ...

@alexcrichton alexcrichton added the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` label Jan 7, 2019
@bors bors closed this as completed in 76938d6 Dec 2, 2021
@jieyouxu jieyouxu added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-elided_lifetimes_in_paths Lint: elided_lifetimes_in_paths 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. C-bug Category: This is a bug. labels Oct 15, 2024
@fmease fmease added A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-edition-2018-lints labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. 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. L-elided_lifetimes_in_paths Lint: elided_lifetimes_in_paths 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.

4 participants