mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Only print out question_mark lint when it actually triggered
This commit is contained in:
parent
18584698ee
commit
65c35333a4
1 changed files with 21 additions and 18 deletions
|
@ -73,7 +73,7 @@ impl Pass {
|
|||
|
||||
then {
|
||||
let receiver_str = &Sugg::hir(cx, subject, "..");
|
||||
let mut replacement_str = String::new();
|
||||
let mut replacement: Option<String> = None;
|
||||
if let Some(else_) = else_ {
|
||||
if_chain! {
|
||||
if let ExprKind::Block(block, None) = &else_.node;
|
||||
|
@ -81,28 +81,31 @@ impl Pass {
|
|||
if let Some(block_expr) = &block.expr;
|
||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(subject, block_expr);
|
||||
then {
|
||||
replacement_str = format!("Some({}?)", receiver_str);
|
||||
replacement = Some(format!("Some({}?)", receiver_str));
|
||||
}
|
||||
}
|
||||
} else if Self::moves_by_default(cx, subject) {
|
||||
replacement_str = format!("{}.as_ref()?;", receiver_str);
|
||||
replacement = Some(format!("{}.as_ref()?;", receiver_str));
|
||||
} else {
|
||||
replacement_str = format!("{}?;", receiver_str);
|
||||
replacement = Some(format!("{}?;", receiver_str));
|
||||
}
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
QUESTION_MARK,
|
||||
expr.span,
|
||||
"this block may be rewritten with the `?` operator",
|
||||
|db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"replace_it_with",
|
||||
replacement_str,
|
||||
Applicability::MaybeIncorrect, // snippet
|
||||
);
|
||||
}
|
||||
)
|
||||
|
||||
if let Some(replacement_str) = replacement {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
QUESTION_MARK,
|
||||
expr.span,
|
||||
"this block may be rewritten with the `?` operator",
|
||||
|db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"replace_it_with",
|
||||
replacement_str,
|
||||
Applicability::MaybeIncorrect, // snippet
|
||||
);
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue