From 4b2a8cc5127b0bbc5f624dce77308049005e1b66 Mon Sep 17 00:00:00 2001 From: newt Date: Sun, 6 Jul 2025 00:30:41 +0100 Subject: [PATCH 1/4] Detect prefixed attributes as duplicated --- .../src/attrs/duplicated_attributes.rs | 43 +++++++----- tests/ui/duplicated_attributes.rs | 1 + tests/ui/duplicated_attributes.stderr | 65 ++++++++++++++++--- 3 files changed, 83 insertions(+), 26 deletions(-) diff --git a/clippy_lints/src/attrs/duplicated_attributes.rs b/clippy_lints/src/attrs/duplicated_attributes.rs index c2406bcfb647..22b0b23145b3 100644 --- a/clippy_lints/src/attrs/duplicated_attributes.rs +++ b/clippy_lints/src/attrs/duplicated_attributes.rs @@ -2,6 +2,7 @@ use super::DUPLICATED_ATTRIBUTES; use clippy_utils::diagnostics::span_lint_and_then; use itertools::Itertools; use rustc_ast::{Attribute, MetaItem}; +use rustc_ast_pretty::pprust::path_to_string; use rustc_data_structures::fx::FxHashMap; use rustc_lint::EarlyContext; use rustc_span::{Span, Symbol, sym}; @@ -35,30 +36,38 @@ fn check_duplicated_attr( if attr.span.from_expansion() { return; } - let Some(ident) = attr.ident() else { return }; - let name = ident.name; - if name == sym::doc || name == sym::cfg_attr_trace || name == sym::rustc_on_unimplemented || name == sym::reason { - // FIXME: Would be nice to handle `cfg_attr` as well. Only problem is to check that cfg - // conditions are the same. - // `#[rustc_on_unimplemented]` contains duplicated subattributes, that's expected. - return; - } - if let Some(direct_parent) = parent.last() - && *direct_parent == sym::cfg_trace - && [sym::all, sym::not, sym::any].contains(&name) - { - // FIXME: We don't correctly check `cfg`s for now, so if it's more complex than just a one - // level `cfg`, we leave. - return; + let attr_path = path_to_string(&attr.path); + if let Some(ident) = attr.ident() { + let name = ident.name; + if name == sym::doc || name == sym::cfg_attr_trace || name == sym::rustc_on_unimplemented || name == sym::reason + { + // FIXME: Would be nice to handle `cfg_attr` as well. Only problem is to check that cfg + // conditions are the same. + // `#[rustc_on_unimplemented]` contains duplicated subattributes, that's expected. + return; + } + if let Some(direct_parent) = parent.last() + && *direct_parent == sym::cfg_trace + && [sym::all, sym::not, sym::any].contains(&name) + { + // FIXME: We don't correctly check `cfg`s for now, so if it's more complex than just a one + // level `cfg`, we leave. + return; + } } if let Some(value) = attr.value_str() { emit_if_duplicated( cx, attr, attr_paths, - format!("{}:{name}={value}", parent.iter().join(":")), + format!("{}:{attr_path}={value}", parent.iter().join(":")), ); } else if let Some(sub_attrs) = attr.meta_item_list() { + let name = if let Some(ident) = attr.ident() { + ident.name + } else { + Symbol::intern(&attr_path) + }; parent.push(name); for sub_attr in sub_attrs { if let Some(meta) = sub_attr.meta_item() { @@ -67,7 +76,7 @@ fn check_duplicated_attr( } parent.pop(); } else { - emit_if_duplicated(cx, attr, attr_paths, format!("{}:{name}", parent.iter().join(":"))); + emit_if_duplicated(cx, attr, attr_paths, format!("{}:{attr_path}", parent.iter().join(":"))); } } diff --git a/tests/ui/duplicated_attributes.rs b/tests/ui/duplicated_attributes.rs index 3ca91d6f1829..e33c57ed8eb2 100644 --- a/tests/ui/duplicated_attributes.rs +++ b/tests/ui/duplicated_attributes.rs @@ -1,4 +1,5 @@ //@aux-build:proc_macro_attr.rs +#![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] //~ ERROR: duplicated attribute #![feature(rustc_attrs)] #![warn(clippy::duplicated_attributes)] #![cfg(any(unix, windows))] diff --git a/tests/ui/duplicated_attributes.stderr b/tests/ui/duplicated_attributes.stderr index 0903617a8d1f..ed084aaa41ad 100644 --- a/tests/ui/duplicated_attributes.stderr +++ b/tests/ui/duplicated_attributes.stderr @@ -1,38 +1,85 @@ error: duplicated attribute - --> tests/ui/duplicated_attributes.rs:6:10 + --> tests/ui/duplicated_attributes.rs:2:17 + | +LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^ + | +note: first defined here + --> tests/ui/duplicated_attributes.rs:2:9 + | +LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^ +help: remove this attribute + --> tests/ui/duplicated_attributes.rs:2:17 + | +LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^ + = note: `-D clippy::duplicated-attributes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` + +error: duplicated attribute + --> tests/ui/duplicated_attributes.rs:2:56 + | +LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/duplicated_attributes.rs:2:25 + | +LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/duplicated_attributes.rs:2:56 + | +LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: duplicated attribute + --> tests/ui/duplicated_attributes.rs:7:10 | LL | #![allow(dead_code)] | ^^^^^^^^^ | note: first defined here - --> tests/ui/duplicated_attributes.rs:5:10 + --> tests/ui/duplicated_attributes.rs:6:10 | LL | #![allow(dead_code)] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/duplicated_attributes.rs:6:10 + --> tests/ui/duplicated_attributes.rs:7:10 | LL | #![allow(dead_code)] | ^^^^^^^^^ - = note: `-D clippy::duplicated-attributes` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` + +error: unused `#[macro_use]` import + --> tests/ui/duplicated_attributes.rs:10:1 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ + | +note: the lint level is defined here + --> tests/ui/duplicated_attributes.rs:2:17 + | +LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^ + = note: `#[deny(unused_imports)]` implied by `#[deny(unused)]` error: duplicated attribute - --> tests/ui/duplicated_attributes.rs:14:9 + --> tests/ui/duplicated_attributes.rs:15:9 | LL | #[allow(dead_code)] | ^^^^^^^^^ | note: first defined here - --> tests/ui/duplicated_attributes.rs:13:9 + --> tests/ui/duplicated_attributes.rs:14:9 | LL | #[allow(dead_code)] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/duplicated_attributes.rs:14:9 + --> tests/ui/duplicated_attributes.rs:15:9 | LL | #[allow(dead_code)] | ^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 5 previous errors From 4e14493c4b3da781443321449d24158b295d9c4c Mon Sep 17 00:00:00 2001 From: newt Date: Sun, 6 Jul 2025 01:14:58 +0100 Subject: [PATCH 2/4] Fix tests impacted by this change --- tests/ui/duplicated_attributes.rs | 6 +- tests/ui/duplicated_attributes.stderr | 14 +-- tests/ui/indexing_slicing_slice.rs | 1 + tests/ui/indexing_slicing_slice.stderr | 59 ++++++---- tests/ui/needless_collect_indirect.rs | 1 + tests/ui/needless_collect_indirect.stderr | 53 ++++++--- tests/ui/unnecessary_clippy_cfg.rs | 8 +- tests/ui/unnecessary_clippy_cfg.stderr | 130 +++++++++++++++++++--- 8 files changed, 211 insertions(+), 61 deletions(-) diff --git a/tests/ui/duplicated_attributes.rs b/tests/ui/duplicated_attributes.rs index e33c57ed8eb2..d3a12864f674 100644 --- a/tests/ui/duplicated_attributes.rs +++ b/tests/ui/duplicated_attributes.rs @@ -1,5 +1,7 @@ //@aux-build:proc_macro_attr.rs -#![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] //~ ERROR: duplicated attribute +#![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] +//~^ duplicated_attributes +//~| duplicated_attributes #![feature(rustc_attrs)] #![warn(clippy::duplicated_attributes)] #![cfg(any(unix, windows))] @@ -7,7 +9,7 @@ #![allow(dead_code)] //~ ERROR: duplicated attribute #![cfg(any(unix, windows))] // Should not warn! -#[macro_use] +#[macro_use] //~ ERROR: unused `#[macro_use]` import extern crate proc_macro_attr; #[cfg(any(unix, windows, target_os = "linux"))] diff --git a/tests/ui/duplicated_attributes.stderr b/tests/ui/duplicated_attributes.stderr index ed084aaa41ad..8f6c02af38f6 100644 --- a/tests/ui/duplicated_attributes.stderr +++ b/tests/ui/duplicated_attributes.stderr @@ -35,24 +35,24 @@ LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_a | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: duplicated attribute - --> tests/ui/duplicated_attributes.rs:7:10 + --> tests/ui/duplicated_attributes.rs:9:10 | LL | #![allow(dead_code)] | ^^^^^^^^^ | note: first defined here - --> tests/ui/duplicated_attributes.rs:6:10 + --> tests/ui/duplicated_attributes.rs:8:10 | LL | #![allow(dead_code)] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/duplicated_attributes.rs:7:10 + --> tests/ui/duplicated_attributes.rs:9:10 | LL | #![allow(dead_code)] | ^^^^^^^^^ error: unused `#[macro_use]` import - --> tests/ui/duplicated_attributes.rs:10:1 + --> tests/ui/duplicated_attributes.rs:12:1 | LL | #[macro_use] | ^^^^^^^^^^^^ @@ -65,18 +65,18 @@ LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_a = note: `#[deny(unused_imports)]` implied by `#[deny(unused)]` error: duplicated attribute - --> tests/ui/duplicated_attributes.rs:15:9 + --> tests/ui/duplicated_attributes.rs:17:9 | LL | #[allow(dead_code)] | ^^^^^^^^^ | note: first defined here - --> tests/ui/duplicated_attributes.rs:14:9 + --> tests/ui/duplicated_attributes.rs:16:9 | LL | #[allow(dead_code)] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/duplicated_attributes.rs:15:9 + --> tests/ui/duplicated_attributes.rs:17:9 | LL | #[allow(dead_code)] | ^^^^^^^^^ diff --git a/tests/ui/indexing_slicing_slice.rs b/tests/ui/indexing_slicing_slice.rs index cad77f56d03a..d08a89015779 100644 --- a/tests/ui/indexing_slicing_slice.rs +++ b/tests/ui/indexing_slicing_slice.rs @@ -12,6 +12,7 @@ unused )] #![warn(clippy::indexing_slicing)] +//~^ duplicated_attributes extern crate proc_macros; use proc_macros::with_span; diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr index e3ef89823e3d..018845fec819 100644 --- a/tests/ui/indexing_slicing_slice.stderr +++ b/tests/ui/indexing_slicing_slice.stderr @@ -1,5 +1,24 @@ +error: duplicated attribute + --> tests/ui/indexing_slicing_slice.rs:15:9 + | +LL | #![warn(clippy::indexing_slicing)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/indexing_slicing_slice.rs:3:9 + | +LL | #![warn(clippy::indexing_slicing)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/indexing_slicing_slice.rs:15:9 + | +LL | #![warn(clippy::indexing_slicing)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::duplicated-attributes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` + error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:115:6 + --> tests/ui/indexing_slicing_slice.rs:116:6 | LL | &x[index..]; | ^^^^^^^^^^ @@ -9,7 +28,7 @@ LL | &x[index..]; = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:117:6 + --> tests/ui/indexing_slicing_slice.rs:118:6 | LL | &x[..index]; | ^^^^^^^^^^ @@ -17,7 +36,7 @@ LL | &x[..index]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:119:6 + --> tests/ui/indexing_slicing_slice.rs:120:6 | LL | &x[index_from..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +44,7 @@ LL | &x[index_from..index_to]; = help: consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:121:6 + --> tests/ui/indexing_slicing_slice.rs:122:6 | LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +52,7 @@ LL | &x[index_from..][..index_to]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:121:6 + --> tests/ui/indexing_slicing_slice.rs:122:6 | LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^ @@ -41,7 +60,7 @@ LL | &x[index_from..][..index_to]; = help: consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:124:6 + --> tests/ui/indexing_slicing_slice.rs:125:6 | LL | &x[5..][..10]; | ^^^^^^^^^^^^ @@ -49,7 +68,7 @@ LL | &x[5..][..10]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> tests/ui/indexing_slicing_slice.rs:124:8 + --> tests/ui/indexing_slicing_slice.rs:125:8 | LL | &x[5..][..10]; | ^ @@ -58,7 +77,7 @@ LL | &x[5..][..10]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:127:6 + --> tests/ui/indexing_slicing_slice.rs:128:6 | LL | &x[0..][..3]; | ^^^^^^^^^^^ @@ -66,7 +85,7 @@ LL | &x[0..][..3]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:129:6 + --> tests/ui/indexing_slicing_slice.rs:130:6 | LL | &x[1..][..5]; | ^^^^^^^^^^^ @@ -74,19 +93,19 @@ LL | &x[1..][..5]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> tests/ui/indexing_slicing_slice.rs:137:12 + --> tests/ui/indexing_slicing_slice.rs:138:12 | LL | &y[0..=4]; | ^ error: range is out of bounds - --> tests/ui/indexing_slicing_slice.rs:139:11 + --> tests/ui/indexing_slicing_slice.rs:140:11 | LL | &y[..=4]; | ^ error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:145:6 + --> tests/ui/indexing_slicing_slice.rs:146:6 | LL | &v[10..100]; | ^^^^^^^^^^ @@ -94,7 +113,7 @@ LL | &v[10..100]; = help: consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:147:6 + --> tests/ui/indexing_slicing_slice.rs:148:6 | LL | &x[10..][..100]; | ^^^^^^^^^^^^^^ @@ -102,13 +121,13 @@ LL | &x[10..][..100]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> tests/ui/indexing_slicing_slice.rs:147:8 + --> tests/ui/indexing_slicing_slice.rs:148:8 | LL | &x[10..][..100]; | ^^ error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:150:6 + --> tests/ui/indexing_slicing_slice.rs:151:6 | LL | &v[10..]; | ^^^^^^^ @@ -116,7 +135,7 @@ LL | &v[10..]; = help: consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic - --> tests/ui/indexing_slicing_slice.rs:152:6 + --> tests/ui/indexing_slicing_slice.rs:153:6 | LL | &v[..100]; | ^^^^^^^^ @@ -124,7 +143,7 @@ LL | &v[..100]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_slice.rs:170:5 + --> tests/ui/indexing_slicing_slice.rs:171:5 | LL | map_with_get[true]; | ^^^^^^^^^^^^^^^^^^ @@ -132,7 +151,7 @@ LL | map_with_get[true]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_slice.rs:174:5 + --> tests/ui/indexing_slicing_slice.rs:175:5 | LL | s[0]; | ^^^^ @@ -140,12 +159,12 @@ LL | s[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui/indexing_slicing_slice.rs:178:5 + --> tests/ui/indexing_slicing_slice.rs:179:5 | LL | y[0]; | ^^^^ | = help: consider using `.get(n)` or `.get_mut(n)` instead -error: aborting due to 19 previous errors +error: aborting due to 20 previous errors diff --git a/tests/ui/needless_collect_indirect.rs b/tests/ui/needless_collect_indirect.rs index 57d0f2b99480..7c807be4ca5a 100644 --- a/tests/ui/needless_collect_indirect.rs +++ b/tests/ui/needless_collect_indirect.rs @@ -1,5 +1,6 @@ #![allow(clippy::uninlined_format_args, clippy::useless_vec)] #![allow(clippy::needless_if, clippy::uninlined_format_args)] +//~^ duplicated_attributes #![warn(clippy::needless_collect)] //@no-rustfix use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque}; diff --git a/tests/ui/needless_collect_indirect.stderr b/tests/ui/needless_collect_indirect.stderr index c7bf1b14df80..05e2d300c78c 100644 --- a/tests/ui/needless_collect_indirect.stderr +++ b/tests/ui/needless_collect_indirect.stderr @@ -1,5 +1,24 @@ +error: duplicated attribute + --> tests/ui/needless_collect_indirect.rs:2:31 + | +LL | #![allow(clippy::needless_if, clippy::uninlined_format_args)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/needless_collect_indirect.rs:1:10 + | +LL | #![allow(clippy::uninlined_format_args, clippy::useless_vec)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/needless_collect_indirect.rs:2:31 + | +LL | #![allow(clippy::needless_if, clippy::uninlined_format_args)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::duplicated-attributes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` + error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:9:39 + --> tests/ui/needless_collect_indirect.rs:10:39 | LL | let indirect_iter = sample.iter().collect::>(); | ^^^^^^^ @@ -18,7 +37,7 @@ LL ~ sample.iter().map(|x| (x, x + 1)).collect::>(); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:13:38 + --> tests/ui/needless_collect_indirect.rs:14:38 | LL | let indirect_len = sample.iter().collect::>(); | ^^^^^^^ @@ -35,7 +54,7 @@ LL ~ sample.iter().count(); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:17:40 + --> tests/ui/needless_collect_indirect.rs:18:40 | LL | let indirect_empty = sample.iter().collect::>(); | ^^^^^^^ @@ -52,7 +71,7 @@ LL ~ sample.iter().next().is_none(); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:21:43 + --> tests/ui/needless_collect_indirect.rs:22:43 | LL | let indirect_contains = sample.iter().collect::>(); | ^^^^^^^ @@ -69,7 +88,7 @@ LL ~ sample.iter().any(|x| x == &5); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:35:48 + --> tests/ui/needless_collect_indirect.rs:36:48 | LL | let non_copy_contains = sample.into_iter().collect::>(); | ^^^^^^^ @@ -86,7 +105,7 @@ LL ~ sample.into_iter().any(|x| x == a); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:66:51 + --> tests/ui/needless_collect_indirect.rs:67:51 | LL | let buffer: Vec<&str> = string.split('/').collect(); | ^^^^^^^ @@ -103,7 +122,7 @@ LL ~ string.split('/').count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:73:55 + --> tests/ui/needless_collect_indirect.rs:74:55 | LL | let indirect_len: VecDeque<_> = sample.iter().collect(); | ^^^^^^^ @@ -120,7 +139,7 @@ LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:80:57 + --> tests/ui/needless_collect_indirect.rs:81:57 | LL | let indirect_len: LinkedList<_> = sample.iter().collect(); | ^^^^^^^ @@ -137,7 +156,7 @@ LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:87:57 + --> tests/ui/needless_collect_indirect.rs:88:57 | LL | let indirect_len: BinaryHeap<_> = sample.iter().collect(); | ^^^^^^^ @@ -154,7 +173,7 @@ LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:149:59 + --> tests/ui/needless_collect_indirect.rs:150:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -172,7 +191,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == i); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:176:59 + --> tests/ui/needless_collect_indirect.rs:177:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -190,7 +209,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:207:63 + --> tests/ui/needless_collect_indirect.rs:208:63 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -208,7 +227,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:245:59 + --> tests/ui/needless_collect_indirect.rs:246:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -226,7 +245,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:272:26 + --> tests/ui/needless_collect_indirect.rs:273:26 | LL | let w = v.iter().collect::>(); | ^^^^^^^ @@ -244,7 +263,7 @@ LL ~ for _ in 0..v.iter().count() { | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:296:30 + --> tests/ui/needless_collect_indirect.rs:297:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ @@ -262,7 +281,7 @@ LL ~ while 1 == v.iter().count() { | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:320:30 + --> tests/ui/needless_collect_indirect.rs:321:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ @@ -279,5 +298,5 @@ LL | // Do lint LL ~ while let Some(i) = Some(v.iter().count()) { | -error: aborting due to 16 previous errors +error: aborting due to 17 previous errors diff --git a/tests/ui/unnecessary_clippy_cfg.rs b/tests/ui/unnecessary_clippy_cfg.rs index e7e01248dfbe..55ef1f6be890 100644 --- a/tests/ui/unnecessary_clippy_cfg.rs +++ b/tests/ui/unnecessary_clippy_cfg.rs @@ -5,22 +5,28 @@ //~^ unnecessary_clippy_cfg #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg +//~| duplicated_attributes #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg //~| duplicated_attributes +//~| duplicated_attributes #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg +//~| duplicated_attributes #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg +//~| duplicated_attributes #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg //~| duplicated_attributes +//~| duplicated_attributes #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg +//~| duplicated_attributes pub struct Bar; -fn main() {} +fn main() {} \ No newline at end of file diff --git a/tests/ui/unnecessary_clippy_cfg.stderr b/tests/ui/unnecessary_clippy_cfg.stderr index f66c68949548..29416d127ff4 100644 --- a/tests/ui/unnecessary_clippy_cfg.stderr +++ b/tests/ui/unnecessary_clippy_cfg.stderr @@ -16,7 +16,7 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:8:37 + --> tests/ui/unnecessary_clippy_cfg.rs:9:37 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,19 +24,19 @@ LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:11:1 + --> tests/ui/unnecessary_clippy_cfg.rs:13:1 | LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:14:1 + --> tests/ui/unnecessary_clippy_cfg.rs:17:1 | LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:16:36 + --> tests/ui/unnecessary_clippy_cfg.rs:19:36 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:18:36 + --> tests/ui/unnecessary_clippy_cfg.rs:22:36 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,13 +52,32 @@ LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] = note: write instead: `#[deny(clippy::non_minimal_cfg)]` error: no need to put clippy lints behind a `clippy` cfg - --> tests/ui/unnecessary_clippy_cfg.rs:21:1 + --> tests/ui/unnecessary_clippy_cfg.rs:26:1 | LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]` error: duplicated attribute - --> tests/ui/unnecessary_clippy_cfg.rs:8:26 + --> tests/ui/unnecessary_clippy_cfg.rs:6:37 + | +LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/unnecessary_clippy_cfg.rs:4:26 + | +LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/unnecessary_clippy_cfg.rs:6:37 + | +LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::duplicated-attributes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` + +error: duplicated attribute + --> tests/ui/unnecessary_clippy_cfg.rs:9:26 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ @@ -69,29 +88,112 @@ note: first defined here LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/unnecessary_clippy_cfg.rs:8:26 + --> tests/ui/unnecessary_clippy_cfg.rs:9:26 | LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ - = note: `-D clippy::duplicated-attributes` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` error: duplicated attribute - --> tests/ui/unnecessary_clippy_cfg.rs:18:25 + --> tests/ui/unnecessary_clippy_cfg.rs:9:37 + | +LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/unnecessary_clippy_cfg.rs:4:26 + | +LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/unnecessary_clippy_cfg.rs:9:37 + | +LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: duplicated attribute + --> tests/ui/unnecessary_clippy_cfg.rs:13:26 + | +LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/unnecessary_clippy_cfg.rs:4:26 + | +LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/unnecessary_clippy_cfg.rs:13:26 + | +LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: duplicated attribute + --> tests/ui/unnecessary_clippy_cfg.rs:19:36 + | +LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/unnecessary_clippy_cfg.rs:17:25 + | +LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/unnecessary_clippy_cfg.rs:19:36 + | +LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: duplicated attribute + --> tests/ui/unnecessary_clippy_cfg.rs:22:25 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ | note: first defined here - --> tests/ui/unnecessary_clippy_cfg.rs:16:25 + --> tests/ui/unnecessary_clippy_cfg.rs:19:25 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/unnecessary_clippy_cfg.rs:18:25 + --> tests/ui/unnecessary_clippy_cfg.rs:22:25 | LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] | ^^^^^^^^^ -error: aborting due to 10 previous errors +error: duplicated attribute + --> tests/ui/unnecessary_clippy_cfg.rs:22:36 + | +LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/unnecessary_clippy_cfg.rs:17:25 + | +LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/unnecessary_clippy_cfg.rs:22:36 + | +LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: duplicated attribute + --> tests/ui/unnecessary_clippy_cfg.rs:26:25 + | +LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/unnecessary_clippy_cfg.rs:17:25 + | +LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/unnecessary_clippy_cfg.rs:26:25 + | +LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 16 previous errors From a42fbc085b476eab47aefb8befb6d552f034892e Mon Sep 17 00:00:00 2001 From: newt Date: Sun, 6 Jul 2025 01:18:00 +0100 Subject: [PATCH 3/4] Remove unnecessary lint from duplicated_attributes test --- tests/ui/duplicated_attributes.rs | 7 +--- tests/ui/duplicated_attributes.stderr | 60 +++++++-------------------- tests/ui/unnecessary_clippy_cfg.rs | 2 +- 3 files changed, 18 insertions(+), 51 deletions(-) diff --git a/tests/ui/duplicated_attributes.rs b/tests/ui/duplicated_attributes.rs index d3a12864f674..9a6714995059 100644 --- a/tests/ui/duplicated_attributes.rs +++ b/tests/ui/duplicated_attributes.rs @@ -1,15 +1,12 @@ //@aux-build:proc_macro_attr.rs -#![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] -//~^ duplicated_attributes -//~| duplicated_attributes +#![warn(clippy::duplicated_attributes, clippy::duplicated_attributes)] //~ ERROR: duplicated attribute #![feature(rustc_attrs)] -#![warn(clippy::duplicated_attributes)] #![cfg(any(unix, windows))] #![allow(dead_code)] #![allow(dead_code)] //~ ERROR: duplicated attribute #![cfg(any(unix, windows))] // Should not warn! -#[macro_use] //~ ERROR: unused `#[macro_use]` import +#[macro_use] extern crate proc_macro_attr; #[cfg(any(unix, windows, target_os = "linux"))] diff --git a/tests/ui/duplicated_attributes.stderr b/tests/ui/duplicated_attributes.stderr index 8f6c02af38f6..922939d60dd6 100644 --- a/tests/ui/duplicated_attributes.stderr +++ b/tests/ui/duplicated_attributes.stderr @@ -1,85 +1,55 @@ error: duplicated attribute - --> tests/ui/duplicated_attributes.rs:2:17 + --> tests/ui/duplicated_attributes.rs:2:40 | -LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] - | ^^^^^^ +LL | #![warn(clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first defined here --> tests/ui/duplicated_attributes.rs:2:9 | -LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] - | ^^^^^^ +LL | #![warn(clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute - --> tests/ui/duplicated_attributes.rs:2:17 + --> tests/ui/duplicated_attributes.rs:2:40 | -LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] - | ^^^^^^ +LL | #![warn(clippy::duplicated_attributes, clippy::duplicated_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::duplicated-attributes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` error: duplicated attribute - --> tests/ui/duplicated_attributes.rs:2:56 - | -LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: first defined here - --> tests/ui/duplicated_attributes.rs:2:25 - | -LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: remove this attribute - --> tests/ui/duplicated_attributes.rs:2:56 - | -LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: duplicated attribute - --> tests/ui/duplicated_attributes.rs:9:10 + --> tests/ui/duplicated_attributes.rs:6:10 | LL | #![allow(dead_code)] | ^^^^^^^^^ | note: first defined here - --> tests/ui/duplicated_attributes.rs:8:10 + --> tests/ui/duplicated_attributes.rs:5:10 | LL | #![allow(dead_code)] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/duplicated_attributes.rs:9:10 + --> tests/ui/duplicated_attributes.rs:6:10 | LL | #![allow(dead_code)] | ^^^^^^^^^ -error: unused `#[macro_use]` import - --> tests/ui/duplicated_attributes.rs:12:1 - | -LL | #[macro_use] - | ^^^^^^^^^^^^ - | -note: the lint level is defined here - --> tests/ui/duplicated_attributes.rs:2:17 - | -LL | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)] - | ^^^^^^ - = note: `#[deny(unused_imports)]` implied by `#[deny(unused)]` - error: duplicated attribute - --> tests/ui/duplicated_attributes.rs:17:9 + --> tests/ui/duplicated_attributes.rs:14:9 | LL | #[allow(dead_code)] | ^^^^^^^^^ | note: first defined here - --> tests/ui/duplicated_attributes.rs:16:9 + --> tests/ui/duplicated_attributes.rs:13:9 | LL | #[allow(dead_code)] | ^^^^^^^^^ help: remove this attribute - --> tests/ui/duplicated_attributes.rs:17:9 + --> tests/ui/duplicated_attributes.rs:14:9 | LL | #[allow(dead_code)] | ^^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/unnecessary_clippy_cfg.rs b/tests/ui/unnecessary_clippy_cfg.rs index 55ef1f6be890..4a7c1416a17f 100644 --- a/tests/ui/unnecessary_clippy_cfg.rs +++ b/tests/ui/unnecessary_clippy_cfg.rs @@ -29,4 +29,4 @@ pub struct Bar; -fn main() {} \ No newline at end of file +fn main() {} From cf3b38a701e893dd5e0dfb55bd3a7471b2364250 Mon Sep 17 00:00:00 2001 From: newt Date: Sun, 6 Jul 2025 01:21:52 +0100 Subject: [PATCH 4/4] Rebless indexing_slicing_slice --- tests/ui/indexing_slicing_slice.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr index 018845fec819..1f2133148265 100644 --- a/tests/ui/indexing_slicing_slice.stderr +++ b/tests/ui/indexing_slicing_slice.stderr @@ -1,5 +1,5 @@ error: duplicated attribute - --> tests/ui/indexing_slicing_slice.rs:15:9 + --> tests/ui/indexing_slicing_slice.rs:14:9 | LL | #![warn(clippy::indexing_slicing)] | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -10,7 +10,7 @@ note: first defined here LL | #![warn(clippy::indexing_slicing)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute - --> tests/ui/indexing_slicing_slice.rs:15:9 + --> tests/ui/indexing_slicing_slice.rs:14:9 | LL | #![warn(clippy::indexing_slicing)] | ^^^^^^^^^^^^^^^^^^^^^^^^