Skip to content

Commit ff78801

Browse files
committed
Obey rustfmt
Reformatted the code using cargo fmt. Added a separate Travis job to the build matrix that fails when code is not properly formatted
1 parent 76beb88 commit ff78801

Some content is hidden

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

67 files changed

+5710
-3492
lines changed

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ language: rust
66

77
matrix:
88
include:
9+
# Separate build to detect if the code is formatted correctly
10+
- os: linux
11+
env: TARGET=x86_64-unknown-linux-gnu
12+
DOCKER=alexcrichton/rust-slave-dist:2015-10-20b
13+
RUSTFMT_ONLY=1
14+
NO_ADD=1
15+
ALLOW_PR=1
916
# Linux builds use the `rust-slave-dist` image so we link them against a
1017
# "super old glibc" to ensure that it runs on as many platforms as possible.
1118
- os: linux
@@ -124,6 +131,7 @@ branches:
124131

125132
install:
126133
- if [ -z "$NO_ADD" ]; then rustup target add $TARGET; fi
134+
- rustup component add rustfmt-preview
127135

128136
script:
129137
- mkdir -p target/$TARGET;
@@ -134,7 +142,7 @@ script:
134142
echo 'skipping master build';
135143
else
136144
if [ ! -z "$DOCKER" ]; then
137-
sh ci/build-run-docker.sh "$DOCKER" "$TARGET" "$SKIP_TESTS";
145+
sh ci/build-run-docker.sh "$DOCKER" "$TARGET" "$SKIP_TESTS" "$RUSTFMT_ONLY";
138146
else
139147
PATH=$HOME/rust/bin:$PATH sh ci/run.sh;
140148
fi

build.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::process::Command;
88
struct Ignore;
99

1010
impl<E> From<E> for Ignore
11-
where E: Error
11+
where
12+
E: Error,
1213
{
1314
fn from(_: E) -> Ignore {
1415
Ignore
@@ -35,18 +36,21 @@ fn commit_info() -> String {
3536
}
3637

3738
fn commit_hash() -> Result<String, Ignore> {
38-
Ok(try!(String::from_utf8(try!(Command::new("git")
39-
.args(&["rev-parse", "--short=9", "HEAD"])
40-
.output())
41-
.stdout)))
39+
Ok(try!(String::from_utf8(
40+
try!(
41+
Command::new("git")
42+
.args(&["rev-parse", "--short=9", "HEAD"])
43+
.output()
44+
).stdout
45+
)))
4246
}
4347

4448
fn commit_date() -> Result<String, Ignore> {
45-
Ok(try!(String::from_utf8(try!(Command::new("git")
46-
.args(&["log",
47-
"-1",
48-
"--date=short",
49-
"--pretty=format:%cd"])
50-
.output())
51-
.stdout)))
49+
Ok(try!(String::from_utf8(
50+
try!(
51+
Command::new("git")
52+
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
53+
.output()
54+
).stdout
55+
)))
5256
}

ci/build-run-docker.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mkdir -p target
77
DOCKER="$1"
88
TARGET="$2"
99
SKIP_TESTS="$3"
10+
RUSTFMT_ONLY="$4"
1011

1112
if [ -f "ci/docker/$DOCKER/Dockerfile" ]; then
1213
docker build -t "$DOCKER" "ci/docker/$DOCKER/"
@@ -21,6 +22,7 @@ docker run \
2122
--workdir /src \
2223
--env TARGET=$TARGET \
2324
--env SKIP_TESTS=$SKIP_TESTS \
25+
--env RUSTFMT_ONLY=$RUSTFMT_ONLY \
2426
$DOCKER \
2527
ci/run-docker.sh
2628

ci/run.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ echo "toolchain versions\n------------------"
77
rustc -vV
88
cargo -vV
99

10-
cargo build --locked -v --release --target $TARGET
10+
if [ ! -z "$RUSTFMT_ONLY" ]; then
11+
cargo fmt --all -- --write-mode=diff
12+
else
13+
cargo build --locked -v --release --target $TARGET
14+
fi
1115

1216
if [ -z "$SKIP_TESTS" ]; then
1317
cargo test --release -p download --target $TARGET

src/download/src/errors.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
error_chain! {
42
links { }
53

0 commit comments

Comments
 (0)