mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +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 {
|
then {
|
||||||
let receiver_str = &Sugg::hir(cx, subject, "..");
|
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 let Some(else_) = else_ {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Block(block, None) = &else_.node;
|
if let ExprKind::Block(block, None) = &else_.node;
|
||||||
|
@ -81,28 +81,31 @@ impl Pass {
|
||||||
if let Some(block_expr) = &block.expr;
|
if let Some(block_expr) = &block.expr;
|
||||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(subject, block_expr);
|
if SpanlessEq::new(cx).ignore_fn().eq_expr(subject, block_expr);
|
||||||
then {
|
then {
|
||||||
replacement_str = format!("Some({}?)", receiver_str);
|
replacement = Some(format!("Some({}?)", receiver_str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if Self::moves_by_default(cx, subject) {
|
} else if Self::moves_by_default(cx, subject) {
|
||||||
replacement_str = format!("{}.as_ref()?;", receiver_str);
|
replacement = Some(format!("{}.as_ref()?;", receiver_str));
|
||||||
} else {
|
} else {
|
||||||
replacement_str = format!("{}?;", receiver_str);
|
replacement = Some(format!("{}?;", receiver_str));
|
||||||
}
|
}
|
||||||
span_lint_and_then(
|
|
||||||
cx,
|
if let Some(replacement_str) = replacement {
|
||||||
QUESTION_MARK,
|
span_lint_and_then(
|
||||||
expr.span,
|
cx,
|
||||||
"this block may be rewritten with the `?` operator",
|
QUESTION_MARK,
|
||||||
|db| {
|
expr.span,
|
||||||
db.span_suggestion_with_applicability(
|
"this block may be rewritten with the `?` operator",
|
||||||
expr.span,
|
|db| {
|
||||||
"replace_it_with",
|
db.span_suggestion_with_applicability(
|
||||||
replacement_str,
|
expr.span,
|
||||||
Applicability::MaybeIncorrect, // snippet
|
"replace_it_with",
|
||||||
);
|
replacement_str,
|
||||||
}
|
Applicability::MaybeIncorrect, // snippet
|
||||||
)
|
);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue