From 2ab317b869e4d81761be071aa879c2599182978a Mon Sep 17 00:00:00 2001 From: lukas Date: Mon, 8 Jul 2024 16:08:11 +0200 Subject: [PATCH] Mark some macros with must_use hint --- library/alloc/src/macros.rs | 10 +- library/core/src/macros/mod.rs | 62 ++++-- library/core/tests/macros.rs | 2 +- src/tools/clippy/tests/ui/box_default.fixed | 2 +- src/tools/clippy/tests/ui/box_default.stderr | 8 +- .../clippy/tests/ui/derivable_impls.fixed | 19 +- .../clippy/tests/ui/derivable_impls.stderr | 25 +-- src/tools/clippy/tests/ui/eta.fixed | 2 +- src/tools/clippy/tests/ui/eta.stderr | 8 +- .../clippy/tests/ui/iter_out_of_bounds.rs | 2 - .../clippy/tests/ui/iter_out_of_bounds.stderr | 32 +-- .../clippy/tests/ui/iter_skip_zero.fixed | 4 +- .../clippy/tests/ui/iter_skip_zero.stderr | 18 +- .../clippy/tests/ui/manual_filter_map.fixed | 8 +- .../clippy/tests/ui/manual_filter_map.stderr | 20 +- .../tests/ui/manual_is_ascii_check.stderr | 68 +++++- .../ui/manual_pattern_char_comparison.fixed | 6 +- .../ui/manual_pattern_char_comparison.stderr | 20 +- src/tools/clippy/tests/ui/mem_replace.fixed | 4 +- src/tools/clippy/tests/ui/mem_replace.stderr | 14 +- src/tools/clippy/tests/ui/or_fun_call.fixed | 6 +- src/tools/clippy/tests/ui/or_fun_call.stderr | 20 +- .../tests/ui/rc_clone_in_vec_init/arc.rs | 8 - .../tests/ui/rc_clone_in_vec_init/arc.stderr | 110 ---------- .../tests/ui/rc_clone_in_vec_init/rc.rs | 3 - .../tests/ui/rc_clone_in_vec_init/rc.stderr | 110 ---------- .../tests/ui/rc_clone_in_vec_init/weak.rs | 9 - .../tests/ui/rc_clone_in_vec_init/weak.stderr | 202 ------------------ .../clippy/tests/ui/read_zero_byte_vec.rs | 1 - .../clippy/tests/ui/read_zero_byte_vec.stderr | 22 +- .../clippy/tests/ui/redundant_guards.fixed | 12 +- .../clippy/tests/ui/redundant_guards.stderr | 73 +------ .../ui/reserve_after_initialization.fixed | 6 +- .../ui/reserve_after_initialization.stderr | 22 +- .../tests/ui/single_range_in_vec_init.stderr | 73 +------ .../tests/ui/slow_vector_initialization.rs | 1 - .../ui/slow_vector_initialization.stderr | 10 +- src/tools/clippy/tests/ui/vec.stderr | 131 ------------ .../tests/ui/zero_repeat_side_effects.fixed | 4 +- .../tests/ui/zero_repeat_side_effects.stderr | 8 +- ..._to_digit.PreCodegen.after.panic-abort.mir | 6 +- ...to_digit.PreCodegen.after.panic-unwind.mir | 6 +- ...ranches.foo.MatchBranchSimplification.diff | 61 +++--- ...p_forward.PreCodegen.after.panic-abort.mir | 4 +- ..._forward.PreCodegen.after.panic-unwind.mir | 4 +- ...macro.issue_77355_opt.PreCodegen.after.mir | 2 + tests/ui/box/unit/unique-create.rs | 2 +- tests/ui/issues/issue-13446.stderr | 12 +- .../drop-order.rs | 2 +- tests/ui/rust-2018/remove-extern-crate.fixed | 2 +- tests/ui/rust-2018/remove-extern-crate.rs | 2 +- 51 files changed, 269 insertions(+), 999 deletions(-) delete mode 100644 src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr delete mode 100644 src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr delete mode 100644 src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr delete mode 100644 src/tools/clippy/tests/ui/vec.stderr diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 8c6a367869ce0..82f2df6088dfe 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -38,21 +38,21 @@ #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "vec_macro"] -#[allow_internal_unstable(rustc_attrs, liballoc_internals)] +#[allow_internal_unstable(rustc_attrs, liballoc_internals, hint_must_use)] macro_rules! vec { () => ( - $crate::vec::Vec::new() + $crate::__export::must_use($crate::vec::Vec::new()) ); ($elem:expr; $n:expr) => ( - $crate::vec::from_elem($elem, $n) + $crate::__export::must_use($crate::vec::from_elem($elem, $n)) ); ($($x:expr),+ $(,)?) => ( - <[_]>::into_vec( + $crate::__export::must_use(<[_]>::into_vec( // This rustc_box is not required, but it produces a dramatic improvement in compile // time when constructing arrays with many elements. #[rustc_box] $crate::boxed::Box::new([$($x),+]) - ) + )) ); } diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 0d4ca4d5f01e4..0e91003d995e6 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -451,13 +451,16 @@ pub macro debug_assert_matches($($arg:tt)*) { /// ``` #[macro_export] #[stable(feature = "matches_macro", since = "1.42.0")] +#[allow_internal_unstable(hint_must_use)] #[cfg_attr(not(test), rustc_diagnostic_item = "matches_macro")] macro_rules! matches { ($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => { - match $expression { - $pattern $(if $guard)? => true, - _ => false - } + $crate::hint::must_use({ + match $expression { + $pattern $(if $guard)? => true, + _ => false + } + }) }; } @@ -1010,8 +1013,12 @@ pub(crate) mod builtin { #[rustc_builtin_macro] #[macro_export] macro_rules! format_args { - ($fmt:expr) => {{ /* compiler built-in */ }}; - ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }}; + ($fmt:expr) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; + ($fmt:expr, $($args:tt)*) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Same as [`format_args`], but can be used in some const contexts. @@ -1081,8 +1088,12 @@ pub(crate) mod builtin { #[macro_export] #[rustc_diagnostic_item = "env_macro"] // useful for external lints macro_rules! env { - ($name:expr $(,)?) => {{ /* compiler built-in */ }}; - ($name:expr, $error_msg:expr $(,)?) => {{ /* compiler built-in */ }}; + ($name:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; + ($name:expr, $error_msg:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Optionally inspects an environment variable at compile time. @@ -1112,7 +1123,9 @@ pub(crate) mod builtin { #[macro_export] #[rustc_diagnostic_item = "option_env_macro"] // useful for external lints macro_rules! option_env { - ($name:expr $(,)?) => {{ /* compiler built-in */ }}; + ($name:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Concatenates identifiers into one identifier. @@ -1174,7 +1187,9 @@ pub(crate) mod builtin { #[rustc_builtin_macro] #[macro_export] macro_rules! concat_bytes { - ($($e:literal),+ $(,)?) => {{ /* compiler built-in */ }}; + ($($e:literal),+ $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Concatenates literals into a static string slice. @@ -1193,10 +1208,13 @@ pub(crate) mod builtin { /// assert_eq!(s, "test10btrue"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[allow_internal_unstable(hint_must_use)] #[rustc_builtin_macro] #[macro_export] macro_rules! concat { - ($($e:expr),* $(,)?) => {{ /* compiler built-in */ }}; + ($($e:expr),* $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Expands to the line number on which it was invoked. @@ -1218,11 +1236,12 @@ pub(crate) mod builtin { /// println!("defined on line: {current_line}"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[allow_internal_unstable(hint_must_use)] #[rustc_builtin_macro] #[macro_export] macro_rules! line { () => { - /* compiler built-in */ + $crate::hint::must_use({ /* compiler built-in */ }) }; } @@ -1257,11 +1276,12 @@ pub(crate) mod builtin { /// assert_ne!(b, c); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[allow_internal_unstable(hint_must_use)] #[rustc_builtin_macro] #[macro_export] macro_rules! column { () => { - /* compiler built-in */ + $crate::hint::must_use(/* compiler built-in */) }; } @@ -1282,11 +1302,12 @@ pub(crate) mod builtin { /// println!("defined in file: {this_file}"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[allow_internal_unstable(hint_must_use)] #[rustc_builtin_macro] #[macro_export] macro_rules! file { () => { - /* compiler built-in */ + $crate::hint::must_use(/* compiler built-in */) }; } @@ -1306,11 +1327,12 @@ pub(crate) mod builtin { /// assert_eq!(one_plus_one, "1 + 1"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[allow_internal_unstable(hint_must_use)] #[rustc_builtin_macro] #[macro_export] macro_rules! stringify { ($($t:tt)*) => { - /* compiler built-in */ + $crate::hint::must_use(/* compiler built-in */) }; } @@ -1351,7 +1373,9 @@ pub(crate) mod builtin { #[macro_export] #[cfg_attr(not(test), rustc_diagnostic_item = "include_str_macro")] macro_rules! include_str { - ($file:expr $(,)?) => {{ /* compiler built-in */ }}; + ($file:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Includes a file as a reference to a byte array. @@ -1391,7 +1415,9 @@ pub(crate) mod builtin { #[macro_export] #[cfg_attr(not(test), rustc_diagnostic_item = "include_bytes_macro")] macro_rules! include_bytes { - ($file:expr $(,)?) => {{ /* compiler built-in */ }}; + ($file:expr $(,)?) => { + $crate::hint::must_use({ /* compiler built-in */ }) + }; } /// Expands to a string that represents the current module path. @@ -1449,7 +1475,7 @@ pub(crate) mod builtin { #[macro_export] macro_rules! cfg { ($($cfg:tt)*) => { - /* compiler built-in */ + $crate::hint::must_use(/* compiler built-in */) }; } diff --git a/library/core/tests/macros.rs b/library/core/tests/macros.rs index 09994fbcbdb78..3357edb7a68d6 100644 --- a/library/core/tests/macros.rs +++ b/library/core/tests/macros.rs @@ -39,7 +39,7 @@ fn assert_ne_trailing_comma() { #[rustfmt::skip] #[test] fn matches_leading_pipe() { - matches!(1, | 1 | 2 | 3); + let _ = matches!(1, | 1 | 2 | 3); } #[test] diff --git a/src/tools/clippy/tests/ui/box_default.fixed b/src/tools/clippy/tests/ui/box_default.fixed index 1f2f57c2507db..17d28a25ec129 100644 --- a/src/tools/clippy/tests/ui/box_default.fixed +++ b/src/tools/clippy/tests/ui/box_default.fixed @@ -36,7 +36,7 @@ fn main() { let impl1: Box = Box::default(); let vec: Box> = Box::default(); let byte: Box = Box::default(); - let vec2: Box> = Box::default(); + let vec2: Box> = Box::new(vec![]); let vec3: Box> = Box::default(); let plain_default = Box::default(); diff --git a/src/tools/clippy/tests/ui/box_default.stderr b/src/tools/clippy/tests/ui/box_default.stderr index 39fd0d29bbf9a..bc00956e6daa6 100644 --- a/src/tools/clippy/tests/ui/box_default.stderr +++ b/src/tools/clippy/tests/ui/box_default.stderr @@ -31,12 +31,6 @@ error: `Box::new(_)` of default value LL | let byte: Box = Box::new(u8::default()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` -error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:39:45 - | -LL | let vec2: Box> = Box::new(vec![]); - | ^^^^^^^^^^^^^^^^ help: try: `Box::default()` - error: `Box::new(_)` of default value --> tests/ui/box_default.rs:40:32 | @@ -61,5 +55,5 @@ error: `Box::new(_)` of default value LL | Self::x(Box::new(T::default())); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` -error: aborting due to 10 previous errors +error: aborting due to 9 previous errors diff --git a/src/tools/clippy/tests/ui/derivable_impls.fixed b/src/tools/clippy/tests/ui/derivable_impls.fixed index c85f384fd6eb9..fa898b77e79c9 100644 --- a/src/tools/clippy/tests/ui/derivable_impls.fixed +++ b/src/tools/clippy/tests/ui/derivable_impls.fixed @@ -2,7 +2,6 @@ use std::collections::HashMap; -#[derive(Default)] struct FooDefault<'a> { a: bool, b: i32, @@ -18,6 +17,24 @@ struct FooDefault<'a> { l: &'a [i32], } +impl std::default::Default for FooDefault<'_> { + fn default() -> Self { + Self { + a: false, + b: 0, + c: 0u64, + d: vec![], + e: Default::default(), + f: FooND2::default(), + g: HashMap::new(), + h: (0, vec![]), + i: [vec![], vec![], vec![]], + j: [0; 5], + k: None, + l: &[], + } + } +} #[derive(Default)] struct TupleDefault(bool, i32, u64); diff --git a/src/tools/clippy/tests/ui/derivable_impls.stderr b/src/tools/clippy/tests/ui/derivable_impls.stderr index 0adb422373d86..84ea89b1465f6 100644 --- a/src/tools/clippy/tests/ui/derivable_impls.stderr +++ b/src/tools/clippy/tests/ui/derivable_impls.stderr @@ -1,24 +1,3 @@ -error: this `impl` can be derived - --> tests/ui/derivable_impls.rs:20:1 - | -LL | / impl std::default::Default for FooDefault<'_> { -LL | | fn default() -> Self { -LL | | Self { -LL | | a: false, -... | -LL | | } -LL | | } - | |_^ - | - = note: `-D clippy::derivable-impls` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::derivable_impls)]` - = help: remove the manual implementation... -help: ...and instead derive it - | -LL + #[derive(Default)] -LL | struct FooDefault<'a> { - | - error: this `impl` can be derived --> tests/ui/derivable_impls.rs:41:1 | @@ -29,6 +8,8 @@ LL | | } LL | | } | |_^ | + = note: `-D clippy::derivable-impls` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::derivable_impls)]` = help: remove the manual implementation... help: ...and instead derive it | @@ -143,5 +124,5 @@ LL ~ #[default] LL ~ Bar, | -error: aborting due to 8 previous errors +error: aborting due to 7 previous errors diff --git a/src/tools/clippy/tests/ui/eta.fixed b/src/tools/clippy/tests/ui/eta.fixed index 7126f2799455f..8a610ec357eef 100644 --- a/src/tools/clippy/tests/ui/eta.fixed +++ b/src/tools/clippy/tests/ui/eta.fixed @@ -30,7 +30,7 @@ fn main() { let c = Some(1u8).map(|a| {1+2; foo}(a)); true.then(|| mac!()); // don't lint function in macro expansion Some(1).map(closure_mac!()); // don't lint closure in macro expansion - let _: Option> = true.then(std::vec::Vec::new); // special case vec! + let _: Option> = true.then(|| vec![]); // special case vec! let d = Some(1u8).map(|a| foo(foo2(a))); //is adjusted? all(&[1, 2, 3], &&2, below); //is adjusted unsafe { diff --git a/src/tools/clippy/tests/ui/eta.stderr b/src/tools/clippy/tests/ui/eta.stderr index c757601042f16..b7c76aebf4059 100644 --- a/src/tools/clippy/tests/ui/eta.stderr +++ b/src/tools/clippy/tests/ui/eta.stderr @@ -7,12 +7,6 @@ LL | let a = Some(1u8).map(|a| foo(a)); = note: `-D clippy::redundant-closure` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` -error: redundant closure - --> tests/ui/eta.rs:33:40 - | -LL | let _: Option> = true.then(|| vec![]); // special case vec! - | ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new` - error: redundant closure --> tests/ui/eta.rs:34:35 | @@ -202,5 +196,5 @@ error: redundant closure LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `f` -error: aborting due to 33 previous errors +error: aborting due to 32 previous errors diff --git a/src/tools/clippy/tests/ui/iter_out_of_bounds.rs b/src/tools/clippy/tests/ui/iter_out_of_bounds.rs index 3cfe6e82fc1e3..eab0b5e93ee8c 100644 --- a/src/tools/clippy/tests/ui/iter_out_of_bounds.rs +++ b/src/tools/clippy/tests/ui/iter_out_of_bounds.rs @@ -32,10 +32,8 @@ fn main() { for _ in opaque_empty_iter().skip(1) {} for _ in vec![1, 2, 3].iter().skip(4) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce for _ in vec![1; 3].iter().skip(4) {} - //~^ ERROR: this `.skip()` call skips more items than the iterator will produce let x = [1, 2, 3]; for _ in x.iter().skip(4) {} diff --git a/src/tools/clippy/tests/ui/iter_out_of_bounds.stderr b/src/tools/clippy/tests/ui/iter_out_of_bounds.stderr index 96df04251fc9e..ee997d24348ac 100644 --- a/src/tools/clippy/tests/ui/iter_out_of_bounds.stderr +++ b/src/tools/clippy/tests/ui/iter_out_of_bounds.stderr @@ -44,23 +44,7 @@ LL | for _ in [1; 3].iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:34:14 - | -LL | for _ in vec![1, 2, 3].iter().skip(4) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this operation is useless and will create an empty iterator - -error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:37:14 - | -LL | for _ in vec![1; 3].iter().skip(4) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this operation is useless and will create an empty iterator - -error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:41:14 + --> tests/ui/iter_out_of_bounds.rs:39:14 | LL | for _ in x.iter().skip(4) {} | ^^^^^^^^^^^^^^^^ @@ -68,7 +52,7 @@ LL | for _ in x.iter().skip(4) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:45:14 + --> tests/ui/iter_out_of_bounds.rs:43:14 | LL | for _ in x.iter().skip(n) {} | ^^^^^^^^^^^^^^^^ @@ -76,7 +60,7 @@ LL | for _ in x.iter().skip(n) {} = note: this operation is useless and will create an empty iterator error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:50:14 + --> tests/ui/iter_out_of_bounds.rs:48:14 | LL | for _ in empty().skip(1) {} | ^^^^^^^^^^^^^^^ @@ -84,7 +68,7 @@ LL | for _ in empty().skip(1) {} = note: this operation is useless and will create an empty iterator error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:53:14 + --> tests/ui/iter_out_of_bounds.rs:51:14 | LL | for _ in empty().take(1) {} | ^^^^^^^^^^^^^^^ @@ -92,7 +76,7 @@ LL | for _ in empty().take(1) {} = note: this operation is useless and the returned iterator will simply yield the same items error: this `.skip()` call skips more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:56:14 + --> tests/ui/iter_out_of_bounds.rs:54:14 | LL | for _ in std::iter::once(1).skip(2) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +84,7 @@ LL | for _ in std::iter::once(1).skip(2) {} = note: this operation is useless and will create an empty iterator error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:59:14 + --> tests/ui/iter_out_of_bounds.rs:57:14 | LL | for _ in std::iter::once(1).take(2) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,12 +92,12 @@ LL | for _ in std::iter::once(1).take(2) {} = note: this operation is useless and the returned iterator will simply yield the same items error: this `.take()` call takes more items than the iterator will produce - --> tests/ui/iter_out_of_bounds.rs:62:14 + --> tests/ui/iter_out_of_bounds.rs:60:14 | LL | for x in [].iter().take(1) { | ^^^^^^^^^^^^^^^^^ | = note: this operation is useless and the returned iterator will simply yield the same items -error: aborting due to 14 previous errors +error: aborting due to 12 previous errors diff --git a/src/tools/clippy/tests/ui/iter_skip_zero.fixed b/src/tools/clippy/tests/ui/iter_skip_zero.fixed index 447d07100e953..1174c31017060 100644 --- a/src/tools/clippy/tests/ui/iter_skip_zero.fixed +++ b/src/tools/clippy/tests/ui/iter_skip_zero.fixed @@ -9,9 +9,9 @@ use std::iter::once; fn main() { let _ = [1, 2, 3].iter().skip(1); - let _ = vec![1, 2, 3].iter().skip(1); + let _ = vec![1, 2, 3].iter().skip(0); let _ = once([1, 2, 3]).skip(1); - let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(1)).skip(1); + let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(1)).skip(0); // Don't lint let _ = [1, 2, 3].iter().skip(1); let _ = vec![1, 2, 3].iter().skip(1); diff --git a/src/tools/clippy/tests/ui/iter_skip_zero.stderr b/src/tools/clippy/tests/ui/iter_skip_zero.stderr index ef46db8433778..3a233960d8d7d 100644 --- a/src/tools/clippy/tests/ui/iter_skip_zero.stderr +++ b/src/tools/clippy/tests/ui/iter_skip_zero.stderr @@ -8,14 +8,6 @@ LL | let _ = [1, 2, 3].iter().skip(0); = note: `-D clippy::iter-skip-zero` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::iter_skip_zero)]` -error: usage of `.skip(0)` - --> tests/ui/iter_skip_zero.rs:12:39 - | -LL | let _ = vec![1, 2, 3].iter().skip(0); - | ^ help: if you meant to skip the first element, use: `1` - | - = note: this call to `skip` does nothing and is useless; remove it - error: usage of `.skip(0)` --> tests/ui/iter_skip_zero.rs:13:34 | @@ -24,14 +16,6 @@ LL | let _ = once([1, 2, 3]).skip(0); | = note: this call to `skip` does nothing and is useless; remove it -error: usage of `.skip(0)` - --> tests/ui/iter_skip_zero.rs:14:71 - | -LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); - | ^ help: if you meant to skip the first element, use: `1` - | - = note: this call to `skip` does nothing and is useless; remove it - error: usage of `.skip(0)` --> tests/ui/iter_skip_zero.rs:14:62 | @@ -40,5 +24,5 @@ LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); | = note: this call to `skip` does nothing and is useless; remove it -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors diff --git a/src/tools/clippy/tests/ui/manual_filter_map.fixed b/src/tools/clippy/tests/ui/manual_filter_map.fixed index a44c46c145c6c..2da467accda98 100644 --- a/src/tools/clippy/tests/ui/manual_filter_map.fixed +++ b/src/tools/clippy/tests/ui/manual_filter_map.fixed @@ -130,14 +130,18 @@ fn issue8010() { let iter = [Enum::A(123), Enum::B].into_iter(); - let _x = iter.clone().filter_map(|x| match x { Enum::A(s) => Some(s), _ => None }); + let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x { + Enum::A(s) => s, + _ => unreachable!(), + }); let _x = iter.clone().filter(|x| matches!(x, Enum::B)).map(|x| match x { Enum::A(s) => s, _ => unreachable!(), }); let _x = iter .clone() - .filter_map(|x| match x { Enum::A(s) => Some(s), _ => None }); + .filter(|x| matches!(x, Enum::A(_))) + .map(|x| if let Enum::A(s) = x { s } else { unreachable!() }); #[allow(clippy::unused_unit)] let _x = iter .clone() diff --git a/src/tools/clippy/tests/ui/manual_filter_map.stderr b/src/tools/clippy/tests/ui/manual_filter_map.stderr index 2e50567278319..d142a4441884b 100644 --- a/src/tools/clippy/tests/ui/manual_filter_map.stderr +++ b/src/tools/clippy/tests/ui/manual_filter_map.stderr @@ -245,23 +245,5 @@ LL | .filter(|f| f.result_field.is_ok()) LL | | .map(|f| f.result_field.to_owned().unwrap()); | |____________________________________________________^ help: try: `filter_map(|f| f.result_field.to_owned().ok())` -error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> tests/ui/manual_filter_map.rs:146:27 - | -LL | let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x { - | ___________________________^ -LL | | Enum::A(s) => s, -LL | | _ => unreachable!(), -LL | | }); - | |______^ help: try: `filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })` - -error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> tests/ui/manual_filter_map.rs:156:10 - | -LL | .filter(|x| matches!(x, Enum::A(_))) - | __________^ -LL | | .map(|x| if let Enum::A(s) = x { s } else { unreachable!() }); - | |_____________________________________________________________________^ help: try: `filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })` - -error: aborting due to 29 previous errors +error: aborting due to 27 previous errors diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr b/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr index a93ccace28a6e..e6d50da82a0dd 100644 --- a/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr +++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr @@ -97,24 +97,90 @@ error: manual check for common ascii range LL | ('A'..='Z').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_uppercase()` +error: current MSRV (Minimum Supported Rust Version) is `1.23.0` but this item is stable since `1.27.0` + --> tests/ui/manual_is_ascii_check.rs:33:13 + | +LL | assert!(matches!(b'1', b'0'..=b'9')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::incompatible-msrv` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]` + = note: this error originates in the macro `matches` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: current MSRV (Minimum Supported Rust Version) is `1.23.0` but this item is stable since `1.27.0` + --> tests/ui/manual_is_ascii_check.rs:34:13 + | +LL | assert!(matches!('X', 'A'..='Z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `matches` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: current MSRV (Minimum Supported Rust Version) is `1.23.0` but this item is stable since `1.27.0` + --> tests/ui/manual_is_ascii_check.rs:35:13 + | +LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `matches` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: current MSRV (Minimum Supported Rust Version) is `1.23.0` but this item is stable since `1.27.0` + --> tests/ui/manual_is_ascii_check.rs:36:13 + | +LL | assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `matches` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: current MSRV (Minimum Supported Rust Version) is `1.24.0` but this item is stable since `1.27.0` + --> tests/ui/manual_is_ascii_check.rs:41:13 + | +LL | assert!(matches!(b'1', b'0'..=b'9')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `matches` (in Nightly builds, run with -Z macro-backtrace for more info) + error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:41:13 | LL | assert!(matches!(b'1', b'0'..=b'9')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()` +error: current MSRV (Minimum Supported Rust Version) is `1.24.0` but this item is stable since `1.27.0` + --> tests/ui/manual_is_ascii_check.rs:42:13 + | +LL | assert!(matches!('X', 'A'..='Z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `matches` (in Nightly builds, run with -Z macro-backtrace for more info) + error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:42:13 | LL | assert!(matches!('X', 'A'..='Z')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()` +error: current MSRV (Minimum Supported Rust Version) is `1.24.0` but this item is stable since `1.27.0` + --> tests/ui/manual_is_ascii_check.rs:43:13 + | +LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `matches` (in Nightly builds, run with -Z macro-backtrace for more info) + error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:43:13 | LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()` +error: current MSRV (Minimum Supported Rust Version) is `1.24.0` but this item is stable since `1.27.0` + --> tests/ui/manual_is_ascii_check.rs:44:13 + | +LL | assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F')); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `matches` (in Nightly builds, run with -Z macro-backtrace for more info) + error: manual check for common ascii range --> tests/ui/manual_is_ascii_check.rs:44:13 | @@ -173,5 +239,5 @@ error: manual check for common ascii range LL | take_while(|c: char| ('A'..='Z').contains(&c)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `c.is_ascii_uppercase()` -error: aborting due to 27 previous errors +error: aborting due to 35 previous errors diff --git a/src/tools/clippy/tests/ui/manual_pattern_char_comparison.fixed b/src/tools/clippy/tests/ui/manual_pattern_char_comparison.fixed index 03e621d95ba16..2a475118ce35a 100644 --- a/src/tools/clippy/tests/ui/manual_pattern_char_comparison.fixed +++ b/src/tools/clippy/tests/ui/manual_pattern_char_comparison.fixed @@ -15,9 +15,9 @@ fn main() { sentence.splitn(3, |c: char| c.is_whitespace() || c == 'X'); let char_compare = 'X'; sentence.splitn(3, char_compare); - sentence.split(['\n', 'X', 'Y']); - sentence.splitn(3, 'X'); - sentence.splitn(3, ['X', 'W']); + sentence.split(|c: char| matches!(c, '\n' | 'X' | 'Y')); + sentence.splitn(3, |c: char| matches!(c, 'X')); + sentence.splitn(3, |c: char| matches!(c, 'X' | 'W')); sentence.find('🎈'); let not_str = NotStr; diff --git a/src/tools/clippy/tests/ui/manual_pattern_char_comparison.stderr b/src/tools/clippy/tests/ui/manual_pattern_char_comparison.stderr index f185d7c8f6767..c2ee4653cb8c1 100644 --- a/src/tools/clippy/tests/ui/manual_pattern_char_comparison.stderr +++ b/src/tools/clippy/tests/ui/manual_pattern_char_comparison.stderr @@ -31,24 +31,6 @@ error: this manual char comparison can be written more succinctly LL | sentence.splitn(3, |c: char| c == char_compare); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a `char`: `char_compare` -error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:18:20 - | -LL | sentence.split(|c: char| matches!(c, '\n' | 'X' | 'Y')); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['\n', 'X', 'Y']` - -error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:19:24 - | -LL | sentence.splitn(3, |c: char| matches!(c, 'X')); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a `char`: `'X'` - -error: this manual char comparison can be written more succinctly - --> tests/ui/manual_pattern_char_comparison.rs:20:24 - | -LL | sentence.splitn(3, |c: char| matches!(c, 'X' | 'W')); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['X', 'W']` - error: this manual char comparison can be written more succinctly --> tests/ui/manual_pattern_char_comparison.rs:21:19 | @@ -61,5 +43,5 @@ error: this manual char comparison can be written more succinctly LL | sentence.trim_end_matches(|c: char| c == '.' || c == ',' || c == '!' || c == '?'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['.', ',', '!', '?']` -error: aborting due to 10 previous errors +error: aborting due to 7 previous errors diff --git a/src/tools/clippy/tests/ui/mem_replace.fixed b/src/tools/clippy/tests/ui/mem_replace.fixed index 78d8b3e9bce6b..3a3d7c2df1af4 100644 --- a/src/tools/clippy/tests/ui/mem_replace.fixed +++ b/src/tools/clippy/tests/ui/mem_replace.fixed @@ -28,7 +28,7 @@ fn replace_with_default() { let _ = std::mem::take(&mut v); let _ = std::mem::take(&mut v); let _ = std::mem::take(&mut v); - let _ = std::mem::take(&mut v); + let _ = std::mem::replace(&mut v, vec![]); let mut hash_map: HashMap = HashMap::new(); let _ = std::mem::take(&mut hash_map); @@ -52,7 +52,7 @@ fn replace_with_default() { let _ = std::mem::take(&mut binary_heap); let mut tuple = (vec![1, 2], BinaryHeap::::new()); - let _ = std::mem::take(&mut tuple); + let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new())); let mut refstr = "hello"; let _ = std::mem::take(&mut refstr); diff --git a/src/tools/clippy/tests/ui/mem_replace.stderr b/src/tools/clippy/tests/ui/mem_replace.stderr index 44be2c9b63d75..3be8a3f3ffe02 100644 --- a/src/tools/clippy/tests/ui/mem_replace.stderr +++ b/src/tools/clippy/tests/ui/mem_replace.stderr @@ -52,12 +52,6 @@ error: replacing a value of type `T` with `T::default()` is better expressed usi LL | let _ = std::mem::replace(&mut v, Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` -error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:31:13 - | -LL | let _ = std::mem::replace(&mut v, vec![]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` - error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> tests/ui/mem_replace.rs:34:13 | @@ -100,12 +94,6 @@ error: replacing a value of type `T` with `T::default()` is better expressed usi LL | let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut binary_heap)` -error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:55:13 - | -LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new())); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)` - error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` --> tests/ui/mem_replace.rs:58:13 | @@ -148,5 +136,5 @@ error: replacing a value of type `T` with `T::default()` is better expressed usi LL | let _ = std::mem::replace(&mut b.val, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)` -error: aborting due to 24 previous errors +error: aborting due to 22 previous errors diff --git a/src/tools/clippy/tests/ui/or_fun_call.fixed b/src/tools/clippy/tests/ui/or_fun_call.fixed index c76f7a81843b2..0f2a428b46cc8 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.fixed +++ b/src/tools/clippy/tests/ui/or_fun_call.fixed @@ -76,7 +76,7 @@ fn or_fun_call() { real_default.unwrap_or_default(); let with_vec = Some(vec![1]); - with_vec.unwrap_or_default(); + with_vec.unwrap_or(vec![]); let without_default = Some(Foo); without_default.unwrap_or_else(Foo::new); @@ -85,13 +85,13 @@ fn or_fun_call() { map.entry(42).or_default(); let mut map_vec = HashMap::>::new(); - map_vec.entry(42).or_default(); + map_vec.entry(42).or_insert(vec![]); let mut btree = BTreeMap::::new(); btree.entry(42).or_default(); let mut btree_vec = BTreeMap::>::new(); - btree_vec.entry(42).or_default(); + btree_vec.entry(42).or_insert(vec![]); let stringy = Some(String::new()); let _ = stringy.unwrap_or_default(); diff --git a/src/tools/clippy/tests/ui/or_fun_call.stderr b/src/tools/clippy/tests/ui/or_fun_call.stderr index 3070db22fc5a6..352d82a7749e6 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.stderr +++ b/src/tools/clippy/tests/ui/or_fun_call.stderr @@ -58,12 +58,6 @@ error: use of `unwrap_or` to construct default value LL | real_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:79:14 - | -LL | with_vec.unwrap_or(vec![]); - | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` - error: use of `unwrap_or` followed by a function call --> tests/ui/or_fun_call.rs:82:21 | @@ -76,24 +70,12 @@ error: use of `or_insert` to construct default value LL | map.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` -error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:88:23 - | -LL | map_vec.entry(42).or_insert(vec![]); - | ^^^^^^^^^^^^^^^^^ help: try: `or_default()` - error: use of `or_insert` to construct default value --> tests/ui/or_fun_call.rs:91:21 | LL | btree.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` -error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:94:25 - | -LL | btree_vec.entry(42).or_insert(vec![]); - | ^^^^^^^^^^^^^^^^^ help: try: `or_default()` - error: use of `unwrap_or` to construct default value --> tests/ui/or_fun_call.rs:97:21 | @@ -196,5 +178,5 @@ error: use of `unwrap_or_else` to construct default value LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: aborting due to 32 previous errors +error: aborting due to 29 previous errors diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.rs b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.rs index 1c9e9aa7ef47d..9cb7f48e75b54 100644 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.rs +++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.rs @@ -7,8 +7,6 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Arc::new("x".to_string()); 2]; - //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Arc` instance } fn should_warn_simple_case_with_big_indentation() { @@ -17,16 +15,12 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Arc::new("x".to_string()); 2]; - //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Arc` instance } } } fn should_warn_complex_case() { let v = vec![ - //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Arc` instance std::sync::Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -36,8 +30,6 @@ fn should_warn_complex_case() { ]; let v1 = vec![ - //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Arc` instance Arc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr deleted file mode 100644 index 1078a97542f2c..0000000000000 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr +++ /dev/null @@ -1,110 +0,0 @@ -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:9:13 - | -LL | let v = vec![Arc::new("x".to_string()); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Arc` instance - = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::rc_clone_in_vec_init)]` -help: consider initializing each `Arc` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Arc::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Arc` initialization to a variable - | -LL ~ let v = { -LL + let data = Arc::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:19:21 - | -LL | let v = vec![Arc::new("x".to_string()); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Arc` instance -help: consider initializing each `Arc` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Arc::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Arc` initialization to a variable - | -LL ~ let v = { -LL + let data = Arc::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:27:13 - | -LL | let v = vec![ - | _____________^ -LL | | -LL | | -LL | | std::sync::Arc::new(Mutex::new({ -... | -LL | | 2 -LL | | ]; - | |_____^ - | - = note: each element will point to the same `Arc` instance -help: consider initializing each `Arc` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(std::sync::Arc::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Arc` initialization to a variable - | -LL ~ let v = { -LL + let data = std::sync::Arc::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/arc.rs:38:14 - | -LL | let v1 = vec![ - | ______________^ -LL | | -LL | | -LL | | Arc::new(Mutex::new({ -... | -LL | | 2 -LL | | ]; - | |_____^ - | - = note: each element will point to the same `Arc` instance -help: consider initializing each `Arc` element individually - | -LL ~ let v1 = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Arc::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Arc` initialization to a variable - | -LL ~ let v1 = { -LL + let data = Arc::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: aborting due to 4 previous errors - diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs index 01cc433cbdae1..34fdc9fafe989 100644 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs +++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs @@ -8,8 +8,6 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Rc::new("x".to_string()); 2]; - //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Rc` instance } fn should_warn_simple_case_with_big_indentation() { @@ -37,7 +35,6 @@ fn should_warn_complex_case() { ]; let v1 = vec![ - //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` //~| NOTE: each element will point to the same `Rc` instance Rc::new(Mutex::new({ let x = 1; diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr deleted file mode 100644 index 702266d62d2c3..0000000000000 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr +++ /dev/null @@ -1,110 +0,0 @@ -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:10:13 - | -LL | let v = vec![Rc::new("x".to_string()); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Rc` instance - = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::rc_clone_in_vec_init)]` -help: consider initializing each `Rc` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Rc::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Rc` initialization to a variable - | -LL ~ let v = { -LL + let data = Rc::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:20:21 - | -LL | let v = vec![Rc::new("x".to_string()); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Rc` instance -help: consider initializing each `Rc` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Rc::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Rc` initialization to a variable - | -LL ~ let v = { -LL + let data = Rc::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:28:13 - | -LL | let v = vec![ - | _____________^ -LL | | -LL | | -LL | | std::rc::Rc::new(Mutex::new({ -... | -LL | | 2 -LL | | ]; - | |_____^ - | - = note: each element will point to the same `Rc` instance -help: consider initializing each `Rc` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(std::rc::Rc::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Rc` initialization to a variable - | -LL ~ let v = { -LL + let data = std::rc::Rc::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/rc.rs:39:14 - | -LL | let v1 = vec![ - | ______________^ -LL | | -LL | | -LL | | Rc::new(Mutex::new({ -... | -LL | | 2 -LL | | ]; - | |_____^ - | - = note: each element will point to the same `Rc` instance -help: consider initializing each `Rc` element individually - | -LL ~ let v1 = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Rc::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Rc` initialization to a variable - | -LL ~ let v1 = { -LL + let data = Rc::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: aborting due to 4 previous errors - diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.rs b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.rs index fd2895d40458a..7405ab260d81f 100644 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.rs +++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.rs @@ -9,7 +9,6 @@ fn main() {} fn should_warn_simple_case() { let v = vec![SyncWeak::::new(); 2]; //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Weak` instance let v2 = vec![UnSyncWeak::::new(); 2]; //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` //~| NOTE: each element will point to the same `Weak` instance @@ -19,7 +18,6 @@ fn should_warn_simple_case() { //~| NOTE: each element will point to the same `Weak` instance let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Weak` instance } fn should_warn_simple_case_with_big_indentation() { @@ -29,18 +27,13 @@ fn should_warn_simple_case_with_big_indentation() { if true { let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Weak` instance let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; - //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Weak` instance } } } fn should_warn_complex_case() { let v = vec![ - //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Weak` instance Arc::downgrade(&Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -50,8 +43,6 @@ fn should_warn_complex_case() { ]; let v1 = vec![ - //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` - //~| NOTE: each element will point to the same `Weak` instance Rc::downgrade(&Rc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr deleted file mode 100644 index 68ca2a7eb848c..0000000000000 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr +++ /dev/null @@ -1,202 +0,0 @@ -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:10:13 - | -LL | let v = vec![SyncWeak::::new(); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Weak` instance - = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::rc_clone_in_vec_init)]` -help: consider initializing each `Weak` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(SyncWeak::::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Weak` initialization to a variable - | -LL ~ let v = { -LL + let data = SyncWeak::::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:13:14 - | -LL | let v2 = vec![UnSyncWeak::::new(); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Weak` instance -help: consider initializing each `Weak` element individually - | -LL ~ let v2 = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(UnSyncWeak::::new(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Weak` initialization to a variable - | -LL ~ let v2 = { -LL + let data = UnSyncWeak::::new(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:17:13 - | -LL | let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Weak` instance -help: consider initializing each `Weak` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Rc::downgrade(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Weak` initialization to a variable - | -LL ~ let v = { -LL + let data = Rc::downgrade(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:20:13 - | -LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Weak` instance -help: consider initializing each `Weak` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Arc::downgrade(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Weak` initialization to a variable - | -LL ~ let v = { -LL + let data = Arc::downgrade(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:30:21 - | -LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Weak` instance -help: consider initializing each `Weak` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Arc::downgrade(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Weak` initialization to a variable - | -LL ~ let v = { -LL + let data = Arc::downgrade(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:33:22 - | -LL | let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: each element will point to the same `Weak` instance -help: consider initializing each `Weak` element individually - | -LL ~ let v2 = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Rc::downgrade(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Weak` initialization to a variable - | -LL ~ let v2 = { -LL + let data = Rc::downgrade(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:41:13 - | -LL | let v = vec![ - | _____________^ -LL | | -LL | | -LL | | Arc::downgrade(&Arc::new(Mutex::new({ -... | -LL | | 2 -LL | | ]; - | |_____^ - | - = note: each element will point to the same `Weak` instance -help: consider initializing each `Weak` element individually - | -LL ~ let v = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Arc::downgrade(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Weak` initialization to a variable - | -LL ~ let v = { -LL + let data = Arc::downgrade(..); -LL + vec![data; 2] -LL ~ }; - | - -error: initializing a reference-counted pointer in `vec![elem; len]` - --> tests/ui/rc_clone_in_vec_init/weak.rs:52:14 - | -LL | let v1 = vec![ - | ______________^ -LL | | -LL | | -LL | | Rc::downgrade(&Rc::new(Mutex::new({ -... | -LL | | 2 -LL | | ]; - | |_____^ - | - = note: each element will point to the same `Weak` instance -help: consider initializing each `Weak` element individually - | -LL ~ let v1 = { -LL + let mut v = Vec::with_capacity(2); -LL + (0..2).for_each(|_| v.push(Rc::downgrade(..))); -LL + v -LL ~ }; - | -help: or if this is intentional, consider extracting the `Weak` initialization to a variable - | -LL ~ let v1 = { -LL + let data = Rc::downgrade(..); -LL + vec![data; 2] -LL ~ }; - | - -error: aborting due to 8 previous errors - diff --git a/src/tools/clippy/tests/ui/read_zero_byte_vec.rs b/src/tools/clippy/tests/ui/read_zero_byte_vec.rs index 68acf4334699b..36c2528a754f8 100644 --- a/src/tools/clippy/tests/ui/read_zero_byte_vec.rs +++ b/src/tools/clippy/tests/ui/read_zero_byte_vec.rs @@ -35,7 +35,6 @@ fn test() -> io::Result<()> { // should lint let mut data4 = vec![]; let _ = f.read(&mut data4)?; - //~^ ERROR: reading zero byte data to `Vec` // should lint let _ = { diff --git a/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr b/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr index e2356f1cb56be..7c1873f0d346e 100644 --- a/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr +++ b/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr @@ -20,52 +20,46 @@ LL | f.read_exact(&mut data3)?; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:37:13 - | -LL | let _ = f.read(&mut data4)?; - | ^^^^^^^^^^^^^^^^^^ - -error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:43:9 + --> tests/ui/read_zero_byte_vec.rs:42:9 | LL | f.read(&mut data5) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:50:9 + --> tests/ui/read_zero_byte_vec.rs:49:9 | LL | f.read(&mut data6) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:84:9 + --> tests/ui/read_zero_byte_vec.rs:83:9 | LL | f.read(&mut v)?; | ^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:94:5 + --> tests/ui/read_zero_byte_vec.rs:93:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:99:5 + --> tests/ui/read_zero_byte_vec.rs:98:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:106:5 + --> tests/ui/read_zero_byte_vec.rs:105:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:111:5 + --> tests/ui/read_zero_byte_vec.rs:110:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 11 previous errors +error: aborting due to 10 previous errors diff --git a/src/tools/clippy/tests/ui/redundant_guards.fixed b/src/tools/clippy/tests/ui/redundant_guards.fixed index ed4b1c219150e..76827908a311c 100644 --- a/src/tools/clippy/tests/ui/redundant_guards.fixed +++ b/src/tools/clippy/tests/ui/redundant_guards.fixed @@ -37,8 +37,8 @@ fn main() { let x = Some(Some(1)); match x { - Some(Some(1)) if true => .., - Some(Some(1)) => { + Some(x) if matches!(x, Some(1) if true) => .., + Some(x) if matches!(x, Some(1)) => { println!("a"); .. }, @@ -69,7 +69,7 @@ fn main() { } let b = B { e: Some(A(0)) }; match b { - B { e: Some(A(2)) } => .., + B { e } if matches!(e, Some(A(2))) => .., _ => todo!(), }; // Do not lint, since we cannot represent this as a pattern (at least, without a conversion) @@ -113,7 +113,7 @@ fn i() { fn h(v: Option) { match v { - Some(0) => .., + x if matches!(x, Some(0)) => .., _ => .., }; } @@ -186,7 +186,7 @@ mod issue11465 { Some(1) => {}, Some(1) => {}, Some(2) => {}, - Some(3) => {}, + Some(ref x) if matches!(x, &3) => {}, _ => {}, }; @@ -209,7 +209,7 @@ mod issue11465 { B { c: 1, .. } => {}, B { c: 1, .. } => {}, B { c: 1, .. } => {}, - B { c: 1, .. } => {}, + B { ref c, .. } if matches!(c, &1) => {}, _ => {}, } } diff --git a/src/tools/clippy/tests/ui/redundant_guards.stderr b/src/tools/clippy/tests/ui/redundant_guards.stderr index fd12e08328231..c2abb2992ed17 100644 --- a/src/tools/clippy/tests/ui/redundant_guards.stderr +++ b/src/tools/clippy/tests/ui/redundant_guards.stderr @@ -12,29 +12,6 @@ LL - C(x, y) if let 1 = y => .., LL + C(x, 1) => .., | -error: redundant guard - --> tests/ui/redundant_guards.rs:40:20 - | -LL | Some(x) if matches!(x, Some(1) if true) => .., - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL | Some(Some(1)) if true => .., - | ~~~~~~~ ~~~~~~~ - -error: redundant guard - --> tests/ui/redundant_guards.rs:41:20 - | -LL | Some(x) if matches!(x, Some(1)) => { - | ^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL - Some(x) if matches!(x, Some(1)) => { -LL + Some(Some(1)) => { - | - error: redundant guard --> tests/ui/redundant_guards.rs:45:20 | @@ -71,18 +48,6 @@ LL - Some(x) if Some(2) == x => .., LL + Some(Some(2)) => .., | -error: redundant guard - --> tests/ui/redundant_guards.rs:72:20 - | -LL | B { e } if matches!(e, Some(A(2))) => .., - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL - B { e } if matches!(e, Some(A(2))) => .., -LL + B { e: Some(A(2)) } => .., - | - error: redundant guard --> tests/ui/redundant_guards.rs:109:20 | @@ -95,18 +60,6 @@ LL - E::A(y) if y == "not from an or pattern" => {}, LL + E::A("not from an or pattern") => {}, | -error: redundant guard - --> tests/ui/redundant_guards.rs:116:14 - | -LL | x if matches!(x, Some(0)) => .., - | ^^^^^^^^^^^^^^^^^^^^ - | -help: try - | -LL - x if matches!(x, Some(0)) => .., -LL + Some(0) => .., - | - error: redundant guard --> tests/ui/redundant_guards.rs:123:14 | @@ -167,18 +120,6 @@ LL - Some(ref x) if let &2 = x => {}, LL + Some(2) => {}, | -error: redundant guard - --> tests/ui/redundant_guards.rs:189:28 - | -LL | Some(ref x) if matches!(x, &3) => {}, - | ^^^^^^^^^^^^^^^ - | -help: try - | -LL - Some(ref x) if matches!(x, &3) => {}, -LL + Some(3) => {}, - | - error: redundant guard --> tests/ui/redundant_guards.rs:209:32 | @@ -215,18 +156,6 @@ LL - B { ref c, .. } if let &1 = c => {}, LL + B { c: 1, .. } => {}, | -error: redundant guard - --> tests/ui/redundant_guards.rs:212:32 - | -LL | B { ref c, .. } if matches!(c, &1) => {}, - | ^^^^^^^^^^^^^^^ - | -help: try - | -LL - B { ref c, .. } if matches!(c, &1) => {}, -LL + B { c: 1, .. } => {}, - | - error: redundant guard --> tests/ui/redundant_guards.rs:222:26 | @@ -335,5 +264,5 @@ LL - y if y.is_empty() => {}, LL + "" => {}, | -error: aborting due to 28 previous errors +error: aborting due to 22 previous errors diff --git a/src/tools/clippy/tests/ui/reserve_after_initialization.fixed b/src/tools/clippy/tests/ui/reserve_after_initialization.fixed index 0675277849ad7..4f92280475be4 100644 --- a/src/tools/clippy/tests/ui/reserve_after_initialization.fixed +++ b/src/tools/clippy/tests/ui/reserve_after_initialization.fixed @@ -7,13 +7,15 @@ use proc_macros::{external, with_span}; // Should lint fn standard() { - let mut v1: Vec = Vec::with_capacity(10); + let mut v1: Vec = vec![]; + v1.reserve(10); } // Should lint fn capacity_as_expr() { let capacity = 10; - let mut v2: Vec = Vec::with_capacity(capacity); + let mut v2: Vec = vec![]; + v2.reserve(capacity); } // Shouldn't lint diff --git a/src/tools/clippy/tests/ui/reserve_after_initialization.stderr b/src/tools/clippy/tests/ui/reserve_after_initialization.stderr index b6dbebb3f14c2..8665ec6e023a1 100644 --- a/src/tools/clippy/tests/ui/reserve_after_initialization.stderr +++ b/src/tools/clippy/tests/ui/reserve_after_initialization.stderr @@ -1,26 +1,12 @@ -error: call to `reserve` immediately after creation - --> tests/ui/reserve_after_initialization.rs:10:5 - | -LL | / let mut v1: Vec = vec![]; -LL | | v1.reserve(10); - | |___________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v1: Vec = Vec::with_capacity(10);` - | - = note: `-D clippy::reserve-after-initialization` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::reserve_after_initialization)]` - -error: call to `reserve` immediately after creation - --> tests/ui/reserve_after_initialization.rs:17:5 - | -LL | / let mut v2: Vec = vec![]; -LL | | v2.reserve(capacity); - | |_________________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v2: Vec = Vec::with_capacity(capacity);` - error: call to `reserve` immediately after creation --> tests/ui/reserve_after_initialization.rs:35:5 | LL | / v5 = Vec::new(); LL | | v5.reserve(10); | |___________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `v5 = Vec::with_capacity(10);` + | + = note: `-D clippy::reserve-after-initialization` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reserve_after_initialization)]` -error: aborting due to 3 previous errors +error: aborting due to 1 previous error diff --git a/src/tools/clippy/tests/ui/single_range_in_vec_init.stderr b/src/tools/clippy/tests/ui/single_range_in_vec_init.stderr index 9c125adb51a73..d4c55f6b1167b 100644 --- a/src/tools/clippy/tests/ui/single_range_in_vec_init.stderr +++ b/src/tools/clippy/tests/ui/single_range_in_vec_init.stderr @@ -15,21 +15,6 @@ help: if you wanted an array of len 200, try LL | [0; 200]; | ~~~~~~ -error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:27:5 - | -LL | vec![0..200]; - | ^^^^^^^^^^^^ - | -help: if you wanted a `Vec` that contains the entire range, try - | -LL | (0..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: if you wanted a `Vec` of len 200, try - | -LL | vec![0; 200]; - | ~~~~~~ - error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:28:5 | @@ -75,51 +60,6 @@ help: if you wanted an array of len 200usize, try LL | [0; 200usize]; | ~~~~~~~~~~~ -error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:31:5 - | -LL | vec![0u8..200]; - | ^^^^^^^^^^^^^^ - | -help: if you wanted a `Vec` that contains the entire range, try - | -LL | (0u8..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: if you wanted a `Vec` of len 200, try - | -LL | vec![0u8; 200]; - | ~~~~~~~~ - -error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:32:5 - | -LL | vec![0usize..200]; - | ^^^^^^^^^^^^^^^^^ - | -help: if you wanted a `Vec` that contains the entire range, try - | -LL | (0usize..200).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: if you wanted a `Vec` of len 200, try - | -LL | vec![0usize; 200]; - | ~~~~~~~~~~~ - -error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:33:5 - | -LL | vec![0..200usize]; - | ^^^^^^^^^^^^^^^^^ - | -help: if you wanted a `Vec` that contains the entire range, try - | -LL | (0..200usize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: if you wanted a `Vec` of len 200usize, try - | -LL | vec![0; 200usize]; - | ~~~~~~~~~~~ - error: an array of `Range` that is only one element --> tests/ui/single_range_in_vec_init.rs:35:5 | @@ -131,16 +71,5 @@ help: if you wanted a `Vec` that contains the entire range, try LL | (0..200isize).collect::>(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:36:5 - | -LL | vec![0..200isize]; - | ^^^^^^^^^^^^^^^^^ - | -help: if you wanted a `Vec` that contains the entire range, try - | -LL | (0..200isize).collect::>(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: aborting due to 10 previous errors +error: aborting due to 5 previous errors diff --git a/src/tools/clippy/tests/ui/slow_vector_initialization.rs b/src/tools/clippy/tests/ui/slow_vector_initialization.rs index 16f81019574fb..b471fc7b0118f 100644 --- a/src/tools/clippy/tests/ui/slow_vector_initialization.rs +++ b/src/tools/clippy/tests/ui/slow_vector_initialization.rs @@ -89,7 +89,6 @@ fn from_empty_vec() { vec1 = vec![]; vec1.resize(10, 0); - //~^ ERROR: slow zero-filling initialization macro_rules! x { () => { diff --git a/src/tools/clippy/tests/ui/slow_vector_initialization.stderr b/src/tools/clippy/tests/ui/slow_vector_initialization.stderr index 353c677097be7..c5bac010112ab 100644 --- a/src/tools/clippy/tests/ui/slow_vector_initialization.stderr +++ b/src/tools/clippy/tests/ui/slow_vector_initialization.stderr @@ -97,13 +97,5 @@ LL | vec1 = Vec::new(); LL | vec1.resize(10, 0); | ^^^^^^^^^^^^^^^^^^ -error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:91:5 - | -LL | vec1 = vec![]; - | ------ help: consider replacing this with: `vec![0; 10]` -LL | vec1.resize(10, 0); - | ^^^^^^^^^^^^^^^^^^ - -error: aborting due to 13 previous errors +error: aborting due to 12 previous errors diff --git a/src/tools/clippy/tests/ui/vec.stderr b/src/tools/clippy/tests/ui/vec.stderr deleted file mode 100644 index 3faea8033fe2c..0000000000000 --- a/src/tools/clippy/tests/ui/vec.stderr +++ /dev/null @@ -1,131 +0,0 @@ -error: useless use of `vec!` - --> tests/ui/vec.rs:30:14 - | -LL | on_slice(&vec![]); - | ^^^^^^^ help: you can use a slice directly: `&[]` - | - = note: `-D clippy::useless-vec` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:32:18 - | -LL | on_mut_slice(&mut vec![]); - | ^^^^^^^^^^^ help: you can use a slice directly: `&mut []` - -error: useless use of `vec!` - --> tests/ui/vec.rs:34:14 - | -LL | on_slice(&vec![1, 2]); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:36:18 - | -LL | on_mut_slice(&mut vec![1, 2]); - | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:38:14 - | -LL | on_slice(&vec![1, 2]); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:40:18 - | -LL | on_mut_slice(&mut vec![1, 2]); - | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:42:14 - | -LL | on_slice(&vec!(1, 2)); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:44:18 - | -LL | on_mut_slice(&mut vec![1, 2]); - | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:46:14 - | -LL | on_slice(&vec![1; 2]); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:48:18 - | -LL | on_mut_slice(&mut vec![1; 2]); - | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1; 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:74:19 - | -LL | let _x: i32 = vec![1, 2, 3].iter().sum(); - | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:77:17 - | -LL | let mut x = vec![1, 2, 3]; - | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:83:22 - | -LL | let _x: &[i32] = &vec![1, 2, 3]; - | ^^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:85:14 - | -LL | for _ in vec![1, 2, 3] {} - | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:124:20 - | -LL | for _string in vec![repro!(true), repro!(null)] { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:141:18 - | -LL | in_macro!(1, vec![1, 2], vec![1; 2]); - | ^^^^^^^^^^ help: you can use an array directly: `[1, 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:141:30 - | -LL | in_macro!(1, vec![1, 2], vec![1; 2]); - | ^^^^^^^^^^ help: you can use an array directly: `[1; 2]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:160:14 - | -LL | for a in vec![1, 2, 3] { - | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:164:14 - | -LL | for a in vec![String::new(), String::new()] { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:196:33 - | -LL | this_macro_doesnt_need_vec!(vec![1]); - | ^^^^^^^ help: you can use an array directly: `[1]` - -error: useless use of `vec!` - --> tests/ui/vec.rs:222:14 - | -LL | for a in &(vec![1, 2]) {} - | ^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: aborting due to 21 previous errors - diff --git a/src/tools/clippy/tests/ui/zero_repeat_side_effects.fixed b/src/tools/clippy/tests/ui/zero_repeat_side_effects.fixed index 6f13252192640..d01d1841a9b98 100644 --- a/src/tools/clippy/tests/ui/zero_repeat_side_effects.fixed +++ b/src/tools/clippy/tests/ui/zero_repeat_side_effects.fixed @@ -23,9 +23,9 @@ fn main() { // on vecs // vecs dont support infering value of consts - f(); let c: std::vec::Vec = vec![]; + let c = { f(); vec![] as std::vec::Vec }; let d; - f(); d = vec![] as std::vec::Vec; + d = { f(); vec![] as std::vec::Vec }; // for macros println!("side effect"); let e: [(); 0] = []; diff --git a/src/tools/clippy/tests/ui/zero_repeat_side_effects.stderr b/src/tools/clippy/tests/ui/zero_repeat_side_effects.stderr index afdc60542534d..0e34f4e74c5a6 100644 --- a/src/tools/clippy/tests/ui/zero_repeat_side_effects.stderr +++ b/src/tools/clippy/tests/ui/zero_repeat_side_effects.stderr @@ -26,16 +26,16 @@ LL | b = [f(); N]; | ^^^^^^^^^^^^ help: consider using: `f(); b = [] as [i32; 0]` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:26:5 + --> tests/ui/zero_repeat_side_effects.rs:26:13 | LL | let c = vec![f(); 0]; - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f(); let c: std::vec::Vec = vec![];` + | ^^^^^^^^^^^^ help: consider using: `{ f(); vec![] as std::vec::Vec }` error: function or method calls as the initial value in zero-sized array initializers may cause side effects - --> tests/ui/zero_repeat_side_effects.rs:28:5 + --> tests/ui/zero_repeat_side_effects.rs:28:9 | LL | d = vec![f(); 0]; - | ^^^^^^^^^^^^^^^^ help: consider using: `f(); d = vec![] as std::vec::Vec` + | ^^^^^^^^^^^^ help: consider using: `{ f(); vec![] as std::vec::Vec }` error: function or method calls as the initial value in zero-sized array initializers may cause side effects --> tests/ui/zero_repeat_side_effects.rs:31:5 diff --git a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir index 8da56d59aaa60..6525e21520d7e 100644 --- a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir @@ -8,12 +8,14 @@ fn num_to_digit(_1: char) -> u32 { let _2: std::option::Option; scope 2 (inlined Option::::is_some) { let mut _3: isize; + scope 3 (inlined must_use::) { + } } } - scope 3 (inlined #[track_caller] Option::::unwrap) { + scope 4 (inlined #[track_caller] Option::::unwrap) { let mut _5: isize; let mut _6: !; - scope 4 { + scope 5 { } } diff --git a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir index 61bc09d901cbf..bd09b49b0434e 100644 --- a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir @@ -8,12 +8,14 @@ fn num_to_digit(_1: char) -> u32 { let _2: std::option::Option; scope 2 (inlined Option::::is_some) { let mut _3: isize; + scope 3 (inlined must_use::) { + } } } - scope 3 (inlined #[track_caller] Option::::unwrap) { + scope 4 (inlined #[track_caller] Option::::unwrap) { let mut _5: isize; let mut _6: !; - scope 4 { + scope 5 { } } diff --git a/tests/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff index 052e2e126643e..4a082bedec2b4 100644 --- a/tests/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff +++ b/tests/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.diff @@ -5,47 +5,58 @@ debug bar => _1; let mut _0: (); let mut _2: bool; - let mut _3: isize; -+ let mut _4: isize; + let mut _3: bool; + let mut _4: isize; ++ let mut _5: isize; bb0: { StorageLive(_2); - _3 = discriminant(_1); -- switchInt(move _3) -> [0: bb2, otherwise: bb1]; -+ StorageLive(_4); -+ _4 = move _3; -+ _2 = Eq(_4, const 0_isize); -+ StorageDead(_4); -+ switchInt(move _2) -> [0: bb2, otherwise: bb1]; + StorageLive(_3); + _4 = discriminant(_1); +- switchInt(move _4) -> [0: bb2, otherwise: bb1]; ++ StorageLive(_5); ++ _5 = move _4; ++ _3 = Eq(_5, const 0_isize); ++ StorageDead(_5); ++ _2 = must_use::(move _3) -> [return: bb1, unwind continue]; } bb1: { -- _2 = const false; -+ _0 = (); - goto -> bb3; +- _3 = const false; +- goto -> bb3; ++ switchInt(move _2) -> [0: bb3, otherwise: bb2]; } bb2: { -- _2 = const true; -+ _0 = const (); - goto -> bb3; - } - - bb3: { -- switchInt(move _2) -> [0: bb5, otherwise: bb4]; +- _3 = const true; +- goto -> bb3; - } - -- bb4: { -- _0 = (); -- goto -> bb6; +- bb3: { +- _2 = must_use::(move _3) -> [return: bb4, unwind continue]; - } - -- bb5: { -- _0 = const (); -- goto -> bb6; +- bb4: { +- switchInt(move _2) -> [0: bb6, otherwise: bb5]; - } - +- bb5: { + StorageDead(_3); + _0 = (); +- goto -> bb7; ++ goto -> bb4; + } + - bb6: { ++ bb3: { + StorageDead(_3); + _0 = const (); +- goto -> bb7; ++ goto -> bb4; + } + +- bb7: { ++ bb4: { StorageDead(_2); return; } diff --git a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir index 69c11ebcacced..d56195850defd 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir @@ -23,9 +23,11 @@ fn step_forward(_1: u16, _2: usize) -> u16 { } scope 7 (inlined Option::::is_none) { scope 8 (inlined Option::::is_some) { + scope 9 (inlined must_use::) { + } } } - scope 9 (inlined core::num::::wrapping_add) { + scope 10 (inlined core::num::::wrapping_add) { } } diff --git a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir index e6ea6c510019c..114b891a3b1be 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir @@ -23,9 +23,11 @@ fn step_forward(_1: u16, _2: usize) -> u16 { } scope 7 (inlined Option::::is_none) { scope 8 (inlined Option::::is_some) { + scope 9 (inlined must_use::) { + } } } - scope 9 (inlined core::num::::wrapping_add) { + scope 10 (inlined core::num::::wrapping_add) { } } diff --git a/tests/mir-opt/pre-codegen/matches_macro.issue_77355_opt.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/matches_macro.issue_77355_opt.PreCodegen.after.mir index d41135c6a4fa3..7a5d5d1d579f6 100644 --- a/tests/mir-opt/pre-codegen/matches_macro.issue_77355_opt.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/matches_macro.issue_77355_opt.PreCodegen.after.mir @@ -4,6 +4,8 @@ fn issue_77355_opt(_1: Foo) -> u64 { debug num => _1; let mut _0: u64; let mut _2: isize; + scope 1 (inlined must_use::) { + } bb0: { _2 = discriminant(_1); diff --git a/tests/ui/box/unit/unique-create.rs b/tests/ui/box/unit/unique-create.rs index bf3826156b1d4..a9691f068ab16 100644 --- a/tests/ui/box/unit/unique-create.rs +++ b/tests/ui/box/unit/unique-create.rs @@ -7,5 +7,5 @@ pub fn main() { } fn vec() { - vec![0]; + let _ = vec![0]; } diff --git a/tests/ui/issues/issue-13446.stderr b/tests/ui/issues/issue-13446.stderr index 28c459e6e62ce..63e23a549dff8 100644 --- a/tests/ui/issues/issue-13446.stderr +++ b/tests/ui/issues/issue-13446.stderr @@ -2,10 +2,20 @@ error[E0308]: mismatched types --> $DIR/issue-13446.rs:3:26 | LL | static VEC: [u32; 256] = vec![]; - | ^^^^^^ expected `[u32; 256]`, found `Vec<_>` + | ^^^^^^ + | | + | expected `[u32; 256]`, found `Vec<_>` + | arguments to this function are incorrect | = note: expected array `[u32; 256]` found struct `Vec<_>` +help: the return type of this call is `Vec<_>` due to the type of the argument passed + --> $DIR/issue-13446.rs:3:26 + | +LL | static VEC: [u32; 256] = vec![]; + | ^^^^^^ this argument influences the return type of `$crate` +note: function defined here + --> $SRC_DIR/core/src/hint.rs:LL:COL = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error diff --git a/tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs b/tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs index d5f6628e0dbc1..4495c193bd759 100644 --- a/tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs +++ b/tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs @@ -195,7 +195,7 @@ fn test_drop_list() { let dropped_fields = Rc::new(RefCell::new(Vec::new())); let cloned = AssertUnwindSafe(dropped_fields.clone()); panic::catch_unwind(|| { - vec![ + let _ = vec![ PushOnDrop::new(2, cloned.clone()), PushOnDrop::new(1, cloned.clone()), panic!("this panic is caught :D") diff --git a/tests/ui/rust-2018/remove-extern-crate.fixed b/tests/ui/rust-2018/remove-extern-crate.fixed index 19b1dc6fb0130..a6aa842238487 100644 --- a/tests/ui/rust-2018/remove-extern-crate.fixed +++ b/tests/ui/rust-2018/remove-extern-crate.fixed @@ -28,7 +28,7 @@ fn main() { with_visibility::foo(); remove_extern_crate::foo!(); bar!(); - alloc::vec![5]; + let _ = alloc::vec![5]; } mod another { diff --git a/tests/ui/rust-2018/remove-extern-crate.rs b/tests/ui/rust-2018/remove-extern-crate.rs index 88ef858da147f..ce194644f7ef5 100644 --- a/tests/ui/rust-2018/remove-extern-crate.rs +++ b/tests/ui/rust-2018/remove-extern-crate.rs @@ -28,7 +28,7 @@ fn main() { with_visibility::foo(); remove_extern_crate::foo!(); bar!(); - alloc::vec![5]; + let _ = alloc::vec![5]; } mod another {