From e5ed8643b6983ff7ddbc3cb2a8712edb65115a87 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 9 Nov 2025 12:55:51 +0100 Subject: [PATCH] adjust clippy to fix some of the issues --- compiler/rustc_span/src/symbol.rs | 1 - library/alloc/src/boxed.rs | 1 + library/alloc/src/slice.rs | 1 - src/tools/clippy/clippy_utils/src/higher.rs | 8 ++-- src/tools/clippy/clippy_utils/src/sym.rs | 1 + .../clippy/tests/ui/manual_map_option.fixed | 5 +-- .../clippy/tests/ui/manual_map_option.rs | 1 + .../clippy/tests/ui/manual_map_option.stderr | 18 ++++++-- src/tools/clippy/tests/ui/or_fun_call.fixed | 6 +-- src/tools/clippy/tests/ui/or_fun_call.rs | 6 +-- .../tests/ui/unwrap_or_else_default.fixed | 3 +- .../clippy/tests/ui/unwrap_or_else_default.rs | 1 - .../tests/ui/unwrap_or_else_default.stderr | 42 ++++++++----------- 13 files changed, 47 insertions(+), 47 deletions(-) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 37fff4a248ef..6ed487cd7efa 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2181,7 +2181,6 @@ symbols! { slice_from_raw_parts_mut, slice_from_ref, slice_get_unchecked, - slice_into_vec, slice_iter, slice_len_fn, slice_patterns, diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 5d36a6c463ea..221375baa2b6 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -259,6 +259,7 @@ unsafe fn box_new_uninit(size: usize, align: usize) -> *mut u8 { #[unstable(feature = "liballoc_internals", issue = "none")] #[inline(always)] #[cfg(not(no_global_oom_handling))] +#[rustc_diagnostic_item = "box_assume_init_into_vec_unsafe"] pub fn box_assume_init_into_vec_unsafe( b: Box>, ) -> crate::vec::Vec { diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index cc8d80aee456..39e72e383eac 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -477,7 +477,6 @@ impl [T] { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - #[rustc_diagnostic_item = "slice_into_vec"] pub fn into_vec(self: Box) -> Vec { unsafe { let len = self.len(); diff --git a/src/tools/clippy/clippy_utils/src/higher.rs b/src/tools/clippy/clippy_utils/src/higher.rs index 7d6787fec295..9c0b136e02b5 100644 --- a/src/tools/clippy/clippy_utils/src/higher.rs +++ b/src/tools/clippy/clippy_utils/src/higher.rs @@ -297,12 +297,12 @@ impl<'a> VecArgs<'a> { // `vec![elem; size]` case Some(VecArgs::Repeat(elem, size)) }, - (sym::slice_into_vec, [slice]) - if let ExprKind::Call(_, [arg]) = slice.kind - && let ExprKind::Array(args) = arg.kind => + (sym::box_assume_init_into_vec_unsafe, [write_box_via_move]) + if let ExprKind::Call(_, [_box, elems]) = write_box_via_move.kind + && let ExprKind::Array(elems) = elems.kind => { // `vec![a, b, c]` case - Some(VecArgs::Vec(args)) + Some(VecArgs::Vec(elems)) }, (sym::vec_new, []) => Some(VecArgs::Vec(&[])), _ => None, diff --git a/src/tools/clippy/clippy_utils/src/sym.rs b/src/tools/clippy/clippy_utils/src/sym.rs index e0b03ae4f7b2..bd99525a86fb 100644 --- a/src/tools/clippy/clippy_utils/src/sym.rs +++ b/src/tools/clippy/clippy_utils/src/sym.rs @@ -91,6 +91,7 @@ generate! { author, borrow, borrow_mut, + box_assume_init_into_vec_unsafe, build_hasher, by_ref, bytes, diff --git a/src/tools/clippy/tests/ui/manual_map_option.fixed b/src/tools/clippy/tests/ui/manual_map_option.fixed index 3586979ab358..e007f7d47b24 100644 --- a/src/tools/clippy/tests/ui/manual_map_option.fixed +++ b/src/tools/clippy/tests/ui/manual_map_option.fixed @@ -113,10 +113,7 @@ fn main() { } // #6811 - match Some(0) { - Some(x) => Some(vec![x]), - None => None, - }; + Some(0).map(|x| vec![x]); // Don't lint, coercion let x: Option> = match Some(()) { diff --git a/src/tools/clippy/tests/ui/manual_map_option.rs b/src/tools/clippy/tests/ui/manual_map_option.rs index 40133748d459..8aa51bab6f83 100644 --- a/src/tools/clippy/tests/ui/manual_map_option.rs +++ b/src/tools/clippy/tests/ui/manual_map_option.rs @@ -183,6 +183,7 @@ fn main() { // #6811 match Some(0) { + //~^ manual_map Some(x) => Some(vec![x]), None => None, }; diff --git a/src/tools/clippy/tests/ui/manual_map_option.stderr b/src/tools/clippy/tests/ui/manual_map_option.stderr index 486379c1e5f3..7d00c1757bb3 100644 --- a/src/tools/clippy/tests/ui/manual_map_option.stderr +++ b/src/tools/clippy/tests/ui/manual_map_option.stderr @@ -173,7 +173,17 @@ LL | | }; | |_____^ help: try: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:196:5 + --> tests/ui/manual_map_option.rs:185:5 + | +LL | / match Some(0) { +LL | | +LL | | Some(x) => Some(vec![x]), +LL | | None => None, +LL | | }; + | |_____^ help: try: `Some(0).map(|x| vec![x])` + +error: manual implementation of `Option::map` + --> tests/ui/manual_map_option.rs:197:5 | LL | / match option_env!("") { LL | | @@ -183,7 +193,7 @@ LL | | }; | |_____^ help: try: `option_env!("").map(String::from)` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:217:12 + --> tests/ui/manual_map_option.rs:218:12 | LL | } else if let Some(x) = Some(0) { | ____________^ @@ -195,7 +205,7 @@ LL | | }; | |_____^ help: try: `{ Some(0).map(|x| x + 1) }` error: manual implementation of `Option::map` - --> tests/ui/manual_map_option.rs:226:12 + --> tests/ui/manual_map_option.rs:227:12 | LL | } else if let Some(x) = Some(0) { | ____________^ @@ -206,5 +216,5 @@ LL | | None LL | | }; | |_____^ help: try: `{ Some(0).map(|x| x + 1) }` -error: aborting due to 20 previous errors +error: aborting due to 21 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 314da0804a5f..0d6f2aefa8a8 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.fixed +++ b/src/tools/clippy/tests/ui/or_fun_call.fixed @@ -53,7 +53,7 @@ fn or_fun_call() { with_constructor.unwrap_or_else(make); //~^ or_fun_call - let with_new = Some(vec![1]); + let with_new: Option> = Some(vec![1]); with_new.unwrap_or_default(); //~^ unwrap_or_default @@ -101,7 +101,7 @@ fn or_fun_call() { real_default.unwrap_or_default(); //~^ unwrap_or_default - let with_vec = Some(vec![1]); + let with_vec: Option> = Some(vec![1]); with_vec.unwrap_or_default(); //~^ unwrap_or_default @@ -329,7 +329,7 @@ mod lazy { } } - let with_new = Some(vec![1]); + let with_new: Option> = Some(vec![1]); with_new.unwrap_or_default(); //~^ unwrap_or_default diff --git a/src/tools/clippy/tests/ui/or_fun_call.rs b/src/tools/clippy/tests/ui/or_fun_call.rs index 2a19614026ec..e1946847698b 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.rs +++ b/src/tools/clippy/tests/ui/or_fun_call.rs @@ -53,7 +53,7 @@ fn or_fun_call() { with_constructor.unwrap_or(make()); //~^ or_fun_call - let with_new = Some(vec![1]); + let with_new: Option> = Some(vec![1]); with_new.unwrap_or(Vec::new()); //~^ unwrap_or_default @@ -101,7 +101,7 @@ fn or_fun_call() { real_default.unwrap_or(::default()); //~^ unwrap_or_default - let with_vec = Some(vec![1]); + let with_vec: Option> = Some(vec![1]); with_vec.unwrap_or(Vec::new()); //~^ unwrap_or_default @@ -329,7 +329,7 @@ mod lazy { } } - let with_new = Some(vec![1]); + let with_new: Option> = Some(vec![1]); with_new.unwrap_or_else(Vec::new); //~^ unwrap_or_default diff --git a/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed b/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed index 561cbce473de..5cf529fe0143 100644 --- a/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed +++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed @@ -43,8 +43,7 @@ fn unwrap_or_else_default() { with_enum.unwrap_or_else(Enum::A); let with_new = Some(vec![1]); - with_new.unwrap_or_default(); - //~^ unwrap_or_default + with_new.unwrap_or_else(Vec::new); let with_err: Result<_, ()> = Ok(vec![1]); with_err.unwrap_or_else(make); diff --git a/src/tools/clippy/tests/ui/unwrap_or_else_default.rs b/src/tools/clippy/tests/ui/unwrap_or_else_default.rs index 8389be964fe6..e49ff13e1f2f 100644 --- a/src/tools/clippy/tests/ui/unwrap_or_else_default.rs +++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.rs @@ -44,7 +44,6 @@ fn unwrap_or_else_default() { let with_new = Some(vec![1]); with_new.unwrap_or_else(Vec::new); - //~^ unwrap_or_default let with_err: Result<_, ()> = Ok(vec![1]); with_err.unwrap_or_else(make); diff --git a/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr b/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr index a001f7e46add..610f20fa62b1 100644 --- a/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr +++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr @@ -1,101 +1,95 @@ error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:46:14 + --> tests/ui/unwrap_or_else_default.rs:60:23 | -LL | with_new.unwrap_or_else(Vec::new); - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` +LL | with_real_default.unwrap_or_else(::default); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` | = note: `-D clippy::unwrap-or-default` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:61:23 - | -LL | with_real_default.unwrap_or_else(::default); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` - -error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:65:24 + --> tests/ui/unwrap_or_else_default.rs:64:24 | LL | with_default_trait.unwrap_or_else(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:69:23 + --> tests/ui/unwrap_or_else_default.rs:68:23 | LL | with_default_type.unwrap_or_else(u64::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:73:23 + --> tests/ui/unwrap_or_else_default.rs:72:23 | LL | with_default_type.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:77:18 + --> tests/ui/unwrap_or_else_default.rs:76:18 | LL | empty_string.unwrap_or_else(|| "".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:82:12 + --> tests/ui/unwrap_or_else_default.rs:81:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:86:12 + --> tests/ui/unwrap_or_else_default.rs:85:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:90:12 + --> tests/ui/unwrap_or_else_default.rs:89:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:94:12 + --> tests/ui/unwrap_or_else_default.rs:93:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:98:12 + --> tests/ui/unwrap_or_else_default.rs:97:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:102:12 + --> tests/ui/unwrap_or_else_default.rs:101:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:106:12 + --> tests/ui/unwrap_or_else_default.rs:105:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:110:12 + --> tests/ui/unwrap_or_else_default.rs:109:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/unwrap_or_else_default.rs:127:12 + --> tests/ui/unwrap_or_else_default.rs:126:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> tests/ui/unwrap_or_else_default.rs:145:32 + --> tests/ui/unwrap_or_else_default.rs:144:32 | LL | let _ = inner_map.entry(0).or_insert_with(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` -error: aborting due to 16 previous errors +error: aborting due to 15 previous errors