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