|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_sugg; |
2 | | -use rustc_lint::{LateContext}; |
3 | 2 | use rustc_ast::ast::LitKind; |
4 | 3 | use rustc_errors::Applicability; |
5 | 4 | use rustc_hir::{Expr, ExprKind}; |
| 5 | +use rustc_lint::LateContext; |
6 | 6 | use rustc_span::Span; |
7 | 7 |
|
8 | 8 | use super::PATH_JOIN_CORRECTION; |
9 | 9 |
|
10 | | - |
11 | | -pub(super) fn check<'tcx>( |
12 | | - cx: &LateContext<'tcx>, |
13 | | - expr: &'tcx Expr<'tcx>, |
14 | | - join_arg: &'tcx Expr<'tcx>, |
15 | | - span: Span, |
16 | | -) { |
17 | | - let applicability = Applicability::MachineApplicable; |
18 | | - if_chain!( |
19 | | - if let ExprKind::Lit(spanned) = &join_arg.kind; |
20 | | - if let LitKind::Str(symbol, _) = spanned.node; |
21 | | - if symbol.as_str().starts_with('/'); |
22 | | - then { |
23 | | - span_lint_and_sugg( |
24 | | - cx, |
25 | | - PATH_JOIN_CORRECTION, |
26 | | - span.with_hi(expr.span.hi()), |
27 | | - r#"argument in join called on path contains a starting '/'"#, |
28 | | - "try removing first '/'", |
29 | | - "join(\"your/path/here\")".to_owned(), |
30 | | - applicability |
31 | | - ); |
32 | | - } |
33 | | - ); |
| 10 | +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, join_arg: &'tcx Expr<'tcx>, span: Span) { |
| 11 | + let applicability = Applicability::MachineApplicable; |
| 12 | + if_chain!( |
| 13 | + if let ExprKind::Lit(spanned) = &join_arg.kind; |
| 14 | + if let LitKind::Str(symbol, _) = spanned.node; |
| 15 | + if symbol.as_str().starts_with('/'); |
| 16 | + then { |
| 17 | + span_lint_and_sugg( |
| 18 | + cx, |
| 19 | + PATH_JOIN_CORRECTION, |
| 20 | + span.with_hi(expr.span.hi()), |
| 21 | + r#"argument in join called on path contains a starting '/'"#, |
| 22 | + "try removing first '/'", |
| 23 | + "join(\"your/path/here\")".to_owned(), |
| 24 | + applicability |
| 25 | + ); |
| 26 | + } |
| 27 | + ); |
34 | 28 | } |
0 commit comments