-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #7608 - andrewpollack:7594/while_let_some_result, r=Man…
…ishearth #7594: Adding new 'while_let_some_result' linting Excited for the opportunity to contribute to Clippy! Since the latest Bay Area Rust Meetup, I've been looking for an opportunity and found it 😄 Please let me know how I can improve this PR! Much of it is similar to ``[`if_let_some_result`]``, but I followed the description in the issue to create its own linting rules. Looking forward to feedback, and continuing to work on Clippy in the future! changelog: - Renamed Lint: `if_let_some_result` is now called [`match_result_ok`]. Now also handles `while let` case.
- Loading branch information
Showing
8 changed files
with
185 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::match_result_ok)] | ||
#![allow(clippy::boxed_local)] | ||
#![allow(dead_code)] | ||
|
||
// Checking `if` cases | ||
|
||
fn str_to_int(x: &str) -> i32 { | ||
if let Ok(y) = x.parse() { y } else { 0 } | ||
} | ||
|
||
fn str_to_int_ok(x: &str) -> i32 { | ||
if let Ok(y) = x.parse() { y } else { 0 } | ||
} | ||
|
||
#[rustfmt::skip] | ||
fn strange_some_no_else(x: &str) -> i32 { | ||
{ | ||
if let Ok(y) = x . parse() { | ||
return y; | ||
}; | ||
0 | ||
} | ||
} | ||
|
||
// Checking `while` cases | ||
|
||
struct Wat { | ||
counter: i32, | ||
} | ||
|
||
impl Wat { | ||
fn next(&mut self) -> Result<i32, &str> { | ||
self.counter += 1; | ||
if self.counter < 5 { | ||
Ok(self.counter) | ||
} else { | ||
Err("Oh no") | ||
} | ||
} | ||
} | ||
|
||
fn base_1(x: i32) { | ||
let mut wat = Wat { counter: x }; | ||
while let Ok(a) = wat.next() { | ||
println!("{}", a); | ||
} | ||
} | ||
|
||
fn base_2(x: i32) { | ||
let mut wat = Wat { counter: x }; | ||
while let Ok(a) = wat.next() { | ||
println!("{}", a); | ||
} | ||
} | ||
|
||
fn base_3(test_func: Box<Result<i32, &str>>) { | ||
// Expected to stay as is | ||
while let Some(_b) = test_func.ok() {} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::match_result_ok)] | ||
#![allow(clippy::boxed_local)] | ||
#![allow(dead_code)] | ||
|
||
// Checking `if` cases | ||
|
||
fn str_to_int(x: &str) -> i32 { | ||
if let Some(y) = x.parse().ok() { y } else { 0 } | ||
} | ||
|
||
fn str_to_int_ok(x: &str) -> i32 { | ||
if let Ok(y) = x.parse() { y } else { 0 } | ||
} | ||
|
||
#[rustfmt::skip] | ||
fn strange_some_no_else(x: &str) -> i32 { | ||
{ | ||
if let Some(y) = x . parse() . ok () { | ||
return y; | ||
}; | ||
0 | ||
} | ||
} | ||
|
||
// Checking `while` cases | ||
|
||
struct Wat { | ||
counter: i32, | ||
} | ||
|
||
impl Wat { | ||
fn next(&mut self) -> Result<i32, &str> { | ||
self.counter += 1; | ||
if self.counter < 5 { | ||
Ok(self.counter) | ||
} else { | ||
Err("Oh no") | ||
} | ||
} | ||
} | ||
|
||
fn base_1(x: i32) { | ||
let mut wat = Wat { counter: x }; | ||
while let Some(a) = wat.next().ok() { | ||
println!("{}", a); | ||
} | ||
} | ||
|
||
fn base_2(x: i32) { | ||
let mut wat = Wat { counter: x }; | ||
while let Ok(a) = wat.next() { | ||
println!("{}", a); | ||
} | ||
} | ||
|
||
fn base_3(test_func: Box<Result<i32, &str>>) { | ||
// Expected to stay as is | ||
while let Some(_b) = test_func.ok() {} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.