Skip to content

Commit 451ef78

Browse files
committed
Use match_def_path instead of match_qpath
1 parent 5b7590f commit 451ef78

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

clippy_lints/src/create_dir.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_qpath, paths, snippet, span_lint_and_sugg};
1+
use crate::utils::{match_def_path, paths, snippet, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc_errors::Applicability;
44
use rustc_hir::{Expr, ExprKind};
@@ -33,7 +33,8 @@ impl LateLintPass<'_> for CreateDir {
3333
if_chain! {
3434
if let ExprKind::Call(ref func, ref args) = expr.kind;
3535
if let ExprKind::Path(ref path) = func.kind;
36-
if match_qpath(path, &paths::STD_FS_CREATE_DIR);
36+
if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id();
37+
if match_def_path(cx, def_id, &paths::STD_FS_CREATE_DIR);
3738
then {
3839
span_lint_and_sugg(
3940
cx,

tests/ui/create_dir.fixed

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
#![allow(unused_must_use)]
33
#![warn(clippy::create_dir)]
44

5-
fn not_create_dir() {}
5+
fn create_dir() {}
66

77
fn main() {
8+
// Should be warned
89
std::fs::create_dir_all("foo");
910
std::fs::create_dir_all("bar").unwrap();
1011

11-
not_create_dir();
12+
// Shouldn't be warned
13+
create_dir();
1214
std::fs::create_dir_all("foobar");
1315
}

tests/ui/create_dir.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
#![allow(unused_must_use)]
33
#![warn(clippy::create_dir)]
44

5-
fn not_create_dir() {}
5+
fn create_dir() {}
66

77
fn main() {
8+
// Should be warned
89
std::fs::create_dir("foo");
910
std::fs::create_dir("bar").unwrap();
1011

11-
not_create_dir();
12+
// Shouldn't be warned
13+
create_dir();
1214
std::fs::create_dir_all("foobar");
1315
}

tests/ui/create_dir.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: calling `std::fs::create_dir` where there may be a better way
2-
--> $DIR/create_dir.rs:8:5
2+
--> $DIR/create_dir.rs:9:5
33
|
44
LL | std::fs::create_dir("foo");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `std::fs::create_dir_all("foo")`
66
|
77
= note: `-D clippy::create-dir` implied by `-D warnings`
88

99
error: calling `std::fs::create_dir` where there may be a better way
10-
--> $DIR/create_dir.rs:9:5
10+
--> $DIR/create_dir.rs:10:5
1111
|
1212
LL | std::fs::create_dir("bar").unwrap();
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `std::fs::create_dir_all("bar")`

0 commit comments

Comments
 (0)