mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-24 12:54:00 +00:00
Merge pull request #1206 from masonium/fmt-extra-files
#1126 cargo-fmt processes bench, test, example files
This commit is contained in:
commit
898208414e
@ -97,7 +97,7 @@ fn format_crate(verbosity: Verbosity) -> Result<ExitStatus, std::io::Error> {
|
|||||||
|
|
||||||
// Currently only bin and lib files get formatted
|
// Currently only bin and lib files get formatted
|
||||||
let files: Vec<_> = targets.into_iter()
|
let files: Vec<_> = targets.into_iter()
|
||||||
.filter(|t| t.kind.is_lib() | t.kind.is_bin())
|
.filter(|t| t.kind.should_format())
|
||||||
.inspect(|t| {
|
.inspect(|t| {
|
||||||
if verbosity == Verbosity::Verbose {
|
if verbosity == Verbosity::Verbose {
|
||||||
println!("[{:?}] {:?}", t.kind, t.path)
|
println!("[{:?}] {:?}", t.kind, t.path)
|
||||||
@ -118,20 +118,17 @@ fn get_fmt_args() -> Vec<String> {
|
|||||||
enum TargetKind {
|
enum TargetKind {
|
||||||
Lib, // dylib, staticlib, lib
|
Lib, // dylib, staticlib, lib
|
||||||
Bin, // bin
|
Bin, // bin
|
||||||
Other, // test, plugin,...
|
Example, // example file
|
||||||
|
Test, // test file
|
||||||
|
Bench, // bench file
|
||||||
|
Other, // plugin,...
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TargetKind {
|
impl TargetKind {
|
||||||
fn is_lib(&self) -> bool {
|
fn should_format(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
TargetKind::Lib => true,
|
TargetKind::Lib | TargetKind::Bin | TargetKind::Example | TargetKind::Test |
|
||||||
_ => false,
|
TargetKind::Bench => true,
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_bin(&self) -> bool {
|
|
||||||
match *self {
|
|
||||||
TargetKind::Bin => true,
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,6 +168,9 @@ fn target_from_json(jtarget: &Json) -> Target {
|
|||||||
let kind = match kinds[0].as_string().unwrap() {
|
let kind = match kinds[0].as_string().unwrap() {
|
||||||
"bin" => TargetKind::Bin,
|
"bin" => TargetKind::Bin,
|
||||||
"lib" | "dylib" | "staticlib" => TargetKind::Lib,
|
"lib" | "dylib" | "staticlib" => TargetKind::Lib,
|
||||||
|
"test" => TargetKind::Test,
|
||||||
|
"example" => TargetKind::Example,
|
||||||
|
"bench" => TargetKind::Bench,
|
||||||
_ => TargetKind::Other,
|
_ => TargetKind::Other,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user