@@ -64,34 +64,33 @@ pub(super) fn check<'tcx>(
64
64
}
65
65
} ;
66
66
67
- if_chain ! {
68
- if let Some ( sugg) = match ( name, call_expr. is_some( ) ) {
69
- ( "unwrap_or" , true ) | ( "unwrap_or_else" , false ) => Some ( "unwrap_or_default" ) ,
70
- ( "or_insert" , true ) | ( "or_insert_with" , false ) => Some ( "or_default" ) ,
71
- _ => None ,
72
- } ;
73
- // needs to target Default::default in particular or be *::new and have a Default impl
74
- // available
75
- if ( is_new( fun) && output_type_implements_default( fun) )
76
- || match call_expr {
77
- Some ( call_expr) => is_default_equivalent( cx, call_expr) ,
78
- None => is_default_equivalent_call( cx, fun) || closure_body_returns_empty_to_string( cx, fun) ,
79
- } ;
80
- then {
81
- span_lint_and_sugg(
82
- cx,
83
- UNWRAP_OR_DEFAULT ,
84
- method_span. with_hi( span. hi( ) ) ,
85
- & format!( "use of `{name}` to construct default value" ) ,
86
- "try" ,
87
- format!( "{sugg}()" ) ,
88
- Applicability :: MachineApplicable ,
89
- ) ;
67
+ let sugg = match ( name, call_expr. is_some ( ) ) {
68
+ ( "unwrap_or" , true ) | ( "unwrap_or_else" , false ) => "unwrap_or_default" ,
69
+ ( "or_insert" , true ) | ( "or_insert_with" , false ) => "or_default" ,
70
+ _ => return false ,
71
+ } ;
90
72
91
- true
92
- } else {
93
- false
73
+ // needs to target Default::default in particular or be *::new and have a Default impl
74
+ // available
75
+ if ( is_new ( fun) && output_type_implements_default ( fun) )
76
+ || match call_expr {
77
+ Some ( call_expr) => is_default_equivalent ( cx, call_expr) ,
78
+ None => is_default_equivalent_call ( cx, fun) || closure_body_returns_empty_to_string ( cx, fun) ,
94
79
}
80
+ {
81
+ span_lint_and_sugg (
82
+ cx,
83
+ UNWRAP_OR_DEFAULT ,
84
+ method_span. with_hi ( span. hi ( ) ) ,
85
+ & format ! ( "use of `{name}` to construct default value" ) ,
86
+ "try" ,
87
+ format ! ( "{sugg}()" ) ,
88
+ Applicability :: MachineApplicable ,
89
+ ) ;
90
+
91
+ true
92
+ } else {
93
+ false
95
94
}
96
95
}
97
96
@@ -223,7 +222,7 @@ fn closure_body_returns_empty_to_string(cx: &LateContext<'_>, e: &hir::Expr<'_>)
223
222
if body. params . is_empty ( )
224
223
&& let hir:: Expr { kind, .. } = & body. value
225
224
&& let hir:: ExprKind :: MethodCall ( hir:: PathSegment { ident, ..} , self_arg, _, _) = kind
226
- && ident == & symbol :: Ident :: from_str ( " to_string" )
225
+ && ident. name == sym :: to_string
227
226
&& let hir:: Expr { kind, .. } = self_arg
228
227
&& let hir:: ExprKind :: Lit ( lit) = kind
229
228
&& let ast:: LitKind :: Str ( symbol:: kw:: Empty , _) = lit. node
0 commit comments