Merge pull request #135 from birkenfeld/consistent_msgs

all: make style of lint messages consistent
This commit is contained in:
Manish Goregaokar 2015-08-12 14:47:24 +05:30
commit 640c3ff8aa
24 changed files with 69 additions and 71 deletions

View file

@ -53,7 +53,7 @@ fn check_known_consts(cx: &Context, span: Span, str: &str, module: &str) {
for &(constant, name) in KNOWN_CONSTS { for &(constant, name) in KNOWN_CONSTS {
if within_epsilon(constant, value) { if within_epsilon(constant, value) {
span_lint(cx, APPROX_CONSTANT, span, &format!( 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));
} }
} }
} }

View file

@ -101,7 +101,7 @@ fn check_attrs(cx: &Context, info: Option<&ExpnInfo>, ident: &Ident,
if let MetaWord(ref always) = values[0].node { if let MetaWord(ref always) = values[0].node {
if always != &"always" { continue; } if always != &"always" { continue; }
span_lint(cx, INLINE_ALWAYS, attr.span, &format!( 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?", is usually a bad idea. Are you sure?",
ident.name.as_str())); ident.name.as_str()));
} }

View file

@ -97,7 +97,7 @@ fn check_bit_mask(cx: &Context, bit_op: BinOp_, cmp_op: BinOp_,
BiBitAnd => if mask_value & cmp_value != mask_value { BiBitAnd => if mask_value & cmp_value != mask_value {
if cmp_value != 0 { if cmp_value != 0 {
span_lint(cx, BAD_BIT_MASK, *span, &format!( 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)); mask_value, cmp_value));
} }
} else { } else {
@ -108,7 +108,7 @@ fn check_bit_mask(cx: &Context, bit_op: BinOp_, cmp_op: BinOp_,
}, },
BiBitOr => if mask_value | cmp_value != cmp_value { BiBitOr => if mask_value | cmp_value != cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!( 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)); mask_value, cmp_value));
}, },
_ => () _ => ()
@ -116,7 +116,7 @@ fn check_bit_mask(cx: &Context, bit_op: BinOp_, cmp_op: BinOp_,
BiLt | BiGe => match bit_op { BiLt | BiGe => match bit_op {
BiBitAnd => if mask_value < cmp_value { BiBitAnd => if mask_value < cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!( 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)); mask_value, cmp_value));
} else { } else {
if mask_value == 0 { if mask_value == 0 {
@ -126,12 +126,12 @@ fn check_bit_mask(cx: &Context, bit_op: BinOp_, cmp_op: BinOp_,
}, },
BiBitOr => if mask_value >= cmp_value { BiBitOr => if mask_value >= cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!( 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)); mask_value, cmp_value));
} else { } else {
if mask_value < cmp_value { if mask_value < cmp_value {
span_lint(cx, INEFFECTIVE_BIT_MASK, *span, &format!( 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)); mask_value, cmp_value));
} }
}, },
@ -140,7 +140,7 @@ fn check_bit_mask(cx: &Context, bit_op: BinOp_, cmp_op: BinOp_,
BiLe | BiGt => match bit_op { BiLe | BiGt => match bit_op {
BiBitAnd => if mask_value <= cmp_value { BiBitAnd => if mask_value <= cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!( 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)); mask_value, cmp_value));
} else { } else {
if mask_value == 0 { if mask_value == 0 {
@ -150,12 +150,12 @@ fn check_bit_mask(cx: &Context, bit_op: BinOp_, cmp_op: BinOp_,
}, },
BiBitOr => if mask_value > cmp_value { BiBitOr => if mask_value > cmp_value {
span_lint(cx, BAD_BIT_MASK, *span, &format!( 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)); mask_value, cmp_value));
} else { } else {
if mask_value < cmp_value { if mask_value < cmp_value {
span_lint(cx, INEFFECTIVE_BIT_MASK, *span, &format!( 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)); mask_value, cmp_value));
} }
}, },

View file

