52 points · by todsacerdoti · 2y ago · 14 comments
https://github.com/rust-lang/rust/commit/04a2887f879
And here's a 2013 bug for the ambiguity:
Do you know why the syntax was decided to get axed? Is this part of a larger PR where the decision is elaborated upon?
// this is a common pattern in rust for one-line matches. If this thing matches Some(..)
// we can do something with the string.
if let Some(username) = maybe_username {
// so ok, this code will run if the username exists...
return username.to_uppercase();
}
// except, uh... Now that code will only run if 'username' matches Some("hey")
const username: &str = "hey";
As convenient as hoisting sometimes can be, I'm wary of it for exactly reasons like this. Even in "normal" code flow, it disrupts the usual linear flow of code logic when you're reading it, and this kind of action-at-a-distance makes it especially bad.That said, the article was an entertaining read and the blog is pleasantly styled. I’m glad I spent some time with this even though my ultimate takeaway is kind of “meh”.
That’s indeed the point.
Go has proven at this point that the language spec is the correct place to settle stupid bike sheding especially when they lead to misfeature like this one.
I understand that it’s not the most urgent thing to fix when it comes to Rust syntax but still a clear downside.
// whoops, accidentally commented out or deleted this import
// use crate::{SOME_GL_CONSTANT, OTHER_THING}
// uh oh!
match value {
SOME_GL_CONSTANT => ..,
OTHER_THING => ..,
_ => ..,
}
Specifically, I think FFI stuff or an initial Rust rewrite can be a strong incentive to (locally) disable compiler/linter warnings around capitalization because you are more interested in consistency with an existing C API. This turns the molehill into at least a real hill (though not a mountain).Set up your highlighting tools so that they don't look the same. Problem solved.