-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename [misleading_use_of_ok] to [unused_result_ok] and add macro tests
- Loading branch information
Showing
10 changed files
with
173 additions
and
68 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 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 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,51 @@ | ||
//@aux-build:proc_macros.rs | ||
#![warn(clippy::unused_result_ok)] | ||
#![allow(dead_code)] | ||
|
||
#[macro_use] | ||
extern crate proc_macros; | ||
|
||
fn bad_style(x: &str) { | ||
let _ = x.parse::<u32>(); | ||
} | ||
|
||
fn good_style(x: &str) -> Option<u32> { | ||
x.parse::<u32>().ok() | ||
} | ||
|
||
#[rustfmt::skip] | ||
fn strange_parse(x: &str) { | ||
let _ = x . parse::<i32>(); | ||
} | ||
|
||
macro_rules! v { | ||
() => { | ||
Ok::<(), ()>(()) | ||
}; | ||
} | ||
|
||
macro_rules! w { | ||
() => { | ||
let _ = Ok::<(), ()>(()); | ||
}; | ||
} | ||
|
||
fn main() { | ||
let _ = v!(); | ||
w!(); | ||
|
||
external! { | ||
macro_rules! x { | ||
() => { Ok::<(), ()>(()) } | ||
} | ||
macro_rules! y { | ||
() => { Ok::<(), ()>(()).ok(); } | ||
} | ||
|
||
x!().ok(); | ||
y!(); | ||
}; | ||
|
||
let _ = x!(); | ||
y!(); | ||
} |
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,51 @@ | ||
//@aux-build:proc_macros.rs | ||
#![warn(clippy::unused_result_ok)] | ||
#![allow(dead_code)] | ||
|
||
#[macro_use] | ||
extern crate proc_macros; | ||
|
||
fn bad_style(x: &str) { | ||
x.parse::<u32>().ok(); | ||
} | ||
|
||
fn good_style(x: &str) -> Option<u32> { | ||
x.parse::<u32>().ok() | ||
} | ||
|
||
#[rustfmt::skip] | ||
fn strange_parse(x: &str) { | ||
x . parse::<i32>() . ok (); | ||
} | ||
|
||
macro_rules! v { | ||
() => { | ||
Ok::<(), ()>(()) | ||
}; | ||
} | ||
|
||
macro_rules! w { | ||
() => { | ||
Ok::<(), ()>(()).ok(); | ||
}; | ||
} | ||
|
||
fn main() { | ||
v!().ok(); | ||
w!(); | ||
|
||
external! { | ||
macro_rules! x { | ||
() => { Ok::<(), ()>(()) } | ||
} | ||
macro_rules! y { | ||
() => { Ok::<(), ()>(()).ok(); } | ||
} | ||
|
||
x!().ok(); | ||
y!(); | ||
}; | ||
|
||
x!().ok(); | ||
y!(); | ||
} |
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 @@ | ||
error: ignoring a result with `.ok()` is misleading | ||
--> $DIR/unused_result_ok.rs:9:5 | ||
| | ||
LL | x.parse::<u32>().ok(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::unused-result-ok` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::unused_result_ok)]` | ||
help: consider using `let _ =` and removing the call to `.ok()` instead | ||
| | ||
LL | let _ = x.parse::<u32>(); | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: ignoring a result with `.ok()` is misleading | ||
--> $DIR/unused_result_ok.rs:18:5 | ||
| | ||
LL | x . parse::<i32>() . ok (); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider using `let _ =` and removing the call to `.ok()` instead | ||
| | ||
LL | let _ = x . parse::<i32>(); | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: ignoring a result with `.ok()` is misleading | ||
--> $DIR/unused_result_ok.rs:34:5 | ||
| | ||
LL | v!().ok(); | ||
| ^^^^^^^^^ | ||
| | ||
help: consider using `let _ =` and removing the call to `.ok()` instead | ||
| | ||
LL | let _ = v!(); | ||
| ~~~~~~~~~~~~ | ||
|
||
error: ignoring a result with `.ok()` is misleading | ||
--> $DIR/unused_result_ok.rs:29:9 | ||
| | ||
LL | Ok::<(), ()>(()).ok(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | w!(); | ||
| ---- in this macro invocation | ||
| | ||
= note: this error originates in the macro `w` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: consider using `let _ =` and removing the call to `.ok()` instead | ||
| | ||
LL | let _ = Ok::<(), ()>(()); | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: ignoring a result with `.ok()` is misleading | ||
--> $DIR/unused_result_ok.rs:49:5 | ||
| | ||
LL | x!().ok(); | ||
| ^^^^^^^^^ | ||
| | ||
help: consider using `let _ =` and removing the call to `.ok()` instead | ||
| | ||
LL | let _ = x!(); | ||
| ~~~~~~~~~~~~ | ||
|
||
error: aborting due to 5 previous errors | ||
|