Skip to content

Commit 6b87037

Browse files
committed
Removed if chain.
1 parent 85f4ccc commit 6b87037

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
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;
23
use rustc_ast::ast::LitKind;
34
use rustc_errors::Applicability;
45
use rustc_hir::{Expr, ExprKind};
56
use rustc_lint::LateContext;
6-
use rustc_span::{symbol::sym::Path, Span};
7+
use rustc_span::symbol::sym::Path;
8+
use rustc_span::Span;
79

810
use super::JOIN_ABSOLUTE_PATHS;
911

1012
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, join_arg: &'tcx Expr<'tcx>, span: Span) {
1113
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+
};
3034
}

0 commit comments

Comments
 (0)