File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change 1
- use clippy_utils:: diagnostics:: span_lint_and_help ;
1
+ use clippy_utils:: diagnostics:: span_lint_and_sugg ;
2
2
use clippy_utils:: ty:: is_type_diagnostic_item;
3
3
use if_chain:: if_chain;
4
+ use rustc_errors:: Applicability ;
4
5
use rustc_hir:: { Expr , ExprKind , QPath } ;
5
6
use rustc_lint:: LateContext ;
6
7
use rustc_span:: { sym, Span } ;
@@ -40,13 +41,14 @@ pub(super) fn check<'tcx>(
40
41
unwrap_expr. span
41
42
} ;
42
43
43
- span_lint_and_help (
44
+ span_lint_and_sugg (
44
45
cx,
45
46
OR_THEN_UNWRAP ,
46
47
or_span. to ( unwrap_span) ,
47
48
title,
48
- None ,
49
- "use `unwrap_or()` instead" ,
49
+ "try this" ,
50
+ "unwrap_or(...)" . into ( ) ,
51
+ Applicability :: HasPlaceholders ,
50
52
) ;
51
53
}
52
54
Original file line number Diff line number Diff line change @@ -2,18 +2,15 @@ error: .or(Some(…)).unwrap() found
2
2
--> $DIR/or_then_unwrap.rs:22:20
3
3
|
4
4
LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or(...)`
6
6
|
7
7
= note: `-D clippy::or-then-unwrap` implied by `-D warnings`
8
- = help: use `unwrap_or()` instead
9
8
10
9
error: .or(Ok(…)).unwrap() found
11
10
--> $DIR/or_then_unwrap.rs:25:20
12
11
|
13
12
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(...)`
17
14
18
15
error: aborting due to 2 previous errors
19
16
You can’t perform that action at this time.
0 commit comments