for &(constant, name) in KNOWN_CONSTS {
if within_epsilon(constant, value) {
span_lint(cx, APPROX_CONSTANT, span, &format!(
- "approximate value of `{}::{}` found. Consider using it directly.", module, &name));
+ "approximate value of `{}::{}` found. Consider using it directly", module, &name));
}
}
}
}
}
span_lint(cx, REDUNDANT_CLOSURE, expr.span,
- &format!("redundant closure found. Consider using `{}` in its place.",
+ &format!("redundant closure found. Consider using `{}` in its place",
expr_to_string(caller))[..])
}
}
fn check(cx: &Context, e: &Expr, m: i8, span: Span, arg: Span) {
if have_lit(cx, e, m) {
span_lint(cx, IDENTITY_OP, span, &format!(
- "the operation is ineffective. Consider reducing it to `{}`.",
+ "the operation is ineffective. Consider reducing it to `{}`",
snippet(cx, arg, "..")));
}
}
if is_named_self(i, "len") {
span_lint(cx, LEN_WITHOUT_IS_EMPTY, i.span,
&format!("trait `{}` has a `.len(_: &Self)` method, but no \
- `.is_empty(_: &Self)` method. Consider adding one.",
+ `.is_empty(_: &Self)` method. Consider adding one",
item.ident.name));
}
};
span_lint(cx, LEN_WITHOUT_IS_EMPTY,
Span{ lo: s.lo, hi: s.lo, expn_id: s.expn_id },
&format!("item `{}` has a `.len(_: &Self)` method, but no \
- `.is_empty(_: &Self)` method. Consider adding one.",
+ `.is_empty(_: &Self)` method. Consider adding one",
item.ident.name));
return;
}
span_lint(cx, OPTION_UNWRAP_USED, expr.span,
"used unwrap() on an Option value. If you don't want \
to handle the None case gracefully, consider using
- expect() to provide a better panic message.");
+ expect() to provide a better panic message");
}
else if match_def_path(cx, did.did, &["core", "result", "Result"]) {
span_lint(cx, RESULT_UNWRAP_USED, expr.span,
"used unwrap() on a Result value. Graceful handling \
- of Err values is preferred.");
+ of Err values is preferred");
}
}
}
let op = cmp.node;
if (op == BiEq || op == BiNe) && (is_float(cx, left) || is_float(cx, right)) {
span_lint(cx, FLOAT_CMP, expr.span, &format!(
- "{}-comparison of f32 or f64 detected. Consider changing this to `abs({} - {}) < epsilon` for some suitable value of epsilon.",
+ "{}-comparison of f32 or f64 detected. Consider changing this to \
+ `abs({} - {}) < epsilon` for some suitable value of epsilon",
binop_to_string(op), snippet(cx, left.span, ".."),
snippet(cx, right.span, "..")));
}
if let ExprBinary(Spanned { node: op, ..}, ref left, ref right) = expr.node {
if is_bit_op(op) && (is_arith_expr(left) || is_arith_expr(right)) {
span_lint(cx, PRECEDENCE, expr.span,
- "operator precedence can trip the unwary. Consider adding parenthesis to the subexpression.");
+ "operator precedence can trip the unwary. Consider adding parenthesis \
+ to the subexpression");
}
}
}
name == "to_owned" && is_str_arg(cx, args) {
span_lint(cx, CMP_OWNED, expr.span, &format!(
"this creates an owned instance just for comparison. \
- Consider using `{}.as_slice()` to compare without allocation.",
+ Consider using `{}.as_slice()` to compare without allocation",
snippet(cx, other_span, "..")))
}
},
match_path(path, &["String", "from"]) {
span_lint(cx, CMP_OWNED, expr.span, &format!(
"this creates an owned instance just for comparison. \
- Consider using `{}.as_slice()` to compare without allocation.",
+ Consider using `{}.as_slice()` to compare without allocation",
snippet(cx, other_span, "..")))
}
}
cx.tcx.expr_ty(e).sty {
span_lint(cx, MUT_MUT, expr.span,
"this expression mutably borrows a mutable reference. \
- Consider reborrowing.")
+ Consider reborrowing")
}
})
})
&["String"]).map_or((), |_| {
span_lint(cx, PTR_ARG, span,
"writing `&String` instead of `&str` involves a new object \
- where a slice will do. Consider changing the type to `&str`.")
+ where a slice will do. Consider changing the type to `&str`")
}), |_| span_lint(cx, PTR_ARG, span,
"writing `&Vec<_>` instead of \
`&[_]` involves one more reference and cannot be used with \
- non-Vec-based slices. Consider changing the type to `&[...]`."))
+ non-Vec-based slices. Consider changing the type to `&[...]`"))
}
if is_string(cx, target) && is_add(src, target) {
span_lint(cx, STRING_ADD_ASSIGN, e.span,
"you assign the result of adding something to this string. \
- Consider using `String::push_str()` instead.")
+ Consider using `String::push_str()` instead")
}
}
}
let bindtype = &cx.tcx.pat_ty(&*local.pat).sty;
if *bindtype == ty::TyTuple(vec![]) {
span_lint(cx, LET_UNIT_VALUE, decl.span, &format!(
- "this let-binding has unit value. Consider omitting `let {} =`.",
+ "this let-binding has unit value. Consider omitting `let {} =`",
snippet(cx, local.pat.span, "..")));
}
}
for (i, c) in string.char_indices() {
if c == '\u{200B}' {
str_pos_lint(cx, ZERO_WIDTH_SPACE, span, i,
- "zero-width space detected. Consider using `\\u{200B}`.");
+ "zero-width space detected. Consider using `\\u{200B}`");
}
if c as u32 > 0x7F {
str_pos_lint(cx, NON_ASCII_LITERAL, span, i, &format!(
- "literal non-ASCII character detected. Consider using `\\u{{{:X}}}`.", c as u32));
+ "literal non-ASCII character detected. Consider using `\\u{{{:X}}}`", c as u32));
}
}
}