mirror of https://github.com/rust-lang/rust.git
Add tests for 'Also apply `warn(for_loops_over_fallibles)` to &T and &mut T, not just T = Result/Option.'
This commit is contained in:
parent
77f288c18d
commit
ea549fd176
|
@ -41,3 +41,25 @@ fn _returns_result() -> Result<(), ()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn _by_ref() {
|
||||
// Shared refs
|
||||
for _ in &Some(1) {}
|
||||
//~^ WARN for loop over an `&Option`. This is more readably written as an `if let` statement
|
||||
//~| HELP to check pattern in a loop use `while let`
|
||||
//~| HELP consider using `if let` to clear intent
|
||||
for _ in &Ok::<_, ()>(1) {}
|
||||
//~^ WARN for loop over a `&Result`. This is more readably written as an `if let` statement
|
||||
//~| HELP to check pattern in a loop use `while let`
|
||||
//~| HELP consider using `if let` to clear intent
|
||||
|
||||
// Mutable refs
|
||||
for _ in &mut Some(1) {}
|
||||
//~^ WARN for loop over an `&mut Option`. This is more readably written as an `if let` statement
|
||||
//~| HELP to check pattern in a loop use `while let`
|
||||
//~| HELP consider using `if let` to clear intent
|
||||
for _ in &mut Ok::<_, ()>(1) {}
|
||||
//~^ WARN for loop over a `&mut Result`. This is more readably written as an `if let` statement
|
||||
//~| HELP to check pattern in a loop use `while let`
|
||||
//~| HELP consider using `if let` to clear intent
|
||||
}
|
||||
|
|
|
@ -97,5 +97,65 @@ help: consider using `if let` to clear intent
|
|||
LL | if let Ok(_) = Ok::<_, ()>([0; 0]) {}
|
||||
| ~~~~~~~~~~ ~~~
|
||||
|
||||
warning: 6 warnings emitted
|
||||
warning: for loop over an `&Option`. This is more readably written as an `if let` statement
|
||||
--> $DIR/for_loop_over_fallibles.rs:47:14
|
||||
|
|
||||
LL | for _ in &Some(1) {}
|
||||
| ^^^^^^^^
|
||||
|
|
||||
help: to check pattern in a loop use `while let`
|
||||
|
|
||||
LL | while let Some(_) = &Some(1) {}
|
||||
| ~~~~~~~~~~~~~~~ ~~~
|
||||
help: consider using `if let` to clear intent
|
||||
|
|
||||
LL | if let Some(_) = &Some(1) {}
|
||||
| ~~~~~~~~~~~~ ~~~
|
||||
|
||||
warning: for loop over a `&Result`. This is more readably written as an `if let` statement
|
||||
--> $DIR/for_loop_over_fallibles.rs:51:14
|
||||
|
|
||||
LL | for _ in &Ok::<_, ()>(1) {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to check pattern in a loop use `while let`
|
||||
|
|
||||
LL | while let Ok(_) = &Ok::<_, ()>(1) {}
|
||||
| ~~~~~~~~~~~~~ ~~~
|
||||
help: consider using `if let` to clear intent
|
||||
|
|
||||
LL | if let Ok(_) = &Ok::<_, ()>(1) {}
|
||||
| ~~~~~~~~~~ ~~~
|
||||
|
||||
warning: for loop over an `&mut Option`. This is more readably written as an `if let` statement
|
||||
--> $DIR/for_loop_over_fallibles.rs:57:14
|
||||
|
|
||||
LL | for _ in &mut Some(1) {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: to check pattern in a loop use `while let`
|
||||
|
|
||||
LL | while let Some(_) = &mut Some(1) {}
|
||||
| ~~~~~~~~~~~~~~~ ~~~
|
||||
help: consider using `if let` to clear intent
|
||||
|
|
||||
LL | if let Some(_) = &mut Some(1) {}
|
||||
| ~~~~~~~~~~~~ ~~~
|
||||
|
||||
warning: for loop over a `&mut Result`. This is more readably written as an `if let` statement
|
||||
--> $DIR/for_loop_over_fallibles.rs:61:14
|
||||
|
|
||||
LL | for _ in &mut Ok::<_, ()>(1) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to check pattern in a loop use `while let`
|
||||
|
|
||||
LL | while let Ok(_) = &mut Ok::<_, ()>(1) {}
|
||||
| ~~~~~~~~~~~~~ ~~~
|
||||
help: consider using `if let` to clear intent
|
||||
|
|
||||
LL | if let Ok(_) = &mut Ok::<_, ()>(1) {}
|
||||
| ~~~~~~~~~~ ~~~
|
||||
|
||||
warning: 10 warnings emitted
|
||||
|
||||
|
|
Loading…
Reference in New Issue