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(
2525 None
2626 } ;
2727
28- let method = if is_err { "unwrap_err " } else { "unwrap " } ;
28+ let method_suffix = if is_err { "_err " } else { "" } ;
2929
3030 if allow_unwrap_in_tests && is_in_test_function ( cx. tcx , expr. hir_id ) {
3131 return ;
@@ -35,7 +35,7 @@ pub(super) fn check(
3535 let help = if is_lint_allowed ( cx, EXPECT_USED , expr. hir_id ) {
3636 format ! (
3737 "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"
3939 )
4040 } else {
4141 format ! ( "if this value is {none_prefix}`{none_value}`, it will panic" )
@@ -45,7 +45,7 @@ pub(super) fn check(
4545 cx,
4646 lint,
4747 expr. span ,
48- & format ! ( "used `{method }()` on `{kind}` value" ) ,
48+ & format ! ( "used `unwrap{method_suffix }()` on `{kind}` value" ) ,
4949 None ,
5050 & help,
5151 ) ;
Original file line number Diff line number Diff line change @@ -6,8 +6,9 @@ fn expect_option() {
66}
77
88fn expect_result ( ) {
9- let res: Result < u8 , ( ) > = Ok ( 0 ) ;
9+ let res: Result < u8 , u8 > = Ok ( 0 ) ;
1010 let _ = res. expect ( "" ) ;
11+ let _ = res. expect_err ( "" ) ;
1112}
1213
1314fn main ( ) {
Original file line number Diff line number Diff line change @@ -15,5 +15,13 @@ LL | let _ = res.expect("");
1515 |
1616 = help: if this value is an `Err`, it will panic
1717
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
1927
Original file line number Diff line number Diff line change @@ -6,8 +6,9 @@ fn unwrap_option() {
66}
77
88fn unwrap_result ( ) {
9- let res: Result < u8 , ( ) > = Ok ( 0 ) ;
9+ let res: Result < u8 , u8 > = Ok ( 0 ) ;
1010 let _ = res. unwrap ( ) ;
11+ let _ = res. unwrap_err ( ) ;
1112}
1213
1314fn main ( ) {
Original file line number Diff line number Diff line change @@ -15,5 +15,13 @@ LL | let _ = res.unwrap();
1515 |
1616 = help: if you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message
1717
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
1927
You can’t perform that action at this time.
0 commit comments