11use 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 } ;
54use rustc_lint:: { LateContext , LateLintPass } ;
65use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
76use rustc_span:: sym;
87
98declare_clippy_lint ! {
109 /// ### What it does
10+ /// Checks for `PathBuf::From(format!(..))` calls.
1111 ///
1212 /// ### Why is this bad?
13+ /// It is not OS-agnostic, and can be harder to read.
1314 ///
1415 /// ### Example
1516 /// ```rust
16- /// // example code where clippy issues a warning
17+ /// PathBuf::from(format!("{}/foo/bar", base_path));
1718 /// ```
1819 /// Use instead:
1920 /// ```rust
20- /// // example code which does not raise clippy warning
21+ /// Path::new(base_path).join("foo").join("bar")
2122 /// ```
2223 #[ clippy:: version = "1.62.0" ]
2324 pub PATH_FROM_FORMAT ,
2425 pedantic,
25- "default lint description "
26+ "builds a `PathBuf` from a format macro "
2627}
2728
2829declare_lint_pass ! ( PathFromFormat => [ PATH_FROM_FORMAT ] ) ;
@@ -66,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
6667 // if let Some(trailing_expr) = block.expr;
6768 // if let ExprKind::Path(ref qpath5) = trailing_expr.kind;
6869 // if match_qpath(qpath5, &["res"]);
69- then {
70+ then {
7071 span_lint_and_help(
7172 cx,
7273 PATH_FROM_FORMAT ,
@@ -79,4 +80,4 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
7980 }
8081 }
8182 }
82- }
83+ }
0 commit comments