@@ -33,7 +33,7 @@ declare_clippy_lint! {
33
33
/// ```
34
34
pub MANUAL_UNWRAP_OR ,
35
35
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`"
37
37
}
38
38
39
39
declare_lint_pass ! ( ManualUnwrapOr => [ MANUAL_UNWRAP_OR ] ) ;
@@ -83,26 +83,19 @@ fn lint_option_unwrap_or_case<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tc
83
83
if let Some ( scrutinee_snippet) = utils:: snippet_opt( cx, scrutinee. span) ;
84
84
if let Some ( none_body_snippet) = utils:: snippet_opt( cx, none_arm. body. span) ;
85
85
if let Some ( indent) = utils:: indent_of( cx, expr. span) ;
86
+ if constant_simple( cx, cx. typeck_results( ) , none_arm. body) . is_some( ) ;
86
87
then {
87
88
let reindented_none_body =
88
89
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
- } ;
95
90
utils:: span_lint_and_sugg(
96
91
cx,
97
92
MANUAL_UNWRAP_OR , expr. span,
98
- & format! ( "this pattern reimplements `Option::{}`" , & method ) ,
93
+ "this pattern reimplements `Option::unwrap_or`" ,
99
94
"replace with" ,
100
95
format!(
101
- "{}.{}({} {})" ,
96
+ "{}.unwrap_or( {})" ,
102
97
scrutinee_snippet,
103
- method,
104
- if eager_eval { "" } else { "|| " } ,
105
- reindented_none_body
98
+ reindented_none_body,
106
99
) ,
107
100
Applicability :: MachineApplicable ,
108
101
) ;
0 commit comments