@@ -48,11 +48,10 @@ pub(super) fn lint<'a, 'tcx>(
4848 let msg = if is_option {
4949 // comparing the snippet from source to raw text ("None") below is safe
5050 // because we already have checked the type.
51- let arg = if unwrap_snippet == "None" { "None" } else { "a" } ;
52- let suggest = if unwrap_snippet == "None" {
53- "and_then(f)"
51+ let ( arg, suggest) = if unwrap_snippet == "None" {
52+ ( "None" , "and_then(f)" )
5453 } else {
55- " map_or(a, f)"
54+ ( "a" , " map_or(a, f)")
5655 } ;
5756
5857 format ! (
@@ -67,6 +66,12 @@ pub(super) fn lint<'a, 'tcx>(
6766 . to_string ( )
6867 } ;
6968
69+ let lint = if is_option {
70+ OPTION_MAP_UNWRAP_OR
71+ } else {
72+ RESULT_MAP_UNWRAP_OR
73+ } ;
74+
7075 // lint, with note if neither arg is > 1 line and both map() and
7176 // unwrap_or() have the same span
7277 let multiline = map_snippet. lines ( ) . count ( ) > 1 || unwrap_snippet. lines ( ) . count ( ) > 1 ;
@@ -81,29 +86,9 @@ pub(super) fn lint<'a, 'tcx>(
8186 "replace `map({}).unwrap_or({})` with `{}`" ,
8287 map_snippet, unwrap_snippet, suggest
8388 ) ;
84- span_note_and_lint (
85- cx,
86- if is_option {
87- OPTION_MAP_UNWRAP_OR
88- } else {
89- RESULT_MAP_UNWRAP_OR
90- } ,
91- expr. span ,
92- & msg,
93- expr. span ,
94- & note,
95- ) ;
89+ span_note_and_lint ( cx, lint, expr. span , & msg, expr. span , & note) ;
9690 } else if same_span && multiline {
97- span_lint (
98- cx,
99- if is_option {
100- OPTION_MAP_UNWRAP_OR
101- } else {
102- RESULT_MAP_UNWRAP_OR
103- } ,
104- expr. span ,
105- & msg,
106- ) ;
91+ span_lint ( cx, lint, expr. span , & msg) ;
10792 } ;
10893 }
10994}
0 commit comments