Skip to content

Commit 643bb6d

Browse files
committed
run rustfmt
1 parent 0d180f4 commit 643bb6d

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed

rustfmt-core/rustfmt-bin/build.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ fn main() {
2828
// (git not installed or if this is not a git repository) just return an empty string.
2929
fn commit_info() -> String {
3030
match (channel(), commit_hash(), commit_date()) {
31-
(channel, Some(hash), Some(date)) => {
32-
format!("{}-{} ({} {})", option_env!("CARGO_PKG_VERSION")
33-
.unwrap_or("unknown"), channel, hash.trim_end(), date)
34-
},
31+
(channel, Some(hash), Some(date)) => format!(
32+
"{}-{} ({} {})",
33+
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"),
34+
channel,
35+
hash.trim_end(),
36+
date
37+
),
3538
_ => String::new(),
3639
}
3740
}

rustfmt-core/rustfmt-bin/src/bin/main.rs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate lazy_static;
55
use std::collections::HashMap;
66
use std::env;
77
use std::fmt;
8-
use std::io::{self, stdout, Error as IoError, Read, Write, stdin};
8+
use std::io::{self, stdin, stdout, Error as IoError, Read, Write};
99
use std::path::{Path, PathBuf};
1010
use std::str::FromStr;
1111

@@ -41,7 +41,7 @@ fn main() {
4141

4242
/// Format Rust code
4343
#[derive(Debug, StructOpt, Clone)]
44-
#[structopt(name = "rustfmt", version = include_str!(concat!(env!("OUT_DIR"), "/version-info.txt")))]
44+
#[structopt(name = "rustfmt", version = include_str!(concat!(env!("OUT_DIR"),"/version-info.txt")))]
4545
struct Opt {
4646
/// Run in 'check' mode.
4747
///
@@ -50,8 +50,8 @@ struct Opt {
5050
#[structopt(short, long)]
5151
check: bool,
5252
/// Specify the format of rustfmt's output.
53-
#[cfg_attr(nightly, structopt(long, name= "files|stdout|checkstyle|json"))]
54-
#[cfg_attr(not(nightly), structopt(long, name= "files|stdout"))]
53+
#[cfg_attr(nightly, structopt(long, name = "files|stdout|checkstyle|json"))]
54+
#[cfg_attr(not(nightly), structopt(long, name = "files|stdout"))]
5555
emit: Option<Emit>,
5656
/// A path to the configuration file.
5757
#[structopt(long = "config-path", parse(from_os_str))]
@@ -92,7 +92,6 @@ struct Opt {
9292
verbose: bool,
9393

9494
// Nightly-only options.
95-
9695
/// Limit formatting to specified ranges.
9796
///
9897
/// If you want to restrict reformatting to specific sets of lines, you can
@@ -124,7 +123,6 @@ struct Opt {
124123
error_on_unformatted: bool,
125124

126125
// Positional arguments.
127-
128126
#[structopt(parse(from_os_str))]
129127
files: Vec<PathBuf>,
130128
}
@@ -148,22 +146,23 @@ impl FromStr for InlineConfig {
148146

149147
s.split(',')
150148
.map(
151-
|key_val| match key_val.char_indices().find(|(_, ch)| *ch == '=') {
152-
Some((middle, _)) => {
153-
let (key, val) = (&key_val[..middle], &key_val[middle + 1..]);
154-
if !Config::is_valid_key_val(key, val) {
155-
Err(format_err!("invalid key=val pair: `{}`", key_val))
156-
} else {
157-
Ok((key.to_string(), val.to_string()))
149+
|key_val| match key_val.char_indices().find(|(_, ch)| *ch == '=') {
150+
Some((middle, _)) => {
151+
let (key, val) = (&key_val[..middle], &key_val[middle + 1..]);
152+
if !Config::is_valid_key_val(key, val) {
153+
Err(format_err!("invalid key=val pair: `{}`", key_val))
154+
} else {
155+
Ok((key.to_string(), val.to_string()))
156+
}
158157
}
159-
}
160158

161-
None => Err(format_err!(
159+
None => Err(format_err!(
162160
"--config expects comma-separated list of key=val pairs, found `{}`",
163161
key_val
164162
)),
165-
},
166-
).collect::<Result<HashMap<_, _>, _>>()
163+
},
164+
)
165+
.collect::<Result<HashMap<_, _>, _>>()
167166
.map(|map| InlineConfig(map, false))
168167
}
169168
}
@@ -183,7 +182,10 @@ impl FromStr for PrintConfig {
183182
"default" => Ok(PrintConfig::Default),
184183
"minimal" => Ok(PrintConfig::Minimal),
185184
"current" => Ok(PrintConfig::Current),
186-
_ => Err(format!("expected one of [current,default,minimal], found `{}`", s)),
185+
_ => Err(format!(
186+
"expected one of [current,default,minimal], found `{}`",
187+
s
188+
)),
187189
}
188190
}
189191
}
@@ -280,7 +282,6 @@ impl Opt {
280282
}
281283
}
282284

283-
284285
/// Rustfmt operations errors.
285286
#[derive(Error, Debug)]
286287
pub enum OperationError {
@@ -347,7 +348,9 @@ impl CliOptions for Opt {
347348
fn execute(mut opt: Opt) -> Result<i32> {
348349
opt.verify()?;
349350

350-
if opt.inline_config.as_ref().map_or(false, |inline_configs| inline_configs.iter().any(InlineConfig::is_help)) {
351+
if opt.inline_config.as_ref().map_or(false, |inline_configs| {
352+
inline_configs.iter().any(InlineConfig::is_help)
353+
}) {
351354
Config::print_docs(&mut stdout(), cfg!(nightly));
352355
return Ok(0);
353356
}
@@ -369,10 +372,12 @@ fn print_default_config() -> Result<i32> {
369372
}
370373

371374
fn print_config(opt: &Opt, print_config: PrintConfig) -> Result<i32> {
372-
let (config, config_path) =
373-
load_config(env::current_dir().ok().as_ref().map(PathBuf::as_path), Some(opt))?;
374-
let actual_config = FileConfigPairIter::new(&opt, config_path.is_some())
375-
.find_map(|pair| match pair.config {
375+
let (config, config_path) = load_config(
376+
env::current_dir().ok().as_ref().map(PathBuf::as_path),
377+
Some(opt),
378+
)?;
379+
let actual_config =
380+
FileConfigPairIter::new(&opt, config_path.is_some()).find_map(|pair| match pair.config {
376381
FileConfig::Local(config, Some(_)) => Some(config),
377382
_ => None,
378383
});
@@ -436,8 +441,7 @@ struct FileConfigPairIter<'a> {
436441
opt: &'a Opt,
437442
}
438443

439-
impl<'a> FileConfigPairIter<'a>
440-
{
444+
impl<'a> FileConfigPairIter<'a> {
441445
fn new(opt: &'a Opt, has_config_from_commandline: bool) -> Self {
442446
FileConfigPairIter {
443447
has_config_from_commandline,
@@ -447,8 +451,7 @@ impl<'a> FileConfigPairIter<'a>
447451
}
448452
}
449453

450-
impl<'a> Iterator for FileConfigPairIter<'a>
451-
{
454+
impl<'a> Iterator for FileConfigPairIter<'a> {
452455
type Item = FileConfigPair<'a>;
453456

454457
fn next(&mut self) -> Option<Self::Item> {
@@ -461,13 +464,11 @@ impl<'a> Iterator for FileConfigPairIter<'a>
461464
FileConfig::Local(local_config, config_path)
462465
};
463466

464-
Some(FileConfigPair {file, config})
467+
Some(FileConfigPair { file, config })
465468
}
466469
}
467470

468-
fn format(
469-
opt: Opt,
470-
) -> Result<i32> {
471+
fn format(opt: Opt) -> Result<i32> {
471472
if opt.files.is_empty() {
472473
let mut buf = String::new();
473474
stdin().read_to_string(&mut buf)?;

rustfmt-core/rustfmt-config/src/config_type.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,3 @@ macro_rules! is_nightly_channel {
340340
option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
341341
};
342342
}
343-

rustfmt-core/rustfmt-config/src/file_lines.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ impl FileLines {
251251
Some(ref map) => map,
252252
};
253253

254-
match canonicalize_path_string(file_name).ok().and_then(|file| map.get(&file)) {
254+
match canonicalize_path_string(file_name)
255+
.ok()
256+
.and_then(|file| map.get(&file))
257+
{
255258
Some(ranges) => ranges.iter().any(f),
256259
None => false,
257260
}

rustfmt-core/rustfmt-config/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,7 @@ mod test {
428428

429429
let used_options = config.used_options();
430430
let toml = used_options.to_toml().unwrap();
431-
assert_eq!(
432-
toml,
433-
"merge_derives = false\n"
434-
);
431+
assert_eq!(toml, "merge_derives = false\n");
435432
}
436433

437434
#[test]

rustfmt-core/rustfmt-emitter/src/diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustfmt_configuration::Config;
22

3-
use crate::rustfmt_diff::{make_diff, print_diff};
43
use super::*;
4+
use crate::rustfmt_diff::{make_diff, print_diff};
55

66
pub struct DiffEmitter {
77
config: Config,

rustfmt-core/rustfmt-emitter/src/rustfmt_diff.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,5 +424,4 @@ mod test {
424424
let diff = make_diff("a\nb\nc\nd", "a\nb\nc\nd", 3);
425425
assert_eq!(diff, vec![]);
426426
}
427-
428427
}

rustfmt-core/rustfmt-lib/src/closures.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ fn is_block_closure_forced(
415415
false
416416
} else {
417417
if let ast::ExprKind::Match(..) = expr.kind {
418-
let is_move_closure_without_brace =
419-
capture == ast::CaptureBy::Value && !context.snippet(expr.span).trim().starts_with("{");
418+
let is_move_closure_without_brace = capture == ast::CaptureBy::Value
419+
&& !context.snippet(expr.span).trim().starts_with("{");
420420

421421
is_block_closure_forced_inner(expr) || is_move_closure_without_brace
422422
} else {

rustfmt-core/rustfmt-lib/src/stmt.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,5 @@ fn format_stmt(
107107
}
108108
ast::StmtKind::Mac(..) | ast::StmtKind::Item(..) => None,
109109
};
110-
result.and_then(|res| {
111-
recover_comment_removed(res, stmt.span(), context)
112-
})
110+
result.and_then(|res| recover_comment_removed(res, stmt.span(), context))
113111
}

rustfmt-core/rustfmt-lib/src/test/configuration_snippet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use std::path::{Path, PathBuf};
66

77
use rustfmt_emitter::rustfmt_diff::{make_diff, Mismatch};
88

9+
use super::{print_mismatches, write_message, DIFF_CONTEXT_SIZE};
910
use crate::config::{Config, EmitMode, Verbosity};
1011
use crate::{Input, Session};
11-
use super::{print_mismatches, write_message, DIFF_CONTEXT_SIZE};
1212

1313
const CONFIGURATIONS_FILE_NAME: &str = "../../Configurations.md";
1414

0 commit comments

Comments
 (0)