Skip to content

Commit 805fbeb

Browse files
committed
Auto merge of #5176 - alexcrichton:rustfmt, r=alexcrichton
Add `cargo fmt` to CI and delete `rustfmt.toml` This commit adds CI to run `cargo fmt` over Cargo itself as well as the internal `crates-io` crate. This should switch Cargo to the "default style" (aka whatever rustfmt spits out) and ensure that we keep it that way via CI. Hopefully this won't be too much of a bother to keep up and running in CI as it should just be a `cargo fmt` away!
2 parents 1eb4c8f + 3d85814 commit 805fbeb

File tree

189 files changed

+31476
-17028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+31476
-17028
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ matrix:
2828

2929
- env: TARGET=x86_64-unknown-linux-gnu
3030
ALT=i686-unknown-linux-gnu
31-
rust: nightly
31+
rust: nightly-2018-03-07
3232
install:
3333
- mdbook --help || cargo install mdbook --force
3434
script:
3535
- cargo test
3636
- cargo doc --no-deps
3737
- (cd src/doc && mdbook build --dest-dir ../../target/doc)
3838

39+
- before_script: rustup component add rustfmt-preview
40+
script: cargo fmt -- --write-mode diff
41+
3942
exclude:
4043
- rust: stable
4144

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ environment:
66

77
install:
88
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
9-
- rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly
9+
- rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly-2018-03-07
1010
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
1111
- rustup target add %OTHER_TARGET%
1212
- rustc -V

rustfmt.toml

-1
This file was deleted.

src/bin/cargo.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
extern crate cargo;
2+
extern crate clap;
23
extern crate env_logger;
34
#[macro_use]
45
extern crate failure;
56
extern crate git2_curl;
6-
extern crate toml;
77
extern crate log;
88
#[macro_use]
99
extern crate serde_derive;
1010
extern crate serde_json;
11-
extern crate clap;
11+
extern crate toml;
1212

1313
use std::env;
1414
use std::fs;
1515
use std::path::{Path, PathBuf};
1616
use std::collections::BTreeSet;
1717

1818
use cargo::core::shell::Shell;
19-
use cargo::util::{self, CliResult, lev_distance, Config, CargoResult};
19+
use cargo::util::{self, lev_distance, CargoResult, CliResult, Config};
2020
use cargo::util::{CliError, ProcessError};
2121

2222
mod cli;
2323
mod command_prelude;
2424
mod commands;
2525

