Skip to content

Commit 98f97d3

Browse files
committed
Run rustfmt
1 parent 6738bef commit 98f97d3

File tree

7 files changed

+71
-73
lines changed

7 files changed

+71
-73
lines changed

src/cargo.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@ pub fn rustflags(config: Option<&Config>, target: &str) -> Result<Rustflags> {
6565
/// This looks into the environment and into `.cargo/config`
6666
fn flags(config: Option<&Config>, target: &str, tool: &str) -> Result<Vec<String>> {
6767
if let Some(t) = env::var_os(tool.to_uppercase()) {
68-
return Ok(
69-
t.to_string_lossy()
70-
.split_whitespace()
71-
.map(|w| w.to_owned())
72-
.collect(),
73-
);
68+
return Ok(t.to_string_lossy()
69+
.split_whitespace()
70+
.map(|w| w.to_owned())
71+
.collect());
7472
}
7573

7674
if let Some(config) = config.as_ref() {
@@ -109,8 +107,7 @@ fn flags(config: Option<&Config>, target: &str, tool: &str) -> Result<Vec<String
109107
Err(format!(
110108
".cargo/config: target.{}.{} must be an \
111109
array of strings",
112-
target,
113-
tool
110+
target, tool
114111
))?
115112
}
116113
} else {
@@ -126,6 +123,7 @@ fn flags(config: Option<&Config>, target: &str, tool: &str) -> Result<Vec<String
126123

127124
pub fn run(args: &Args, verbose: bool) -> Result<ExitStatus> {
128125
Command::new("cargo")
126+
.arg("build")
129127
.args(args.all())
130128
.run_and_get_status(verbose)
131129
}
@@ -137,8 +135,9 @@ pub struct Config {
137135
impl Config {
138136
pub fn target(&self) -> Result<Option<&str>> {
139137
if let Some(v) = self.table.lookup("build.target") {
140-
Ok(Some(v.as_str()
141-
.ok_or_else(|| format!(".cargo/config: build.target must be a string"))?))
138+
Ok(Some(v.as_str().ok_or_else(|| {
139+
format!(".cargo/config: build.target must be a string")
140+
})?))
142141
} else {
143142
Ok(None)
144143
}

src/flock.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,9 @@ impl Filesystem {
107107

108108
match state {
109109
State::Exclusive => {
110-
acquire(
111-
msg,
112-
&path,
113-
&|| f.try_lock_exclusive(),
114-
&|| f.lock_exclusive(),
115-
)?;
110+
acquire(msg, &path, &|| f.try_lock_exclusive(), &|| {
111+
f.lock_exclusive()
112+
})?;
116113
}
117114
State::Shared => {
118115
acquire(msg, &path, &|| f.try_lock_shared(), &|| f.lock_shared())?;

src/main.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
extern crate cargo_metadata;
12
#[macro_use]
23
extern crate error_chain;
34
extern crate fs2;
@@ -8,7 +9,6 @@ extern crate serde_json;
89
extern crate tempdir;
910
extern crate toml;
1011
extern crate walkdir;
11-
extern crate cargo_metadata;
1212

1313
use std::hash::{Hash, Hasher};
1414
use std::io::Write;
@@ -126,7 +126,7 @@ fn run() -> Result<Option<ExitStatus>> {
126126
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
127127
).unwrap();
128128
Ok(None)
129-
},
129+
}
130130
}
131131
}
132132

@@ -136,8 +136,8 @@ fn build(args: cli::Args) -> Result<(ExitStatus)> {
136136
let cd = CurrentDirectory::get()?;
137137
let config = cargo::config()?;
138138

139-
let metadata = cargo_metadata::metadata(args.manifest_path())
140-
.expect("cargo metadata invocation failed");
139+
let metadata =
140+
cargo_metadata::metadata(args.manifest_path()).expect("cargo metadata invocation failed");
141141
let root = Path::new(&metadata.workspace_root);
142142
let target_directory = Path::new(&metadata.target_directory);
143143

@@ -146,7 +146,7 @@ fn build(args: cli::Args) -> Result<(ExitStatus)> {
146146
let src = match meta.channel {
147147
Channel::Dev => rustc::Src::from_env().ok_or(
148148
"The XARGO_RUST_SRC env variable must be set and point to the \
149-
Rust source directory when working with the 'dev' channel",
149+
Rust source directory when working with the 'dev' channel",
150150
)?,
151151
Channel::Nightly => if let Some(src) = rustc::Src::from_env() {
152152
src
@@ -157,7 +157,7 @@ fn build(args: cli::Args) -> Result<(ExitStatus)> {
157157
writeln!(
158158
io::stderr(),
159159
"WARNING: the sysroot can't be built for the {:?} channel. \
160-
Switch to nightly.",
160+
Switch to nightly.",
161161
meta.channel
162162
).ok();
163163
return cargo::run(&args, verbose);
@@ -196,14 +196,7 @@ fn build(args: cli::Args) -> Result<(ExitStatus)> {
196196
&sysroot,
197197
verbose,
198198
)?;
199-
return xargo::run(
200-
&args,
201-
&cmode,
202-
rustflags,
203-
&home,
204-
&meta,
205-
verbose,
206-
);
199+
return xargo::run(&args, &cmode, rustflags, &home, &meta, verbose);
207200
}
208201

209202
cargo::run(&args, verbose)

src/rustc.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ pub fn sysroot(verbose: bool) -> Result<Sysroot> {
3434
command()
3535
.args(&["--print", "sysroot"])
3636
.run_and_get_stdout(verbose)
37-
.map(|l| {
38-
Sysroot {
39-
path: PathBuf::from(l.trim()),
40-
}
37+
.map(|l| Sysroot {
38+
path: PathBuf::from(l.trim()),
4139
})
4240
}
4341
/// Path to Rust source
@@ -47,10 +45,8 @@ pub struct Src {
4745

4846
impl Src {
4947
pub fn from_env() -> Option<Self> {
50-
env::var_os("XARGO_RUST_SRC").map(|s| {
51-
Src {
52-
path: PathBuf::from(s),
53-
}
48+
env::var_os("XARGO_RUST_SRC").map(|s| Src {
49+
path: PathBuf::from(s),
5450
})
5551
}
5652

@@ -101,17 +97,21 @@ impl Sysroot {
10197
}
10298
}
10399

104-
Err(
105-
"`rust-src` component not found. Run `rustup component add \
106-
rust-src`.",
107-
)?
100+
Err("`rust-src` component not found. Run `rustup component add \
101+
rust-src`.")?
108102
}
109103
}
110104

111105
#[derive(Debug)]
112106
pub enum Target {
113-
Builtin { triple: String },
114-
Custom { json: PathBuf, triple: String, orig_triple: String },
107+
Builtin {
108+
triple: String,
109+
},
110+
Custom {
111+
json: PathBuf,
112+
triple: String,
113+
orig_triple: String,
114+
},
115115
}
116116

117117
impl Target {
@@ -125,11 +125,16 @@ impl Target {
125125
if json.exists() {
126126
let file_stem = match json.file_stem().and_then(|stem| stem.to_str()) {
127127
Some(stem) => stem.into(),
128-
None => {
129-
bail!("target file name {:?} is empty or contains invalid unicode", json)
130-
}
128+
None => bail!(
129+
"target file name {:?} is empty or contains invalid unicode",
130+
json
131+
),
131132
};
132-
return Ok(Some(Target::Custom { json, triple: file_stem, orig_triple: triple }))
133+
return Ok(Some(Target::Custom {
134+
json,
135+
triple: file_stem,
136+
orig_triple: triple,
137+
}));
133138
}
134139
let mut json = cd.path().join(&triple);
135140
json.set_extension("json");
@@ -172,7 +177,9 @@ impl Target {
172177
pub fn orig_triple(&self) -> &str {
173178
match *self {
174179
Target::Builtin { ref triple } => triple,
175-
Target::Custom { ref orig_triple, .. } => orig_triple,
180+
Target::Custom {
181+
ref orig_triple, ..
182+
} => orig_triple,
176183
}
177184
}
178185

src/sysroot.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tempdir::TempDir;
99
use toml::{Table, Value};
1010

1111
use CompilationMode;
12-
use cargo::{Rustflags};
12+
use cargo::Rustflags;
1313
use errors::*;
1414
use extensions::CommandExt;
1515
use rustc::{Src, Sysroot, Target};
@@ -33,7 +33,7 @@ fn build(
3333
home: &Home,
3434
src: &Src,
3535
hash: u64,
36-
verbose: bool
36+
verbose: bool,
3737
) -> Result<()> {
3838
let rustlib = home.lock_rw(cmode.triple())?;
3939
rustlib
@@ -59,7 +59,7 @@ fn build_crate(
5959
ctoml: &cargo::Toml,
6060
home: &Home,
6161
dst: &Path,
62-
verbose: bool
62+
verbose: bool,
6363
) -> Result<()> {
6464
let td = TempDir::new("xargo").chain_err(|| "couldn't create a temporary directory")?;
6565
let td = td.path();
@@ -136,9 +136,9 @@ fn build_libcore(
136136
home: &Home,
137137
src: &Src,
138138
dst: &Path,
139-
verbose: bool
139+
verbose: bool,
140140
) -> Result<()> {
141-
const TOML: &'static str = r#"
141+
const TOML: &'static str = r#"
142142
[package]
143143
authors = ["The Rust Project Developers"]
144144
name = "sysroot"
@@ -165,9 +165,9 @@ fn build_libcompiler_builtins(
165165
home: &Home,
166166
src: &Src,
167167
dst: &Path,
168-
verbose: bool
168+
verbose: bool,
169169
) -> Result<()> {
170-
const TOML: &'static str = r#"
170+
const TOML: &'static str = r#"
171171
[package]
172172
authors = ["The Rust Project Developers"]
173173
name = "sysroot"
@@ -176,7 +176,10 @@ version = "0.0.0"
176176

177177
let mut stoml = TOML.to_owned();
178178

179-
let path = src.path().join("libcompiler_builtins").display().to_string();
179+
let path = src.path()
180+
.join("libcompiler_builtins")
181+
.display()
182+
.to_string();
180183
let mut compiler_builtin_dep = Table::new();
181184
compiler_builtin_dep.insert("path".to_owned(), Value::String(path));
182185
compiler_builtin_dep.insert("default-features".to_owned(), Value::Boolean(false));
@@ -188,7 +191,10 @@ version = "0.0.0"
188191
]),
189192
);
190193
let mut deps = Table::new();
191-
deps.insert("compiler_builtins".to_owned(), Value::Table(compiler_builtin_dep));
194+
deps.insert(
195+
"compiler_builtins".to_owned(),
196+
Value::Table(compiler_builtin_dep),
197+
);
192198
let mut map = Table::new();
193199
map.insert("dependencies".to_owned(), Value::Table(deps));
194200
stoml.push_str(&Value::Table(map).to_string());
@@ -202,9 +208,9 @@ fn build_liballoc(
202208
home: &Home,
203209
src: &Src,
204210
dst: &Path,
205-
verbose: bool
211+
verbose: bool,
206212
) -> Result<()> {
207-
const TOML: &'static str = r#"
213+
const TOML: &'static str = r#"
208214
[package]
209215
authors = ["The Rust Project Developers"]
210216
name = "alloc"

src/util.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ pub fn cp_r(src: &Path, dst: &Path) -> Result<()> {
3131
})?;
3232

3333
let dst_file = dst.join(relative_path);
34-
let metadata = e.metadata().chain_err(|| {
35-
format!("Could not retrieve metadata of `{}`", e.path().display())
36-
})?;
34+
let metadata = e.metadata()
35+
.chain_err(|| format!("Could not retrieve metadata of `{}`", e.path().display()))?;
3736

3837
if metadata.is_dir() {
3938
// ensure the destination directory exists
40-
fs::create_dir_all(&dst_file).chain_err(|| {
41-
format!("Could not create directory `{}`", dst_file.display())
42-
})?;
39+
fs::create_dir_all(&dst_file)
40+
.chain_err(|| format!("Could not create directory `{}`", dst_file.display()))?;
4341
} else {
4442
// else copy the file
4543
fs::copy(&src_file, &dst_file).chain_err(|| {
@@ -63,7 +61,9 @@ pub fn mkdir(path: &Path) -> Result<()> {
6361
pub fn parse(path: &Path) -> Result<Value> {
6462
Ok(Value::Table(Parser::new(&read(path)?)
6563
.parse()
66-
.ok_or_else(|| format!("{} is not valid TOML", path.display()))?))
64+
.ok_or_else(|| {
65+
format!("{} is not valid TOML", path.display())
66+
})?))
6767
}
6868

6969
pub fn read(path: &Path) -> Result<String> {

src/xargo.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,14 @@ impl Home {
5757
let fs = self.path(triple);
5858

5959
fs.open_ro(".sentinel", &format!("{}'s sysroot", triple))
60-
.chain_err(|| {
61-
format!("couldn't lock {}'s sysroot as read-only", triple)
62-
})
60+
.chain_err(|| format!("couldn't lock {}'s sysroot as read-only", triple))
6361
}
6462

6563
pub fn lock_rw(&self, triple: &str) -> Result<FileLock> {
6664
let fs = self.path(triple);
6765

6866
fs.open_rw(".sentinel", &format!("{}'s sysroot", triple))
69-
.chain_err(|| {
70-
format!("couldn't lock {}'s sysroot as read-only", triple)
71-
})
67+
.chain_err(|| format!("couldn't lock {}'s sysroot as read-only", triple))
7268
}
7369
}
7470

0 commit comments

Comments
 (0)