@@ -1022,9 +1022,47 @@ fn lint_expect_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, n
1022
1022
}
1023
1023
1024
1024
let closure = if match_type ( cx, self_type, & paths:: OPTION ) { "||" } else { "|_|" } ;
1025
+ let span_replace_word = method_span. with_hi ( span. hi ( ) ) ;
1026
+
1027
+ if let hir:: ExprAddrOf ( _, ref addr_of) = arg. node {
1028
+ if let hir:: ExprCall ( ref _inner_fun, ref inner_args) = addr_of. node {
1029
+ // TODO: check if inner_fun is call to format!
1030
+ if inner_args. len ( ) == 1 {
1031
+ if let hir:: ExprCall ( _, ref format_args) = inner_args[ 0 ] . node {
1032
+ let args_len = format_args. len ( ) ;
1033
+ let args: Vec < String > = format_args
1034
+ . into_iter ( )
1035
+ . take ( args_len - 1 )
1036
+ . map ( |a| {
1037
+ if let hir:: ExprAddrOf ( _, ref format_arg) = a. node {
1038
+ if let hir:: ExprMatch ( ref format_arg_expr, _, _) = format_arg. node {
1039
+ if let hir:: ExprTup ( ref format_arg_expr_tup) = format_arg_expr. node {
1040
+ return snippet ( cx, format_arg_expr_tup[ 0 ] . span , ".." ) . into_owned ( ) ;
1041
+ }
1042
+ }
1043
+ } ;
1044
+ snippet ( cx, a. span , ".." ) . into_owned ( )
1045
+ } )
1046
+ . collect ( ) ;
1047
+
1048
+ let sugg = args. join ( ", " ) ;
1049
+
1050
+ span_lint_and_sugg (
1051
+ cx,
1052
+ EXPECT_FUN_CALL ,
1053
+ span_replace_word,
1054
+ & format ! ( "use of `{}` followed by a function call" , name) ,
1055
+ "try this" ,
1056
+ format ! ( "unwrap_or_else({} panic!({}))" , closure, sugg) ,
1057
+ ) ;
1058
+
1059
+ return ;
1060
+ }
1061
+ }
1062
+ }
1063
+ }
1025
1064
1026
1065
let sugg: Cow < _ > = snippet ( cx, arg. span , ".." ) ;
1027
- let span_replace_word = method_span. with_hi ( span. hi ( ) ) ;
1028
1066
1029
1067
span_lint_and_sugg (
1030
1068
cx,
0 commit comments