-
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
Suggest defining variable as mutable on &mut _
type mismatch in pats
#98431
Conversation
This comment has been minimized.
This comment has been minimized.
9b680d5
to
3c7f1f1
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
|
||
ident_kind.map(|thing| ( | ||
pat.span, | ||
format!("to declare a mutable {thing} use `mut variable_name`"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to declare a mutable {thing} use:
-- the mut variable_name
part is redundant with the suggestion that follows direectly after
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine after nits
}, | ||
|
||
// Don't provide suggestions in other cases | ||
_ => None, | ||
_ => break 'block None, | ||
}; | ||
|
||
ident_kind.map(|thing| ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, my suggestion was not complete! you should probably remove this .map
since it's no longer Option
. I should have been more clear.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Michael Goulet <michael@errs.io>
91292b7
to
1dfb53b
Compare
Cool, thanks. @bors r+ rollup |
📌 Commit 1dfb53b has been approved by |
I think that actually has been implemented: |
Does |
…=compiler-errors Suggest defining variable as mutable on `&mut _` type mismatch in pats Suggest writing `mut a` where `&mut a` was written but a non-ref type provided. Since we still don't have "apply either one of the suggestions but not both" kind of thing, the interaction with the suggestion of removing `&[mut]` or moving it to the type is weird, and idk how to make it better.. r? `@compiler-errors`
In what regard? I think rustfix won't autoapply the suggestions if you use |
…=compiler-errors Suggest defining variable as mutable on `&mut _` type mismatch in pats Suggest writing `mut a` where `&mut a` was written but a non-ref type provided. Since we still don't have "apply either one of the suggestions but not both" kind of thing, the interaction with the suggestion of removing `&[mut]` or moving it to the type is weird, and idk how to make it better.. r? `@compiler-errors`
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#96412 (Windows: Iterative `remove_dir_all`) - rust-lang#98126 (Mitigate MMIO stale data vulnerability) - rust-lang#98149 (Set relocation_model to Pic on emscripten target) - rust-lang#98194 (Leak pthread_{mutex,rwlock}_t if it's dropped while locked.) - rust-lang#98298 (Point to type parameter definition when not finding variant, method and associated item) - rust-lang#98311 (Reverse folder hierarchy) - rust-lang#98401 (Add tracking issues to `--extern` option docs.) - rust-lang#98429 (Use correct substs in enum discriminant cast) - rust-lang#98431 (Suggest defining variable as mutable on `&mut _` type mismatch in pats) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
@camelid rustfix tries to apply all suggestions:
Also the output of the diagnostic is not perfect either, since suggestions don't have labels and it's hard to distinguish them:
I think to fix this problem we need a different format for suggestions, that would allow for more flexibility. For example marking placeholders as such (so the tooling could allow users to fill them) or having "either one of these suggestions, but not all" kind of thing. I was meaning to try implementing something like this for a while, but haven't yet. |
I believe that's what |
Suggest writing
mut a
where&mut a
was written but a non-ref type provided.Since we still don't have "apply either one of the suggestions but not both" kind of thing, the interaction with the suggestion of removing
&[mut]
or moving it to the type is weird, and idk how to make it better..r? @compiler-errors