mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 17:07:17 +00:00
rustfmt round n
This commit is contained in:
parent
4a4e1ea2c5
commit
44533f09aa
10 changed files with 59 additions and 58 deletions
|
@ -85,7 +85,9 @@ fn check_known_consts(cx: &LateContext, e: &Expr, s: &symbol::Symbol, module: &s
|
|||
APPROX_CONSTANT,
|
||||
e.span,
|
||||
&format!("approximate value of `{}::consts::{}` found. \
|
||||
Consider using it directly", module, &name));
|
||||
Consider using it directly",
|
||||
module,
|
||||
&name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -473,10 +473,10 @@ fn check_for_loop_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, ar
|
|||
expr.span,
|
||||
&format!("the loop variable `{}` is used to index `{}`", ident.node, indexed),
|
||||
|db| {
|
||||
multispan_sugg(db, "consider using an iterator".to_string(), &[
|
||||
(pat.span, &format!("({}, <item>)", ident.node)),
|
||||
(arg.span, &format!("{}.iter().enumerate(){}{}", indexed, take, skip)),
|
||||
]);
|
||||
multispan_sugg(db,
|
||||
"consider using an iterator".to_string(),
|
||||
&[(pat.span, &format!("({}, <item>)", ident.node)),
|
||||
(arg.span, &format!("{}.iter().enumerate(){}{}", indexed, take, skip))]);
|
||||
});
|
||||
} else {
|
||||
let repl = if starts_at_zero && take.is_empty() {
|
||||
|
@ -488,13 +488,14 @@ fn check_for_loop_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, ar
|
|||
span_lint_and_then(cx,
|
||||
NEEDLESS_RANGE_LOOP,
|
||||
expr.span,
|
||||
&format!("the loop variable `{}` is only used to index `{}`.", ident.node, indexed),
|
||||
&format!("the loop variable `{}` is only used to index `{}`.",
|
||||
ident.node,
|
||||
indexed),
|
||||
|db| {
|
||||
multispan_sugg(db, "consider using an iterator".to_string(), &[
|
||||
(pat.span, "<item>"),
|
||||
(arg.span, &repl),
|
||||
]);
|
||||
});
|
||||
multispan_sugg(db,
|
||||
"consider using an iterator".to_string(),
|
||||
&[(pat.span, "<item>"), (arg.span, &repl)]);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -551,9 +552,9 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
|
|||
"consider using the following if you are attempting to iterate over this \
|
||||
range in reverse",
|
||||
format!("({end}{dots}{start}).rev()",
|
||||
end=end_snippet,
|
||||
dots=dots,
|
||||
start=start_snippet));
|
||||
end = end_snippet,
|
||||
dots = dots,
|
||||
start = start_snippet));
|
||||
});
|
||||
} else if eq && limits != ast::RangeLimits::Closed {
|
||||
// if they are equal, it's also problematic - this loop
|
||||
|
@ -597,9 +598,9 @@ fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) {
|
|||
EXPLICIT_INTO_ITER_LOOP,
|
||||
expr.span,
|
||||
&format!("it is more idiomatic to loop over `{}` instead of `{}.{}()`",
|
||||
object,
|
||||
object,
|
||||
method_name));
|
||||
object,
|
||||
object,
|
||||
method_name));
|
||||
|
||||
} else if &*method_name.as_str() == "next" && match_trait_method(cx, arg, &paths::ITERATOR) {
|
||||
span_lint(cx,
|
||||
|
|
|
@ -776,10 +776,10 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
|
|||
span,
|
||||
&format!("use of `{}` followed by a function call", name),
|
||||
|db| {
|
||||
db.span_suggestion(span,
|
||||
db.span_suggestion(span,
|
||||
"try this",
|
||||
format!("{}.{}_{}({})", snippet(cx, self_expr.span, "_"), name, suffix, sugg));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if args.len() == 2 {
|
||||
|
@ -836,10 +836,10 @@ fn lint_vec_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
|
|||
expr.span,
|
||||
"use of `extend` to extend a Vec by a slice",
|
||||
|db| {
|
||||
db.span_suggestion(expr.span,
|
||||
db.span_suggestion(expr.span,
|
||||
"try this",
|
||||
format!("{}.extend_from_slice({})", snippet(cx, args[0].span, "_"), slice));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,12 @@ pub struct Pass;
|
|||
|
||||
impl LintPass for Pass {
|
||||
fn get_lints(&self) -> LintArray {
|
||||
lint_array!(TOPLEVEL_REF_ARG, CMP_NAN, FLOAT_CMP, CMP_OWNED, MODULO_ONE, REDUNDANT_PATTERN,
|
||||
lint_array!(TOPLEVEL_REF_ARG,
|
||||
CMP_NAN,
|
||||
FLOAT_CMP,
|
||||
CMP_OWNED,
|
||||
MODULO_ONE,
|
||||
REDUNDANT_PATTERN,
|
||||
USED_UNDERSCORE_BINDING)
|
||||
}
|
||||
}
|
||||
|
@ -285,7 +290,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
USED_UNDERSCORE_BINDING,
|
||||
expr.span,
|
||||
&format!("used binding `{}` which is prefixed with an underscore. A leading \
|
||||
underscore signals that a binding will not be used.", binding));
|
||||
underscore signals that a binding will not be used.",
|
||||
binding));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,9 +301,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
span_lint(cx,
|
||||
REDUNDANT_PATTERN,
|
||||
pat.span,
|
||||
&format!("the `{} @ _` pattern can be written as just `{}`",
|
||||
ident.node,
|
||||
ident.node));
|
||||
&format!("the `{} @ _` pattern can be written as just `{}`", ident.node, ident.node));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -210,8 +210,8 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
|
|||
diag.span_help(span,
|
||||
&format!("separate the discriminating character by an \
|
||||
underscore like: `{}_{}`",
|
||||
&interned_name[..split],
|
||||
&interned_name[split..]));
|
||||
&interned_name[..split],
|
||||
&interned_name[split..]));
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
|
|
@ -219,8 +219,7 @@ fn check_regex(cx: &LateContext, expr: &Expr, utf8: bool) {
|
|||
span_lint(cx,
|
||||
INVALID_REGEX,
|
||||
str_span(expr.span, r, e.position()),
|
||||
&format!("regex syntax error: {}",
|
||||
e.description()));
|
||||
&format!("regex syntax error: {}", e.description()));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -239,9 +238,7 @@ fn check_regex(cx: &LateContext, expr: &Expr, utf8: bool) {
|
|||
span_lint(cx,
|
||||
INVALID_REGEX,
|
||||
expr.span,
|
||||
&format!("regex syntax error on position {}: {}",
|
||||
e.position(),
|
||||
e.description()));
|
||||
&format!("regex syntax error on position {}: {}", e.position(), e.description()));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,25 +144,26 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||
CROSSPOINTER_TRANSMUTE,
|
||||
e.span,
|
||||
&format!("transmute from a type (`{}`) to the type that it points to (`{}`)",
|
||||
from_ty,
|
||||
to_ty))
|
||||
from_ty,
|
||||
to_ty))
|
||||
},
|
||||
(_, &TyRawPtr(to_ptr)) if to_ptr.ty == from_ty => {
|
||||
span_lint(cx,
|
||||
CROSSPOINTER_TRANSMUTE,
|
||||
e.span,
|
||||
&format!("transmute from a type (`{}`) to a pointer to that type (`{}`)",
|
||||
from_ty,
|
||||
to_ty))
|
||||
from_ty,
|
||||
to_ty))
|
||||
},
|
||||
(&TyRawPtr(from_pty), &TyRef(_, to_rty)) => span_lint_and_then(
|
||||
cx,
|
||||
TRANSMUTE_PTR_TO_REF,
|
||||
e.span,
|
||||
&format!("transmute from a pointer type (`{}`) to a reference type (`{}`)",
|
||||
from_ty,
|
||||
to_ty),
|
||||
|db| {
|
||||
(&TyRawPtr(from_pty), &TyRef(_, to_rty)) => {
|
||||
span_lint_and_then(cx,
|
||||
TRANSMUTE_PTR_TO_REF,
|
||||
e.span,
|
||||
&format!("transmute from a pointer type (`{}`) to a reference type \
|
||||
(`{}`)",
|
||||
from_ty,
|
||||
to_ty),
|
||||
|db| {
|
||||
let arg = sugg::Sugg::hir(cx, &args[0], "..");
|
||||
let (deref, cast) = if to_rty.mutbl == Mutability::MutMutable {
|
||||
("&mut *", "*mut")
|
||||
|
@ -177,8 +178,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||
};
|
||||
|
||||
db.span_suggestion(e.span, "try", sugg::make_unop(deref, arg).to_string());
|
||||
},
|
||||
),
|
||||
})
|
||||
},
|
||||
_ => return,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -352,11 +352,7 @@ fn span_precision_loss_lint(cx: &LateContext, expr: &Expr, cast_from: &ty::TyS,
|
|||
&format!("casting {0} to {1} causes a loss of precision {2}({0} is {3} bits wide, but {1}'s mantissa \
|
||||
is only {4} bits wide)",
|
||||
cast_from,
|
||||
if cast_to_f64 {
|
||||
"f64"
|
||||
} else {
|
||||
"f32"
|
||||
},
|
||||
if cast_to_f64 { "f64" } else { "f32" },
|
||||
if arch_dependent {
|
||||
arch_dependent_str
|
||||
} else {
|
||||
|
@ -687,9 +683,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 {
|
|||
let msg = "casting character literal to u8. `char`s \
|
||||
are 4 bytes wide in rust, so casting to u8 \
|
||||
truncates them";
|
||||
let help = format!("Consider using a byte literal \
|
||||
instead:\nb{}",
|
||||
snippet(cx, e.span, "'x'"));
|
||||
let help = format!("Consider using a byte literal instead:\nb{}", snippet(cx, e.span, "'x'"));
|
||||
span_help_and_lint(cx, CHAR_LIT_AS_U8, expr.span, msg, &help);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -500,7 +500,7 @@ impl<'a> DiagnosticWrapper<'a> {
|
|||
fn wiki_link(&mut self, lint: &'static Lint) {
|
||||
if env::var("CLIPPY_DISABLE_WIKI_LINKS").is_err() {
|
||||
self.0.help(&format!("for further information visit https://github.com/Manishearth/rust-clippy/wiki#{}",
|
||||
lint.name_lower()));
|
||||
lint.name_lower()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -780,7 +780,8 @@ pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>, env: Node
|
|||
/// Return whether a pattern is refutable.
|
||||
pub fn is_refutable(cx: &LateContext, pat: &Pat) -> bool {
|
||||
fn is_enum_variant(cx: &LateContext, qpath: &QPath, did: NodeId) -> bool {
|
||||
matches!(cx.tcx.tables().qpath_def(qpath, did), def::Def::Variant(..) | def::Def::VariantCtor(..))
|
||||
matches!(cx.tcx.tables().qpath_def(qpath, did),
|
||||
def::Def::Variant(..) | def::Def::VariantCtor(..))
|
||||
}
|
||||
|
||||
fn are_refutable<'a, I: Iterator<Item = &'a Pat>>(cx: &LateContext, mut i: I) -> bool {
|
||||
|
|
|
@ -249,7 +249,8 @@ pub fn make_assoc(op: AssocOp, lhs: &Sugg, rhs: &Sugg) -> Sugg<'static> {
|
|||
|
||||
/// Whether the operator is a arithmetic operator (`+`, `-`, `*`, `/`, `%`).
|
||||
fn is_arith(op: &AssocOp) -> bool {
|
||||
matches!(*op, AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide | AssocOp::Modulus)
|
||||
matches!(*op,
|
||||
AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide | AssocOp::Modulus)
|
||||
}
|
||||
|
||||
/// Whether the operator `op` needs parenthesis with the operator `other` in the direction
|
||||
|
|
Loading…
Reference in a new issue