@ -48,7 +48,7 @@ fn check_expr_expd(cx: &Context, e: &Expr, info: Option<&ExpnInfo>) {
if let Some(&Expr{ node: ExprIf(ref check_inner, _, None), ..}) = if let Some(&Expr{ node: ExprIf(ref check_inner, _, None), ..}) =
single_stmt_of_block(then) { single_stmt_of_block(then) {
span_lint(cx, COLLAPSIBLE_IF, e.span, &format!( 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)); check_to_string(check), check_to_string(check_inner), e));
} }
} }

View file

@ -51,7 +51,7 @@ impl LintPass for EtaPass {
} }
} }
span_lint(cx, REDUNDANT_CLOSURE, expr.span, 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))[..]) expr_to_string(caller))[..])
} }
} }

View file

@ -49,7 +49,7 @@ impl LintPass for IdentityOp {
fn check(cx: &Context, e: &Expr, m: i8, span: Span, arg: Span) { fn check(cx: &Context, e: &Expr, m: i8, span: Span, arg: Span) {
if have_lit(cx, e, m) { if have_lit(cx, e, m) {
span_lint(cx, IDENTITY_OP, span, &format!( 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, ".."))); snippet(cx, arg, "..")));
} }
} }

View file

@ -58,8 +58,8 @@ fn check_trait_items(cx: &Context, item: &Item, trait_items: &[P<TraitItem>]) {
for i in trait_items { for i in trait_items {
if is_named_self(i, "len") { if is_named_self(i, "len") {
span_lint(cx, LEN_WITHOUT_IS_EMPTY, i.span, span_lint(cx, LEN_WITHOUT_IS_EMPTY, i.span,
&format!("Trait '{}' has a '.len(_: &Self)' method, but no \ &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)); item.ident.name));
} }
}; };
@ -78,8 +78,8 @@ fn check_impl_items(cx: &Context, item: &Item, impl_items: &[P<ImplItem>]) {
let s = i.span; let s = i.span;
span_lint(cx, LEN_WITHOUT_IS_EMPTY, span_lint(cx, LEN_WITHOUT_IS_EMPTY,
Span{ lo: s.lo, hi: s.lo, expn_id: s.expn_id }, Span{ lo: s.lo, hi: s.lo, expn_id: s.expn_id },
&format!("Item '{}' has a '.len(_: &Self)' method, but no \ &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)); item.ident.name));
return; return;
} }
@ -108,7 +108,7 @@ fn check_len_zero(cx: &Context, span: Span, method: &SpannedIdent,
if method.node.name == "len" && args.len() == 1 && if method.node.name == "len" && args.len() == 1 &&
has_is_empty(cx, &*args[0]) { has_is_empty(cx, &*args[0]) {
span_lint(cx, LEN_ZERO, span, &format!( span_lint(cx, LEN_ZERO, span, &format!(
"Consider replacing the len comparison with '{}_.is_empty()'", "consider replacing the len comparison with `{}_.is_empty()`",
empty)) empty))
} }
} }

View file

@ -43,10 +43,10 @@ impl LintPass for MiscPass {
format!("{{ {} }}", body_code) format!("{{ {} }}", body_code)
}; };
span_help_and_lint(cx, SINGLE_MATCH, expr.span, 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 \ destructuring a single pattern. Did you mean to \
use `if let`?", use `if let`?",
&*format!("Try\nif let {} = {} {}", &*format!("try\nif let {} = {} {}",
snippet(cx, arms[0].pats[0].span, ".."), snippet(cx, arms[0].pats[0].span, ".."),
snippet(cx, ex.span, ".."), snippet(cx, ex.span, ".."),
suggestion) suggestion)
@ -74,7 +74,7 @@ impl LintPass for StrToStringPass {
ast::ExprMethodCall(ref method, _, ref args) ast::ExprMethodCall(ref method, _, ref args)
if method.node.name == "to_string" if method.node.name == "to_string"
&& is_str(cx, &*args[0]) => { && 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");
}, },
_ => () _ => ()
} }
@ -105,7 +105,7 @@ impl LintPass for TopLevelRefPass {
span_lint(cx, span_lint(cx,
TOPLEVEL_REF_ARG, TOPLEVEL_REF_ARG,
arg.pat.span, 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."
); );
} }
} }
@ -139,7 +139,7 @@ impl LintPass for CmpNan {
fn check_nan(cx: &Context, path: &Path, span: Span) { fn check_nan(cx: &Context, path: &Path, span: Span) {
path.segments.last().map(|seg| if seg.identifier.name == "NAN" { path.segments.last().map(|seg| if seg.identifier.name == "NAN" {
span_lint(cx, CMP_NAN, span, 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");
}); });
} }
@ -159,7 +159,7 @@ impl LintPass for FloatCmp {
let op = cmp.node; let op = cmp.node;
if (op == BiEq || op == BiNe) && (is_float(cx, left) || is_float(cx, right)) { if (op == BiEq || op == BiNe) && (is_float(cx, left) || is_float(cx, right)) {
span_lint(cx, FLOAT_CMP, expr.span, &format!( 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, ".."), binop_to_string(op), snippet(cx, left.span, ".."),
snippet(cx, right.span, ".."))); snippet(cx, right.span, "..")));
} }
@ -190,7 +190,7 @@ impl LintPass for Precedence {
if let ExprBinary(Spanned { node: op, ..}, ref left, ref right) = expr.node { 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)) { if is_bit_op(op) && (is_arith_expr(left) || is_arith_expr(right)) {
span_lint(cx, PRECEDENCE, expr.span, 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.");
} }
} }
} }
@ -246,7 +246,7 @@ fn check_to_owned(cx: &Context, expr: &Expr, other_span: Span) {
name == "to_owned" && is_str_arg(cx, args) { name == "to_owned" && is_str_arg(cx, args) {
span_lint(cx, CMP_OWNED, expr.span, &format!( span_lint(cx, CMP_OWNED, expr.span, &format!(
"this creates an owned instance just for comparison. \ "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, ".."))) snippet(cx, other_span, "..")))
} }
}, },
@ -256,7 +256,7 @@ fn check_to_owned(cx: &Context, expr: &Expr, other_span: Span) {
match_path(path, &["String", "from"]) { match_path(path, &["String", "from"]) {
span_lint(cx, CMP_OWNED, expr.span, &format!( span_lint(cx, CMP_OWNED, expr.span, &format!(
"this creates an owned instance just for comparison. \ "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, ".."))) snippet(cx, other_span, "..")))
} }
} }
@ -284,7 +284,7 @@ impl LintPass for ModuloOne {
if let ExprBinary(ref cmp, _, ref right) = expr.node { if let ExprBinary(ref cmp, _, ref right) = expr.node {
if let &Spanned {node: BinOp_::BiRem, ..} = cmp { if let &Spanned {node: BinOp_::BiRem, ..} = cmp {
if is_lit_one(right) { 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");
} }
} }
} }

