about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/methods/or_then_unwrap.rs10
-rw-r--r--tests/ui/or_then_unwrap.stderr7
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