mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Add missing suggestions and help message to tests
This commit is contained in:
parent
dd3fd41a03
commit
1f419a2986
4 changed files with 50 additions and 14 deletions
|
@ -356,13 +356,19 @@ fn starts_with() {
|
|||
|
||||
fn use_extend_from_slice() {
|
||||
let mut v : Vec<&'static str> = vec![];
|
||||
v.extend(&["Hello", "World"]); //~ERROR use of `extend`
|
||||
v.extend(&["Hello", "World"]);
|
||||
//~^ ERROR use of `extend`
|
||||
//~| HELP try this
|
||||
//~| SUGGESTION v.extend_from_slice(&["Hello", "World"]);
|
||||
v.extend(&vec!["Some", "more"]);
|
||||
//~^ERROR use of `extend`
|
||||
//~^ ERROR use of `extend`
|
||||
//~| HELP try this
|
||||
//~| SUGGESTION v.extend_from_slice(&vec!["Some", "more"]);
|
||||
|
||||
v.extend(vec!["And", "even", "more"].iter()); //~ERROR use of `extend`
|
||||
v.extend(vec!["And", "even", "more"].iter());
|
||||
//~^ ERROR use of `extend`
|
||||
//~| HELP try this
|
||||
//FIXME: the suggestion if broken because of the macro
|
||||
let o : Option<&'static str> = None;
|
||||
v.extend(o);
|
||||
v.extend(Some("Bye"));
|
||||
|
|
|
@ -23,26 +23,41 @@ fn test_no_semicolon() -> bool {
|
|||
|
||||
fn test_if_block() -> bool {
|
||||
if true {
|
||||
return true; //~ERROR unneeded return statement
|
||||
return true;
|
||||
//~^ ERROR unneeded return statement
|
||||
//~| HELP remove `return` as shown
|
||||
//~| SUGGESTION true
|
||||
} else {
|
||||
return false; //~ERROR unneeded return statement
|
||||
return false;
|
||||
//~^ ERROR unneeded return statement
|
||||
//~| HELP remove `return` as shown
|
||||
//~| SUGGESTION false
|
||||
}
|
||||
}
|
||||
|
||||
fn test_match(x: bool) -> bool {
|
||||
match x {
|
||||
true => {
|
||||
return false; //~ERROR unneeded return statement
|
||||
return false;
|
||||
//~^ ERROR unneeded return statement
|
||||
//~| HELP remove `return` as shown
|
||||
//~| SUGGESTION false
|
||||
}
|
||||
false => {
|
||||
return true; //~ERROR unneeded return statement
|
||||
return true;
|
||||
//~^ ERROR unneeded return statement
|
||||
//~| HELP remove `return` as shown
|
||||
//~| SUGGESTION true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_closure() {
|
||||
let _ = || {
|
||||
return true; //~ERROR unneeded return statement
|
||||
return true;
|
||||
//~^ ERROR unneeded return statement
|
||||
//~| HELP remove `return` as shown
|
||||
//~| SUGGESTION true
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -63,8 +63,11 @@ fn main() {
|
|||
add_assign_only();
|
||||
both();
|
||||
|
||||
// the add is only caught for String
|
||||
// the add is only caught for `String`
|
||||
let mut x = 1;
|
||||
x = x + 1; //~ WARN assign_op_pattern
|
||||
; x = x + 1;
|
||||
//~^ WARN assign_op_pattern
|
||||
//~| HELP replace
|
||||
//~| SUGGESTION ; x += 1;
|
||||
assert_eq!(2, x);
|
||||
}
|
||||
|
|
|
@ -80,17 +80,26 @@ fn main() {
|
|||
}
|
||||
|
||||
let mut iter = 1..20;
|
||||
while let Option::Some(x) = iter.next() { //~ERROR this loop could be written as a `for` loop
|
||||
while let Option::Some(x) = iter.next() {
|
||||
//~^ ERROR this loop could be written as a `for` loop
|
||||
//~| HELP try
|
||||
//~| SUGGESTION for x in iter {
|
||||
println!("{}", x);
|
||||
}
|
||||
|
||||
let mut iter = 1..20;
|
||||
while let Some(x) = iter.next() { //~ERROR this loop could be written as a `for` loop
|
||||
while let Some(x) = iter.next() {
|
||||
//~^ ERROR this loop could be written as a `for` loop
|
||||
//~| HELP try
|
||||
//~| SUGGESTION for x in iter {
|
||||
println!("{}", x);
|
||||
}
|
||||
|
||||
let mut iter = 1..20;
|
||||
while let Some(_) = iter.next() {} //~ERROR this loop could be written as a `for` loop
|
||||
while let Some(_) = iter.next() {}
|
||||
//~^ ERROR this loop could be written as a `for` loop
|
||||
//~| HELP try
|
||||
//~| SUGGESTION for _ in iter {
|
||||
|
||||
let mut iter = 1..20;
|
||||
while let None = iter.next() {} // this is fine (if nonsensical)
|
||||
|
@ -130,7 +139,10 @@ fn main() {
|
|||
// cause this function to trigger it
|
||||
fn no_panic<T>(slice: &[T]) {
|
||||
let mut iter = slice.iter();
|
||||
loop { //~ERROR
|
||||
loop {
|
||||
//~^ ERROR
|
||||
//~| HELP try
|
||||
//~| SUGGESTION while let Some(ele) = iter.next() { .. }
|
||||
let _ = match iter.next() {
|
||||
Some(ele) => ele,
|
||||
None => break
|
||||
|
|
Loading…
Reference in a new issue