Skip to content

Commit 3a09496

Browse files
committed
Rename [misleading_use_of_ok] to [unused_result_ok] and add macro tests
1 parent 8935208 commit 3a09496

10 files changed

+140
-68
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5583,7 +5583,6 @@ Released 2018-09-13
55835583
[`min_ident_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars
55845584
[`min_max`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_max
55855585
[`misaligned_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#misaligned_transmute
5586-
[`misleading_use_of_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#misleading_use_of_ok
55875586
[`mismatched_target_os`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatched_target_os
55885587
[`mismatching_type_param_order`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatching_type_param_order
55895588
[`misnamed_getters`]: https://rust-lang.github.io/rust-clippy/master/index.html#misnamed_getters
@@ -5956,6 +5955,7 @@ Released 2018-09-13
59565955
[`unused_io_amount`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount
59575956
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
59585957
[`unused_peekable`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_peekable
5958+
[`unused_result_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_result_ok
59595959
[`unused_rounding`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_rounding
59605960
[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
59615961
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
500500
crate::misc_early::UNNEEDED_WILDCARD_PATTERN_INFO,
501501
crate::misc_early::UNSEPARATED_LITERAL_SUFFIX_INFO,
502502
crate::misc_early::ZERO_PREFIXED_LITERAL_INFO,
503-
crate::misleading_use_of_ok::MISLEADING_USE_OF_OK_INFO,
504503
crate::mismatching_type_param_order::MISMATCHING_TYPE_PARAM_ORDER_INFO,
505504
crate::missing_assert_message::MISSING_ASSERT_MESSAGE_INFO,
506505
crate::missing_asserts_for_indexing::MISSING_ASSERTS_FOR_INDEXING_INFO,
@@ -741,6 +740,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
741740
crate::unused_async::UNUSED_ASYNC_INFO,
742741
crate::unused_io_amount::UNUSED_IO_AMOUNT_INFO,
743742
crate::unused_peekable::UNUSED_PEEKABLE_INFO,
743+
crate::unused_result_ok::UNUSED_RESULT_OK_INFO,
744744
crate::unused_rounding::UNUSED_ROUNDING_INFO,
745745
crate::unused_self::UNUSED_SELF_INFO,
746746
crate::unused_unit::UNUSED_UNIT_INFO,

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ mod min_ident_chars;
229229
mod minmax;
230230
mod misc;
231231
mod misc_early;
232-
mod misleading_use_of_ok;
233232
mod mismatching_type_param_order;
234233
mod missing_assert_message;
235234
mod missing_asserts_for_indexing;
@@ -372,6 +371,7 @@ mod unsafe_removed_from_name;
372371
mod unused_async;
373372
mod unused_io_amount;
374373
mod unused_peekable;
374+
mod unused_result_ok;
375375
mod unused_rounding;
376376
mod unused_self;
377377
mod unused_unit;
@@ -669,7 +669,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
669669
store.register_late_pass(move |_| Box::new(missing_doc::MissingDoc::new(conf)));
670670
store.register_late_pass(|_| Box::new(missing_inline::MissingInline));
671671
store.register_late_pass(move |_| Box::new(exhaustive_items::ExhaustiveItems));
672-
store.register_late_pass(|_| Box::new(misleading_use_of_ok::MisleadingUseOfOk));
672+
store.register_late_pass(|_| Box::new(unused_result_ok::UnusedResultOk));
673673
store.register_late_pass(|_| Box::new(match_result_ok::MatchResultOk));
674674
store.register_late_pass(|_| Box::new(partialeq_ne_impl::PartialEqNeImpl));
675675
store.register_late_pass(|_| Box::new(unused_io_amount::UnusedIoAmount));

clippy_lints/src/misleading_use_of_ok.rs renamed to clippy_lints/src/unused_result_ok.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ declare_clippy_lint! {
2727
/// let _ = some_function();
2828
/// ```
2929
#[clippy::version = "1.70.0"]
30-
pub MISLEADING_USE_OF_OK,
30+
pub UNUSED_RESULT_OK,
3131
style,
3232
"Use of `.ok()` to silence `Result`'s `#[must_use]` is misleading. Use `let _ =` instead."
3333
}
34-
declare_lint_pass!(MisleadingUseOfOk => [MISLEADING_USE_OF_OK]);
34+
declare_lint_pass!(UnusedResultOk => [UNUSED_RESULT_OK]);
3535

36-
impl LateLintPass<'_> for MisleadingUseOfOk {
36+
impl LateLintPass<'_> for UnusedResultOk {
3737
fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) {
3838
if let StmtKind::Semi(expr) = stmt.kind &&
3939
let ExprKind::MethodCall(ok_path, recv, [], ..) = expr.kind //check is expr.ok() has type Result<T,E>.ok(, _)
@@ -47,7 +47,7 @@ impl LateLintPass<'_> for MisleadingUseOfOk {
4747
let sugg = format!("let _ = {snippet}");
4848
span_lint_and_sugg(
4949
cx,
50-
MISLEADING_USE_OF_OK,
50+
UNUSED_RESULT_OK,
5151
expr.span,
5252
"ignoring a result with `.ok()` is misleading",
5353
"consider using `let _ =` and removing the call to `.ok()` instead",

tests/ui/misleading_use_of_ok.fixed

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/ui/misleading_use_of_ok.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/ui/misleading_use_of_ok.stderr

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/ui/unused_result_ok.fixed

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//@aux-build:proc_macros.rs
2+
#![warn(clippy::unused_result_ok)]
3+
#![allow(dead_code)]
4+
5+
#[macro_use]
6+
extern crate proc_macros;
7+
8+
fn bad_style(x: &str) {
9+
let _ = x.parse::<u32>();
10+
}
11+
12+
fn good_style(x: &str) -> Option<u32> {
13+
x.parse::<u32>().ok()
14+
}
15+
16+
#[rustfmt::skip]
17+
fn strange_parse(x: &str) {
18+
let _ = x . parse::<i32>();
19+
}
20+
21+
macro_rules! v {
22+
() => {
23+
Ok::<(), ()>(())
24+
};
25+
}
26+
27+
macro_rules! w {
28+
() => {
29+
let _ = Ok::<(), ()>(());
30+
};
31+
}
32+
33+
fn main() {
34+
let _ = v!();
35+
w!();
36+
37+
external! {
38+
Ok::<(),()>(()).ok();
39+
};
40+
}

tests/ui/unused_result_ok.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//@aux-build:proc_macros.rs
2+
#![warn(clippy::unused_result_ok)]
3+
#![allow(dead_code)]
4+
5+
#[macro_use]
6+
extern crate proc_macros;
7+
8+
fn bad_style(x: &str) {
9+
x.parse::<u32>().ok();
10+
}
11+
12+
fn good_style(x: &str) -> Option<u32> {
13+
x.parse::<u32>().ok()
14+
}
15+
16+
#[rustfmt::skip]
17+
fn strange_parse(x: &str) {
18+
x . parse::<i32>() . ok ();
19+
}
20+
21+
macro_rules! v {
22+
() => {
23+
Ok::<(), ()>(())
24+
};
25+
}
26+
27+
macro_rules! w {
28+
() => {
29+
Ok::<(), ()>(()).ok();
30+
};
31+
}
32+
33+
fn main() {
34+
v!().ok();
35+
w!();
36+
37+
external! {
38+
Ok::<(),()>(()).ok();
39+
};
40+
}

tests/ui/unused_result_ok.stderr

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error: ignoring a result with `.ok()` is misleading
2+
--> $DIR/unused_result_ok.rs:9:5
3+
|
4+
LL | x.parse::<u32>().ok();
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::unused-result-ok` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::unused_result_ok)]`
9+
help: consider using `let _ =` and removing the call to `.ok()` instead
10+
|
11+
LL | let _ = x.parse::<u32>();
12+
| ~~~~~~~~~~~~~~~~~~~~~~~~
13+
14+
error: ignoring a result with `.ok()` is misleading
15+
--> $DIR/unused_result_ok.rs:18:5
16+
|
17+
LL | x . parse::<i32>() . ok ();
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
|
20+
help: consider using `let _ =` and removing the call to `.ok()` instead
21+
|
22+
LL | let _ = x . parse::<i32>();
23+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
25+
error: ignoring a result with `.ok()` is misleading
26+
--> $DIR/unused_result_ok.rs:34:5
27+
|
28+
LL | v!().ok();
29+
| ^^^^^^^^^
30+
|
31+
help: consider using `let _ =` and removing the call to `.ok()` instead
32+
|
33+
LL | let _ = v!();
34+
| ~~~~~~~~~~~~
35+
36+
error: ignoring a result with `.ok()` is misleading
37+
--> $DIR/unused_result_ok.rs:29:9
38+
|
39+
LL | Ok::<(), ()>(()).ok();
40+
| ^^^^^^^^^^^^^^^^^^^^^
41+
...
42+
LL | w!();
43+
| ---- in this macro invocation
44+
|
45+
= note: this error originates in the macro `w` (in Nightly builds, run with -Z macro-backtrace for more info)
46+
help: consider using `let _ =` and removing the call to `.ok()` instead
47+
|
48+
LL | let _ = Ok::<(), ()>(());
49+
| ~~~~~~~~~~~~~~~~~~~~~~~~
50+
51+
error: aborting due to 4 previous errors
52+

0 commit comments

Comments
 (0)