-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Wrong suggestion from single_match #1404
Comments
We're probably just taking the wrong span. Since I'm sure this worked before, we probably messed up a rustup. |
We should probably add a test with a single line match to produce a single line if let so we can test te suggestion |
There are tests for this, but the problem seems to be that this is in a macro. Investigating further, it seems that the
when given this example file to lint: #![feature(plugin)]
#![plugin(clippy)]
#![deny(clippy)]
#![allow(unused, if_let_redundant_pattern_matching)]
fn main() {
#[derive(Debug)]
enum Foo {
A(String),
B,
}
struct Thingy(Foo);
macro_rules! issue_1404 {
($idx:tt) => {{
let thingy = Thingy(Foo::A("Foo".into()));
let t = &thingy;
match t.$idx { Foo::A(ref val) => { println!("42"); }, _ => {} }
}}
}
issue_1404!(0)
} which causes it to show this error:
|
Thanks for the detailed report and minimal example! Cooking up a fix now. |
ok... looks like rustc is generating the wrong span here. |
ok, so I know what's going on. rustc expands Not sure how to fix it yet though. |
hmm... looking at it again. Rustc is not doing anything wrong. We have two options:
Anyone against simply removing the suggestion if macros are involved? Or even go as far as to not lint at all if macros are involved, since we can't guarantee that changing the macro won't have unintended side-effects (like in this case, suddenly having more arms, so the lint stops applying) |
Wow, thanks for further digging into this. I hope regular people don't find themselves having these problem inside of macros, so I'm okay with disabling the lint there 😅
… Am 28.01.2017 um 19:22 schrieb Oliver Schneider ***@***.***>:
hmm... looking at it again. Rustc is not doing anything wrong.
We have two options:
• don't give suggestions when an expansion is involved
• figure out a way to find the macro_rules arm, which was responsible for this expansion and lint somewhere in there. This has the problem that some expansions might lint, some not, depending on the types involved.
Anyone against simply removing the suggestion if macros are involved? Or even go as far as to not lint at all if macros are involved, since we can't guarantee that changing the macro won't have unintended side-effects (like in this case, suddenly having more arms, so the lint stops applying)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
It seems we cannot reproduce this (Playground). I think that the code for |
Ah great, thanks! |
I'm trying to add clippy to diesel (again), and just got this:
The suggestion contains the correct line for if-let itself, but the body is an exact copy of the match arms, not the expression on the right side of the single match arm.
The correct suggestion would be:
As you can see, this is inside a macro. I can try to make a smaller example to reproduce this if you want.
The text was updated successfully, but these errors were encountered: