Skip to content

Commit de2b8d9

Browse files
committed
Merge pull request #960 from rust-lang-nursery/big-closures
Block indent large closures and field/method chains
2 parents 9188ec0 + fcd2021 commit de2b8d9

26 files changed

+843
-460
lines changed

bootstrap.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Make sure you double check the diffs after running this script - with great
4+
# power comes great responsibility.
5+
# We deliberately avoid reformatting files with rustfmt comment directives.
6+
7+
cargo build
8+
9+
target/debug/rustfmt --write-mode=overwrite src/lib.rs
10+
target/debug/rustfmt --write-mode=overwrite src/bin/rustfmt.rs
11+
target/debug/rustfmt --write-mode=overwrite src/bin/cargo-fmt.rs
12+
target/debug/rustfmt --write-mode=overwrite tests/system.rs
13+
14+
for filename in tests/target/*.rs; do
15+
if ! grep -q "rustfmt-" "$filename"; then
16+
target/debug/rustfmt --write-mode=overwrite $filename
17+
fi
18+
done

src/bin/cargo-fmt.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ fn format_crate(verbosity: Verbosity) -> Result<ExitStatus, std::io::Error> {
9898

9999
// Currently only bin and lib files get formatted
100100
let files: Vec<_> = targets.into_iter()
101-
.filter(|t| t.kind.is_lib() | t.kind.is_bin())
102-
.inspect(|t| {
103-
if verbosity == Verbosity::Verbose {
104-
println!("[{:?}] {:?}", t.kind, t.path)
105-
}
106-
})
107-
.map(|t| t.path)
108-
.collect();
101+
.filter(|t| t.kind.is_lib() | t.kind.is_bin())
102+
.inspect(|t| {
103+
if verbosity == Verbosity::Verbose {
104+
println!("[{:?}] {:?}", t.kind, t.path)
105+
}
106+
})
107+
.map(|t| t.path)
108+
.collect();
109109

110110
format_files(&files, &get_fmt_args(), verbosity)
111111
}
@@ -201,9 +201,9 @@ fn format_files(files: &Vec<PathBuf>,
201201
println!("");
202202
}
203203
let mut command = try!(Command::new("rustfmt")
204-
.stdout(stdout)
205-
.args(files)
206-
.args(fmt_args)
207-
.spawn());
204+
.stdout(stdout)
205+
.args(files)
206+
.args(fmt_args)
207+
.spawn());
208208
command.wait()
209209
}

src/bin/rustfmt.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
191191
Operation::Stdin { input, config_path } => {
192192
// try to read config from local directory
193193
let (mut config, _) = match_cli_path_or_file(config_path, &env::current_dir().unwrap())
194-
.expect("Error resolving config");
194+
.expect("Error resolving config");
195195

196196
// write_mode is always Plain for Stdin.
197197
config.write_mode = WriteMode::Plain;
@@ -205,8 +205,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
205205
// Load the config path file if provided
206206
if let Some(config_file) = config_path {
207207
let (cfg_tmp, path_tmp) = resolve_config(config_file.as_ref())
208-
.expect(&format!("Error resolving config for {:?}",
209-
config_file));
208+
.expect(&format!("Error resolving config for {:?}", config_file));
210209
config = cfg_tmp;
211210
path = path_tmp;
212211
};
@@ -219,9 +218,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
219218
// Check the file directory if the config-path could not be read or not provided
220219
if path.is_none() {
221220
let (config_tmp, path_tmp) = resolve_config(file.parent().unwrap())
222-
.expect(&format!("Error resolving config \
223-
for {}",
224-
file.display()));
221+
.expect(&format!("Error resolving config for {}", file.display()));
225222
if let Some(path) = path_tmp.as_ref() {
226223
println!("Using rustfmt config file {} for {}",
227224
path.display(),
@@ -301,13 +298,13 @@ fn determine_operation(matches: &Matches) -> FmtResult<Operation> {
301298

302299
// Read the config_path and convert to parent dir if a file is provided.
303300
let config_path: Option<PathBuf> = matches.opt_str("config-path")
304-
.map(PathBuf::from)
305-
.and_then(|dir| {
306-
if dir.is_file() {
307-
return dir.parent().map(|v| v.into());
308-
}
309-
Some(dir)
310-
});
301+
.map(PathBuf::from)
302+
.and_then(|dir| {
303+
if dir.is_file() {
304+
return dir.parent().map(|v| v.into());
305+
}
306+
Some(dir)
307+
});
311308

312309
// if no file argument is supplied, read from stdin
313310
if matches.free.is_empty() {

0 commit comments

Comments
 (0)