@@ -64,34 +64,33 @@ pub(super) fn check<'tcx>(
6464 }
6565 } ;
6666
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+ } ;
9072
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) ,
9479 }
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
9594 }
9695 }
9796
@@ -223,7 +222,7 @@ fn closure_body_returns_empty_to_string(cx: &LateContext<'_>, e: &hir::Expr<'_>)
223222 if body. params . is_empty ( )
224223 && let hir:: Expr { kind, .. } = & body. value
225224 && let hir:: ExprKind :: MethodCall ( hir:: PathSegment { ident, ..} , self_arg, _, _) = kind
226- && ident == & symbol :: Ident :: from_str ( " to_string" )
225+ && ident. name == sym :: to_string
227226 && let hir:: Expr { kind, .. } = self_arg
228227 && let hir:: ExprKind :: Lit ( lit) = kind
229228 && let ast:: LitKind :: Str ( symbol:: kw:: Empty , _) = lit. node
0 commit comments