@@ -33,7 +33,7 @@ declare_clippy_lint! {
3333 /// ```
3434 pub MANUAL_UNWRAP_OR ,
3535 complexity,
36- "finds patterns that can be encoded more concisely with `Option::unwrap_or(_else) `"
36+ "finds patterns that can be encoded more concisely with `Option::unwrap_or`"
3737}
3838
3939declare_lint_pass ! ( ManualUnwrapOr => [ MANUAL_UNWRAP_OR ] ) ;
@@ -83,26 +83,19 @@ fn lint_option_unwrap_or_case<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tc
8383 if let Some ( scrutinee_snippet) = utils:: snippet_opt( cx, scrutinee. span) ;
8484 if let Some ( none_body_snippet) = utils:: snippet_opt( cx, none_arm. body. span) ;
8585 if let Some ( indent) = utils:: indent_of( cx, expr. span) ;
86+ if constant_simple( cx, cx. typeck_results( ) , none_arm. body) . is_some( ) ;
8687 then {
8788 let reindented_none_body =
8889 utils:: reindent_multiline( none_body_snippet. into( ) , true , Some ( indent) ) ;
89- let eager_eval = constant_simple( cx, cx. typeck_results( ) , none_arm. body) . is_some( ) ;
90- let method = if eager_eval {
91- "unwrap_or"
92- } else {
93- "unwrap_or_else"
94- } ;
9590 utils:: span_lint_and_sugg(
9691 cx,
9792 MANUAL_UNWRAP_OR , expr. span,
98- & format! ( "this pattern reimplements `Option::{}`" , & method ) ,
93+ "this pattern reimplements `Option::unwrap_or`" ,
9994 "replace with" ,
10095 format!(
101- "{}.{}({} {})" ,
96+ "{}.unwrap_or( {})" ,
10297 scrutinee_snippet,
103- method,
104- if eager_eval { "" } else { "|| " } ,
105- reindented_none_body
98+ reindented_none_body,
10699 ) ,
107100 Applicability :: MachineApplicable ,
108101 ) ;
0 commit comments