26-
2726
fn main() {
2827
env_logger::init();
2928

@@ -53,7 +52,8 @@ fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<Str
5352
match config.get_string(&alias_name) {
5453
Ok(value) => {
5554
if let Some(record) = value {
56-
let alias_commands = record.val
55+
let alias_commands = record
56+
.val
5757
.split_whitespace()
5858
.map(|s| s.to_string())
5959
.collect();
@@ -63,10 +63,8 @@ fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<Str
6363
Err(_) => {
6464
let value = config.get_list(&alias_name)?;
6565
if let Some(record) = value {
66-
let alias_commands: Vec<String> = record.val
67-
.iter()
68-
.map(|s| s.0.to_string())
69-
.collect();
66+
let alias_commands: Vec<String> =
67+
record.val.iter().map(|s| s.0.to_string()).collect();
7068
result = Ok(Some(alias_commands));
7169
}
7270
}
@@ -95,10 +93,10 @@ fn list_commands(config: &Config) -> BTreeSet<(String, Option<String>)> {
9593
}
9694
if is_executable(entry.path()) {
9795
let end = filename.len() - suffix.len();
98-
commands.insert(
99-
(filename[prefix.len()..end].to_string(),
100-
Some(path.display().to_string()))
101-
);
96+
commands.insert((
97+
filename[prefix.len()..end].to_string(),
98+
Some(path.display().to_string()),
99+
));
102100
}
103101
}
104102
}
@@ -110,7 +108,6 @@ fn list_commands(config: &Config) -> BTreeSet<(String, Option<String>)> {
110108
commands
111109
}
112110

113-
114111
fn find_closest(config: &Config, cmd: &str) -> Option<String> {
115112
let cmds = list_commands(config);
116113
// Only consider candidates with a lev_distance of 3 or less so we don't
@@ -133,22 +130,23 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
133130
Some(command) => command,
134131
None => {
135132
let err = match find_closest(config, cmd) {
136-
Some(closest) => {
137-
format_err!("no such subcommand: `{}`\n\n\tDid you mean `{}`?\n",
138-
cmd,
139-
closest)
140-
}
133+
Some(closest) => format_err!(
134+
"no such subcommand: `{}`\n\n\tDid you mean `{}`?\n",
135+
cmd,
136+
closest
137+
),
141138
None => format_err!("no such subcommand: `{}`", cmd),
142139
};
143-
return Err(CliError::new(err, 101))
140+
return Err(CliError::new(err, 101));
144141
}
145142
};
146143

147144
let cargo_exe = config.cargo_exe()?;
148145
let err = match util::process(&command)
149146
.env(cargo::CARGO_ENV, cargo_exe)
150147
.args(&args[1..])
151-
.exec_replace() {
148+
.exec_replace()
149+
{
152150
Ok(()) => return Ok(()),
153151
Err(e) => e,
154152
};
@@ -170,7 +168,9 @@ fn is_executable<P: AsRef<Path>>(path: P) -> bool {
170168
}
171169
#[cfg(windows)]
172170
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
173-
fs::metadata(path).map(|metadata| metadata.is_file()).unwrap_or(false)
171+
fs::metadata(path)
172+
.map(|metadata| metadata.is_file())
173+
.unwrap_or(false)
174174
}
175175

176176
fn search_directories(config: &Config) -> Vec<PathBuf> {

src/bin/cli.rs

+43-40
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate clap;
22

33
use clap::{AppSettings, Arg, ArgMatches};
44

5-
use cargo::{self, Config, CliResult};
5+
use cargo::{self, CliResult, Config};
66

77
use super::list_commands;
88
use super::commands;
@@ -15,10 +15,10 @@ pub fn main(config: &mut Config) -> CliResult {
1515
let version = cargo::version();
1616
println!("{}", version);
1717
if is_verbose {
18-
println!("release: {}.{}.{}",
19-
version.major,
20-
version.minor,
21-
version.patch);
18+
println!(
19+
"release: {}.{}.{}",
20+
version.major, version.minor, version.patch
21+
);
2222
if let Some(ref cfg) = version.cfg_info {
2323
if let Some(ref ci) = cfg.commit_info {
2424
println!("commit-hash: {}", ci.commit_hash);
@@ -51,20 +51,24 @@ pub fn main(config: &mut Config) -> CliResult {
5151
return Ok(());
5252
}
5353

54-
if args.subcommand_name().is_none() {
55-
}
54+
if args.subcommand_name().is_none() {}
5655

5756
execute_subcommand(config, args)
5857
}
5958

6059
fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult {
6160
config.configure(
6261
args.occurrences_of("verbose") as u32,
63-
if args.is_present("quiet") { Some(true) } else { None },
62+
if args.is_present("quiet") {
63+
Some(true)
64+
} else {
65+
None
66+
},
6467
&args.value_of("color").map(|s| s.to_string()),
6568
args.is_present("frozen"),
6669
args.is_present("locked"),
67-
&args.values_of_lossy("unstable-features").unwrap_or_default(),
70+
&args.values_of_lossy("unstable-features")
71+
.unwrap_or_default(),
6872
)?;
6973

7074
let (cmd, args) = match args.subcommand() {
@@ -80,7 +84,11 @@ fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult {
8084
}
8185

8286
if let Some(mut alias) = super::aliased_command(config, cmd)? {
83-
alias.extend(args.values_of("").unwrap_or_default().map(|s| s.to_string()));
87+
alias.extend(
88+
args.values_of("")
89+
.unwrap_or_default()
90+
.map(|s| s.to_string()),
91+
);
8492
let args = cli()
8593
.setting(AppSettings::NoBinaryName)
8694
.get_matches_from_safe(alias)?;
@@ -91,7 +99,6 @@ fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult {
9199
super::execute_external_subcommand(config, cmd, &ext_args)
92100
}
93101

94-
95102
fn cli() -> App {
96103
let app = App::new("cargo")
97104
.settings(&[
@@ -101,7 +108,8 @@ fn cli() -> App {
101108
AppSettings::AllowExternalSubcommands,
102109
])
103110
.about("")
104-
.template("\
111+
.template(
112+
"\
105113
Rust's package manager
106114
107115
USAGE:
@@ -126,44 +134,39 @@ Some common cargo commands are (see all commands with --list):
126134
install Install a Rust binary
127135
uninstall Uninstall a Rust binary
128136
129-
See 'cargo help <command>' for more information on a specific command."
130-
)
131-
.arg(
132-
opt("version", "Print version info and exit")
133-
.short("V")
134-
)
135-
.arg(
136-
opt("list", "List installed commands")
137+
See 'cargo help <command>' for more information on a specific command.",
137138
)
139+
.arg(opt("version", "Print version info and exit").short("V"))
140+
.arg(opt("list", "List installed commands"))
141+
.arg(opt("explain", "Run `rustc --explain CODE`").value_name("CODE"))
138142
.arg(
139-
opt("explain", "Run `rustc --explain CODE`")
140-
.value_name("CODE")
141-
)
142-
.arg(
143-
opt("verbose", "Use verbose output (-vv very verbose/build.rs output)")
144-
.short("v").multiple(true).global(true)
143+
opt(
144+
"verbose",
145+
"Use verbose output (-vv very verbose/build.rs output)",
146+
).short("v")
147+
.multiple(true)
148+
.global(true),
145149
)
146150
.arg(
147151
opt("quiet", "No output printed to stdout")
148-
.short("q").global(true)
152+
.short("q")
153+
.global(true),
149154
)
150155
.arg(
151156
opt("color", "Coloring: auto, always, never")
152-
.value_name("WHEN").global(true)
153-
)
154-
.arg(
155-
opt("frozen", "Require Cargo.lock and cache are up to date")
156-
.global(true)
157-
)
158-
.arg(
159-
opt("locked", "Require Cargo.lock is up to date")
160-
.global(true)
157+
.value_name("WHEN")
158+
.global(true),
161159
)
160+
.arg(opt("frozen", "Require Cargo.lock and cache are up to date").global(true))
161+
.arg(opt("locked", "Require Cargo.lock is up to date").global(true))
162162
.arg(
163-
Arg::with_name("unstable-features").help("Unstable (nightly-only) flags to Cargo")
164-
.short("Z").value_name("FLAG").multiple(true).global(true)
163+
Arg::with_name("unstable-features")
164+
.help("Unstable (nightly-only) flags to Cargo")
165+
.short("Z")
166+
.value_name("FLAG")
167+
.multiple(true)
168+
.global(true),
165169
)
166-
.subcommands(commands::builtin())
167-
;
170+
.subcommands(commands::builtin());
168171
app
169172
}

0 commit comments

Comments
 (0)