Change suggestion to create_dir_all({}) from std::fs::create_dir_all({})

This commit is contained in:
Hirochika Matsumoto 2020-09-08 23:35:19 +09:00
parent 451ef78803
commit a899ad2e12
4 changed files with 11 additions and 7 deletions

View file

@ -42,7 +42,7 @@ impl LateLintPass<'_> for CreateDir {
expr.span, expr.span,
"calling `std::fs::create_dir` where there may be a better way", "calling `std::fs::create_dir` where there may be a better way",
"consider calling `std::fs::create_dir_all` instead", "consider calling `std::fs::create_dir_all` instead",
format!("std::fs::create_dir_all({})", snippet(cx, args[0].span, "..")), format!("create_dir_all({})", snippet(cx, args[0].span, "..")),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
) )
} }

View file

@ -2,12 +2,14 @@
#![allow(unused_must_use)] #![allow(unused_must_use)]
#![warn(clippy::create_dir)] #![warn(clippy::create_dir)]
use std::fs::create_dir_all;
fn create_dir() {} fn create_dir() {}
fn main() { fn main() {
// Should be warned // Should be warned
std::fs::create_dir_all("foo"); create_dir_all("foo");
std::fs::create_dir_all("bar").unwrap(); create_dir_all("bar").unwrap();
// Shouldn't be warned // Shouldn't be warned
create_dir(); create_dir();

View file

@ -2,6 +2,8 @@
#![allow(unused_must_use)] #![allow(unused_must_use)]
#![warn(clippy::create_dir)] #![warn(clippy::create_dir)]
use std::fs::create_dir_all;
fn create_dir() {} fn create_dir() {}
fn main() { fn main() {

View file

@ -1,16 +1,16 @@
error: calling `std::fs::create_dir` where there may be a better way error: calling `std::fs::create_dir` where there may be a better way
--> $DIR/create_dir.rs:9:5 --> $DIR/create_dir.rs:11:5
| |
LL | std::fs::create_dir("foo"); LL | std::fs::create_dir("foo");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `std::fs::create_dir_all("foo")` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("foo")`
| |
= note: `-D clippy::create-dir` implied by `-D warnings` = note: `-D clippy::create-dir` implied by `-D warnings`
error: calling `std::fs::create_dir` where there may be a better way error: calling `std::fs::create_dir` where there may be a better way
--> $DIR/create_dir.rs:10:5 --> $DIR/create_dir.rs:12:5
| |
LL | std::fs::create_dir("bar").unwrap(); LL | std::fs::create_dir("bar").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `std::fs::create_dir_all("bar")` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("bar")`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors