1
1
use clippy_utils:: diagnostics:: span_lint_and_help;
2
- use clippy_utils:: ty:: is_type_diagnostic_item;
3
- use clippy_utils:: { match_qpath, paths, peel_hir_expr_refs} ;
4
- use rustc_hir:: { StmtKind , BorrowKind , Mutability , BindingAnnotation , PatKind , Expr , ExprKind } ;
2
+ use clippy_utils:: match_qpath;
3
+ use rustc_hir:: { Expr , ExprKind } ;
5
4
use rustc_lint:: { LateContext , LateLintPass } ;
6
5
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
7
6
use rustc_span:: sym;
8
7
9
8
declare_clippy_lint ! {
10
9
/// ### What it does
10
+ /// Checks for `PathBuf::From(format!(..))` calls.
11
11
///
12
12
/// ### Why is this bad?
13
+ /// It is not OS-agnostic, and can be harder to read.
13
14
///
14
15
/// ### Example
15
16
/// ```rust
16
- /// // example code where clippy issues a warning
17
+ /// PathBuf::from(format!("{}/foo/bar", base_path));
17
18
/// ```
18
19
/// Use instead:
19
20
/// ```rust
20
- /// // example code which does not raise clippy warning
21
+ /// Path::new(base_path).join("foo").join("bar")
21
22
/// ```
22
23
#[ clippy:: version = "1.62.0" ]
23
24
pub PATH_FROM_FORMAT ,
24
25
pedantic,
25
- "default lint description "
26
+ "builds a `PathBuf` from a format macro "
26
27
}
27
28
28
29
declare_lint_pass ! ( PathFromFormat => [ PATH_FROM_FORMAT ] ) ;
@@ -66,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
66
67
// if let Some(trailing_expr) = block.expr;
67
68
// if let ExprKind::Path(ref qpath5) = trailing_expr.kind;
68
69
// if match_qpath(qpath5, &["res"]);
69
- then {
70
+ then {
70
71
span_lint_and_help(
71
72
cx,
72
73
PATH_FROM_FORMAT ,
@@ -79,4 +80,4 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
79
80
}
80
81
}
81
82
}
82
- }
83
+ }
0 commit comments