mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +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() {
|
fn use_extend_from_slice() {
|
||||||
let mut v : Vec<&'static str> = vec![];
|
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"]);
|
v.extend(&vec!["Some", "more"]);
|
||||||
//~^ERROR use of `extend`
|
//~^ ERROR use of `extend`
|
||||||
//~| HELP try this
|
//~| HELP try this
|
||||||
//~| SUGGESTION v.extend_from_slice(&vec!["Some", "more"]);
|
//~| 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;
|
let o : Option<&'static str> = None;
|
||||||
v.extend(o);
|
v.extend(o);
|
||||||
v.extend(Some("Bye"));
|
v.extend(Some("Bye"));
|
||||||
|
|
|
@ -23,26 +23,41 @@ fn test_no_semicolon() -> bool {
|
||||||
|
|
||||||
fn test_if_block() -> bool {
|
fn test_if_block() -> bool {
|
||||||
if true {
|
if true {
|
||||||
return true; //~ERROR unneeded return statement
|
return true;
|
||||||
|
//~^ ERROR unneeded return statement
|
||||||
|
//~| HELP remove `return` as shown
|
||||||
|
//~| SUGGESTION true
|
||||||
} else {
|
} 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 {
|
fn test_match(x: bool) -> bool {
|
||||||
match x {
|
match x {
|
||||||
true => {
|
true => {
|
||||||
return false; //~ERROR unneeded return statement
|
return false;
|
||||||
|
//~^ ERROR unneeded return statement
|
||||||
|
//~| HELP remove `return` as shown
|
||||||
|
//~| SUGGESTION false
|
||||||
}
|
}
|
||||||
false => {
|
false => {
|
||||||
return true; //~ERROR unneeded return statement
|
return true;
|
||||||
|
//~^ ERROR unneeded return statement
|
||||||
|
//~| HELP remove `return` as shown
|
||||||
|
//~| SUGGESTION true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_closure() {
|
fn test_closure() {
|
||||||
let _ = || {
|
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();
|
add_assign_only();
|
||||||
both();
|
both();
|
||||||
|
|
||||||
// the add is only caught for String
|
// the add is only caught for `String`
|
||||||
let mut x = 1;
|
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);
|
assert_eq!(2, x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,17 +80,26 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut iter = 1..20;
|
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);
|
println!("{}", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut iter = 1..20;
|
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);
|
println!("{}", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut iter = 1..20;
|
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;
|
let mut iter = 1..20;
|
||||||
while let None = iter.next() {} // this is fine (if nonsensical)
|
while let None = iter.next() {} // this is fine (if nonsensical)
|
||||||
|
@ -130,7 +139,10 @@ fn main() {
|
||||||
// cause this function to trigger it
|
// cause this function to trigger it
|
||||||
fn no_panic<T>(slice: &[T]) {
|
fn no_panic<T>(slice: &[T]) {
|
||||||
let mut iter = slice.iter();
|
let mut iter = slice.iter();
|
||||||
loop { //~ERROR
|
loop {
|
||||||
|
//~^ ERROR
|
||||||
|
//~| HELP try
|
||||||
|
//~| SUGGESTION while let Some(ele) = iter.next() { .. }
|
||||||
let _ = match iter.next() {
|
let _ = match iter.next() {
|
||||||
Some(ele) => ele,
|
Some(ele) => ele,
|
||||||
None => break
|
None => break
|
||||||
|
|
Loading…
Reference in a new issue