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));
}
}
}
if let MetaWord(ref always) = values[0].node {
if always != &"always" { continue; }
span_lint(cx, INLINE_ALWAYS, attr.span, &format!(
- "You have declared #[inline(always)] on {}. This \
+ "you have declared `#[inline(always)]` on `{}`. This \
is usually a bad idea. Are you sure?",
ident.name.as_str()));
}
BiBitAnd => if mask_value & cmp_value != mask_value {
if cmp_value != 0 {
span_lint(cx, BAD_BIT_MASK, *span, &format!(
- "incompatible bit mask: _ & {} can never be equal to {}",
+ "incompatible bit mask: `_ & {}` can never be equal to `{}`",
mask_value, cmp_value));
}
} else {
},
BiBitOr => if mask_value | cmp_value != cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!(
- "incompatible bit mask: _ | {} can never be equal to {}",
+ "incompatible bit mask: `_ | {}` can never be equal to `{}`",
mask_value, cmp_value));
},
_ => ()
BiLt | BiGe => match bit_op {
BiBitAnd => if mask_value < cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!(
- "incompatible bit mask: _ & {} will always be lower than {}",
+ "incompatible bit mask: `_ & {}` will always be lower than `{}`",
mask_value, cmp_value));
} else {
if mask_value == 0 {
},
BiBitOr => if mask_value >= cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!(
- "incompatible bit mask: _ | {} will never be lower than {}",
+ "incompatible bit mask: `_ | {}` will never be lower than `{}`",
mask_value, cmp_value));
} else {
if mask_value < cmp_value {
span_lint(cx, INEFFECTIVE_BIT_MASK, *span, &format!(
- "ineffective bit mask: x | {} compared to {} is the same as x compared directly",
+ "ineffective bit mask: `x | {}` compared to `{}` is the same as x compared directly",
mask_value, cmp_value));
}
},
BiLe | BiGt => match bit_op {
BiBitAnd => if mask_value <= cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!(
- "incompatible bit mask: _ & {} will never be higher than {}",
+ "incompatible bit mask: `_ & {}` will never be higher than `{}`",
mask_value, cmp_value));
} else {
if mask_value == 0 {
},
BiBitOr => if mask_value > cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!(
- "incompatible bit mask: _ | {} will always be higher than {}",
+ "incompatible bit mask: `_ | {}` will always be higher than `{}`",
mask_value, cmp_value));
} else {
if mask_value < cmp_value {
span_lint(cx, INEFFECTIVE_BIT_MASK, *span, &format!(
- "ineffective bit mask: x | {} compared to {} is the same as x compared directly",
+ "ineffective bit mask: `x | {}` compared to `{}` is the same as x compared directly",
mask_value, cmp_value));
}
},
if let Some(&Expr{ node: ExprIf(ref check_inner, _, None), ..}) =
single_stmt_of_block(then) {
span_lint(cx, COLLAPSIBLE_IF, e.span, &format!(
- "This if statement can be collapsed. Try: if {} && {}\n{:?}",
+ "this if statement can be collapsed. Try: `if {} && {}`\n{:?}",
check_to_string(check), check_to_string(check_inner), e));
}
}
}
}
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, "..")));
}
}
for i in trait_items {
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.",
+ &format!("trait `{}` has a `.len(_: &Self)` method, but no \
+ `.is_empty(_: &Self)` method. Consider adding one.",
item.ident.name));
}
};
let s = i.span;
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.",
+ &format!("item `{}` has a `.len(_: &Self)` method, but no \
+ `.is_empty(_: &Self)` method. Consider adding one.",
item.ident.name));
return;
}
if method.node.name == "len" && args.len() == 1 &&
has_is_empty(cx, &*args[0]) {
span_lint(cx, LEN_ZERO, span, &format!(
- "Consider replacing the len comparison with '{}_.is_empty()'",
+ "consider replacing the len comparison with `{}_.is_empty()`",
empty))
}
}
format!("{{ {} }}", body_code)
};
span_help_and_lint(cx, SINGLE_MATCH, expr.span,
- "You seem to be trying to use match for \
+ "you seem to be trying to use match for \
destructuring a single pattern. Did you mean to \
use `if let`?",
- &*format!("Try\nif let {} = {} {}",
+ &*format!("try\nif let {} = {} {}",
snippet(cx, arms[0].pats[0].span, ".."),
snippet(cx, ex.span, ".."),
suggestion)
ast::ExprMethodCall(ref method, _, ref args)
if method.node.name == "to_string"
&& is_str(cx, &*args[0]) => {
- span_lint(cx, STR_TO_STRING, expr.span, "str.to_owned() is faster");
+ span_lint(cx, STR_TO_STRING, expr.span, "`str.to_owned()` is faster");
},
_ => ()
}
span_lint(cx,
TOPLEVEL_REF_ARG,
arg.pat.span,
- "`ref` directly on a function argument is ignored. Have you considered using a reference type instead?"
+ "`ref` directly on a function argument is ignored. Consider using a reference type instead."
);
}
}
fn check_nan(cx: &Context, path: &Path, span: Span) {
path.segments.last().map(|seg| if seg.identifier.name == "NAN" {
span_lint(cx, CMP_NAN, span,
- "Doomed comparison with NAN, use std::{f32,f64}::is_nan instead");
+ "doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead");
});
}
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. You may want to change 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, "..")))
}
}
if let ExprBinary(ref cmp, _, ref right) = expr.node {
if let &Spanned {node: BinOp_::BiRem, ..} = cmp {
if is_lit_one(right) {
- cx.span_lint(MODULO_ONE, expr.span, "Any number modulo 1 will be 0");
+ cx.span_lint(MODULO_ONE, expr.span, "any number modulo 1 will be 0");
}
}
}
fn check_ty(&mut self, cx: &Context, ty: &Ty) {
unwrap_mut(ty).and_then(unwrap_mut).map_or((), |_| span_lint(cx, MUT_MUT,
- ty.span, "Generally you want to avoid &mut &mut _ if possible."))
+ ty.span, "generally you want to avoid `&mut &mut _` if possible"))
}
}
unwrap_addr(expr).map_or((), |e| {
unwrap_addr(e).map(|_| {
span_lint(cx, MUT_MUT, expr.span,
- "Generally you want to avoid &mut &mut _ if possible.")
+ "generally you want to avoid `&mut &mut _` if possible")
}).unwrap_or_else(|| {
if let TyRef(_, TypeAndMut{ty: _, mutbl: MutMutable}) =
cx.tcx.expr_ty(e).sty {
span_lint(cx, MUT_MUT, expr.span,
- "This expression mutably borrows a mutable reference. \
- Consider reborrowing")
+ "this expression mutably borrows a mutable reference. \
+ Consider reborrowing.")
}
})
})
"your if-then-else expression will always return true"); },
(Option::Some(true), Option::Some(false)) => {
span_lint(cx, NEEDLESS_BOOL, e.span,
- "you can reduce your if-statement to its predicate"); },
+ "you can reduce your if statement to its predicate"); },
(Option::Some(false), Option::Some(true)) => {
span_lint(cx, NEEDLESS_BOOL, e.span,
- "you can reduce your if-statement to '!' + your predicate"); },
+ "you can reduce your if statement to `!` + your predicate"); },
(Option::Some(false), Option::Some(false)) => {
span_lint(cx, NEEDLESS_BOOL, e.span,
"your if-then-else expression will always return false"); },
match_ty_unwrap(ty, &["Vec"]).map_or_else(|| match_ty_unwrap(ty,
&["String"]).map_or((), |_| {
span_lint(cx, PTR_ARG, span,
- "Writing '&String' instead of '&str' involves a new Object \
- where a slices will do. Consider changing the type to &str")
+ "writing `&String` instead of `&str` involves a new object \
+ 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 &[...]"))
+ "writing `&Vec<_>` instead of \
+ `&[_]` involves one more reference and cannot be used with \
+ non-Vec-based slices. Consider changing the type to `&[...]`."))
}
fn emit_return_lint(&mut self, cx: &Context, spans: (Span, Span)) {
span_lint(cx, NEEDLESS_RETURN, spans.0, &format!(
- "unneeded return statement. Consider using {} \
+ "unneeded return statement. Consider using `{}` \
without the trailing semicolon",
snippet(cx, spans.1, "..")))
}
if let &ExprAssign(ref target, ref src) = &e.node {
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.")
+ "you assign the result of adding something to this string. \
+ Consider using `String::push_str()` instead.")
}
}
}
-
-
use syntax::ptr::P;
use syntax::ast;
use syntax::ast::*;
.and_then(|t| match_ty_unwrap(&**t, &["std", "vec", "Vec"]))
.map(|_| {
span_help_and_lint(cx, BOX_VEC, ty.span,
- "You seem to be trying to use Box<Vec<T>>. Did you mean to use Vec<T>?",
- "Vec<T> is already on the heap, Box<Vec<T>> makes an extra allocation");
+ "you seem to be trying to use `Box<Vec<T>>`. Did you mean to use `Vec<T>`?",
+ "`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation");
});
{
// In case stuff gets moved around
if match_ty_unwrap(ty, &path[..]).is_some() {
span_help_and_lint(cx, LINKEDLIST, ty.span,
"I see you're using a LinkedList! Perhaps you meant some other data structure?",
- "A RingBuf might work.");
+ "a RingBuf might work");
return;
}
}
lo: span.lo + BytePos(index as u32),
hi: span.lo + BytePos(index as u32),
expn_id: span.expn_id,
- }, "Zero-width space detected. Consider using \\u{200B}")
+ }, "zero-width space detected. Consider using `\\u{200B}`.")
});
}
#![deny(inline_always)]
-#[inline(always)] //~ERROR You have declared #[inline(always)] on test_attr_lint.
+#[inline(always)] //~ERROR you have declared `#[inline(always)]` on `test_attr_lint`.
fn test_attr_lint() {
assert!(true)
}
#![plugin(clippy)]
#![deny(clippy)]
-pub fn test(foo: Box<Vec<bool>>) { //~ ERROR You seem to be trying to use Box<Vec<T>>
+pub fn test(foo: Box<Vec<bool>>) { //~ ERROR you seem to be trying to use `Box<Vec<T>>`
println!("{:?}", foo.get(0))
}
fn main() {
let x = "hello";
let y = "world";
- if x == "hello" { //~ERROR This if statement can be collapsed
+ if x == "hello" { //~ERROR this if statement can be collapsed
if y == "world" {
println!("Hello world!");
}
}
- if x == "hello" || x == "world" { //~ERROR This if statement can be collapsed
+ if x == "hello" || x == "world" { //~ERROR this if statement can be collapsed
if y == "world" || y == "hello" {
println!("Hello world!");
}
fn main() {
let a = |a, b| foo(a, b);
- //~^ ERROR Redundant closure found, consider using `foo` in its place
+ //~^ ERROR redundant closure found. Consider using `foo` in its place
let c = |a, b| {1+2; foo}(a, b);
- //~^ ERROR Redundant closure found, consider using `{ 1 + 2; foo }` in its place
+ //~^ ERROR redundant closure found. Consider using `{ 1 + 2; foo }` in its place
let d = |a, b| foo((|c, d| foo2(c,d))(a,b), b);
- //~^ ERROR Redundant closure found, consider using `foo2` in its place
+ //~^ ERROR redundant closure found. Consider using `foo2` in its place
}
fn foo(_: u8, _: u8) {
fn foo2(_: u8, _: u8) -> u8 {
1u8
-}
\ No newline at end of file
+}
#[deny(len_without_is_empty)]
impl One {
- fn len(self: &Self) -> isize { //~ERROR Item 'One' has a '.len(_: &Self)'
+ fn len(self: &Self) -> isize { //~ERROR item `One` has a `.len(_: &Self)`
1
}
}
#[deny(len_without_is_empty)]
trait TraitsToo {
- fn len(self: &Self) -> isize; //~ERROR Trait 'TraitsToo' has a '.len(_:
+ fn len(self: &Self) -> isize; //~ERROR trait `TraitsToo` has a `.len(_:
}
impl TraitsToo for One {
#[deny(len_without_is_empty)]
impl HasWrongIsEmpty {
- fn len(self: &Self) -> isize { //~ERROR Item 'HasWrongIsEmpty' has a '.len(_: &Self)'
+ fn len(self: &Self) -> isize { //~ERROR item `HasWrongIsEmpty` has a `.len(_: &Self)`
1
}
#[deny(len_zero)]
fn main() {
let x = [1, 2];
- if x.len() == 0 { //~ERROR Consider replacing the len comparison
+ if x.len() == 0 { //~ERROR consider replacing the len comparison
println!("This should not happen!");
}
}
let hie = HasIsEmpty;
- if hie.len() == 0 { //~ERROR Consider replacing the len comparison
+ if hie.len() == 0 { //~ERROR consider replacing the len comparison
println!("Or this!");
}
assert!(!hie.is_empty());
let wie : &WithIsEmpty = &Wither;
- if wie.len() == 0 { //~ERROR Consider replacing the len comparison
+ if wie.len() == 0 { //~ERROR consider replacing the len comparison
println!("Or this!");
}
assert!(!wie.is_empty());
fn main(){
let x = Some(1u8);
- match x { //~ ERROR You seem to be trying to use match
- //~^ HELP Try
+ match x { //~ ERROR you seem to be trying to use match
+ //~^ HELP try
Some(y) => {
println!("{:?}", y);
}
None => ()
}
let z = (1u8,1u8);
- match z { //~ ERROR You seem to be trying to use match
- //~^ HELP Try
+ match z { //~ ERROR you seem to be trying to use match
+ //~^ HELP try
(2...3, 7...9) => println!("{:?}", z),
_ => {}
}
#![deny(modulo_one)]
fn main() {
- 10 % 1; //~ERROR Any number modulo 1 will be 0
+ 10 % 1; //~ERROR any number modulo 1 will be 0
10 % 2;
}
#[deny(ptr_arg)]
#[allow(unused)]
-fn do_vec(x: &Vec<i64>) { //~ERROR: Writing '&Vec<_>' instead of '&[_]'
+fn do_vec(x: &Vec<i64>) { //~ERROR: writing `&Vec<_>` instead of `&[_]`
//Nothing here
}
#[deny(zero_width_space)]
fn zero() {
print!("Here >< is a ZWS, and another");
- //~^ ERROR Zero-width space detected. Consider using \u{200B}
- //~^^ ERROR Zero-width space detected. Consider using \u{200B}
+ //~^ ERROR zero-width space detected. Consider using `\u{200B}`
+ //~^^ ERROR zero-width space detected. Consider using `\u{200B}`
}
//#[deny(unicode_canon)]
fn canon() {
- print!("̀ah?"); //not yet ~ERROR Non-canonical unicode sequence detected. Consider using à
+ print!("̀ah?"); //not yet ~ERROR non-canonical unicode sequence detected. Consider using à
}
//#[deny(ascii_only)]