mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
map_unit_fn: make test rustfixable
This commit is contained in:
parent
ad0e7c8e7f
commit
e4ff86dcd4
6 changed files with 197 additions and 34 deletions
78
tests/ui/option_map_unit_fn_fixable.fixed
Normal file
78
tests/ui/option_map_unit_fn_fixable.fixed
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#![warn(clippy::option_map_unit_fn)]
|
||||||
|
#![allow(unused)]
|
||||||
|
|
||||||
|
fn do_nothing<T>(_: T) {}
|
||||||
|
|
||||||
|
fn diverge<T>(_: T) -> ! {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn plus_one(value: usize) -> usize {
|
||||||
|
value + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
struct HasOption {
|
||||||
|
field: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasOption {
|
||||||
|
fn do_option_nothing(self: &Self, value: usize) {}
|
||||||
|
|
||||||
|
fn do_option_plus_one(self: &Self, value: usize) -> usize {
|
||||||
|
value + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[rustfmt::skip]
|
||||||
|
fn option_map_unit_fn() {
|
||||||
|
let x = HasOption { field: Some(10) };
|
||||||
|
|
||||||
|
x.field.map(plus_one);
|
||||||
|
let _ : Option<()> = x.field.map(do_nothing);
|
||||||
|
|
||||||
|
if let Some(x_field) = x.field { do_nothing(x_field) }
|
||||||
|
|
||||||
|
if let Some(x_field) = x.field { do_nothing(x_field) }
|
||||||
|
|
||||||
|
if let Some(x_field) = x.field { diverge(x_field) }
|
||||||
|
|
||||||
|
let captured = 10;
|
||||||
|
if let Some(value) = x.field { do_nothing(value + captured) };
|
||||||
|
let _ : Option<()> = x.field.map(|value| do_nothing(value + captured));
|
||||||
|
|
||||||
|
if let Some(value) = x.field { x.do_option_nothing(value + captured) }
|
||||||
|
|
||||||
|
if let Some(value) = x.field { x.do_option_plus_one(value + captured); }
|
||||||
|
|
||||||
|
|
||||||
|
if let Some(value) = x.field { do_nothing(value + captured) }
|
||||||
|
|
||||||
|
if let Some(value) = x.field { do_nothing(value + captured) }
|
||||||
|
|
||||||
|
if let Some(value) = x.field { do_nothing(value + captured); }
|
||||||
|
|
||||||
|
if let Some(value) = x.field { do_nothing(value + captured); }
|
||||||
|
|
||||||
|
|
||||||
|
if let Some(value) = x.field { diverge(value + captured) }
|
||||||
|
|
||||||
|
if let Some(value) = x.field { diverge(value + captured) }
|
||||||
|
|
||||||
|
if let Some(value) = x.field { diverge(value + captured); }
|
||||||
|
|
||||||
|
if let Some(value) = x.field { diverge(value + captured); }
|
||||||
|
|
||||||
|
|
||||||
|
x.field.map(|value| plus_one(value + captured));
|
||||||
|
x.field.map(|value| { plus_one(value + captured) });
|
||||||
|
if let Some(value) = x.field { let y = plus_one(value + captured); }
|
||||||
|
|
||||||
|
if let Some(value) = x.field { plus_one(value + captured); }
|
||||||
|
|
||||||
|
if let Some(value) = x.field { plus_one(value + captured); }
|
||||||
|
|
||||||
|
|
||||||
|
if let Some(ref value) = x.field { do_nothing(value + captured) }}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -1,3 +1,5 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
#![warn(clippy::option_map_unit_fn)]
|
#![warn(clippy::option_map_unit_fn)]
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: called `map(f)` on an Option value where `f` is a unit function
|
error: called `map(f)` on an Option value where `f` is a unit function
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:32:5
|
--> $DIR/option_map_unit_fn_fixable.rs:34:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(do_nothing);
|
LL | x.field.map(do_nothing);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -9,7 +9,7 @@ LL | x.field.map(do_nothing);
|
||||||
= note: `-D clippy::option-map-unit-fn` implied by `-D warnings`
|
= note: `-D clippy::option-map-unit-fn` implied by `-D warnings`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit function
|
error: called `map(f)` on an Option value where `f` is a unit function
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:34:5
|
--> $DIR/option_map_unit_fn_fixable.rs:36:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(do_nothing);
|
LL | x.field.map(do_nothing);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -17,7 +17,7 @@ LL | x.field.map(do_nothing);
|
||||||
| help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }`
|
| help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit function
|
error: called `map(f)` on an Option value where `f` is a unit function
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:36:5
|
--> $DIR/option_map_unit_fn_fixable.rs:38:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(diverge);
|
LL | x.field.map(diverge);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -25,7 +25,7 @@ LL | x.field.map(diverge);
|
||||||
| help: try this: `if let Some(x_field) = x.field { diverge(x_field) }`
|
| help: try this: `if let Some(x_field) = x.field { diverge(x_field) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:42:5
|
--> $DIR/option_map_unit_fn_fixable.rs:44:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| x.do_option_nothing(value + captured));
|
LL | x.field.map(|value| x.do_option_nothing(value + captured));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -33,7 +33,7 @@ LL | x.field.map(|value| x.do_option_nothing(value + captured));
|
||||||
| help: try this: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }`
|
| help: try this: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:44:5
|
--> $DIR/option_map_unit_fn_fixable.rs:46:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { x.do_option_plus_one(value + captured); });
|
LL | x.field.map(|value| { x.do_option_plus_one(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -41,7 +41,7 @@ LL | x.field.map(|value| { x.do_option_plus_one(value + captured); });
|
||||||
| help: try this: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }`
|
| help: try this: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:47:5
|
--> $DIR/option_map_unit_fn_fixable.rs:49:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| do_nothing(value + captured));
|
LL | x.field.map(|value| do_nothing(value + captured));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -49,7 +49,7 @@ LL | x.field.map(|value| do_nothing(value + captured));
|
||||||
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
|
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:49:5
|
--> $DIR/option_map_unit_fn_fixable.rs:51:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { do_nothing(value + captured) });
|
LL | x.field.map(|value| { do_nothing(value + captured) });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -57,7 +57,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) });
|
||||||
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
|
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:51:5
|
--> $DIR/option_map_unit_fn_fixable.rs:53:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { do_nothing(value + captured); });
|
LL | x.field.map(|value| { do_nothing(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -65,7 +65,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); });
|
||||||
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
|
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:53:5
|
--> $DIR/option_map_unit_fn_fixable.rs:55:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { { do_nothing(value + captured); } });
|
LL | x.field.map(|value| { { do_nothing(value + captured); } });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -73,7 +73,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } });
|
||||||
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
|
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:56:5
|
--> $DIR/option_map_unit_fn_fixable.rs:58:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| diverge(value + captured));
|
LL | x.field.map(|value| diverge(value + captured));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -81,7 +81,7 @@ LL | x.field.map(|value| diverge(value + captured));
|
||||||
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
|
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:58:5
|
--> $DIR/option_map_unit_fn_fixable.rs:60:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { diverge(value + captured) });
|
LL | x.field.map(|value| { diverge(value + captured) });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -89,7 +89,7 @@ LL | x.field.map(|value| { diverge(value + captured) });
|
||||||
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
|
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:60:5
|
--> $DIR/option_map_unit_fn_fixable.rs:62:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { diverge(value + captured); });
|
LL | x.field.map(|value| { diverge(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -97,7 +97,7 @@ LL | x.field.map(|value| { diverge(value + captured); });
|
||||||
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
|
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:62:5
|
--> $DIR/option_map_unit_fn_fixable.rs:64:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { { diverge(value + captured); } });
|
LL | x.field.map(|value| { { diverge(value + captured); } });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -105,7 +105,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } });
|
||||||
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
|
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:67:5
|
--> $DIR/option_map_unit_fn_fixable.rs:69:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { let y = plus_one(value + captured); });
|
LL | x.field.map(|value| { let y = plus_one(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -113,7 +113,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); });
|
||||||
| help: try this: `if let Some(value) = x.field { let y = plus_one(value + captured); }`
|
| help: try this: `if let Some(value) = x.field { let y = plus_one(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:69:5
|
--> $DIR/option_map_unit_fn_fixable.rs:71:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { plus_one(value + captured); });
|
LL | x.field.map(|value| { plus_one(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -121,7 +121,7 @@ LL | x.field.map(|value| { plus_one(value + captured); });
|
||||||
| help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
|
| help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:71:5
|
--> $DIR/option_map_unit_fn_fixable.rs:73:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { { plus_one(value + captured); } });
|
LL | x.field.map(|value| { { plus_one(value + captured); } });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -129,7 +129,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } });
|
||||||
| help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
|
| help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Option value where `f` is a unit closure
|
error: called `map(f)` on an Option value where `f` is a unit closure
|
||||||
--> $DIR/option_map_unit_fn_fixable.rs:74:5
|
--> $DIR/option_map_unit_fn_fixable.rs:76:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|ref value| { do_nothing(value + captured) });}
|
LL | x.field.map(|ref value| { do_nothing(value + captured) });}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
|
81
tests/ui/result_map_unit_fn_fixable.fixed
Normal file
81
tests/ui/result_map_unit_fn_fixable.fixed
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#![feature(never_type)]
|
||||||
|
#![warn(clippy::result_map_unit_fn)]
|
||||||
|
#![allow(unused)]
|
||||||
|
|
||||||
|
fn do_nothing<T>(_: T) {}
|
||||||
|
|
||||||
|
fn diverge<T>(_: T) -> ! {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn plus_one(value: usize) -> usize {
|
||||||
|
value + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
struct HasResult {
|
||||||
|
field: Result<usize, usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasResult {
|
||||||
|
fn do_result_nothing(self: &Self, value: usize) {}
|
||||||
|
|
||||||
|
fn do_result_plus_one(self: &Self, value: usize) -> usize {
|
||||||
|
value + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
fn result_map_unit_fn() {
|
||||||
|
let x = HasResult { field: Ok(10) };
|
||||||
|
|
||||||
|
x.field.map(plus_one);
|
||||||
|
let _: Result<(), usize> = x.field.map(do_nothing);
|
||||||
|
|
||||||
|
if let Ok(x_field) = x.field { do_nothing(x_field) }
|
||||||
|
|
||||||
|
if let Ok(x_field) = x.field { do_nothing(x_field) }
|
||||||
|
|
||||||
|
if let Ok(x_field) = x.field { diverge(x_field) }
|
||||||
|
|
||||||
|
let captured = 10;
|
||||||
|
if let Ok(value) = x.field { do_nothing(value + captured) };
|
||||||
|
let _: Result<(), usize> = x.field.map(|value| do_nothing(value + captured));
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { x.do_result_nothing(value + captured) }
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }
|
||||||
|
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { do_nothing(value + captured) }
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { do_nothing(value + captured) }
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { do_nothing(value + captured); }
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { do_nothing(value + captured); }
|
||||||
|
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { diverge(value + captured) }
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { diverge(value + captured) }
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { diverge(value + captured); }
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { diverge(value + captured); }
|
||||||
|
|
||||||
|
|
||||||
|
x.field.map(|value| plus_one(value + captured));
|
||||||
|
x.field.map(|value| { plus_one(value + captured) });
|
||||||
|
if let Ok(value) = x.field { let y = plus_one(value + captured); }
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { plus_one(value + captured); }
|
||||||
|
|
||||||
|
if let Ok(value) = x.field { plus_one(value + captured); }
|
||||||
|
|
||||||
|
|
||||||
|
if let Ok(ref value) = x.field { do_nothing(value + captured) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -1,3 +1,5 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![warn(clippy::result_map_unit_fn)]
|
#![warn(clippy::result_map_unit_fn)]
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: called `map(f)` on an Result value where `f` is a unit function
|
error: called `map(f)` on an Result value where `f` is a unit function
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:34:5
|
--> $DIR/result_map_unit_fn_fixable.rs:36:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(do_nothing);
|
LL | x.field.map(do_nothing);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -9,7 +9,7 @@ LL | x.field.map(do_nothing);
|
||||||
= note: `-D clippy::result-map-unit-fn` implied by `-D warnings`
|
= note: `-D clippy::result-map-unit-fn` implied by `-D warnings`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit function
|
error: called `map(f)` on an Result value where `f` is a unit function
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:36:5
|
--> $DIR/result_map_unit_fn_fixable.rs:38:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(do_nothing);
|
LL | x.field.map(do_nothing);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -17,7 +17,7 @@ LL | x.field.map(do_nothing);
|
||||||
| help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }`
|
| help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit function
|
error: called `map(f)` on an Result value where `f` is a unit function
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:38:5
|
--> $DIR/result_map_unit_fn_fixable.rs:40:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(diverge);
|
LL | x.field.map(diverge);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -25,7 +25,7 @@ LL | x.field.map(diverge);
|
||||||
| help: try this: `if let Ok(x_field) = x.field { diverge(x_field) }`
|
| help: try this: `if let Ok(x_field) = x.field { diverge(x_field) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:44:5
|
--> $DIR/result_map_unit_fn_fixable.rs:46:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| x.do_result_nothing(value + captured));
|
LL | x.field.map(|value| x.do_result_nothing(value + captured));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -33,7 +33,7 @@ LL | x.field.map(|value| x.do_result_nothing(value + captured));
|
||||||
| help: try this: `if let Ok(value) = x.field { x.do_result_nothing(value + captured) }`
|
| help: try this: `if let Ok(value) = x.field { x.do_result_nothing(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:46:5
|
--> $DIR/result_map_unit_fn_fixable.rs:48:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { x.do_result_plus_one(value + captured); });
|
LL | x.field.map(|value| { x.do_result_plus_one(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -41,7 +41,7 @@ LL | x.field.map(|value| { x.do_result_plus_one(value + captured); });
|
||||||
| help: try this: `if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }`
|
| help: try this: `if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:49:5
|
--> $DIR/result_map_unit_fn_fixable.rs:51:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| do_nothing(value + captured));
|
LL | x.field.map(|value| do_nothing(value + captured));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -49,7 +49,7 @@ LL | x.field.map(|value| do_nothing(value + captured));
|
||||||
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }`
|
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:51:5
|
--> $DIR/result_map_unit_fn_fixable.rs:53:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { do_nothing(value + captured) });
|
LL | x.field.map(|value| { do_nothing(value + captured) });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -57,7 +57,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) });
|
||||||
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }`
|
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:53:5
|
--> $DIR/result_map_unit_fn_fixable.rs:55:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { do_nothing(value + captured); });
|
LL | x.field.map(|value| { do_nothing(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -65,7 +65,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); });
|
||||||
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }`
|
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:55:5
|
--> $DIR/result_map_unit_fn_fixable.rs:57:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { { do_nothing(value + captured); } });
|
LL | x.field.map(|value| { { do_nothing(value + captured); } });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -73,7 +73,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } });
|
||||||
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }`
|
| help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:58:5
|
--> $DIR/result_map_unit_fn_fixable.rs:60:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| diverge(value + captured));
|
LL | x.field.map(|value| diverge(value + captured));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -81,7 +81,7 @@ LL | x.field.map(|value| diverge(value + captured));
|
||||||
| help: try this: `if let Ok(value) = x.field { diverge(value + captured) }`
|
| help: try this: `if let Ok(value) = x.field { diverge(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:60:5
|
--> $DIR/result_map_unit_fn_fixable.rs:62:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { diverge(value + captured) });
|
LL | x.field.map(|value| { diverge(value + captured) });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -89,7 +89,7 @@ LL | x.field.map(|value| { diverge(value + captured) });
|
||||||
| help: try this: `if let Ok(value) = x.field { diverge(value + captured) }`
|
| help: try this: `if let Ok(value) = x.field { diverge(value + captured) }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:62:5
|
--> $DIR/result_map_unit_fn_fixable.rs:64:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { diverge(value + captured); });
|
LL | x.field.map(|value| { diverge(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -97,7 +97,7 @@ LL | x.field.map(|value| { diverge(value + captured); });
|
||||||
| help: try this: `if let Ok(value) = x.field { diverge(value + captured); }`
|
| help: try this: `if let Ok(value) = x.field { diverge(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:64:5
|
--> $DIR/result_map_unit_fn_fixable.rs:66:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { { diverge(value + captured); } });
|
LL | x.field.map(|value| { { diverge(value + captured); } });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -105,7 +105,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } });
|
||||||
| help: try this: `if let Ok(value) = x.field { diverge(value + captured); }`
|
| help: try this: `if let Ok(value) = x.field { diverge(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:69:5
|
--> $DIR/result_map_unit_fn_fixable.rs:71:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { let y = plus_one(value + captured); });
|
LL | x.field.map(|value| { let y = plus_one(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -113,7 +113,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); });
|
||||||
| help: try this: `if let Ok(value) = x.field { let y = plus_one(value + captured); }`
|
| help: try this: `if let Ok(value) = x.field { let y = plus_one(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:71:5
|
--> $DIR/result_map_unit_fn_fixable.rs:73:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { plus_one(value + captured); });
|
LL | x.field.map(|value| { plus_one(value + captured); });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -121,7 +121,7 @@ LL | x.field.map(|value| { plus_one(value + captured); });
|
||||||
| help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }`
|
| help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:73:5
|
--> $DIR/result_map_unit_fn_fixable.rs:75:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|value| { { plus_one(value + captured); } });
|
LL | x.field.map(|value| { { plus_one(value + captured); } });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
@ -129,7 +129,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } });
|
||||||
| help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }`
|
| help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }`
|
||||||
|
|
||||||
error: called `map(f)` on an Result value where `f` is a unit closure
|
error: called `map(f)` on an Result value where `f` is a unit closure
|
||||||
--> $DIR/result_map_unit_fn_fixable.rs:76:5
|
--> $DIR/result_map_unit_fn_fixable.rs:78:5
|
||||||
|
|
|
|
||||||
LL | x.field.map(|ref value| { do_nothing(value + captured) });
|
LL | x.field.map(|ref value| { do_nothing(value + captured) });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
|
||||||
|
|
Loading…
Reference in a new issue