You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code is not compiling, yet looking correct from my point of view:
println!("{}", match 777_i64 /* any i64 value will do */ {
i64::MIN...i64::MAX => "valid i64 value"
});
This does, but `_' here is kinda redundant:
println!("{}", match 777_i64 /* any i64 value will do */ {
i64::MIN...i64::MAX => "just as expected",
_ => "how this can possibly happen?"
});
Expected result: better match exhaustiveness checking or explicit reference to this kind of problems in E0004 (at least until this gets fixed, or forever, if this is not going to be fixed).
Details
To be more precise, by fixed size decimals I mean i/ui{8, 16, 32, 64}.
Currently in Rustc 1.3.0 (stable channel) user can not satisfy the compiler
even when whole range of possible [literal] values are covered in match pattern.
Lets imagine some of the if/else chain:
trait SubjectiveMeasurement {
fn how_big(self) -> &'static str;
}
impl SubjectiveMeasurement for i64 {
fn how_big(self) -> &'static str {
if self < -10000 {
"number is really tiny"
} else if self < -1000 {
"number is tiny"
} else if self < 0 {
"number is small"
} else if self == 0 {
"number is nil"
} else if self > 10000 {
"number is really huge"
} else if self > 1000 {
"number is huge"
} else {
"number is big"
}
}
}
fn main() {
println!("{}", (-1000_i64).how_big());
println!("{}", (1000_i64).how_big());
}
We can use pattern matching by ranges here to get better readability:
impl SubjectiveMeasurement for i64 {
fn how_big(self) -> &'static str {
match self {
i64::MIN...-10000 => "number is really tiny",
-9999...-1001 => "number is tiny",
-1000...-1 => "number is small",
0 => "number is nil",
1...1000 => "number is big",
1001...9999 => "number is huge",
10000...i64::MAX => "number is really huge",
_ => "why the hell I need this arm?!"
}
}
}
But again, we need an extra `_' arm.
From a position of compiler user, not a compiler developer, I want it to do a better job at
checking are all cases guarded or not.
The following code is not compiling, yet looking correct from my point of view:
This does, but `_' here is kinda redundant:
Expected result: better match exhaustiveness checking or explicit reference to this kind of problems in E0004 (at least until this gets fixed, or forever, if this is not going to be fixed).
Details
To be more precise, by fixed size decimals I mean i/ui{8, 16, 32, 64}.
Currently in Rustc 1.3.0 (stable channel) user can not satisfy the compiler
even when whole range of possible [literal] values are covered in match pattern.
Lets imagine some of the if/else chain:
We can use pattern matching by ranges here to get better readability:
But again, we need an extra `_' arm.
From a position of compiler user, not a compiler developer, I want it to do a better job at
checking are all cases guarded or not.
Meta
The text was updated successfully, but these errors were encountered: