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-lints Area: lints supporting the 2018 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`.

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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018-lints Area: lints supporting the 2018 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants