Skip to content

Commit 01f2b53

Browse files
committed
Auto merge of #4303 - mikerite:dev-fmt-20190728, r=flip1995
Make fmt test and command more robust changelog: none
2 parents d1b4fc9 + be646ac commit 01f2b53

File tree

14 files changed

+62
-23
lines changed

14 files changed

+62
-23
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
install:
2323
- |
2424
if [ -z ${INTEGRATION} ]; then
25-
# rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force
25+
rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force
2626
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
2727
. $HOME/.nvm/nvm.sh
2828
nvm install stable

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ install:
2222
- del rust-toolchain
2323
- cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
2424
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
25-
#- rustup component add rustfmt --toolchain nightly
25+
- rustup component add rustfmt --toolchain nightly || echo "rustfmt nightly is unavailable"
2626
- rustup default master
2727
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
2828
- rustc -V

clippy_dev/src/fmt.rs

+29
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum CliError {
1010
CommandFailed(String),
1111
IoError(io::Error),
1212
ProjectRootNotFound,
13+
RustfmtNotInstalled,
1314
WalkDirError(walkdir::Error),
1415
}
1516

@@ -36,6 +37,8 @@ pub fn run(check: bool, verbose: bool) {
3637

3738
let project_root = project_root()?;
3839

40+
rustfmt_test(context)?;
41+
3942
success &= cargo_fmt(context, project_root.as_path())?;
4043
success &= cargo_fmt(context, &project_root.join("clippy_dev"))?;
4144
success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;
@@ -69,6 +72,9 @@ pub fn run(check: bool, verbose: bool) {
6972
CliError::ProjectRootNotFound => {
7073
eprintln!("error: Can't determine root of project. Please run inside a Clippy working dir.");
7174
},
75+
CliError::RustfmtNotInstalled => {
76+
eprintln!("error: rustfmt nightly is not installed.");
77+
},
7278
CliError::WalkDirError(err) => {
7379
eprintln!("error: {}", err);
7480
},
@@ -139,6 +145,29 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
139145
Ok(success)
140146
}
141147

148+
fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
149+
let program = "rustfmt";
150+
let dir = std::env::current_dir()?;
151+
let args = &["+nightly", "--version"];
152+
153+
if context.verbose {
154+
println!("{}", format_command(&program, &dir, args));
155+
}
156+
157+
let output = Command::new(&program).current_dir(&dir).args(args.iter()).output()?;
158+
159+
if output.status.success() {
160+
Ok(())
161+
} else if std::str::from_utf8(&output.stderr)
162+
.unwrap_or("")
163+
.starts_with("error: 'rustfmt' is not installed")
164+
{
165+
Err(CliError::RustfmtNotInstalled)
166+
} else {
167+
Err(CliError::CommandFailed(format_command(&program, &dir, args)))
168+
}
169+
}
170+
142171
fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
143172
let mut args = vec!["+nightly".as_ref(), path.as_os_str()];
144173
if context.check {

clippy_lints/src/consts.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ impl PartialEq for Constant {
6565
f64::from(l).to_bits() == f64::from(r).to_bits()
6666
},
6767
(&Self::Bool(l), &Self::Bool(r)) => l == r,
68-
(&Self::Vec(ref l), &Self::Vec(ref r)) | (&Self::Tuple(ref l), &Self::Tuple(ref r)) => {
69-
l == r
70-
},
68+
(&Self::Vec(ref l), &Self::Vec(ref r)) | (&Self::Tuple(ref l), &Self::Tuple(ref r)) => l == r,
7169
(&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => ls == rs && lv == rv,
7270
// TODO: are there inter-type equalities?
7371
_ => false,

clippy_lints/src/misc_early.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl EarlyLintPass for MiscEarlyLints {
305305
name makes code comprehension and documentation more difficult",
306306
arg_name[1..].to_owned()
307307
),
308-
);;
308+
);
309309
}
310310
} else {
311311
registered_names.insert(arg_name, arg.pat.span);

clippy_lints/src/open_options.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
127127
} else {
128128
create = true
129129
}
130-
create_arg = create_arg || (arg == Argument::True);;
130+
create_arg = create_arg || (arg == Argument::True);
131131
},
132132
(OpenOption::Append, arg) => {
133133
if append {
@@ -140,7 +140,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
140140
} else {
141141
append = true
142142
}
143-
append_arg = append_arg || (arg == Argument::True);;
143+
append_arg = append_arg || (arg == Argument::True);
144144
},
145145
(OpenOption::Truncate, arg) => {
146146
if truncate {
@@ -166,7 +166,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
166166
} else {
167167
read = true
168168
}
169-
read_arg = read_arg || (arg == Argument::True);;
169+
read_arg = read_arg || (arg == Argument::True);
170170
},
171171
(OpenOption::Write, arg) => {
172172
if write {
@@ -179,7 +179,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
179179
} else {
180180
write = true
181181
}
182-
write_arg = write_arg || (arg == Argument::True);;
182+
write_arg = write_arg || (arg == Argument::True);
183183
},
184184
}
185185
}

