Skip to content

Commit

Permalink
fix code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Guanqun Lu committed Dec 18, 2019
1 parent 0d4c7ec commit 2ecaf8f
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions clippy_lints/src/methods/map_unwrap_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ pub(super) fn lint<'a, 'tcx>(
let msg = if is_option {
// comparing the snippet from source to raw text ("None") below is safe
// because we already have checked the type.
let arg = if unwrap_snippet == "None" { "None" } else { "a" };
let suggest = if unwrap_snippet == "None" {
"and_then(f)"
let (arg, suggest) = if unwrap_snippet == "None" {
("None", "and_then(f)")
} else {
"map_or(a, f)"
("a", "map_or(a, f)")
};

format!(
Expand All @@ -67,6 +66,12 @@ pub(super) fn lint<'a, 'tcx>(
.to_string()
};

let lint = if is_option {
OPTION_MAP_UNWRAP_OR
} else {
RESULT_MAP_UNWRAP_OR
};

// lint, with note if neither arg is > 1 line and both map() and
// unwrap_or() have the same span
let multiline = map_snippet.lines().count() > 1 || unwrap_snippet.lines().count() > 1;
Expand All @@ -81,29 +86,9 @@ pub(super) fn lint<'a, 'tcx>(
"replace `map({}).unwrap_or({})` with `{}`",
map_snippet, unwrap_snippet, suggest
);
span_note_and_lint(
cx,
if is_option {
OPTION_MAP_UNWRAP_OR
} else {
RESULT_MAP_UNWRAP_OR
},
expr.span,
&msg,
expr.span,
&note,
);
span_note_and_lint(cx, lint, expr.span, &msg, expr.span, &note);
} else if same_span && multiline {
span_lint(
cx,
if is_option {
OPTION_MAP_UNWRAP_OR
} else {
RESULT_MAP_UNWRAP_OR
},
expr.span,
&msg,
);
span_lint(cx, lint, expr.span, &msg);
};
}
}
Expand Down

0 comments on commit 2ecaf8f

Please sign in to comment.