-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Use 'mut' as alias for 'let mut' #65257
Comments
Rust wants to make to make you think when you try and use mutation, even if only a little bit, because mutation can be difficult to reason about. Shortening tldr: |
I politely disagree. In fact, it is actually the other way around. Using |
The fact that people will choose |
Incorrect. Extreme brevity harms readability. See Perl. lol Readers would ignore the It's true boilerplate often harms readability, but boilerplate requires some complexity be repeated, not merely the It harms readability even further if Rust syntax was designed largely to reduce cognitive load, not to reduce typing. We use Rust has short keywords only really for fundamental "items" used repeatedly by basically every module. It's similar cognitive load if you write |
The |
It seems unlikely to me that we would support However, I've taken the liberty of reusing this issue towards improved diagnostics:
The idea here is to check
The idea here is to check: is_ident_var_or_auto && !self.look_ahead(1, |t| is_brace(t))` The relevant code is here: rust/src/libsyntax/parse/parser/stmt.rs Lines 44 to 49 in ece4977
cc @estebank |
@rustbot claim |
This comment has been minimized.
This comment has been minimized.
@Centril Although I would also guess that the initial idea is very unlikely to end up accepted, it feels premature to unilaterally hijack the thread in your very first comment and make it have a different (and in a way opposite) purpose. Teams of the Rust project are designed to make decisions collectively. Improving diagnostics sounds good, but issue numbers are cheap. |
Implementing something as a diagnostic actually brings you closer to a working implementation -- I think more proposals should start out as diagnostics.
I will not bother the other language team members with not-fully-formed proposals that we will not accept in either case. I converted the issue into the most actionable and productive thing it could be. If you want to discuss this further, I'm available at Discord (but will not respond to it further here).
...but wasting everyone's time with things that will go nowhere (because it won't be accepted and because it is not important enough to be raised at the team) is not. |
IMHO, the original thing this issue was opened for should be an RFC, not an issue. I'd have closed this, pointed the OP to the RFCs repo, and opened a new issue for the diagnostic issue. |
This issue was literally in the RFCs repo initially, @Centril transferred it from there. |
@burdges Language bashing is not welcome here |
@steveklabnik Wait, so should I unassign here, and assign to the new issue? |
@Chocol4te Nah, just use this one. |
Yeah, thats fine. You can just change this issue to be for diagnostics instead. |
I'm sorry, I've been pretty busy with coursework, and I'm still fighting my Python installation to even build the compiler, let alone make progress on this. Sorry :( |
I'll assign this to myself to work on when I have time. If you want to work on it however, feel free to work-steal it from me! |
I would like to help with this |
@JesterOrNot Sorry; should have updated this issue...! There's a PR #65811 at the moment. Feel free to leave suggestions on it if you like. :) |
The idea of shortening
let mut
tovar
has been discussed many times before, and the general consensus always ends up being that it is not a good idea. I would like to propose something a bit different, so please hear me out.I propose that instead of aliasing
var
tolet mut
, we instead just makemut
expand intolet mut
when in the context of a variable declaration. For example:This solves the problems (readability, more concise) that people have with
let mut
, whilst not causing the issues that people have (pattern matching and consistancy).The most common issue people have with aliasing
var
tolet mut
is that it doesn't fit well with patterns, likelet (x, mut y) = ...
. However,mut
gets rid of this problem, because you wouldn't writelet mut (x, mut y)
if you were trying to pattern match, so why would someone want to writemut (x, mut y)
? You wouldn't do that, and it wouldn't compile.This would be optional, of course.
let mut x = 1
would still work fine, and people would just have to option of removing thelet
to let it be implied.There are a lot of other abbreviations used in rust (
fn
,mod
,pub
) that all serve the purpose of writing less. It just doesn't feel right that one of the most commonly used keywords is so long.❤️🦀
The text was updated successfully, but these errors were encountered: