|
1 |
| -use clippy_utils::diagnostics::span_lint; |
| 1 | +use clippy_utils::diagnostics::span_lint_and_sugg; |
| 2 | +use clippy_utils::source::snippet_with_applicability; |
2 | 3 | use clippy_utils::ty::is_type_diagnostic_item;
|
| 4 | +use rustc_errors::Applicability; |
3 | 5 | use rustc_hir::Expr;
|
4 | 6 | use rustc_lint::LateContext;
|
5 | 7 | use rustc_span::sym;
|
6 | 8 |
|
7 | 9 | use super::OPTION_TAKE_ON_TEMPORARY;
|
8 | 10 |
|
9 |
| -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, _recv: &'tcx Expr<'_>) { |
| 11 | +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &'tcx Expr<'_>) { |
10 | 12 | // Checks if expression type is equal to sym::Option and if the expr is not a syntactic place
|
11 | 13 | if is_expr_option(cx, expr) & !expr.is_syntactic_place_expr() {
|
12 |
| - span_lint(cx, OPTION_TAKE_ON_TEMPORARY, expr.span, "Format test"); |
| 14 | + let mut applicability = Applicability::MachineApplicable; |
| 15 | + span_lint_and_sugg( |
| 16 | + cx, |
| 17 | + OPTION_TAKE_ON_TEMPORARY, |
| 18 | + expr.span, |
| 19 | + "Called `Option::take()` on a temporary value", |
| 20 | + "try", |
| 21 | + format!( |
| 22 | + "{}", |
| 23 | + snippet_with_applicability(cx, recv.span, "..", &mut applicability) |
| 24 | + ), |
| 25 | + Applicability::MachineApplicable, |
| 26 | + ); |
13 | 27 | }
|
14 |
| - /* if_chain! { |
15 |
| - is_expr_option(cx, expr); |
16 |
| - then { |
17 |
| - span_lint( |
18 |
| - cx, |
19 |
| - OPTION_TAKE_ON_TEMPORARY, |
20 |
| - expr.span, |
21 |
| - "Format test" |
22 |
| - ); |
23 |
| - } |
24 |
| - };*/ |
25 | 28 | }
|
26 | 29 |
|
27 | 30 | fn is_expr_option(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
|
0 commit comments