Refactor and re-use BindingAnnotation
This commit is contained in:
parent
9353538c7b
commit
02ba216e3c
25 changed files with 176 additions and 225 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