feat: use span_lint_and_sugg

This commit is contained in:
Max Baumann 2022-03-18 22:44:56 +01:00
parent 34ad33c57a
commit f00e844a1f
No known key found for this signature in database
GPG key ID: 20FA1609B03B1D6D
2 changed files with 8 additions and 9 deletions

View file

@ -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,
);
}

View file

@ -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