-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Pattern matches with ranges & unsucessful guards don't behave correctly #13027
Comments
Based on reading PR #13034 and the code, I think the bug is a bug in What
and the opt here is Imagine that there were no guard: in that case, I could imagine the correct answer being just 1, because that match has the highest precedence. But the code doesn't appear to be setup that way, it seems to test each option independently with no regard for order. Therefore I gather that it would yield (in the case with no guard) 1 and 3. And then I think in the next recursion call to Note: Marijn's article may shed some light on the intended workings of the code. For some reason I haven't read it. I'm a glutton for punishment I guess. I really ought to, particularly since he writes so well. Based on all this, the right fix is... not immediately obvious to me. One option is to have Having
My conclusion is thus that the best thing would be to change |
I think I understand the logic of
to something like:
By the virtue of the fact that we are in Note,
is translated correctly to:
because we have exact equality of two So, we probably need to change the semantic of |
By carefully distinguishing falling back to the default arm from moving on to the next pattern, this patch adjusts the codegen logic for range and guarded arms of pattern matching expression. It is a more appropriate way of fixing rust-lang#12582 and rust-lang#13027 without causing regressions such as rust-lang#13867. Closes rust-lang#13867
By carefully distinguishing falling back to the default arm from moving on to the next pattern, this patch adjusts the codegen logic for range and guarded arms of pattern matching expression. It is a more appropriate way of fixing #12582 and #13027 without causing regressions such as #13867. Closes #13867
…iling-empty-macro, r=jonas-schievink fix: Fix incorrect type mismatch with `cfg_if!` and other macros in expression position Fixes rust-lang/rust-analyzer#12940 This is a bit of a hack, ideally `MacroStmts` would not exist at all after HIR lowering, but that requires changing how the lowering code works.
`needless_return`: Support `#[expect]` on the return statement A fix for rust-lang/rust-clippy#9361 suppresses `clippy::needless_return` if there are any attributes on the `return` statement. This leads to some unexpected behavior, as described in rust-lang/rust-clippy#12998, where adding `#[expect(clippy::needless_return)]` suppresses the lint, but doesn't fulfill the expectation. I now decided to manually fulfill any expectations, if they are before the attribute check. --- Closes: rust-lang/rust-clippy#12998 changelog: none
The following code prints
3
instead of2
:Removing the first arm (
1 if false => ...
) makes it print2
as expected.The text was updated successfully, but these errors were encountered: