diff options
| author | Max Baumann <max@bmn.dev> | 2022-03-18 22:44:56 +0100 |
|---|---|---|
| committer | Max Baumann <max@bmn.dev> | 2022-03-18 22:44:56 +0100 |
| commit | f00e844a1f3b7e6d8a5d84e90baa37b0cebeac67 (patch) | |
| tree | f144c3f35473794a800d8a85ef86be95e337c7d2 | |
| parent | 34ad33c57aa9db1b0c8473925affef08fadc7b8a (diff) | |
| download | rust-f00e844a1f3b7e6d8a5d84e90baa37b0cebeac67.tar.gz rust-f00e844a1f3b7e6d8a5d84e90baa37b0cebeac67.zip | |
feat: use span_lint_and_sugg
| -rw-r--r-- | clippy_lints/src/methods/or_then_unwrap.rs | 10 | ||||
| -rw-r--r-- | tests/ui/or_then_unwrap.stderr | 7 |
2 files changed, 8 insertions, 9 deletions
diff --git a/clippy_lints/src/methods/or_then_unwrap.rs b/clippy_lints/src/methods/or_then_unwrap.rs index 02fa5887f67..578f898da78 100644 --- a/clippy_lints/src/methods/or_then_unwrap.rs +++ b/clippy_lints/src/methods/or_then_unwrap.rs @@ -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, ); } diff --git a/tests/ui/or_then_unwrap.stderr b/tests/ui/or_then_unwrap.stderr index fdd718b3580..7eade84bd65 100644 --- a/tests/ui/or_then_unwrap.stderr +++ b/tests/ui/or_then_unwrap.stderr @@ -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 |
