-
Notifications
You must be signed in to change notification settings - Fork 1.7k
FP redundant_pattern_matching: try! macro #5504
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
Comments
😄 hm, it seems like
|
I investigated the problem. I was wrong in comment about
inside the Well, now we need to fix it here in clippy. I suggest to replace I need an advice, @flip1995 |
Minimal reproducer: macro_rules! m {
() => {
Some(42u32)
};
}
fn main() {
if let Some(_) = m!() {}
if m!().is_some() {} // This should be suggested
if Some(42u32).is_some() {} // This is suggested
} The problem here is that the macro gets expanded, when building the suggestion. A possible fix is to use
Nope, this is not a rustc bug. |
I don't talk about macros here. It's an important thing, but out-of-scope a bit. I talk about the question: what span should corresponds to the match expression with source And the other question is "What should I use to get the span pointed to a whole
Of course. I added this test. And already get the correct suggestion. Thanks. |
Ah now I get your question. That would be the span of the expression, that destructures to
I disagree, since the arm is the thing matched against. In this case while let Some(_) = opt {}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ expr.span, where expr.kind = ExprKind::Match(cond, arms, MatchSource::WhileLetDesugar)
// ^^^^^^^ arms[0].pat.span
// ^^^ cond.span
// gets lowered to:
loop {
match opt { // cond
Some(_) => {}, // arms[0]
_ => break,
}
} |
Arrgh... You didn't completely got what I mean, but now much better 😄 Maybe it's because of my english 😞
Yes, it's a good point. I thought the same, but This is the result of
I talk about And now I have another question: Does there exists a documentation about "spans", where I can read some stable properties of spans? |
Fix redundant_pattern_matching lint fixes #5504 changelog: Fix suggestion in `redundant_pattern_matching` for macros.
Fix redundant_pattern_matching lint fixes #5504 changelog: Fix suggestion in `redundant_pattern_matching` for macros.
Fix redundant_pattern_matching lint fixes #5504 changelog: Fix suggestion in `redundant_pattern_matching` for macros.
Oh, that is indeed weird. That should be the whole
Ah, I see. I guess the two lines you referenced are kind of a hack, since the
Nothing of rustc internals is anywhere close to stable, that's why we have so much fun with rustup. 😭:smile: The Span documentation maybe. In the rustc-dev-guide there's sadly not much about |
But I need some span... 😄 In the PR I use Actually |
Just have a little patience, with the currently open PR, until I figured this out. IMO you were right and this is a bug in the lowering. |
This code from serde
caused the warning
_.is_some()
does not look like it is going to work 😄clippy 0.0.212 (891e1a8 2020-04-18)
The text was updated successfully, but these errors were encountered: