Skip to content

Commit f43bc18

Browse files
committed
Commit with just personally changed files.
0 parents  commit f43bc18

File tree

6 files changed

+5097
-0
lines changed

6 files changed

+5097
-0
lines changed

clippy_lints/src/declared_lints.rs

+692
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use clippy_utils::diagnostics::span_lint_and_then;
2+
use clippy_utils::ty::is_type_diagnostic_item;
3+
use rustc_ast::ast::LitKind;
4+
use rustc_hir::{Expr, ExprKind};
5+
use rustc_lint::LateContext;
6+
use rustc_span::symbol::sym::Path;
7+
8+
use super::JOIN_ABSOLUTE_PATHS;
9+
10+
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, join_arg: &'tcx Expr<'tcx>) {
11+
let ty = cx.typeck_results().expr_ty(expr).peel_refs();
12+
if is_type_diagnostic_item(cx, ty, Path)
13+
&& let ExprKind::Lit(spanned) = &join_arg.kind
14+
&& let LitKind::Str(symbol, _) = spanned.node
15+
&& (symbol.as_str().starts_with('/') || symbol.as_str().starts_with('\\'))
16+
{
17+
span_lint_and_then(
18+
cx,
19+
JOIN_ABSOLUTE_PATHS,
20+
join_arg.span,
21+
"argument to `Path::join` starts with a path separator",
22+
|diag| {
23+
diag
24+
.note("joining a path starting with separator will replace the path instead")
25+
.help(r#"if this is unintentional, try removing the starting separator"#)
26+
.help(r#"if this is intentional, try creating a new Path instead"#);
27+
},
28+
);
29+
}
30+
}

0 commit comments

Comments
 (0)