Skip to content

Commit d4c2a9d

Browse files
committed
update ui test
1 parent ec5b5f2 commit d4c2a9d

File tree

3 files changed

+84
-64
lines changed

3 files changed

+84
-64
lines changed
Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#![allow(unused)]
22
#![warn(clippy::unnecessary_map_on_constructor)]
33

4+
use std::ffi::OsStr;
5+
46
fn fun(t: i32) -> i32 {
57
t
68
}
79

810
fn notfun(e: SimpleError) -> SimpleError {
911
e
1012
}
13+
macro_rules! expands_to_fun {
14+
() => {
15+
fun
16+
};
17+
}
1118

1219
#[derive(Copy, Clone)]
1320
struct SimpleError {}
@@ -16,28 +23,31 @@ type SimpleResult = std::result::Result<i32, SimpleError>;
1623

1724
fn main() {
1825
let x: i32 = 4;
19-
//
26+
2027
let err = SimpleError {};
21-
let a = Some(x); // => Some(fun(x))
22-
let b: SimpleResult = Ok(x); // => Ok(fun(x))
23-
let c: SimpleResult = Err(err); // => Ok(fun(x))
24-
//
25-
let a = Some(fun(x)); // => Some(fun(x))
26-
let b: SimpleResult = Ok(fun(x)); // => Ok(fun(x))
27-
let c: SimpleResult = Err(notfun(err)); // => Ok(fun(x))
28-
//
29-
//
30-
let a = Option::Some(fun(x)); // => Some(fun(x))
31-
let b: SimpleResult = SimpleResult::Ok(fun(x)); // => SimpleResult::Ok(fun(x))
32-
let c: SimpleResult = SimpleResult::Err(notfun(err)); // => SimpleResult::Err(notfun(x))
33-
let b: std::result::Result<i32, SimpleError> = Ok(fun(x)); // => Ok(fun(x))
34-
let c: std::result::Result<i32, SimpleError> = Err(notfun(err)); // => Err(notfun(x))
35-
36-
a.map(fun); // these should not trigger
37-
b.map(fun);
38-
c.map_err(notfun);
28+
let a = Some(x);
29+
let b: SimpleResult = Ok(x);
30+
let c: SimpleResult = Err(err);
3931

4032
let a = Some(fun(x));
4133
let b: SimpleResult = Ok(fun(x));
42-
let c: SimpleResult = Err(notfun(err)); // => Ok(fun(x))
34+
let c: SimpleResult = Err(notfun(err));
35+
36+
let a = Option::Some(fun(x));
37+
let b: SimpleResult = SimpleResult::Ok(fun(x));
38+
let c: SimpleResult = SimpleResult::Err(notfun(err));
39+
let b: std::result::Result<i32, SimpleError> = Ok(fun(x));
40+
let c: std::result::Result<i32, SimpleError> = Err(notfun(err));
41+
42+
let a = Some(fun(x));
43+
let b: SimpleResult = Ok(fun(x));
44+
let c: SimpleResult = Err(notfun(err));
45+
46+
// Should not trigger warning
47+
a.map(fun);
48+
b.map(fun);
49+
c.map_err(notfun);
50+
51+
option_env!("PATH").map(OsStr::new);
52+
Some(x).map(expands_to_fun!());
4353
}
Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#![allow(unused)]
22
#![warn(clippy::unnecessary_map_on_constructor)]
33

4+
use std::ffi::OsStr;
5+
46
fn fun(t: i32) -> i32 {
57
t
68
}
79

810
fn notfun(e: SimpleError) -> SimpleError {
911
e
1012
}
13+
macro_rules! expands_to_fun {
14+
() => {
15+
fun
16+
};
17+
}
1118

1219
#[derive(Copy, Clone)]
1320
struct SimpleError {}
@@ -16,28 +23,31 @@ type SimpleResult = std::result::Result<i32, SimpleError>;
1623

1724
fn main() {
1825
let x: i32 = 4;
19-
//
26+
2027
let err = SimpleError {};
21-
let a = Some(x); // => Some(fun(x))
22-
let b: SimpleResult = Ok(x); // => Ok(fun(x))
23-
let c: SimpleResult = Err(err); // => Ok(fun(x))
24-
//
25-
let a = Some(x).map(fun); // => Some(fun(x))
26-
let b: SimpleResult = Ok(x).map(fun); // => Ok(fun(x))
27-
let c: SimpleResult = Err(err).map_err(notfun); // => Ok(fun(x))
28-
//
29-
//
30-
let a = Option::Some(x).map(fun); // => Some(fun(x))
31-
let b: SimpleResult = SimpleResult::Ok(x).map(fun); // => SimpleResult::Ok(fun(x))
32-
let c: SimpleResult = SimpleResult::Err(err).map_err(notfun); // => SimpleResult::Err(notfun(x))
33-
let b: std::result::Result<i32, SimpleError> = Ok(x).map(fun); // => Ok(fun(x))
34-
let c: std::result::Result<i32, SimpleError> = Err(err).map_err(notfun); // => Err(notfun(x))
35-
36-
a.map(fun); // these should not trigger
37-
b.map(fun);
38-
c.map_err(notfun);
28+
let a = Some(x);
29+
let b: SimpleResult = Ok(x);
30+
let c: SimpleResult = Err(err);
31+
32+
let a = Some(x).map(fun);
33+
let b: SimpleResult = Ok(x).map(fun);
34+
let c: SimpleResult = Err(err).map_err(notfun);
35+
36+
let a = Option::Some(x).map(fun);
37+
let b: SimpleResult = SimpleResult::Ok(x).map(fun);
38+
let c: SimpleResult = SimpleResult::Err(err).map_err(notfun);
39+
let b: std::result::Result<i32, SimpleError> = Ok(x).map(fun);
40+
let c: std::result::Result<i32, SimpleError> = Err(err).map_err(notfun);
3941

4042
let a = Some(fun(x));
4143
let b: SimpleResult = Ok(fun(x));
42-
let c: SimpleResult = Err(notfun(err)); // => Ok(fun(x))
44+
let c: SimpleResult = Err(notfun(err));
45+
46+
// Should not trigger warning
47+
a.map(fun);
48+
b.map(fun);
49+
c.map_err(notfun);
50+
51+
option_env!("PATH").map(OsStr::new);
52+
Some(x).map(expands_to_fun!());
4353
}
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
error: unnecessary fun on contstuctor Some(_)
2-
--> $DIR/unnecessary_map_on_constructor.rs:25:13
2+
--> $DIR/unnecessary_map_on_constructor.rs:32:13
33
|
4-
LL | let a = Some(x).map(fun); // => Some(fun(x))
5-
| ^^^^^^^^^^^^^^^^ help: try using: `Some(fun(x))`
4+
LL | let a = Some(x).map(fun);
5+
| ^^^^^^^^^^^^^^^^ help: try: `Some(fun(x))`
66
|
77
= note: `-D clippy::unnecessary-map-on-constructor` implied by `-D warnings`
88

