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,12 +488,13 @@ 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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,11 +155,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||
from_ty,
|
||||
to_ty))
|
||||
},
|
||||
(&TyRawPtr(from_pty), &TyRef(_, to_rty)) => span_lint_and_then(
|
||||
cx,
|
||||
(&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 (`{}`)",
|
||||
&format!("transmute from a pointer type (`{}`) to a reference type \
|
||||
(`{}`)",
|
||||
from_ty,
|
||||
to_ty),
|
||||
|db| {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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