feat: use span_lint_and_sugg
This commit is contained in:
parent
34ad33c57a
commit
f00e844a1f
|
@ -1,6 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_help;
|
||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::ty::is_type_diagnostic_item;
|
||||
use if_chain::if_chain;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Expr, ExprKind, QPath};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_span::{sym, Span};
|
||||
|
@ -40,13 +41,14 @@ pub(super) fn check<'tcx>(
|
|||
unwrap_expr.span
|
||||
};
|
||||
|
||||
span_lint_and_help(
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
OR_THEN_UNWRAP,
|
||||
or_span.to(unwrap_span),
|
||||
title,
|
||||
None,
|
||||
"use `unwrap_or()` instead",
|
||||
"try this",
|
||||
"unwrap_or(...)".into(),
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,18 +2,15 @@ error: .or(Some(…)).unwrap() found
|
|||
--> $DIR/or_then_unwrap.rs:22:20
|
||||
|
|
||||
LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or(...)`
|
||||
|
|
||||
= note: `-D clippy::or-then-unwrap` implied by `-D warnings`
|
||||
= help: use `unwrap_or()` instead
|
||||
|
||||
error: .or(Ok(…)).unwrap() found
|
||||
--> $DIR/or_then_unwrap.rs:25:20
|
||||
|
|
||||
LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: use `unwrap_or()` instead
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or(...)`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue