Skip to content

Commit a3564ef

Browse files
committed
rustfmt
1 parent 3353277 commit a3564ef

File tree

11 files changed

+477
-337
lines changed

11 files changed

+477
-337
lines changed

build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::process::Command;
88
struct Some {}
99

1010
impl<E> From<E> for Some
11-
where E: Error
11+
where
12+
E: Error,
1213
{
1314
fn from(_: E) -> Some {
1415
Some {}
@@ -32,7 +33,8 @@ fn commit_info() -> String {
3233
}
3334

3435
fn commit_hash() -> Result<String, Some> {
35-
let output = Command::new("git").args(&["rev-parse", "--short", "HEAD"])
36+
let output = Command::new("git")
37+
.args(&["rev-parse", "--short", "HEAD"])
3638
.output()?;
3739

3840
if output.status.success() {

src/cargo.rs

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ pub struct Rustflags {
1818

1919
impl Rustflags {
2020
pub fn hash<H>(&self, hasher: &mut H)
21-
where H: Hasher
21+
where
22+
H: Hasher,
2223
{
2324
let mut flags = self.flags.iter();
2425

2526
while let Some(flag) = flags.next() {
2627
if flag == "-C" {
2728
if let Some(next) = flags.next() {
2829
if next.starts_with("link-arg=") ||
29-
next.starts_with("link-args=") {
30+
next.starts_with("link-args=")
31+
{
3032
// don't hash linker arguments
3133
} else {
3234
flag.hash(hasher);
@@ -74,35 +76,41 @@ impl Rustdocflags {
7476
}
7577
}
7678

77-
pub fn rustdocflags(config: Option<&Config>,
78-
target: &str)
79-
-> Result<Rustdocflags> {
79+
pub fn rustdocflags(
80+
config: Option<&Config>,
81+
target: &str,
82+
) -> Result<Rustdocflags> {
8083
flags(config, target, "rustdocflags").map(|fs| Rustdocflags { flags: fs })
8184
}
8285

8386

8487
/// Returns the flags for `tool` (e.g. rustflags)
8588
///
8689
/// This looks into the environment and into `.cargo/config`
87-
fn flags(config: Option<&Config>,
88-
target: &str,
89-
tool: &str)
90-
-> Result<Vec<String>> {
90+
fn flags(
91+
config: Option<&Config>,
92+
target: &str,
93+
tool: &str,
94+
) -> Result<Vec<String>> {
9195
if let Some(t) = env::var_os(tool.to_uppercase()) {
92-
return Ok(t.to_string_lossy()
93-
.split_whitespace()
94-
.map(|w| w.to_owned())
95-
.collect());
96+
return Ok(
97+
t.to_string_lossy()
98+
.split_whitespace()
99+
.map(|w| w.to_owned())
100+
.collect(),
101+
);
96102
}
97103

98104
if let Some(config) = config.as_ref() {
99105
let mut build = false;
100-
if let Some(array) = config.table
106+
if let Some(array) = config
107+
.table
101108
.lookup(&format!("target.{}.{}", target, tool))
102109
.or_else(|| {
103110
build = true;
104111
config.table.lookup(&format!("build.{}", tool))
105-
}) {
112+
})
113+
{
106114
let mut flags = vec![];
107115

108116
let mut error = false;
@@ -121,14 +129,18 @@ fn flags(config: Option<&Config>,
121129

122130
if error {
123131
if build {
124-
Err(format!(".cargo/config: build.{} must be an array \
132+
Err(format!(
133+
".cargo/config: build.{} must be an array \
125134
of strings",
126-
tool))?
135+
tool
136+
))?
127137
} else {
128-
Err(format!(".cargo/config: target.{}.{} must be an \
138+
Err(format!(
139+
".cargo/config: target.{}.{} must be an \
129140
array of strings",
130-
target,
131-
tool))?
141+
target,
142+
tool
143+
))?
132144
}
133145
} else {
134146
Ok(flags)
@@ -142,7 +154,9 @@ fn flags(config: Option<&Config>,
142154
}
143155

144156
pub fn run(args: &Args, verbose: bool) -> Result<ExitStatus> {
145-
Command::new("cargo").args(args.all()).run_and_get_status(verbose)
157+
Command::new("cargo").args(args.all()).run_and_get_status(
158+
verbose,
159+
)
146160
}
147161

148162
pub struct Config {
@@ -152,22 +166,26 @@ pub struct Config {
152166
impl Config {
153167
pub fn target(&self) -> Result<Option<&str>> {
154168
if let Some(v) = self.table.lookup("build.target") {
155-
Ok(Some(v.as_str()
156-
.ok_or_else(|| {
157-
format!(".cargo/config: build.target must be a string")
158-
})?))
169+
Ok(Some(
170+
v.as_str().ok_or_else(
171+
|| format!(".cargo/config: build.target must be a string"),
172+
)?,
173+
))
159174
} else {
160175
Ok(None)
161176
}
162177
}
163178
}
164179

165180
pub fn config() -> Result<Option<Config>> {
166-
let cd =
167-
env::current_dir().chain_err(|| "couldn't get the current directory")?;
181+
let cd = env::current_dir().chain_err(
182+
|| "couldn't get the current directory",
183+
)?;
168184

169185
if let Some(p) = util::search(&cd, ".cargo/config") {
170-
Ok(Some(Config { table: util::parse(&p.join(".cargo/config"))? }))
186+
Ok(Some(
187+
Config { table: util::parse(&p.join(".cargo/config"))? },
188+
))
171189
} else {
172190
Ok(None)
173191
}
@@ -179,7 +197,8 @@ pub struct Profile<'t> {
179197

180198
impl<'t> Profile<'t> {
181199
pub fn hash<H>(&self, hasher: &mut H)
182-
where H: Hasher
200+
where
201+
H: Hasher,
183202
{
184203
let mut v = self.table.clone();
185204

@@ -218,7 +237,9 @@ pub struct Toml {
218237
impl Toml {
219238
/// `profile.release` part of `Cargo.toml`
220239
pub fn profile(&self) -> Option<Profile> {
221-
self.table.lookup("profile.release").map(|t| Profile { table: t })
240+
self.table.lookup("profile.release").map(
241+
|t| Profile { table: t },
242+
)
222243
}
223244
}
224245

@@ -237,10 +258,13 @@ impl Root {
237258
}
238259

239260
pub fn root() -> Result<Option<Root>> {
240-
let cd =
241-
env::current_dir().chain_err(|| "couldn't get the current directory")?;
261+
let cd = env::current_dir().chain_err(
262+
|| "couldn't get the current directory",
263+
)?;
242264

243-
Ok(util::search(&cd, "Cargo.toml").map(|p| Root { path: p.to_owned() }))
265+
Ok(
266+
util::search(&cd, "Cargo.toml").map(|p| Root { path: p.to_owned() }),
267+
)
244268
}
245269

246270
#[derive(Clone, Copy, PartialEq)]

src/cli.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ impl Args {
2222
}
2323

2424
pub fn verbose(&self) -> bool {
25-
self.all.iter().any(|a| a == "--verbose" || a == "-v" || a == "-vv")
25+
self.all.iter().any(|a| {
26+
a == "--verbose" || a == "-v" || a == "-vv"
27+
})
2628
}
2729

2830
pub fn version(&self) -> bool {

src/extensions.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ impl CommandExt for Command {
1818
if status.success() {
1919
Ok(())
2020
} else {
21-
Err(format!("`{:?}` failed with exit code: {:?}",
22-
self,
23-
status.code()))?
21+
Err(format!(
22+
"`{:?}` failed with exit code: {:?}",
23+
self,
24+
status.code()
25+
))?
2426
}
2527
}
2628

@@ -30,8 +32,9 @@ impl CommandExt for Command {
3032
writeln!(io::stderr(), "+ {:?}", self).ok();
3133
}
3234

33-
self.status()
34-
.chain_err(|| format!("couldn't execute `{:?}`", self))
35+
self.status().chain_err(
36+
|| format!("couldn't execute `{:?}`", self),
37+
)
3538
}
3639

3740
/// Runs the command to completion and returns its stdout
@@ -40,18 +43,22 @@ impl CommandExt for Command {
4043
writeln!(io::stderr(), "+ {:?}", self).ok();
4144
}
4245

43-
let out = self.output()
44-
.chain_err(|| format!("couldn't execute `{:?}`", self))?;
46+
let out = self.output().chain_err(
47+
|| format!("couldn't execute `{:?}`", self),
48+
)?;
4549

4650
if out.status.success() {
47-
Ok(String::from_utf8(out.stdout).chain_err(|| {
48-
format!("`{:?}` output was not UTF-8",
49-
self)
50-
})?)
51+
Ok(
52+
String::from_utf8(out.stdout).chain_err(|| {
53+
format!("`{:?}` output was not UTF-8", self)
54+
})?,
55+
)
5156
} else {
52-
Err(format!("`{:?}` failed with exit code: {:?}",
53-
self,
54-
out.status.code()))?
57+
Err(format!(
58+
"`{:?}` failed with exit code: {:?}",
59+
self,
60+
out.status.code()
61+
))?
5562
}
5663
}
5764
}

0 commit comments

Comments
 (0)