use crate::utils;
use if_chain::if_chain;
-use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
if let ExprKind::Path(ref els_call_qpath) = els_expr.kind;
if utils::match_qpath(els_call_qpath, &utils::paths::OPTION_NONE);
then {
- let mut applicability = Applicability::MachineApplicable;
- let cond_snip = utils::snippet_with_applicability(cx, cond.span, "[condition]", &mut applicability);
- let arg_snip = utils::snippet_with_applicability(cx, then_arg.span, "", &mut applicability);
- let sugg = format!(
- "{}.then(|| {{ /* snippet */ {} }})",
+ let cond_snip = utils::snippet(cx, cond.span, "[condition]");
+ let arg_snip = utils::snippet(cx, then_arg.span, "");
+ let help = format!(
+ "consider using `bool::then` like: `{}.then(|| {{ /* snippet */ {} }})`",
cond_snip,
arg_snip,
);
- utils::span_lint_and_sugg(
+ utils::span_lint_and_help(
cx,
IF_THEN_SOME_ELSE_NONE,
expr.span,
"this could be simplified with `bool::then`",
- "try this",
- sugg,
- applicability,
+ None,
+ &help,
);
}
}
LL | | } else {
LL | | None
LL | | };
- | |_____^ help: try this: `foo().then(|| { /* snippet */ "foo" })`
+ | |_____^
|
= note: `-D clippy::if-then-some-else-none` implied by `-D warnings`
+ = help: consider using `bool::then` like: `foo().then(|| { /* snippet */ "foo" })`
error: this could be simplified with `bool::then`
--> $DIR/if_then_some_else_none.rs:66:13
LL | let _ = if foo() {
| _____________^
LL | | println!("true!");
-LL | | Some("foo")
+LL | | Some(150)
LL | | } else {
LL | | None
LL | | };
- | |_____^ help: try this: `foo().then(|| { /* snippet */ "foo" })`
+ | |_____^
+ |
+ = help: consider using `bool::then` like: `foo().then(|| { /* snippet */ 150 })`
error: aborting due to 2 previous errors