I apologize for presenting this in an IDE-centric way, but I am shocked to find that when I am matching on &str arms, and I include a symbol as one of the arms that is not in scope, instead of a compilation error, Rust compiles and treats that arm as the 'catch all arm'.
For example, given this complete program:
pub const SOMETHING: &str = "something";
pub const SOMETHING_ELSE: &str = "somethingElse";
fn main() {
let x = "something";
match x {
SOMETHING => {},
SOMETHING_ELSE => {},
BOGUS_SYMBOL => {},
_ => {}
}
}
I'm surprised that it compiles with a warning unused variable: BOGUS_SYMBOL.
What is going on here. This is not the desired behavior as far as I'm concerned! This is especially bad when trying to quickly refactor, move things around etc, when compilations have a million warnings until you clean things up... instead of following compiler errors around and fixing, I can actually get a baffling program instead!
There is a warnings group nonstandard-style that you might want to deny entirely. It includes the warnings non-camel-case-types, non-snake-case, non-upper-case-globals.
Iām currently trying to find out if you can specify something like this in the Cargo.toml.
There is a warnings group nonstandard-style that you might want to deny entirely. It includes the warnings non-camel-case-types , non-snake-case , non-upper-case-globals .
These errors are good solutions and I will use them.
The reason that I am still very sad, and for which nothing can be done, is that my IDE cannot automatically import symbols in this case.
I use JetBrains and fly through missing imports (in all languages) with a quick option-enter->import on everything that turns red. Can't do it in this case because of language design.
I'm sure that design aspect of the syntax was done way before such considerations came about. It's too bad in retrospect that it doesn't look like this instead
pub const SOMETHING: &str = "something";
pub const SOMETHING_ELSE: &str = "somethingElse";
fn main() {
let x = "something";
match x {
SOMETHING => {},
SOMETHING_ELSE => {},
_(unknown_string) => {}
}
}