View file

@ -23,7 +23,7 @@ impl LintPass for MutMut {
fn check_ty(&mut self, cx: &Context, ty: &Ty) { fn check_ty(&mut self, cx: &Context, ty: &Ty) {
unwrap_mut(ty).and_then(unwrap_mut).map_or((), |_| span_lint(cx, MUT_MUT, 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"))
} }
} }
@ -40,13 +40,13 @@ fn check_expr_expd(cx: &Context, expr: &Expr, info: Option<&ExpnInfo>) {
unwrap_addr(expr).map_or((), |e| { unwrap_addr(expr).map_or((), |e| {
unwrap_addr(e).map(|_| { unwrap_addr(e).map(|_| {
span_lint(cx, MUT_MUT, expr.span, 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(|| { }).unwrap_or_else(|| {
if let TyRef(_, TypeAndMut{ty: _, mutbl: MutMutable}) = if let TyRef(_, TypeAndMut{ty: _, mutbl: MutMutable}) =
cx.tcx.expr_ty(e).sty { cx.tcx.expr_ty(e).sty {
span_lint(cx, MUT_MUT, expr.span, span_lint(cx, MUT_MUT, expr.span,
"This expression mutably borrows a mutable reference. \ "this expression mutably borrows a mutable reference. \
Consider reborrowing") Consider reborrowing.")
} }
}) })
}) })

View file

@ -34,10 +34,10 @@ impl LintPass for NeedlessBool {
"your if-then-else expression will always return true"); }, "your if-then-else expression will always return true"); },
(Option::Some(true), Option::Some(false)) => { (Option::Some(true), Option::Some(false)) => {
span_lint(cx, NEEDLESS_BOOL, e.span, 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)) => { (Option::Some(false), Option::Some(true)) => {
span_lint(cx, NEEDLESS_BOOL, e.span, 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)) => { (Option::Some(false), Option::Some(false)) => {
span_lint(cx, NEEDLESS_BOOL, e.span, span_lint(cx, NEEDLESS_BOOL, e.span,
"your if-then-else expression will always return false"); }, "your if-then-else expression will always return false"); },

View file

@ -60,10 +60,10 @@ fn check_ptr_subtype(cx: &Context, span: Span, ty: &Ty) {
match_ty_unwrap(ty, &["Vec"]).map_or_else(|| match_ty_unwrap(ty, match_ty_unwrap(ty, &["Vec"]).map_or_else(|| match_ty_unwrap(ty,
&["String"]).map_or((), |_| { &["String"]).map_or((), |_| {
span_lint(cx, PTR_ARG, span, span_lint(cx, PTR_ARG, span,
"Writing '&String' instead of '&str' involves a new Object \ "writing `&String` instead of `&str` involves a new object \
where a slices 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, }), |_| span_lint(cx, PTR_ARG, span,
"Writing '&Vec<_>' instead of \ "writing `&Vec<_>` instead of \
'&[_]' involves one more reference and cannot be used with \ `&[_]` 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 `&[...]`."))
} }

View file

@ -59,7 +59,7 @@ impl ReturnPass {
fn emit_return_lint(&mut self, cx: &Context, spans: (Span, Span)) { fn emit_return_lint(&mut self, cx: &Context, spans: (Span, Span)) {
span_lint(cx, NEEDLESS_RETURN, spans.0, &format!( span_lint(cx, NEEDLESS_RETURN, spans.0, &format!(
"unneeded return statement. Consider using {} \ "unneeded return statement. Consider using `{}` \
without the trailing semicolon", without the trailing semicolon",
snippet(cx, spans.1, ".."))) snippet(cx, spans.1, "..")))
} }

View file

@ -29,8 +29,8 @@ impl LintPass for StringAdd {
if let &ExprAssign(ref target, ref src) = &e.node { if let &ExprAssign(ref target, ref src) = &e.node {
if is_string(cx, target) && is_add(src, target) { if is_string(cx, target) && is_add(src, target) {
span_lint(cx, STRING_ADD_ASSIGN, e.span, span_lint(cx, STRING_ADD_ASSIGN, e.span,
"You assign the result of adding something to this string. \ "you assign the result of adding something to this string. \
Consider using `String::push_str(..) instead.") Consider using `String::push_str()` instead.")
} }
} }
} }

View file

@ -1,5 +1,3 @@
use syntax::ptr::P; use syntax::ptr::P;
use syntax::ast; use syntax::ast;
use syntax::ast::*; use syntax::ast::*;
@ -55,8 +53,8 @@ impl LintPass for TypePass {
.and_then(|t| match_ty_unwrap(&**t, &["std", "vec", "Vec"])) .and_then(|t| match_ty_unwrap(&**t, &["std", "vec", "Vec"]))
.map(|_| { .map(|_| {
span_help_and_lint(cx, BOX_VEC, ty.span, 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>?", "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"); "`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation");
}); });
{ {
// In case stuff gets moved around // In case stuff gets moved around
@ -71,7 +69,7 @@ impl LintPass for TypePass {
if match_ty_unwrap(ty, &path[..]).is_some() { if match_ty_unwrap(ty, &path[..]).is_some() {
span_help_and_lint(cx, LINKEDLIST, ty.span, span_help_and_lint(cx, LINKEDLIST, ty.span,
"I see you're using a LinkedList! Perhaps you meant some other data structure?", "I see you're using a LinkedList! Perhaps you meant some other data structure?",
"A RingBuf might work."); "a RingBuf might work");
return; return;
} }
} }

View file

@ -41,6 +41,6 @@ fn lint_zero_width(cx: &Context, span: Span, start: Option<usize>) {
lo: span.lo + BytePos(index as u32), lo: span.lo + BytePos(index as u32),
hi: span.lo + BytePos(index as u32), hi: span.lo + BytePos(index as u32),
expn_id: span.expn_id, expn_id: span.expn_id,
}, "Zero-width space detected. Consider using \\u{200B}") }, "zero-width space detected. Consider using `\\u{200B}`.")
}); });
} }

View file

@ -3,7 +3,7 @@
#![deny(inline_always)] #![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() { fn test_attr_lint() {
assert!(true) assert!(true)
} }

View file

@ -3,7 +3,7 @@
#![plugin(clippy)] #![plugin(clippy)]
#![deny(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)) println!("{:?}", foo.get(0))
} }

View file

@ -5,13 +5,13 @@
fn main() { fn main() {
let x = "hello"; let x = "hello";
let y = "world"; 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" { if y == "world" {
println!("Hello 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" { if y == "world" || y == "hello" {
println!("Hello world!"); println!("Hello world!");
} }

6
tests/compile-fail/eta.rs Normal file → Executable file
View file

@ -5,11 +5,11 @@
fn main() { fn main() {
let a = |a, b| foo(a, b); 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); 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); 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 foo(_: u8, _: u8) {

View file

@ -5,14 +5,14 @@ struct One;
#[deny(len_without_is_empty)] #[deny(len_without_is_empty)]
impl One { 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 1
} }
} }
#[deny(len_without_is_empty)] #[deny(len_without_is_empty)]
trait TraitsToo { 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 { impl TraitsToo for One {
@ -56,7 +56,7 @@ struct HasWrongIsEmpty;
#[deny(len_without_is_empty)] #[deny(len_without_is_empty)]
impl HasWrongIsEmpty { 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 1
} }
@ -69,7 +69,7 @@ impl HasWrongIsEmpty {
#[deny(len_zero)] #[deny(len_zero)]
fn main() { fn main() {
let x = [1, 2]; 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!"); println!("This should not happen!");
} }
@ -84,13 +84,13 @@ fn main() {
} }
let hie = HasIsEmpty; 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!"); println!("Or this!");
} }
assert!(!hie.is_empty()); assert!(!hie.is_empty());
let wie : &WithIsEmpty = &Wither; 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!"); println!("Or this!");
} }
assert!(!wie.is_empty()); assert!(!wie.is_empty());

View file

@ -5,8 +5,8 @@
fn main(){ fn main(){
let x = Some(1u8); let x = Some(1u8);
match x { //~ ERROR You seem to be trying to use match match x { //~ ERROR you seem to be trying to use match
//~^ HELP Try //~^ HELP try
Some(y) => { Some(y) => {
println!("{:?}", y); println!("{:?}", y);
} }
@ -18,8 +18,8 @@ fn main(){
None => () None => ()
} }
let z = (1u8,1u8); let z = (1u8,1u8);
match z { //~ ERROR You seem to be trying to use match match z { //~ ERROR you seem to be trying to use match
//~^ HELP Try //~^ HELP try
(2...3, 7...9) => println!("{:?}", z), (2...3, 7...9) => println!("{:?}", z),
_ => {} _ => {}
} }

2
tests/compile-fail/modulo_one.rs Normal file → Executable file
View file

@ -3,6 +3,6 @@
#![deny(modulo_one)] #![deny(modulo_one)]
fn main() { fn main() {
10 % 1; //~ERROR Any number modulo 1 will be 0 10 % 1; //~ERROR any number modulo 1 will be 0
10 % 2; 10 % 2;
} }

View file

@ -3,7 +3,7 @@
#[deny(ptr_arg)] #[deny(ptr_arg)]
#[allow(unused)] #[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 //Nothing here
} }

View file

@ -4,13 +4,13 @@
#[deny(zero_width_space)] #[deny(zero_width_space)]
fn zero() { fn zero() {
print!("Here >< is a ZWS, and another"); 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)] //#[deny(unicode_canon)]
fn 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)] //#[deny(ascii_only)]