clippy_lints/src/redundant_static_lifetimes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ impl EarlyLintPass for RedundantStaticLifetimes {
8181
if !in_macro_or_desugar(item.span) {
8282
if let ItemKind::Const(ref var_type, _) = item.node {
8383
self.visit_type(var_type, cx, "Constants have by default a `'static` lifetime");
84-
// Don't check associated consts because `'static` cannot be elided on those (issue #2438)
84+
// Don't check associated consts because `'static` cannot be elided on those (issue
85+
// #2438)
8586
}
8687

8788
if let ItemKind::Static(ref var_type, _, _) = item.node {

clippy_lints/src/use_self.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,12 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
222222
let last_but_one = &path.segments[path.segments.len() - 2];
223223
if last_but_one.ident.name != kw::SelfUpper {
224224
let enum_def_id = match path.res {
225-
Res::Def(DefKind::Variant, variant_def_id) =>
226-
self.cx.tcx.parent(variant_def_id),
225+
Res::Def(DefKind::Variant, variant_def_id) => self.cx.tcx.parent(variant_def_id),
227226
Res::Def(DefKind::Ctor(def::CtorOf::Variant, _), ctor_def_id) => {
228227
let variant_def_id = self.cx.tcx.parent(ctor_def_id);
229228
variant_def_id.and_then(|def_id| self.cx.tcx.parent(def_id))
230-
}
231-
_ => None
229+
},
230+
_ => None,
232231
};
233232

234233
if self.item_path.res.opt_def_id() == enum_def_id {

rustc_tools_util/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,4 @@ mod test {
154154
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 2, patch: 0 }"
155155
);
156156
}
157-
158157
}

tests/fmt.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1+
use std::process::Command;
2+
13
#[test]
2-
#[ignore]
34
fn fmt() {
45
if option_env!("RUSTC_TEST_SUITE").is_some() {
56
return;
67
}
78

9+
// Skip this test if rustup nightly is unavailable
10+
let rustup_output = Command::new("rustup")
11+
.args(&["component", "list", "--toolchain", "nightly"])
12+
.output()
13+
.unwrap();
14+
assert!(rustup_output.status.success());
15+
let component_output = String::from_utf8_lossy(&rustup_output.stdout);
16+
if !component_output.contains("rustfmt") {
17+
return;
18+
}
19+
820
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
921
let dev_dir = root_dir.join("clippy_dev");
10-
let output = std::process::Command::new("cargo")
22+
let output = Command::new("cargo")
1123
.current_dir(dev_dir)
1224
.args(&["+nightly", "run", "--", "fmt", "--check"])
1325
.output()

tests/ui/checked_unwrap/simple_conditionals.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ fn main() {
3131
if x.is_ok() {
3232
x = Err(());
3333
x.unwrap(); // not unnecessary because of mutation of x
34-
// it will always panic but the lint is not smart enough to see this (it only checks if conditions).
34+
// it will always panic but the lint is not smart enough to see this (it only
35+
// checks if conditions).
3536
} else {
3637
x = Ok(());
3738
x.unwrap_err(); // not unnecessary because of mutation of x
38-
// it will always panic but the lint is not smart enough to see this (it only checks if conditions).
39+
// it will always panic but the lint is not smart enough to see this (it
40+
// only checks if conditions).
3941
}
4042
}

tests/ui/drop_forget_ref.rs

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ fn test_owl_result() -> Result<(), ()> {
7878
Ok(())
7979
}
8080

81-
8281
#[allow(dead_code)]
8382
fn test_owl_result_2() -> Result<u8, ()> {
8483
produce_half_owl_error().map_err(|_| ())?;

tests/ui/use_self.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ mod nesting {
266266
enum Enum {
267267
A,
268268
B(u64),
269-
C { field: bool }
269+
C { field: bool },
270270
}
271271
impl Enum {
272272
fn method() {

tests/ui/use_self.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ mod nesting {
266266
enum Enum {
267267
A,
268268
B(u64),
269-
C { field: bool }
269+
C { field: bool },
270270
}
271271
impl Enum {
272272
fn method() {

0 commit comments

Comments
 (0)