@@ -54,21 +54,6 @@ impl LateLintPass<'_> for ManualUnwrapOr {
5454 }
5555}
5656
57- #[ derive( Copy , Clone ) ]
58- enum Case {
59- Option ,
60- Result ,
61- }
62-
63- impl Case {
64- fn unwrap_fn_path ( & self ) -> & str {
65- match self {
66- Case :: Option => "Option::unwrap_or" ,
67- Case :: Result => "Result::unwrap_or" ,
68- }
69- }
70- }
71-
7257fn lint_manual_unwrap_or < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
7358 fn applicable_or_arm < ' a > ( cx : & LateContext < ' _ > , arms : & ' a [ Arm < ' a > ] ) -> Option < & ' a Arm < ' a > > {
7459 if_chain ! {
@@ -101,10 +86,10 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
10186 if_chain ! {
10287 if let ExprKind :: Match ( scrutinee, match_arms, _) = expr. kind;
10388 let ty = cx. typeck_results( ) . expr_ty( scrutinee) ;
104- if let Some ( case ) = if is_type_diagnostic_item( cx, ty, sym:: option_type) {
105- Some ( Case :: Option )
89+ if let Some ( ty_name ) = if is_type_diagnostic_item( cx, ty, sym:: option_type) {
90+ Some ( " Option" )
10691 } else if is_type_diagnostic_item( cx, ty, sym:: result_type) {
107- Some ( Case :: Result )
92+ Some ( " Result" )
10893 } else {
10994 None
11095 } ;
@@ -127,7 +112,7 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
127112 span_lint_and_sugg(
128113 cx,
129114 MANUAL_UNWRAP_OR , expr. span,
130- & format!( "this pattern reimplements `{}`" , case . unwrap_fn_path ( ) ) ,
115+ & format!( "this pattern reimplements `{}::unwrap_or `" , ty_name ) ,
131116 "replace with" ,
132117 format!(
133118 "{}.unwrap_or({})" ,
0 commit comments