From 14207503a80083e2b4ea6eabada46fbc8db27682 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 9 Aug 2018 09:41:32 +0200 Subject: [PATCH 01/12] Version checks are useless now that we ride the trains --- Cargo.toml | 4 --- build.rs | 87 ------------------------------------------------- min_version.txt | 7 ---- 3 files changed, 98 deletions(-) delete mode 100644 min_version.txt diff --git a/Cargo.toml b/Cargo.toml index 5b6900409028..798b713a07f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,9 +59,5 @@ derive-new = "0.5" # for more information. rustc-workspace-hack = "1.0.0" -[build-dependencies] -rustc_version = "0.2.2" -ansi_term = "0.11" - [features] debugging = [] diff --git a/build.rs b/build.rs index 9d05678f718c..3b9f217c8848 100644 --- a/build.rs +++ b/build.rs @@ -13,98 +13,11 @@ //! This build script was originally taken from the Rocket web framework: //! https://github.com/SergioBenitez/Rocket -use ansi_term::Colour::Red; -use rustc_version::{version_meta, version_meta_for, Channel, Version, VersionMeta}; use std::env; fn main() { - check_rustc_version(); - // Forward the profile to the main compilation println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap()); // Don't rebuild even if nothing changed println!("cargo:rerun-if-changed=build.rs"); } - -fn check_rustc_version() { - let string = include_str!("min_version.txt"); - let min_version_meta = version_meta_for(string).expect("Could not parse version string in min_version.txt"); - let current_version_meta = version_meta().expect("Could not retrieve current rustc version information from ENV"); - - let min_version = min_version_meta.clone().semver; - let min_date_str = min_version_meta - .clone() - .commit_date - .expect("min_version.txt does not contain a rustc commit date"); - - // Dev channel (rustc built from git) does not have any date or commit information in rustc -vV - // `current_version_meta.commit_date` would crash, so we return early here. - if current_version_meta.channel == Channel::Dev { - return; - } - - let current_version = current_version_meta.clone().semver; - let current_date_str = current_version_meta - .clone() - .commit_date - .expect("current rustc version information does not contain a rustc commit date"); - - let print_version_err = |version: &Version, date: &str| { - eprintln!( - "> {} {}. {} {}.\n", - "Installed rustc version is:", - format!("{} ({})", version, date), - "Minimum required rustc version:", - format!("{} ({})", min_version, min_date_str) - ); - }; - - if !correct_channel(¤t_version_meta) { - eprintln!( - "\n{} {}", - Red.bold().paint("error:"), - "Clippy requires a nightly version of Rust." - ); - print_version_err(¤t_version, &*current_date_str); - eprintln!( - "{}{}{}", - "See the README (", "https://github.com/rust-lang-nursery/rust-clippy#usage", ") for more information." - ); - panic!("Aborting compilation due to incompatible compiler.") - } - - let current_date = str_to_ymd(¤t_date_str).unwrap(); - let min_date = str_to_ymd(&min_date_str).unwrap(); - - if current_date < min_date { - eprintln!( - "\n{} {}", - Red.bold().paint("error:"), - "Clippy does not support this version of rustc nightly." - ); - eprintln!( - "> {}{}{}", - "Use `", "rustup update", "` or your preferred method to update Rust." - ); - print_version_err(¤t_version, &*current_date_str); - panic!("Aborting compilation due to incompatible compiler.") - } -} - -fn correct_channel(version_meta: &VersionMeta) -> bool { - match version_meta.channel { - Channel::Stable | Channel::Beta => false, - Channel::Nightly | Channel::Dev => true, - } -} - -/// Convert a string of %Y-%m-%d to a single u32 maintaining ordering. -fn str_to_ymd(ymd: &str) -> Option { - let ymd: Vec = ymd.split("-").filter_map(|s| s.parse::().ok()).collect(); - if ymd.len() != 3 { - return None; - } - - let (y, m, d) = (ymd[0], ymd[1], ymd[2]); - Some((y << 9) | (m << 5) | d) -} diff --git a/min_version.txt b/min_version.txt deleted file mode 100644 index bd6a57973fc5..000000000000 --- a/min_version.txt +++ /dev/null @@ -1,7 +0,0 @@ -rustc 1.28.0-nightly (e3bf634e0 2018-06-28) -binary: rustc -commit-hash: e3bf634e060bc2f8665878288bcea02008ca346e -commit-date: 2018-06-28 -host: x86_64-unknown-linux-gnu -release: 1.28.0-nightly -LLVM version: 6.0 From 246a77ebe8c9d640c76a82f3869c5272ba51346d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Thu, 15 Nov 2018 16:50:28 +0100 Subject: [PATCH 02/12] rustup https://github.com/rust-lang/rust/pull/55852/ --- clippy_lints/src/misc_early.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index a2fd487078e8..1f5973dad163 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -216,7 +216,7 @@ impl EarlyLintPass for MiscEarly { } } - fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) { + fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat, _: &mut bool) { if let PatKind::Struct(ref npat, ref pfields, _) = pat.node { let mut wilds = 0; let type_name = npat.segments From 2e26fdc2a86f03771a31b8a1e1a35cf8397cb69b Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Wed, 21 Nov 2018 13:33:42 +0100 Subject: [PATCH 03/12] Enable rustup clippy to refer to the correct documentation --- clippy_lints/src/utils/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 05356f8d3856..410819136bc2 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -507,8 +507,11 @@ impl<'a> DiagnosticWrapper<'a> { fn docs_link(&mut self, lint: &'static Lint) { if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() { self.0.help(&format!( - "for further information visit https://rust-lang-nursery.github.io/rust-clippy/v{}/index.html#{}", - env!("CARGO_PKG_VERSION"), + "for further information visit https://rust-lang-nursery.github.io/rust-clippy/{}/index.html#{}", + &option_env!("RUST_RELEASE_NUM").map_or("master".to_string(), |n| { + // extract just major + minor version and ignore patch versions + format!("rust-{}", n.rsplitn(2, '.').nth(1).unwrap()) + }), lint.name_lower().replacen("clippy::", "", 1) )); } From fd05696b9d8a42e4c7c44375795c280fae57c115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20S=CC=B6c=CC=B6h=CC=B6n=CC=B6e=CC=B6i=CC=B6d=CC=B6?= =?UTF-8?q?e=CC=B6r=20Scherer?= Date: Mon, 26 Nov 2018 13:39:09 +0100 Subject: [PATCH 04/12] Update mod.rs --- clippy_lints/src/utils/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 410819136bc2..b54f64dacf3a 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -507,7 +507,7 @@ impl<'a> DiagnosticWrapper<'a> { fn docs_link(&mut self, lint: &'static Lint) { if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() { self.0.help(&format!( - "for further information visit https://rust-lang-nursery.github.io/rust-clippy/{}/index.html#{}", + "for further information visit https://rust-lang.github.io/rust-clippy/{}/index.html#{}", &option_env!("RUST_RELEASE_NUM").map_or("master".to_string(), |n| { // extract just major + minor version and ignore patch versions format!("rust-{}", n.rsplitn(2, '.').nth(1).unwrap()) From 5d7c24f9b7eeee8e1d24e509785bacb070666baa Mon Sep 17 00:00:00 2001 From: Martins Polakovs Date: Sat, 23 Feb 2019 19:29:30 +0200 Subject: [PATCH 05/12] Fix ICE #3747 [Martins Polakovs, John Firebaugh] --- clippy_lints/src/functions.rs | 6 +++--- tests/ui/crashes/ice-3747.rs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/ui/crashes/ice-3747.rs diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 7ea01ad5ec95..b58587087968 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -150,7 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { let nodeid = cx.tcx.hir().hir_to_node_id(hir_id); self.check_raw_ptr(cx, unsafety, decl, body, nodeid); - self.check_line_number(cx, span); + self.check_line_number(cx, span, body); } fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem) { @@ -181,12 +181,12 @@ impl<'a, 'tcx> Functions { } } - fn check_line_number(self, cx: &LateContext<'_, '_>, span: Span) { + fn check_line_number(self, cx: &LateContext<'_, '_>, span: Span, body: &'tcx hir::Body) { if in_external_macro(cx.sess(), span) { return; } - let code_snippet = snippet(cx, span, ".."); + let code_snippet = snippet(cx, body.value.span, ".."); let mut line_count: u64 = 0; let mut in_comment = false; let mut code_in_line; diff --git a/tests/ui/crashes/ice-3747.rs b/tests/ui/crashes/ice-3747.rs new file mode 100644 index 000000000000..cdf018cbc88d --- /dev/null +++ b/tests/ui/crashes/ice-3747.rs @@ -0,0 +1,17 @@ +/// Test for https://github.com/rust-lang/rust-clippy/issues/3747 + +macro_rules! a { + ( $pub:tt $($attr:tt)* ) => { + $($attr)* $pub fn say_hello() {} + }; +} + +macro_rules! b { + () => { + a! { pub } + }; +} + +b! {} + +fn main() {} From e9cc540ab5606f3c3ce3e298e78df610ede3f7bb Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Tue, 26 Feb 2019 12:12:27 +0100 Subject: [PATCH 06/12] do not trigger redundant_closure when there is a difference in borrow level between closure parameter and "self" --- clippy_lints/src/eta_reduction.rs | 23 ++++++++++++++--------- tests/ui/eta.rs | 8 ++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 87a82b2a169e..59e6ec768fbc 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -129,18 +129,13 @@ fn get_ufcs_type_name( let actual_type_of_self = &cx.tables.node_type(self_arg.hir_id).sty; if let Some(trait_id) = cx.tcx.trait_of_item(method_def_id) { - //if the method expectes &self, ufcs requires explicit borrowing so closure can't be removed - return match (expected_type_of_self, actual_type_of_self) { - (ty::Ref(_, _, _), ty::Ref(_, _, _)) => Some(cx.tcx.item_path_str(trait_id)), - (l, r) => match (l, r) { - (ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _)) => None, - (_, _) => Some(cx.tcx.item_path_str(trait_id)), - }, - }; + if match_borrow_depth(expected_type_of_self, actual_type_of_self) { + return Some(cx.tcx.item_path_str(trait_id)); + } } cx.tcx.impl_of_method(method_def_id).and_then(|_| { - //a type may implicitly implement other types methods (e.g. Deref) + //a type may implicitly implement other type's methods (e.g. Deref) if match_types(expected_type_of_self, actual_type_of_self) { return Some(get_type_name(cx, &actual_type_of_self)); } @@ -148,6 +143,16 @@ fn get_ufcs_type_name( }) } +fn match_borrow_depth(lhs: &ty::TyKind<'_>, rhs: &ty::TyKind<'_>) -> bool { + match (lhs, rhs) { + (ty::Ref(_, t1, _), ty::Ref(_, t2, _)) => match_borrow_depth(&t1.sty, &t2.sty), + (l, r) => match (l, r) { + (ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _)) => false, + (_, _) => true, + }, + } +} + fn match_types(lhs: &ty::TyKind<'_>, rhs: &ty::TyKind<'_>) -> bool { match (lhs, rhs) { (ty::Bool, ty::Bool) diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index 6eeb093eae99..f777939c67d2 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -88,6 +88,14 @@ fn test_redundant_closures_containing_method_calls() { let c = Some(TestStruct { some_ref: &i }) .as_ref() .map(|c| c.to_ascii_uppercase()); + + fn test_different_borrow_levels(t: &[&T]) + where + T: TestTrait, + { + t.iter().filter(|x| x.trait_foo_ref()); + t.iter().map(|x| x.trait_foo_ref()); + } } fn meta(f: F) From 2b189d2d11106dcfde67376645141ca14a36680e Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 18 Apr 2019 21:58:07 -0700 Subject: [PATCH 07/12] Pin stable compiletest to 0.3.18 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c37104850273..c41f0f5856ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"} [dev-dependencies] clippy_dev = { version = "0.0.1", path = "clippy_dev" } cargo_metadata = "0.7.1" -compiletest_rs = "0.3.18" +compiletest_rs = "=0.3.18" lazy_static = "1.0" serde_derive = "1.0" clippy-mini-macro-test = { version = "0.2", path = "mini-macro" } From e29559fdfd685553cb4587eeaabb4d541c4e7885 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Mon, 4 Mar 2019 22:56:33 +0100 Subject: [PATCH 08/12] Don't trigger missing_const_for_fn in external macros As reported in #3841. Only fixes the part where it triggers on the `derive`. --- clippy_lints/src/missing_const_for_fn.rs | 4 ++-- tests/ui/missing_const_for_fn/cant_be_const.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 00a3de0632f8..bd9e8ce8b8df 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -2,7 +2,7 @@ use crate::utils::{is_entrypoint_fn, span_lint}; use rustc::hir; use rustc::hir::intravisit::FnKind; use rustc::hir::{Body, Constness, FnDecl, HirId}; -use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; +use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_tool_lint, lint_array}; use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn; use syntax_pos::Span; @@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn { ) { let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); - if is_entrypoint_fn(cx, def_id) { + if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id) { return; } diff --git a/tests/ui/missing_const_for_fn/cant_be_const.rs b/tests/ui/missing_const_for_fn/cant_be_const.rs index 36efe16b84f0..4a2e6adb8f06 100644 --- a/tests/ui/missing_const_for_fn/cant_be_const.rs +++ b/tests/ui/missing_const_for_fn/cant_be_const.rs @@ -55,3 +55,7 @@ trait Foo { 33 } } + +// Don't lint in external macros (derive) +#[derive(PartialEq, Eq)] +struct Point(isize, isize); From 5ab87dd8568208016a82a7d087292312af786921 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Tue, 5 Mar 2019 08:11:55 +0100 Subject: [PATCH 09/12] Fix missing_const_for_fn for impl trait methods --- clippy_lints/src/missing_const_for_fn.rs | 15 ++++++++++++++- tests/ui/missing_const_for_fn/cant_be_const.rs | 9 +++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index bd9e8ce8b8df..633105ff60bb 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -1,4 +1,5 @@ use crate::utils::{is_entrypoint_fn, span_lint}; +use if_chain::if_chain; use rustc::hir; use rustc::hir::intravisit::FnKind; use rustc::hir::{Body, Constness, FnDecl, HirId}; @@ -95,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn { } }, FnKind::Method(_, sig, ..) => { - if already_const(sig.header) { + if is_trait_method(cx, hir_id) || already_const(sig.header) { return; } }, @@ -114,6 +115,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn { } } +fn is_trait_method(cx: &LateContext<'_, '_>, hir_id: HirId) -> bool { + // Get the implemented trait for the current function + let parent_impl = cx.tcx.hir().get_parent_item(hir_id); + if_chain! { + if parent_impl != hir::CRATE_HIR_ID; + if let hir::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl); + if let hir::ItemKind::Impl(_, _, _, _, Some(_trait_ref), _, _) = &item.node; + then { return true; } + } + false +} + // We don't have to lint on something that's already `const` fn already_const(header: hir::FnHeader) -> bool { header.constness == Constness::Const diff --git a/tests/ui/missing_const_for_fn/cant_be_const.rs b/tests/ui/missing_const_for_fn/cant_be_const.rs index 4a2e6adb8f06..115cc954dc78 100644 --- a/tests/ui/missing_const_for_fn/cant_be_const.rs +++ b/tests/ui/missing_const_for_fn/cant_be_const.rs @@ -59,3 +59,12 @@ trait Foo { // Don't lint in external macros (derive) #[derive(PartialEq, Eq)] struct Point(isize, isize); + +impl std::ops::Add for Point { + type Output = Self; + + // Don't lint in trait impls of derived methods + fn add(self, other: Self) -> Self { + Point(self.0 + other.0, self.1 + other.1) + } +} From 9170ca3349fca483c2789dc26e0d7dabbbe822f5 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 16 May 2019 09:47:21 -0700 Subject: [PATCH 10/12] Backport #4101 https://github.com/rust-lang/rust-clippy/pull/4101 Splits up redundant_closure's method checking into a pedantic lint --- .travis.yml | 5 +++-- CHANGELOG.md | 1 + README.md | 2 +- appveyor.yml | 9 ++------- ci/base-tests.sh | 2 +- clippy_lints/src/eta_reduction.rs | 26 ++++++++++++++++++++++++-- clippy_lints/src/lib.rs | 1 + rust-toolchain | 2 +- tests/ui/eta.rs | 6 +++++- tests/ui/eta.stderr | 24 +++++++++++++----------- tests/ui/map_clone.fixed | 2 +- tests/ui/map_clone.rs | 2 +- 12 files changed, 54 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index acb5b9ae0d24..7a7315663851 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: rust -rust: nightly +rust: beta os: - linux @@ -17,6 +17,7 @@ branches: env: global: - RUST_BACKTRACE=1 + - RUSTC_BOOTSTRAP=1 install: - | @@ -90,7 +91,7 @@ matrix: script: - | rm rust-toolchain - ./setup-toolchain.sh + rustup override set beta export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib - | if [ -z ${INTEGRATION} ]; then diff --git a/CHANGELOG.md b/CHANGELOG.md index 7837b899b533..aca02b53d017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -978,6 +978,7 @@ All notable changes to this project will be documented in this file. [`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone [`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure [`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call +[`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls [`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern [`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching diff --git a/README.md b/README.md index 43b477d2cef3..523704a86f33 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 298 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 299 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/appveyor.yml b/appveyor.yml index c852cd8232e1..0bf74c6fe707 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,14 +16,8 @@ branches: install: - curl -sSf -o rustup-init.exe https://win.rustup.rs/ - - rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly + - rustup-init.exe -y --default-host %TARGET% --default-toolchain beta - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - - git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}' >rustc-hash.txt - - set /p RUSTC_HASH= LintArray { - lint_array!(REDUNDANT_CLOSURE) + lint_array!(REDUNDANT_CLOSURE, REDUNDANT_CLOSURE_FOR_METHOD_CALLS) } fn name(&self) -> &'static str { @@ -110,7 +132,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { if let Some(name) = get_ufcs_type_name(cx, method_def_id, &args[0]); then { - span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| { + span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure found", |db| { db.span_suggestion( expr.span, "remove closure as shown", diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d547e0a99b79..dca0badc29f2 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -611,6 +611,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { enum_glob_use::ENUM_GLOB_USE, enum_variants::MODULE_NAME_REPETITIONS, enum_variants::PUB_ENUM_VARIANT_NAMES, + eta_reduction::REDUNDANT_CLOSURE_FOR_METHOD_CALLS, functions::TOO_MANY_LINES, if_not_else::IF_NOT_ELSE, infinite_iter::MAYBE_INFINITE_ITER, diff --git a/rust-toolchain b/rust-toolchain index bf867e0ae5b6..65b2df87f7df 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly +beta diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index f777939c67d2..d65f8eaab1cb 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -7,7 +7,11 @@ clippy::option_map_unit_fn, clippy::trivially_copy_pass_by_ref )] -#![warn(clippy::redundant_closure, clippy::needless_borrow)] +#![warn( + clippy::redundant_closure, + clippy::redundant_closure_for_method_calls, + clippy::needless_borrow +)] use std::path::PathBuf; diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index 5f56cd7912a7..0d9f48d6f4a2 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -1,5 +1,5 @@ error: redundant closure found - --> $DIR/eta.rs:15:27 + --> $DIR/eta.rs:19:27 | LL | let a = Some(1u8).map(|a| foo(a)); | ^^^^^^^^^^ help: remove closure as shown: `foo` @@ -7,19 +7,19 @@ LL | let a = Some(1u8).map(|a| foo(a)); = note: `-D clippy::redundant-closure` implied by `-D warnings` error: redundant closure found - --> $DIR/eta.rs:16:10 + --> $DIR/eta.rs:20:10 | LL | meta(|a| foo(a)); | ^^^^^^^^^^ help: remove closure as shown: `foo` error: redundant closure found - --> $DIR/eta.rs:17:27 + --> $DIR/eta.rs:21:27 | LL | let c = Some(1u8).map(|a| {1+2; foo}(a)); | ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `{1+2; foo}` error: this expression borrows a reference that is immediately dereferenced by the compiler - --> $DIR/eta.rs:19:21 + --> $DIR/eta.rs:23:21 | LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted | ^^^ help: change this to: `&2` @@ -27,43 +27,45 @@ LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted = note: `-D clippy::needless-borrow` implied by `-D warnings` error: redundant closure found - --> $DIR/eta.rs:26:27 + --> $DIR/eta.rs:30:27 | LL | let e = Some(1u8).map(|a| generic(a)); | ^^^^^^^^^^^^^^ help: remove closure as shown: `generic` error: redundant closure found - --> $DIR/eta.rs:69:51 + --> $DIR/eta.rs:73:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); | ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo` + | + = note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings` error: redundant closure found - --> $DIR/eta.rs:71:51 + --> $DIR/eta.rs:75:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo()); | ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo` error: redundant closure found - --> $DIR/eta.rs:74:42 + --> $DIR/eta.rs:78:42 | LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear()); | ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear` error: redundant closure found - --> $DIR/eta.rs:79:29 + --> $DIR/eta.rs:83:29 | LL | let e = Some("str").map(|s| s.to_string()); | ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string` error: redundant closure found - --> $DIR/eta.rs:81:27 + --> $DIR/eta.rs:85:27 | LL | let e = Some('a').map(|s| s.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_uppercase` error: redundant closure found - --> $DIR/eta.rs:84:65 + --> $DIR/eta.rs:88:65 | LL | let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase` diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index d804e838d5a6..afd1568a3e11 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -3,7 +3,7 @@ #![allow(clippy::iter_cloned_collect)] #![allow(clippy::clone_on_copy)] #![allow(clippy::missing_docs_in_private_items)] -#![allow(clippy::redundant_closure)] +#![allow(clippy::redundant_closure_for_method_calls)] fn main() { let _: Vec = vec![5_i8; 6].iter().cloned().collect(); diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index d98cd939d8cc..deacaf4abe8b 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -3,7 +3,7 @@ #![allow(clippy::iter_cloned_collect)] #![allow(clippy::clone_on_copy)] #![allow(clippy::missing_docs_in_private_items)] -#![allow(clippy::redundant_closure)] +#![allow(clippy::redundant_closure_for_method_calls)] fn main() { let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); From 64a9f568e9b96c1843218200140c7029e6e27494 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 17 May 2019 13:19:28 +0200 Subject: [PATCH 11/12] Don't run dogfood on windows --- src/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index e0b2bcc72664..05e0c58f88d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,10 +86,9 @@ where }) .map(|p| ("CARGO_TARGET_DIR", p)); - // Run the dogfood tests directly on nightly cargo. This is required due - // to a bug in rustup.rs when running cargo on custom toolchains. See issue #3118. + // Don't run the dogfood tests on beta if std::env::var_os("CLIPPY_DOGFOOD").is_some() && cfg!(windows) { - args.insert(0, "+nightly".to_string()); + return Ok(()) } let exit_status = std::process::Command::new("cargo") From 28bde0638e2b28512d77cea2416cb44c1bbfdc05 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 17 May 2019 15:47:11 +0200 Subject: [PATCH 12/12] Don't require rustfmt on beta --- ci/base-tests.sh | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/ci/base-tests.sh b/ci/base-tests.sh index 187fc062fbf6..14b573454bbe 100755 --- a/ci/base-tests.sh +++ b/ci/base-tests.sh @@ -23,7 +23,6 @@ export CARGO_TARGET_DIR=`pwd`/target/ # Perform various checks for lint registration ./util/dev update_lints --check -cargo +nightly fmt --all -- --check # Check running clippy-driver without cargo ( @@ -50,29 +49,5 @@ cargo +nightly fmt --all -- --check # TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR ) -# make sure tests are formatted - -# some lints are sensitive to formatting, exclude some files -tests_need_reformatting="false" -# switch to nightly -rustup override set nightly -# avoid loop spam and allow cmds with exit status != 0 -set +ex - -for file in `find tests | grep "\.rs$"` ; do - rustfmt ${file} --check - if [ $? -ne 0 ]; then - echo "${file} needs reformatting!" - tests_need_reformatting="true" - fi -done - -set -ex # reset - -if [ "${tests_need_reformatting}" == "true" ] ; then - echo "Tests need reformatting!" - exit 2 -fi - # switch back to master # rustup override set master