Skip to content

Commit 265318d

Browse files
committed
Auto merge of #4104 - Manishearth:beta-backports, r=flip1995
Backport #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

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

tests/ui/eta.stderr

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,71 @@
11
error: redundant closure found
2-
--> $DIR/eta.rs:15:27
2+
--> $DIR/eta.rs:19:27
33
|
44
LL | let a = Some(1u8).map(|a| foo(a));
55
| ^^^^^^^^^^ help: remove closure as shown: `foo`
66
|
77
= note: `-D clippy::redundant-closure` implied by `-D warnings`
88

99
error: redundant closure found
10-
--> $DIR/eta.rs:16:10
10+
--> $DIR/eta.rs:20:10
1111
|
1212
LL | meta(|a| foo(a));
1313
| ^^^^^^^^^^ help: remove closure as shown: `foo`
1414

1515
error: redundant closure found
16-
--> $DIR/eta.rs:17:27
16+
--> $DIR/eta.rs:21:27
1717
|
1818
LL | let c = Some(1u8).map(|a| {1+2; foo}(a));
1919
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `{1+2; foo}`
2020

2121
error: this expression borrows a reference that is immediately dereferenced by the compiler
22-
--> $DIR/eta.rs:19:21
22+
--> $DIR/eta.rs:23:21
2323
|
2424
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
2525
| ^^^ help: change this to: `&2`
2626
|
2727
= note: `-D clippy::needless-borrow` implied by `-D warnings`
2828

2929
error: redundant closure found
30-
--> $DIR/eta.rs:26:27
30+
--> $DIR/eta.rs:30:27
3131
|
3232
LL | let e = Some(1u8).map(|a| generic(a));
3333
| ^^^^^^^^^^^^^^ help: remove closure as shown: `generic`
3434

3535
error: redundant closure found
36-
--> $DIR/eta.rs:69:51
36+
--> $DIR/eta.rs:73:51
3737
|
3838
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
3939
| ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo`
40+
|
41+
= note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings`
4042

4143
error: redundant closure found
42-
--> $DIR/eta.rs:71:51
44+
--> $DIR/eta.rs:75:51
4345
|
4446
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
4547
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo`
4648

4749
error: redundant closure found
48-
--> $DIR/eta.rs:74:42
50+
--> $DIR/eta.rs:78:42
4951
|
5052
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
5153
| ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear`
5254

5355
error: redundant closure found
54-
--> $DIR/eta.rs:79:29
56+
--> $DIR/eta.rs:83:29
5557
|
5658
LL | let e = Some("str").map(|s| s.to_string());
5759
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string`
5860

5961
error: redundant closure found
60-
--> $DIR/eta.rs:81:27
62+
--> $DIR/eta.rs:85:27
6163
|
6264
LL | let e = Some('a').map(|s| s.to_uppercase());
6365
| ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_uppercase`
6466

6567
error: redundant closure found
66-
--> $DIR/eta.rs:84:65
68+
--> $DIR/eta.rs:88:65
6769
|
6870
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
6971
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`

tests/ui/map_clone.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(clippy::iter_cloned_collect)]
44
#![allow(clippy::clone_on_copy)]
55
#![allow(clippy::missing_docs_in_private_items)]
6-
#![allow(clippy::redundant_closure)]
6+
#![allow(clippy::redundant_closure_for_method_calls)]
77

88
fn main() {
99
let _: Vec<i8> = vec![5_i8; 6].iter().cloned().collect();

tests/ui/map_clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(clippy::iter_cloned_collect)]
44
#![allow(clippy::clone_on_copy)]
55
#![allow(clippy::missing_docs_in_private_items)]
6-
#![allow(clippy::redundant_closure)]
6+
#![allow(clippy::redundant_closure_for_method_calls)]
77

88
fn main() {
99
let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();

0 commit comments

Comments
 (0)