-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Change mutation of non-mutable locals from an error to a lint #134233
Conversation
- replace errors related to local variable mutation with success + flag - check flag in add_unused_mut and emit lint if so The lint is kind of jank right now, and has trouble with closures. I want to re-use the diagnostic-generating code that was used to emit the original error, but from what I understand of rustc's diagnostic infrastructure that could require a not-insubstantial refactor.
… errors Create a "BorrowckDiag" trait which can be used to specialize report_mutability_error on the fatal-ness of the error
Still not lints, though...
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @SparrowLii (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Thanks for the work! I think this change should at least be submitted to a formal MCP or a language team fcp decision? |
@rust-lang/compiler |
Yeah this definitely needs an RFC. |
I'd frankly opt to close this PR at this point. While it's definitely cool that you've demonstrated that this is within the realm of possibility of implementation, it's probably not actionable to keep this PR open indefinitely (and accumulating merge conflicts) while the underlying desire for this feature is still up in the air. Both the zulip thread and the i-rl-o thread you linked failed to converged on any consensus towards this being experimented with, and the latter was actually closed by a moderator because of how much back and forth it led to. I expect an RFC to take some serious time to settle on a decision as well. I think it's most appropriate to reopen this PR when there's actually team consensus that this should be pushed forward. |
However it's not bad to have this as a future reference for an implementation if the team decides to go forward. |
Overview
Hello, all. This idea has been discussed previously:
As a quick summary of the above: the rust
mut
keyword has two meanings currently:&mut
The first of these is fundamental to Rust's safety guarantees and enables some optimizations. The second, however, is more of a lint: the error message may help catch mistakes, but ignoring it doesn't violate type safety or subvert any of Rust's global correctness guarantees.
Reasons for making the lint configurable instead of a hard error:
Reasons for maintaining the status quo:
mut
annotation for localsI don't necessarily expect this PR to get merged, but:
Implementation Details
add_used_mut
, the extra information is used to create and buffer non-fatal diagnosticsImplementation Concerns