Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-Authored-By: Philipp Krones <[email protected]>
  • Loading branch information
sinkuu and flip1995 committed Mar 4, 2020
1 parent 246709f commit a78a1fc
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions clippy_lints/src/question_mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
use crate::utils::paths::{OPTION, OPTION_NONE};
use crate::utils::sugg::Sugg;
use crate::utils::{
higher, match_def_path, match_qpath, match_type, snippet_with_applicability, span_lint_and_then, SpanlessEq,
higher, match_def_path, match_qpath, match_type, snippet_with_applicability, span_lint_and_sugg, SpanlessEq,
};

declare_clippy_lint! {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl QuestionMark {

then {
let mut applicability = Applicability::MachineApplicable;
let receiver_str = snippet_with_applicability(cx, subject.span, "..", &mut applicability);
let receiver_str = &Sugg::hir_with_applicability(cx, subject, "..", &mut applicability);
let mut replacement: Option<String> = None;
if let Some(else_) = else_ {
if_chain! {
Expand All @@ -77,19 +77,14 @@ impl QuestionMark {
}

if let Some(replacement_str) = replacement {
span_lint_and_then(
span_lint_and_sugg(
cx,
QUESTION_MARK,
expr.span,
"this block may be rewritten with the `?` operator",
|db| {
db.span_suggestion(
expr.span,
"replace it with",
replacement_str,
applicability,
);
}
"replace it with",
replacement_str,
applicability,
)
}
}
Expand Down Expand Up @@ -124,19 +119,14 @@ impl QuestionMark {
if by_ref { ".as_ref()" } else { "" },
);

span_lint_and_then(
span_lint_and_sugg(
cx,
QUESTION_MARK,
expr.span,
"this if-let-else may be rewritten with the `?` operator",
|db| {
db.span_suggestion(
expr.span,
"replace it with",
replacement,
applicability,
);
}
"replace it with",
replacement,
applicability,
)
}
}
Expand Down

0 comments on commit a78a1fc

Please sign in to comment.