Skip to content

Commit 265318d

Browse files
committed
Auto merge of rust-lang#4104 - Manishearth:beta-backports, r=flip1995
Backport rust-lang#4101 to beta This lint has been causing lots of problems. I'll check up on other potential beta backports when I build the new changelog r? @oli-obk
2 parents 37f5c1e + 28bde06 commit 265318d

File tree

13 files changed

+56
-56
lines changed

13 files changed

+56
-56
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: rust
22

3-
rust: nightly
3+
rust: beta
44

55
os:
66
- linux
@@ -17,6 +17,7 @@ branches:
1717
env:
1818
global:
1919
- RUST_BACKTRACE=1
20+
- RUSTC_BOOTSTRAP=1
2021

2122
install:
2223
- |
@@ -90,7 +91,7 @@ matrix:
9091
script:
9192
- |
9293
rm rust-toolchain
93-
./setup-toolchain.sh
94+
rustup override set beta
9495
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
9596
- |
9697
if [ -z ${INTEGRATION} ]; then

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ All notable changes to this project will be documented in this file.
978978
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
979979
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
980980
[`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
981+
[`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
981982
[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
982983
[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern
983984
[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
99

10-
[There are 298 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 299 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1111

1212
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1313

appveyor.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ branches:
1616

1717
install:
1818
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
19-
- rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly
19+
- rustup-init.exe -y --default-host %TARGET% --default-toolchain beta
2020
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
21-
- git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}' >rustc-hash.txt
22-
- set /p RUSTC_HASH=<rustc-hash.txt
23-
- del rust-toolchain
24-
- cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
25-
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
26-
- rustup default master
2721
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
2822
- rustc -V
2923
- cargo -V
@@ -32,6 +26,7 @@ build: false
3226

3327
test_script:
3428
- set RUST_BACKTRACE=1
29+
- set RUSTC_BOOTSTRAP=1
3530
- cargo build --features debugging
3631
- cargo test --features debugging
3732

ci/base-tests.sh

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export CARGO_TARGET_DIR=`pwd`/target/
2323

2424
# Perform various checks for lint registration
2525
./util/dev update_lints --check
26-
cargo +nightly fmt --all -- --check
2726

2827
# Check running clippy-driver without cargo
2928
(
@@ -50,29 +49,5 @@ cargo +nightly fmt --all -- --check
5049
# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR
5150
)
5251

53-
# make sure tests are formatted
54-
55-
# some lints are sensitive to formatting, exclude some files
56-
tests_need_reformatting="false"
57-
# switch to nightly
58-
rustup override set nightly
59-
# avoid loop spam and allow cmds with exit status != 0
60-
set +ex
61-
62-
for file in `find tests | grep "\.rs$"` ; do
63-
rustfmt ${file} --check
64-
if [ $? -ne 0 ]; then
65-
echo "${file} needs reformatting!"
66-
tests_need_reformatting="true"
67-
fi
68-
done
69-
70-
set -ex # reset
71-
72-
if [ "${tests_need_reformatting}" == "true" ] ; then
73-
echo "Tests need reformatting!"
74-
exit 2
75-
fi
76-
7752
# switch back to master
78-
rustup override set master
53+
# rustup override set master

clippy_lints/src/eta_reduction.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,31 @@ declare_clippy_lint! {
3333
"redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)"
3434
}
3535

36+
declare_clippy_lint! {
37+
/// **What it does:** Checks for closures which only invoke a method on the closure
38+
/// argument and can be replaced by referencing the method directly.
39+
///
40+
/// **Why is this bad?** It's unnecessary to create the closure.
41+
///
42+
/// **Known problems:** rust-lang/rust-clippy#3071, rust-lang/rust-clippy#4002,
43+
/// rust-lang/rust-clippy#3942
44+
///
45+
/// **Example:**
46+
/// ```rust,ignore
47+
/// Some('a').map(|s| s.to_uppercase());
48+
/// ```
49+
/// may be rewritten as
50+
/// ```rust,ignore
51+
/// Some('a').map(char::to_uppercase);
52+
/// ```
53+
pub REDUNDANT_CLOSURE_FOR_METHOD_CALLS,
54+
pedantic,
55+
"redundant closures for method calls"
56+
}
57+
3658
impl LintPass for EtaPass {
3759
fn get_lints(&self) -> LintArray {
38-
lint_array!(REDUNDANT_CLOSURE)
60+
lint_array!(REDUNDANT_CLOSURE, REDUNDANT_CLOSURE_FOR_METHOD_CALLS)
3961
}
4062

4163
fn name(&self) -> &'static str {
@@ -110,7 +132,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
110132
if let Some(name) = get_ufcs_type_name(cx, method_def_id, &args[0]);
111133

112134
then {
113-
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
135+
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure found", |db| {
114136
db.span_suggestion(
115137
expr.span,
116138
"remove closure as shown",

clippy_lints/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
611611
enum_glob_use::ENUM_GLOB_USE,
612612
enum_variants::MODULE_NAME_REPETITIONS,
613613
enum_variants::PUB_ENUM_VARIANT_NAMES,
614+
eta_reduction::REDUNDANT_CLOSURE_FOR_METHOD_CALLS,
614615
functions::TOO_MANY_LINES,
615616
if_not_else::IF_NOT_ELSE,
616617
infinite_iter::MAYBE_INFINITE_ITER,

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly
1+
beta

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ where
8686
})
8787
.map(|p| ("CARGO_TARGET_DIR", p));
8888

89-
// Run the dogfood tests directly on nightly cargo. This is required due
90-
// to a bug in rustup.rs when running cargo on custom toolchains. See issue #3118.
89+
// Don't run the dogfood tests on beta
9190
if std::env::var_os("CLIPPY_DOGFOOD").is_some() && cfg!(windows) {
92-
args.insert(0, "+nightly".to_string());
91+
return Ok(())
9392
}
9493

9594
let exit_status = std::process::Command::new("cargo")

tests/ui/eta.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
clippy::option_map_unit_fn,
88
clippy::trivially_copy_pass_by_ref
99
)]
10-
#![warn(clippy::redundant_closure, clippy::needless_borrow)]
10+
#![warn(
11+
clippy::redundant_closure,
12+
clippy::redundant_closure_for_method_calls,
13+
clippy::needless_borrow
14+
)]
1115

1216
use std::path::PathBuf;
1317

0 commit comments

Comments
 (0)