Skip to content

Commit f00e844

Browse files
committed
feat: use span_lint_and_sugg
1 parent 34ad33c commit f00e844

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

clippy_lints/src/methods/or_then_unwrap.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use clippy_utils::diagnostics::span_lint_and_help;
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::ty::is_type_diagnostic_item;
33
use if_chain::if_chain;
4+
use rustc_errors::Applicability;
45
use rustc_hir::{Expr, ExprKind, QPath};
56
use rustc_lint::LateContext;
67
use rustc_span::{sym, Span};
@@ -40,13 +41,14 @@ pub(super) fn check<'tcx>(
4041
unwrap_expr.span
4142
};
4243

43-
span_lint_and_help(
44+
span_lint_and_sugg(
4445
cx,
4546
OR_THEN_UNWRAP,
4647
or_span.to(unwrap_span),
4748
title,
48-
None,
49-
"use `unwrap_or()` instead",
49+
"try this",
50+
"unwrap_or(...)".into(),
51+
Applicability::HasPlaceholders,
5052
);
5153
}
5254

tests/ui/or_then_unwrap.stderr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ error: .or(Some(…)).unwrap() found
22
--> $DIR/or_then_unwrap.rs:22:20
33
|
44
LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or(...)`
66
|
77
= note: `-D clippy::or-then-unwrap` implied by `-D warnings`
8-
= help: use `unwrap_or()` instead
98

109
error: .or(Ok(…)).unwrap() found
1110
--> $DIR/or_then_unwrap.rs:25:20
1211
|
1312
LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= help: use `unwrap_or()` instead
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or(...)`
1714

1815
error: aborting due to 2 previous errors
1916

0 commit comments

Comments
 (0)