Auto merge of #101241 - camsteffen:refactor-binding-annotations, r=cjgillot
`BindingAnnotation` refactor * `ast::BindingMode` is deleted and replaced with `hir::BindingAnnotation` (which is moved to `ast`) * `BindingAnnotation` is changed from an enum to a tuple struct e.g. `BindingAnnotation(ByRef::No, Mutability::Mut)` * Associated constants added for convenience `BindingAnnotation::{NONE, REF, MUT, REF_MUT}` One goal is to make it more clear that `BindingAnnotation` merely represents syntax `ref mut` and not the actual binding mode. This was especially confusing since we had `ast::BindingMode`->`hir::BindingAnnotation`->`thir::BindingMode`. I wish there were more symmetry between `ByRef` and `Mutability` (variant) naming (maybe `Mutable::Yes`?), and I also don't love how long the name `BindingAnnotation` is, but this seems like the best compromise. Ideas welcome.
This commit is contained in:
commit
6c358c67d4
61 changed files with 278 additions and 333 deletions
|
@ -259,17 +259,8 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
|
|||
== Some(cx.tcx.field_index(fieldpat.hir_id, cx.typeck_results()))
|
||||
{
|
||||
cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, |lint| {
|
||||
let binding = match binding_annot {
|
||||
hir::BindingAnnotation::Unannotated => None,
|
||||
hir::BindingAnnotation::Mutable => Some("mut"),
|
||||
hir::BindingAnnotation::Ref => Some("ref"),
|
||||
hir::BindingAnnotation::RefMut => Some("ref mut"),
|
||||
};
|
||||
let suggested_ident = if let Some(binding) = binding {
|
||||
format!("{} {}", binding, ident)
|
||||
} else {
|
||||
ident.to_string()
|
||||
};
|
||||
let suggested_ident =
|
||||
format!("{}{}", binding_annot.prefix_str(), ident);
|
||||
lint.build(fluent::lint::builtin_non_shorthand_field_patterns)
|
||||
.set_arg("ident", ident.clone())
|
||||
.span_suggestion(
|
||||
|
|
|
@ -751,7 +751,7 @@ impl UnusedParens {
|
|||
avoid_or: bool,
|
||||
avoid_mut: bool,
|
||||
) {
|
||||
use ast::{BindingMode, Mutability, PatKind};
|
||||
use ast::{BindingAnnotation, PatKind};
|
||||
|
||||
if let PatKind::Paren(inner) = &value.kind {
|
||||
match inner.kind {
|
||||
|
@ -763,7 +763,9 @@ impl UnusedParens {
|
|||
// Avoid `p0 | .. | pn` if we should.
|
||||
PatKind::Or(..) if avoid_or => return,
|
||||
// Avoid `mut x` and `mut x @ p` if we should:
|
||||
PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..) if avoid_mut => return,
|
||||
PatKind::Ident(BindingAnnotation::MUT, ..) if avoid_mut => {
|
||||
return;
|
||||
}
|
||||
// Otherwise proceed with linting.
|
||||
_ => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue