File tree Expand file tree Collapse file tree 5 files changed +25
-7
lines changed Expand file tree Collapse file tree 5 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ pub(super) fn check(
25
25
None
26
26
} ;
27
27
28
- let method = if is_err { "unwrap_err " } else { "unwrap " } ;
28
+ let method_suffix = if is_err { "_err " } else { "" } ;
29
29
30
30
if allow_unwrap_in_tests && is_in_test_function ( cx. tcx , expr. hir_id ) {
31
31
return ;
@@ -35,7 +35,7 @@ pub(super) fn check(
35
35
let help = if is_lint_allowed ( cx, EXPECT_USED , expr. hir_id ) {
36
36
format ! (
37
37
"if you don't want to handle the `{none_value}` case gracefully, consider \
38
- using `expect()` to provide a better panic message"
38
+ using `expect{method_suffix} ()` to provide a better panic message"
39
39
)
40
40
} else {
41
41
format ! ( "if this value is {none_prefix}`{none_value}`, it will panic" )
@@ -45,7 +45,7 @@ pub(super) fn check(
45
45
cx,
46
46
lint,
47
47
expr. span ,
48
- & format ! ( "used `{method }()` on `{kind}` value" ) ,
48
+ & format ! ( "used `unwrap{method_suffix }()` on `{kind}` value" ) ,
49
49
None ,
50
50
& help,
51
51
) ;
Original file line number Diff line number Diff line change @@ -6,8 +6,9 @@ fn expect_option() {
6
6
}
7
7
8
8
fn expect_result ( ) {
9
- let res: Result < u8 , ( ) > = Ok ( 0 ) ;
9
+ let res: Result < u8 , u8 > = Ok ( 0 ) ;
10
10
let _ = res. expect ( "" ) ;
11
+ let _ = res. expect_err ( "" ) ;
11
12
}
12
13
13
14
fn main ( ) {
Original file line number Diff line number Diff line change @@ -15,5 +15,13 @@ LL | let _ = res.expect("");
15
15
|
16
16
= help: if this value is an `Err`, it will panic
17
17
18
- error: aborting due to 2 previous errors
18
+ error: used `expect_err()` on `a Result` value
19
+ --> $DIR/expect.rs:11:13
20
+ |
21
+ LL | let _ = res.expect_err("");
22
+ | ^^^^^^^^^^^^^^^^^^
23
+ |
24
+ = help: if this value is an `Ok`, it will panic
25
+
26
+ error: aborting due to 3 previous errors
19
27
Original file line number Diff line number Diff line change @@ -6,8 +6,9 @@ fn unwrap_option() {
6
6
}
7
7
8
8
fn unwrap_result ( ) {
9
- let res: Result < u8 , ( ) > = Ok ( 0 ) ;
9
+ let res: Result < u8 , u8 > = Ok ( 0 ) ;
10
10
let _ = res. unwrap ( ) ;
11
+ let _ = res. unwrap_err ( ) ;
11
12
}
12
13
13
14
fn main ( ) {
Original file line number Diff line number Diff line change @@ -15,5 +15,13 @@ LL | let _ = res.unwrap();
15
15
|
16
16
= help: if you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message
17
17
18
- error: aborting due to 2 previous errors
18
+ error: used `unwrap_err()` on `a Result` value
19
+ --> $DIR/unwrap.rs:11:13
20
+ |
21
+ LL | let _ = res.unwrap_err();
22
+ | ^^^^^^^^^^^^^^^^
23
+ |
24
+ = help: if you don't want to handle the `Ok` case gracefully, consider using `expect_err()` to provide a better panic message
25
+
26
+ error: aborting due to 3 previous errors
19
27
You can’t perform that action at this time.
0 commit comments