From 3142ee3f7a2169ee9aa591ebd6414d8952c5a412 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 1 Apr 2020 19:42:15 +0200 Subject: [PATCH 1/4] Rustup to rust-lang/rust#70627 --- clippy_lints/src/redundant_clone.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index 6bb11c8d9d7..dc1ff86c0bd 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -437,7 +437,7 @@ fn call_return_effect( _block: mir::BasicBlock, _func: &mir::Operand<'tcx>, _args: &[mir::Operand<'tcx>], - _return_place: &mir::Place<'tcx>, + _return_place: mir::Place<'tcx>, ) { // Nothing to do when a call returns successfully } From 63987aafba617fcd07a617e36727365430d97e76 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 1 Apr 2020 20:12:36 +0200 Subject: [PATCH 2/4] Rustup to rust-lang/rust#70081 --- tests/ui/unit_arg.fixed | 2 +- tests/ui/unit_arg.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/unit_arg.fixed b/tests/ui/unit_arg.fixed index cf146c91f6d..a739cf7ad81 100644 --- a/tests/ui/unit_arg.fixed +++ b/tests/ui/unit_arg.fixed @@ -1,6 +1,6 @@ // run-rustfix #![warn(clippy::unit_arg)] -#![allow(clippy::no_effect, unused_must_use)] +#![allow(unused_braces, clippy::no_effect, unused_must_use)] use std::fmt::Debug; diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index c15b0a50045..d90c49f79de 100644 --- a/tests/ui/unit_arg.rs +++ b/tests/ui/unit_arg.rs @@ -1,6 +1,6 @@ // run-rustfix #![warn(clippy::unit_arg)] -#![allow(clippy::no_effect, unused_must_use)] +#![allow(unused_braces, clippy::no_effect, unused_must_use)] use std::fmt::Debug; From 7d58ba20b436422a46a1a94c97d0ace199e853ec Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 1 Apr 2020 20:14:05 +0200 Subject: [PATCH 3/4] Rustup to rust-lang/rust#70632 --- clippy_lints/src/utils/higher.rs | 3 +++ clippy_lints/src/utils/paths.rs | 1 + tests/ui/or_fun_call.fixed | 4 +--- tests/ui/or_fun_call.rs | 2 -- tests/ui/or_fun_call.stderr | 16 ++++++++-------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index 7dfe666b18e..33fba7df8d3 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -280,6 +280,9 @@ pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr<'_>) -> Optio None } + else if match_def_path(cx, fun_def_id, &paths::VEC_NEW) && args.is_empty() { + Some(VecArgs::Vec(&[])) + } else { None }; diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 4a4ee5baf00..d443d63cc18 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -131,5 +131,6 @@ pub const VEC_AS_SLICE: [&str; 4] = ["alloc", "vec", "Vec", "as_slice"]; pub const VEC_DEQUE: [&str; 4] = ["alloc", "collections", "vec_deque", "VecDeque"]; pub const VEC_FROM_ELEM: [&str; 3] = ["alloc", "vec", "from_elem"]; +pub const VEC_NEW: [&str; 4] = ["alloc", "vec", "Vec", "new"]; pub const WEAK_ARC: [&str; 3] = ["alloc", "sync", "Weak"]; pub const WEAK_RC: [&str; 3] = ["alloc", "rc", "Weak"]; diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index cf2a42fa485..8ea03fe4261 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -53,9 +53,7 @@ fn or_fun_call() { with_default_type.unwrap_or_default(); let with_vec = Some(vec![1]); - with_vec.unwrap_or_else(|| vec![]); - - // FIXME #944: ~|SUGGESTION with_vec.unwrap_or_else(|| vec![]); + with_vec.unwrap_or_default(); let without_default = Some(Foo); without_default.unwrap_or_else(Foo::new); diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index 35fd0a30f6c..7599b945a91 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -55,8 +55,6 @@ fn make() -> T { let with_vec = Some(vec![1]); with_vec.unwrap_or(vec![]); - // FIXME #944: ~|SUGGESTION with_vec.unwrap_or_else(|| vec![]); - let without_default = Some(Foo); without_default.unwrap_or(Foo::new()); diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index cb92892b8e1..96d55771e6c 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -42,38 +42,38 @@ error: use of `unwrap_or` followed by a call to `default` LL | with_default_type.unwrap_or(u64::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_type.unwrap_or_default()` -error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:56:14 +error: use of `unwrap_or` followed by a call to `new` + --> $DIR/or_fun_call.rs:56:5 | LL | with_vec.unwrap_or(vec![]); - | ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| vec![])` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_vec.unwrap_or_default()` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:61:21 + --> $DIR/or_fun_call.rs:59:21 | LL | without_default.unwrap_or(Foo::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(Foo::new)` error: use of `or_insert` followed by a function call - --> $DIR/or_fun_call.rs:64:19 + --> $DIR/or_fun_call.rs:62:19 | LL | map.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)` error: use of `or_insert` followed by a function call - --> $DIR/or_fun_call.rs:67:21 + --> $DIR/or_fun_call.rs:65:21 | LL | btree.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:70:21 + --> $DIR/or_fun_call.rs:68:21 | LL | let _ = stringy.unwrap_or("".to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "".to_owned())` error: use of `or` followed by a function call - --> $DIR/or_fun_call.rs:95:35 + --> $DIR/or_fun_call.rs:93:35 | LL | let _ = Some("a".to_string()).or(Some("b".to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))` From fcc56fcd1b539ece92a645d664b71b9bf366fb41 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 1 Apr 2020 20:24:46 +0200 Subject: [PATCH 4/4] Fix dogfood fallout --- clippy_lints/src/loops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 43217b6cc64..2c0a274e969 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -922,7 +922,7 @@ fn get_assignment<'a, 'tcx>( .chain(expr.as_ref().into_iter().map(|e| Some(get_assignment(cx, &*e, var)))) .filter_map(|op| op) .collect::>>() - .unwrap_or_else(|| vec![]) + .unwrap_or_default() } else { get_assignment(cx, body, var).into_iter().collect() }