-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
match expression falling through? #26251
Comments
If you increase the first range to With modified rangefn main() {
let x = 'a';
match x {
'a'...'c' if false => {
println!("one");
},
'a' => {
println!("two");
},
'a'...'b' => {
println!("three");
},
_ => panic!("what?")
}
} With commented-out following match armfn main() {
let x = 'a';
match x {
'a'...'b' if false => {
println!("one");
},
'a' => {
println!("two");
},
/*
'a'...'b' => {
println!("three");
},
*/
_ => panic!("what?")
}
} |
#18060 is similar but doesn't have guards. IMO, these should both be marked P-high, I-wrong. |
triage: I-nominated |
cc @jakub- |
I agree this is totally bogus... seems like the chance of someone relying on this behavior is... low but not non-trivial? |
triage: P-high |
jrvidal ran across this in the wild so it can't be that low. |
FWIW, here is a simplified version of my use case, where I try to parse a number literal: loop {
match c {
// ...
'0'...'9' | 'a'...'f' if valid_digit(c, radix) => {/* parse digit */},
'e' | 'f' | 's' | 'd' | 'l' if is_decimal_literal() => {/* parse exponential marker */},
'0'...'9' | 'a'...'f' => {/* return error, bad digit */},
_ => break
}
} |
The root problem is the same as #18060. I've gotta say that I'm convinced the trans bits for This, however, is extremely worrisome in that it can lead to really nasty bugs in user code. |
The old code was not well structured, difficult to understand, and buggy. The new implementation is completely naive, so there may be a slight runtime performance loss. That said, adding optimizations on top of a clear and correct implementation seems easier than trying to fix the old mess. Fixes issue rust-lang#19064. Fixes issue rust-lang#26989. Fixes issue rust-lang#26251. Fixes issue rust-lang#18060. Fixes issue rust-lang#24875. Fixes issue rust-lang#23311. Fixes issue rust-lang#20046.
triage: P-medium also mir, apparently |
I just compiled with the latest nightly and it seems to be working!
|
I tried this code:
I expected to get
two
but I getthree
. Is this the expected semantics?Meta
rustc --version --verbose
:rustc 1.1.0-beta (cd7d89a 2015-05-16) (built 2015-05-16)
binary: rustc
commit-hash: cd7d89a
commit-date: 2015-05-16
build-date: 2015-05-16
host: x86_64-unknown-linux-gnu
release: 1.1.0-beta
The text was updated successfully, but these errors were encountered: