diff --git a/.gitignore b/.gitignore index a6b636709c52..33ecb63593cd 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ Cargo.lock # gh pages docs util/gh-pages/lints.json + +# rustfmt backups +*.rs.bk diff --git a/.travis.yml b/.travis.yml index ef97bd57e2f5..052a543bfd57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,10 +17,14 @@ install: - nvm install stable - nvm use stable - npm install remark-cli remark-lint + # || true, because we cache rustfmt and don't want to crash on the next travis run + # due to rustfmt already being installed + - (cargo install rustfmt || true) script: - remark -f README.md > /dev/null - python util/update_lints.py -c + - PATH=$PATH:~/.cargo/bin cargo fmt -- --write-mode=diff - set -e - cargo build --features debugging - cargo test --features debugging diff --git a/rustfmt.toml b/rustfmt.toml index c0695c04126e..6daad2b65bd9 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,4 +2,5 @@ max_width = 120 ideal_width = 100 fn_args_density = "Compressed" fn_call_width = 80 -fn_args_paren_newline = false \ No newline at end of file +fn_args_paren_newline = false +match_block_trailing_comma = true diff --git a/src/main.rs b/src/main.rs index a839bbad3417..89db653929c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,30 +38,17 @@ impl ClippyCompilerCalls { } impl<'a> CompilerCalls<'a> for ClippyCompilerCalls { - fn early_callback(&mut self, - matches: &getopts::Matches, - sopts: &config::Options, - cfg: &ast::CrateConfig, - descriptions: &rustc_errors::registry::Registry, - output: ErrorOutputType) + fn early_callback(&mut self, matches: &getopts::Matches, sopts: &config::Options, cfg: &ast::CrateConfig, + descriptions: &rustc_errors::registry::Registry, output: ErrorOutputType) -> Compilation { self.default.early_callback(matches, sopts, cfg, descriptions, output) } - fn no_input(&mut self, - matches: &getopts::Matches, - sopts: &config::Options, - cfg: &ast::CrateConfig, - odir: &Option, - ofile: &Option, - descriptions: &rustc_errors::registry::Registry) + fn no_input(&mut self, matches: &getopts::Matches, sopts: &config::Options, cfg: &ast::CrateConfig, + odir: &Option, ofile: &Option, descriptions: &rustc_errors::registry::Registry) -> Option<(Input, Option)> { self.default.no_input(matches, sopts, cfg, odir, ofile, descriptions) } - fn late_callback(&mut self, - matches: &getopts::Matches, - sess: &Session, - input: &Input, - odir: &Option, + fn late_callback(&mut self, matches: &getopts::Matches, sess: &Session, input: &Input, odir: &Option, ofile: &Option) -> Compilation { self.default.late_callback(matches, sess, input, odir, ofile) @@ -73,7 +60,12 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls { let old = std::mem::replace(&mut control.after_parse.callback, box |_| {}); control.after_parse.callback = Box::new(move |state| { { - let mut registry = rustc_plugin::registry::Registry::new(state.session, state.krate.as_ref().expect("at this compilation stage the krate must be parsed").span); + let mut registry = rustc_plugin::registry::Registry::new(state.session, + state.krate + .as_ref() + .expect("at this compilation stage \ + the krate must be parsed") + .span); registry.args_hidden = Some(Vec::new()); clippy_lints::register_plugins(&mut registry); @@ -153,7 +145,7 @@ pub fn main() { if env::var("CLIPPY_DOGFOOD").map(|_| true).unwrap_or(false) { panic!("yummy"); } - + // Check for version and help flags even when invoked as 'cargo-clippy' if std::env::args().any(|a| a == "--help" || a == "-h") { show_help(); @@ -184,14 +176,16 @@ pub fn main() { let current_dir = std::env::current_dir(); - let package_index = metadata.packages.iter() + let package_index = metadata.packages + .iter() .position(|package| { let package_manifest_path = Path::new(&package.manifest_path); if let Some(ref manifest_path) = manifest_path { package_manifest_path == manifest_path } else { let current_dir = current_dir.as_ref().expect("could not read current directory"); - let package_manifest_directory = package_manifest_path.parent().expect("could not find parent directory of package manifest"); + let package_manifest_directory = package_manifest_path.parent() + .expect("could not find parent directory of package manifest"); package_manifest_directory == current_dir } }) @@ -205,7 +199,8 @@ pub fn main() { std::process::exit(code); } } else if ["bin", "example", "test", "bench"].contains(&&**first) { - if let Err(code) = process(vec![format!("--{}", first), target.name].into_iter().chain(args), &dep_path) { + if let Err(code) = process(vec![format!("--{}", first), target.name].into_iter().chain(args), + &dep_path) { std::process::exit(code); } } @@ -285,8 +280,10 @@ fn process(old_args: I, dep_path: P) -> Result<(), i32> let exit_status = std::process::Command::new("cargo") .args(&args) .env("RUSTC", path) - .spawn().expect("could not run cargo") - .wait().expect("failed to wait for cargo?"); + .spawn() + .expect("could not run cargo") + .wait() + .expect("failed to wait for cargo?"); if exit_status.success() { Ok(()) diff --git a/tests/ice_exacte_size.rs b/tests/ice_exacte_size.rs index 37e3b4ebe7a9..eeab3a2bec59 100644 --- a/tests/ice_exacte_size.rs +++ b/tests/ice_exacte_size.rs @@ -14,4 +14,4 @@ impl Iterator for Foo { } } -impl ExactSizeIterator for Foo { } +impl ExactSizeIterator for Foo {} diff --git a/tests/issue-825.rs b/tests/issue-825.rs index 76b0250ca0e1..87cbb72f5857 100644 --- a/tests/issue-825.rs +++ b/tests/issue-825.rs @@ -5,19 +5,10 @@ // this should compile in a reasonable amount of time fn rust_type_id(name: String) { - if "bool" == &name[..] || - "uint" == &name[..] || - "u8" == &name[..] || - "u16" == &name[..] || - "u32" == &name[..] || - "f32" == &name[..] || - "f64" == &name[..] || - "i8" == &name[..] || - "i16" == &name[..] || - "i32" == &name[..] || - "i64" == &name[..] || - "Self" == &name[..] || - "str" == &name[..] { + if "bool" == &name[..] || "uint" == &name[..] || "u8" == &name[..] || "u16" == &name[..] || + "u32" == &name[..] || "f32" == &name[..] || "f64" == &name[..] || "i8" == &name[..] || + "i16" == &name[..] || "i32" == &name[..] || "i64" == &name[..] || + "Self" == &name[..] || "str" == &name[..] { unreachable!(); } } diff --git a/tests/trim_multiline.rs b/tests/trim_multiline.rs index 90f1c76fb80e..d6de36bfca73 100644 --- a/tests/trim_multiline.rs +++ b/tests/trim_multiline.rs @@ -13,6 +13,7 @@ fn test_single_line() { } #[test] +#[cfg_attr(rustfmt, rustfmt_skip)] fn test_block() { assert_eq!("\ if x { @@ -37,6 +38,7 @@ if x { } #[test] +#[cfg_attr(rustfmt, rustfmt_skip)] fn test_empty_line() { assert_eq!("\ if x {