99
error: unnecessary fun on contstuctor Ok(_)
10-
--> $DIR/unnecessary_map_on_constructor.rs:26:27
10+
--> $DIR/unnecessary_map_on_constructor.rs:33:27
1111
|
12-
LL | let b: SimpleResult = Ok(x).map(fun); // => Ok(fun(x))
13-
| ^^^^^^^^^^^^^^ help: try using: `Ok(fun(x))`
12+
LL | let b: SimpleResult = Ok(x).map(fun);
13+
| ^^^^^^^^^^^^^^ help: try: `Ok(fun(x))`
1414

1515
error: unnecessary notfun on contstuctor Err(_)
16-
--> $DIR/unnecessary_map_on_constructor.rs:27:27
16+
--> $DIR/unnecessary_map_on_constructor.rs:34:27
1717
|
18-
LL | let c: SimpleResult = Err(err).map_err(notfun); // => Ok(fun(x))
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try using: `Err(notfun(err))`
18+
LL | let c: SimpleResult = Err(err).map_err(notfun);
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Err(notfun(err))`
2020

2121
error: unnecessary fun on contstuctor Option::Some(_)
22-
--> $DIR/unnecessary_map_on_constructor.rs:30:13
22+
--> $DIR/unnecessary_map_on_constructor.rs:36:13
2323
|
24-
LL | let a = Option::Some(x).map(fun); // => Some(fun(x))
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try using: `Option::Some(fun(x))`
24+
LL | let a = Option::Some(x).map(fun);
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option::Some(fun(x))`
2626

2727
error: unnecessary fun on contstuctor SimpleResult::Ok(_)
28-
--> $DIR/unnecessary_map_on_constructor.rs:31:27
28+
--> $DIR/unnecessary_map_on_constructor.rs:37:27
2929
|
30-
LL | let b: SimpleResult = SimpleResult::Ok(x).map(fun); // => SimpleResult::Ok(fun(x))
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using: `SimpleResult::Ok(fun(x))`
30+
LL | let b: SimpleResult = SimpleResult::Ok(x).map(fun);
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `SimpleResult::Ok(fun(x))`
3232

3333
error: unnecessary notfun on contstuctor SimpleResult::Err(_)
34-
--> $DIR/unnecessary_map_on_constructor.rs:32:27
34+
--> $DIR/unnecessary_map_on_constructor.rs:38:27
3535
|
36-
LL | let c: SimpleResult = SimpleResult::Err(err).map_err(notfun); // => SimpleResult::Err(notfun(x))
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using: `SimpleResult::Err(notfun(err))`
36+
LL | let c: SimpleResult = SimpleResult::Err(err).map_err(notfun);
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `SimpleResult::Err(notfun(err))`
3838

3939
error: unnecessary fun on contstuctor Ok(_)
40-
--> $DIR/unnecessary_map_on_constructor.rs:33:52
40+
--> $DIR/unnecessary_map_on_constructor.rs:39:52
4141
|
42-
LL | let b: std::result::Result<i32, SimpleError> = Ok(x).map(fun); // => Ok(fun(x))
43-
| ^^^^^^^^^^^^^^ help: try using: `Ok(fun(x))`
42+
LL | let b: std::result::Result<i32, SimpleError> = Ok(x).map(fun);
43+
| ^^^^^^^^^^^^^^ help: try: `Ok(fun(x))`
4444

4545
error: unnecessary notfun on contstuctor Err(_)
46-
--> $DIR/unnecessary_map_on_constructor.rs:34:52
46+
--> $DIR/unnecessary_map_on_constructor.rs:40:52
4747
|
48-
LL | let c: std::result::Result<i32, SimpleError> = Err(err).map_err(notfun); // => Err(notfun(x))
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try using: `Err(notfun(err))`
48+
LL | let c: std::result::Result<i32, SimpleError> = Err(err).map_err(notfun);
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Err(notfun(err))`
5050

5151
error: aborting due to 8 previous errors
5252

0 commit comments

Comments
 (0)