-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit with just personally changed files.
- Loading branch information
0 parents
commit f43bc18
Showing
6 changed files
with
5,097 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use clippy_utils::diagnostics::span_lint_and_then; | ||
use clippy_utils::ty::is_type_diagnostic_item; | ||
use rustc_ast::ast::LitKind; | ||
use rustc_hir::{Expr, ExprKind}; | ||
use rustc_lint::LateContext; | ||
use rustc_span::symbol::sym::Path; | ||
|
||
use super::JOIN_ABSOLUTE_PATHS; | ||
|
||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, join_arg: &'tcx Expr<'tcx>) { | ||
let ty = cx.typeck_results().expr_ty(expr).peel_refs(); | ||
if is_type_diagnostic_item(cx, ty, Path) | ||
&& let ExprKind::Lit(spanned) = &join_arg.kind | ||
&& let LitKind::Str(symbol, _) = spanned.node | ||
&& (symbol.as_str().starts_with('/') || symbol.as_str().starts_with('\\')) | ||
{ | ||
span_lint_and_then( | ||
cx, | ||
JOIN_ABSOLUTE_PATHS, | ||
join_arg.span, | ||
"argument to `Path::join` starts with a path separator", | ||
|diag| { | ||
diag | ||
.note("joining a path starting with separator will replace the path instead") | ||
.help(r#"if this is unintentional, try removing the starting separator"#) | ||
.help(r#"if this is intentional, try creating a new Path instead"#); | ||
}, | ||
); | ||
} | ||
} |
Oops, something went wrong.