From 227cce4c0a874fee4664b469de87d121cedf6c1c Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 11 Jun 2026 12:52:12 +0200 Subject: [PATCH 01/63] The command to update the test results is `cargo uibless` --- clippy_dev/src/deprecate_lint.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_dev/src/deprecate_lint.rs b/clippy_dev/src/deprecate_lint.rs index bee7508dabb9a..616245ac99a71 100644 --- a/clippy_dev/src/deprecate_lint.rs +++ b/clippy_dev/src/deprecate_lint.rs @@ -55,7 +55,7 @@ pub fn deprecate<'cx>(cx: ParseCx<'cx>, clippy_version: Version, name: &'cx str, if remove_lint_declaration(name, &mod_path, &mut lints).unwrap_or(false) { generate_lint_files(UpdateMode::Change, &lints, &deprecated_lints, &renamed_lints); println!("info: `{name}` has successfully been deprecated"); - println!("note: you must run `cargo uitest` to update the test results"); + println!("note: you must run `cargo uibless` to update the test results"); } else { eprintln!("error: lint not found"); } @@ -107,7 +107,7 @@ pub fn uplift<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam if remove_lint_declaration(old_name, &mod_path, &mut lints).unwrap_or(false) { generate_lint_files(UpdateMode::Change, &lints, &deprecated_lints, &renamed_lints); println!("info: `{old_name}` has successfully been uplifted"); - println!("note: you must run `cargo uitest` to update the test results"); + println!("note: you must run `cargo uibless` to update the test results"); } else { eprintln!("error: lint not found"); } From d35c889c333ffa5b2f3e7fe5498ffec5ed223204 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 12 Jun 2026 11:40:55 -0700 Subject: [PATCH 02/63] Count length of the first paragraph by its text Because of the way this lint implements text splitting, I need to track markdown and text lengths separately. This is fairly easy, since we can exhaustively check every markdown event and count the characters inside. --- clippy_lints/src/doc/mod.rs | 25 +++++++++++++++---- .../src/doc/too_long_first_doc_paragraph.rs | 9 ++++--- .../ui/too_long_first_doc_paragraph-fix.fixed | 10 ++++++++ tests/ui/too_long_first_doc_paragraph-fix.rs | 8 ++++++ .../too_long_first_doc_paragraph-fix.stderr | 21 +++++++++++++++- tests/ui/too_long_first_doc_paragraph.rs | 12 +++++++++ tests/ui/too_long_first_doc_paragraph.stderr | 11 +++++++- 7 files changed, 85 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 81da571bdd601..4ae1d27280fea 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -776,7 +776,8 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { cx, item, attrs, - headers.first_paragraph_len, + headers.first_paragraph_text_len, + headers.first_paragraph_md_len, self.check_private_items, ); match item.kind { @@ -851,7 +852,8 @@ struct DocHeaders { safety: bool, errors: bool, panics: bool, - first_paragraph_len: usize, + first_paragraph_md_len: usize, + first_paragraph_text_len: usize, } /// Does some pre-processing on raw, desugared `#[doc]` attributes such as parsing them and @@ -1227,11 +1229,13 @@ fn check_doc<'a, Events: Iterator, Range { + if is_first_paragraph { + is_first_paragraph = false; + } if let End(TagEnd::Heading(_)) = event { in_heading = false; } @@ -1257,8 +1261,11 @@ fn check_doc<'a, Events: Iterator, Range in_footnote_definition = true, End(TagEnd::FootnoteDefinition) => in_footnote_definition = false, Start(_) | End(_) // We don't care about other tags - | TaskListMarker(_) | Code(_) | Rule | InlineMath(..) | DisplayMath(..) => (), + | TaskListMarker(_) | Rule => (), SoftBreak | HardBreak => { + if is_first_paragraph { + headers.first_paragraph_text_len += 1; + } if !containers.is_empty() && !in_footnote_definition // Tabs aren't handled correctly vvvv @@ -1284,7 +1291,15 @@ fn check_doc<'a, Events: Iterator, Range { + if is_first_paragraph { + headers.first_paragraph_text_len += code.chars().count(); + } + } Text(text) => { + if is_first_paragraph { + headers.first_paragraph_text_len += text.chars().count(); + } paragraph_range.end = range.end; let range_ = range.clone(); ticks_unbalanced |= text.contains('`') diff --git a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs index 8ba6e9d332ba8..0bafd63732a56 100644 --- a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs +++ b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs @@ -13,13 +13,14 @@ pub(super) fn check( cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute], - mut first_paragraph_len: usize, + first_paragraph_text_len: usize, + mut first_paragraph_md_len: usize, check_private_items: bool, ) { if !check_private_items && !cx.effective_visibilities.is_exported(item.owner_id.def_id) { return; } - if first_paragraph_len <= 200 + if first_paragraph_text_len <= 200 || !matches!( item.kind, // This is the list of items which can be documented AND are displayed on the module @@ -58,10 +59,10 @@ pub(super) fn check( } let len = doc.chars().count(); - if len >= first_paragraph_len { + if len >= first_paragraph_md_len { break; } - first_paragraph_len -= len; + first_paragraph_md_len -= len; } } diff --git a/tests/ui/too_long_first_doc_paragraph-fix.fixed b/tests/ui/too_long_first_doc_paragraph-fix.fixed index 7075aefd50b67..d2a07770f42e9 100644 --- a/tests/ui/too_long_first_doc_paragraph-fix.fixed +++ b/tests/ui/too_long_first_doc_paragraph-fix.fixed @@ -9,3 +9,13 @@ /// and probably spanning a many rows. Blablabla, it needs to be over /// 200 characters so I needed to write something longeeeeeeer. pub struct Foo; + +/// [A](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [very](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [short](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [summary](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com). +//~^ too_long_first_doc_paragraph +/// +//~^ too_long_first_doc_paragraph +/// A much longer explanation that goes into a lot more detail about +/// how the thing works, possibly with doclinks and so one, +/// and probably spanning a many rows. Blablabla, it needs to be over +/// 200 characters so I needed to write something longeeeeeeer. +pub struct Bar; diff --git a/tests/ui/too_long_first_doc_paragraph-fix.rs b/tests/ui/too_long_first_doc_paragraph-fix.rs index 844417d741ef8..ad01b0c3e8330 100644 --- a/tests/ui/too_long_first_doc_paragraph-fix.rs +++ b/tests/ui/too_long_first_doc_paragraph-fix.rs @@ -7,3 +7,11 @@ /// and probably spanning a many rows. Blablabla, it needs to be over /// 200 characters so I needed to write something longeeeeeeer. pub struct Foo; + +/// [A](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [very](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [short](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [summary](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com). +//~^ too_long_first_doc_paragraph +/// A much longer explanation that goes into a lot more detail about +/// how the thing works, possibly with doclinks and so one, +/// and probably spanning a many rows. Blablabla, it needs to be over +/// 200 characters so I needed to write something longeeeeeeer. +pub struct Bar; diff --git a/tests/ui/too_long_first_doc_paragraph-fix.stderr b/tests/ui/too_long_first_doc_paragraph-fix.stderr index bc2fbc2d14df6..f409b50e674d6 100644 --- a/tests/ui/too_long_first_doc_paragraph-fix.stderr +++ b/tests/ui/too_long_first_doc_paragraph-fix.stderr @@ -19,5 +19,24 @@ LL + /// LL + | -error: aborting due to 1 previous error +error: first doc comment paragraph is too long + --> tests/ui/too_long_first_doc_paragraph-fix.rs:11:1 + | +LL | / /// [A](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [very](https://foooooooooooooooooooooooooo... +LL | | +LL | | /// A much longer explanation that goes into a lot more detail about +LL | | /// how the thing works, possibly with doclinks and so one, +LL | | /// and probably spanning a many rows. Blablabla, it needs to be over +LL | | /// 200 characters so I needed to write something longeeeeeeer. + | |_^ + | +help: add an empty line + | +LL | /// [A](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [very](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [short](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) [summary](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com). +LL | +LL + /// +LL + + | + +error: aborting due to 2 previous errors diff --git a/tests/ui/too_long_first_doc_paragraph.rs b/tests/ui/too_long_first_doc_paragraph.rs index 49420841c88c7..e3dcc6f1f559b 100644 --- a/tests/ui/too_long_first_doc_paragraph.rs +++ b/tests/ui/too_long_first_doc_paragraph.rs @@ -68,6 +68,18 @@ fn f() {} /// Here's a second paragraph. It would be preferable to put the details here. pub fn issue_14274() {} +#[rustfmt::skip] +/// This doc comment contains two references: [this](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) +/// and [this](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com) +pub fn issue_13315() {} + +#[rustfmt::skip] +/// Some function. This doc-string paragraph is too long. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of [Lorem Ipsum](https://fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.example.com). +//~^ too_long_first_doc_paragraph +/// +/// Here's a second paragraph. It would be preferable to put the details here. +pub fn issue_1331_warn() {} + fn main() { // test code goes here } diff --git a/tests/ui/too_long_first_doc_paragraph.stderr b/tests/ui/too_long_first_doc_paragraph.stderr index 949ada30dc97d..0c67bc945c19e 100644 --- a/tests/ui/too_long_first_doc_paragraph.stderr +++ b/tests/ui/too_long_first_doc_paragraph.stderr @@ -48,5 +48,14 @@ LL | | /// LL | | /// Here's a second paragraph. It would be preferable to put the details here. | |_^ -error: aborting due to 4 previous errors +error: first doc comment paragraph is too long + --> tests/ui/too_long_first_doc_paragraph.rs:77:1 + | +LL | / /// Some function. This doc-string paragraph is too long. Lorem Ipsum is simply dummy text of the printing and typesetting industr... +LL | | +LL | | /// +LL | | /// Here's a second paragraph. It would be preferable to put the details here. + | |_^ + +error: aborting due to 5 previous errors From ee0e5a5e4f2bdef7cc4a43e5085f20e6f28fc657 Mon Sep 17 00:00:00 2001 From: Kokoro2336 <2529677678@qq.com> Date: Sat, 9 May 2026 21:26:07 +0800 Subject: [PATCH 03/63] fix: type inference failure in mul_add. test: supply test for issue 16954. fix: suggest MethodCall for expr with type anchor. fix: remove redudant is_lit check. fix: missing parenthesis for a * b. fix: remove redundant lit check. --- .../src/floating_point_arithmetic/lib.rs | 9 +- .../src/floating_point_arithmetic/ln1p.rs | 2 +- .../src/floating_point_arithmetic/mul_add.rs | 39 +++--- .../src/floating_point_arithmetic/powf.rs | 2 +- tests/ui/floating_point_mul_add.fixed | 73 +++++++++-- tests/ui/floating_point_mul_add.rs | 73 +++++++++-- tests/ui/floating_point_mul_add.stderr | 124 ++++++++++++++++-- 7 files changed, 269 insertions(+), 53 deletions(-) diff --git a/clippy_lints/src/floating_point_arithmetic/lib.rs b/clippy_lints/src/floating_point_arithmetic/lib.rs index 3fa041f97802a..2e8af518d0cd7 100644 --- a/clippy_lints/src/floating_point_arithmetic/lib.rs +++ b/clippy_lints/src/floating_point_arithmetic/lib.rs @@ -5,13 +5,15 @@ use rustc_hir::{Expr, ExprKind, UnOp}; use rustc_lint::LateContext; use rustc_middle::ty; -// Adds type suffixes and parenthesis to method receivers if necessary +// Adds type suffixes and parenthesis to method receivers if necessary, and returns whether a suffix +// was added. pub(super) fn prepare_receiver_sugg<'a>( cx: &LateContext<'_>, mut expr: &'a Expr<'a>, app: &mut Applicability, -) -> Sugg<'a> { +) -> (Sugg<'a>, bool) { let mut suggestion = Sugg::hir_with_applicability(cx, expr, "_", app); + let mut suffix_was_added = false; if let ExprKind::Unary(UnOp::Neg, inner_expr) = expr.kind { expr = inner_expr; @@ -36,7 +38,8 @@ pub(super) fn prepare_receiver_sugg<'a>( Sugg::MaybeParen(_) | Sugg::UnOp(UnOp::Neg, _) => Sugg::MaybeParen(op), _ => Sugg::NonParen(op), }; + suffix_was_added = true; } - suggestion.maybe_paren() + (suggestion.maybe_paren(), suffix_was_added) } diff --git a/clippy_lints/src/floating_point_arithmetic/ln1p.rs b/clippy_lints/src/floating_point_arithmetic/ln1p.rs index f37737c71aee1..d15547cf8082b 100644 --- a/clippy_lints/src/floating_point_arithmetic/ln1p.rs +++ b/clippy_lints/src/floating_point_arithmetic/ln1p.rs @@ -33,7 +33,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>) "ln(1 + x) can be computed more accurately", |diag| { let mut app = Applicability::MachineApplicable; - let recv = super::lib::prepare_receiver_sugg(cx, recv, &mut app); + let (recv, _) = super::lib::prepare_receiver_sugg(cx, recv, &mut app); diag.span_suggestion(expr.span, "consider using", format!("{recv}.ln_1p()"), app); }, ); diff --git a/clippy_lints/src/floating_point_arithmetic/mul_add.rs b/clippy_lints/src/floating_point_arithmetic/mul_add.rs index eb96e65638445..f5c3608696d5b 100644 --- a/clippy_lints/src/floating_point_arithmetic/mul_add.rs +++ b/clippy_lints/src/floating_point_arithmetic/mul_add.rs @@ -1,10 +1,12 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::sugg::Sugg; -use clippy_utils::{get_parent_expr, has_ambiguous_literal_in_expr, sym}; +use clippy_utils::ty::expr_type_is_certain; +use clippy_utils::{get_parent_expr, sym}; use rustc_ast::AssignOpKind; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment}; use rustc_lint::LateContext; +use rustc_middle::ty; use rustc_span::Spanned; use super::SUBOPTIMAL_FLOPS; @@ -65,24 +67,15 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { return; } - // Check if any variable in the expression has an ambiguous type (could be f32 or f64) - // see: https://github.com/rust-lang/rust-clippy/issues/14897 - let has_ambiguous_type = |expr: &Expr<'_>| { - (matches!(expr.kind, ExprKind::Path(_)) || matches!(expr.kind, ExprKind::Call(_, _))) - && has_ambiguous_literal_in_expr(cx, expr) - }; - - let (recv, arg1, arg2, is_from_rhs) = if let Some((inner_lhs, inner_rhs)) = is_float_mul_expr(cx, rhs) - && cx.typeck_results().expr_ty(lhs).is_floating_point() - && !has_ambiguous_type(inner_lhs) + let (recv, arg1, arg2, is_from_rhs, lhs_typ) = if let Some((inner_lhs, inner_rhs)) = is_float_mul_expr(cx, rhs) + && let ty::Float(float_ty) = cx.typeck_results().expr_ty(lhs).kind() { - (inner_lhs, inner_rhs, lhs, true) + (inner_lhs, inner_rhs, lhs, true, float_ty) } else if !is_assign && let Some((inner_lhs, inner_rhs)) = is_float_mul_expr(cx, lhs) - && cx.typeck_results().expr_ty(rhs).is_floating_point() - && !has_ambiguous_type(inner_lhs) + && let ty::Float(float_ty) = cx.typeck_results().expr_ty(rhs).kind() { - (inner_lhs, inner_rhs, rhs, false) + (inner_lhs, inner_rhs, rhs, false, float_ty) } else { return; }; @@ -98,7 +91,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if let BinOpKind::Sub = op { -sugg } else { sugg } }; let mut app = Applicability::MachineApplicable; - let recv_sugg = super::lib::prepare_receiver_sugg(cx, recv, &mut app); + + let (recv_sugg, suffix_was_added) = super::lib::prepare_receiver_sugg(cx, recv, &mut app); + let (arg1, arg2) = if is_from_rhs { ( maybe_neg_sugg(arg1, &mut app), @@ -110,13 +105,21 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { maybe_neg_sugg(arg2, &mut app), ) }; + + let mul_add_call = if suffix_was_added || expr_type_is_certain(cx, recv) { + format!("{recv_sugg}.mul_add({arg1}, {arg2})") + } else { + // If the receiver contains an ambiguous literal, we need to call `mul_add` with its inferred type. + format!("{}::mul_add({recv_sugg}, {arg1}, {arg2})", lhs_typ.name_str()) + }; + diag.span_suggestion( expr.span, "consider using", if is_assign { - format!("{arg2} = {recv_sugg}.mul_add({arg1}, {arg2})") + format!("{arg2} = {mul_add_call}") } else { - format!("{recv_sugg}.mul_add({arg1}, {arg2})") + mul_add_call }, app, ); diff --git a/clippy_lints/src/floating_point_arithmetic/powf.rs b/clippy_lints/src/floating_point_arithmetic/powf.rs index 8e4a7388e7841..6ad6824083cd4 100644 --- a/clippy_lints/src/floating_point_arithmetic/powf.rs +++ b/clippy_lints/src/floating_point_arithmetic/powf.rs @@ -54,7 +54,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, "exponent for bases 2 and e can be computed more accurately", |diag| { let mut app = Applicability::MachineApplicable; - let recv = super::lib::prepare_receiver_sugg(cx, &args[0], &mut app); + let (recv, _) = super::lib::prepare_receiver_sugg(cx, &args[0], &mut app); diag.span_suggestion(expr.span, "consider using", format!("{recv}.{method}()"), app); }, ); diff --git a/tests/ui/floating_point_mul_add.fixed b/tests/ui/floating_point_mul_add.fixed index a4841d309d569..3e60b9efe5b0c 100644 --- a/tests/ui/floating_point_mul_add.fixed +++ b/tests/ui/floating_point_mul_add.fixed @@ -72,32 +72,46 @@ fn _issue11831() { fn _issue14897() { let x = 1.0; - let _ = x * 2.0 + 0.5; // should not suggest mul_add - let _ = 0.5 + x * 2.0; // should not suggest mul_add - let _ = 0.5 + x * 1.2; // should not suggest mul_add - let _ = 1.2 + x * 1.2; // should not suggest mul_add + let _ = f64::mul_add(x, 2.0, 0.5); + //~^ suboptimal_flops + + let x = 1.0; + let _ = f64::mul_add(x, 2.0, 0.5); + //~^ suboptimal_flops + let _ = f64::mul_add(x, 1.2, 0.5); + //~^ suboptimal_flops + let _ = f64::mul_add(x, 1.2, 1.2); + //~^ suboptimal_flops let x = -1.0; - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = f64::mul_add(x, 1.2, 0.5); + //~^ suboptimal_flops let x = { 4.0 }; - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = f64::mul_add(x, 1.2, 0.5); + //~^ suboptimal_flops let x = if 1 > 2 { 1.0 } else { 2.0 }; - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = f64::mul_add(x, 1.2, 0.5); + //~^ suboptimal_flops let x = 2.4 + 1.2; - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = f64::mul_add(x, 1.2, 0.5); + //~^ suboptimal_flops let f = || 4.0; let x = f(); - let _ = 0.5 + f() * 1.2; // should not suggest mul_add - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = f64::mul_add(f(), 1.2, 0.5); + //~^ suboptimal_flops + + let _ = f64::mul_add(x, 1.2, 0.5); + //~^ suboptimal_flops let x = 0.1; let y = x; let z = y; - let _ = 0.5 + z * 1.2; // should not suggest mul_add + let _ = f64::mul_add(z, 1.2, 0.5); + //~^ suboptimal_flops let _ = 2.0f64.mul_add(x, 0.5); //~^ suboptimal_flops @@ -125,3 +139,40 @@ fn issue16573() { a = b.mul_add(-c, a); //~^ suboptimal_flops } + +fn issue16954() { + let k = 2.0_f32; + + let k3 = k * k * k; + let y = k3 + 0.1; + let _ = y.mul_add(-0.3, 1.0); + //~^ suboptimal_flops + + let k3 = k * k * k; + let y = k3 + 0.1_f32; + let _ = y.mul_add(-0.3, 1.0); + //~^ suboptimal_flops + + let k3 = k * k * k; + let y: f32 = k3 + 0.1; + let _ = y.mul_add(-0.3, 1.0); + //~^ suboptimal_flops + + const OFFSET: f32 = 0.1; + let k3 = k * k * k; + let y = k3 + OFFSET; + let _ = y.mul_add(-0.3, 1.0); + //~^ suboptimal_flops + + let x = 0.1; + let y = 0.2; + let z = 0.3; + let _ = f32::mul_add(y, z, x); + //~^ suboptimal_flops + let _ = f32::mul_add(y, z, x); + //~^ suboptimal_flops + + let a: f32 = 0.1; + let _ = a.mul_add(z, y); + //~^ suboptimal_flops +} diff --git a/tests/ui/floating_point_mul_add.rs b/tests/ui/floating_point_mul_add.rs index c048653a41238..13625b4bb9ce5 100644 --- a/tests/ui/floating_point_mul_add.rs +++ b/tests/ui/floating_point_mul_add.rs @@ -72,32 +72,46 @@ fn _issue11831() { fn _issue14897() { let x = 1.0; - let _ = x * 2.0 + 0.5; // should not suggest mul_add - let _ = 0.5 + x * 2.0; // should not suggest mul_add - let _ = 0.5 + x * 1.2; // should not suggest mul_add - let _ = 1.2 + x * 1.2; // should not suggest mul_add + let _ = x * 2.0 + 0.5; + //~^ suboptimal_flops + + let x = 1.0; + let _ = 0.5 + x * 2.0; + //~^ suboptimal_flops + let _ = 0.5 + x * 1.2; + //~^ suboptimal_flops + let _ = 1.2 + x * 1.2; + //~^ suboptimal_flops let x = -1.0; - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = 0.5 + x * 1.2; + //~^ suboptimal_flops let x = { 4.0 }; - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = 0.5 + x * 1.2; + //~^ suboptimal_flops let x = if 1 > 2 { 1.0 } else { 2.0 }; - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = 0.5 + x * 1.2; + //~^ suboptimal_flops let x = 2.4 + 1.2; - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = 0.5 + x * 1.2; + //~^ suboptimal_flops let f = || 4.0; let x = f(); - let _ = 0.5 + f() * 1.2; // should not suggest mul_add - let _ = 0.5 + x * 1.2; // should not suggest mul_add + let _ = 0.5 + f() * 1.2; + //~^ suboptimal_flops + + let _ = 0.5 + x * 1.2; + //~^ suboptimal_flops let x = 0.1; let y = x; let z = y; - let _ = 0.5 + z * 1.2; // should not suggest mul_add + let _ = 0.5 + z * 1.2; + //~^ suboptimal_flops let _ = 0.5 + 2.0 * x; //~^ suboptimal_flops @@ -125,3 +139,40 @@ fn issue16573() { a -= b * c; //~^ suboptimal_flops } + +fn issue16954() { + let k = 2.0_f32; + + let k3 = k * k * k; + let y = k3 + 0.1; + let _ = 1.0 - y * 0.3; + //~^ suboptimal_flops + + let k3 = k * k * k; + let y = k3 + 0.1_f32; + let _ = 1.0 - y * 0.3; + //~^ suboptimal_flops + + let k3 = k * k * k; + let y: f32 = k3 + 0.1; + let _ = 1.0 - y * 0.3; + //~^ suboptimal_flops + + const OFFSET: f32 = 0.1; + let k3 = k * k * k; + let y = k3 + OFFSET; + let _ = 1.0 - y * 0.3; + //~^ suboptimal_flops + + let x = 0.1; + let y = 0.2; + let z = 0.3; + let _ = x + y * z; + //~^ suboptimal_flops + let _ = y * z + x; + //~^ suboptimal_flops + + let a: f32 = 0.1; + let _ = y + a * z; + //~^ suboptimal_flops +} diff --git a/tests/ui/floating_point_mul_add.stderr b/tests/ui/floating_point_mul_add.stderr index b14d0585f2c96..f74a874c3351f 100644 --- a/tests/ui/floating_point_mul_add.stderr +++ b/tests/ui/floating_point_mul_add.stderr @@ -81,46 +81,154 @@ LL | let _ = a - (b * u as f64); | ^^^^^^^^^^^^^^^^^^ help: consider using: `b.mul_add(-(u as f64), a)` error: multiply and add expressions may be calculated more efficiently and accurately - --> tests/ui/floating_point_mul_add.rs:102:13 + --> tests/ui/floating_point_mul_add.rs:75:13 + | +LL | let _ = x * 2.0 + 0.5; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(x, 2.0, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:79:13 + | +LL | let _ = 0.5 + x * 2.0; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(x, 2.0, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:81:13 + | +LL | let _ = 0.5 + x * 1.2; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(x, 1.2, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:83:13 + | +LL | let _ = 1.2 + x * 1.2; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(x, 1.2, 1.2)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:87:13 + | +LL | let _ = 0.5 + x * 1.2; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(x, 1.2, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:91:13 + | +LL | let _ = 0.5 + x * 1.2; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(x, 1.2, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:95:13 + | +LL | let _ = 0.5 + x * 1.2; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(x, 1.2, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:99:13 + | +LL | let _ = 0.5 + x * 1.2; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(x, 1.2, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:104:13 + | +LL | let _ = 0.5 + f() * 1.2; + | ^^^^^^^^^^^^^^^ help: consider using: `f64::mul_add(f(), 1.2, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:107:13 + | +LL | let _ = 0.5 + x * 1.2; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(x, 1.2, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:113:13 + | +LL | let _ = 0.5 + z * 1.2; + | ^^^^^^^^^^^^^ help: consider using: `f64::mul_add(z, 1.2, 0.5)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:116:13 | LL | let _ = 0.5 + 2.0 * x; | ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(x, 0.5)` error: multiply and add expressions may be calculated more efficiently and accurately - --> tests/ui/floating_point_mul_add.rs:104:13 + --> tests/ui/floating_point_mul_add.rs:118:13 | LL | let _ = 2.0 * x + 0.5; | ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(x, 0.5)` error: multiply and add expressions may be calculated more efficiently and accurately - --> tests/ui/floating_point_mul_add.rs:107:13 + --> tests/ui/floating_point_mul_add.rs:121:13 | LL | let _ = x + 2.0 * 4.0; | ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4.0, x)` error: multiply and add expressions may be calculated more efficiently and accurately - --> tests/ui/floating_point_mul_add.rs:111:13 + --> tests/ui/floating_point_mul_add.rs:125:13 | LL | let _ = y * 2.0 + 0.5; | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(2.0, 0.5)` error: multiply and add expressions may be calculated more efficiently and accurately - --> tests/ui/floating_point_mul_add.rs:113:13 + --> tests/ui/floating_point_mul_add.rs:127:13 | LL | let _ = 1.0 * 2.0 + 0.5; | ^^^^^^^^^^^^^^^ help: consider using: `1.0f64.mul_add(2.0, 0.5)` error: multiply and add expressions may be calculated more efficiently and accurately - --> tests/ui/floating_point_mul_add.rs:122:5 + --> tests/ui/floating_point_mul_add.rs:136:5 | LL | a += b * c; | ^^^^^^^^^^ help: consider using: `a = b.mul_add(c, a)` error: multiply and add expressions may be calculated more efficiently and accurately - --> tests/ui/floating_point_mul_add.rs:125:5 + --> tests/ui/floating_point_mul_add.rs:139:5 | LL | a -= b * c; | ^^^^^^^^^^ help: consider using: `a = b.mul_add(-c, a)` -error: aborting due to 20 previous errors +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:148:13 + | +LL | let _ = 1.0 - y * 0.3; + | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(-0.3, 1.0)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:153:13 + | +LL | let _ = 1.0 - y * 0.3; + | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(-0.3, 1.0)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:158:13 + | +LL | let _ = 1.0 - y * 0.3; + | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(-0.3, 1.0)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:164:13 + | +LL | let _ = 1.0 - y * 0.3; + | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(-0.3, 1.0)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:170:13 + | +LL | let _ = x + y * z; + | ^^^^^^^^^ help: consider using: `f32::mul_add(y, z, x)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:172:13 + | +LL | let _ = y * z + x; + | ^^^^^^^^^ help: consider using: `f32::mul_add(y, z, x)` + +error: multiply and add expressions may be calculated more efficiently and accurately + --> tests/ui/floating_point_mul_add.rs:176:13 + | +LL | let _ = y + a * z; + | ^^^^^^^^^ help: consider using: `a.mul_add(z, y)` + +error: aborting due to 38 previous errors From 518a89fc9e2328f9077f3ac6e66838f51d856b0e Mon Sep 17 00:00:00 2001 From: "Tim (Theemathas Chirananthavat)" Date: Tue, 23 Jun 2026 17:45:40 +0700 Subject: [PATCH 04/63] Rename `negated` to `is_negated_pat`. This better matches how the argument is actually used. See `rustc_hir::intravisit::{walk_expr,walk_pat_expr}`. --- clippy_lints/src/approx_const.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 2ea921e5d4614..b7b9befd10b0b 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -75,7 +75,7 @@ impl ApproxConstant { } impl LateLintPass<'_> for ApproxConstant { - fn check_lit(&mut self, cx: &LateContext<'_>, _hir_id: HirId, lit: Lit, _negated: bool) { + fn check_lit(&mut self, cx: &LateContext<'_>, _hir_id: HirId, lit: Lit, _is_negated_pat: bool) { match lit.node { LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty { FloatTy::F16 => self.check_known_consts(cx, lit.span, s, "f16"), From a8bc1d7c42ba20478ed10edab54316a1c5d49b6d Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 7 Jun 2026 17:41:40 -0700 Subject: [PATCH 05/63] Fix `unbalanced_ticks` when doc isn't contiguous --- clippy_lints/src/doc/mod.rs | 13 +++---------- tests/ui/doc/unbalanced_ticks.stderr | 5 ++--- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index c5816cb8b2d63..013fb32bdaf3c 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -1242,7 +1242,8 @@ fn check_doc<'a, Events: Iterator, Range, Range tests/ui/doc/unbalanced_ticks.rs:6:5 + --> tests/ui/doc/unbalanced_ticks.rs:6:1 | -LL | /// This is a doc comment with `unbalanced_tick marks and several words that - | _____^ +LL | / /// This is a doc comment with `unbalanced_tick marks and several words that LL | | LL | | /// should be `encompassed_by` tick marks because they `contain_underscores`. LL | | /// Because of the initial `unbalanced_tick` pair, the error message is From f08a46a4affd77e667e1b76754fbb1b33d2e4d23 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 7 Jun 2026 17:46:08 -0700 Subject: [PATCH 06/63] Add test case for split missing punctuation --- ...doc_paragraph_missing_punctuation_split_16169.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/ui/doc/doc_paragraph_missing_punctuation_split_16169.rs diff --git a/tests/ui/doc/doc_paragraph_missing_punctuation_split_16169.rs b/tests/ui/doc/doc_paragraph_missing_punctuation_split_16169.rs new file mode 100644 index 0000000000000..c01b0c90b120e --- /dev/null +++ b/tests/ui/doc/doc_paragraph_missing_punctuation_split_16169.rs @@ -0,0 +1,13 @@ +//@ check-pass +// https://github.com/rust-lang/rust-clippy/issues/16169 +#![allow(clippy::mixed_attributes_style)] + +/// +pub fn dont_warn_inner_outer() { + //!w +} +/// +#[inline] +///w +pub fn dont_warn_split_by_attr() { +} From 490da02117a421084c5934676c233404c7fa692c Mon Sep 17 00:00:00 2001 From: Aliaksei Semianiuk Date: Sun, 28 Jun 2026 00:19:31 +0500 Subject: [PATCH 07/63] Changelog for Clippy 1.97 --- CHANGELOG.md | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 689d56d0fb7c6..d456c3127138a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,115 @@ document. ## Unreleased / Beta / In Rust Nightly -[88f787...master](https://github.com/rust-lang/rust-clippy/compare/88f787...master) +[b147b68...master](https://github.com/rust-lang/rust-clippy/compare/b147b68...master) + +## Rust 1.97 + +Current stable, released 2026-07-09 + +[View all 55 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2026-04-04T13%3A32%3A00Z..2026-05-13T17%3A35%3A43Z+base%3Amaster) + +### New Lints + +* Added [`manual_assert_eq`] to `pedantic` + [#16025](https://github.com/rust-lang/rust-clippy/pull/16025) +* Added [`manual_clear`] to `perf` + [#16617](https://github.com/rust-lang/rust-clippy/pull/16617) +* Added [`useless_borrows_in_formatting`] to `perf` + [#16523](https://github.com/rust-lang/rust-clippy/pull/16523) +* Added [`inline_trait_bounds`] to `restriction` + [#16486](https://github.com/rust-lang/rust-clippy/pull/16486) +* Added [`inline_modules`] to `restriction` + [#16732](https://github.com/rust-lang/rust-clippy/pull/16732) + +### Moves and Deprecations + +* Moved [`nonminimal_bool`] from `complexity` to `pedantic` + [#16761](https://github.com/rust-lang/rust-clippy/pull/16761) +* Moved [`overly_complex_bool_expr`] from `correctness` to `pedantic` + [#16761](https://github.com/rust-lang/rust-clippy/pull/16761) + +### Enhancements + +* [`unused_format_specs`] detect format width below the minimum output size for `#x`/`#o`/`#b`, + exponent, and pointer formats + [#16542](https://github.com/rust-lang/rust-clippy/pull/16542) +* [`zst_offset`] detect zero-sized `NonNull` offset calculations + [#16888](https://github.com/rust-lang/rust-clippy/pull/16888) +* [`byte_char_slices`] enhance to cover arrays + [#16770](https://github.com/rust-lang/rust-clippy/pull/16770) +* [`manual_filter`] enhance to cover `and_then` + [#16456](https://github.com/rust-lang/rust-clippy/pull/16456) +* [`unneeded_wildcard_pattern`] add support for struct constructs + [#16733](https://github.com/rust-lang/rust-clippy/pull/16733) +* [`needless_late_init`] enhance to cover grouped assignments + [#16746](https://github.com/rust-lang/rust-clippy/pull/16746) +* [`needless_return_with_question_mark`] fix FN in async function bodies + [#16952](https://github.com/rust-lang/rust-clippy/pull/16952) +* [`needless_ifs`] fix FN when code contains a vertical tab (`\x0B`) whitespace + [#16845](https://github.com/rust-lang/rust-clippy/pull/16845) +* [`cloned_ref_to_slice_refs`] fix FN on `to_owned()` + [#16329](https://github.com/rust-lang/rust-clippy/pull/16329) +* [`for_kv_map`] fix FN when using `iter` and `iter_mut` + [#16830](https://github.com/rust-lang/rust-clippy/pull/16830) +* [`question_mark`] fix FN for manual unwrap with `if let` or `match`, when the scrutinee is behind + a reference, and when the binding is behind `ref` or `mut` + [#16769](https://github.com/rust-lang/rust-clippy/pull/16769) +* [`question_mark`] fix wrong suggestion when the match arm body is a destructuring assignment + [#16863](https://github.com/rust-lang/rust-clippy/pull/16863) +* [`expect_fun_call`] fix wrong suggestions for string slicing + [#16752](https://github.com/rust-lang/rust-clippy/pull/16752) +* [`println_empty_string`] fix wrong suggestion with non-parenthesis delimiters + [#16846](https://github.com/rust-lang/rust-clippy/pull/16846) +* [`int_plus_one`] parenthesize an `as` cast in the suggestion when the replacement operator is `<` + to avoid a parse error + [#16848](https://github.com/rust-lang/rust-clippy/pull/16848) +* [`bad_bit_mask`] truncate the constant to the target type before warning about impossible equality + [#16782](https://github.com/rust-lang/rust-clippy/pull/16782) +* [`manual_rotate`], [`map_with_unused_argument_over_ranges`], [`needless_bool`], + [`manual_is_power_of_two`], [`manual_div_ceil`], [`implicit_saturating_sub`], [`range_minus_one`], + [`range_plus_one`], [`manual_swap`], [`let_and_return`] fix wrongly unmangled macros + [#16443](https://github.com/rust-lang/rust-clippy/pull/16443) +* [`manual_noop_waker`] add an MSRV check + [#16850](https://github.com/rust-lang/rust-clippy/pull/16850) + +### False Positive Fixes + +* [`manual_option_zip`] fix FP when the outer param is used in a closure + [#16970](https://github.com/rust-lang/rust-clippy/pull/16970) +* [`non_canonical_clone_impl`] fix incompatibility with [`implicit_return`] + [#16949](https://github.com/rust-lang/rust-clippy/pull/16949) +* [`from_over_into`] don't lint when a blanket `From` impl would cause a coherence conflict + [#16881](https://github.com/rust-lang/rust-clippy/pull/16881) +* [`collapsible_match`] no longer suggests collapsing `pattern => { if test { body } }` into a match + guard when non-wildcard arms follow, as this changes the semantics of the match + [#16878](https://github.com/rust-lang/rust-clippy/pull/16878) +* [`unused_async`] fix FP for stubs with args + [#16832](https://github.com/rust-lang/rust-clippy/pull/16832) +* [`useless_conversion`] do not lint on `(a..b).into_iter()`, for compatibility with future range + syntax changes + [#16891](https://github.com/rust-lang/rust-clippy/pull/16891) +* [`bind_instead_of_map`] do not propose a rewrite when the only way to leave the closure is through + a divergent statement other than `return` + [#16867](https://github.com/rust-lang/rust-clippy/pull/16867) +* [`let_and_return`] do not trigger on the `let else` construct + [#16829](https://github.com/rust-lang/rust-clippy/pull/16829) +* [`fn_to_numeric_cast_any`] fix FP on a cast to a raw pointer + [#14109](https://github.com/rust-lang/rust-clippy/pull/14109) +* [`unnecessary_cast`] no longer suggests removing a cast that can cause a compilation error + [#16796](https://github.com/rust-lang/rust-clippy/pull/16796) +* [`unsafe_removed_from_name`] skip linting when renaming to `_` + [#16802](https://github.com/rust-lang/rust-clippy/pull/16802) + +### ICE Fixes + +* [`bad_bit_mask`] fix ICE for overloaded bit ops + [#16937](https://github.com/rust-lang/rust-clippy/pull/16937) + +### Performance Improvements + +* Fold all late lint passes into one statically-combined pass + [#17124](https://github.com/rust-lang/rust-clippy/pull/17124) ## Rust 1.96 From b9a091141930f62d9ffa0e282594966dfefb9b95 Mon Sep 17 00:00:00 2001 From: wasd243 Date: Fri, 3 Jul 2026 12:03:46 -0400 Subject: [PATCH 08/63] arbitrary_source_item_ordering: add configurable trait impl ordering modes Implement configuration-based approach with three options: - alphabetical (default) - trait_item_ordering - alphabetical_or_trait_item_ordering Fixes false positives for non-alphabetically-ordered trait definitions. --- CHANGELOG.md | 1 + book/src/lint_configuration.md | 24 +++ clippy_config/src/conf.rs | 19 +- clippy_config/src/types.rs | 9 + .../src/arbitrary_source_item_ordering.rs | 183 +++++++++++++++--- clippy_test_deps/Cargo.lock | 4 +- .../alphabetical_or_trait_item_order.rs | 46 +++++ ...alphabetical_or_trait_item_order_failed.rs | 33 ++++ ...abetical_or_trait_item_order_failed.stderr | 31 +++ .../clippy.toml | 1 + .../trait_definition_order/clippy.toml | 1 + .../trait_definition_order.rs | 24 +++ .../trait_definition_order_failed.rs | 53 +++++ ...t_definition_order_failed.trait_def.stderr | 43 ++++ .../toml_unknown_key/conf_unknown_key.stderr | 3 + 15 files changed, 446 insertions(+), 29 deletions(-) create mode 100644 tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order.rs create mode 100644 tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs create mode 100644 tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.stderr create mode 100644 tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/clippy.toml create mode 100644 tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/clippy.toml create mode 100644 tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order.rs create mode 100644 tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs create mode 100644 tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.trait_def.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 689d56d0fb7c6..d7f6fff40b160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7626,6 +7626,7 @@ Released 2018-09-13 [`too-many-arguments-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#too-many-arguments-threshold [`too-many-lines-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#too-many-lines-threshold [`trait-assoc-item-kinds-order`]: https://doc.rust-lang.org/clippy/lint_configuration.html#trait-assoc-item-kinds-order +[`trait-impl-item-order`]: https://doc.rust-lang.org/clippy/lint_configuration.html#trait-impl-item-order [`trivial-copy-size-limit`]: https://doc.rust-lang.org/clippy/lint_configuration.html#trivial-copy-size-limit [`type-complexity-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#type-complexity-threshold [`unnecessary-box-size`]: https://doc.rust-lang.org/clippy/lint_configuration.html#unnecessary-box-size diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index b3bef3b4666dc..fb4df6234dacd 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -1168,6 +1168,30 @@ The order of associated items in traits. * [`arbitrary_source_item_ordering`](https://rust-lang.github.io/rust-clippy/master/index.html#arbitrary_source_item_ordering) +## `trait-impl-item-order` +The required ordering of associated items in trait impls: purely alphabetical, +following the trait definition order, or accepting either. + +Note that the trait definition order may change between versions of the +crate defining the trait without being considered a breaking change. + +Examples: +When using trait definition item ordering: +```toml +trait-impl-item-order = "trait_item_ordering" +``` +When using trait definition item ordering and alphabetical for fallbacks: +```toml +trait-impl-item-order = "alphabetical_or_trait_item_ordering" +``` + +**Default Value:** `"alphabetical"` + +--- +**Affected lints:** +* [`arbitrary_source_item_ordering`](https://rust-lang.github.io/rust-clippy/master/index.html#arbitrary_source_item_ordering) + + ## `trivial-copy-size-limit` The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by reference. diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 5dfb934b90ce7..8a2795defc08f 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -3,7 +3,7 @@ use crate::types::{ DisallowedPath, DisallowedPathWithoutReplacement, InherentImplLintScope, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrdering, SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind, SourceItemOrderingTraitAssocItemKind, - SourceItemOrderingTraitAssocItemKinds, SourceItemOrderingWithinModuleItemGroupings, + SourceItemOrderingTraitAssocItemKinds, SourceItemOrderingWithinModuleItemGroupings, TraitImplItemOrder, }; use clippy_utils::msrvs::Msrv; use itertools::Itertools; @@ -917,6 +917,23 @@ define_Conf! { /// The order of associated items in traits. #[lints(arbitrary_source_item_ordering)] trait_assoc_item_kinds_order: SourceItemOrderingTraitAssocItemKinds = DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER.into(), + /// The required ordering of associated items in trait impls: purely alphabetical, + /// following the trait definition order, or accepting either. + /// + /// Note that the trait definition order may change between versions of the + /// crate defining the trait without being considered a breaking change. + /// + /// Examples: + /// When using trait definition item ordering: + /// ```toml + /// trait-impl-item-order = "trait_item_ordering" + /// ``` + /// When using trait definition item ordering and alphabetical for fallbacks: + /// ```toml + /// trait-impl-item-order = "alphabetical_or_trait_item_ordering" + /// ``` + #[lints(arbitrary_source_item_ordering)] + trait_impl_item_order: TraitImplItemOrder = TraitImplItemOrder::Alphabetical, /// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by /// reference. #[default_text = "target_pointer_width"] diff --git a/clippy_config/src/types.rs b/clippy_config/src/types.rs index 8d9326a904b1e..a6f7bd69226b5 100644 --- a/clippy_config/src/types.rs +++ b/clippy_config/src/types.rs @@ -706,3 +706,12 @@ pub enum InherentImplLintScope { File, Module, } + +/// Represents the ordering requirement for associated items in trait impls. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum TraitImplItemOrder { + Alphabetical, + TraitItemOrdering, + AlphabeticalOrTraitItemOrdering, +} diff --git a/clippy_lints/src/arbitrary_source_item_ordering.rs b/clippy_lints/src/arbitrary_source_item_ordering.rs index 6afc1f9ef0928..90c4134c3ca22 100644 --- a/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -2,7 +2,7 @@ use clippy_config::Conf; use clippy_config::types::{ SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind, SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds, - SourceItemOrderingWithinModuleItemGroupings, + SourceItemOrderingWithinModuleItemGroupings, TraitImplItemOrder, }; use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::is_cfg_test; @@ -14,7 +14,7 @@ use rustc_hir::{ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty::AssocKind; use rustc_session::impl_lint_pass; -use rustc_span::Ident; +use rustc_span::{Ident, Symbol}; declare_clippy_lint! { /// ### What it does @@ -177,6 +177,7 @@ pub struct ArbitrarySourceItemOrdering { enable_ordering_for_trait: bool, module_item_order_groupings: SourceItemOrderingModuleItemGroupings, module_items_ordered_within_groupings: SourceItemOrderingWithinModuleItemGroupings, + trait_impl_item_order: TraitImplItemOrder, } impl ArbitrarySourceItemOrdering { @@ -192,6 +193,7 @@ impl ArbitrarySourceItemOrdering { enable_ordering_for_trait: conf.source_item_ordering.contains(&Trait), module_item_order_groupings: conf.module_item_order_groupings.clone(), module_items_ordered_within_groupings: conf.module_items_ordered_within_groupings.clone(), + trait_impl_item_order: conf.trait_impl_item_order, } } @@ -210,6 +212,18 @@ impl ArbitrarySourceItemOrdering { ); } + /// Produces a linting warning for impl items that don't follow the trait definition order. + fn lint_trait_impl_item(cx: &LateContext<'_>, item: ImplItemId, before_item: ImplItemId) { + span_lint_and_note( + cx, + ARBITRARY_SOURCE_ITEM_ORDERING, + cx.tcx.def_span(item.owner_id), + "incorrect ordering of impl items (should follow the trait definition order)", + Some(cx.tcx.def_span(before_item.owner_id)), + format!("should be placed before `{}`", cx.tcx.item_name(before_item.owner_id)), + ); + } + /// Produces a linting warning for incorrectly ordered item members. fn lint_member_name(cx: &T, ident: Ident, before_ident: Ident) { span_lint_and_note( @@ -260,6 +274,121 @@ impl ArbitrarySourceItemOrdering { format!("should be placed before `{}`", cx.tcx.item_name(before_item.owner_id)), ); } + + /// Checks the ordering of items in an impl block against the configured + /// associated item kind order, alphabetically within each kind. + fn check_impl_alphabetical(&self, cx: &LateContext<'_>, trait_impl: &rustc_hir::Impl<'_>) { + let mut cur_t: Option<(ImplItemId, Ident)> = None; + + for &item in trait_impl.items { + let span = cx.tcx.def_span(item.owner_id); + let ident = cx.tcx.item_ident(item.owner_id); + if span.in_external_macro(cx.sess().source_map()) { + continue; + } + + if let Some((cur_t, cur_ident)) = cur_t { + let cur_t_kind = convert_assoc_item_kind(cx, cur_t.owner_id); + let cur_t_kind_index = self.assoc_types_order.index_of(&cur_t_kind); + let item_kind = convert_assoc_item_kind(cx, item.owner_id); + let item_kind_index = self.assoc_types_order.index_of(&item_kind); + + if cur_t_kind == item_kind && cur_ident.name.as_str() > ident.name.as_str() { + Self::lint_member_name(cx, ident, cur_ident); + } else if cur_t_kind_index > item_kind_index { + self.lint_impl_item(cx, item, cur_t); + } + } + cur_t = Some((item, ident)); + } + } + + /// Checks the ordering of items in a trait impl against the order in + /// which they are declared in the trait definition. + /// + /// Falls back to the alphabetical check for impl blocks without a trait. + fn check_impl_trait_def_order(&self, cx: &LateContext<'_>, trait_impl: &rustc_hir::Impl<'_>) { + let Some(trait_order) = get_trait_item_order(cx, trait_impl) else { + // Bare impl blocks have no trait definition to compare against. + self.check_impl_alphabetical(cx, trait_impl); + return; + }; + + let mut cur_t: Option<(ImplItemId, Ident)> = None; + + for &item in trait_impl.items { + let span = cx.tcx.def_span(item.owner_id); + let ident = cx.tcx.item_ident(item.owner_id); + if span.in_external_macro(cx.sess().source_map()) { + continue; + } + + if let Some((cur_t, cur_ident)) = cur_t { + // Compare positions in the trait definition. + let cur_pos = trait_order.iter().position(|n| *n == cur_ident.name); + let item_pos = trait_order.iter().position(|n| *n == ident.name); + if let (Some(cur_pos), Some(item_pos)) = (cur_pos, item_pos) + && cur_pos > item_pos + { + Self::lint_trait_impl_item(cx, item, cur_t); + } + } + cur_t = Some((item, ident)); + } + } + + /// Checks impl items, accepting either the alphabetical + kind ordering + /// or the trait definition order. Lints only when both are violated. + /// + /// Fallbacks to the alphabetical check for impl blocks without a trait. + fn check_impl_alphabetical_or_trait_def_order(&self, cx: &LateContext<'_>, trait_impl: &rustc_hir::Impl<'_>) { + let Some(trait_order) = get_trait_item_order(cx, trait_impl) else { + // Bare impl blocks have no trait definition to compare against, + // so only the alphabetical ordering applies. + self.check_impl_alphabetical(cx, trait_impl); + return; + }; + + let mut cur_t: Option<(ImplItemId, Ident)> = None; + + for &item in trait_impl.items { + let span = cx.tcx.def_span(item.owner_id); + let ident = cx.tcx.item_ident(item.owner_id); + if span.in_external_macro(cx.sess().source_map()) { + continue; + } + + if let Some((cur_t, cur_ident)) = cur_t { + let cur_t_kind = convert_assoc_item_kind(cx, cur_t.owner_id); + let cur_t_kind_index = self.assoc_types_order.index_of(&cur_t_kind); + let item_kind = convert_assoc_item_kind(cx, item.owner_id); + let item_kind_index = self.assoc_types_order.index_of(&item_kind); + + // Same check as in `check_impl_alphabetical` + let alpha_violation = if cur_t_kind == item_kind { + cur_ident.name.as_str() > ident.name.as_str() + } else { + cur_t_kind_index > item_kind_index + }; + + // Same check as in `check_impl_trait_def_order` + let trait_violation = matches!( + ( + trait_order.iter().position(|n| *n == cur_ident.name), + trait_order.iter().position(|n| *n == ident.name), + ), + (Some(cur_pos), Some(item_pos)) if cur_pos > item_pos + ); + + // Accepting either ordering means linting only when the pair + // satisfies neither of them. + if alpha_violation && trait_violation { + Self::lint_trait_impl_item(cx, item, cur_t); + } + } + cur_t = Some((item, ident)); + } + } } impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering { @@ -340,30 +469,17 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering { cur_t = Some((item, ident)); } }, - ItemKind::Impl(trait_impl) if self.enable_ordering_for_impl => { - let mut cur_t: Option<(ImplItemId, Ident)> = None; - - for &item in trait_impl.items { - let span = cx.tcx.def_span(item.owner_id); - let ident = cx.tcx.item_ident(item.owner_id); - if span.in_external_macro(cx.sess().source_map()) { - continue; - } - - if let Some((cur_t, cur_ident)) = cur_t { - let cur_t_kind = convert_assoc_item_kind(cx, cur_t.owner_id); - let cur_t_kind_index = self.assoc_types_order.index_of(&cur_t_kind); - let item_kind = convert_assoc_item_kind(cx, item.owner_id); - let item_kind_index = self.assoc_types_order.index_of(&item_kind); - - if cur_t_kind == item_kind && cur_ident.name.as_str() > ident.name.as_str() { - Self::lint_member_name(cx, ident, cur_ident); - } else if cur_t_kind_index > item_kind_index { - self.lint_impl_item(cx, item, cur_t); - } - } - cur_t = Some((item, ident)); - } + ItemKind::Impl(trait_impl) if self.enable_ordering_for_impl => match self.trait_impl_item_order { + // Match trait impl item orderings based on the configured ordering. + TraitImplItemOrder::Alphabetical => { + self.check_impl_alphabetical(cx, trait_impl); + }, + TraitImplItemOrder::TraitItemOrdering => { + self.check_impl_trait_def_order(cx, trait_impl); + }, + TraitImplItemOrder::AlphabeticalOrTraitItemOrdering => { + self.check_impl_alphabetical_or_trait_def_order(cx, trait_impl); + }, }, _ => {}, // Catch-all for `ItemKinds` that don't have fields. } @@ -566,3 +682,18 @@ fn get_item_name(item: &Item<'_>) -> Option { _ => item.kind.ident().map(|name| name.as_str().to_owned()), } } + +/// Returns the associated item names of the implemented trait in +/// definition order, or `None` if the impl block has no trait. +fn get_trait_item_order(cx: &LateContext<'_>, trait_impl: &rustc_hir::Impl<'_>) -> Option> { + trait_impl + .of_trait + .and_then(|t| t.trait_ref.trait_def_id()) + .map(|def_id| { + cx.tcx + .associated_items(def_id) + .in_definition_order() + .map(rustc_middle::ty::AssocItem::name) + .collect() + }) +} diff --git a/clippy_test_deps/Cargo.lock b/clippy_test_deps/Cargo.lock index 33ee75ad49450..4708b523557b8 100644 --- a/clippy_test_deps/Cargo.lock +++ b/clippy_test_deps/Cargo.lock @@ -194,9 +194,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.12.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc" dependencies = [ "either", ] diff --git a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order.rs b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order.rs new file mode 100644 index 0000000000000..14fe6beecd47c --- /dev/null +++ b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order.rs @@ -0,0 +1,46 @@ +//@rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order +//@check-pass +#![deny(clippy::arbitrary_source_item_ordering)] + +struct Languages; +struct Language; +struct Iter<'a, T>(&'a [&'a T]); + +impl<'a> Iterator for Iter<'a, Language> { + type Item = &'a Language; + fn next(&mut self) -> Option { + todo!() + } +} + +// Follows the trait definition order (but not alphabetical order): +// accepted, because either ordering is allowed in this mode. +impl<'a> IntoIterator for &'a Languages { + type Item = &'a Language; + type IntoIter = Iter<'a, Language>; + fn into_iter(self) -> Self::IntoIter { + todo!() + } +} + +struct AlsoLanguages; + +// Follows the alphabetical order (but not the trait definition order): +// also accepted in this mode. +impl<'a> IntoIterator for &'a AlsoLanguages { + type IntoIter = Iter<'a, Language>; + type Item = &'a Language; + fn into_iter(self) -> Self::IntoIter { + todo!() + } +} + +// Bare impls only have the alphabetical ordering to compare against. +struct BareImpl; +impl BareImpl { + fn a() {} + fn b() {} + fn c() {} +} + +fn main() {} diff --git a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs new file mode 100644 index 0000000000000..bad8757d19710 --- /dev/null +++ b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs @@ -0,0 +1,33 @@ +//@rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order +#![deny(clippy::arbitrary_source_item_ordering)] + +// Trait definition order: b, a, c. Deliberately unordered to make the +// trait definition order differ from the alphabetical order; its own +// ordering check is not what this test is about. +#[allow(clippy::arbitrary_source_item_ordering)] +trait MixedOrder { + fn b(); + fn a(); + fn c(); +} + +struct WrongInBothOrders; + +// `c, a, b`: the pair (c, a) violates the alphabetical order, and in the +// trait definition `c` comes after `a`, so it violates both orderings. +impl MixedOrder for WrongInBothOrders { + fn c() {} + fn a() {} + //~^ arbitrary_source_item_ordering + fn b() {} +} + +// Bare impls fall back to the alphabetical check. +struct BareImpl; +impl BareImpl { + fn b() {} + fn a() {} + //~^ arbitrary_source_item_ordering +} + +fn main() {} diff --git a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.stderr b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.stderr new file mode 100644 index 0000000000000..4035d1592f70e --- /dev/null +++ b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.stderr @@ -0,0 +1,31 @@ +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:20:5 + | +LL | fn a() {} + | ^^^^^^ + | +note: should be placed before `c` + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:19:5 + | +LL | fn c() {} + | ^^^^^^ +note: the lint level is defined here + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:2:9 + | +LL | #![deny(clippy::arbitrary_source_item_ordering)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: incorrect ordering of items (must be alphabetically ordered) + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:29:8 + | +LL | fn a() {} + | ^ + | +note: should be placed before `b` + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:28:8 + | +LL | fn b() {} + | ^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/clippy.toml b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/clippy.toml new file mode 100644 index 0000000000000..81ec9245db21b --- /dev/null +++ b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/clippy.toml @@ -0,0 +1 @@ +trait-impl-item-order = "alphabetical_or_trait_item_ordering" diff --git a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/clippy.toml b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/clippy.toml new file mode 100644 index 0000000000000..33da8613cfa00 --- /dev/null +++ b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/clippy.toml @@ -0,0 +1 @@ +trait-impl-item-order = "trait_item_ordering" diff --git a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order.rs b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order.rs new file mode 100644 index 0000000000000..59c1666986093 --- /dev/null +++ b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order.rs @@ -0,0 +1,24 @@ +//@rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order +//@check-pass +#![deny(clippy::arbitrary_source_item_ordering)] + +struct Languages; +struct Language; +struct Iter<'a, T>(&'a [&'a T]); + +impl<'a> Iterator for Iter<'a, Language> { + type Item = &'a Language; + fn next(&mut self) -> Option { + todo!() + } +} + +impl<'a> IntoIterator for &'a Languages { + type Item = &'a Language; + type IntoIter = Iter<'a, Language>; + fn into_iter(self) -> Self::IntoIter { + todo!() + } +} + +fn main() {} diff --git a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs new file mode 100644 index 0000000000000..a16c9f676b404 --- /dev/null +++ b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs @@ -0,0 +1,53 @@ +//@revisions: trait_def +//@rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order +#![deny(clippy::arbitrary_source_item_ordering)] + +// A trait whose definition order happens to be alphabetical. +trait AlphaOrder { + fn a(); + fn b(); + fn c(); +} + +struct WrongInBothOrders; + +// `a, c, b` violates both the alphabetical order and the trait +// definition order, so it is linted in every mode. +impl AlphaOrder for WrongInBothOrders { + fn a() {} + fn c() {} + fn b() {} + //~^ arbitrary_source_item_ordering +} + +// Bare impls have no trait definition to compare against, so the +// trait_item_ordering mode falls back to the alphabetical check. +struct BareImpl; +impl BareImpl { + fn a() {} + fn c() {} + fn b() {} + //~^ arbitrary_source_item_ordering +} + +struct Languages; +struct Language; +struct Iter<'a, T>(&'a [&'a T]); + +impl<'a> Iterator for Iter<'a, Language> { + type Item = &'a Language; + fn next(&mut self) -> Option { + todo!() + } +} + +impl<'a> IntoIterator for &'a Languages { + fn into_iter(self) -> Self::IntoIter { + todo!() + } + type Item = &'a Language; + //~^ arbitrary_source_item_ordering + type IntoIter = Iter<'a, Language>; +} + +fn main() {} diff --git a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.trait_def.stderr b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.trait_def.stderr new file mode 100644 index 0000000000000..210f35ca7e01b --- /dev/null +++ b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.trait_def.stderr @@ -0,0 +1,43 @@ +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:19:5 + | +LL | fn b() {} + | ^^^^^^ + | +note: should be placed before `c` + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:18:5 + | +LL | fn c() {} + | ^^^^^^ +note: the lint level is defined here + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:3:9 + | +LL | #![deny(clippy::arbitrary_source_item_ordering)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: incorrect ordering of items (must be alphabetically ordered) + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:29:8 + | +LL | fn b() {} + | ^ + | +note: should be placed before `c` + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:28:8 + | +LL | fn c() {} + | ^ + +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:48:5 + | +LL | type Item = &'a Language; + | ^^^^^^^^^ + | +note: should be placed before `into_iter` + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:45:5 + | +LL | fn into_iter(self) -> Self::IntoIter { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index 528e2f1089c04..537b80dbace21 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -86,6 +86,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect too-many-arguments-threshold too-many-lines-threshold trait-assoc-item-kinds-order + trait-impl-item-order trivial-copy-size-limit type-complexity-threshold unnecessary-box-size @@ -188,6 +189,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect too-many-arguments-threshold too-many-lines-threshold trait-assoc-item-kinds-order + trait-impl-item-order trivial-copy-size-limit type-complexity-threshold unnecessary-box-size @@ -290,6 +292,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni too-many-arguments-threshold too-many-lines-threshold trait-assoc-item-kinds-order + trait-impl-item-order trivial-copy-size-limit type-complexity-threshold unnecessary-box-size From 04dafefcd5f9e3cc7b73ec3c6fdb38de71b2fbe8 Mon Sep 17 00:00:00 2001 From: wasd243 Date: Sun, 5 Jul 2026 11:12:45 -0400 Subject: [PATCH 09/63] test(arbitrary_source_item_ordering): add comprehensive tests for `trait_item_ordering` and `alphabetical_or_trait_item_ordering --- .../alphabetical_or_trait_item_order.rs | 66 +++++++++++++++++ ...alphabetical_or_trait_item_order_failed.rs | 73 +++++++++++++++++++ ...abetical_or_trait_item_order_failed.stderr | 66 ++++++++++++++++- .../trait_definition_order.rs | 70 ++++++++++++++++++ .../trait_definition_order_failed.rs | 52 +++++++++++++ ...t_definition_order_failed.trait_def.stderr | 46 ++++++++++-- 6 files changed, 365 insertions(+), 8 deletions(-) diff --git a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order.rs b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order.rs index 14fe6beecd47c..03e0fbfa31d20 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order.rs @@ -43,4 +43,70 @@ impl BareImpl { fn c() {} } +// Default trait impl ordering. +trait WithDefault { + fn a() {} + fn b() {} + fn c() {} +} + +trait WithDefault2 { + fn a(); + fn b(); + fn c(); +} + +struct SkipMiddle; + +impl WithDefault for SkipMiddle { + fn a() {} + fn c() {} +} + +struct FullImpl; + +impl WithDefault for FullImpl { + fn a() {} + fn b() {} + fn c() {} +} + +impl WithDefault2 for FullImpl { + fn a() {} + fn b() {} + fn c() {} +} + +// Tests `const` in trait. +trait ConstTrait { + const A: bool; + const B: bool; + const C: bool; + fn method(); +} + +struct FullImpl3; + +impl ConstTrait for FullImpl3 { + const A: bool = true; + const B: bool = false; + const C: bool = true; + fn method() {} +} + +trait ConstTrait2 { + const A: bool = true; + const B: bool = false; + const C: bool = true; + fn method() {} +} + +struct SkipImpl; + +// Skips `B` `C`, keeps order of `A` and `C`. +impl ConstTrait2 for SkipImpl { + const A: bool = true; + fn method() {} +} + fn main() {} diff --git a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs index bad8757d19710..ff96d0669e119 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs @@ -22,12 +22,85 @@ impl MixedOrder for WrongInBothOrders { fn b() {} } +trait WithDefault { + fn a() {} + fn b() {} + fn c() {} +} + +struct SkipMiddleFailed; + +impl WithDefault for SkipMiddleFailed { + fn c() {} + fn a() {} + //~^ arbitrary_source_item_ordering +} + +struct FullImplFailed; + +impl WithDefault for FullImplFailed { + fn c() {} + fn a() {} + //~^ arbitrary_source_item_ordering + fn b() {} +} + +trait WithDefault2 { + fn a(); + fn b(); + fn c(); +} + +struct FullImplFailed2; + +impl WithDefault2 for FullImplFailed2 { + fn b() {} + fn a() {} + //~^ arbitrary_source_item_ordering + fn c() {} +} + // Bare impls fall back to the alphabetical check. struct BareImpl; + impl BareImpl { fn b() {} fn a() {} //~^ arbitrary_source_item_ordering } +// Tests `const` in trait failed by invalid alphabetical order. +trait ConstTrait { + const A: bool; + const B: bool; + const C: bool; + fn method(); +} + +struct FullImplFailed3; + +impl ConstTrait for FullImplFailed3 { + const A: bool = true; + const C: bool = true; + const B: bool = false; + //~^ arbitrary_source_item_ordering + fn method() {} +} + +trait ConstTrait2 { + const A: bool = true; + const B: bool = false; + const C: bool = true; + fn method() {} +} + +struct SkipMiddleFailed2; + +impl ConstTrait2 for SkipMiddleFailed2 { + const C: bool = true; + const A: bool = true; + //~^ arbitrary_source_item_ordering + fn method() {} +} + fn main() {} diff --git a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.stderr b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.stderr index 4035d1592f70e..b0b8c9e483889 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.stderr +++ b/tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.stderr @@ -15,17 +15,77 @@ note: the lint level is defined here LL | #![deny(clippy::arbitrary_source_item_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:35:5 + | +LL | fn a() {} + | ^^^^^^ + | +note: should be placed before `c` + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:34:5 + | +LL | fn c() {} + | ^^^^^^ + +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:43:5 + | +LL | fn a() {} + | ^^^^^^ + | +note: should be placed before `c` + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:42:5 + | +LL | fn c() {} + | ^^^^^^ + +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:58:5 + | +LL | fn a() {} + | ^^^^^^ + | +note: should be placed before `b` + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:57:5 + | +LL | fn b() {} + | ^^^^^^ + error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:29:8 + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:68:8 | LL | fn a() {} | ^ | note: should be placed before `b` - --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:28:8 + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:67:8 | LL | fn b() {} | ^ -error: aborting due to 2 previous errors +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:85:5 + | +LL | const B: bool = false; + | ^^^^^^^^^^^^^ + | +note: should be placed before `C` + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:84:5 + | +LL | const C: bool = true; + | ^^^^^^^^^^^^^ + +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:101:5 + | +LL | const A: bool = true; + | ^^^^^^^^^^^^^ + | +note: should be placed before `C` + --> tests/ui-toml/arbitrary_source_item_ordering/alphabetical_or_trait_item_order/alphabetical_or_trait_item_order_failed.rs:100:5 + | +LL | const C: bool = true; + | ^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors diff --git a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order.rs b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order.rs index 59c1666986093..31554937e9dd7 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order.rs @@ -21,4 +21,74 @@ impl<'a> IntoIterator for &'a Languages { } } +// Default trait impl ordering. +trait WithDefault { + fn a() {} + fn b() {} + fn c() {} +} + +struct SkipMiddle; + +impl WithDefault for SkipMiddle { + fn a() {} + fn c() {} +} + +struct FullImpl; + +impl WithDefault for FullImpl { + fn a() {} + fn b() {} + fn c() {} +} + +trait WithDefault2 { + fn a(); + fn b(); + fn c(); +} + +struct FullImpl2; + +impl WithDefault2 for FullImpl2 { + fn a() {} + fn b() {} + fn c() {} +} + +// Tests `const` in trait. +trait ConstTrait { + const A: bool; + const B: bool; + const C: bool; + fn method(); +} + +struct FullImpl3; + +// Tests `const` in trait without value. +impl ConstTrait for FullImpl3 { + const A: bool = true; + const B: bool = false; + const C: bool = true; + fn method() {} +} + +trait ConstTrait2 { + const A: bool = true; + const B: bool = false; + const C: bool = true; + fn method() {} +} + +struct SkipImpl; + +// Tests skipped `const` in trait. +impl ConstTrait2 for SkipImpl { + const A: bool = true; + const C: bool = true; + fn method() {} +} + fn main() {} diff --git a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs index a16c9f676b404..510df33de322f 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs @@ -20,6 +20,21 @@ impl AlphaOrder for WrongInBothOrders { //~^ arbitrary_source_item_ordering } +trait AlphaOrder2 { + fn a() {} + fn b() {} + fn c() {} +} + +struct WrongInBothOrder2; + +impl AlphaOrder2 for WrongInBothOrder2 { + fn a() {} + fn c() {} + fn b() {} + //~^ arbitrary_source_item_ordering +} + // Bare impls have no trait definition to compare against, so the // trait_item_ordering mode falls back to the alphabetical check. struct BareImpl; @@ -50,4 +65,41 @@ impl<'a> IntoIterator for &'a Languages { type IntoIter = Iter<'a, Language>; } +// Tests `const` in trait when failed by invalid trait definition order (e.g. Not in alphabetical +// order). +trait ConstTrait { + const A: bool; + const B: bool; + const C: bool; + fn method(); +} + +struct WrongInBothOrder3; + +impl ConstTrait for WrongInBothOrder3 { + const A: bool = true; + const C: bool = true; + const B: bool = false; + //~^ arbitrary_source_item_ordering + fn method() {} +} + +// Tests skipped trait which has `const` in trait failed by invalid trait definition order (e.g. Not +// in alphabetical order). +trait SkipConstTrait { + const A: bool = true; + const B: bool = false; + const C: bool = true; + fn method() {} +} + +struct WrongInBothOrder4; + +impl SkipConstTrait for WrongInBothOrder4 { + const C: bool = true; + const A: bool = true; + //~^ arbitrary_source_item_ordering + fn method() {} +} + fn main() {} diff --git a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.trait_def.stderr b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.trait_def.stderr index 210f35ca7e01b..c70c3c9e7978f 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.trait_def.stderr +++ b/tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.trait_def.stderr @@ -15,29 +15,65 @@ note: the lint level is defined here LL | #![deny(clippy::arbitrary_source_item_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:34:5 + | +LL | fn b() {} + | ^^^^^^ + | +note: should be placed before `c` + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:33:5 + | +LL | fn c() {} + | ^^^^^^ + error: incorrect ordering of items (must be alphabetically ordered) - --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:29:8 + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:44:8 | LL | fn b() {} | ^ | note: should be placed before `c` - --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:28:8 + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:43:8 | LL | fn c() {} | ^ error: incorrect ordering of impl items (should follow the trait definition order) - --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:48:5 + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:63:5 | LL | type Item = &'a Language; | ^^^^^^^^^ | note: should be placed before `into_iter` - --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:45:5 + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:60:5 | LL | fn into_iter(self) -> Self::IntoIter { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:82:5 + | +LL | const B: bool = false; + | ^^^^^^^^^^^^^ + | +note: should be placed before `C` + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:81:5 + | +LL | const C: bool = true; + | ^^^^^^^^^^^^^ + +error: incorrect ordering of impl items (should follow the trait definition order) + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:100:5 + | +LL | const A: bool = true; + | ^^^^^^^^^^^^^ + | +note: should be placed before `C` + --> tests/ui-toml/arbitrary_source_item_ordering/trait_definition_order/trait_definition_order_failed.rs:99:5 + | +LL | const C: bool = true; + | ^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors From 6be69ecfe4426ffced5dc96ca4e8bc2aa2c00002 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Wed, 1 Jul 2026 10:13:45 -0700 Subject: [PATCH 10/63] Oh yeah, clippy too --- clippy_utils/src/ty/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index ae348651c0d62..cec4a028179b5 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -525,7 +525,7 @@ fn is_uninit_value_valid_for_layout<'tcx>(cx: &LateContext<'tcx>, layout: TyAndL match layout.layout.backend_repr { BackendRepr::Scalar(s) => s.is_uninit_valid(), - BackendRepr::ScalarPair(a, b) => a.is_uninit_valid() && b.is_uninit_valid(), + BackendRepr::ScalarPair { a, b, b_offset: _ } => a.is_uninit_valid() && b.is_uninit_valid(), BackendRepr::SimdVector { element, count } => count == 0 || element.is_uninit_valid(), BackendRepr::SimdScalableVector { element, .. } => element.is_uninit_valid(), // Here validity is determined by the structural fields instead. From f6876f2b9682a3635a403a9d1049ddd94a24eb3e Mon Sep 17 00:00:00 2001 From: John Costa Date: Tue, 7 Jul 2026 12:31:35 -0700 Subject: [PATCH 11/63] manual_filter: don't eat comments in the `and_then` suggestion The `opt.and_then(|x| { /* comment */ if .. { Some(x) } else { None } })` to `filter` rewrite drops any comment inside the closure. Mark the suggestion `MaybeIncorrect` when the replaced span contains a comment, so `clippy --fix` no longer applies it silently. This matches the existing `span_contains_comment` handling in manual_ok_err / manual_unwrap_or / manual_flatten. --- clippy_lints/src/matches/manual_filter.rs | 10 ++++++++-- tests/ui/manual_filter_unfixable.rs | 15 +++++++++++++++ tests/ui/manual_filter_unfixable.stderr | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/ui/manual_filter_unfixable.rs create mode 100644 tests/ui/manual_filter_unfixable.stderr diff --git a/clippy_lints/src/matches/manual_filter.rs b/clippy_lints/src/matches/manual_filter.rs index 9c2d60eb9c575..942a08bf07c44 100644 --- a/clippy_lints/src/matches/manual_filter.rs +++ b/clippy_lints/src/matches/manual_filter.rs @@ -1,10 +1,10 @@ -use clippy_utils::as_some_expr; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; use clippy_utils::source::snippet_with_context; use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_copy; use clippy_utils::visitors::contains_unsafe_block; +use clippy_utils::{as_some_expr, span_contains_comment}; use rustc_errors::Applicability; use rustc_hir::LangItem::OptionNone; use rustc_hir::{Arm, Expr, ExprKind, HirId, Pat, PatKind}; @@ -118,7 +118,13 @@ pub(crate) fn check_and_then_method<'tcx>( call_span, "manual implementation of `Option::filter`", |diag| { - let mut applicability = Applicability::MachineApplicable; + // A comment inside the replaced `and_then` closure (for example, one explaining the + // predicate) would be dropped by the rewrite, so don't auto-apply the fix then (#17376). + let mut applicability = if span_contains_comment(cx, call_span) { + Applicability::MaybeIncorrect + } else { + Applicability::MachineApplicable + }; let mut cond_snip = Sugg::hir_with_context(cx, some_expr.expr, expr_span_ctxt, "..", &mut applicability); diff --git a/tests/ui/manual_filter_unfixable.rs b/tests/ui/manual_filter_unfixable.rs new file mode 100644 index 0000000000000..0212e2fbd4504 --- /dev/null +++ b/tests/ui/manual_filter_unfixable.rs @@ -0,0 +1,15 @@ +//@no-rustfix: the suggestion drops the closure's comment, so it is not machine-applicable + +#![warn(clippy::manual_filter)] + +fn issue17376(opt: Option) { + // Rewriting to `filter` would drop the comment below, so the suggestion must not be + // machine-applicable here. Otherwise `clippy --fix` would silently eat the comment (#17376). + opt.and_then(|x| { + //~^ manual_filter + // keep this explanation + if x < 10 { Some(x) } else { None } + }); +} + +fn main() {} diff --git a/tests/ui/manual_filter_unfixable.stderr b/tests/ui/manual_filter_unfixable.stderr new file mode 100644 index 0000000000000..00b267e97ac48 --- /dev/null +++ b/tests/ui/manual_filter_unfixable.stderr @@ -0,0 +1,16 @@ +error: manual implementation of `Option::filter` + --> tests/ui/manual_filter_unfixable.rs:8:9 + | +LL | opt.and_then(|x| { + | _________^ +LL | | +LL | | // keep this explanation +LL | | if x < 10 { Some(x) } else { None } +LL | | }); + | |______^ help: try: `filter(|&x| x < 10)` + | + = note: `-D clippy::manual-filter` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_filter)]` + +error: aborting due to 1 previous error + From 62c9f92cfaefbfa6a9c1dc19fa0046b84f840d57 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khyperia@users.noreply.github.com> Date: Wed, 8 Jul 2026 07:46:21 +0200 Subject: [PATCH 12/63] allow mGCA const arguments to fall back to anon consts --- clippy_utils/src/check_proc_macro.rs | 1 + clippy_utils/src/sugg.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 7400891f75b58..7b47141c9fb8a 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -537,6 +537,7 @@ fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) { | TyKind::Pat(..) | TyKind::FieldOf(..) | TyKind::View(..) + | TyKind::DirectConstArg(..) // unused | TyKind::CVarArgs diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index f194103ae2e88..cb0db1ed014fc 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -248,6 +248,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Array(..) | ast::ExprKind::While(..) | ast::ExprKind::Await(..) + | ast::ExprKind::DirectConstArg(..) | ast::ExprKind::Err(_) | ast::ExprKind::Dummy | ast::ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(snippet(expr.span)), From 5911c52e9bcc6d106ada0623d1b5f897283be604 Mon Sep 17 00:00:00 2001 From: Connor Shea <2977353+connorshea@users.noreply.github.com> Date: Wed, 8 Jul 2026 20:59:31 -0600 Subject: [PATCH 13/63] perf: Bail out of the disallowed_methods rule if the disallowed list is empty. This matches the same check from disallowed_macros and skips unnecessary work when the rule has been enabled but not configured. --- clippy_lints/src/disallowed_methods.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clippy_lints/src/disallowed_methods.rs b/clippy_lints/src/disallowed_methods.rs index e2fd71b7d990f..71c9c0c58ceb5 100644 --- a/clippy_lints/src/disallowed_methods.rs +++ b/clippy_lints/src/disallowed_methods.rs @@ -88,6 +88,9 @@ impl DisallowedMethods { impl<'tcx> LateLintPass<'tcx> for DisallowedMethods { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { + if self.disallowed.is_empty() { + return; + } if expr.span.desugaring_kind().is_some() { return; } From a12bfc626e9da95463b3fde419e4e9ee27710a1d Mon Sep 17 00:00:00 2001 From: Sasha Pourcelot Date: Sun, 3 May 2026 13:58:31 +0000 Subject: [PATCH 14/63] view-types: lower view types to HIR --- clippy_lints/src/dereference.rs | 4 ++++ clippy_utils/src/hir_utils.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index fbff41fe00914..0868ee322a646 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -902,6 +902,10 @@ impl TyCoercionStability { | TyKind::TraitObject(..) | TyKind::InferDelegation(..) | TyKind::Err(_) => Self::Reborrow, + TyKind::View(ty, _) => { + // FIXME(scrabsha): what are the semantics of view types here? + Self::for_hir_ty(ty) + } TyKind::UnsafeBinder(..) => Self::None, }; } diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 050e43344d0c4..7c3fa51228bc9 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -1650,6 +1650,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::UnsafeBinder(binder) => { self.hash_ty(binder.inner_ty); }, + TyKind::View(ty, _) => { + self.hash_ty(ty); + // FIXME(scrabsha): probably hash the fields as well? + }, TyKind::Err(_) | TyKind::Infer(()) | TyKind::Never From 355b42ae28cd7a19d99264bc1f12da75d15da528 Mon Sep 17 00:00:00 2001 From: Aluminium Date: Thu, 9 Jul 2026 16:15:09 +0300 Subject: [PATCH 15/63] Fix needless_collect suggests a suggestion that cannot be typed --- clippy_lints/src/methods/needless_collect.rs | 39 ++++++++++++++++++++ tests/ui/needless_collect.fixed | 24 ++++++++++++ tests/ui/needless_collect.rs | 24 ++++++++++++ 3 files changed, 87 insertions(+) diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index 62a192b7f770f..b132d60007cf0 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -35,6 +35,10 @@ pub(super) fn check<'tcx>( return; // don't lint if the iterator has side effects } + if collect_turbofish_is_fully_concrete(collect_expr) { + return; // don't lint if turbofish on collect maybe the only thing anchoring the type + } + match cx.tcx.parent_hir_node(collect_expr.hir_id) { Node::Expr(parent) => { check_collect_into_intoiterator(cx, parent, collect_expr, call_span, iter_expr); @@ -230,6 +234,41 @@ fn check_collect_into_intoiterator<'tcx>( } } +/// Returns `true` if `collect_expr`'s turbofish is fully concrete (has +/// generic arguments and none of them are inference placeholders) +fn collect_turbofish_is_fully_concrete(collect_expr: &Expr<'_>) -> bool { + if let ExprKind::MethodCall(segment, ..) = collect_expr.kind + && let Some(args) = segment.args + && !args.args.is_empty() + { + args.args.iter().all(generic_arg_is_fully_concrete) + } else { + false + } +} + +fn generic_arg_is_fully_concrete(arg: &rustc_hir::GenericArg<'_>) -> bool { + match arg { + rustc_hir::GenericArg::Infer(_) => false, + rustc_hir::GenericArg::Type(ty) => ty_is_fully_concrete(ty.as_unambig_ty()), + rustc_hir::GenericArg::Const(ct) => !matches!(ct.as_unambig_ct().kind, rustc_hir::ConstArgKind::Infer(..)), + rustc_hir::GenericArg::Lifetime(_) => true, + } +} + +fn ty_is_fully_concrete(ty: &rustc_hir::Ty<'_>) -> bool { + match &ty.kind { + rustc_hir::TyKind::Infer(..) => false, + rustc_hir::TyKind::Path(rustc_hir::QPath::Resolved(_, path)) => path.segments.iter().all(|seg| { + seg.args + .is_none_or(|a| a.args.iter().all(generic_arg_is_fully_concrete)) + }), + rustc_hir::TyKind::Ref(_, mut_ty) => ty_is_fully_concrete(mut_ty.ty), + rustc_hir::TyKind::Slice(ty) | rustc_hir::TyKind::Array(ty, _) => ty_is_fully_concrete(ty), + rustc_hir::TyKind::Tup(tys) => tys.iter().all(ty_is_fully_concrete), + _ => true, + } +} /// Checks if the given method call matches the expected signature of `([&[mut]] self) -> bool` fn is_is_empty_sig(cx: &LateContext<'_>, call_id: HirId) -> bool { cx.typeck_results().type_dependent_def_id(call_id).is_some_and(|id| { diff --git a/tests/ui/needless_collect.fixed b/tests/ui/needless_collect.fixed index ca25395e375bc..00cd5514aa4b6 100644 --- a/tests/ui/needless_collect.fixed +++ b/tests/ui/needless_collect.fixed @@ -291,3 +291,27 @@ mod collect_push_then_iter { [5].into_iter().chain([1, 3].into_iter().chain(iter).chain([2]).chain(iter2)).chain([4, 6]).map(|x| x + 1).collect() } } + +fn issue_17315() { + struct Foo { + inner: T, + marker: core::marker::PhantomData, + } + + impl Iterator for Foo { + type Item = T::Item; + fn next(&mut self) -> Option { + self.inner.next() + } + } + + // not trigger needless_collect. + fn foo() { + Foo { + inner: [].iter(), + marker: core::marker::PhantomData, + } + .collect::>() + .len(); + } +} diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs index 4fafa2e9adf6b..9c276455eaadb 100644 --- a/tests/ui/needless_collect.rs +++ b/tests/ui/needless_collect.rs @@ -291,3 +291,27 @@ mod collect_push_then_iter { v.into_iter().map(|x| x + 1).collect() } } + +fn issue_17315() { + struct Foo { + inner: T, + marker: core::marker::PhantomData, + } + + impl Iterator for Foo { + type Item = T::Item; + fn next(&mut self) -> Option { + self.inner.next() + } + } + + // not trigger needless_collect. + fn foo() { + Foo { + inner: [].iter(), + marker: core::marker::PhantomData, + } + .collect::>() + .len(); + } +} From 0c209c1ef0cb81f67850b12e9df7370e3a7bebd2 Mon Sep 17 00:00:00 2001 From: Aluminium Date: Thu, 9 Jul 2026 17:18:25 +0300 Subject: [PATCH 16/63] Remove expect now that needless_collect is fixed --- tests/ui/needless_collect.fixed | 28 ---------------------------- tests/ui/needless_collect.rs | 28 ---------------------------- tests/ui/needless_collect.stderr | 12 ++++++------ 3 files changed, 6 insertions(+), 62 deletions(-) diff --git a/tests/ui/needless_collect.fixed b/tests/ui/needless_collect.fixed index 00cd5514aa4b6..a7df03ff3ef1e 100644 --- a/tests/ui/needless_collect.fixed +++ b/tests/ui/needless_collect.fixed @@ -198,10 +198,6 @@ mod issue8055_regression { } } - #[expect( - clippy::needless_collect, - reason = "FIXME: proposed fix cannot determine type, see issue #17315" - )] fn foo() { Foo { inner: [].iter(), @@ -291,27 +287,3 @@ mod collect_push_then_iter { [5].into_iter().chain([1, 3].into_iter().chain(iter).chain([2]).chain(iter2)).chain([4, 6]).map(|x| x + 1).collect() } } - -fn issue_17315() { - struct Foo { - inner: T, - marker: core::marker::PhantomData, - } - - impl Iterator for Foo { - type Item = T::Item; - fn next(&mut self) -> Option { - self.inner.next() - } - } - - // not trigger needless_collect. - fn foo() { - Foo { - inner: [].iter(), - marker: core::marker::PhantomData, - } - .collect::>() - .len(); - } -} diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs index 9c276455eaadb..b46c41068b2be 100644 --- a/tests/ui/needless_collect.rs +++ b/tests/ui/needless_collect.rs @@ -198,10 +198,6 @@ mod issue8055_regression { } } - #[expect( - clippy::needless_collect, - reason = "FIXME: proposed fix cannot determine type, see issue #17315" - )] fn foo() { Foo { inner: [].iter(), @@ -291,27 +287,3 @@ mod collect_push_then_iter { v.into_iter().map(|x| x + 1).collect() } } - -fn issue_17315() { - struct Foo { - inner: T, - marker: core::marker::PhantomData, - } - - impl Iterator for Foo { - type Item = T::Item; - fn next(&mut self) -> Option { - self.inner.next() - } - } - - // not trigger needless_collect. - fn foo() { - Foo { - inner: [].iter(), - marker: core::marker::PhantomData, - } - .collect::>() - .len(); - } -} diff --git a/tests/ui/needless_collect.stderr b/tests/ui/needless_collect.stderr index 402a1fd19a7c7..caaaee7705454 100644 --- a/tests/ui/needless_collect.stderr +++ b/tests/ui/needless_collect.stderr @@ -122,7 +122,7 @@ LL | baz((0..10), (), ('a'..='z').collect::>()) | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:224:26 + --> tests/ui/needless_collect.rs:220:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ @@ -139,7 +139,7 @@ LL ~ iter.chain([1]).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:236:26 + --> tests/ui/needless_collect.rs:232:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ @@ -157,7 +157,7 @@ LL ~ iter.chain([1, 2]).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:244:26 + --> tests/ui/needless_collect.rs:240:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ @@ -174,7 +174,7 @@ LL ~ iter.chain([1]).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:264:27 + --> tests/ui/needless_collect.rs:260:27 | LL | let mut ll = iter.collect::>(); | ^^^^^^^ @@ -191,7 +191,7 @@ LL ~ iter.chain(s).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:271:26 + --> tests/ui/needless_collect.rs:267:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ @@ -209,7 +209,7 @@ LL ~ [1, 2].into_iter().chain(iter).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:282:26 + --> tests/ui/needless_collect.rs:278:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ From 9a87d257f85563ed279660ac101419870830c18d Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 21 May 2026 19:06:48 +0200 Subject: [PATCH 17/63] Attributes cleanup in tests [17/20] --- tests/ui/single_char_pattern.fixed | 1 - tests/ui/single_char_pattern.rs | 1 - tests/ui/single_char_pattern.stderr | 70 +++++++++---------- tests/ui/single_component_path_imports.fixed | 3 - tests/ui/single_component_path_imports.rs | 3 - tests/ui/single_component_path_imports.stderr | 4 +- .../ui/single_component_path_imports_macro.rs | 1 - ...gle_component_path_imports_nested_first.rs | 2 - ...component_path_imports_nested_first.stderr | 6 +- ...ingle_component_path_imports_self_after.rs | 1 - ...ngle_component_path_imports_self_before.rs | 1 - tests/ui/single_match.fixed | 9 +-- tests/ui/single_match.rs | 9 +-- tests/ui/single_match.stderr | 62 ++++++++-------- tests/ui/single_match_else.fixed | 2 +- tests/ui/single_match_else.rs | 2 +- .../ui/single_match_else_deref_patterns.fixed | 12 +--- tests/ui/single_match_else_deref_patterns.rs | 12 +--- .../single_match_else_deref_patterns.stderr | 31 ++++---- ...single_range_in_vec_init.new_range.1.fixed | 2 +- ...single_range_in_vec_init.new_range.2.fixed | 2 +- ...single_range_in_vec_init.old_range.1.fixed | 2 +- ...single_range_in_vec_init.old_range.2.fixed | 2 +- tests/ui/single_range_in_vec_init.rs | 2 +- .../size_of_in_element_count/expressions.rs | 1 - .../expressions.stderr | 8 +-- .../ui/size_of_in_element_count/functions.rs | 2 +- tests/ui/size_of_ref.rs | 1 - tests/ui/size_of_ref.stderr | 6 +- tests/ui/skip_while_next.rs | 2 +- tests/ui/sliced_string_as_bytes.fixed | 1 - tests/ui/sliced_string_as_bytes.rs | 1 - tests/ui/sliced_string_as_bytes.stderr | 6 +- tests/ui/slow_vector_initialization.fixed | 4 +- tests/ui/slow_vector_initialization.rs | 4 +- tests/ui/slow_vector_initialization.stderr | 26 +++---- tests/ui/some_filter.fixed | 2 +- tests/ui/some_filter.rs | 2 +- tests/ui/stable_sort_primitive.fixed | 2 +- tests/ui/stable_sort_primitive.rs | 2 +- tests/ui/starts_ends_with.fixed | 2 +- tests/ui/starts_ends_with.rs | 2 +- tests/ui/std_instead_of_core.fixed | 3 +- tests/ui/std_instead_of_core.rs | 3 +- tests/ui/std_instead_of_core.stderr | 8 +-- tests/ui/std_instead_of_core_unfixable.rs | 4 +- tests/ui/std_instead_of_core_unfixable.stderr | 10 +-- tests/ui/string_lit_as_bytes.fixed | 2 +- tests/ui/string_lit_as_bytes.rs | 2 +- tests/ui/string_lit_chars_any.fixed | 2 +- tests/ui/string_lit_chars_any.rs | 2 +- tests/ui/string_slice.rs | 2 +- tests/ui/strlen_on_c_strings.fixed | 2 +- tests/ui/strlen_on_c_strings.rs | 2 +- tests/ui/struct_fields.rs | 1 - tests/ui/struct_fields.stderr | 52 +++++++------- tests/ui/suspicious_arithmetic_impl.rs | 2 +- tests/ui/suspicious_command_arg_space.fixed | 3 +- tests/ui/suspicious_command_arg_space.rs | 3 +- tests/ui/suspicious_command_arg_space.stderr | 4 +- tests/ui/suspicious_doc_comments.fixed | 1 - tests/ui/suspicious_doc_comments.rs | 1 - tests/ui/suspicious_doc_comments.stderr | 18 ++--- tests/ui/suspicious_doc_comments_unfixable.rs | 2 +- tests/ui/suspicious_else_formatting.rs | 8 +-- tests/ui/suspicious_map.rs | 2 +- tests/ui/suspicious_operation_groupings.fixed | 2 +- tests/ui/suspicious_operation_groupings.rs | 2 +- tests/ui/suspicious_splitn.rs | 1 - tests/ui/suspicious_splitn.stderr | 18 ++--- tests/ui/suspicious_to_owned.1.fixed | 5 +- tests/ui/suspicious_to_owned.2.fixed | 5 +- tests/ui/suspicious_to_owned.rs | 5 +- tests/ui/suspicious_to_owned.stderr | 12 ++-- tests/ui/suspicious_unary_op_formatting.rs | 2 +- tests/ui/suspicious_xor_used_as_pow.rs | 3 +- tests/ui/suspicious_xor_used_as_pow.stderr | 14 ++-- tests/ui/swap.fixed | 9 ++- tests/ui/swap.rs | 9 ++- tests/ui/swap.stderr | 39 ++++++----- 80 files changed, 264 insertions(+), 317 deletions(-) diff --git a/tests/ui/single_char_pattern.fixed b/tests/ui/single_char_pattern.fixed index 9bf9d66304411..2b1f403b1f2c9 100644 --- a/tests/ui/single_char_pattern.fixed +++ b/tests/ui/single_char_pattern.fixed @@ -1,4 +1,3 @@ -#![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes, unused_must_use)] #![warn(clippy::single_char_pattern)] use std::collections::HashSet; diff --git a/tests/ui/single_char_pattern.rs b/tests/ui/single_char_pattern.rs index 0560a848fe9de..a933e73edc10e 100644 --- a/tests/ui/single_char_pattern.rs +++ b/tests/ui/single_char_pattern.rs @@ -1,4 +1,3 @@ -#![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes, unused_must_use)] #![warn(clippy::single_char_pattern)] use std::collections::HashSet; diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr index aa4ba28884a8c..bf8bac0b00be5 100644 --- a/tests/ui/single_char_pattern.stderr +++ b/tests/ui/single_char_pattern.stderr @@ -1,5 +1,5 @@ error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:7:13 + --> tests/ui/single_char_pattern.rs:6:13 | LL | x.split("x"); | ^^^ help: consider using a `char`: `'x'` @@ -8,205 +8,205 @@ LL | x.split("x"); = help: to override `-D warnings` add `#[allow(clippy::single_char_pattern)]` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:19:23 + --> tests/ui/single_char_pattern.rs:18:23 | LL | x.split_inclusive("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:21:16 + --> tests/ui/single_char_pattern.rs:20:16 | LL | x.contains("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:23:19 + --> tests/ui/single_char_pattern.rs:22:19 | LL | x.starts_with("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:25:17 + --> tests/ui/single_char_pattern.rs:24:17 | LL | x.ends_with("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:27:12 + --> tests/ui/single_char_pattern.rs:26:12 | LL | x.find("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:29:13 + --> tests/ui/single_char_pattern.rs:28:13 | LL | x.rfind("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:31:14 + --> tests/ui/single_char_pattern.rs:30:14 | LL | x.rsplit("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:33:24 + --> tests/ui/single_char_pattern.rs:32:24 | LL | x.split_terminator("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:35:25 + --> tests/ui/single_char_pattern.rs:34:25 | LL | x.rsplit_terminator("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:37:17 + --> tests/ui/single_char_pattern.rs:36:17 | LL | x.splitn(2, "x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:39:18 + --> tests/ui/single_char_pattern.rs:38:18 | LL | x.rsplitn(2, "x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:41:18 + --> tests/ui/single_char_pattern.rs:40:18 | LL | x.split_once("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:43:19 + --> tests/ui/single_char_pattern.rs:42:19 | LL | x.rsplit_once("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:45:15 + --> tests/ui/single_char_pattern.rs:44:15 | LL | x.matches("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:47:16 + --> tests/ui/single_char_pattern.rs:46:16 | LL | x.rmatches("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:49:21 + --> tests/ui/single_char_pattern.rs:48:21 | LL | x.match_indices("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:51:22 + --> tests/ui/single_char_pattern.rs:50:22 | LL | x.rmatch_indices("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:53:26 + --> tests/ui/single_char_pattern.rs:52:26 | LL | x.trim_start_matches("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:55:24 + --> tests/ui/single_char_pattern.rs:54:24 | LL | x.trim_end_matches("x"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:57:15 + --> tests/ui/single_char_pattern.rs:56:15 | LL | x.replace("x", "y"); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:59:16 + --> tests/ui/single_char_pattern.rs:58:16 | LL | x.replacen("x", "y", 3); | ^^^ help: consider using a `char`: `'x'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:62:13 + --> tests/ui/single_char_pattern.rs:61:13 | LL | x.split("\n"); | ^^^^ help: consider using a `char`: `'\n'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:64:13 + --> tests/ui/single_char_pattern.rs:63:13 | LL | x.split("'"); | ^^^ help: consider using a `char`: `'\''` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:66:13 + --> tests/ui/single_char_pattern.rs:65:13 | LL | x.split("\'"); | ^^^^ help: consider using a `char`: `'\''` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:69:13 + --> tests/ui/single_char_pattern.rs:68:13 | LL | x.split("\""); | ^^^^ help: consider using a `char`: `'"'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:75:31 + --> tests/ui/single_char_pattern.rs:74:31 | LL | x.replace(';', ",").split(","); // issue #2978 | ^^^ help: consider using a `char`: `','` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:78:19 + --> tests/ui/single_char_pattern.rs:77:19 | LL | x.starts_with("\x03"); // issue #2996 | ^^^^^^ help: consider using a `char`: `'\x03'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:87:13 + --> tests/ui/single_char_pattern.rs:86:13 | LL | x.split(r"a"); | ^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:89:13 + --> tests/ui/single_char_pattern.rs:88:13 | LL | x.split(r#"a"#); | ^^^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:91:13 + --> tests/ui/single_char_pattern.rs:90:13 | LL | x.split(r###"a"###); | ^^^^^^^^^^ help: consider using a `char`: `'a'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:93:13 + --> tests/ui/single_char_pattern.rs:92:13 | LL | x.split(r###"'"###); | ^^^^^^^^^^ help: consider using a `char`: `'\''` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:95:13 + --> tests/ui/single_char_pattern.rs:94:13 | LL | x.split(r###"#"###); | ^^^^^^^^^^ help: consider using a `char`: `'#'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:98:13 + --> tests/ui/single_char_pattern.rs:97:13 | LL | x.split(r#"\"#); | ^^^^^^ help: consider using a `char`: `'\\'` error: single-character string constant used as pattern - --> tests/ui/single_char_pattern.rs:100:13 + --> tests/ui/single_char_pattern.rs:99:13 | LL | x.split(r"\"); | ^^^^ help: consider using a `char`: `'\\'` diff --git a/tests/ui/single_component_path_imports.fixed b/tests/ui/single_component_path_imports.fixed index 180a55813b19f..02a3d575e5b91 100644 --- a/tests/ui/single_component_path_imports.fixed +++ b/tests/ui/single_component_path_imports.fixed @@ -1,5 +1,4 @@ #![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] use core; @@ -31,13 +30,11 @@ fn main() { mod hello_mod { //~^ single_component_path_imports - #[allow(dead_code)] fn hello_mod() {} } mod hi_mod { use self::regex::{Regex, RegexSet}; use regex; - #[allow(dead_code)] fn hi_mod() {} } diff --git a/tests/ui/single_component_path_imports.rs b/tests/ui/single_component_path_imports.rs index 888c533c534c7..efd425abc4bf4 100644 --- a/tests/ui/single_component_path_imports.rs +++ b/tests/ui/single_component_path_imports.rs @@ -1,5 +1,4 @@ #![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] use core; @@ -32,13 +31,11 @@ fn main() { mod hello_mod { use regex; //~^ single_component_path_imports - #[allow(dead_code)] fn hello_mod() {} } mod hi_mod { use self::regex::{Regex, RegexSet}; use regex; - #[allow(dead_code)] fn hi_mod() {} } diff --git a/tests/ui/single_component_path_imports.stderr b/tests/ui/single_component_path_imports.stderr index f1c56b14358ff..d0c950c966608 100644 --- a/tests/ui/single_component_path_imports.stderr +++ b/tests/ui/single_component_path_imports.stderr @@ -1,5 +1,5 @@ error: this import is redundant - --> tests/ui/single_component_path_imports.rs:6:1 + --> tests/ui/single_component_path_imports.rs:5:1 | LL | use regex; | ^^^^^^^^^^ help: remove it entirely @@ -8,7 +8,7 @@ LL | use regex; = help: to override `-D warnings` add `#[allow(clippy::single_component_path_imports)]` error: this import is redundant - --> tests/ui/single_component_path_imports.rs:33:5 + --> tests/ui/single_component_path_imports.rs:32:5 | LL | use regex; | ^^^^^^^^^^ help: remove it entirely diff --git a/tests/ui/single_component_path_imports_macro.rs b/tests/ui/single_component_path_imports_macro.rs index f655ea482d1cf..991fcfbe8a3d6 100644 --- a/tests/ui/single_component_path_imports_macro.rs +++ b/tests/ui/single_component_path_imports_macro.rs @@ -1,7 +1,6 @@ //@ check-pass #![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] // #7106: use statements exporting a macro within a crate should not trigger lint // #7923: normal `use` statements of macros should also not trigger the lint diff --git a/tests/ui/single_component_path_imports_nested_first.rs b/tests/ui/single_component_path_imports_nested_first.rs index 77213bc482c39..32043bacc240d 100644 --- a/tests/ui/single_component_path_imports_nested_first.rs +++ b/tests/ui/single_component_path_imports_nested_first.rs @@ -1,5 +1,4 @@ #![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] //@no-rustfix use regex; //~^ single_component_path_imports @@ -18,6 +17,5 @@ mod root_nested_use_mod { //~^ single_component_path_imports //~| single_component_path_imports - #[allow(dead_code)] fn root_nested_use_mod() {} } diff --git a/tests/ui/single_component_path_imports_nested_first.stderr b/tests/ui/single_component_path_imports_nested_first.stderr index 8eec877860e7e..59663f5a1e716 100644 --- a/tests/ui/single_component_path_imports_nested_first.stderr +++ b/tests/ui/single_component_path_imports_nested_first.stderr @@ -1,5 +1,5 @@ error: this import is redundant - --> tests/ui/single_component_path_imports_nested_first.rs:4:1 + --> tests/ui/single_component_path_imports_nested_first.rs:3:1 | LL | use regex; | ^^^^^^^^^^ help: remove it entirely @@ -8,7 +8,7 @@ LL | use regex; = help: to override `-D warnings` add `#[allow(clippy::single_component_path_imports)]` error: this import is redundant - --> tests/ui/single_component_path_imports_nested_first.rs:17:10 + --> tests/ui/single_component_path_imports_nested_first.rs:16:10 | LL | use {regex, serde}; | ^^^^^ @@ -16,7 +16,7 @@ LL | use {regex, serde}; = help: remove this import error: this import is redundant - --> tests/ui/single_component_path_imports_nested_first.rs:17:17 + --> tests/ui/single_component_path_imports_nested_first.rs:16:17 | LL | use {regex, serde}; | ^^^^^ diff --git a/tests/ui/single_component_path_imports_self_after.rs b/tests/ui/single_component_path_imports_self_after.rs index a0f2cf6908091..f9e85555a2623 100644 --- a/tests/ui/single_component_path_imports_self_after.rs +++ b/tests/ui/single_component_path_imports_self_after.rs @@ -1,7 +1,6 @@ //@ check-pass #![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] use self::regex::{Regex as xeger, RegexSet as tesxeger}; #[rustfmt::skip] diff --git a/tests/ui/single_component_path_imports_self_before.rs b/tests/ui/single_component_path_imports_self_before.rs index b80580da10c39..753fc67cdb295 100644 --- a/tests/ui/single_component_path_imports_self_before.rs +++ b/tests/ui/single_component_path_imports_self_before.rs @@ -1,7 +1,6 @@ //@ check-pass #![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] use regex; diff --git a/tests/ui/single_match.fixed b/tests/ui/single_match.fixed index fe28674ec18e5..653c88c0f860d 100644 --- a/tests/ui/single_match.fixed +++ b/tests/ui/single_match.fixed @@ -1,13 +1,6 @@ //@require-annotations-for-level: WARN #![warn(clippy::single_match)] -#![allow( - unused, - clippy::uninlined_format_args, - clippy::needless_ifs, - clippy::redundant_guards, - clippy::redundant_pattern_matching, - clippy::manual_unwrap_or_default -)] +#![allow(clippy::redundant_pattern_matching)] fn dummy() {} fn single_match() { diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs index 0f558cb5f786c..2b627781b9d07 100644 --- a/tests/ui/single_match.rs +++ b/tests/ui/single_match.rs @@ -1,13 +1,6 @@ //@require-annotations-for-level: WARN #![warn(clippy::single_match)] -#![allow( - unused, - clippy::uninlined_format_args, - clippy::needless_ifs, - clippy::redundant_guards, - clippy::redundant_pattern_matching, - clippy::manual_unwrap_or_default -)] +#![allow(clippy::redundant_pattern_matching)] fn dummy() {} fn single_match() { diff --git a/tests/ui/single_match.stderr b/tests/ui/single_match.stderr index ba8bc5af5a608..2cd9777a1ba9a 100644 --- a/tests/ui/single_match.stderr +++ b/tests/ui/single_match.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:16:5 + --> tests/ui/single_match.rs:9:5 | LL | / match x { LL | | Some(y) => { @@ -19,7 +19,7 @@ LL ~ }; | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:25:5 + --> tests/ui/single_match.rs:18:5 | LL | / match x { ... | @@ -30,7 +30,7 @@ LL | | } = note: you might want to preserve the comments from inside the `match` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:36:5 + --> tests/ui/single_match.rs:29:5 | LL | / match z { LL | | (2..=3, 7..=9) => dummy(), @@ -39,7 +39,7 @@ LL | | }; | |_____^ help: try: `if let (2..=3, 7..=9) = z { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:66:5 + --> tests/ui/single_match.rs:59:5 | LL | / match x { LL | | Some(y) => dummy(), @@ -48,7 +48,7 @@ LL | | }; | |_____^ help: try: `if let Some(y) = x { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:72:5 + --> tests/ui/single_match.rs:65:5 | LL | / match y { LL | | Ok(y) => dummy(), @@ -57,7 +57,7 @@ LL | | }; | |_____^ help: try: `if let Ok(y) = y { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:80:5 + --> tests/ui/single_match.rs:73:5 | LL | / match c { LL | | Cow::Borrowed(..) => dummy(), @@ -66,7 +66,7 @@ LL | | }; | |_____^ help: try: `if let Cow::Borrowed(..) = c { dummy() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:102:5 + --> tests/ui/single_match.rs:95:5 | LL | / match x { LL | | "test" => println!(), @@ -75,7 +75,7 @@ LL | | } | |_____^ help: try: `if x == "test" { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:116:5 + --> tests/ui/single_match.rs:109:5 | LL | / match x { LL | | Foo::A => println!(), @@ -84,7 +84,7 @@ LL | | } | |_____^ help: try: `if x == Foo::A { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:123:5 + --> tests/ui/single_match.rs:116:5 | LL | / match x { LL | | FOO_C => println!(), @@ -93,7 +93,7 @@ LL | | } | |_____^ help: try: `if x == FOO_C { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:129:5 + --> tests/ui/single_match.rs:122:5 | LL | / match &&x { LL | | Foo::A => println!(), @@ -102,7 +102,7 @@ LL | | } | |_____^ help: try: `if x == Foo::A { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:136:5 + --> tests/ui/single_match.rs:129:5 | LL | / match &x { LL | | Foo::A => println!(), @@ -111,7 +111,7 @@ LL | | } | |_____^ help: try: `if x == &Foo::A { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:154:5 + --> tests/ui/single_match.rs:147:5 | LL | / match x { LL | | Bar::A => println!(), @@ -120,7 +120,7 @@ LL | | } | |_____^ help: try: `if let Bar::A = x { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:163:5 + --> tests/ui/single_match.rs:156:5 | LL | / match x { LL | | None => println!(), @@ -129,7 +129,7 @@ LL | | }; | |_____^ help: try: `if let None = x { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:186:5 + --> tests/ui/single_match.rs:179:5 | LL | / match x { LL | | (Some(_), _) => {}, @@ -138,7 +138,7 @@ LL | | } | |_____^ help: try: `if let (Some(_), _) = x {}` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:193:5 + --> tests/ui/single_match.rs:186:5 | LL | / match x { LL | | (Some(E::V), _) => todo!(), @@ -147,7 +147,7 @@ LL | | } | |_____^ help: try: `if let (Some(E::V), _) = x { todo!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:200:5 + --> tests/ui/single_match.rs:193:5 | LL | / match (Some(42), Some(E::V), Some(42)) { LL | | (.., Some(E::V), _) => {}, @@ -156,7 +156,7 @@ LL | | } | |_____^ help: try: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:273:5 + --> tests/ui/single_match.rs:266:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -176,7 +176,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:282:5 + --> tests/ui/single_match.rs:275:5 | LL | / match bar { LL | | #[rustfmt::skip] @@ -198,7 +198,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:363:5 + --> tests/ui/single_match.rs:356:5 | LL | / match Ok::<_, u32>(Some(A)) { LL | | Ok(Some(A)) => println!(), @@ -207,7 +207,7 @@ LL | | } | |_____^ help: try: `if let Ok(Some(A)) = Ok::<_, u32>(Some(A)) { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:379:5 + --> tests/ui/single_match.rs:372:5 | LL | / match &Some(A) { LL | | Some(A | B) => println!(), @@ -216,7 +216,7 @@ LL | | } | |_____^ help: try: `if let Some(A | B) = &Some(A) { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:387:5 + --> tests/ui/single_match.rs:380:5 | LL | / match &s[0..3] { LL | | b"foo" => println!(), @@ -225,7 +225,7 @@ LL | | } | |_____^ help: try: `if &s[0..3] == b"foo" { println!() }` error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:402:5 + --> tests/ui/single_match.rs:395:5 | LL | / match DATA { LL | | DATA => println!(), @@ -234,7 +234,7 @@ LL | | } | |_____^ help: try: `println!();` error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:408:5 + --> tests/ui/single_match.rs:401:5 | LL | / match CONST_I32 { LL | | CONST_I32 => println!(), @@ -243,7 +243,7 @@ LL | | } | |_____^ help: try: `println!();` error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:415:5 + --> tests/ui/single_match.rs:408:5 | LL | / match i { LL | | i => { @@ -263,7 +263,7 @@ LL + } | error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:424:5 + --> tests/ui/single_match.rs:417:5 | LL | / match i { LL | | i => {}, @@ -272,7 +272,7 @@ LL | | } | |_____^ help: `match` expression can be removed error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:430:5 + --> tests/ui/single_match.rs:423:5 | LL | / match i { LL | | i => (), @@ -281,7 +281,7 @@ LL | | } | |_____^ help: `match` expression can be removed error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:436:5 + --> tests/ui/single_match.rs:429:5 | LL | / match CONST_I32 { LL | | CONST_I32 => println!(), @@ -290,7 +290,7 @@ LL | | } | |_____^ help: try: `println!();` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:444:5 + --> tests/ui/single_match.rs:437:5 | LL | / match x.pop() { LL | | // bla @@ -302,7 +302,7 @@ LL | | } = note: you might want to preserve the comments from inside the `match` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:453:5 + --> tests/ui/single_match.rs:446:5 | LL | / match x.pop() { LL | | // bla @@ -322,7 +322,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:479:5 + --> tests/ui/single_match.rs:472:5 | LL | / match mac!(some) { LL | | Some(u) => println!("{u}"), @@ -331,7 +331,7 @@ LL | | } | |_____^ help: try: `if let Some(u) = mac!(some) { println!("{u}") }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:487:5 + --> tests/ui/single_match.rs:480:5 | LL | / match mac!(str) { LL | | "foo" => println!("eq"), diff --git a/tests/ui/single_match_else.fixed b/tests/ui/single_match_else.fixed index fde13fb90dbb2..db14fdc097d35 100644 --- a/tests/ui/single_match_else.fixed +++ b/tests/ui/single_match_else.fixed @@ -2,7 +2,7 @@ //@require-annotations-for-level: WARN #![warn(clippy::single_match_else)] -#![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] +#![expect(clippy::needless_return)] extern crate proc_macros; use proc_macros::with_span; diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs index ca282200067ce..45225e260ae7f 100644 --- a/tests/ui/single_match_else.rs +++ b/tests/ui/single_match_else.rs @@ -2,7 +2,7 @@ //@require-annotations-for-level: WARN #![warn(clippy::single_match_else)] -#![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] +#![expect(clippy::needless_return)] extern crate proc_macros; use proc_macros::with_span; diff --git a/tests/ui/single_match_else_deref_patterns.fixed b/tests/ui/single_match_else_deref_patterns.fixed index 1743ae6bf5a7d..381a9efd7c1c3 100644 --- a/tests/ui/single_match_else_deref_patterns.fixed +++ b/tests/ui/single_match_else_deref_patterns.fixed @@ -1,13 +1,7 @@ #![feature(deref_patterns)] -#![allow( - incomplete_features, - clippy::eq_op, - clippy::op_ref, - clippy::deref_addrof, - clippy::borrow_deref_ref, - clippy::needless_ifs -)] -#![deny(clippy::single_match_else)] +#![warn(clippy::single_match_else)] +#![allow(clippy::eq_op, clippy::needless_ifs, clippy::op_ref)] +#![expect(clippy::borrow_deref_ref, clippy::deref_addrof)] fn string() { if *"" == *"" {} diff --git a/tests/ui/single_match_else_deref_patterns.rs b/tests/ui/single_match_else_deref_patterns.rs index d5cb8a24a609c..dbed5d38a6a34 100644 --- a/tests/ui/single_match_else_deref_patterns.rs +++ b/tests/ui/single_match_else_deref_patterns.rs @@ -1,13 +1,7 @@ #![feature(deref_patterns)] -#![allow( - incomplete_features, - clippy::eq_op, - clippy::op_ref, - clippy::deref_addrof, - clippy::borrow_deref_ref, - clippy::needless_ifs -)] -#![deny(clippy::single_match_else)] +#![warn(clippy::single_match_else)] +#![allow(clippy::eq_op, clippy::needless_ifs, clippy::op_ref)] +#![expect(clippy::borrow_deref_ref, clippy::deref_addrof)] fn string() { match *"" { diff --git a/tests/ui/single_match_else_deref_patterns.stderr b/tests/ui/single_match_else_deref_patterns.stderr index a47df55459be1..b55f57681f57f 100644 --- a/tests/ui/single_match_else_deref_patterns.stderr +++ b/tests/ui/single_match_else_deref_patterns.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:13:5 + --> tests/ui/single_match_else_deref_patterns.rs:7:5 | LL | / match *"" { LL | | @@ -13,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::single_match)]` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:19:5 + --> tests/ui/single_match_else_deref_patterns.rs:13:5 | LL | / match *&*&*&*"" { LL | | @@ -25,7 +25,7 @@ LL | | } = note: you might want to preserve the comments from inside the `match` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:25:5 + --> tests/ui/single_match_else_deref_patterns.rs:19:5 | LL | / match ***&&"" { LL | | @@ -37,7 +37,7 @@ LL | | } = note: you might want to preserve the comments from inside the `match` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:31:5 + --> tests/ui/single_match_else_deref_patterns.rs:25:5 | LL | / match *&*&*"" { LL | | @@ -49,7 +49,7 @@ LL | | } = note: you might want to preserve the comments from inside the `match` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:37:5 + --> tests/ui/single_match_else_deref_patterns.rs:31:5 | LL | / match **&&*"" { LL | | @@ -61,7 +61,7 @@ LL | | } = note: you might want to preserve the comments from inside the `match` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:45:5 + --> tests/ui/single_match_else_deref_patterns.rs:39:5 | LL | / match &&&1 { LL | | &&&2 => unreachable!(), @@ -70,11 +70,8 @@ LL | | _ => { LL | | } | |_____^ | -note: the lint level is defined here - --> tests/ui/single_match_else_deref_patterns.rs:10:9 - | -LL | #![deny(clippy::single_match_else)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::single-match-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_match_else)]` help: try | LL ~ if &&&1 == &&&2 { unreachable!() } else { @@ -83,7 +80,7 @@ LL + } | error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:52:5 + --> tests/ui/single_match_else_deref_patterns.rs:46:5 | LL | / match &&&1 { LL | | &&2 => unreachable!(), @@ -100,7 +97,7 @@ LL + } | error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:59:5 + --> tests/ui/single_match_else_deref_patterns.rs:53:5 | LL | / match &&1 { LL | | &&2 => unreachable!(), @@ -117,7 +114,7 @@ LL + } | error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:66:5 + --> tests/ui/single_match_else_deref_patterns.rs:60:5 | LL | / match &&&1 { LL | | &2 => unreachable!(), @@ -134,7 +131,7 @@ LL + } | error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:73:5 + --> tests/ui/single_match_else_deref_patterns.rs:67:5 | LL | / match &&1 { LL | | &2 => unreachable!(), @@ -151,7 +148,7 @@ LL + } | error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:80:5 + --> tests/ui/single_match_else_deref_patterns.rs:74:5 | LL | / match &&&1 { LL | | 2 => unreachable!(), @@ -168,7 +165,7 @@ LL + } | error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match_else_deref_patterns.rs:87:5 + --> tests/ui/single_match_else_deref_patterns.rs:81:5 | LL | / match &&1 { LL | | 2 => unreachable!(), diff --git a/tests/ui/single_range_in_vec_init.new_range.1.fixed b/tests/ui/single_range_in_vec_init.new_range.1.fixed index 02a91e654a5cb..c154b6d416efd 100644 --- a/tests/ui/single_range_in_vec_init.new_range.1.fixed +++ b/tests/ui/single_range_in_vec_init.new_range.1.fixed @@ -5,8 +5,8 @@ // When feature(new_range) stabilizes, this should be converted to testing // old and new editions instead. #![cfg_attr(new_range, feature(new_range))] -#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] +#![expect(clippy::no_effect, clippy::useless_vec)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/single_range_in_vec_init.new_range.2.fixed b/tests/ui/single_range_in_vec_init.new_range.2.fixed index afd183ab87ac3..bc9cc4eb4dfe5 100644 --- a/tests/ui/single_range_in_vec_init.new_range.2.fixed +++ b/tests/ui/single_range_in_vec_init.new_range.2.fixed @@ -5,8 +5,8 @@ // When feature(new_range) stabilizes, this should be converted to testing // old and new editions instead. #![cfg_attr(new_range, feature(new_range))] -#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] +#![expect(clippy::no_effect, clippy::useless_vec)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/single_range_in_vec_init.old_range.1.fixed b/tests/ui/single_range_in_vec_init.old_range.1.fixed index 2e082cb7d7a90..60f113736202a 100644 --- a/tests/ui/single_range_in_vec_init.old_range.1.fixed +++ b/tests/ui/single_range_in_vec_init.old_range.1.fixed @@ -5,8 +5,8 @@ // When feature(new_range) stabilizes, this should be converted to testing // old and new editions instead. #![cfg_attr(new_range, feature(new_range))] -#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] +#![expect(clippy::no_effect, clippy::useless_vec)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/single_range_in_vec_init.old_range.2.fixed b/tests/ui/single_range_in_vec_init.old_range.2.fixed index ab297ccfa819f..d338dd87bc779 100644 --- a/tests/ui/single_range_in_vec_init.old_range.2.fixed +++ b/tests/ui/single_range_in_vec_init.old_range.2.fixed @@ -5,8 +5,8 @@ // When feature(new_range) stabilizes, this should be converted to testing // old and new editions instead. #![cfg_attr(new_range, feature(new_range))] -#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] +#![expect(clippy::no_effect, clippy::useless_vec)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/single_range_in_vec_init.rs b/tests/ui/single_range_in_vec_init.rs index 8fdeac1fc9a0d..2bd15af26a93e 100644 --- a/tests/ui/single_range_in_vec_init.rs +++ b/tests/ui/single_range_in_vec_init.rs @@ -5,8 +5,8 @@ // When feature(new_range) stabilizes, this should be converted to testing // old and new editions instead. #![cfg_attr(new_range, feature(new_range))] -#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] +#![expect(clippy::no_effect, clippy::useless_vec)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/size_of_in_element_count/expressions.rs b/tests/ui/size_of_in_element_count/expressions.rs index 3fe4d923441dd..9d4fa69ed90be 100644 --- a/tests/ui/size_of_in_element_count/expressions.rs +++ b/tests/ui/size_of_in_element_count/expressions.rs @@ -1,5 +1,4 @@ #![warn(clippy::size_of_in_element_count)] -#![allow(clippy::ptr_offset_with_cast)] use std::mem::{size_of, size_of_val}; use std::ptr::{copy, copy_nonoverlapping, write_bytes}; diff --git a/tests/ui/size_of_in_element_count/expressions.stderr b/tests/ui/size_of_in_element_count/expressions.stderr index 74be0d7773dff..c85c818679f2e 100644 --- a/tests/ui/size_of_in_element_count/expressions.stderr +++ b/tests/ui/size_of_in_element_count/expressions.stderr @@ -1,5 +1,5 @@ error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:15:62 + --> tests/ui/size_of_in_element_count/expressions.rs:14:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of:: = help: to override `-D warnings` add `#[allow(clippy::size_of_in_element_count)]` error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:19:62 + --> tests/ui/size_of_in_element_count/expressions.rs:18:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * si = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:23:47 + --> tests/ui/size_of_in_element_count/expressions.rs:22:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::( = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> tests/ui/size_of_in_element_count/expressions.rs:33:47 + --> tests/ui/size_of_in_element_count/expressions.rs:32:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 / size_of::())) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/size_of_in_element_count/functions.rs b/tests/ui/size_of_in_element_count/functions.rs index afd12edec1edb..a8be9af099f3a 100644 --- a/tests/ui/size_of_in_element_count/functions.rs +++ b/tests/ui/size_of_in_element_count/functions.rs @@ -1,5 +1,5 @@ #![warn(clippy::size_of_in_element_count)] -#![allow(clippy::ptr_offset_with_cast)] +#![expect(clippy::ptr_offset_with_cast)] use std::mem::{size_of, size_of_val}; use std::ptr::{ diff --git a/tests/ui/size_of_ref.rs b/tests/ui/size_of_ref.rs index 9a6a9419f681e..068f3bd514397 100644 --- a/tests/ui/size_of_ref.rs +++ b/tests/ui/size_of_ref.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::size_of_ref)] use std::mem::size_of_val; diff --git a/tests/ui/size_of_ref.stderr b/tests/ui/size_of_ref.stderr index 46af9f55deaf6..79b0ec837e2f9 100644 --- a/tests/ui/size_of_ref.stderr +++ b/tests/ui/size_of_ref.stderr @@ -1,5 +1,5 @@ error: argument to `size_of_val()` is a reference to a reference - --> tests/ui/size_of_ref.rs:13:5 + --> tests/ui/size_of_ref.rs:12:5 | LL | size_of_val(&&x); | ^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | size_of_val(&&x); = help: to override `-D warnings` add `#[allow(clippy::size_of_ref)]` error: argument to `size_of_val()` is a reference to a reference - --> tests/ui/size_of_ref.rs:16:5 + --> tests/ui/size_of_ref.rs:15:5 | LL | size_of_val(&y); | ^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | size_of_val(&y); = help: dereference the argument to `size_of_val()` to get the size of the value instead of the size of the reference-type error: argument to `size_of_val()` is a reference to a reference - --> tests/ui/size_of_ref.rs:28:9 + --> tests/ui/size_of_ref.rs:27:9 | LL | std::mem::size_of_val(&self) + (std::mem::size_of::() * self.data.capacity()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/skip_while_next.rs b/tests/ui/skip_while_next.rs index 6dbb6a2ebb9af..7a176edaef10c 100644 --- a/tests/ui/skip_while_next.rs +++ b/tests/ui/skip_while_next.rs @@ -1,7 +1,7 @@ //@aux-build:option_helpers.rs #![warn(clippy::skip_while_next)] -#![allow(clippy::disallowed_names, clippy::useless_vec)] +#![expect(clippy::disallowed_names, clippy::useless_vec)] extern crate option_helpers; use option_helpers::IteratorFalsePositives; diff --git a/tests/ui/sliced_string_as_bytes.fixed b/tests/ui/sliced_string_as_bytes.fixed index b5576188b83f6..69347ea299cbf 100644 --- a/tests/ui/sliced_string_as_bytes.fixed +++ b/tests/ui/sliced_string_as_bytes.fixed @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::sliced_string_as_bytes)] use std::ops::{Index, Range}; diff --git a/tests/ui/sliced_string_as_bytes.rs b/tests/ui/sliced_string_as_bytes.rs index 58b8d92902942..15e5fd575c71c 100644 --- a/tests/ui/sliced_string_as_bytes.rs +++ b/tests/ui/sliced_string_as_bytes.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::sliced_string_as_bytes)] use std::ops::{Index, Range}; diff --git a/tests/ui/sliced_string_as_bytes.stderr b/tests/ui/sliced_string_as_bytes.stderr index ae7f02781f4bb..3e4989ceae834 100644 --- a/tests/ui/sliced_string_as_bytes.stderr +++ b/tests/ui/sliced_string_as_bytes.stderr @@ -1,5 +1,5 @@ error: calling `as_bytes` after slicing a string - --> tests/ui/sliced_string_as_bytes.rs:28:17 + --> tests/ui/sliced_string_as_bytes.rs:27:17 | LL | let bytes = s[1..5].as_bytes(); | ^^^^^^^^^^^^^^^^^^ help: try: `&s.as_bytes()[1..5]` @@ -8,13 +8,13 @@ LL | let bytes = s[1..5].as_bytes(); = help: to override `-D warnings` add `#[allow(clippy::sliced_string_as_bytes)]` error: calling `as_bytes` after slicing a string - --> tests/ui/sliced_string_as_bytes.rs:30:17 + --> tests/ui/sliced_string_as_bytes.rs:29:17 | LL | let bytes = string[1..].as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&string.as_bytes()[1..]` error: calling `as_bytes` after slicing a string - --> tests/ui/sliced_string_as_bytes.rs:32:17 + --> tests/ui/sliced_string_as_bytes.rs:31:17 | LL | let bytes = "consectetur adipiscing"[..=5].as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&"consectetur adipiscing".as_bytes()[..=5]` diff --git a/tests/ui/slow_vector_initialization.fixed b/tests/ui/slow_vector_initialization.fixed index a13be693e4ec2..8ef967882b651 100644 --- a/tests/ui/slow_vector_initialization.fixed +++ b/tests/ui/slow_vector_initialization.fixed @@ -1,4 +1,6 @@ -#![allow(clippy::useless_vec, clippy::manual_repeat_n)] +#![warn(clippy::slow_vector_initialization)] +#![allow(clippy::useless_vec)] +#![expect(clippy::manual_repeat_n)] use std::iter::repeat; diff --git a/tests/ui/slow_vector_initialization.rs b/tests/ui/slow_vector_initialization.rs index eda96d0a0f82a..637bbe09d6846 100644 --- a/tests/ui/slow_vector_initialization.rs +++ b/tests/ui/slow_vector_initialization.rs @@ -1,4 +1,6 @@ -#![allow(clippy::useless_vec, clippy::manual_repeat_n)] +#![warn(clippy::slow_vector_initialization)] +#![allow(clippy::useless_vec)] +#![expect(clippy::manual_repeat_n)] use std::iter::repeat; diff --git a/tests/ui/slow_vector_initialization.stderr b/tests/ui/slow_vector_initialization.stderr index 320f2cacf61b3..2876c6e1e534c 100644 --- a/tests/ui/slow_vector_initialization.stderr +++ b/tests/ui/slow_vector_initialization.stderr @@ -1,5 +1,5 @@ error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:10:20 + --> tests/ui/slow_vector_initialization.rs:12:20 | LL | let mut vec1 = Vec::with_capacity(len); | ____________________^ @@ -11,7 +11,7 @@ LL | | vec1.extend(repeat(0).take(len)); = help: to override `-D warnings` add `#[allow(clippy::slow_vector_initialization)]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:16:20 + --> tests/ui/slow_vector_initialization.rs:18:20 | LL | let mut vec2 = Vec::with_capacity(len - 10); | ____________________^ @@ -20,7 +20,7 @@ LL | | vec2.extend(repeat(0).take(len - 10)); | |_________________________________________^ help: consider replacing this with: `vec![0; len - 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:25:20 + --> tests/ui/slow_vector_initialization.rs:27:20 | LL | let mut vec4 = Vec::with_capacity(len); | ____________________^ @@ -29,7 +29,7 @@ LL | | vec4.extend(repeat(0).take(vec4.capacity())); | |________________________________________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:37:27 + --> tests/ui/slow_vector_initialization.rs:39:27 | LL | let mut resized_vec = Vec::with_capacity(30); | ___________________________^ @@ -38,7 +38,7 @@ LL | | resized_vec.resize(30, 0); | |_____________________________^ help: consider replacing this with: `vec![0; 30]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:42:26 + --> tests/ui/slow_vector_initialization.rs:44:26 | LL | let mut extend_vec = Vec::with_capacity(30); | __________________________^ @@ -47,7 +47,7 @@ LL | | extend_vec.extend(repeat(0).take(30)); | |_________________________________________^ help: consider replacing this with: `vec![0; 30]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:51:20 + --> tests/ui/slow_vector_initialization.rs:53:20 | LL | let mut vec1 = Vec::with_capacity(len); | ____________________^ @@ -56,7 +56,7 @@ LL | | vec1.resize(len, 0); | |_______________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:61:20 + --> tests/ui/slow_vector_initialization.rs:63:20 | LL | let mut vec3 = Vec::with_capacity(len - 10); | ____________________^ @@ -65,7 +65,7 @@ LL | | vec3.resize(len - 10, 0); | |____________________________^ help: consider replacing this with: `vec![0; len - 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:66:20 + --> tests/ui/slow_vector_initialization.rs:68:20 | LL | let mut vec4 = Vec::with_capacity(len); | ____________________^ @@ -74,7 +74,7 @@ LL | | vec4.resize(vec4.capacity(), 0); | |___________________________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:72:12 + --> tests/ui/slow_vector_initialization.rs:74:12 | LL | vec1 = Vec::with_capacity(10); | ____________^ @@ -83,7 +83,7 @@ LL | | vec1.resize(10, 0); | |______________________^ help: consider replacing this with: `vec![0; 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:81:20 + --> tests/ui/slow_vector_initialization.rs:83:20 | LL | let mut vec1 = Vec::new(); | ____________________^ @@ -92,7 +92,7 @@ LL | | vec1.resize(len, 0); | |_______________________^ help: consider replacing this with: `vec![0; len]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:87:20 + --> tests/ui/slow_vector_initialization.rs:89:20 | LL | let mut vec3 = Vec::new(); | ____________________^ @@ -101,7 +101,7 @@ LL | | vec3.resize(len - 10, 0); | |____________________________^ help: consider replacing this with: `vec![0; len - 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:93:12 + --> tests/ui/slow_vector_initialization.rs:95:12 | LL | vec1 = Vec::new(); | ____________^ @@ -110,7 +110,7 @@ LL | | vec1.resize(10, 0); | |______________________^ help: consider replacing this with: `vec![0; 10]` error: slow zero-filling initialization - --> tests/ui/slow_vector_initialization.rs:98:12 + --> tests/ui/slow_vector_initialization.rs:100:12 | LL | vec1 = vec![]; | ____________^ diff --git a/tests/ui/some_filter.fixed b/tests/ui/some_filter.fixed index a214dec920d4e..938dc8514e2e9 100644 --- a/tests/ui/some_filter.fixed +++ b/tests/ui/some_filter.fixed @@ -1,5 +1,5 @@ #![warn(clippy::some_filter)] -#![allow(clippy::const_is_empty)] +#![expect(clippy::const_is_empty)] macro_rules! unchanged { ($result:expr) => { diff --git a/tests/ui/some_filter.rs b/tests/ui/some_filter.rs index eec797536a8f7..a121417356662 100644 --- a/tests/ui/some_filter.rs +++ b/tests/ui/some_filter.rs @@ -1,5 +1,5 @@ #![warn(clippy::some_filter)] -#![allow(clippy::const_is_empty)] +#![expect(clippy::const_is_empty)] macro_rules! unchanged { ($result:expr) => { diff --git a/tests/ui/stable_sort_primitive.fixed b/tests/ui/stable_sort_primitive.fixed index b4870ebad2b36..a29bc8e7c360c 100644 --- a/tests/ui/stable_sort_primitive.fixed +++ b/tests/ui/stable_sort_primitive.fixed @@ -1,5 +1,5 @@ #![warn(clippy::stable_sort_primitive)] -#![allow(clippy::useless_vec)] +#![expect(clippy::useless_vec)] fn main() { // positive examples diff --git a/tests/ui/stable_sort_primitive.rs b/tests/ui/stable_sort_primitive.rs index b3fe64efd6201..848898c56e0b8 100644 --- a/tests/ui/stable_sort_primitive.rs +++ b/tests/ui/stable_sort_primitive.rs @@ -1,5 +1,5 @@ #![warn(clippy::stable_sort_primitive)] -#![allow(clippy::useless_vec)] +#![expect(clippy::useless_vec)] fn main() { // positive examples diff --git a/tests/ui/starts_ends_with.fixed b/tests/ui/starts_ends_with.fixed index f2fab9217604b..88f422ed21229 100644 --- a/tests/ui/starts_ends_with.fixed +++ b/tests/ui/starts_ends_with.fixed @@ -1,4 +1,4 @@ -#![allow(clippy::needless_ifs, dead_code, unused_must_use, clippy::double_ended_iterator_last)] +#![warn(clippy::chars_last_cmp, clippy::chars_next_cmp)] fn main() {} diff --git a/tests/ui/starts_ends_with.rs b/tests/ui/starts_ends_with.rs index 1460d77a094dd..db4789244783b 100644 --- a/tests/ui/starts_ends_with.rs +++ b/tests/ui/starts_ends_with.rs @@ -1,4 +1,4 @@ -#![allow(clippy::needless_ifs, dead_code, unused_must_use, clippy::double_ended_iterator_last)] +#![warn(clippy::chars_last_cmp, clippy::chars_next_cmp)] fn main() {} diff --git a/tests/ui/std_instead_of_core.fixed b/tests/ui/std_instead_of_core.fixed index 3020ed5c6f39d..63d0e204d72fd 100644 --- a/tests/ui/std_instead_of_core.fixed +++ b/tests/ui/std_instead_of_core.fixed @@ -1,7 +1,7 @@ //@aux-build:proc_macro_derive.rs #![warn(clippy::std_instead_of_core)] -#![allow(unused_imports, deprecated)] +#![expect(deprecated)] extern crate alloc; @@ -69,7 +69,6 @@ fn alloc_instead_of_core() { mod std_in_proc_macro_derive { #[warn(clippy::alloc_instead_of_core)] - #[allow(unused)] #[derive(ImplStructWithStdDisplay)] struct B {} } diff --git a/tests/ui/std_instead_of_core.rs b/tests/ui/std_instead_of_core.rs index 49b4218aa8983..e5cde188bedd7 100644 --- a/tests/ui/std_instead_of_core.rs +++ b/tests/ui/std_instead_of_core.rs @@ -1,7 +1,7 @@ //@aux-build:proc_macro_derive.rs #![warn(clippy::std_instead_of_core)] -#![allow(unused_imports, deprecated)] +#![expect(deprecated)] extern crate alloc; @@ -69,7 +69,6 @@ fn alloc_instead_of_core() { mod std_in_proc_macro_derive { #[warn(clippy::alloc_instead_of_core)] - #[allow(unused)] #[derive(ImplStructWithStdDisplay)] struct B {} } diff --git a/tests/ui/std_instead_of_core.stderr b/tests/ui/std_instead_of_core.stderr index 0363852cf8d49..7045d44482114 100644 --- a/tests/ui/std_instead_of_core.stderr +++ b/tests/ui/std_instead_of_core.stderr @@ -86,25 +86,25 @@ LL | use alloc::slice::from_ref; = help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]` error: used import from `std` instead of `core` - --> tests/ui/std_instead_of_core.rs:81:9 + --> tests/ui/std_instead_of_core.rs:80:9 | LL | std::intrinsics::copy(a, b, 1); | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> tests/ui/std_instead_of_core.rs:90:17 + --> tests/ui/std_instead_of_core.rs:89:17 | LL | fn msrv_1_77(_: std::net::IpAddr) {} | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> tests/ui/std_instead_of_core.rs:110:33 + --> tests/ui/std_instead_of_core.rs:109:33 | LL | fn issue13158_msrv_1_41(_: &dyn std::panic::UnwindSafe) {} | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> tests/ui/std_instead_of_core.rs:117:33 + --> tests/ui/std_instead_of_core.rs:116:33 | LL | fn issue13158_msrv_1_81(_: &dyn std::error::Error) {} | ^^^ help: consider importing the item from `core`: `core` diff --git a/tests/ui/std_instead_of_core_unfixable.rs b/tests/ui/std_instead_of_core_unfixable.rs index 66d834b5e4279..459db5e8944ae 100644 --- a/tests/ui/std_instead_of_core_unfixable.rs +++ b/tests/ui/std_instead_of_core_unfixable.rs @@ -1,6 +1,4 @@ -#![warn(clippy::std_instead_of_core)] -#![warn(clippy::std_instead_of_alloc)] -#![allow(unused_imports)] +#![warn(clippy::std_instead_of_alloc, clippy::std_instead_of_core)] #[rustfmt::skip] fn issue14982() { diff --git a/tests/ui/std_instead_of_core_unfixable.stderr b/tests/ui/std_instead_of_core_unfixable.stderr index 6fa8f47a4d6f4..c79b3e48cad37 100644 --- a/tests/ui/std_instead_of_core_unfixable.stderr +++ b/tests/ui/std_instead_of_core_unfixable.stderr @@ -1,5 +1,5 @@ error: used import from `std` instead of `core` - --> tests/ui/std_instead_of_core_unfixable.rs:7:43 + --> tests/ui/std_instead_of_core_unfixable.rs:5:43 | LL | use std::{collections::HashMap, hash::Hash}; | ^^^^ @@ -9,7 +9,7 @@ LL | use std::{collections::HashMap, hash::Hash}; = help: to override `-D warnings` add `#[allow(clippy::std_instead_of_core)]` error: used import from `std` instead of `core` - --> tests/ui/std_instead_of_core_unfixable.rs:13:22 + --> tests/ui/std_instead_of_core_unfixable.rs:11:22 | LL | use std::{error::Error, vec::Vec, fs::File}; | ^^^^^ @@ -17,7 +17,7 @@ LL | use std::{error::Error, vec::Vec, fs::File}; = help: consider importing the item from `core` error: used import from `std` instead of `alloc` - --> tests/ui/std_instead_of_core_unfixable.rs:13:34 + --> tests/ui/std_instead_of_core_unfixable.rs:11:34 | LL | use std::{error::Error, vec::Vec, fs::File}; | ^^^ @@ -27,7 +27,7 @@ LL | use std::{error::Error, vec::Vec, fs::File}; = help: to override `-D warnings` add `#[allow(clippy::std_instead_of_alloc)]` error: used import from `std` instead of `alloc` - --> tests/ui/std_instead_of_core_unfixable.rs:21:17 + --> tests/ui/std_instead_of_core_unfixable.rs:19:17 | LL | borrow::Cow, | ^^^ @@ -35,7 +35,7 @@ LL | borrow::Cow, = help: consider importing the item from `alloc` error: used import from `std` instead of `alloc` - --> tests/ui/std_instead_of_core_unfixable.rs:23:22 + --> tests/ui/std_instead_of_core_unfixable.rs:21:22 | LL | collections::BTreeSet, | ^^^^^^^^ diff --git a/tests/ui/string_lit_as_bytes.fixed b/tests/ui/string_lit_as_bytes.fixed index 2a86dffbc7627..a913951961ba8 100644 --- a/tests/ui/string_lit_as_bytes.fixed +++ b/tests/ui/string_lit_as_bytes.fixed @@ -1,7 +1,7 @@ //@aux-build:macro_rules.rs -#![allow(clippy::needless_raw_string_hashes, dead_code, unused_variables)] #![warn(clippy::string_lit_as_bytes)] +#![expect(clippy::needless_raw_string_hashes)] #[macro_use] extern crate macro_rules; diff --git a/tests/ui/string_lit_as_bytes.rs b/tests/ui/string_lit_as_bytes.rs index 785d8f1e0f6ba..2e7f47dfcf651 100644 --- a/tests/ui/string_lit_as_bytes.rs +++ b/tests/ui/string_lit_as_bytes.rs @@ -1,7 +1,7 @@ //@aux-build:macro_rules.rs -#![allow(clippy::needless_raw_string_hashes, dead_code, unused_variables)] #![warn(clippy::string_lit_as_bytes)] +#![expect(clippy::needless_raw_string_hashes)] #[macro_use] extern crate macro_rules; diff --git a/tests/ui/string_lit_chars_any.fixed b/tests/ui/string_lit_chars_any.fixed index cf05a2c2e8356..e1dd36df5ec6c 100644 --- a/tests/ui/string_lit_chars_any.fixed +++ b/tests/ui/string_lit_chars_any.fixed @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::string_lit_chars_any)] +#![expect(clippy::eq_op, clippy::no_effect)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/string_lit_chars_any.rs b/tests/ui/string_lit_chars_any.rs index 22cfb784ed7d0..43197a438fa2b 100644 --- a/tests/ui/string_lit_chars_any.rs +++ b/tests/ui/string_lit_chars_any.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::string_lit_chars_any)] +#![expect(clippy::eq_op, clippy::no_effect)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/string_slice.rs b/tests/ui/string_slice.rs index 0acc48c1f4121..b67d84bbea897 100644 --- a/tests/ui/string_slice.rs +++ b/tests/ui/string_slice.rs @@ -1,5 +1,5 @@ #![warn(clippy::string_slice)] -#![allow(clippy::no_effect)] +#![expect(clippy::no_effect)] use std::borrow::Cow; diff --git a/tests/ui/strlen_on_c_strings.fixed b/tests/ui/strlen_on_c_strings.fixed index 6604da70874d9..3f88a7373d152 100644 --- a/tests/ui/strlen_on_c_strings.fixed +++ b/tests/ui/strlen_on_c_strings.fixed @@ -1,5 +1,5 @@ #![warn(clippy::strlen_on_c_strings)] -#![allow(clippy::manual_c_str_literals, clippy::boxed_local)] +#![expect(clippy::boxed_local, clippy::manual_c_str_literals)] use libc::strlen; use std::ffi::{CStr, CString}; diff --git a/tests/ui/strlen_on_c_strings.rs b/tests/ui/strlen_on_c_strings.rs index 11fbdf5850643..e20d985d64653 100644 --- a/tests/ui/strlen_on_c_strings.rs +++ b/tests/ui/strlen_on_c_strings.rs @@ -1,5 +1,5 @@ #![warn(clippy::strlen_on_c_strings)] -#![allow(clippy::manual_c_str_literals, clippy::boxed_local)] +#![expect(clippy::boxed_local, clippy::manual_c_str_literals)] use libc::strlen; use std::ffi::{CStr, CString}; diff --git a/tests/ui/struct_fields.rs b/tests/ui/struct_fields.rs index e7ff2e6573b2a..be26e69ac7e47 100644 --- a/tests/ui/struct_fields.rs +++ b/tests/ui/struct_fields.rs @@ -1,7 +1,6 @@ //@aux-build:proc_macros.rs #![warn(clippy::struct_field_names)] -#![allow(unused)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/struct_fields.stderr b/tests/ui/struct_fields.stderr index a5ff1b1259074..254498ad2eebc 100644 --- a/tests/ui/struct_fields.stderr +++ b/tests/ui/struct_fields.stderr @@ -1,5 +1,5 @@ error: field name ends with the struct's name - --> tests/ui/struct_fields.rs:10:5 + --> tests/ui/struct_fields.rs:9:5 | LL | field_data1: u8, | ^^^^^^^^^^^^^^^ @@ -8,13 +8,13 @@ LL | field_data1: u8, = help: to override `-D warnings` add `#[allow(clippy::struct_field_names)]` error: field name starts with the struct's name - --> tests/ui/struct_fields.rs:20:5 + --> tests/ui/struct_fields.rs:19:5 | LL | data2_field: u8, | ^^^^^^^^^^^^^^^ error: all fields have the same postfix: `data` - --> tests/ui/struct_fields.rs:25:1 + --> tests/ui/struct_fields.rs:24:1 | LL | / struct StructData { LL | | @@ -27,7 +27,7 @@ LL | | } = help: remove the postfixes error: all fields have the same prefix: `data` - --> tests/ui/struct_fields.rs:32:1 + --> tests/ui/struct_fields.rs:31:1 | LL | / struct DataStruct { LL | | @@ -40,7 +40,7 @@ LL | | } = help: remove the prefixes error: all fields have the same prefix: `some_data` - --> tests/ui/struct_fields.rs:39:1 + --> tests/ui/struct_fields.rs:38:1 | LL | / struct DoublePrefix { LL | | @@ -53,7 +53,7 @@ LL | | } = help: remove the prefixes error: all fields have the same postfix: `some_data` - --> tests/ui/struct_fields.rs:46:1 + --> tests/ui/struct_fields.rs:45:1 | LL | / struct DoublePostfix { LL | | @@ -66,7 +66,7 @@ LL | | } = help: remove the postfixes error: all fields have the same postfix: `someData` - --> tests/ui/struct_fields.rs:54:1 + --> tests/ui/struct_fields.rs:53:1 | LL | / struct NotSnakeCase { LL | | @@ -79,7 +79,7 @@ LL | | } = help: remove the postfixes error: all fields have the same prefix: `someData` - --> tests/ui/struct_fields.rs:61:1 + --> tests/ui/struct_fields.rs:60:1 | LL | / struct NotSnakeCase2 { LL | | @@ -92,7 +92,7 @@ LL | | } = help: remove the prefixes error: all fields have the same prefix: `prefix` - --> tests/ui/struct_fields.rs:74:1 + --> tests/ui/struct_fields.rs:73:1 | LL | / struct NonCaps { LL | | @@ -105,7 +105,7 @@ LL | | } = help: remove the prefixes error: all fields have the same prefix: `_type` - --> tests/ui/struct_fields.rs:124:5 + --> tests/ui/struct_fields.rs:123:5 | LL | / struct DoLint { LL | | @@ -119,7 +119,7 @@ LL | | } = help: remove the prefixes error: all fields have the same prefix: `__type` - --> tests/ui/struct_fields.rs:132:5 + --> tests/ui/struct_fields.rs:131:5 | LL | / struct DoLint2 { LL | | @@ -133,7 +133,7 @@ LL | | } = help: remove the prefixes error: all fields have the same prefix: `___type` - --> tests/ui/struct_fields.rs:140:5 + --> tests/ui/struct_fields.rs:139:5 | LL | / struct DoLint3 { LL | | @@ -147,7 +147,7 @@ LL | | } = help: remove the prefixes error: all fields have the same postfix: `_` - --> tests/ui/struct_fields.rs:148:5 + --> tests/ui/struct_fields.rs:147:5 | LL | / struct DoLint4 { LL | | @@ -161,7 +161,7 @@ LL | | } = help: remove the postfixes error: all fields have the same postfix: `__` - --> tests/ui/struct_fields.rs:156:5 + --> tests/ui/struct_fields.rs:155:5 | LL | / struct DoLint5 { LL | | @@ -175,7 +175,7 @@ LL | | } = help: remove the postfixes error: all fields have the same postfix: `___` - --> tests/ui/struct_fields.rs:164:5 + --> tests/ui/struct_fields.rs:163:5 | LL | / struct DoLint6 { LL | | @@ -189,7 +189,7 @@ LL | | } = help: remove the postfixes error: all fields have the same postfix: `type` - --> tests/ui/struct_fields.rs:172:5 + --> tests/ui/struct_fields.rs:171:5 | LL | / struct DoLintToo { LL | | @@ -202,13 +202,13 @@ LL | | } = help: remove the postfixes error: field name starts with the struct's name - --> tests/ui/struct_fields.rs:210:5 + --> tests/ui/struct_fields.rs:209:5 | LL | proxy: i32, | ^^^^^^^^^^ error: all fields have the same prefix: `some` - --> tests/ui/struct_fields.rs:226:13 + --> tests/ui/struct_fields.rs:225:13 | LL | / struct MacroStruct { LL | | @@ -225,7 +225,7 @@ LL | mk_struct!(); = note: this error originates in the macro `mk_struct` (in Nightly builds, run with -Z macro-backtrace for more info) error: field name starts with the struct's name - --> tests/ui/struct_fields.rs:239:17 + --> tests/ui/struct_fields.rs:238:17 | LL | macrobaz_a: i32, | ^^^^^^^^^^^^^^^ @@ -236,7 +236,7 @@ LL | mk_struct2!(); = note: this error originates in the macro `mk_struct2` (in Nightly builds, run with -Z macro-backtrace for more info) error: field name starts with the struct's name - --> tests/ui/struct_fields.rs:251:17 + --> tests/ui/struct_fields.rs:250:17 | LL | $field: i32, | ^^^^^^^^^^^ @@ -247,7 +247,7 @@ LL | mk_struct_with_names!(Foo, foo); = note: this error originates in the macro `mk_struct_with_names` (in Nightly builds, run with -Z macro-backtrace for more info) error: all fields have the same prefix: `some` - --> tests/ui/struct_fields.rs:291:13 + --> tests/ui/struct_fields.rs:290:13 | LL | / struct $struct_name { LL | | @@ -264,31 +264,31 @@ LL | mk_struct_full_def!(PrefixData, some_data, some_meta, some_other); = note: this error originates in the macro `mk_struct_full_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: field name starts with the struct's name - --> tests/ui/struct_fields.rs:339:5 + --> tests/ui/struct_fields.rs:338:5 | LL | use_foo: bool, | ^^^^^^^^^^^^^ error: field name starts with the struct's name - --> tests/ui/struct_fields.rs:341:5 + --> tests/ui/struct_fields.rs:340:5 | LL | use_bar: bool, | ^^^^^^^^^^^^^ error: field name starts with the struct's name - --> tests/ui/struct_fields.rs:343:5 + --> tests/ui/struct_fields.rs:342:5 | LL | use_baz: bool, | ^^^^^^^^^^^^^ error: field name starts with the struct's name - --> tests/ui/struct_fields.rs:349:5 + --> tests/ui/struct_fields.rs:348:5 | LL | pub_struct_field_named_after_struct: bool, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: all fields have the same prefix: `field` - --> tests/ui/struct_fields.rs:354:1 + --> tests/ui/struct_fields.rs:353:1 | LL | / pub struct PubStructFieldPrefix { LL | | diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs index 9798d2049c624..f6a7a20f4848f 100644 --- a/tests/ui/suspicious_arithmetic_impl.rs +++ b/tests/ui/suspicious_arithmetic_impl.rs @@ -1,5 +1,5 @@ -#![allow(clippy::legacy_numeric_constants)] #![warn(clippy::suspicious_arithmetic_impl)] +#![expect(clippy::legacy_numeric_constants)] use std::ops::{ Add, AddAssign, BitAnd, BitOr, BitOrAssign, BitXor, Div, DivAssign, Mul, MulAssign, Rem, Shl, Shr, Sub, }; diff --git a/tests/ui/suspicious_command_arg_space.fixed b/tests/ui/suspicious_command_arg_space.fixed index 0a0d90f75e573..5eae8e80add32 100644 --- a/tests/ui/suspicious_command_arg_space.fixed +++ b/tests/ui/suspicious_command_arg_space.fixed @@ -1,4 +1,5 @@ -#![allow(clippy::zombie_processes)] +#![warn(clippy::suspicious_command_arg_space)] +#![expect(clippy::zombie_processes)] fn main() { // Things it should warn about: std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); diff --git a/tests/ui/suspicious_command_arg_space.rs b/tests/ui/suspicious_command_arg_space.rs index 78bdfbdf0cb6b..70547336773b8 100644 --- a/tests/ui/suspicious_command_arg_space.rs +++ b/tests/ui/suspicious_command_arg_space.rs @@ -1,4 +1,5 @@ -#![allow(clippy::zombie_processes)] +#![warn(clippy::suspicious_command_arg_space)] +#![expect(clippy::zombie_processes)] fn main() { // Things it should warn about: std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); diff --git a/tests/ui/suspicious_command_arg_space.stderr b/tests/ui/suspicious_command_arg_space.stderr index 8952a3ffe4b8b..0509a7854803c 100644 --- a/tests/ui/suspicious_command_arg_space.stderr +++ b/tests/ui/suspicious_command_arg_space.stderr @@ -1,5 +1,5 @@ error: single argument that looks like it should be multiple arguments - --> tests/ui/suspicious_command_arg_space.rs:4:44 + --> tests/ui/suspicious_command_arg_space.rs:5:44 | LL | std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); | ^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap | error: single argument that looks like it should be multiple arguments - --> tests/ui/suspicious_command_arg_space.rs:7:43 + --> tests/ui/suspicious_command_arg_space.rs:8:43 | LL | std::process::Command::new("cat").arg("--number file").spawn().unwrap(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_doc_comments.fixed b/tests/ui/suspicious_doc_comments.fixed index 3faa4b21ee414..c7d288095db35 100644 --- a/tests/ui/suspicious_doc_comments.fixed +++ b/tests/ui/suspicious_doc_comments.fixed @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::suspicious_doc_comments)] #![allow(clippy::empty_line_after_doc_comments)] diff --git a/tests/ui/suspicious_doc_comments.rs b/tests/ui/suspicious_doc_comments.rs index 4af6ed850c2bb..fdd93bae8f842 100644 --- a/tests/ui/suspicious_doc_comments.rs +++ b/tests/ui/suspicious_doc_comments.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::suspicious_doc_comments)] #![allow(clippy::empty_line_after_doc_comments)] diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index df04d08537c91..bd04f5d23f3f1 100644 --- a/tests/ui/suspicious_doc_comments.stderr +++ b/tests/ui/suspicious_doc_comments.stderr @@ -1,5 +1,5 @@ error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:6:1 + --> tests/ui/suspicious_doc_comments.rs:5:1 | LL | ///! Fake module documentation. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + //! Fake module documentation. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:11:5 + --> tests/ui/suspicious_doc_comments.rs:10:5 | LL | ///! This module contains useful functions. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + //! This module contains useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:24:5 + --> tests/ui/suspicious_doc_comments.rs:23:5 | LL | / /**! This module contains useful functions. LL | | */ @@ -38,7 +38,7 @@ LL + */ | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:39:5 + --> tests/ui/suspicious_doc_comments.rs:38:5 | LL | / ///! This module LL | | @@ -55,7 +55,7 @@ LL ~ //! useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:48:5 + --> tests/ui/suspicious_doc_comments.rs:47:5 | LL | / ///! a LL | | @@ -70,7 +70,7 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:57:5 + --> tests/ui/suspicious_doc_comments.rs:56:5 | LL | ///! a | ^^^^^^ @@ -82,7 +82,7 @@ LL + //! a | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:64:5 + --> tests/ui/suspicious_doc_comments.rs:63:5 | LL | / ///! a ... | @@ -98,7 +98,7 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:77:5 + --> tests/ui/suspicious_doc_comments.rs:76:5 | LL | ///! Very cool macro | ^^^^^^^^^^^^^^^^^^^^ @@ -110,7 +110,7 @@ LL + //! Very cool macro | error: this is an outer doc comment and does not apply to the parent module or crate - --> tests/ui/suspicious_doc_comments.rs:85:5 + --> tests/ui/suspicious_doc_comments.rs:84:5 | LL | ///! Huh. | ^^^^^^^^^ diff --git a/tests/ui/suspicious_doc_comments_unfixable.rs b/tests/ui/suspicious_doc_comments_unfixable.rs index 17c7cc15b170a..aa75c079692c7 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.rs +++ b/tests/ui/suspicious_doc_comments_unfixable.rs @@ -1,5 +1,5 @@ -#![allow(unused, clippy::empty_line_after_doc_comments)] #![warn(clippy::suspicious_doc_comments)] +#![expect(clippy::empty_line_after_doc_comments)] //@no-rustfix ///! a //~^ suspicious_doc_comments diff --git a/tests/ui/suspicious_else_formatting.rs b/tests/ui/suspicious_else_formatting.rs index 8574cf1c20a1a..71fd9aac5fda3 100644 --- a/tests/ui/suspicious_else_formatting.rs +++ b/tests/ui/suspicious_else_formatting.rs @@ -1,11 +1,11 @@ //@aux-build:proc_macro_suspicious_else_formatting.rs -#![warn(clippy::suspicious_else_formatting, clippy::possible_missing_else)] -#![allow( +#![warn(clippy::possible_missing_else, clippy::suspicious_else_formatting)] +#![expect( clippy::if_same_then_else, clippy::let_unit_value, - clippy::needless_ifs, - clippy::needless_else + clippy::needless_else, + clippy::needless_ifs )] extern crate proc_macro_suspicious_else_formatting; diff --git a/tests/ui/suspicious_map.rs b/tests/ui/suspicious_map.rs index 86e48e29bb9e5..46bb3da56785c 100644 --- a/tests/ui/suspicious_map.rs +++ b/tests/ui/suspicious_map.rs @@ -1,5 +1,5 @@ -#![allow(clippy::map_with_unused_argument_over_ranges)] #![warn(clippy::suspicious_map)] +#![expect(clippy::map_with_unused_argument_over_ranges)] fn main() { let _ = (0..3).map(|x| x + 2).count(); diff --git a/tests/ui/suspicious_operation_groupings.fixed b/tests/ui/suspicious_operation_groupings.fixed index fa680e537d305..4c4daf561cf34 100644 --- a/tests/ui/suspicious_operation_groupings.fixed +++ b/tests/ui/suspicious_operation_groupings.fixed @@ -1,7 +1,7 @@ //@compile-flags: -Zdeduplicate-diagnostics=yes #![warn(clippy::suspicious_operation_groupings)] -#![allow(dead_code, unused_parens, clippy::eq_op, clippy::manual_midpoint)] +#![expect(clippy::eq_op, clippy::manual_midpoint)] struct Vec3 { x: f64, diff --git a/tests/ui/suspicious_operation_groupings.rs b/tests/ui/suspicious_operation_groupings.rs index 4ffee640e8bda..f153972a3064d 100644 --- a/tests/ui/suspicious_operation_groupings.rs +++ b/tests/ui/suspicious_operation_groupings.rs @@ -1,7 +1,7 @@ //@compile-flags: -Zdeduplicate-diagnostics=yes #![warn(clippy::suspicious_operation_groupings)] -#![allow(dead_code, unused_parens, clippy::eq_op, clippy::manual_midpoint)] +#![expect(clippy::eq_op, clippy::manual_midpoint)] struct Vec3 { x: f64, diff --git a/tests/ui/suspicious_splitn.rs b/tests/ui/suspicious_splitn.rs index 535f62c6bedee..4eab716bd8820 100644 --- a/tests/ui/suspicious_splitn.rs +++ b/tests/ui/suspicious_splitn.rs @@ -1,5 +1,4 @@ #![warn(clippy::suspicious_splitn)] -#![allow(clippy::needless_splitn)] fn main() { let _ = "a,b,c".splitn(3, ','); diff --git a/tests/ui/suspicious_splitn.stderr b/tests/ui/suspicious_splitn.stderr index 910c905bc990e..6ae19520673e8 100644 --- a/tests/ui/suspicious_splitn.stderr +++ b/tests/ui/suspicious_splitn.stderr @@ -1,5 +1,5 @@ error: `splitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:10:13 + --> tests/ui/suspicious_splitn.rs:9:13 | LL | let _ = "a,b".splitn(0, ','); | ^^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | let _ = "a,b".splitn(0, ','); = help: to override `-D warnings` add `#[allow(clippy::suspicious_splitn)]` error: `rsplitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:13:13 + --> tests/ui/suspicious_splitn.rs:12:13 | LL | let _ = "a,b".rsplitn(0, ','); | ^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = "a,b".rsplitn(0, ','); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> tests/ui/suspicious_splitn.rs:16:13 + --> tests/ui/suspicious_splitn.rs:15:13 | LL | let _ = "a,b".splitn(1, ','); | ^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = "a,b".splitn(1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:19:13 + --> tests/ui/suspicious_splitn.rs:18:13 | LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn_mut` called with `0` splits - --> tests/ui/suspicious_splitn.rs:22:13 + --> tests/ui/suspicious_splitn.rs:21:13 | LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> tests/ui/suspicious_splitn.rs:25:13 + --> tests/ui/suspicious_splitn.rs:24:13 | LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `rsplitn_mut` called with `1` split - --> tests/ui/suspicious_splitn.rs:28:13 + --> tests/ui/suspicious_splitn.rs:27:13 | LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `splitn` called with `1` split - --> tests/ui/suspicious_splitn.rs:32:13 + --> tests/ui/suspicious_splitn.rs:31:13 | LL | let _ = "a,b".splitn(X + 1, ','); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | let _ = "a,b".splitn(X + 1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> tests/ui/suspicious_splitn.rs:35:13 + --> tests/ui/suspicious_splitn.rs:34:13 | LL | let _ = "a,b".splitn(X, ','); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_to_owned.1.fixed b/tests/ui/suspicious_to_owned.1.fixed index 6fd536a38ed1b..0b025e6188940 100644 --- a/tests/ui/suspicious_to_owned.1.fixed +++ b/tests/ui/suspicious_to_owned.1.fixed @@ -1,6 +1,5 @@ -#![warn(clippy::suspicious_to_owned)] -#![warn(clippy::implicit_clone)] -#![allow(clippy::redundant_clone)] +#![warn(clippy::implicit_clone, clippy::suspicious_to_owned)] +#![expect(clippy::redundant_clone)] use std::borrow::Cow; use std::ffi::{CStr, c_char}; diff --git a/tests/ui/suspicious_to_owned.2.fixed b/tests/ui/suspicious_to_owned.2.fixed index 841adf8ea274e..203a6368d7986 100644 --- a/tests/ui/suspicious_to_owned.2.fixed +++ b/tests/ui/suspicious_to_owned.2.fixed @@ -1,6 +1,5 @@ -#![warn(clippy::suspicious_to_owned)] -#![warn(clippy::implicit_clone)] -#![allow(clippy::redundant_clone)] +#![warn(clippy::implicit_clone, clippy::suspicious_to_owned)] +#![expect(clippy::redundant_clone)] use std::borrow::Cow; use std::ffi::{CStr, c_char}; diff --git a/tests/ui/suspicious_to_owned.rs b/tests/ui/suspicious_to_owned.rs index f59b3fd6ed0c0..c843ff6514b60 100644 --- a/tests/ui/suspicious_to_owned.rs +++ b/tests/ui/suspicious_to_owned.rs @@ -1,6 +1,5 @@ -#![warn(clippy::suspicious_to_owned)] -#![warn(clippy::implicit_clone)] -#![allow(clippy::redundant_clone)] +#![warn(clippy::implicit_clone, clippy::suspicious_to_owned)] +#![expect(clippy::redundant_clone)] use std::borrow::Cow; use std::ffi::{CStr, c_char}; diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index 5fda1ed1cc9c9..ae6cbfeb94ddb 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -1,5 +1,5 @@ error: this `to_owned` call clones the `Cow<'_, str>` itself and does not cause its contents to become owned - --> tests/ui/suspicious_to_owned.rs:16:13 + --> tests/ui/suspicious_to_owned.rs:15:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL + let _ = cow.clone(); | error: this `to_owned` call clones the `Cow<'_, [char; 3]>` itself and does not cause its contents to become owned - --> tests/ui/suspicious_to_owned.rs:28:13 + --> tests/ui/suspicious_to_owned.rs:27:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL + let _ = cow.clone(); | error: this `to_owned` call clones the `Cow<'_, Vec>` itself and does not cause its contents to become owned - --> tests/ui/suspicious_to_owned.rs:40:13 + --> tests/ui/suspicious_to_owned.rs:39:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + let _ = cow.clone(); | error: this `to_owned` call clones the `Cow<'_, str>` itself and does not cause its contents to become owned - --> tests/ui/suspicious_to_owned.rs:52:13 + --> tests/ui/suspicious_to_owned.rs:51:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL + let _ = cow.clone(); | error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type - --> tests/ui/suspicious_to_owned.rs:68:13 + --> tests/ui/suspicious_to_owned.rs:67:13 | LL | let _ = String::from(moo).to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::from(moo).clone()` @@ -74,7 +74,7 @@ LL | let _ = String::from(moo).to_owned(); = help: to override `-D warnings` add `#[allow(clippy::implicit_clone)]` error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> tests/ui/suspicious_to_owned.rs:71:13 + --> tests/ui/suspicious_to_owned.rs:70:13 | LL | let _ = moos_vec.to_owned(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `moos_vec.clone()` diff --git a/tests/ui/suspicious_unary_op_formatting.rs b/tests/ui/suspicious_unary_op_formatting.rs index 19f8b231925b7..7a5d710c14599 100644 --- a/tests/ui/suspicious_unary_op_formatting.rs +++ b/tests/ui/suspicious_unary_op_formatting.rs @@ -1,5 +1,5 @@ #![warn(clippy::suspicious_unary_op_formatting)] -#![allow(clippy::needless_ifs)] +#![expect(clippy::needless_ifs)] #[rustfmt::skip] fn main() { diff --git a/tests/ui/suspicious_xor_used_as_pow.rs b/tests/ui/suspicious_xor_used_as_pow.rs index 40a8d8c366bac..55ca85480b551 100644 --- a/tests/ui/suspicious_xor_used_as_pow.rs +++ b/tests/ui/suspicious_xor_used_as_pow.rs @@ -1,6 +1,5 @@ -#![allow(unused)] #![warn(clippy::suspicious_xor_used_as_pow)] -#![allow(clippy::eq_op)] +#![expect(clippy::eq_op)] //@no-rustfix macro_rules! macro_test { () => { diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index efeafdb94acb8..2b6570bb0adfc 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -1,5 +1,5 @@ error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:21:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:20:13 | LL | let _ = 2 ^ 5; | ^^^^^ @@ -13,7 +13,7 @@ LL + let _ = 2.pow(5); | error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:24:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:23:13 | LL | let _ = 2i32 ^ 9i32; | ^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _ = 2i32.pow(9i32); | error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:27:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:26:13 | LL | let _ = 2i32 ^ 2i32; | ^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + let _ = 2i32.pow(2i32); | error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:30:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:29:13 | LL | let _ = 50i32 ^ 3i32; | ^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + let _ = 50i32.pow(3i32); | error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:33:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:32:13 | LL | let _ = 5i32 ^ 8i32; | ^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let _ = 5i32.pow(8i32); | error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:36:13 + --> tests/ui/suspicious_xor_used_as_pow.rs:35:13 | LL | let _ = 2i32 ^ 32i32; | ^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + let _ = 2i32.pow(32i32); | error: `^` is not the exponentiation operator - --> tests/ui/suspicious_xor_used_as_pow.rs:13:9 + --> tests/ui/suspicious_xor_used_as_pow.rs:12:9 | LL | 1 ^ 2 // should warn even if inside macro | ^^^^^ diff --git a/tests/ui/swap.fixed b/tests/ui/swap.fixed index 0d968e96ff794..98f2d0c746030 100644 --- a/tests/ui/swap.fixed +++ b/tests/ui/swap.fixed @@ -1,12 +1,11 @@ //@aux-build: macro_rules.rs -#![allow( +#![warn(clippy::almost_swapped, clippy::manual_swap)] +#![expect( clippy::disallowed_names, - clippy::no_effect, - clippy::redundant_clone, clippy::let_and_return, - clippy::useless_vec, - clippy::redundant_locals + clippy::redundant_locals, + clippy::useless_vec )] struct Foo(u32); diff --git a/tests/ui/swap.rs b/tests/ui/swap.rs index c78c320332fbc..a37753a007941 100644 --- a/tests/ui/swap.rs +++ b/tests/ui/swap.rs @@ -1,12 +1,11 @@ //@aux-build: macro_rules.rs -#![allow( +#![warn(clippy::almost_swapped, clippy::manual_swap)] +#![expect( clippy::disallowed_names, - clippy::no_effect, - clippy::redundant_clone, clippy::let_and_return, - clippy::useless_vec, - clippy::redundant_locals + clippy::redundant_locals, + clippy::useless_vec )] struct Foo(u32); diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr index e730be40e3492..1fd1737d7aafd 100644 --- a/tests/ui/swap.stderr +++ b/tests/ui/swap.stderr @@ -1,5 +1,5 @@ error: this looks like you are swapping `bar.a` and `bar.b` manually - --> tests/ui/swap.rs:23:5 + --> tests/ui/swap.rs:22:5 | LL | / let temp = bar.a; LL | | @@ -12,7 +12,7 @@ LL | | bar.b = temp; = help: to override `-D warnings` add `#[allow(clippy::manual_swap)]` error: this looks like you are swapping elements of `foo` manually - --> tests/ui/swap.rs:36:5 + --> tests/ui/swap.rs:35:5 | LL | / let temp = foo[0]; LL | | @@ -21,7 +21,7 @@ LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping elements of `foo` manually - --> tests/ui/swap.rs:46:5 + --> tests/ui/swap.rs:45:5 | LL | / let temp = foo[0]; LL | | @@ -30,7 +30,7 @@ LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping elements of `foo` manually - --> tests/ui/swap.rs:66:5 + --> tests/ui/swap.rs:65:5 | LL | / let temp = foo[0]; LL | | @@ -39,7 +39,7 @@ LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping `a` and `b` manually - --> tests/ui/swap.rs:78:5 + --> tests/ui/swap.rs:77:5 | LL | / a ^= b; LL | | @@ -48,7 +48,7 @@ LL | | a ^= b; | |___________^ help: try: `std::mem::swap(&mut a, &mut b);` error: this looks like you are swapping `bar.a` and `bar.b` manually - --> tests/ui/swap.rs:87:5 + --> tests/ui/swap.rs:86:5 | LL | / bar.a ^= bar.b; LL | | @@ -57,7 +57,7 @@ LL | | bar.a ^= bar.b; | |___________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b);` error: this looks like you are swapping elements of `foo` manually - --> tests/ui/swap.rs:96:5 + --> tests/ui/swap.rs:95:5 | LL | / foo[0] ^= foo[1]; LL | | @@ -66,7 +66,7 @@ LL | | foo[0] ^= foo[1]; | |_____________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping `foo[0][1]` and `bar[1][0]` manually - --> tests/ui/swap.rs:126:5 + --> tests/ui/swap.rs:125:5 | LL | / let temp = foo[0][1]; LL | | @@ -77,7 +77,7 @@ LL | | bar[1][0] = temp; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `a` and `b` manually - --> tests/ui/swap.rs:142:7 + --> tests/ui/swap.rs:141:7 | LL | ; let t = a; | _______^ @@ -89,7 +89,7 @@ LL | | b = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `c.0` and `a` manually - --> tests/ui/swap.rs:153:7 + --> tests/ui/swap.rs:152:7 | LL | ; let t = c.0; | _______^ @@ -101,7 +101,7 @@ LL | | a = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `b` and `a` manually - --> tests/ui/swap.rs:183:5 + --> tests/ui/swap.rs:182:5 | LL | / let t = b; LL | | @@ -112,7 +112,7 @@ LL | | a = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> tests/ui/swap.rs:138:5 + --> tests/ui/swap.rs:137:5 | LL | / a = b; LL | | @@ -120,10 +120,11 @@ LL | | b = a; | |_________^ help: try: `std::mem::swap(&mut a, &mut b)` | = note: or maybe you should use `std::mem::replace`? - = note: `#[deny(clippy::almost_swapped)]` on by default + = note: `-D clippy::almost-swapped` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::almost_swapped)]` error: this looks like you are trying to swap `c.0` and `a` - --> tests/ui/swap.rs:149:5 + --> tests/ui/swap.rs:148:5 | LL | / c.0 = a; LL | | @@ -133,7 +134,7 @@ LL | | a = c.0; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> tests/ui/swap.rs:158:5 + --> tests/ui/swap.rs:157:5 | LL | / let a = b; LL | | @@ -143,7 +144,7 @@ LL | | let b = a; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `d` and `c` - --> tests/ui/swap.rs:164:5 + --> tests/ui/swap.rs:163:5 | LL | / d = c; LL | | @@ -153,7 +154,7 @@ LL | | c = d; = note: or maybe you should use `std::mem::replace`? error: this looks like you are trying to swap `a` and `b` - --> tests/ui/swap.rs:169:5 + --> tests/ui/swap.rs:168:5 | LL | / let a = b; LL | | @@ -163,7 +164,7 @@ LL | | b = a; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `s.0.x` and `s.0.y` manually - --> tests/ui/swap.rs:219:5 + --> tests/ui/swap.rs:218:5 | LL | / let t = s.0.x; LL | | @@ -174,7 +175,7 @@ LL | | s.0.y = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping elements of `test_slice!(foo)` manually - --> tests/ui/swap.rs:253:5 + --> tests/ui/swap.rs:252:5 | LL | / let temp = test_slice!(foo)[0]; LL | | From 85f9ced12285552bd8cc813ff268fe79afcf2991 Mon Sep 17 00:00:00 2001 From: Urgau <3616612+Urgau@users.noreply.github.com> Date: Thu, 9 Jul 2026 19:45:24 +0200 Subject: [PATCH 18/63] Enable community reviews feature in triagebot --- triagebot.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index f98831b42bfc2..8da713e7eac54 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -117,3 +117,9 @@ users_on_vacation = [ "@samueltardieu", "@ada4a", ] + +# Require community reviews before automatic assignment +# Documentation at: https://forge.rust-lang.org/triagebot/pr-assignment.html#community-reviews +[assign.community_reviews] +minimum_approvals = 2 +label = "S-waiting-on-community-reviews" From 14f42a55e2cec89c6e6dfb5cbfda600485760e51 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 9 Jul 2026 20:17:57 +0200 Subject: [PATCH 19/63] Merge commit '09382ed3c34e091d7705f96964e303b59978533c' into clippy-subtree-update --- CHANGELOG.md | 2 + Cargo.toml | 4 +- book/src/development/adding_lints.md | 4 +- book/src/lint_configuration.md | 1 + clippy_config/Cargo.toml | 4 +- clippy_config/src/conf.rs | 1 + clippy_dev/Cargo.toml | 2 +- clippy_dev/src/edit_lints.rs | 45 +- clippy_dev/src/fmt.rs | 19 +- clippy_dev/src/generate.rs | 50 +- clippy_dev/src/lib.rs | 2 +- clippy_dev/src/parse.rs | 228 ++++-- clippy_dev/src/utils.rs | 189 +++-- clippy_lints/Cargo.toml | 4 +- clippy_lints/src/bit_width.rs | 191 +++++ .../src/cargo/multiple_crate_versions.rs | 2 +- clippy_lints/src/casts/borrow_as_ptr.rs | 3 +- clippy_lints/src/casts/cast_possible_wrap.rs | 4 +- clippy_lints/src/casts/cast_sign_loss.rs | 4 +- clippy_lints/src/casts/ptr_as_ptr.rs | 2 +- clippy_lints/src/casts/utils.rs | 2 +- clippy_lints/src/declared_lints.rs | 2 + clippy_lints/src/dereference.rs | 44 +- clippy_lints/src/doc/mod.rs | 18 +- clippy_lints/src/from_over_into.rs | 5 +- clippy_lints/src/indexing_slicing.rs | 2 +- clippy_lints/src/len_without_is_empty.rs | 11 +- clippy_lints/src/len_zero.rs | 29 +- clippy_lints/src/lib.rs | 12 +- .../src/loops/explicit_counter_loop.rs | 2 +- clippy_lints/src/loops/infinite_loop.rs | 2 +- clippy_lints/src/loops/manual_memcpy.rs | 8 +- clippy_lints/src/loops/manual_slice_fill.rs | 3 +- clippy_lints/src/loops/needless_range_loop.rs | 10 +- clippy_lints/src/manual_is_ascii_check.rs | 3 +- clippy_lints/src/matches/mod.rs | 8 +- .../src/methods/chunks_exact_to_as_chunks.rs | 51 +- clippy_lints/src/methods/filter_map_next.rs | 55 +- clippy_lints/src/methods/iter_next_slice.rs | 3 +- .../src/methods/manual_c_str_literals.rs | 49 +- .../src/methods/manual_is_variant_and.rs | 22 +- .../map_with_unused_argument_over_ranges.rs | 6 +- clippy_lints/src/methods/mod.rs | 4 +- .../src/methods/ptr_offset_by_literal.rs | 12 +- .../src/methods/ptr_offset_with_cast.rs | 14 +- .../src/methods/unnecessary_to_owned.rs | 22 +- .../methods/unnecessary_unwrap_unchecked.rs | 14 +- .../src/missing_asserts_for_indexing.rs | 6 +- clippy_lints/src/missing_const_for_fn.rs | 3 +- clippy_lints/src/missing_trait_methods.rs | 17 +- clippy_lints/src/mut_mut.rs | 203 ++--- clippy_lints/src/needless_bool.rs | 56 +- .../src/needless_borrows_for_generic_args.rs | 3 +- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/no_effect.rs | 9 +- clippy_lints/src/operators/bit_mask.rs | 387 +++++---- clippy_lints/src/ranges.rs | 10 +- clippy_lints/src/redundant_else.rs | 243 +++--- clippy_lints/src/single_range_in_vec_init.rs | 40 +- clippy_lints/src/strings.rs | 97 +-- clippy_lints/src/strlen_on_c_strings.rs | 12 +- .../src/suspicious_operation_groupings.rs | 37 +- .../src/suspicious_xor_used_as_pow.rs | 27 +- .../missing_transmute_annotations.rs | 11 +- clippy_lints/src/tuple_array_conversions.rs | 415 ++++++---- clippy_lints/src/unicode.rs | 56 +- clippy_lints/src/uninhabited_references.rs | 46 +- clippy_lints/src/vec_init_then_push.rs | 1 + clippy_lints_internal/Cargo.toml | 2 +- clippy_lints_internal/src/lib.rs | 22 +- clippy_test_deps/Cargo.lock | 4 +- clippy_test_deps/Cargo.toml | 2 +- clippy_utils/Cargo.toml | 4 +- clippy_utils/README.md | 2 +- clippy_utils/src/ast_utils/mod.rs | 15 +- clippy_utils/src/consts.rs | 10 +- clippy_utils/src/higher.rs | 175 +++-- clippy_utils/src/lib.rs | 66 +- clippy_utils/src/msrvs.rs | 24 +- clippy_utils/src/qualify_min_const_fn.rs | 11 +- clippy_utils/src/sugg.rs | 37 +- clippy_utils/src/sym.rs | 1 + clippy_utils/src/ty/mod.rs | 58 +- clippy_utils/src/visitors.rs | 214 +++-- declare_clippy_lint/Cargo.toml | 2 +- lintcheck/Cargo.toml | 2 +- rust-toolchain.toml | 2 +- src/main.rs | 3 +- tests/integration.rs | 10 +- tests/ui/bad_bit_masks.rs | 125 +++ tests/ui/bad_bit_masks.stderr | 308 ++++++++ tests/ui/bit_masks.rs | 123 --- tests/ui/bit_masks.stderr | 112 --- tests/ui/borrow_as_ptr.fixed | 6 + tests/ui/borrow_as_ptr.rs | 6 + tests/ui/chunks_exact_to_as_chunks.rs | 44 +- tests/ui/chunks_exact_to_as_chunks.stderr | 48 +- .../chunks_exact_to_as_chunks_fixable.fixed | 34 + tests/ui/chunks_exact_to_as_chunks_fixable.rs | 34 + .../chunks_exact_to_as_chunks_fixable.stderr | 59 ++ tests/ui/crashes/ice-17352.rs | 6 + tests/ui/declare_interior_mutable_const.rs | 4 +- .../doc_comment_double_space_linebreaks.fixed | 8 +- .../doc_comment_double_space_linebreaks.rs | 8 +- ...doc_comment_double_space_linebreaks.stderr | 8 +- tests/ui/eta.fixed | 29 + tests/ui/eta.rs | 29 + tests/ui/eta.stderr | 8 +- ...xt_fixable.fixed => filter_map_next.fixed} | 21 + tests/ui/filter_map_next.rs | 27 + tests/ui/filter_map_next.stderr | 71 +- tests/ui/filter_map_next_fixable.rs | 22 - tests/ui/filter_map_next_fixable.stderr | 17 - tests/ui/ineffective_bit_masks.rs | 194 +++++ tests/ui/ineffective_bit_masks.stderr | 739 ++++++++++++++++++ tests/ui/infinite_loops.rs | 7 + tests/ui/infinite_loops.stderr | 64 +- tests/ui/inline_modules_cfg_test.rs | 17 + tests/ui/invisible_characters_unfixable.rs | 16 + .../ui/invisible_characters_unfixable.stderr | 36 + tests/ui/len_zero_unstable.fixed | 7 - tests/ui/len_zero_unstable.rs | 7 - tests/ui/len_zero_unstable.stderr | 11 - tests/ui/manual_bit_width.fixed | 59 ++ tests/ui/manual_bit_width.rs | 59 ++ tests/ui/manual_bit_width.stderr | 244 ++++++ .../manual_c_str_literals.edition2021.fixed | 6 + .../manual_c_str_literals.edition2021.stderr | 26 +- tests/ui/manual_c_str_literals.rs | 6 + tests/ui/manual_is_variant_and.fixed | 13 + tests/ui/manual_is_variant_and.rs | 13 + tests/ui/manual_is_variant_and.stderr | 16 +- tests/ui/match_same_arms_expect.rs | 18 + tests/ui/mismatched_bit_width_type.fixed | 79 ++ tests/ui/mismatched_bit_width_type.rs | 79 ++ tests/ui/mismatched_bit_width_type.stderr | 524 +++++++++++++ tests/ui/missing_trait_methods.rs | 27 + tests/ui/missing_trait_methods.stderr | 40 +- tests/ui/mut_mut.stderr | 68 +- tests/ui/mut_mut_unfixable.stderr | 58 +- tests/ui/needless_bool/fixable.fixed | 18 + tests/ui/needless_bool/fixable.rs | 18 + tests/ui/needless_bool/fixable.stderr | 28 +- tests/ui/needless_borrow.fixed | 12 +- tests/ui/needless_borrow.rs | 12 +- tests/ui/needless_borrow.stderr | 56 +- tests/ui/needless_borrow_pat.fixed | 5 +- tests/ui/needless_borrow_pat.rs | 5 +- tests/ui/needless_borrowed_ref.fixed | 4 +- tests/ui/needless_borrowed_ref.rs | 4 +- tests/ui/needless_borrowed_ref.stderr | 34 +- .../needless_borrows_for_generic_args.fixed | 7 +- tests/ui/needless_borrows_for_generic_args.rs | 7 +- .../needless_borrows_for_generic_args.stderr | 10 +- tests/ui/needless_character_iteration.fixed | 3 +- tests/ui/needless_character_iteration.rs | 3 +- tests/ui/needless_character_iteration.stderr | 18 +- tests/ui/needless_collect.fixed | 16 +- tests/ui/needless_collect.rs | 16 +- tests/ui/needless_collect.stderr | 52 +- tests/ui/needless_collect_indirect.fixed | 9 +- tests/ui/needless_collect_indirect.rs | 9 +- tests/ui/needless_collect_indirect.stderr | 32 +- tests/ui/needless_continue.rs | 2 +- tests/ui/needless_else.fixed | 2 - tests/ui/needless_else.rs | 2 - tests/ui/needless_else.stderr | 2 +- tests/ui/needless_for_each_fixable.fixed | 3 +- tests/ui/needless_for_each_fixable.rs | 3 +- tests/ui/needless_for_each_fixable.stderr | 24 +- tests/ui/needless_for_each_unfixable.rs | 2 +- tests/ui/needless_ifs.fixed | 18 +- tests/ui/needless_ifs.rs | 16 +- tests/ui/needless_ifs.stderr | 22 +- tests/ui/needless_late_init.fixed | 12 +- tests/ui/needless_late_init.rs | 12 +- tests/ui/needless_late_init.stderr | 50 +- tests/ui/needless_lifetimes.fixed | 17 +- tests/ui/needless_lifetimes.rs | 17 +- tests/ui/needless_lifetimes.stderr | 84 +- tests/ui/needless_match.fixed | 4 +- tests/ui/needless_match.rs | 4 +- tests/ui/needless_match.stderr | 30 +- tests/ui/needless_maybe_sized.fixed | 2 +- tests/ui/needless_maybe_sized.rs | 2 +- tests/ui/needless_option_as_deref.fixed | 3 +- tests/ui/needless_option_as_deref.rs | 3 +- tests/ui/needless_option_as_deref.stderr | 6 +- .../needless_parens_on_range_literals.fixed | 2 +- tests/ui/needless_parens_on_range_literals.rs | 2 +- tests/ui/needless_pass_by_ref_mut.rs | 8 +- tests/ui/needless_pass_by_ref_mut.stderr | 68 +- tests/ui/needless_pass_by_ref_mut2.fixed | 1 - tests/ui/needless_pass_by_ref_mut2.rs | 1 - tests/ui/needless_pass_by_ref_mut2.stderr | 6 +- tests/ui/needless_pass_by_value.rs | 10 +- tests/ui/needless_pass_by_value.stderr | 62 +- tests/ui/needless_pub_self.fixed | 1 - tests/ui/needless_pub_self.rs | 1 - tests/ui/needless_pub_self.stderr | 6 +- tests/ui/needless_question_mark.fixed | 8 +- tests/ui/needless_question_mark.rs | 8 +- tests/ui/needless_question_mark.stderr | 30 +- tests/ui/needless_range_loop.rs | 7 +- tests/ui/needless_range_loop.stderr | 32 +- tests/ui/needless_range_loop2.rs | 2 +- tests/ui/needless_raw_string.fixed | 2 +- tests/ui/needless_raw_string.rs | 2 +- tests/ui/needless_raw_string_hashes.fixed | 2 +- tests/ui/needless_raw_string_hashes.rs | 2 +- tests/ui/needless_return.fixed | 11 +- tests/ui/needless_return.rs | 11 +- tests/ui/needless_return.stderr | 126 +-- .../needless_return_with_question_mark.fixed | 9 +- .../ui/needless_return_with_question_mark.rs | 9 +- .../needless_return_with_question_mark.stderr | 10 +- tests/ui/needless_splitn.fixed | 3 +- tests/ui/needless_splitn.rs | 3 +- tests/ui/needless_splitn.stderr | 26 +- tests/ui/needless_type_cast.fixed | 2 +- tests/ui/needless_type_cast.rs | 2 +- tests/ui/needless_update.rs | 2 +- tests/ui/neg_multiply.fixed | 4 +- tests/ui/neg_multiply.rs | 4 +- tests/ui/new_ret_no_self.rs | 1 - tests/ui/new_ret_no_self.stderr | 24 +- tests/ui/new_without_default.fixed | 183 +++-- tests/ui/new_without_default.rs | 27 +- tests/ui/new_without_default.stderr | 92 ++- tests/ui/no_effect.rs | 2 +- tests/ui/no_effect_return.rs | 3 +- tests/ui/no_effect_return.stderr | 18 +- tests/ui/no_mangle_with_rust_abi.rs | 1 - tests/ui/no_mangle_with_rust_abi.stderr | 12 +- tests/ui/no_mangle_with_rust_abi_2021.rs | 1 - tests/ui/no_mangle_with_rust_abi_2021.stderr | 10 +- tests/ui/non_ascii_literal_unfixable.rs | 16 + tests/ui/non_ascii_literal_unfixable.stderr | 36 + tests/ui/non_canonical_clone_impl.fixed | 2 +- tests/ui/non_canonical_clone_impl.rs | 2 +- tests/ui/non_expressive_names.rs | 3 +- tests/ui/non_expressive_names.stderr | 12 +- tests/ui/non_minimal_cfg.fixed | 3 +- tests/ui/non_minimal_cfg.rs | 3 +- tests/ui/non_minimal_cfg.stderr | 8 +- tests/ui/non_minimal_cfg2.rs | 6 +- .../non_std_lazy_static_fixable.fixed | 2 +- .../non_std_lazy_static_fixable.rs | 2 +- .../non_std_lazy_static_unfixable.rs | 2 +- tests/ui/nonminimal_bool.rs | 5 +- tests/ui/nonminimal_bool.stderr | 62 +- tests/ui/nonminimal_bool_methods.fixed | 2 +- tests/ui/nonminimal_bool_methods.rs | 2 +- tests/ui/obfuscated_if_else.fixed | 2 +- tests/ui/obfuscated_if_else.rs | 2 +- tests/ui/ok_expect.fixed | 3 +- tests/ui/ok_expect.rs | 3 +- tests/ui/ok_expect.stderr | 16 +- tests/ui/only_used_in_recursion.rs | 3 +- tests/ui/only_used_in_recursion.stderr | 64 +- tests/ui/op_ref.fixed | 2 +- tests/ui/op_ref.rs | 2 +- tests/ui/open_options.rs | 1 - tests/ui/open_options.stderr | 16 +- tests/ui/option_as_ref_deref.fixed | 2 +- tests/ui/option_as_ref_deref.rs | 2 +- tests/ui/option_env_unwrap.rs | 1 - tests/ui/option_env_unwrap.stderr | 14 +- tests/ui/option_filter_map.fixed | 3 +- tests/ui/option_filter_map.rs | 3 +- tests/ui/option_filter_map.stderr | 16 +- tests/ui/option_if_let_else.fixed | 14 +- tests/ui/option_if_let_else.rs | 14 +- tests/ui/option_if_let_else.stderr | 58 +- tests/ui/option_map_unit_fn_unfixable.rs | 2 +- tests/ui/or_fun_call.fixed | 11 +- tests/ui/or_fun_call.rs | 11 +- tests/ui/or_fun_call.stderr | 98 +-- tests/ui/or_then_unwrap.fixed | 3 +- tests/ui/or_then_unwrap.rs | 3 +- tests/ui/or_then_unwrap.stderr | 8 +- tests/ui/out_of_bounds_indexing/issue-3102.rs | 2 +- tests/ui/out_of_bounds_indexing/simple.rs | 2 +- tests/ui/overly_complex_bool_expr.fixed | 2 +- tests/ui/overly_complex_bool_expr.rs | 2 +- tests/ui/panic_in_result_fn.rs | 2 +- tests/ui/panic_in_result_fn_assertions.rs | 2 +- .../ui/panic_in_result_fn_debug_assertions.rs | 2 +- tests/ui/panicking_macros.rs | 4 +- tests/ui/panicking_overflow_checks.rs | 2 +- tests/ui/partial_pub_fields.rs | 1 - tests/ui/partial_pub_fields.stderr | 8 +- tests/ui/partialeq_ne_impl.rs | 3 +- tests/ui/partialeq_ne_impl.stderr | 2 +- tests/ui/partialeq_to_none.fixed | 3 +- tests/ui/partialeq_to_none.rs | 3 +- tests/ui/partialeq_to_none.stderr | 30 +- tests/ui/pattern_type_mismatch/mutability.rs | 2 +- tests/ui/pattern_type_mismatch/syntax.rs | 2 +- tests/ui/patterns.fixed | 3 +- tests/ui/patterns.rs | 3 +- tests/ui/patterns.stderr | 6 +- tests/ui/permissions_set_readonly_false.rs | 1 - .../ui/permissions_set_readonly_false.stderr | 2 +- tests/ui/precedence.fixed | 9 +- tests/ui/precedence.rs | 9 +- tests/ui/precedence.stderr | 18 +- tests/ui/precedence_bits.fixed | 9 +- tests/ui/precedence_bits.rs | 9 +- tests/ui/precedence_bits.stderr | 8 +- tests/ui/print_in_format_impl.rs | 1 - tests/ui/print_in_format_impl.stderr | 14 +- tests/ui/print_literal.fixed | 2 +- tests/ui/print_literal.rs | 2 +- tests/ui/print_with_newline.fixed | 4 +- tests/ui/print_with_newline.rs | 4 +- tests/ui/print_with_newline.stderr | 18 +- tests/ui/println_empty_string.fixed | 3 +- tests/ui/println_empty_string.rs | 3 +- tests/ui/println_empty_string.stderr | 28 +- tests/ui/println_empty_string_unfixable.rs | 2 +- tests/ui/ptr_arg.rs | 8 - tests/ui/ptr_arg.stderr | 66 +- tests/ui/ptr_cast_constness.fixed | 7 +- tests/ui/ptr_cast_constness.rs | 7 +- tests/ui/ptr_cast_constness.stderr | 30 +- tests/ui/ptr_eq.fixed | 1 - tests/ui/ptr_eq.rs | 1 - tests/ui/ptr_eq.stderr | 12 +- tests/ui/ptr_offset_by_literal.fixed | 3 +- tests/ui/ptr_offset_by_literal.rs | 3 +- tests/ui/ptr_offset_by_literal.stderr | 24 +- tests/ui/ptr_offset_with_cast.fixed | 3 +- tests/ui/ptr_offset_with_cast.rs | 3 +- tests/ui/ptr_offset_with_cast.stderr | 16 +- tests/ui/pub_use.rs | 1 - tests/ui/pub_use.stderr | 2 +- tests/ui/pub_with_shorthand.fixed | 2 +- tests/ui/pub_with_shorthand.rs | 2 +- tests/ui/pub_without_shorthand.fixed | 2 +- tests/ui/pub_without_shorthand.rs | 2 +- tests/ui/question_mark.fixed | 8 +- tests/ui/question_mark.rs | 8 +- tests/ui/question_mark.stderr | 52 +- tests/ui/question_mark_used.rs | 2 - tests/ui/question_mark_used.stderr | 2 +- tests/ui/range.fixed | 4 +- tests/ui/range.rs | 4 +- tests/ui/range.stderr | 6 +- tests/ui/range_contains.fixed | 12 +- tests/ui/range_contains.rs | 12 +- tests/ui/range_plus_minus_one.fixed | 2 - tests/ui/range_plus_minus_one.rs | 2 - tests/ui/range_plus_minus_one.stderr | 28 +- tests/ui/range_unfixable.rs | 3 +- tests/ui/range_unfixable.stderr | 2 +- tests/ui/rc_clone_in_vec_init/arc.rs | 2 +- tests/ui/rc_clone_in_vec_init/rc.rs | 2 +- tests/ui/rc_clone_in_vec_init/weak.rs | 2 +- tests/ui/rc_mutex.rs | 2 +- tests/ui/read_line_without_trim.fixed | 1 - tests/ui/read_line_without_trim.rs | 1 - tests/ui/read_line_without_trim.stderr | 28 +- tests/ui/read_zero_byte_vec.rs | 6 +- tests/ui/read_zero_byte_vec.stderr | 30 +- tests/ui/recursive_format_impl.rs | 6 +- tests/ui/redundant_allocation.rs | 3 +- tests/ui/redundant_allocation.stderr | 40 +- tests/ui/redundant_allocation_fixable.fixed | 4 +- tests/ui/redundant_allocation_fixable.rs | 4 +- tests/ui/redundant_as_str.fixed | 2 +- tests/ui/redundant_as_str.rs | 2 +- tests/ui/redundant_async_block.fixed | 2 +- tests/ui/redundant_async_block.rs | 2 +- tests/ui/redundant_at_rest_pattern.fixed | 2 +- tests/ui/redundant_at_rest_pattern.rs | 2 +- tests/ui/redundant_clone.fixed | 2 +- tests/ui/redundant_clone.rs | 2 +- tests/ui/redundant_closure_call_fixable.fixed | 2 +- tests/ui/redundant_closure_call_fixable.rs | 2 +- tests/ui/redundant_closure_call_late.rs | 4 +- tests/ui/redundant_closure_call_late.stderr | 6 +- tests/ui/redundant_else.fixed | 544 ++++++++++--- tests/ui/redundant_else.rs | 577 +++++++++++--- tests/ui/redundant_else.stderr | 571 +++++++++++++- tests/ui/redundant_field_names.fixed | 2 +- tests/ui/redundant_field_names.rs | 2 +- tests/ui/redundant_guards.fixed | 3 +- tests/ui/redundant_guards.rs | 3 +- tests/ui/redundant_guards.stderr | 60 +- tests/ui/redundant_locals.rs | 2 +- ...edundant_pattern_matching_drop_order.fixed | 8 +- .../redundant_pattern_matching_drop_order.rs | 8 +- ...dundant_pattern_matching_drop_order.stderr | 44 +- ...dundant_pattern_matching_if_let_true.fixed | 2 +- .../redundant_pattern_matching_if_let_true.rs | 2 +- .../redundant_pattern_matching_ipaddr.fixed | 7 +- tests/ui/redundant_pattern_matching_ipaddr.rs | 7 +- .../redundant_pattern_matching_ipaddr.stderr | 40 +- .../redundant_pattern_matching_option.fixed | 11 +- tests/ui/redundant_pattern_matching_option.rs | 11 +- .../redundant_pattern_matching_option.stderr | 70 +- .../ui/redundant_pattern_matching_poll.fixed | 9 +- tests/ui/redundant_pattern_matching_poll.rs | 9 +- .../ui/redundant_pattern_matching_poll.stderr | 40 +- .../redundant_pattern_matching_result.fixed | 2 +- tests/ui/redundant_pattern_matching_result.rs | 2 +- tests/ui/redundant_pub_crate.fixed | 3 - tests/ui/redundant_pub_crate.rs | 3 - tests/ui/redundant_pub_crate.stderr | 36 +- tests/ui/redundant_slicing.fixed | 2 +- tests/ui/redundant_slicing.rs | 2 +- tests/ui/redundant_static_lifetimes.fixed | 2 +- tests/ui/redundant_static_lifetimes.rs | 2 +- tests/ui/redundant_test_prefix.fixed | 1 - tests/ui/redundant_test_prefix.rs | 1 - tests/ui/redundant_test_prefix.stderr | 38 +- ....rs => redundant_test_prefix_unfixable.rs} | 1 - ...=> redundant_test_prefix_unfixable.stderr} | 66 +- tests/ui/redundant_type_annotations.rs | 1 - tests/ui/redundant_type_annotations.stderr | 34 +- tests/ui/ref_as_ptr.fixed | 2 +- tests/ui/ref_as_ptr.rs | 2 +- tests/ui/ref_binding_to_reference.rs | 3 +- tests/ui/ref_binding_to_reference.stderr | 14 +- tests/ui/ref_option_ref.rs | 1 - tests/ui/ref_option_ref.stderr | 22 +- tests/ui/ref_patterns.rs | 1 - tests/ui/ref_patterns.stderr | 6 +- tests/ui/regex.rs | 10 +- tests/ui/regex.stderr | 64 +- tests/ui/repeat_vec_with_capacity.fixed | 1 - tests/ui/repeat_vec_with_capacity.rs | 1 - tests/ui/repeat_vec_with_capacity.stderr | 6 +- .../ui/rest_pat_in_fully_bound_structs.fixed | 2 +- tests/ui/rest_pat_in_fully_bound_structs.rs | 2 +- tests/ui/result_filter_map.fixed | 2 +- tests/ui/result_filter_map.rs | 2 +- tests/ui/result_large_err.rs | 2 +- tests/ui/result_map_unit_fn_unfixable.rs | 2 +- tests/ui/return_and_then.fixed | 2 +- tests/ui/return_and_then.rs | 2 +- tests/ui/reversed_empty_ranges_fixable.fixed | 2 +- tests/ui/reversed_empty_ranges_fixable.rs | 2 +- .../reversed_empty_ranges_loops_fixable.fixed | 2 +- .../ui/reversed_empty_ranges_loops_fixable.rs | 2 +- .../reversed_empty_ranges_loops_unfixable.rs | 2 +- tests/ui/same_functions_in_if_condition.rs | 7 +- .../ui/same_functions_in_if_condition.stderr | 19 +- tests/ui/same_name_method.rs | 2 +- tests/ui/search_is_some.rs | 3 +- tests/ui/search_is_some.stderr | 4 +- tests/ui/search_is_some_fixable_none.fixed | 3 +- tests/ui/search_is_some_fixable_none.rs | 3 +- tests/ui/search_is_some_fixable_none.stderr | 114 +-- tests/ui/search_is_some_fixable_some.fixed | 3 +- tests/ui/search_is_some_fixable_some.rs | 3 +- tests/ui/search_is_some_fixable_some.stderr | 98 +-- .../ui/seek_to_start_instead_of_rewind.fixed | 1 - tests/ui/seek_to_start_instead_of_rewind.rs | 1 - .../ui/seek_to_start_instead_of_rewind.stderr | 6 +- tests/ui/self_assignment.rs | 2 +- tests/ui/semicolon_if_nothing_returned.fixed | 8 +- tests/ui/semicolon_if_nothing_returned.rs | 8 +- tests/ui/semicolon_if_nothing_returned.stderr | 10 +- tests/ui/semicolon_inside_block.fixed | 11 +- tests/ui/semicolon_inside_block.rs | 11 +- tests/ui/semicolon_inside_block.stderr | 8 +- ...micolon_inside_block_stmt_expr_attrs.fixed | 2 +- .../semicolon_inside_block_stmt_expr_attrs.rs | 2 +- tests/ui/semicolon_outside_block.fixed | 11 +- tests/ui/semicolon_outside_block.rs | 11 +- tests/ui/semicolon_outside_block.stderr | 12 +- tests/ui/serde.rs | 1 - tests/ui/serde.stderr | 2 +- tests/ui/set_contains_or_insert.rs | 4 +- tests/ui/set_contains_or_insert.stderr | 30 +- tests/ui/shadow.rs | 9 +- tests/ui/shadow.stderr | 104 +-- tests/ui/short_circuit_statement.fixed | 1 - tests/ui/short_circuit_statement.rs | 1 - tests/ui/short_circuit_statement.stderr | 14 +- tests/ui/should_impl_trait/corner_cases.rs | 14 +- .../method_list_1.edition2015.stderr | 30 +- .../method_list_1.edition2021.stderr | 30 +- tests/ui/should_impl_trait/method_list_1.rs | 12 +- .../method_list_2.edition2015.stderr | 28 +- .../method_list_2.edition2021.stderr | 30 +- tests/ui/should_impl_trait/method_list_2.rs | 12 +- tests/ui/significant_drop_in_scrutinee.rs | 8 +- tests/ui/significant_drop_in_scrutinee.stderr | 62 +- tests/ui/similar_names.rs | 8 +- tests/ui/similar_names.stderr | 24 +- tests/ui/single_call_fn.rs | 1 - tests/ui/single_call_fn.stderr | 24 +- tests/ui/single_char_add_str.fixed | 1 - tests/ui/single_char_add_str.rs | 1 - tests/ui/single_char_add_str.stderr | 42 +- tests/ui/single_char_lifetime_names.rs | 1 - tests/ui/single_char_lifetime_names.stderr | 10 +- ...single_range_in_vec_init.new_range.1.fixed | 97 +++ ...single_range_in_vec_init.new_range.2.fixed | 97 +++ .../single_range_in_vec_init.new_range.stderr | 200 +++++ ...ingle_range_in_vec_init.old_range.1.fixed} | 6 + ...ingle_range_in_vec_init.old_range.2.fixed} | 6 + ...single_range_in_vec_init.old_range.stderr} | 26 +- tests/ui/single_range_in_vec_init.rs | 6 + tests/ui/strlen_on_c_strings.fixed | 24 +- tests/ui/strlen_on_c_strings.rs | 24 +- tests/ui/strlen_on_c_strings.stderr | 42 +- tests/ui/suspicious_operation_groupings.fixed | 4 - tests/ui/suspicious_operation_groupings.rs | 4 - .../ui/suspicious_operation_groupings.stderr | 62 +- tests/ui/tuple_array_conversions.rs | 2 + tests/ui/tuple_array_conversions.stderr | 36 +- tests/ui/unicode.fixed | 35 + tests/ui/unicode.rs | 35 + tests/ui/unicode.stderr | 14 +- tests/ui/unnecessary_operation.fixed | 19 + tests/ui/unnecessary_operation.rs | 21 + tests/ui/unnecessary_operation.stderr | 10 +- tests/ui/unnecessary_unwrap_unchecked.fixed | 69 ++ tests/ui/unnecessary_unwrap_unchecked.rs | 69 ++ tests/ui/vec_init_then_push.rs | 29 + triagebot.toml | 3 +- 525 files changed, 9751 insertions(+), 4413 deletions(-) create mode 100644 clippy_lints/src/bit_width.rs create mode 100644 tests/ui/bad_bit_masks.rs create mode 100644 tests/ui/bad_bit_masks.stderr delete mode 100644 tests/ui/bit_masks.rs delete mode 100644 tests/ui/bit_masks.stderr create mode 100644 tests/ui/chunks_exact_to_as_chunks_fixable.fixed create mode 100644 tests/ui/chunks_exact_to_as_chunks_fixable.rs create mode 100644 tests/ui/chunks_exact_to_as_chunks_fixable.stderr create mode 100644 tests/ui/crashes/ice-17352.rs rename tests/ui/{filter_map_next_fixable.fixed => filter_map_next.fixed} (53%) delete mode 100644 tests/ui/filter_map_next_fixable.rs delete mode 100644 tests/ui/filter_map_next_fixable.stderr create mode 100644 tests/ui/ineffective_bit_masks.rs create mode 100644 tests/ui/ineffective_bit_masks.stderr create mode 100644 tests/ui/inline_modules_cfg_test.rs create mode 100644 tests/ui/invisible_characters_unfixable.rs create mode 100644 tests/ui/invisible_characters_unfixable.stderr delete mode 100644 tests/ui/len_zero_unstable.fixed delete mode 100644 tests/ui/len_zero_unstable.rs delete mode 100644 tests/ui/len_zero_unstable.stderr create mode 100644 tests/ui/manual_bit_width.fixed create mode 100644 tests/ui/manual_bit_width.rs create mode 100644 tests/ui/manual_bit_width.stderr create mode 100644 tests/ui/match_same_arms_expect.rs create mode 100644 tests/ui/mismatched_bit_width_type.fixed create mode 100644 tests/ui/mismatched_bit_width_type.rs create mode 100644 tests/ui/mismatched_bit_width_type.stderr create mode 100644 tests/ui/non_ascii_literal_unfixable.rs create mode 100644 tests/ui/non_ascii_literal_unfixable.stderr rename tests/ui/{redundant_test_prefix_noautofix.rs => redundant_test_prefix_unfixable.rs} (99%) rename tests/ui/{redundant_test_prefix_noautofix.stderr => redundant_test_prefix_unfixable.stderr} (77%) create mode 100644 tests/ui/single_range_in_vec_init.new_range.1.fixed create mode 100644 tests/ui/single_range_in_vec_init.new_range.2.fixed create mode 100644 tests/ui/single_range_in_vec_init.new_range.stderr rename tests/ui/{single_range_in_vec_init.1.fixed => single_range_in_vec_init.old_range.1.fixed} (90%) rename tests/ui/{single_range_in_vec_init.2.fixed => single_range_in_vec_init.old_range.2.fixed} (89%) rename tests/ui/{single_range_in_vec_init.stderr => single_range_in_vec_init.old_range.stderr} (93%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 689d56d0fb7c6..b809638dfcf93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6979,6 +6979,7 @@ Released 2018-09-13 [`manual_assert`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert [`manual_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert_eq [`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn +[`manual_bit_width`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_bit_width [`manual_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits [`manual_c_str_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_c_str_literals [`manual_checked_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_checked_ops @@ -7071,6 +7072,7 @@ Released 2018-09-13 [`min_ident_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars [`min_max`]: https://rust-lang.github.io/rust-clippy/master/index.html#min_max [`misaligned_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#misaligned_transmute +[`mismatched_bit_width_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatched_bit_width_type [`mismatched_target_os`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatched_target_os [`mismatching_type_param_order`]: https://rust-lang.github.io/rust-clippy/master/index.html#mismatching_type_param_order [`misnamed_getters`]: https://rust-lang.github.io/rust-clippy/master/index.html#misnamed_getters diff --git a/Cargo.toml b/Cargo.toml index 06c1840a3da26..2831f0f5dc5e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.1.98" +version = "0.1.99" description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" @@ -40,7 +40,7 @@ serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0.122" walkdir = "2.3" filetime = "0.2.9" -itertools = "0.12" +itertools = "0.15" pulldown-cmark = { version = "0.11", default-features = false, features = ["html"] } askama = { version = "0.16.0", default-features = false, features = ["alloc", "config", "derive"] } diff --git a/book/src/development/adding_lints.md b/book/src/development/adding_lints.md index 474b8c6c474ef..f28985d375f64 100644 --- a/book/src/development/adding_lints.md +++ b/book/src/development/adding_lints.md @@ -447,8 +447,8 @@ Sometimes a lint makes suggestions that require a certain version of Rust. For example, the `manual_strip` lint suggests using `str::strip_prefix` and `str::strip_suffix` which is only available after Rust 1.45. In such cases, you need to ensure that the MSRV configured for the project is >= the MSRV of the -required Rust feature. If multiple features are required, just use the one with -a lower MSRV. +required Rust feature. If multiple features are used in a suggestion, choose a +MSRV that supports them all. First, add an MSRV alias for the required feature in [`clippy_utils::msrvs`]. This can be accessed later as `msrvs::STR_STRIP_PREFIX`, for example. diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 6c6ccd4747c1f..b3bef3b4666dc 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -957,6 +957,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`manual_hash_one`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one) * [`manual_is_ascii_check`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check) * [`manual_is_power_of_two`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_power_of_two) +* [`manual_is_variant_and`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_variant_and) * [`manual_isolate_lowest_one`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_isolate_lowest_one) * [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else) * [`manual_midpoint`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_midpoint) diff --git a/clippy_config/Cargo.toml b/clippy_config/Cargo.toml index 9154439defc1a..0007cece5de96 100644 --- a/clippy_config/Cargo.toml +++ b/clippy_config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_config" -version = "0.1.98" +version = "0.1.99" edition = "2024" publish = false @@ -8,7 +8,7 @@ publish = false [dependencies] clippy_utils = { path = "../clippy_utils" } -itertools = "0.12" +itertools = "0.15" serde = { version = "1.0", features = ["derive"] } toml = "0.7.3" diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index d910eb47752b5..5dfb934b90ce7 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -812,6 +812,7 @@ define_Conf! { manual_hash_one, manual_is_ascii_check, manual_is_power_of_two, + manual_is_variant_and, manual_isolate_lowest_one, manual_let_else, manual_midpoint, diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml index a11abc8d7cc4c..c4e06d8d6c4b9 100644 --- a/clippy_dev/Cargo.toml +++ b/clippy_dev/Cargo.toml @@ -8,7 +8,7 @@ edition = "2024" chrono = { version = "0.4.38", default-features = false, features = ["clock"] } clap = { version = "4.4", features = ["derive"] } indoc = "1.0" -itertools = "0.12" +itertools = "0.15" opener = "0.8" rustc-literal-escaper = "0.0.8" walkdir = "2.3" diff --git a/clippy_dev/src/edit_lints.rs b/clippy_dev/src/edit_lints.rs index 70c096783af8e..2ea3a84bdc710 100644 --- a/clippy_dev/src/edit_lints.rs +++ b/clippy_dev/src/edit_lints.rs @@ -8,8 +8,8 @@ use core::mem; use rustc_lexer::TokenKind; use std::collections::hash_map::Entry; use std::ffi::OsString; -use std::fs; use std::path::Path; +use std::{fs, path}; /// Runs the `deprecate` command /// @@ -103,7 +103,7 @@ pub fn rename<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam eprintln!("error: failed to find lint `{old_name}`"); return; }; - let Lint::Active(mut prev_lint) = mem::replace( + let Lint::Active(prev_lint) = mem::replace( lint.get_mut(), Lint::Renamed(RenamedLint { new_name: LintName::new_clippy(new_name), @@ -116,26 +116,19 @@ pub fn rename<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam let mut rename_mod = false; if let Entry::Vacant(e) = data.lints.entry(new_name) { - if prev_lint.module.ends_with(old_name) - && prev_lint - .path - .file_stem() - .is_some_and(|x| x.as_encoded_bytes() == old_name.as_bytes()) + if let Some((path, file)) = prev_lint.file.path.get().rsplit_once(path::MAIN_SEPARATOR) + && let Some(file) = file.strip_suffix(".rs") + && file == old_name { - let mut new_path = prev_lint.path.with_file_name(new_name).into_os_string(); - new_path.push(".rs"); - if try_rename_file(prev_lint.path.as_ref(), new_path.as_ref()) { + let new_path = cx + .str_buf + .alloc_display(cx.arena, format_args!("{path}{}{new_name}.rs", path::MAIN_SEPARATOR)); + if try_rename_file(prev_lint.file.path.get(), new_path) { rename_mod = true; + prev_lint.file.path.set(new_path); } - - prev_lint.module = cx.str_buf.with(|buf| { - buf.push_str(&prev_lint.module[..prev_lint.module.len() - old_name.len()]); - buf.push_str(new_name); - cx.arena.alloc_str(buf) - }); } e.insert(Lint::Active(prev_lint)); - rename_test_files(old_name, new_name, &create_ignored_prefixes(old_name, &data)); } else { println!("Renamed `{old_name}` to `{new_name}`"); @@ -163,14 +156,14 @@ pub fn rename<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam fn remove_lint_declaration(name: &str, lint: &ActiveLint<'_>, data: &LintData<'_>, updater: &mut FileUpdater) -> bool { let delete_mod = if data.lints.iter().all(|(_, l)| { if let Lint::Active(l) = l { - l.module != lint.module + l.file != lint.file } else { true } }) { - delete_file_if_exists(lint.path.as_ref()) + delete_file_if_exists(lint.file.path.get()) } else { - updater.update_file(&lint.path, &mut |_, src, dst| -> UpdateStatus { + updater.update_file(lint.file.path.get(), &mut |_, src, dst| -> UpdateStatus { let mut start = &src[..lint.declaration_range.start as usize]; if start.ends_with("\n\n") { start = &start[..start.len() - 1]; @@ -257,9 +250,9 @@ fn rename_test_files(old_name: &str, new_name: &str, ignored_prefixes: &[&str]) old_buf.push(name); new_buf.extend([new_name.as_ref(), name.slice_encoded_bytes(old_name.len()..)]); if is_file { - try_rename_file(old_buf.as_ref(), new_buf.as_ref()); + try_rename_file(&old_buf, &new_buf); } else { - try_rename_dir(old_buf.as_ref(), new_buf.as_ref()); + try_rename_dir(&old_buf, &new_buf); } old_buf.truncate("tests/ui/".len()); new_buf.truncate("tests/ui/".len()); @@ -274,7 +267,7 @@ fn rename_test_files(old_name: &str, new_name: &str, ignored_prefixes: &[&str]) for (name, _) in &tests { old_buf.push(name); new_buf.extend([new_name.as_ref(), name.slice_encoded_bytes(old_name.len()..)]); - try_rename_dir(old_buf.as_ref(), new_buf.as_ref()); + try_rename_dir(&old_buf, &new_buf); old_buf.truncate("tests/ui/".len()); new_buf.truncate("tests/ui/".len()); } @@ -290,9 +283,9 @@ fn delete_test_files(lint: &str, ignored_prefixes: &[&str]) { for &(ref name, is_file) in &tests { buf.push(name); if is_file { - delete_file_if_exists(buf.as_ref()); + delete_file_if_exists(&buf); } else { - delete_dir_if_exists(buf.as_ref()); + delete_dir_if_exists(&buf); } buf.truncate("tests/ui/".len()); } @@ -304,7 +297,7 @@ fn delete_test_files(lint: &str, ignored_prefixes: &[&str]) { collect_ui_toml_test_names(lint, ignored_prefixes, &mut tests); for (name, _) in &tests { buf.push(name); - delete_dir_if_exists(buf.as_ref()); + delete_dir_if_exists(&buf); buf.truncate("tests/ui/".len()); } } diff --git a/clippy_dev/src/fmt.rs b/clippy_dev/src/fmt.rs index d13f966b19c39..8a7150052f031 100644 --- a/clippy_dev/src/fmt.rs +++ b/clippy_dev/src/fmt.rs @@ -337,22 +337,23 @@ pub fn run(update_mode: UpdateMode) { new_parse_cx(|cx| { let mut data = cx.parse_lint_decls(); - let (mut lints, passes) = data.split_by_lint_file(); + let mut updater = FileUpdater::default(); - let mut ranges = VecBuf::with_capacity(256); - for passes in passes { - let path = passes[0].path.clone(); - let mut lints = lints.remove(&*path); + #[expect(clippy::mutable_key_type)] + let mut lints = data.mk_file_to_lint_decl_map(); + let mut ranges = VecBuf::with_capacity(256); + for passes in data.iter_passes_by_file_mut() { + let file = passes[0].file; + let mut lints = lints.remove(file); let lints = lints.as_deref_mut().unwrap_or_default(); - updater.update_file_checked("cargo dev fmt", update_mode, &path, &mut |_, src, dst| { + updater.update_loaded_file_checked("cargo dev fmt", update_mode, file, &mut |_, src, dst| { gen_sorted_lints_file(src, dst, lints, passes, &mut ranges); UpdateStatus::from_changed(src != dst) }); } - - for (&path, lints) in &mut lints { - updater.update_file_checked("cargo dev fmt", update_mode, path, &mut |_, src, dst| { + for (&file, lints) in &mut lints { + updater.update_loaded_file_checked("cargo dev fmt", update_mode, file, &mut |_, src, dst| { gen_sorted_lints_file(src, dst, lints, &mut [], &mut ranges); UpdateStatus::from_changed(src != dst) }); diff --git a/clippy_dev/src/generate.rs b/clippy_dev/src/generate.rs index 24e4218716abf..c35e718fa7913 100644 --- a/clippy_dev/src/generate.rs +++ b/clippy_dev/src/generate.rs @@ -1,6 +1,6 @@ use crate::parse::cursor::Cursor; use crate::parse::{Lint, LintData, LintPass, VecBuf}; -use crate::utils::{FileUpdater, UpdateMode, UpdateStatus, update_text_region_fn}; +use crate::utils::{FileUpdater, UpdateMode, UpdateStatus, slice_groups, update_text_region_fn}; use core::range::Range; use itertools::Itertools; use std::collections::HashSet; @@ -40,12 +40,12 @@ impl LintData<'_> { let mut renamed = Vec::with_capacity(lints.len() / 8); for &(name, lint) in &lints { match lint { - Lint::Active(lint) => active.push((name, lint)), + Lint::Active(lint) => active.push((name, lint.file.path_as_krate_mod())), Lint::Deprecated(lint) => deprecated.push((name, lint)), Lint::Renamed(lint) => renamed.push((name, lint)), } } - active.sort_by_key(|&(_, lint)| lint.module); + active.sort_by_key(|&(_, path)| path); // Round to avoid updating the readme every time a lint is added/deprecated. let lint_count = active.len() / 50 * 50; @@ -66,10 +66,10 @@ impl LintData<'_> { }), ); - updater.update_file_checked( + updater.update_loaded_file_checked( "cargo dev update_lints", update_mode, - "clippy_lints/src/deprecated_lints.rs", + self.deprecated_file, &mut |_, src, dst| { let mut cursor = Cursor::new(src); assert!( @@ -138,29 +138,25 @@ impl LintData<'_> { UpdateStatus::from_changed(src != dst) }, ); - for (crate_name, lints) in active.iter().copied().into_group_map_by(|&(_, lint)| { - let Some(path::Component::Normal(name)) = lint.path.components().next() else { - // All paths should start with `{crate_name}/src` when parsed from `find_lint_decls` - panic!( - "internal error: can't read crate name from path `{}`", - lint.path.display() - ); - }; - name + + for lints in slice_groups(&active, |(_, (head, _)), tail| { + tail.iter().take_while(|(_, (x, _))| head == x).count() }) { + let (_, (krate, _)) = lints[0]; updater.update_file_checked( "cargo dev update_lints", update_mode, - Path::new(crate_name).join("src/lib.rs"), + Path::new(krate).join("src/lib.rs"), &mut update_text_region_fn( "// begin lints modules, do not remove this comment, it's used in `update_lints`\n", "// end lints modules, do not remove this comment, it's used in `update_lints`", |dst| { let mut prev = ""; - for &(_, lint) in &lints { - if lint.module != prev { - writeln!(dst, "mod {};", lint.module).unwrap(); - prev = lint.module; + for &(_, (_, mod_path)) in lints { + let module = mod_path.split_once(path::MAIN_SEPARATOR).map_or(mod_path, |(x, _)| x); + if module != prev { + writeln!(dst, "mod {module};").unwrap(); + prev = module; } } }, @@ -169,20 +165,21 @@ impl LintData<'_> { updater.update_file_checked( "cargo dev update_lints", update_mode, - Path::new(crate_name).join("src/declared_lints.rs"), + Path::new(krate).join("src/declared_lints.rs"), &mut |_, src, dst| { dst.push_str(GENERATED_FILE_COMMENT); dst.push_str("pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[\n"); let mut buf = String::new(); - for &(name, lint) in &lints { + for &(name, (_, mod_path)) in lints { + dst.push_str(" crate::"); + for part in mod_path.split(path::MAIN_SEPARATOR) { + dst.push_str(part); + dst.push_str("::"); + } buf.clear(); buf.push_str(name); buf.make_ascii_uppercase(); - if lint.module.is_empty() { - writeln!(dst, " crate::{buf}_INFO,").unwrap(); - } else { - writeln!(dst, " crate::{}::{buf}_INFO,", lint.module).unwrap(); - } + let _ = writeln!(dst, "{buf}_INFO,"); } dst.push_str("];\n"); UpdateStatus::from_changed(src != dst) @@ -283,6 +280,7 @@ pub fn gen_sorted_lints_file( dst.push_str("\n\n"); } for pass in passes { + pass.lints.sort_unstable(); pass.gen_mac(dst); dst.push_str("\n\n"); } diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 433d4e8cdcf16..b707c2cea6e5b 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -13,7 +13,7 @@ unused_lifetimes, unused_qualifications )] -#![allow(clippy::missing_panics_doc)] +#![allow(clippy::case_sensitive_file_extension_comparisons, clippy::missing_panics_doc)] extern crate rustc_arena; extern crate rustc_data_structures; diff --git a/clippy_dev/src/parse.rs b/clippy_dev/src/parse.rs index d51fb25552f9d..ff6c63f61d866 100644 --- a/clippy_dev/src/parse.rs +++ b/clippy_dev/src/parse.rs @@ -2,16 +2,76 @@ pub mod cursor; use self::cursor::{Capture, Cursor}; use crate::utils::{ErrAction, File, Scoped, expect_action, slice_groups_mut, walk_dir_no_dot_or_target}; +use core::cell::Cell; use core::fmt::{self, Display, Write as _}; +use core::hash::{Hash, Hasher}; +use core::ptr; use core::range::Range; -use rustc_arena::DroplessArena; +use rustc_arena::{DroplessArena, TypedArena}; use rustc_data_structures::fx::FxHashMap; -use std::fs; -use std::path::{self, Path, PathBuf}; use std::str::pattern::Pattern; +use std::{fs, path}; + +#[derive(Eq)] +pub struct SourceFile<'cx> { + // `cargo dev rename_lint` needs to be able to rename files. + pub path: Cell<&'cx str>, + pub contents: String, +} +impl<'cx> SourceFile<'cx> { + pub fn load(path: &'cx str) -> Self { + let mut contents = String::new(); + File::open_read(path).read_append_to_string(&mut contents); + SourceFile { + path: Cell::new(path), + contents, + } + } + + /// Splits the file's path into the crate it's a part of and the module it implements. + /// + /// Only supports paths in the form `CRATE_NAME/src/PATH/TO/FILE.rs` using the current + /// platform's path separator. The module path returned will use the current platform's + /// path separator. + pub fn path_as_krate_mod(&self) -> (&'cx str, &'cx str) { + let path = self.path.get(); + let Some((krate, path)) = path.split_once(path::MAIN_SEPARATOR) else { + return ("", ""); + }; + let module = if let Some(path) = path.strip_prefix("src") + && let Some(path) = path.strip_prefix(path::MAIN_SEPARATOR) + && let Some(path) = path.strip_suffix(".rs") + { + if path == "lib" { + "" + } else if let Some(path) = path.strip_suffix("mod") + && let Some(path) = path.strip_suffix(path::MAIN_SEPARATOR) + { + path + } else { + path + } + } else { + "" + }; + (krate, module) + } +} +impl PartialEq> for SourceFile<'_> { + fn eq(&self, other: &SourceFile<'_>) -> bool { + // We should only be creating one source file per path. + ptr::addr_eq(self, other) + } +} +impl Hash for SourceFile<'_> { + fn hash(&self, state: &mut H) { + ptr::hash(self, state); + } +} pub struct ParseCxImpl<'cx> { pub arena: &'cx DroplessArena, + pub source_files: &'cx TypedArena>, pub str_buf: StrBuf, pub str_list_buf: VecBuf<&'cx str>, } @@ -20,8 +80,10 @@ pub type ParseCx<'cx> = &'cx mut ParseCxImpl<'cx>; /// Calls the given function inside a newly created parsing context. pub fn new_parse_cx<'env, T>(f: impl for<'cx> FnOnce(&'cx mut Scoped<'cx, 'env, ParseCxImpl<'cx>>) -> T) -> T { let arena = DroplessArena::default(); + let source_files = TypedArena::default(); f(&mut Scoped::new(ParseCxImpl { arena: &arena, + source_files: &source_files, str_buf: StrBuf::with_capacity(128), str_list_buf: VecBuf::with_capacity(128), })) @@ -51,6 +113,21 @@ impl StrBuf { arena.alloc_str(&self.0) } + /// Collects all elements into the buffer and allocates that onto the arena. + pub fn alloc_collect<'cx, I>(&mut self, arena: &'cx DroplessArena, iter: I) -> &'cx str + where + I: IntoIterator, + String: Extend, + { + self.0.clear(); + self.0.extend(iter); + if self.0.is_empty() { + "" + } else { + arena.alloc_str(&self.0) + } + } + /// Allocates the result of replacing all instances the pattern with the given string /// onto the arena. pub fn alloc_replaced<'cx>( @@ -141,9 +218,8 @@ impl Display for LintName<'_> { } pub struct ActiveLint<'cx> { + pub file: &'cx SourceFile<'cx>, pub group: &'cx str, - pub module: &'cx str, - pub path: PathBuf, pub declaration_range: Range, } @@ -184,37 +260,36 @@ pub struct LintPass<'cx> { pub name: &'cx str, pub lt: Option<&'cx str>, pub mac: LintPassMac, + pub file: &'cx SourceFile<'cx>, pub decl_range: Range, - pub lints: &'cx [&'cx str], - pub path: PathBuf, + pub lints: &'cx mut [&'cx str], } pub struct LintData<'cx> { pub lints: FxHashMap<&'cx str, Lint<'cx>>, pub lint_passes: Vec>, + pub deprecated_file: &'cx SourceFile<'cx>, } impl<'cx> LintData<'cx> { - #[expect(clippy::type_complexity)] - pub fn split_by_lint_file<'s>( - &'s mut self, - ) -> ( - FxHashMap<&'s Path, Vec<(&'s str, Range)>>, - impl Iterator]>, - ) { + #[expect(clippy::mutable_key_type)] + pub fn mk_file_to_lint_decl_map(&self) -> FxHashMap<&'cx SourceFile<'cx>, Vec<(&'cx str, Range)>> { #[expect(clippy::default_trait_access)] let mut lints = FxHashMap::with_capacity_and_hasher(500, Default::default()); for (&name, lint) in &self.lints { if let Lint::Active(lint) = lint { lints - .entry(&*lint.path) + .entry(lint.file) .or_insert_with(|| Vec::with_capacity(8)) .push((name, lint.declaration_range)); } } - let passes = slice_groups_mut(&mut self.lint_passes, |head, tail| { - tail.iter().take_while(|&x| x.path == head.path).count() - }); - (lints, passes) + lints + } + + pub fn iter_passes_by_file_mut<'s>(&'s mut self) -> impl Iterator]> { + slice_groups_mut(&mut self.lint_passes, |head, tail| { + tail.iter().take_while(|&x| x.file == head.file).count() + }) } } @@ -226,9 +301,18 @@ impl<'cx> ParseCxImpl<'cx> { #[expect(clippy::default_trait_access)] lints: FxHashMap::with_capacity_and_hasher(1000, Default::default()), lint_passes: Vec::with_capacity(400), + deprecated_file: self.source_files.alloc(SourceFile::load(self.str_buf.alloc_collect( + self.arena, + [ + "clippy_lints", + path::MAIN_SEPARATOR_STR, + "src", + path::MAIN_SEPARATOR_STR, + "deprecated_lints.rs", + ], + ))), }; - let mut contents = String::new(); for e in expect_action(fs::read_dir("."), ErrAction::Read, ".") { let e = expect_action(e, ErrAction::Read, "."); @@ -247,36 +331,24 @@ impl<'cx> ParseCxImpl<'cx> { crate_path.push_str("src"); for e in walk_dir_no_dot_or_target(&crate_path) { let e = expect_action(e, ErrAction::Read, &crate_path); - if let Some(path) = e.path().to_str() - && let Some(path) = path.strip_suffix(".rs") - && let Some(path) = path.get(crate_path.len() + 1..) + if e.path().as_os_str().as_encoded_bytes().ends_with(b".rs") + && let Some(file_path) = e.path().to_str() + && file_path != data.deprecated_file.path.get() { - let module = if path == "lib" { - "" - } else { - let path = path - .strip_suffix("mod") - .and_then(|x| x.strip_suffix(path::MAIN_SEPARATOR)) - .unwrap_or(path); - self.str_buf - .alloc_replaced(self.arena, path, path::MAIN_SEPARATOR, "::") - }; - self.parse_lint_src_file( - e.path(), - File::open_read_to_cleared_string(e.path(), &mut contents), - module, - &mut data, - ); + let file = self + .source_files + .alloc(SourceFile::load(self.arena.alloc_str(file_path))); + self.parse_lint_src_file(&mut data, file); } } } - self.read_deprecated_lints(&mut data); + self.parse_deprecated_lints(&mut data); data } /// Parse a source file looking for `declare_clippy_lint` macro invocations. - fn parse_lint_src_file(&mut self, path: &Path, contents: &str, module: &'cx str, data: &mut LintData<'cx>) { + fn parse_lint_src_file(&mut self, data: &mut LintData<'cx>, file: &'cx SourceFile<'cx>) { #[allow(clippy::enum_glob_use)] use cursor::Pat::*; #[rustfmt::skip] @@ -294,7 +366,7 @@ impl<'cx> ParseCxImpl<'cx> { Bang, OpenParen, CaptureDocLines, CaptureIdent, CaptureOptLifetimeArg, FatArrow, OpenBracket, ]; - let mut cursor = Cursor::new(contents); + let mut cursor = Cursor::new(&file.contents); let mut captures = [Capture::EMPTY; 3]; while let Some(mac_name) = cursor.find_any_ident() { match cursor.get_text(mac_name) { @@ -306,9 +378,8 @@ impl<'cx> ParseCxImpl<'cx> { .insert( self.str_buf.alloc_ascii_lower(self.arena, cursor.get_text(captures[0])), Lint::Active(ActiveLint { - group: self.arena.alloc_str(cursor.get_text(captures[1])), - module, - path: path.into(), + file, + group: cursor.get_text(captures[1]), declaration_range: mac_name.pos..cursor.pos(), }), ) @@ -321,17 +392,10 @@ impl<'cx> ParseCxImpl<'cx> { } else { LintPassMac::Impl }; - let docs = match cursor.get_text(captures[0]) { - "" => "", - x => self.arena.alloc_str(x), - }; - let name = self.arena.alloc_str(cursor.get_text(captures[1])); + let docs = cursor.get_text(captures[0]); + let name = cursor.get_text(captures[1]); let lt = cursor.get_text(captures[2]); - let lt = if lt.is_empty() { - None - } else { - Some(self.arena.alloc_str(lt)) - }; + let lt = if lt.is_empty() { None } else { Some(lt) }; let lints = self.str_list_buf.with(|buf| { // Parses a comma separated list of paths and converts each path @@ -361,10 +425,9 @@ impl<'cx> ParseCxImpl<'cx> { // The arena panics when allocating a size of zero. Some(if buf.is_empty() { - &[] + &mut [] } else { - buf.sort_unstable(); - &*self.arena.alloc_slice(buf) + self.arena.alloc_slice(buf) }) }); @@ -376,9 +439,9 @@ impl<'cx> ParseCxImpl<'cx> { name, lt, mac, + file, decl_range: mac_name.pos..cursor.pos(), lints, - path: path.into(), }); } }, @@ -387,7 +450,7 @@ impl<'cx> ParseCxImpl<'cx> { } } - fn read_deprecated_lints(&mut self, data: &mut LintData<'cx>) { + fn parse_deprecated_lints(&mut self, data: &mut LintData<'cx>) { #[allow(clippy::enum_glob_use)] use cursor::Pat::*; #[rustfmt::skip] @@ -408,11 +471,8 @@ impl<'cx> ParseCxImpl<'cx> { Bang, OpenBrace, Ident("RENAMED"), OpenParen, Ident("RENAMED_VERSION"), CloseParen, Eq, OpenBracket, ]; - let path = "clippy_lints/src/deprecated_lints.rs"; - let mut contents = String::new(); - File::open_read_to_cleared_string(path, &mut contents); - - let mut cursor = Cursor::new(&contents); + let file = data.deprecated_file; + let mut cursor = Cursor::new(&file.contents); let mut captures = [Capture::EMPTY; 3]; // First instance is the macro definition. @@ -426,10 +486,10 @@ impl<'cx> ParseCxImpl<'cx> { assert!( data.lints .insert( - self.parse_clippy_lint_name(path.as_ref(), cursor.get_text(captures[1])), + self.parse_clippy_lint_name(file, cursor.get_text(captures[1])), Lint::Deprecated(DeprecatedLint { - reason: self.parse_str_single_line(path.as_ref(), cursor.get_text(captures[2])), - version: self.parse_str_single_line(path.as_ref(), cursor.get_text(captures[0])), + reason: self.parse_str_single_line(file, cursor.get_text(captures[2])), + version: self.parse_str_single_line(file, cursor.get_text(captures[0])), }), ) .is_none() @@ -444,10 +504,10 @@ impl<'cx> ParseCxImpl<'cx> { assert!( data.lints .insert( - self.parse_clippy_lint_name(path.as_ref(), cursor.get_text(captures[1])), + self.parse_clippy_lint_name(file, cursor.get_text(captures[1])), Lint::Renamed(RenamedLint { - new_name: self.parse_lint_name(path.as_ref(), cursor.get_text(captures[2])), - version: self.parse_str_single_line(path.as_ref(), cursor.get_text(captures[0])), + new_name: self.parse_lint_name(file, cursor.get_text(captures[2])), + version: self.parse_str_single_line(file, cursor.get_text(captures[0])), }), ) .is_none() @@ -459,7 +519,7 @@ impl<'cx> ParseCxImpl<'cx> { } /// Removes the line splices and surrounding quotes from a string literal - fn parse_str_lit(&mut self, s: &str) -> &'cx str { + fn parse_str_lit(&mut self, s: &'cx str) -> &'cx str { let (s, is_raw) = if let Some(s) = s.strip_prefix("r") { (s.trim_matches('#'), true) } else { @@ -471,7 +531,7 @@ impl<'cx> ParseCxImpl<'cx> { .unwrap_or_else(|| panic!("expected quoted string, found `{s}`")); if is_raw { - if s.is_empty() { "" } else { self.arena.alloc_str(s) } + s } else { self.str_buf.with(|buf| { rustc_literal_escaper::unescape_str(s, &mut |_, ch| { @@ -479,33 +539,39 @@ impl<'cx> ParseCxImpl<'cx> { buf.push(ch); } }); - if buf.is_empty() { "" } else { self.arena.alloc_str(buf) } + if buf == s { + s + } else if buf.is_empty() { + "" + } else { + self.arena.alloc_str(buf) + } }) } } - fn parse_str_single_line(&mut self, path: &Path, s: &str) -> &'cx str { + fn parse_str_single_line(&mut self, file: &SourceFile<'_>, s: &'cx str) -> &'cx str { let value = self.parse_str_lit(s); assert!( !value.contains('\n'), "error parsing `{}`: `{s}` should be a single line string", - path.display(), + file.path.get(), ); value } - fn parse_clippy_lint_name(&mut self, path: &Path, s: &str) -> &'cx str { - match self.parse_str_single_line(path, s).strip_prefix("clippy::") { + fn parse_clippy_lint_name(&mut self, file: &SourceFile<'_>, s: &'cx str) -> &'cx str { + match self.parse_str_single_line(file, s).strip_prefix("clippy::") { Some(x) => x, None => panic!( "error parsing `{}`: `{s}` should be a string starting with `clippy::`", - path.display() + file.path.get(), ), } } - fn parse_lint_name(&mut self, path: &Path, s: &str) -> LintName<'cx> { - let s = self.parse_str_single_line(path, s); + fn parse_lint_name(&mut self, file: &SourceFile<'_>, s: &'cx str) -> LintName<'cx> { + let s = self.parse_str_single_line(file, s); let (name, tool) = match s.strip_prefix("clippy::") { Some(s) => (s, LintTool::Clippy), None => (s, LintTool::Rustc), diff --git a/clippy_dev/src/utils.rs b/clippy_dev/src/utils.rs index 1f931140467eb..797eed7d59348 100644 --- a/clippy_dev/src/utils.rs +++ b/clippy_dev/src/utils.rs @@ -13,6 +13,8 @@ use std::process::{self, Command, Stdio}; use std::{env, thread}; use walkdir::WalkDir; +use crate::parse::SourceFile; + pub struct Scoped<'inner, 'outer: 'inner, T>(T, PhantomData<&'inner mut T>, PhantomData<&'outer mut ()>); impl Scoped<'_, '_, T> { pub fn new(value: T) -> Self { @@ -96,13 +98,10 @@ impl<'a> File<'a> { } } - /// Opens and reads a file into a string, panicking of failure. + /// Opens a file for reading, panicking of failure. #[track_caller] - pub fn open_read_to_cleared_string<'dst>( - path: &'a (impl AsRef + ?Sized), - dst: &'dst mut String, - ) -> &'dst mut String { - Self::open(path, OpenOptions::new().read(true)).read_to_cleared_string(dst) + pub fn open_read(path: &'a (impl AsRef + ?Sized)) -> Self { + Self::open(path, OpenOptions::new().read(true)) } /// Read the entire contents of a file to the given buffer. @@ -118,13 +117,19 @@ impl<'a> File<'a> { self.read_append_to_string(dst) } + /// Writes the entire contents of the specified buffer to the file, panicking on failure. + #[track_caller] + pub fn write(&mut self, data: &[u8]) { + expect_action(self.inner.write_all(data), ErrAction::Write, self.path); + } + /// Replaces the entire contents of a file. #[track_caller] pub fn replace_contents(&mut self, data: &[u8]) { let res = match self.inner.seek(SeekFrom::Start(0)) { - Ok(_) => match self.inner.write_all(data) { - Ok(()) => self.inner.set_len(data.len() as u64), - Err(e) => Err(e), + Ok(_) => { + self.write(data); + self.inner.set_len(data.len() as u64) }, Err(e) => Err(e), }; @@ -364,6 +369,34 @@ impl FileUpdater { } } + #[track_caller] + pub fn update_loaded_file_checked( + &mut self, + tool: &str, + mode: UpdateMode, + file: &SourceFile<'_>, + update: &mut dyn FnMut(&Path, &str, &mut String) -> UpdateStatus, + ) { + self.dst_buf.clear(); + match ( + mode, + update(file.path.get().as_ref(), &file.contents, &mut self.dst_buf), + ) { + (UpdateMode::Check, UpdateStatus::Changed) => { + eprintln!( + "the contents of `{}` are out of date\nplease run `{tool}` to update", + file.path.get(), + ); + process::exit(1); + }, + (UpdateMode::Change, UpdateStatus::Changed) => { + File::open(file.path.get(), OpenOptions::new().truncate(true).write(true)) + .write(self.dst_buf.as_bytes()); + }, + (UpdateMode::Check | UpdateMode::Change, UpdateStatus::Unchanged) => {}, + } + } + #[track_caller] fn update_file_inner(&mut self, path: &Path, update: &mut dyn FnMut(&Path, &str, &mut String) -> UpdateStatus) { let mut file = File::open(path, OpenOptions::new().read(true).write(true)); @@ -430,51 +463,59 @@ pub fn update_text_region_fn( } #[track_caller] -pub fn try_rename_file(old_name: &Path, new_name: &Path) -> bool { - match OpenOptions::new().create_new(true).write(true).open(new_name) { - Ok(file) => drop(file), - Err(e) if matches!(e.kind(), io::ErrorKind::AlreadyExists | io::ErrorKind::NotFound) => return false, - Err(ref e) => panic_action(e, ErrAction::Create, new_name), - } - match fs::rename(old_name, new_name) { - Ok(()) => true, - Err(ref e) => { - drop(fs::remove_file(new_name)); - // `NotADirectory` happens on posix when renaming a directory to an existing file. - // Windows will ignore this and rename anyways. - if matches!(e.kind(), io::ErrorKind::NotFound | io::ErrorKind::NotADirectory) { - false - } else { - panic_action(e, ErrAction::Rename, old_name); - } - }, +pub fn try_rename_file(old_name: impl AsRef, new_name: impl AsRef) -> bool { + #[track_caller] + fn f(old_name: &Path, new_name: &Path) -> bool { + match OpenOptions::new().create_new(true).write(true).open(new_name) { + Ok(file) => drop(file), + Err(e) if matches!(e.kind(), io::ErrorKind::AlreadyExists | io::ErrorKind::NotFound) => return false, + Err(ref e) => panic_action(e, ErrAction::Create, new_name), + } + match fs::rename(old_name, new_name) { + Ok(()) => true, + Err(ref e) => { + drop(fs::remove_file(new_name)); + // `NotADirectory` happens on posix when renaming a directory to an existing file. + // Windows will ignore this and rename anyways. + if matches!(e.kind(), io::ErrorKind::NotFound | io::ErrorKind::NotADirectory) { + false + } else { + panic_action(e, ErrAction::Rename, old_name); + } + }, + } } + f(old_name.as_ref(), new_name.as_ref()) } #[track_caller] -pub fn try_rename_dir(old_name: &Path, new_name: &Path) -> bool { - match fs::create_dir(new_name) { - Ok(()) => {}, - Err(e) if matches!(e.kind(), io::ErrorKind::AlreadyExists | io::ErrorKind::NotFound) => return false, - Err(ref e) => panic_action(e, ErrAction::Create, new_name), - } - // Windows can't reliably rename to an empty directory. - #[cfg(windows)] - drop(fs::remove_dir(new_name)); - match fs::rename(old_name, new_name) { - Ok(()) => true, - Err(ref e) => { - // Already dropped earlier on windows. - #[cfg(not(windows))] - drop(fs::remove_dir(new_name)); - // `NotADirectory` happens on posix when renaming a file to an existing directory. - if matches!(e.kind(), io::ErrorKind::NotFound | io::ErrorKind::NotADirectory) { - false - } else { - panic_action(e, ErrAction::Rename, old_name); - } - }, +pub fn try_rename_dir(old_name: impl AsRef, new_name: impl AsRef) -> bool { + #[track_caller] + fn f(old_name: &Path, new_name: &Path) -> bool { + match fs::create_dir(new_name) { + Ok(()) => {}, + Err(e) if matches!(e.kind(), io::ErrorKind::AlreadyExists | io::ErrorKind::NotFound) => return false, + Err(ref e) => panic_action(e, ErrAction::Create, new_name), + } + // Windows can't reliably rename to an empty directory. + #[cfg(windows)] + drop(fs::remove_dir(new_name)); + match fs::rename(old_name, new_name) { + Ok(()) => true, + Err(ref e) => { + // Already dropped earlier on windows. + #[cfg(not(windows))] + drop(fs::remove_dir(new_name)); + // `NotADirectory` happens on posix when renaming a file to an existing directory. + if matches!(e.kind(), io::ErrorKind::NotFound | io::ErrorKind::NotADirectory) { + false + } else { + panic_action(e, ErrAction::Rename, old_name); + } + }, + } } + f(old_name.as_ref(), new_name.as_ref()) } #[track_caller] @@ -576,21 +617,29 @@ pub fn split_args_for_threads( } #[track_caller] -pub fn delete_file_if_exists(path: &Path) -> bool { - match fs::remove_file(path) { - Ok(()) => true, - Err(e) if matches!(e.kind(), io::ErrorKind::NotFound | io::ErrorKind::IsADirectory) => false, - Err(ref e) => panic_action(e, ErrAction::Delete, path), +pub fn delete_file_if_exists(path: impl AsRef) -> bool { + #[track_caller] + fn f(path: &Path) -> bool { + match fs::remove_file(path) { + Ok(()) => true, + Err(e) if matches!(e.kind(), io::ErrorKind::NotFound | io::ErrorKind::IsADirectory) => false, + Err(ref e) => panic_action(e, ErrAction::Delete, path), + } } + f(path.as_ref()) } #[track_caller] -pub fn delete_dir_if_exists(path: &Path) { - match fs::remove_dir_all(path) { - Ok(()) => {}, - Err(e) if matches!(e.kind(), io::ErrorKind::NotFound | io::ErrorKind::NotADirectory) => {}, - Err(ref e) => panic_action(e, ErrAction::Delete, path), +pub fn delete_dir_if_exists(path: impl AsRef) { + #[track_caller] + fn f(path: &Path) { + match fs::remove_dir_all(path) { + Ok(()) => {}, + Err(e) if matches!(e.kind(), io::ErrorKind::NotFound | io::ErrorKind::NotADirectory) => {}, + Err(ref e) => panic_action(e, ErrAction::Delete, path), + } } + f(path.as_ref()); } /// Walks all items excluding top-level dot files/directories and any target directories. @@ -602,6 +651,28 @@ pub fn walk_dir_no_dot_or_target(p: impl AsRef) -> impl Iterator(slice: &[T], split_idx: impl FnMut(&T, &[T]) -> usize) -> impl Iterator { + struct I<'a, T, F> { + slice: &'a [T], + split_idx: F, + } + impl<'a, T, F: FnMut(&T, &[T]) -> usize> Iterator for I<'a, T, F> { + type Item = &'a [T]; + fn next(&mut self) -> Option { + let (head, tail) = self.slice.split_first()?; + let idx = (self.split_idx)(head, tail) + 1; + if let Some((head, tail)) = self.slice.split_at_checked(idx) { + self.slice = tail; + Some(head) + } else { + self.slice = &mut []; + None + } + } + } + I { slice, split_idx } +} + pub fn slice_groups_mut( slice: &mut [T], split_idx: impl FnMut(&T, &[T]) -> usize, diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 2e4191f25ce24..c2f524a7ee235 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_lints" -version = "0.1.98" +version = "0.1.99" description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" @@ -14,7 +14,7 @@ cargo_metadata = "0.23" clippy_config = { path = "../clippy_config" } clippy_utils = { path = "../clippy_utils" } declare_clippy_lint = { path = "../declare_clippy_lint" } -itertools = "0.12" +itertools = "0.15" quine-mc_cluskey = "0.2" regex-syntax = "0.8" serde = { version = "1.0", features = ["derive"] } diff --git a/clippy_lints/src/bit_width.rs b/clippy_lints/src/bit_width.rs new file mode 100644 index 0000000000000..3403d55494734 --- /dev/null +++ b/clippy_lints/src/bit_width.rs @@ -0,0 +1,191 @@ +use clippy_config::Conf; +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::source::snippet_with_context; +use clippy_utils::{is_from_proc_macro, sym}; +use rustc_errors::Applicability; +use rustc_hir::{BinOpKind, Expr, ExprKind, QPath}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_middle::ty::{self, Ty}; +use rustc_session::impl_lint_pass; + +declare_clippy_lint! { + /// ### What it does + /// Checks for usage of `T::BITS - x.leading_zeros()` when `x.bit_width()` is available. + /// + /// ### Why is this bad? + /// Manual reimplementations of `bit_width` increase code complexity for little benefit. + /// + /// ### Example + /// ```no_run + /// let x: u32 = 5; + /// let bit_width = u32::BITS - x.leading_zeros(); + /// ``` + /// Use instead: + /// ```no_run + /// let x: u32 = 5; + /// let bit_width = x.bit_width(); + /// ``` + #[clippy::version = "1.98.0"] + pub MANUAL_BIT_WIDTH, + pedantic, + "manually reimplementing `bit_width`" +} + +declare_clippy_lint! { + /// ### What it does + /// Checks for usage of `T::BITS - x.leading_zeros()` where T and x are of different types. + /// + /// ### Why is this bad? + /// Substracting `leading_zeros` from the number of bits of another type might be + /// a buggy implementation of the `bit_width` method. + /// + /// ### Example + /// ```no_run + /// let x: u64 = 5; + /// let bit_width = u32::BITS - x.leading_zeros(); + /// ``` + /// Use instead: + /// ```no_run + /// let x: u64 = 5; + /// let bit_width = x.bit_width(); + /// ``` + #[clippy::version = "1.98.0"] + pub MISMATCHED_BIT_WIDTH_TYPE, + suspicious, + "type mismatch in bit width calculation" +} + +impl_lint_pass!(ManualBitWidth => [MANUAL_BIT_WIDTH, MISMATCHED_BIT_WIDTH_TYPE]); + +#[derive(Clone, Copy, PartialEq)] +enum IntKind<'a> { + Int(ty::IntTy), + Uint(ty::UintTy), + // NOTE: in the following two variants, the inner `Ty` stores the entire `NonZero` + // and not just `T`. This is so that we can print it in the suggestion. + NonZero(Ty<'a>), + NonZeroU(Ty<'a>), +} + +impl IntKind<'_> { + fn inner_ty(self) -> String { + match self { + Self::Int(ty) => ty.name_str().to_string(), + Self::Uint(ty) => ty.name_str().to_string(), + Self::NonZero(ty) | Self::NonZeroU(ty) => ty.to_string(), + } + } + + fn suggestion(&self) -> &'static str { + match self { + Self::Int(_) => ".cast_unsigned().bit_width()", + Self::Uint(_) => ".bit_width()", + Self::NonZero(_) => ".cast_unsigned().bit_width().get()", + Self::NonZeroU(_) => ".bit_width().get()", + } + } +} + +pub struct ManualBitWidth { + msrv: Msrv, +} + +impl ManualBitWidth { + pub fn new(conf: &Conf) -> Self { + Self { msrv: conf.msrv } + } +} + +impl LateLintPass<'_> for ManualBitWidth { + fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { + if expr.span.in_external_macro(cx.sess().source_map()) { + return; + } + + match expr.kind { + // `T::BITS - n.leading_zeros()` + ExprKind::Binary(op, left, right) + if op.node == BinOpKind::Sub + && let ExprKind::MethodCall(leading_zeros, recv, [], _) = right.kind + && leading_zeros.ident.name == sym::leading_zeros + && let ExprKind::Path(QPath::TypeRelative(hir_ty, segment)) = left.kind + && segment.ident.name == sym::BITS + && let right_ty = cx.typeck_results().expr_ty(recv) + && let Some(right_int_kind) = get_int_kind(cx, right_ty) + && let left_ty = cx.typeck_results().node_type(hir_ty.hir_id) + && let Some(left_int_kind) = get_int_kind(cx, left_ty) + && self.msrv.meets(cx, msrvs::BIT_WIDTH) + && left.span.eq_ctxt(right.span) + && !is_from_proc_macro(cx, expr) => + { + if left_int_kind == right_int_kind { + // manual implementation of bit_width + emit_manual_bit_width(cx, recv, expr, right_int_kind); + } else { + // mismatched calling types + emit_type_mismatch(cx, recv, expr, right_int_kind); + } + }, + _ => {}, + } + } +} + +fn get_int_kind<'a>(cx: &LateContext<'a>, ty: Ty<'a>) -> Option> { + match ty.kind() { + // int::BITS or uint::BITS + ty::Int(int_ty) => Some(IntKind::Int(*int_ty)), + ty::Uint(uint_ty) => Some(IntKind::Uint(*uint_ty)), + // NonZero::::BITS + ty::Adt(adt, args) if cx.tcx.is_diagnostic_item(sym::NonZero, adt.did()) => { + let arg = args.type_at(0); + match arg.kind() { + ty::Int(_) => Some(IntKind::NonZero(ty)), + ty::Uint(_) => Some(IntKind::NonZeroU(ty)), + _ => None, + } + }, + _ => None, + } +} + +fn emit_manual_bit_width(cx: &LateContext<'_>, recv: &Expr<'_>, full_expr: &Expr<'_>, ty_kind: IntKind<'_>) { + span_lint_and_then( + cx, + MANUAL_BIT_WIDTH, + full_expr.span, + "manual implementation of `bit_width`", + |diag| { + let mut app = Applicability::MachineApplicable; + let (recv_snip, _) = snippet_with_context(cx, recv.span, full_expr.span.ctxt(), "_", &mut app); + let suggestion = ty_kind.suggestion(); + + diag.span_suggestion_verbose(full_expr.span, "try", format!("{recv_snip}{suggestion}"), app); + }, + ); +} + +fn emit_type_mismatch(cx: &LateContext<'_>, recv: &Expr<'_>, full_expr: &Expr<'_>, ty_kind: IntKind<'_>) { + span_lint_and_then( + cx, + MISMATCHED_BIT_WIDTH_TYPE, + full_expr.span, + "possible buggy implementation of `bit_width`", + |diag| { + diag.note("in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()`"); + + let mut app = Applicability::MaybeIncorrect; + let (recv_snip, _) = snippet_with_context(cx, recv.span, full_expr.span.ctxt(), "_", &mut app); + let suggestion = ty_kind.suggestion(); + let x_ty = ty_kind.inner_ty(); + + diag.span_suggestion_verbose( + full_expr.span, + format!("if you meant to use `{x_ty}::BITS`, use"), + format!("{recv_snip}{suggestion}"), + app, + ); + }, + ); +} diff --git a/clippy_lints/src/cargo/multiple_crate_versions.rs b/clippy_lints/src/cargo/multiple_crate_versions.rs index 21b5acf640733..805bf4623f1f1 100644 --- a/clippy_lints/src/cargo/multiple_crate_versions.rs +++ b/clippy_lints/src/cargo/multiple_crate_versions.rs @@ -33,7 +33,7 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, allowed_duplicate for (name, group) in &packages .iter() .filter(|p| !allowed_duplicate_crates.contains(p.name.as_str())) - .group_by(|p| &p.name) + .chunk_by(|p| &p.name) { let group: Vec<&Package> = group.collect(); diff --git a/clippy_lints/src/casts/borrow_as_ptr.rs b/clippy_lints/src/casts/borrow_as_ptr.rs index eb75d5576f5cf..51d9628fe330f 100644 --- a/clippy_lints/src/casts/borrow_as_ptr.rs +++ b/clippy_lints/src/casts/borrow_as_ptr.rs @@ -58,7 +58,7 @@ pub(super) fn check<'tcx>( } /// Check for an implicit cast from reference to raw pointer outside an explicit `as`. -pub(super) fn check_implicit_cast(cx: &LateContext<'_>, expr: &Expr<'_>) { +pub(super) fn check_implicit_cast<'cx>(cx: &LateContext<'cx>, expr: &Expr<'cx>) { if !expr.span.from_expansion() && let ExprKind::AddrOf(BorrowKind::Ref, _, pointee) = expr.kind && !matches!(get_parent_expr(cx, expr).map(|e| e.kind), Some(ExprKind::Cast(..))) @@ -67,6 +67,7 @@ pub(super) fn check_implicit_cast(cx: &LateContext<'_>, expr: &Expr<'_>) { && let Adjust::Borrow(AutoBorrow::RawPtr(mutability)) = borrow.kind // Do not suggest taking a raw pointer to a temporary value && !is_expr_temporary_value(cx, pointee) + && !is_from_proc_macro(cx, expr) { span_lint_and_then(cx, BORROW_AS_PTR, expr.span, "implicit borrow as raw pointer", |diag| { diag.span_suggestion_verbose( diff --git a/clippy_lints/src/casts/cast_possible_wrap.rs b/clippy_lints/src/casts/cast_possible_wrap.rs index 9eaa6e4cf26e4..f371c2f780926 100644 --- a/clippy_lints/src/casts/cast_possible_wrap.rs +++ b/clippy_lints/src/casts/cast_possible_wrap.rs @@ -96,8 +96,8 @@ pub(super) fn check( .note("for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types"); } - if msrv.meets(cx, msrvs::INTEGER_SIGN_CAST) - && let Some(cast) = utils::is_signedness_cast(cast_from, cast_to) + if let Some(cast) = utils::is_signedness_cast(cast_from, cast_to) + && msrv.meets(cx, msrvs::INTEGER_SIGN_CAST) { let method = match cast { utils::CastTo::Signed => "cast_signed()", diff --git a/clippy_lints/src/casts/cast_sign_loss.rs b/clippy_lints/src/casts/cast_sign_loss.rs index f870d27b796e8..ff8e67d44560a 100644 --- a/clippy_lints/src/casts/cast_sign_loss.rs +++ b/clippy_lints/src/casts/cast_sign_loss.rs @@ -54,8 +54,8 @@ pub(super) fn check<'cx>( expr.span, format!("casting `{cast_from}` to `{cast_to}` may lose the sign of the value"), |diag| { - if msrv.meets(cx, msrvs::INTEGER_SIGN_CAST) - && let Some(cast) = utils::is_signedness_cast(cast_from, cast_to) + if let Some(cast) = utils::is_signedness_cast(cast_from, cast_to) + && msrv.meets(cx, msrvs::INTEGER_SIGN_CAST) { let method = match cast { utils::CastTo::Signed => "cast_signed()", diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index d012380cb762f..61fe563512b60 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -41,8 +41,8 @@ pub(super) fn check<'tcx>( // The `U` in `pointer::cast` have to be `Sized` // as explained here: https://github.com/rust-lang/rust/issues/60602. && to_pointee_ty.is_sized(cx.tcx, cx.typing_env()) - && msrv.meets(cx, msrvs::POINTER_CAST) && !is_from_proc_macro(cx, expr) + && msrv.meets(cx, msrvs::POINTER_CAST) { let mut app = Applicability::MachineApplicable; let turbofish = match &cast_to_hir.kind { diff --git a/clippy_lints/src/casts/utils.rs b/clippy_lints/src/casts/utils.rs index 707fc2a8eed35..5a30c24e0bc06 100644 --- a/clippy_lints/src/casts/utils.rs +++ b/clippy_lints/src/casts/utils.rs @@ -67,7 +67,7 @@ pub(super) enum CastTo { } /// Returns `Some` if the type cast is between 2 integral types that differ /// only in signedness, otherwise `None`. The value of `Some` is which -/// signedness is casted to. +/// signedness is cast to. pub(super) fn is_signedness_cast(cast_from: Ty<'_>, cast_to: Ty<'_>) -> Option { match (cast_from.kind(), cast_to.kind()) { (ty::Int(from), ty::Uint(to)) if from.to_unsigned() == *to => Some(CastTo::Unsigned), diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 51a848d022d80..83ab6e31d2b26 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -33,6 +33,8 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[ crate::await_holding_invalid::AWAIT_HOLDING_INVALID_TYPE_INFO, crate::await_holding_invalid::AWAIT_HOLDING_LOCK_INFO, crate::await_holding_invalid::AWAIT_HOLDING_REFCELL_REF_INFO, + crate::bit_width::MANUAL_BIT_WIDTH_INFO, + crate::bit_width::MISMATCHED_BIT_WIDTH_TYPE_INFO, crate::blocks_in_conditions::BLOCKS_IN_CONDITIONS_INFO, crate::bool_assert_comparison::BOOL_ASSERT_COMPARISON_INFO, crate::bool_comparison::BOOL_COMPARISON_INFO, diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index fbff41fe00914..fe1115443d790 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -925,21 +925,30 @@ impl TyCoercionStability { continue; }, ty::Param(_) if for_return => Self::Deref, - ty::Alias(_, ty::AliasTy { - kind: ty::Free { .. } | ty::Inherent { .. }, - .. - }) => unreachable!("should have been normalized away above"), - ty::Alias(_, ty::AliasTy { - kind: ty::Projection { .. }, - .. - }) if !for_return && ty.has_non_region_param() => Self::Reborrow, + ty::Alias( + _, + ty::AliasTy { + kind: ty::Free { .. } | ty::Inherent { .. }, + .. + }, + ) => unreachable!("should have been normalized away above"), + ty::Alias( + _, + ty::AliasTy { + kind: ty::Projection { .. }, + .. + }, + ) if !for_return && ty.has_non_region_param() => Self::Reborrow, ty::Infer(_) | ty::Error(_) | ty::Bound(..) - | ty::Alias(_, ty::AliasTy { - kind: ty::Opaque { .. }, - .. - }) + | ty::Alias( + _, + ty::AliasTy { + kind: ty::Opaque { .. }, + .. + }, + ) | ty::Placeholder(_) | ty::Dynamic(..) | ty::Param(_) => Self::Reborrow, @@ -970,10 +979,13 @@ impl TyCoercionStability { | ty::CoroutineClosure(..) | ty::Never | ty::Tuple(_) - | ty::Alias(_, ty::AliasTy { - kind: ty::Projection { .. }, - .. - }) + | ty::Alias( + _, + ty::AliasTy { + kind: ty::Projection { .. }, + .. + }, + ) | ty::UnsafeBinder(_) => Self::Deref, }; } diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index c5816cb8b2d63..296c6e1d28002 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -69,18 +69,18 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Detects doc comment linebreaks that use double spaces to separate lines, instead of back-slash (`\`). + /// Detects doc comments that use double spaces as hard line break, instead of backslash (`\`). /// /// ### Why is this bad? - /// Double spaces, when used as doc comment linebreaks, can be difficult to see, and may - /// accidentally be removed during automatic formatting or manual refactoring. The use of a back-slash (`\`) + /// Double spaces, when used as hard line break in doc comments, can be difficult to see, and may + /// accidentally be removed during automatic formatting or manual refactoring. The use of a backslash (`\`) /// is clearer in this regard. /// /// ### Example - /// The two replacement dots in this example represent a double space. + /// The two replacement dots (`··`) in this example represent a double space. /// ```no_run - /// /// This command takes two numbers as inputs and·· - /// /// adds them together, and then returns the result. + /// /// This function adds two numbers and returns the result·· + /// /// Overflow can occur when the max value is exceeded. /// fn add(l: i32, r: i32) -> i32 { /// l + r /// } @@ -88,8 +88,8 @@ declare_clippy_lint! { /// /// Use instead: /// ```no_run - /// /// This command takes two numbers as inputs and\ - /// /// adds them together, and then returns the result. + /// /// This function adds two numbers and returns the result\ + /// /// Overflow can occur when the max value is exceeded. /// fn add(l: i32, r: i32) -> i32 { /// l + r /// } @@ -97,7 +97,7 @@ declare_clippy_lint! { #[clippy::version = "1.87.0"] pub DOC_COMMENT_DOUBLE_SPACE_LINEBREAKS, pedantic, - "double-space used for doc comment linebreak instead of `\\`" + "double space used for doc comment hard line break instead of `\\`" } declare_clippy_lint! { diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index c2836741b969e..7c2dc59f66d5b 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -78,7 +78,10 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && span_is_local(item.span) && let middle_trait_ref = cx.tcx.impl_trait_ref(item.owner_id).instantiate_identity().skip_norm_wip() && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) - && !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(_, ty::AliasTy { kind: ty::Opaque{..} , .. })) + && !matches!( + middle_trait_ref.args.type_at(1).kind(), + ty::Alias(_, ty::AliasTy { kind: ty::Opaque{..} , .. }) + ) && self.msrv.meets(cx, msrvs::RE_REBALANCING_COHERENCE) // skip if there's a blanket From impl, the suggested impl would conflict && !has_blanket_from_impl(cx, middle_trait_ref.self_ty()) diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index e19e02901caef..6fd1e833ede38 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -245,7 +245,7 @@ fn to_const_range(cx: &LateContext<'_>, range: higher::Range<'_>, array_size: u1 let e = range.end.map(|expr| ecx.eval(expr)); let end = match e { Some(Some(Constant::Int(x))) => { - if range.limits == RangeLimits::Closed { + if range.ty.limits() == RangeLimits::Closed { Some(x + 1) } else { Some(x) diff --git a/clippy_lints/src/len_without_is_empty.rs b/clippy_lints/src/len_without_is_empty.rs index 4453c4622caed..d947fa77d80e7 100644 --- a/clippy_lints/src/len_without_is_empty.rs +++ b/clippy_lints/src/len_without_is_empty.rs @@ -149,10 +149,13 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, ident: Iden } fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> { - if let ty::Alias(_, ty::AliasTy { - kind: ty::Opaque { def_id }, - .. - }) = *ty.kind() + if let ty::Alias( + _, + ty::AliasTy { + kind: ty::Opaque { def_id }, + .. + }, + ) = *ty.kind() && let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(def_id) && let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin && let [GenericBound::Trait(trait_ref)] = &opaque.bounds diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 9b54da5b020e7..cb0565ef60e5a 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -9,7 +9,7 @@ use clippy_utils::{parent_item_name, peel_ref_operators, sym}; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; -use rustc_hir::{BinOpKind, Expr, ExprKind, PatExprKind, PatKind, RustcVersion, StabilityLevel, StableSince}; +use rustc_hir::{BinOpKind, Expr, ExprKind, PatExprKind, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Ty}; use rustc_session::impl_lint_pass; @@ -298,21 +298,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) -> bool { if item.is_fn() { let sig = cx.tcx.fn_sig(item.def_id).skip_binder(); let ty = sig.skip_binder(); - ty.inputs().len() == 1 - && cx.tcx.lookup_stability(item.def_id).is_none_or(|stability| { - if let StabilityLevel::Stable { since, .. } = stability.level { - let version = match since { - StableSince::Version(version) => version, - StableSince::Current => RustcVersion::CURRENT, - StableSince::Err(_) => return false, - }; - - msrv.meets(cx, version) - } else { - // Unstable fn, check if the feature is enabled. - cx.tcx.features().enabled(stability.feature) && msrv.current(cx).is_none() - } - }) + ty.inputs().len() == 1 && msrv.is_stable(cx, item.def_id) } else { false } @@ -336,10 +322,13 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) -> bool { .filter_by_name_unhygienic(sym::is_empty) .any(|item| is_is_empty_and_stable(cx, item, msrv)) }), - &ty::Alias(_, ty::AliasTy { - kind: ty::Projection { def_id }, - .. - }) => has_is_empty_impl(cx, def_id, msrv), + &ty::Alias( + _, + ty::AliasTy { + kind: ty::Projection { def_id }, + .. + }, + ) => has_is_empty_impl(cx, def_id, msrv), ty::Adt(id, _) => { has_is_empty_impl(cx, id.did(), msrv) || (cx.tcx.recursion_limit().value_within_limit(depth) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index a65b27f550995..974abc30db0fd 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -75,6 +75,7 @@ mod assigning_clones; mod async_yields_async; mod attrs; mod await_holding_invalid; +mod bit_width; mod blocks_in_conditions; mod bool_assert_comparison; mod bool_comparison; @@ -454,9 +455,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co // NOTE: Do not add any more pre-expansion passes. These should be removed eventually. // Due to the architecture of the compiler, currently `cfg_attr` attributes on crate // level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass. - store.register_pre_expansion_lint_pass( - Box::new(move || Box::new(attrs::EarlyAttributes::new(conf))) - ); + store.register_pre_expansion_lint_pass(Box::new(move || Box::new(attrs::EarlyAttributes::new(conf)))); let format_args_storage = FormatArgsStorage::default(); let attr_storage = AttrStorage::default(); @@ -497,7 +496,7 @@ rustc_lint::early_lint_methods!( UnnestedOrPatterns: unnested_or_patterns::UnnestedOrPatterns = unnested_or_patterns::UnnestedOrPatterns::new(conf), EarlyFunctions: functions::EarlyFunctions = functions::EarlyFunctions, Documentation: doc::Documentation = doc::Documentation::new(conf), - SuspiciousOperationGroupings: suspicious_operation_groupings::SuspiciousOperationGroupings = suspicious_operation_groupings::SuspiciousOperationGroupings, + SuspiciousOperationGroupings: suspicious_operation_groupings::SuspiciousOperationGroupings = ::default(), DoubleParens: double_parens::DoubleParens = double_parens::DoubleParens, UnsafeNameRemoval: unsafe_removed_from_name::UnsafeNameRemoval = unsafe_removed_from_name::UnsafeNameRemoval, ElseIfWithoutElse: else_if_without_else::ElseIfWithoutElse = else_if_without_else::ElseIfWithoutElse, @@ -506,7 +505,6 @@ rustc_lint::early_lint_methods!( MiscEarlyLints: misc_early::MiscEarlyLints = misc_early::MiscEarlyLints, UnusedUnit: unused_unit::UnusedUnit = unused_unit::UnusedUnit, Precedence: precedence::Precedence = precedence::Precedence, - RedundantElse: redundant_else::RedundantElse = redundant_else::RedundantElse, NeedlessArbitrarySelfType: needless_arbitrary_self_type::NeedlessArbitrarySelfType = needless_arbitrary_self_type::NeedlessArbitrarySelfType, LiteralDigitGrouping: literal_representation::LiteralDigitGrouping = literal_representation::LiteralDigitGrouping::new(conf), DecimalLiteralRepresentation: literal_representation::DecimalLiteralRepresentation = literal_representation::DecimalLiteralRepresentation::new(conf), @@ -731,6 +729,7 @@ rustc_lint::late_lint_methods!( NeedlessLateInit: needless_late_init::NeedlessLateInit<'tcx> = needless_late_init::NeedlessLateInit::new(conf), ReturnSelfNotMustUse: return_self_not_must_use::ReturnSelfNotMustUse = return_self_not_must_use::ReturnSelfNotMustUse, NumberedFields: init_numbered_fields::NumberedFields = init_numbered_fields::NumberedFields, + ManualBitWidth: bit_width::ManualBitWidth = bit_width::ManualBitWidth::new(conf), ManualBits: manual_bits::ManualBits = manual_bits::ManualBits::new(conf), DefaultUnionRepresentation: default_union_representation::DefaultUnionRepresentation = default_union_representation::DefaultUnionRepresentation, OnlyUsedInRecursion: only_used_in_recursion::OnlyUsedInRecursion = ::default(), @@ -761,7 +760,7 @@ rustc_lint::late_lint_methods!( BoolToIntWithIf: bool_to_int_with_if::BoolToIntWithIf = bool_to_int_with_if::BoolToIntWithIf, BoxDefault: box_default::BoxDefault = box_default::BoxDefault, ImplicitSaturatingAdd: implicit_saturating_add::ImplicitSaturatingAdd = implicit_saturating_add::ImplicitSaturatingAdd, - MissingTraitMethods: missing_trait_methods::MissingTraitMethods = missing_trait_methods::MissingTraitMethods, + MissingTraitMethods: missing_trait_methods::MissingTraitMethods = missing_trait_methods::MissingTraitMethods::new(conf), FromRawWithVoidPtr: from_raw_with_void_ptr::FromRawWithVoidPtr = from_raw_with_void_ptr::FromRawWithVoidPtr, ConfusingXorAndPow: suspicious_xor_used_as_pow::ConfusingXorAndPow = suspicious_xor_used_as_pow::ConfusingXorAndPow, ManualIsAsciiCheck: manual_is_ascii_check::ManualIsAsciiCheck = manual_is_ascii_check::ManualIsAsciiCheck::new(conf), @@ -859,6 +858,7 @@ rustc_lint::late_lint_methods!( ManualAssertEq: manual_assert_eq::ManualAssertEq = manual_assert_eq::ManualAssertEq, WithCapacityZero: with_capacity_zero::WithCapacityZero = with_capacity_zero::WithCapacityZero, RefPatterns: ref_patterns::RefPatterns = ref_patterns::RefPatterns, + RedundantElse: redundant_else::RedundantElse = redundant_else::RedundantElse, // add late passes here, used by `cargo dev new_lint` ]] ); diff --git a/clippy_lints/src/loops/explicit_counter_loop.rs b/clippy_lints/src/loops/explicit_counter_loop.rs index b10584fb9bd7c..b74e733c40642 100644 --- a/clippy_lints/src/loops/explicit_counter_loop.rs +++ b/clippy_lints/src/loops/explicit_counter_loop.rs @@ -87,7 +87,7 @@ pub(super) fn check<'tcx>( // If the loop variable is unused and the range is `0..n`, suggest `(init..).take(n)`. if pat_snippet == "_" && let Some(range) = Range::hir(cx, arg) - && range.limits == RangeLimits::HalfOpen + && range.ty.limits() == RangeLimits::HalfOpen && range.start.is_some_and(|start| is_integer_literal(start, 0)) && let Some(end) = range.end { diff --git a/clippy_lints/src/loops/infinite_loop.rs b/clippy_lints/src/loops/infinite_loop.rs index 3a0c2b33c5adf..dbd9deff1c2b6 100644 --- a/clippy_lints/src/loops/infinite_loop.rs +++ b/clippy_lints/src/loops/infinite_loop.rs @@ -178,7 +178,7 @@ impl<'hir> Visitor<'hir> for LoopVisitor<'hir, '_> { self.is_finite = true; } }, - ExprKind::Ret(..) => self.is_finite = true, + ExprKind::Ret(..) | ExprKind::Yield(_, hir::YieldSource::Yield) => self.is_finite = true, ExprKind::Loop(_, label, _, _) => { if let Some(label) = label { self.inner_labels.push(*label); diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index d8c55974fa926..eb1987806416f 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -27,7 +27,7 @@ pub(super) fn check<'tcx>( if let Some(higher::Range { start: Some(start), end: Some(end), - limits, + ty: range_ty, span: _, }) = higher::Range::hir(cx, arg) // the var must be a single name @@ -89,7 +89,11 @@ pub(super) fn check<'tcx>( } }) }) - .map(|o| o.map(|(ty, dst, src)| build_manual_memcpy_suggestion(cx, start, end, limits, ty, &dst, &src))) + .map(|o| { + o.map(|(ty, dst, src)| { + build_manual_memcpy_suggestion(cx, start, end, range_ty.limits(), ty, &dst, &src) + }) + }) .collect::>>() .filter(|v| !v.is_empty()) .map(|v| v.join("\n ")); diff --git a/clippy_lints/src/loops/manual_slice_fill.rs b/clippy_lints/src/loops/manual_slice_fill.rs index ceaf681088399..93c5f21c30ab7 100644 --- a/clippy_lints/src/loops/manual_slice_fill.rs +++ b/clippy_lints/src/loops/manual_slice_fill.rs @@ -30,9 +30,10 @@ pub(super) fn check<'tcx>( if let Some(higher::Range { start: Some(start), end: Some(end), - limits: RangeLimits::HalfOpen, + ty: range_ty, span: _, }) = higher::Range::hir(cx, arg) + && let RangeLimits::HalfOpen = range_ty.limits() && let ExprKind::Lit(Spanned { node: LitKind::Int(Pu128(0), _), .. diff --git a/clippy_lints/src/loops/needless_range_loop.rs b/clippy_lints/src/loops/needless_range_loop.rs index 71280e4b03f8f..0ded5b69f56f8 100644 --- a/clippy_lints/src/loops/needless_range_loop.rs +++ b/clippy_lints/src/loops/needless_range_loop.rs @@ -29,7 +29,7 @@ pub(super) fn check<'tcx>( if let Some(higher::Range { start: Some(start), ref end, - limits, + ty: range_ty, span, }) = higher::Range::hir(cx, arg) // the var must be a single name @@ -114,12 +114,12 @@ pub(super) fn check<'tcx>( end_is_start_plus_val = start_equal_left | start_equal_right; } - if is_len_call(end, indexed) || is_end_eq_array_len(cx, end, limits, indexed_ty) { + if is_len_call(end, indexed) || is_end_eq_array_len(cx, end, range_ty, indexed_ty) { String::new() } else if visitor.indexed_mut.contains(&indexed) && contains_name(indexed, take_expr, cx) { return; } else { - match limits { + match range_ty.limits() { ast::RangeLimits::Closed => { let take_expr = sugg::Sugg::hir(cx, take_expr, ""); format!(".take({})", take_expr + sugg::ONE) @@ -205,7 +205,7 @@ fn is_len_call(expr: &Expr<'_>, var: Symbol) -> bool { fn is_end_eq_array_len<'tcx>( cx: &LateContext<'tcx>, end: &Expr<'_>, - limits: ast::RangeLimits, + range_ty: higher::RangeTy, indexed_ty: Ty<'tcx>, ) -> bool { if let ExprKind::Lit(lit) = end.kind @@ -213,7 +213,7 @@ fn is_end_eq_array_len<'tcx>( && let ty::Array(_, arr_len_const) = indexed_ty.kind() && let Some(arr_len) = arr_len_const.try_to_target_usize(cx.tcx) { - return match limits { + return match range_ty.limits() { ast::RangeLimits::Closed => end_int.get() + 1 >= arr_len.into(), ast::RangeLimits::HalfOpen => end_int.get() >= arr_len.into(), }; diff --git a/clippy_lints/src/manual_is_ascii_check.rs b/clippy_lints/src/manual_is_ascii_check.rs index dd1385e48e977..996b00466de7d 100644 --- a/clippy_lints/src/manual_is_ascii_check.rs +++ b/clippy_lints/src/manual_is_ascii_check.rs @@ -117,9 +117,10 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck { && let Some(higher::Range { start: Some(start), end: Some(end), - limits: RangeLimits::Closed, + ty: range_ty, span: _, }) = higher::Range::hir(cx, receiver) + && let RangeLimits::Closed = range_ty.limits() && !matches!(cx.typeck_results().expr_ty(arg).peel_refs().kind(), ty::Param(_)) { let arg = peel_ref_operators(cx, arg); diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index 459c2bf1fef73..7b9d10cccfef0 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -1111,7 +1111,13 @@ impl<'tcx> LateLintPass<'tcx> for Matches { if source == MatchSource::Normal { let is_match_like_matches = self.msrv.meets(cx, msrvs::MATCHES_MACRO) && match_like_matches::check_match(cx, expr, ex, arms); - if !(is_match_like_matches || is_lint_allowed(cx, MATCH_SAME_ARMS, expr.hir_id)) { + // Even when the lint is allowed on the match expression, an arm can carry its + // own `#[expect]`/`#[warn]` attribute, which `match_same_arms::check` handles + // at arm granularity. Only skip the check when no arm has attributes. + if !(is_match_like_matches + || (is_lint_allowed(cx, MATCH_SAME_ARMS, expr.hir_id) + && arms.iter().all(|arm| cx.tcx.hir_attrs(arm.hir_id).is_empty()))) + { match_same_arms::check(cx, arms); } diff --git a/clippy_lints/src/methods/chunks_exact_to_as_chunks.rs b/clippy_lints/src/methods/chunks_exact_to_as_chunks.rs index e151cf43a5044..ec9fbd4432ab0 100644 --- a/clippy_lints/src/methods/chunks_exact_to_as_chunks.rs +++ b/clippy_lints/src/methods/chunks_exact_to_as_chunks.rs @@ -3,10 +3,10 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; use clippy_utils::source::snippet_with_context; -use clippy_utils::visitors::is_const_evaluatable; +use clippy_utils::visitors::is_const_param_evaluatable; use clippy_utils::{get_expr_use_site, sym}; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, Node, PatKind}; +use rustc_hir::{BlockCheckMode, Expr, ExprKind, Node, PatKind, QPath}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::{DesugaringKind, ExpnKind, Span, Symbol}; @@ -25,25 +25,22 @@ pub(super) fn check<'tcx>( return; } - if is_const_evaluatable(cx.tcx, cx.typeck_results(), arg) { - if !msrv.meets(cx, msrvs::AS_CHUNKS) { - return; - } - + if is_const_param_evaluatable(cx.tcx, cx.typeck_results(), arg) { let use_ctxt = get_expr_use_site(cx.tcx, cx.typeck_results(), expr.span.ctxt(), expr); - if use_ctxt.is_ty_unified { + if use_ctxt.is_ty_unified || !msrv.meets(cx, msrvs::AS_CHUNKS) { return; } - let suggestion_method = if method_name == sym::chunks_exact_mut { - "as_chunks_mut" - } else { - "as_chunks" - }; + let is_mut = method_name == sym::chunks_exact_mut; + let suggestion_method = if is_mut { "as_chunks_mut" } else { "as_chunks" }; + let iter_method = if is_mut { "iter_mut" } else { "iter" }; let mut applicability = Applicability::MachineApplicable; - let arg_str = snippet_with_context(cx, arg.span, expr.span.ctxt(), "_", &mut applicability).0; + let mut arg_str = snippet_with_context(cx, arg.span, expr.span.ctxt(), "_", &mut applicability).0; + if expr_needs_braces_for_const(arg) { + arg_str = std::borrow::Cow::Owned(format!("{{ {arg_str} }}")); + } let as_chunks = format_args!("{suggestion_method}::<{arg_str}>()"); @@ -64,7 +61,7 @@ pub(super) fn check<'tcx>( { diag.span_suggestion( call_span, - "consider using `as_chunks` instead", + format!("consider using `{suggestion_method}` instead"), format!("{as_chunks}.0"), applicability, ); @@ -79,8 +76,8 @@ pub(super) fn check<'tcx>( { diag.span_suggestion( call_span, - "consider using `as_chunks` instead", - format!("{as_chunks}.0.iter()"), + format!("consider using `{suggestion_method}` instead"), + format!("{as_chunks}.0.{iter_method}()"), applicability, ); return; @@ -95,10 +92,28 @@ pub(super) fn check<'tcx>( && let PatKind::Binding(_, _, ident, _) = let_stmt.pat.kind { diag.note(format!( - "you can access the chunks using `{ident}.0.iter()`, and the remainder using `{ident}.1`" + "you can access the chunks using `{ident}.0.{iter_method}()`, and the remainder using `{ident}.1`" )); } }, ); } } + +/// Whether the given expression needs braces to be a syntactically valid const generics argument. +/// +/// For more details, see: +fn expr_needs_braces_for_const(e: &Expr<'_>) -> bool { + match e.kind { + ExprKind::Lit(_) => false, + ExprKind::Block(block, None) => { + // unsafe blocks need braces + block.rules != BlockCheckMode::DefaultBlock + }, + ExprKind::Path(QPath::Resolved(_, p)) => { + // path must be a single segment. E.g. Foo::BAR is not allowed + p.segments.len() != 1 + }, + _ => true, + } +} diff --git a/clippy_lints/src/methods/filter_map_next.rs b/clippy_lints/src/methods/filter_map_next.rs index 698025d58e543..9e55732830bc6 100644 --- a/clippy_lints/src/methods/filter_map_next.rs +++ b/clippy_lints/src/methods/filter_map_next.rs @@ -1,42 +1,33 @@ -use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; -use clippy_utils::source::snippet; +use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; -use rustc_hir as hir; +use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_span::sym; use super::FILTER_MAP_NEXT; -pub(super) fn check<'tcx>( - cx: &LateContext<'tcx>, - expr: &'tcx hir::Expr<'_>, - recv: &'tcx hir::Expr<'_>, - arg: &'tcx hir::Expr<'_>, - msrv: Msrv, -) { - if cx.ty_based_def(expr).opt_parent(cx).is_diag_item(cx, sym::Iterator) { - if !msrv.meets(cx, msrvs::ITERATOR_FIND_MAP) { - return; - } - - let msg = "called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling \ - `.find_map(..)` instead"; - let filter_snippet = snippet(cx, arg.span, ".."); - if filter_snippet.lines().count() <= 1 { - let iter_snippet = snippet(cx, recv.span, ".."); - span_lint_and_sugg( - cx, - FILTER_MAP_NEXT, - expr.span, - msg, - "try", - format!("{iter_snippet}.find_map({filter_snippet})"), - Applicability::MachineApplicable, - ); - } else { - span_lint(cx, FILTER_MAP_NEXT, expr.span, msg); - } +pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<'_>, msrv: Msrv) { + if cx.ty_based_def(expr).opt_parent(cx).is_diag_item(cx, sym::Iterator) && msrv.meets(cx, msrvs::ITERATOR_FIND_MAP) + { + span_lint_and_then( + cx, + FILTER_MAP_NEXT, + expr.span, + "called `filter_map(..).next()` on an `Iterator`", + |diag| { + let mut app = Applicability::MachineApplicable; + let iter_snippet = snippet_with_applicability(cx, recv.span, "_", &mut app); + let filter_snippet = snippet_with_applicability(cx, arg.span, "..", &mut app); + diag.span_suggestion_verbose( + expr.span, + "use `.find_map(..)` instead", + format!("{iter_snippet}.find_map({filter_snippet})"), + app, + ); + }, + ); } } diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs index 4d1a4343c03c3..ff467cb63414d 100644 --- a/clippy_lints/src/methods/iter_next_slice.rs +++ b/clippy_lints/src/methods/iter_next_slice.rs @@ -38,9 +38,10 @@ pub(super) fn check<'tcx>( && let Some(higher::Range { start: Some(start_expr), end: None, - limits: ast::RangeLimits::HalfOpen, + ty: range_ty, span: _, }) = higher::Range::hir(cx, index_expr) + && let ast::RangeLimits::HalfOpen = range_ty.limits() && let hir::ExprKind::Lit(start_lit) = &start_expr.kind && let ast::LitKind::Int(start_idx, _) = start_lit.node { diff --git a/clippy_lints/src/methods/manual_c_str_literals.rs b/clippy_lints/src/methods/manual_c_str_literals.rs index a8445b68dd608..f70a2a3a88c7b 100644 --- a/clippy_lints/src/methods/manual_c_str_literals.rs +++ b/clippy_lints/src/methods/manual_c_str_literals.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::snippet; use clippy_utils::{get_parent_expr, sym}; @@ -31,19 +31,28 @@ pub(super) fn check_as_ptr<'tcx>( && !get_parent_expr(cx, casts_removed).is_some_and( |parent| matches!(parent.kind, ExprKind::Call(func, _) if is_c_str_function(cx, func).is_some()), ) - && let Some(sugg) = rewrite_as_cstr(cx, lit.span) + && let Some(sugg) = rewrite_as_cstr(cx, lit.span, lit.node) && msrv.meets(cx, msrvs::C_STR_LITERALS) { - span_lint_and_sugg( + span_lint_and_then( cx, MANUAL_C_STR_LITERALS, receiver.span, "manually constructing a nul-terminated string", - r#"use a `c""` literal"#, - sugg, - // an additional cast may be needed, since the type of `CStr::as_ptr` and - // `"".as_ptr()` can differ and is platform dependent - Applicability::HasPlaceholders, + |diag| { + diag.span_suggestion( + receiver.span, + r#"use a `c""` literal"#, + sugg, + Applicability::HasPlaceholders, + ); + if casts_removed.hir_id == expr.hir_id { + diag.note( + "an additional cast may be needed, since the type of `c\"\".as_ptr()` \ + and `b\"\".as_ptr()` can differ and is platform dependent", + ); + } + }, ); } } @@ -77,7 +86,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, func: &Expr<'_>, args && let ExprKind::Lit(lit) = arg.kind && let LitKind::ByteStr(_, StrStyle::Cooked) | LitKind::Str(_, StrStyle::Cooked) = lit.node => { - check_from_bytes(cx, expr, arg, fn_name); + check_from_bytes(cx, expr, arg, lit.node, fn_name); }, sym::from_ptr => check_from_ptr(cx, expr, arg), _ => {}, @@ -92,7 +101,7 @@ fn check_from_ptr(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>) { && !lit.span.from_expansion() && let ExprKind::Lit(lit) = lit.kind && let LitKind::ByteStr(_, StrStyle::Cooked) = lit.node - && let Some(sugg) = rewrite_as_cstr(cx, lit.span) + && let Some(sugg) = rewrite_as_cstr(cx, lit.span, lit.node) { span_lint_and_sugg( cx, @@ -106,7 +115,7 @@ fn check_from_ptr(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>) { } } /// Checks `CStr::from_bytes_with_nul(b"foo\0")` -fn check_from_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, method: Symbol) { +fn check_from_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, lit: LitKind, method: Symbol) { let (span, applicability) = if let Some(parent) = get_parent_expr(cx, expr) && let ExprKind::MethodCall(method, ..) = parent.kind && [sym::unwrap, sym::expect].contains(&method.ident.name) @@ -120,7 +129,7 @@ fn check_from_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, metho (expr.span, Applicability::HasPlaceholders) }; - let Some(sugg) = rewrite_as_cstr(cx, arg.span) else { + let Some(sugg) = rewrite_as_cstr(cx, arg.span, lit) else { return; }; @@ -139,7 +148,11 @@ fn check_from_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, metho /// `b"foo\0"` -> `c"foo"` /// /// Returns `None` if it doesn't end in a NUL byte. -fn rewrite_as_cstr(cx: &LateContext<'_>, span: Span) -> Option { +fn rewrite_as_cstr(cx: &LateContext<'_>, span: Span, lit: LitKind) -> Option { + if !is_nul_terminated(lit) { + return None; + } + let mut sugg = String::from("c") + snippet(cx, span.source_callsite(), "..").trim_start_matches('b'); // NUL byte should always be right before the closing quote. @@ -166,6 +179,16 @@ fn rewrite_as_cstr(cx: &LateContext<'_>, span: Span) -> Option { Some(sugg) } +/// Checks whether the `ByteString` or `String` literal ends with a `NUL` character +fn is_nul_terminated(lit: LitKind) -> bool { + match lit { + LitKind::ByteStr(content, _) => content.as_byte_str().last() == Some(&0), + // In UTF-8, no multi-byte character can contain a NUL byte + LitKind::Str(content, _) => content.as_str().as_bytes().last() == Some(&0), + _ => false, + } +} + fn get_cast_target<'tcx>(e: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { match &e.kind { ExprKind::MethodCall(method, receiver, [], _) if method.ident.name == sym::cast => Some(receiver), diff --git a/clippy_lints/src/methods/manual_is_variant_and.rs b/clippy_lints/src/methods/manual_is_variant_and.rs index df209a1671509..8a0da622982c6 100644 --- a/clippy_lints/src/methods/manual_is_variant_and.rs +++ b/clippy_lints/src/methods/manual_is_variant_and.rs @@ -168,6 +168,7 @@ impl<'hir> MapFunc<'hir> { } } +#[expect(clippy::too_many_arguments)] fn emit_lint<'tcx>( cx: &LateContext<'tcx>, span: Span, @@ -176,7 +177,16 @@ fn emit_lint<'tcx>( in_some_or_ok: bool, map_func: MapFunc<'tcx>, recv: &Expr<'_>, + msrv: Msrv, ) { + let required_msrv = match (flavor, op) { + (Flavor::Option, Op::Ne) => msrvs::IS_NONE_OR, + _ => msrvs::OPTION_RESULT_IS_VARIANT_AND, + }; + if !msrv.meets(cx, required_msrv) { + return; + } + let mut app = Applicability::MachineApplicable; let recv = snippet_with_applicability(cx, recv.span, "_", &mut app); @@ -201,7 +211,7 @@ fn emit_lint<'tcx>( ); } -pub(super) fn check_map(cx: &LateContext<'_>, expr: &Expr<'_>) { +pub(super) fn check_map(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) { if let Some(parent_expr) = get_parent_expr(cx, expr) && let ExprKind::Binary(op, left, right) = parent_expr.kind && op.span.eq_ctxt(expr.span) @@ -222,7 +232,7 @@ pub(super) fn check_map(cx: &LateContext<'_>, expr: &Expr<'_>) { && cx.typeck_results().expr_ty(recv).is_diag_item(cx, flavor.diag_sym()) && let Ok(map_func) = MapFunc::try_from(map_expr) { - emit_lint(cx, parent_expr.span, op, flavor, bool_cst, map_func, recv); + emit_lint(cx, parent_expr.span, op, flavor, bool_cst, map_func, recv, msrv); return; } } @@ -263,14 +273,14 @@ pub(super) fn check_or<'tcx>( return; }; - if !msrv.meets(cx, msrvs::IS_NONE_OR) { - return; - } - let Ok(map_func) = MapFunc::try_from(some_arg) else { return; }; + if !msrv.meets(cx, msrvs::IS_NONE_OR) { + return; + } + span_lint_and_then( cx, MANUAL_IS_VARIANT_AND, diff --git a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs index 216ca7dbc27f5..aca065bbc65a5 100644 --- a/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs +++ b/clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs @@ -32,7 +32,7 @@ fn extract_count_with_applicability( { // Here we can explicitly calculate the number of iterations let count = if upper_bound >= lower_bound { - match range.limits { + match range.ty.limits() { RangeLimits::HalfOpen => upper_bound - lower_bound, RangeLimits::Closed => (upper_bound - lower_bound).checked_add(1)?, } @@ -45,12 +45,12 @@ fn extract_count_with_applicability( .maybe_paren() .into_string(); if lower_bound == 0 { - if range.limits == RangeLimits::Closed { + if range.ty.limits() == RangeLimits::Closed { return Some(format!("{end_snippet} + 1")); } return Some(end_snippet); } - if range.limits == RangeLimits::Closed { + if range.ty.limits() == RangeLimits::Closed { return Some(format!("{end_snippet} - {}", lower_bound - 1)); } return Some(format!("{end_snippet} - {lower_bound}")); diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 38a3b1705ad17..ddb2fba94bba9 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3157,7 +3157,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for usage of the `offset` pointer method with a `usize` casted to an + /// Checks for usage of the `offset` pointer method with a `usize` cast to an /// `isize`. /// /// ### Why is this bad? @@ -5598,7 +5598,7 @@ impl Methods { if name == sym::map { map_clone::check(cx, expr, recv, m_arg, self.msrv); map_with_unused_argument_over_ranges::check(cx, expr, recv, m_arg, self.msrv, span); - manual_is_variant_and::check_map(cx, expr); + manual_is_variant_and::check_map(cx, expr, self.msrv); match method_call(recv) { Some((map_name @ (sym::iter | sym::into_iter), recv2, _, _, _)) => { iter_kv_map::check(cx, map_name, expr, recv2, m_arg, self.msrv, sym::map); diff --git a/clippy_lints/src/methods/ptr_offset_by_literal.rs b/clippy_lints/src/methods/ptr_offset_by_literal.rs index 17f81f547aeb0..25d7f05f9a10a 100644 --- a/clippy_lints/src/methods/ptr_offset_by_literal.rs +++ b/clippy_lints/src/methods/ptr_offset_by_literal.rs @@ -12,12 +12,6 @@ use std::fmt; use super::PTR_OFFSET_BY_LITERAL; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Msrv) { - // `pointer::add` and `pointer::wrapping_add` are only stable since 1.26.0. These functions - // became const-stable in 1.61.0, the same version that `pointer::offset` became const-stable. - if !msrv.meets(cx, msrvs::POINTER_ADD_SUB_METHODS) { - return; - } - let ExprKind::MethodCall(method_name, recv, [arg_expr], _) = expr.kind else { return; }; @@ -28,6 +22,12 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Ms _ => return, }; + // `pointer::add` and `pointer::wrapping_add` are only stable since 1.26.0. These functions + // became const-stable in 1.61.0, the same version that `pointer::offset` became const-stable. + if !msrv.meets(cx, msrvs::POINTER_ADD_SUB_METHODS) { + return; + } + if !cx.typeck_results().expr_ty_adjusted(recv).is_raw_ptr() { return; } diff --git a/clippy_lints/src/methods/ptr_offset_with_cast.rs b/clippy_lints/src/methods/ptr_offset_with_cast.rs index d19d3b8eb89d9..8fd0e345ce2c7 100644 --- a/clippy_lints/src/methods/ptr_offset_with_cast.rs +++ b/clippy_lints/src/methods/ptr_offset_with_cast.rs @@ -17,18 +17,18 @@ pub(super) fn check( arg: &Expr<'_>, msrv: Msrv, ) { - // `pointer::add` and `pointer::wrapping_add` are only stable since 1.26.0. These functions - // became const-stable in 1.61.0, the same version that `pointer::offset` became const-stable. - if !msrv.meets(cx, msrvs::POINTER_ADD_SUB_METHODS) { - return; - } - let method = match method { sym::offset => Method::Offset, sym::wrapping_offset => Method::WrappingOffset, _ => return, }; + // `pointer::add` and `pointer::wrapping_add` are only stable since 1.26.0. These functions + // became const-stable in 1.61.0, the same version that `pointer::offset` became const-stable. + if !msrv.meets(cx, msrvs::POINTER_ADD_SUB_METHODS) { + return; + } + if !cx.typeck_results().expr_ty_adjusted(recv).is_raw_ptr() { return; } @@ -43,7 +43,7 @@ pub(super) fn check( return; }; - let msg = format!("use of `{method}` with a `usize` casted to an `isize`"); + let msg = format!("use of `{method}` with a `usize` cast to an `isize`"); span_lint_and_then(cx, PTR_OFFSET_WITH_CAST, expr.span, msg, |diag| { diag.multipart_suggestion( format!("use `{}` instead", method.suggestion()), diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index a9121db33ed44..9c6f307cc6594 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -544,19 +544,15 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< } let mut trait_clauses = - cx.tcx - .param_env(callee_def_id) - .caller_bounds() - .iter() - .filter(|clause| { - if let ClauseKind::Trait(trait_predicate) = clause.kind().skip_binder() - && trait_predicate.trait_ref.self_ty() == param_ty - { - true - } else { - false - } - }); + cx.tcx.param_env(callee_def_id).caller_bounds().iter().filter(|clause| { + if let ClauseKind::Trait(trait_predicate) = clause.kind().skip_binder() + && trait_predicate.trait_ref.self_ty() == param_ty + { + true + } else { + false + } + }); let new_subst = cx .tcx diff --git a/clippy_lints/src/methods/unnecessary_unwrap_unchecked.rs b/clippy_lints/src/methods/unnecessary_unwrap_unchecked.rs index 3f7f146446361..0a13bffa733e2 100644 --- a/clippy_lints/src/methods/unnecessary_unwrap_unchecked.rs +++ b/clippy_lints/src/methods/unnecessary_unwrap_unchecked.rs @@ -188,13 +188,13 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, recv: return; } let expected_ret_ty = cx.typeck_results().expr_ty(expr); - let (variant, checked_span, unchecked_sugg, unchecked_full_path) = match recv.kind { + let (variant, checked_span, unchecked_sugg, unchecked_full_path, unchecked_def_id) = match recv.kind { // Construct `Variant::Fn(_)`, if applicable. This is necessary for us to handle // functions like `std::str::from_utf8_unchecked`. ExprKind::Call(path, _) if let ExprKind::Path(qpath) = path.kind && let checked_ident = last_path_segment(&qpath).ident - && let checked_def_id = path.res(cx).def_id() + && let Some(checked_def_id) = path.res(cx).opt_def_id() && let Some((unchecked_def_id, unchecked_ident)) = find_unchecked_sibling_fn(cx, checked_def_id, checked_ident) && same_functions_modulo_safety(cx, checked_def_id, unchecked_def_id, expected_ret_ty) => @@ -213,6 +213,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, recv: unchecked_ident.to_string() }, unchecked_full_path, + unchecked_def_id, ) }, // We unfortunately must handle `A::a(&a)` and `a.a()` separately, this handles the @@ -220,7 +221,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, recv: ExprKind::Call(path, _) if let ExprKind::Path(qpath) = path.kind && let checked_ident = last_path_segment(&qpath).ident - && let checked_def_id = path.res(cx).def_id() + && let Some(checked_def_id) = path.res(cx).opt_def_id() && let Some((unchecked, unchecked_ident)) = find_unchecked_sibling_method(cx, checked_def_id, checked_ident) && let ty::AssocKind::Fn { has_self, .. } = unchecked.kind @@ -233,6 +234,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, recv: checked_ident.span, unchecked_ident.to_string(), unchecked_full_path, + unchecked.def_id, ) }, // ... And now the latter ^^ @@ -250,11 +252,17 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, recv: checked_ident.span, unchecked_ident.to_string(), unchecked_full_path, + unchecked.def_id, ) }, _ => return, }; + // Do not lint from inside the `_unchecked` function itself + if unchecked_def_id.as_local() == Some(expr.hir_id.owner.def_id) { + return; + } + if !is_from_proc_macro(cx, expr) { span_lint_and_then(cx, UNNECESSARY_UNWRAP_UNCHECKED, expr.span, variant.msg(), |diag| { let sugg = vec![ diff --git a/clippy_lints/src/missing_asserts_for_indexing.rs b/clippy_lints/src/missing_asserts_for_indexing.rs index 885e0c4ed527d..005f1c929a9a1 100644 --- a/clippy_lints/src/missing_asserts_for_indexing.rs +++ b/clippy_lints/src/missing_asserts_for_indexing.rs @@ -221,13 +221,11 @@ fn upper_index_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { && let LitKind::Int(Pu128(index), _) = lit.node { Some(index as usize) - } else if let Some(Range { - end: Some(end), limits, .. - }) = Range::hir(cx, expr) + } else if let Some(Range { end: Some(end), ty, .. }) = Range::hir(cx, expr) && let ExprKind::Lit(lit) = &end.kind && let LitKind::Int(Pu128(index @ 1..), _) = lit.node { - match limits { + match ty.limits() { RangeLimits::HalfOpen => Some(index as usize - 1), RangeLimits::Closed => Some(index as usize), } diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index 95c02751f8619..743b5123fed6d 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -213,7 +213,8 @@ fn fn_inputs_has_impl_trait_ty(cx: &LateContext<'_>, def_id: LocalDefId) -> bool inputs.iter().any(|input| { matches!( input.kind(), - &ty::Alias(_, ty::AliasTy { kind: ty::Free{def_id} , ..}) if cx.tcx.type_of(def_id).skip_binder().is_opaque() + &ty::Alias(_, ty::AliasTy { kind: ty::Free{def_id} , ..}) + if cx.tcx.type_of(def_id).skip_binder().is_opaque() ) }) } diff --git a/clippy_lints/src/missing_trait_methods.rs b/clippy_lints/src/missing_trait_methods.rs index 332d31feeecfb..a024088c7baf8 100644 --- a/clippy_lints/src/missing_trait_methods.rs +++ b/clippy_lints/src/missing_trait_methods.rs @@ -1,11 +1,13 @@ +use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_lint_allowed; use clippy_utils::macros::span_is_local; +use clippy_utils::msrvs::Msrv; use clippy_utils::source::snippet_opt; use rustc_hir::def_id::DefIdSet; use rustc_hir::{Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::declare_lint_pass; +use rustc_session::impl_lint_pass; declare_clippy_lint! { /// ### What it does @@ -56,7 +58,17 @@ declare_clippy_lint! { "trait implementation uses default provided method" } -declare_lint_pass!(MissingTraitMethods => [MISSING_TRAIT_METHODS]); +impl_lint_pass!(MissingTraitMethods => [MISSING_TRAIT_METHODS]); + +pub struct MissingTraitMethods { + msrv: Msrv, +} + +impl MissingTraitMethods { + pub fn new(conf: &'static Conf) -> Self { + Self { msrv: conf.msrv } + } +} impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { @@ -79,6 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods { .tcx .provided_trait_methods(trait_id) .filter(|assoc| !trait_item_ids.contains(&assoc.def_id)) + .filter(|assoc| self.msrv.is_stable(cx, assoc.def_id)) { span_lint_and_then( cx, diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index 588afd85afb02..a4750a271ff78 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -1,13 +1,11 @@ -use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; -use clippy_utils::higher; -use clippy_utils::source::snippet_with_applicability; -use clippy_utils::sugg::Sugg; -use rustc_data_structures::fx::FxHashSet; +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::source::walk_span_to_context; use rustc_errors::Applicability; -use rustc_hir::{self as hir, AmbigArg, BorrowKind, Expr, ExprKind, HirId, Mutability, TyKind, intravisit}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_hir::{self as hir, AmbigArg, BorrowKind, Expr, ExprKind, HirId, Mutability, TyKind}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::impl_lint_pass; +use rustc_span::ExpnKind; declare_clippy_lint! { /// ### What it does @@ -44,136 +42,99 @@ impl_lint_pass!(MutMut => [MUT_MUT]); #[derive(Default)] pub(crate) struct MutMut { - seen_tys: FxHashSet, + skip_id: Option, } impl<'tcx> LateLintPass<'tcx> for MutMut { - fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) { - intravisit::walk_block(&mut MutVisitor { cx }, block); - } - - fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'_, AmbigArg>) { - if let TyKind::Ref(_, mty) = ty.kind - && mty.mutbl == Mutability::Mut - && let TyKind::Ref(_, mty2) = mty.ty.kind - && mty2.mutbl == Mutability::Mut - && !ty.span.in_external_macro(cx.sess().source_map()) + fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { + if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, base) = e.kind + && let ctxt = e.span.ctxt() + && ctxt == base.span.ctxt() { - if self.seen_tys.contains(&ty.hir_id) { - // we have 2+ `&mut`s, e.g., `&mut &mut &mut x` - // and we have already flagged on the outermost `&mut &mut (&mut x)`, - // so don't flag the inner `&mut &mut (x)` + if self.skip_id.replace(base.hir_id) == Some(e.hir_id) { return; } - // if there is an even longer chain, like `&mut &mut &mut x`, suggest peeling off - // all extra ones at once - let (mut t, mut t2) = (mty.ty, mty2.ty); - let mut many_muts = false; - loop { - // this should allow us to remember all the nested types, so that the `contains` - // above fails faster - self.seen_tys.insert(t.hir_id); - if let TyKind::Ref(_, next) = t2.kind - && next.mutbl == Mutability::Mut + if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, mut base2) = base.kind { + while let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, next) = base2.kind + && ctxt == base2.span.ctxt() { - (t, t2) = (t2, next.ty); - many_muts = true; - } else { - break; + base2 = next; } + if !ctxt.in_external_macro(cx.tcx.sess.source_map()) + && let Some(sp) = walk_span_to_context(base2.span, ctxt) + { + span_lint_and_then( + cx, + MUT_MUT, + e.span.until(sp), + "multiple successive mutable borrows", + |diag| { + diag.span_suggestion_verbose( + base.span.until(sp), + "make only a single borrow", + "", + Applicability::MaybeIncorrect, + ); + }, + ); + } + } else if let ty::Ref(_, ty, Mutability::Mut) = *cx.typeck_results().expr_ty(base).kind() + && ty.peel_refs().is_sized(cx.tcx, cx.typing_env()) + && !ctxt.in_external_macro(cx.tcx.sess.source_map()) + // Don't lint on the explicit borrow in for-loop desugarings. + && !matches!(ctxt.outer_expn_data().kind, ExpnKind::Desugaring(_)) + && let Some(sp) = walk_span_to_context(base.span, ctxt) + { + span_lint_and_then(cx, MUT_MUT, e.span.until(sp), "borrow of a mutable reference", |diag| { + diag.span_suggestion_verbose( + sp.shrink_to_lo(), + "reborrow instead", + "*", + Applicability::MaybeIncorrect, + ); + }); } - - let mut applicability = Applicability::MaybeIncorrect; - let sugg = snippet_with_applicability(cx.sess(), t.span, "..", &mut applicability); - let suffix = if many_muts { "s" } else { "" }; - span_lint_and_sugg( - cx, - MUT_MUT, - ty.span, - "a type of form `&mut &mut _`", - format!("remove the extra `&mut`{suffix}"), - sugg.to_string(), - applicability, - ); } } -} -pub struct MutVisitor<'a, 'tcx> { - cx: &'a LateContext<'tcx>, -} - -impl<'tcx> intravisit::Visitor<'tcx> for MutVisitor<'_, 'tcx> { - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - if expr.span.in_external_macro(self.cx.sess().source_map()) { - return; - } + fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'_, AmbigArg>) { + if let TyKind::Ref(_, base) = ty.kind + && base.mutbl.is_mut() + && let ctxt = ty.span.ctxt() + && ctxt == base.ty.span.ctxt() + { + if self.skip_id.replace(base.ty.hir_id) == Some(ty.hir_id) { + return; + } - if let Some(higher::ForLoop { arg, body, .. }) = higher::ForLoop::hir(expr) { - // A `for` loop lowers to: - // ```rust - // match ::std::iter::Iterator::next(&mut iter) { - // // ^^^^ - // ``` - // Let's ignore the generated code. - intravisit::walk_expr(self, arg); - intravisit::walk_expr(self, body); - } else if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, e) = expr.kind { - if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, e2) = e.kind { - if !expr.span.eq_ctxt(e.span) { - return; + if let TyKind::Ref(_, mut base2) = base.ty.kind + && base2.mutbl.is_mut() + { + while let TyKind::Ref(_, next) = base2.ty.kind + && next.mutbl.is_mut() + && ctxt == base2.ty.span.ctxt() + { + base2 = next; } - - // if there is an even longer chain, like `&mut &mut &mut x`, suggest peeling off - // all extra ones at once - let (mut e, mut e2) = (e, e2); - let mut many_muts = false; - loop { - if !e.span.eq_ctxt(e2.span) { - return; - } - if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, next) = e2.kind { - (e, e2) = (e2, next); - many_muts = true; - } else { - break; - } + if !ctxt.in_external_macro(cx.tcx.sess.source_map()) + && let Some(sp) = walk_span_to_context(base2.ty.span, ctxt) + { + span_lint_and_then( + cx, + MUT_MUT, + ty.span.until(sp), + "multiple successive mutable references", + |diag| { + diag.span_suggestion_verbose( + base.ty.span.until(sp), + "use only a single mutable reference", + "", + Applicability::MaybeIncorrect, + ); + }, + ); } - - let mut applicability = Applicability::MaybeIncorrect; - let sugg = Sugg::hir_with_applicability(self.cx, e, "..", &mut applicability); - let suffix = if many_muts { "s" } else { "" }; - span_lint_hir_and_then( - self.cx, - MUT_MUT, - expr.hir_id, - expr.span, - "an expression of form `&mut &mut _`", - |diag| { - diag.span_suggestion( - expr.span, - format!("remove the extra `&mut`{suffix}"), - sugg, - applicability, - ); - }, - ); - } else if let ty::Ref(_, ty, Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind() - && ty.peel_refs().is_sized(self.cx.tcx, self.cx.typing_env()) - { - let mut applicability = Applicability::MaybeIncorrect; - let sugg = Sugg::hir_with_applicability(self.cx, e, "..", &mut applicability).mut_addr_deref(); - span_lint_hir_and_then( - self.cx, - MUT_MUT, - expr.hir_id, - expr.span, - "this expression mutably borrows a mutable reference", - |diag| { - diag.span_suggestion(expr.span, "reborrow instead", sugg, applicability); - }, - ); } } } diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index 7da507c6d395e..0ccef99d2eca2 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_with_context; use clippy_utils::sugg::Sugg; use clippy_utils::{ @@ -112,33 +112,34 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBool { && !span_contains_comment(cx, e.span) { let reduce = |ret, not| { - let mut applicability = Applicability::MachineApplicable; - let snip = Sugg::hir_with_context(cx, cond, e.span.ctxt(), "", &mut applicability); - let mut snip = if not { !snip } else { snip }; - - if ret { - snip = snip.make_return(); - } - - if is_else_clause(cx.tcx, e) { - snip = snip.blockify(); - } - - if (condition_needs_parentheses(cond) && is_parent_stmt(cx, e.hir_id)) - || is_receiver_of_method_call(cx, e) - || is_as_argument(cx, e) - { - snip = snip.maybe_paren(); - } - - span_lint_and_sugg( + span_lint_and_then( cx, NEEDLESS_BOOL, e.span, "this if-then-else expression returns a bool literal", - "you can reduce it to", - snip.to_string(), - applicability, + |diag| { + let mut applicability = Applicability::MachineApplicable; + let snip = Sugg::hir_with_context(cx, cond, e.span.ctxt(), "", &mut applicability); + let mut snip = if not { !snip } else { snip }; + + if ret { + snip = snip.make_return(); + } + + if is_else_clause(cx.tcx, e) { + snip = snip.blockify(); + } + + if (condition_needs_parentheses(cond) && is_parent_stmt(cx, e.hir_id)) + || is_receiver_of_method_call(cx, e) + || is_as_argument(cx, e) + || is_operand_of_binary_or_unary(cx, e) + { + snip = snip.maybe_paren(); + } + + diag.span_suggestion(e.span, "you can reduce it to", snip.to_string(), applicability); + }, ); }; if let Some(a) = fetch_bool_block(then) @@ -231,3 +232,10 @@ fn fetch_assign<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<(&'tcx Expr<'tcx>, bool) fn is_as_argument(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { matches!(get_parent_expr(cx, e).map(|e| e.kind), Some(ExprKind::Cast(_, _))) } + +fn is_operand_of_binary_or_unary(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { + matches!( + get_parent_expr(cx, e).map(|e| e.kind), + Some(ExprKind::Binary(..) | ExprKind::Unary(..)) + ) +} diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index 1288b639d4809..b82c6c171e37f 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -357,9 +357,8 @@ fn is_mixed_projection_predicate<'tcx>( }, } } - } else { - false } + false } fn referent_used_exactly_once<'tcx>( diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 430b6f055f5f3..7a3c304a3ad3f 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -179,7 +179,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { impl_item.span, format!("you should consider adding a `Default` implementation for `{self_type_snip}`"), |diag| { - diag.suggest_prepend_item( + diag.suggest_append_item( cx, item.span, "try adding this", diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index 933ad716446f2..e471d42679fc5 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -341,10 +341,15 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option reduce_expression(cx, inner).or_else(|| Some(vec![inner])), + | ExprKind::AddrOf(_, _, inner) + // accessing a field of type `!` makes the statement unreachable in + // the eye of the type checker, so don't remove it + if !cx.typeck_results().expr_ty(expr).is_never() => { + reduce_expression(cx, inner).or_else(|| Some(vec![inner])) + } ExprKind::Cast(inner, _) if expr_type_is_certain(cx, inner) => { reduce_expression(cx, inner).or_else(|| Some(vec![inner])) - }, + } ExprKind::Struct(_, fields, ref base) => { if has_drop(cx, cx.typeck_results().expr_ty(expr)) { None diff --git a/clippy_lints/src/operators/bit_mask.rs b/clippy_lints/src/operators/bit_mask.rs index 1607d23e6a335..3190177258c19 100644 --- a/clippy_lints/src/operators/bit_mask.rs +++ b/clippy_lints/src/operators/bit_mask.rs @@ -1,179 +1,278 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; -use clippy_utils::diagnostics::span_lint; +use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; +use clippy_utils::source::walk_span_to_context; +use core::cmp::Ordering; +use core::convert::identity; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_span::Span; +use rustc_middle::ty; use super::{BAD_BIT_MASK, INEFFECTIVE_BIT_MASK}; pub(super) fn check<'tcx>( cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, - op: BinOpKind, - left: &'tcx Expr<'_>, - right: &'tcx Expr<'_>, + cmp_op: BinOpKind, + lhs: &'tcx Expr<'_>, + rhs: &'tcx Expr<'_>, ) { - if op.is_comparison() { - if let Some(cmp_opt) = fetch_int_literal(cx, right) { - check_compare(cx, left, op, cmp_opt, e.span); - } else if let Some(cmp_val) = fetch_int_literal(cx, left) { - check_compare(cx, right, invert_cmp(op), cmp_val, e.span); + let Some(cmp_op) = CmpOp::from_bin_op(cmp_op) else { + return; + }; + + // Check for a bitwise op compared to a constant. + let typeck = cx.typeck_results(); + let ecx = ConstEvalCtxt::new(cx); + let ctxt = e.span.ctxt(); + let Some((cmp_op, bit_op, bit_lhs, bit_rhs, cmp_val)) = try_maybe_swap( + lhs, + rhs, + |lhs, rhs| { + if let ExprKind::Binary(bit_op, bit_lhs, bit_rhs) = lhs.kind + && let bit_sp = bit_op.span + && let Some(bit_op) = BitOp::from_bin_op(bit_op.node) + && matches!(typeck.expr_ty(rhs).peel_refs().kind(), ty::Uint(_) | ty::Int(_)) + && bit_sp.ctxt() == ctxt + && let Some(Constant::Int(cmp_val)) = ecx.eval(rhs) + && walk_span_to_context(rhs.span, ctxt).is_some() + { + Some((cmp_op, bit_op, bit_lhs, bit_rhs, cmp_val)) + } else { + None + } + }, + |r| (r.0.swap_operands(), r.1, r.2, r.3, r.4), + ) else { + return; + }; + + if !ctxt.in_external_macro(cx.tcx.sess.source_map()) + && let ty = typeck.expr_ty(bit_lhs).peel_refs() + && matches!(ty.kind(), ty::Uint(_) | ty::Int(_)) + && matches!(typeck.expr_ty(bit_rhs).peel_refs().kind(), ty::Uint(_) | ty::Int(_)) + && let Some(Constant::Int(op_val)) = try_maybe_swap( + bit_lhs, + bit_rhs, + |_, e| ecx.eval(e).filter(|_| walk_span_to_context(e.span, ctxt).is_some()), + identity, + ) + { + let (lint, msg, note) = if matches!(bit_op, BitOp::And) && op_val == 0 { + let is_eq = cmp_op.matches_ordering(0.cmp(&cmp_val)); + (BAD_BIT_MASK, LintMsg::from_cmp_result(is_eq), NoteMsg::AndZero) + } else { + match cmp_op.kind { + CmpOpKind::Eq => { + let help_msg = match bit_op { + BitOp::And if op_val & cmp_val != cmp_val => NoteMsg::OpMissingBits, + BitOp::Or if op_val | cmp_val != cmp_val => NoteMsg::OpExtraBits, + _ => return, + }; + (BAD_BIT_MASK, LintMsg::from_cmp_result(cmp_op.negate), help_msg) + }, + CmpOpKind::Lt if matches!(ty.kind(), ty::Uint(_)) => match bit_op { + BitOp::And if op_val < cmp_val => { + (BAD_BIT_MASK, LintMsg::from_cmp_result(!cmp_op.negate), NoteMsg::OpLt) + }, + BitOp::Or if op_val >= cmp_val => { + (BAD_BIT_MASK, LintMsg::from_cmp_result(cmp_op.negate), NoteMsg::OpGe) + }, + BitOp::Xor if op_val == 0 && cmp_val == 0 => ( + BAD_BIT_MASK, + LintMsg::from_cmp_result(cmp_op.negate), + NoteMsg::XorCmpZero, + ), + BitOp::Xor | BitOp::Or if u128::MAX.wrapping_shl(cmp_val.trailing_zeros()) & op_val == 0 => ( + INEFFECTIVE_BIT_MASK, + LintMsg::Ineffective, + NoteMsg::OpBitsInTrailingZeros, + ), + _ => return, + }, + CmpOpKind::Gt if matches!(ty.kind(), ty::Uint(_)) => match bit_op { + BitOp::And if op_val <= cmp_val => { + (BAD_BIT_MASK, LintMsg::from_cmp_result(!cmp_op.negate), NoteMsg::OpLe) + }, + BitOp::Or if op_val > cmp_val => { + (BAD_BIT_MASK, LintMsg::from_cmp_result(cmp_op.negate), NoteMsg::OpGt) + }, + BitOp::Xor | BitOp::Or if u128::MAX.unbounded_shl(cmp_val.trailing_ones()) & op_val == 0 => ( + INEFFECTIVE_BIT_MASK, + LintMsg::Ineffective, + NoteMsg::OpBitsInTrailingOnes, + ), + _ => return, + }, + CmpOpKind::Lt | CmpOpKind::Gt => return, + } + }; + + if !is_from_proc_macro(cx, e) { + #[expect(clippy::collapsible_span_lint_calls)] + span_lint_and_then(cx, lint, e.span, msg.to_str(), |diag| { + diag.note(note.to_string(op_val, cmp_val)); + }); } } } -#[must_use] -fn invert_cmp(cmp: BinOpKind) -> BinOpKind { - match cmp { - BinOpKind::Eq => BinOpKind::Eq, - BinOpKind::Ne => BinOpKind::Ne, - BinOpKind::Lt => BinOpKind::Gt, - BinOpKind::Gt => BinOpKind::Lt, - BinOpKind::Le => BinOpKind::Ge, - BinOpKind::Ge => BinOpKind::Le, - _ => BinOpKind::Or, // Dummy +fn try_maybe_swap( + lhs: &T, + rhs: &T, + mut f: impl FnMut(&T, &T) -> Option, + inv: impl FnOnce(R) -> R, +) -> Option { + if let Some(x) = f(lhs, rhs) { + Some(x) + } else { + f(rhs, lhs).map(inv) } } -fn check_compare<'a>(cx: &LateContext<'a>, bit_op: &Expr<'a>, cmp_op: BinOpKind, mut cmp_value: u128, span: Span) { - if let ExprKind::Binary(op, left, right) = &bit_op.kind { - if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr || is_from_proc_macro(cx, bit_op) { - return; +#[derive(Clone, Copy)] +struct CmpOp { + pub kind: CmpOpKind, + pub negate: bool, +} +impl CmpOp { + fn from_bin_op(op: BinOpKind) -> Option { + match op { + BinOpKind::Eq => Some(Self { + kind: CmpOpKind::Eq, + negate: false, + }), + BinOpKind::Lt => Some(Self { + kind: CmpOpKind::Lt, + negate: false, + }), + BinOpKind::Le => Some(Self { + kind: CmpOpKind::Gt, + negate: true, + }), + BinOpKind::Ne => Some(Self { + kind: CmpOpKind::Eq, + negate: true, + }), + BinOpKind::Ge => Some(Self { + kind: CmpOpKind::Lt, + negate: true, + }), + BinOpKind::Gt => Some(Self { + kind: CmpOpKind::Gt, + negate: false, + }), + _ => None, } - if let Some(mask) = fetch_int_literal(cx, right).or_else(|| fetch_int_literal(cx, left)) { - let ty = cx.typeck_results().expr_ty(bit_op); - if ty.is_primitive() - && !ty.is_ptr_sized_integral() - && let bits = ty.primitive_size(cx.tcx) - { - // Strip high bits that don't fit into the result type as they won't be used in the comparison - cmp_value &= bits.unsigned_int_max(); - } - check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span); + } + + fn swap_operands(self) -> Self { + Self { + kind: self.kind.swap_operands(), + negate: self.negate, } } + + fn matches_ordering(self, ord: Ordering) -> bool { + let res = matches!( + (self.kind, ord), + (CmpOpKind::Lt, Ordering::Less) | (CmpOpKind::Eq, Ordering::Equal) | (CmpOpKind::Gt, Ordering::Greater) + ); + if self.negate { !res } else { res } + } } -fn check_bit_mask( - cx: &LateContext<'_>, - bit_op: BinOpKind, - cmp_op: BinOpKind, - mask_value: u128, - cmp_value: u128, - span: Span, -) { - match cmp_op { - BinOpKind::Eq | BinOpKind::Ne => match bit_op { - BinOpKind::BitAnd => { - if mask_value & cmp_value != cmp_value { - if cmp_value != 0 { - span_lint( - cx, - BAD_BIT_MASK, - span, - format!("incompatible bit mask: `_ & {mask_value}` can never be equal to `{cmp_value}`"), - ); - } - } else if mask_value == 0 { - span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero"); - } - }, - BinOpKind::BitOr if mask_value | cmp_value != cmp_value => { - span_lint( - cx, - BAD_BIT_MASK, - span, - format!("incompatible bit mask: `_ | {mask_value}` can never be equal to `{cmp_value}`"), - ); - }, - _ => (), - }, - BinOpKind::Lt | BinOpKind::Ge => match bit_op { - BinOpKind::BitAnd => { - if mask_value < cmp_value { - span_lint( - cx, - BAD_BIT_MASK, - span, - format!("incompatible bit mask: `_ & {mask_value}` will always be lower than `{cmp_value}`"), - ); - } else if mask_value == 0 { - span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero"); - } +#[derive(Clone, Copy)] +enum CmpOpKind { + Eq, + Lt, + Gt, +} +impl CmpOpKind { + fn swap_operands(self) -> Self { + match self { + Self::Eq => Self::Eq, + Self::Lt => Self::Gt, + Self::Gt => Self::Lt, + } + } +} + +#[derive(Clone, Copy)] +enum BitOp { + Xor, + And, + Or, +} +impl BitOp { + fn from_bin_op(op: BinOpKind) -> Option { + match op { + BinOpKind::BitXor => Some(Self::Xor), + BinOpKind::BitAnd => Some(Self::And), + BinOpKind::BitOr => Some(Self::Or), + _ => None, + } + } +} + +#[derive(Clone, Copy)] +enum NoteMsg { + AndZero, + XorCmpZero, + OpMissingBits, + OpExtraBits, + OpLt, + OpLe, + OpGt, + OpGe, + OpBitsInTrailingZeros, + OpBitsInTrailingOnes, +} +impl NoteMsg { + pub fn to_string(self, op_val: u128, cmp_val: u128) -> String { + match self { + Self::AndZero => "`_ & 0` is always equal to zero".to_owned(), + Self::XorCmpZero => "with constants resolved this is `_ ^ 0 < 0`".to_owned(), + Self::OpMissingBits => { + format!("`0x{op_val:x}` is missing bits contained in the compared constant `0x{cmp_val:x}`") }, - BinOpKind::BitOr => { - if mask_value >= cmp_value { - span_lint( - cx, - BAD_BIT_MASK, - span, - format!("incompatible bit mask: `_ | {mask_value}` will never be lower than `{cmp_value}`"), - ); - } else { - check_ineffective_lt(cx, span, mask_value, cmp_value, "|"); - } + Self::OpExtraBits => { + format!("`0x{op_val:x}` has bits not contained in the compared constant `0x{cmp_val:x}`") }, - BinOpKind::BitXor => check_ineffective_lt(cx, span, mask_value, cmp_value, "^"), - _ => (), - }, - BinOpKind::Le | BinOpKind::Gt => match bit_op { - BinOpKind::BitAnd => { - if mask_value <= cmp_value { - span_lint( - cx, - BAD_BIT_MASK, - span, - format!("incompatible bit mask: `_ & {mask_value}` will never be higher than `{cmp_value}`"), - ); - } else if mask_value == 0 { - span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero"); - } + Self::OpLt => format!("`0x{op_val:x}` is less than the compared constant `0x{cmp_val:x}`"), + Self::OpLe => { + format!("`0x{op_val:x}` is less than or equal to the compared constant `0x{cmp_val:x}`") }, - BinOpKind::BitOr => { - if mask_value > cmp_value { - span_lint( - cx, - BAD_BIT_MASK, - span, - format!("incompatible bit mask: `_ | {mask_value}` will always be higher than `{cmp_value}`"), - ); - } else { - check_ineffective_gt(cx, span, mask_value, cmp_value, "|"); - } + Self::OpGt => format!("`0x{op_val:x}` is greater than the compared constant `0x{cmp_val:x}`"), + Self::OpGe => { + format!("`0x{op_val:x}` is greater than or equal to the compared constant `0x{cmp_val:x}`") }, - BinOpKind::BitXor => check_ineffective_gt(cx, span, mask_value, cmp_value, "^"), - _ => (), - }, - _ => (), + Self::OpBitsInTrailingZeros => format!( + "`0x{op_val:x}` contains only bits in the trailing zeros of the compared constant `0x{cmp_val:x}`" + ), + Self::OpBitsInTrailingOnes => format!( + "`0x{op_val:x}` contains only bits in the trailing ones of the compared constant `0x{cmp_val:x}`" + ), + } } } -fn check_ineffective_lt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: &str) { - if c.is_power_of_two() && m < c { - span_lint( - cx, - INEFFECTIVE_BIT_MASK, - span, - format!("ineffective bit mask: `x {op} {m}` compared to `{c}`, is the same as x compared directly"), - ); - } +#[derive(Clone, Copy)] +enum LintMsg { + AlwaysTrue, + AlwaysFalse, + Ineffective, } - -fn check_ineffective_gt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: &str) { - if (c + 1).is_power_of_two() && m <= c { - span_lint( - cx, - INEFFECTIVE_BIT_MASK, - span, - format!("ineffective bit mask: `x {op} {m}` compared to `{c}`, is the same as x compared directly"), - ); +impl LintMsg { + fn from_cmp_result(res: bool) -> Self { + if res { Self::AlwaysTrue } else { Self::AlwaysFalse } } -} -fn fetch_int_literal(cx: &LateContext<'_>, lit: &Expr<'_>) -> Option { - match ConstEvalCtxt::new(cx).eval(lit)? { - Constant::Int(n) => Some(n), - _ => None, + fn to_str(self) -> &'static str { + match self { + Self::AlwaysTrue => "this comparison is always true", + Self::AlwaysFalse => "this comparison is always false", + Self::Ineffective => "this comparison's result is unaffected by the bitwise operation", + } } } diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 66fa9f34473eb..f3ab0f82f224a 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -523,11 +523,11 @@ fn check_range_switch<'tcx>( if let higher::Range { start, end: Some(end), - limits, + ty, span, } = *range && span.can_be_used_for_suggestions() - && limits == kind + && ty.limits() == kind && let Some(y) = predicate(end) && can_switch_ranges(cx, span.ctxt(), expr, kind, cx.typeck_results().expr_ty(y)) { @@ -590,7 +590,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>, range: &hig if let higher::Range { start: Some(start), end: Some(end), - limits, + ty: range_ty, span, } = *range && let ty = cx.typeck_results().expr_ty(start) @@ -599,7 +599,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>, range: &hig && let Some(start_idx) = ecx.eval(start) && let Some(end_idx) = ecx.eval(end) && let Some(ordering) = Constant::partial_cmp(cx.tcx, ty, &start_idx, &end_idx) - && is_empty_range(limits, ordering) + && is_empty_range(range_ty.limits(), ordering) { if inside_indexing_expr(cx, expr) { // Avoid linting `N..N` as it has proven to be useful, see #5689 and #5628 ... @@ -622,7 +622,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>, range: &hig if ordering != Ordering::Equal { let start_snippet = snippet(cx, start.span, "_"); let end_snippet = snippet(cx, end.span, "_"); - let dots = match limits { + let dots = match range_ty.limits() { RangeLimits::HalfOpen => "..", RangeLimits::Closed => "..=", }; diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 79353dc9247e0..148290b4faec4 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -1,11 +1,12 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::{indent_of, reindent_multiline, snippet}; -use rustc_ast::ast::{Block, Expr, ExprKind, Stmt, StmtKind}; -use rustc_ast::visit::{Visitor, walk_expr}; +use clippy_utils::diagnostics::span_lint_hir_and_then; +use clippy_utils::is_from_proc_macro; +use clippy_utils::source::{SpanExt, indent_of, reindent_multiline}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_hir::{Block, Expr, ExprKind, MatchSource, Stmt, StmtKind}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::TypeckResults; use rustc_session::declare_lint_pass; -use rustc_span::Span; +use rustc_span::{ExpnKind, SyntaxContext}; declare_clippy_lint! { /// ### What it does @@ -46,125 +47,147 @@ declare_clippy_lint! { declare_lint_pass!(RedundantElse => [REDUNDANT_ELSE]); -impl EarlyLintPass for RedundantElse { - fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &Stmt) { - if stmt.span.in_external_macro(cx.sess().source_map()) { - return; - } - // Only look at expressions that are a whole statement - let expr: &Expr = match &stmt.kind { - StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr, - _ => return, - }; - // if else - let (mut then, mut els): (&Block, &Expr) = match &expr.kind { - ExprKind::If(_, then, Some(els)) => (then, els), - _ => return, - }; - loop { - if !BreakVisitor::default().check_block(then) { - // then block does not always break - return; - } - match &els.kind { - // else if else - ExprKind::If(_, next_then, Some(next_els)) => { - then = next_then; - els = next_els; - }, - // else if without else - ExprKind::If(..) => return, - // done - _ => break, - } +impl<'tcx> LateLintPass<'tcx> for RedundantElse { + fn check_block_post(&mut self, cx: &LateContext<'tcx>, b: &'tcx Block<'_>) { + if let Some(e) = b.expr { + check(cx, b.span.ctxt(), false, e); } + } - let mut app = Applicability::MachineApplicable; - if let ExprKind::Block(block, _) = &els.kind { - for stmt in &block.stmts { - // If the `else` block contains a local binding or a macro invocation, Clippy shouldn't auto-fix it - if matches!(&stmt.kind, StmtKind::Let(_) | StmtKind::MacCall(_)) { - app = Applicability::Unspecified; - break; - } - } + fn check_stmt(&mut self, cx: &LateContext<'tcx>, s: &'tcx Stmt<'_>) { + if let StmtKind::Expr(e) | StmtKind::Semi(e) = s.kind { + check(cx, s.span.ctxt(), matches!(s.kind, StmtKind::Expr(_)), e); } - - // FIXME: The indentation of the suggestion would be the same as the one of the macro invocation in this implementation, see https://github.com/rust-lang/rust-clippy/pull/13936#issuecomment-2569548202 - span_lint_and_sugg( - cx, - REDUNDANT_ELSE, - els.span.with_lo(then.span.hi()), - "redundant else block", - "remove the `else` block and move the contents out", - make_sugg(cx, els.span, "..", Some(expr.span)), - app, - ); } } -/// Call `check` functions to check if an expression always breaks control flow -#[derive(Default)] -struct BreakVisitor { - is_break: bool, -} - -impl<'ast> Visitor<'ast> for BreakVisitor { - fn visit_block(&mut self, block: &'ast Block) { - self.is_break = match block.stmts.as_slice() { - [.., last] => self.check_stmt(last), - _ => false, - }; - } - - fn visit_expr(&mut self, expr: &'ast Expr) { - self.is_break = match expr.kind { - ExprKind::Break(..) | ExprKind::Continue(..) | ExprKind::Ret(..) => true, - ExprKind::Match(_, ref arms, _) => arms.iter().all(|arm| - arm.body.is_none() || arm.body.as_deref().is_some_and(|body| self.check_expr(body)) - ), - ExprKind::If(_, ref then, Some(ref els)) => self.check_block(then) && self.check_expr(els), - ExprKind::If(_, _, None) - // ignore loops for simplicity - | ExprKind::While(..) | ExprKind::ForLoop { .. } | ExprKind::Loop(..) => false, - _ => { - walk_expr(self, expr); - return; +fn check<'tcx>(cx: &LateContext<'tcx>, ctxt: SyntaxContext, needs_semi: bool, e: &'tcx Expr<'_>) { + // Find the final `else` block in an `if` chain. + let mut prev_then = None; + let mut next = e; + let (then, else_) = loop { + match next.kind { + ExprKind::If(_, then, Some(else_)) + if is_never(cx.typeck_results(), ctxt, then) + && then.span.ctxt() == ctxt + && else_.span.ctxt() == ctxt => + { + prev_then = Some(then); + next = else_; }, - }; - } -} - -impl BreakVisitor { - fn check(&mut self, item: T, visit: fn(&mut Self, T)) -> bool { - visit(self, item); - std::mem::replace(&mut self.is_break, false) - } + ExprKind::Block(b, _) if let Some(then) = prev_then => break (then, b), + _ => return, + } + }; - fn check_block(&mut self, block: &Block) -> bool { - self.check(block, Self::visit_block) + if e.span.ctxt() == ctxt + && !ctxt.in_external_macro(cx.tcx.sess.source_map()) + && !is_from_proc_macro(cx, e) + && let Some(src) = else_.span.get_text(cx) + && let Some(src) = src.strip_prefix('{') + && let Some(src) = src.strip_suffix('}') + // FIXME(@Jarcho): `indent_of` walks to the root context before getting the indent + // which gives the wrong result here. + && let Some(indent) = indent_of(cx, e.span) + { + let sp = else_.span.with_lo(then.span.hi()); + span_lint_hir_and_then(cx, REDUNDANT_ELSE, e.hir_id, sp, "redundant else block", |diag| { + let mut sugg = reindent_multiline(src.trim_end(), false, Some(indent)); + if needs_semi && else_.expr.is_some_and(|e| expr_needs_semi(ctxt, e)) { + sugg.push(';'); + } + diag.span_suggestion( + sp, + "remove the `else` block and move the contents out", + sugg, + if ctxt.is_root() && else_.stmts.iter().all(|s| !matches!(s.kind, StmtKind::Let(_))) { + Applicability::MachineApplicable + } else { + Applicability::MaybeIncorrect + }, + ); + }); } +} - fn check_expr(&mut self, expr: &Expr) -> bool { - self.check(expr, Self::visit_expr) +/// Checks if an expression, viewed from the specified context, needs a trailing semicolon +/// to be parsed as a statement. +fn expr_needs_semi(ctxt: SyntaxContext, e: &Expr<'_>) -> bool { + match e.kind { + ExprKind::Block(..) | ExprKind::Loop(..) | ExprKind::Match(..) | ExprKind::If(..) if ctxt == e.span.ctxt() => { + false + }, + ExprKind::Loop(..) => { + let expn = e.span.ctxt().outer_expn_data(); + ctxt != expn.call_site.ctxt() || !matches!(expn.kind, ExpnKind::Desugaring(_)) + }, + ExprKind::Match(_, _, MatchSource::ForLoopDesugar) => ctxt != e.span.ctxt().outer_expn_data().call_site.ctxt(), + _ => true, } +} - fn check_stmt(&mut self, stmt: &Stmt) -> bool { - self.check(stmt, Self::visit_stmt) +fn is_never(typeck: &TypeckResults<'_>, ctxt: SyntaxContext, e: &Expr<'_>) -> bool { + if ctxt.is_root() { + is_never_root(typeck, e) + } else { + is_never_mac(ctxt, e) } } -// Extract the inner contents of an `else` block str -// e.g. `{ foo(); bar(); }` -> `foo(); bar();` -fn extract_else_block(mut block: &str) -> String { - block = block.strip_prefix("{").unwrap_or(block); - block = block.strip_suffix("}").unwrap_or(block); - block.trim_end().to_string() +fn is_never_root(typeck: &TypeckResults<'_>, e: &Expr<'_>) -> bool { + match e.kind { + ExprKind::Break(..) | ExprKind::Continue(_) | ExprKind::Ret(_) | ExprKind::Become(..) => true, + ExprKind::DropTemps(e) => is_never_root(typeck, e), + ExprKind::Block(b, _) + if let Some(e) = b.expr + && !b.targeted_by_break => + { + is_never_root(typeck, e) + }, + ExprKind::Match(_, arms, _) => arms.iter().all(|a| is_never_root(typeck, a.body)), + ExprKind::If(_, then, Some(else_)) => is_never_root(typeck, then) && is_never_root(typeck, else_), + ExprKind::Call(..) + | ExprKind::MethodCall(..) + | ExprKind::Binary(..) + | ExprKind::Unary(..) + | ExprKind::Block(..) + | ExprKind::Loop(..) + | ExprKind::Path(_) => typeck.expr_ty(e).is_never(), + _ => false, + } } -fn make_sugg(cx: &EarlyContext<'_>, els_span: Span, default: &str, indent_relative_to: Option) -> String { - let extracted = extract_else_block(&snippet(cx, els_span, default)); - let indent = indent_relative_to.and_then(|s| indent_of(cx, s)); - - reindent_multiline(&extracted, false, indent) +fn is_never_mac(ctxt: SyntaxContext, mut e: &Expr<'_>) -> bool { + loop { + let next = match e.kind { + ExprKind::Break(..) | ExprKind::Continue(_) | ExprKind::Ret(_) | ExprKind::Become(..) => return true, + ExprKind::DropTemps(e) => e, + ExprKind::Block(b, _) + if !b.targeted_by_break + && let Some(e) = match (b.expr, b.stmts) { + (Some(e), _) => Some(e), + (None, [.., s]) if let StmtKind::Expr(e) | StmtKind::Semi(e) = s.kind => Some(e), + _ => None, + } + && ctxt == b.span.ctxt() => + { + e + }, + ExprKind::Match(_, arms, _) => { + return arms + .iter() + .all(|a| ctxt == a.span.ctxt() && ctxt == a.body.span.ctxt() && is_never_mac(ctxt, a.body)); + }, + ExprKind::If(_, then, Some(else_)) + if ctxt == then.span.ctxt() && ctxt == else_.span.ctxt() && is_never_mac(ctxt, then) => + { + else_ + }, + _ => return false, + }; + if ctxt != next.span.ctxt() { + return false; + } + e = next; + } } diff --git a/clippy_lints/src/single_range_in_vec_init.rs b/clippy_lints/src/single_range_in_vec_init.rs index 3d5de785b790c..e922f72330b3e 100644 --- a/clippy_lints/src/single_range_in_vec_init.rs +++ b/clippy_lints/src/single_range_in_vec_init.rs @@ -69,6 +69,7 @@ impl Display for SuggestedType { } impl LateLintPass<'_> for SingleRangeInVecInit { + #[expect(clippy::too_many_lines)] fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { // inner_expr: `vec![0..200]` or `[0..200]` // ^^^^^^ ^^^^^^^ @@ -100,22 +101,23 @@ impl LateLintPass<'_> for SingleRangeInVecInit { } let mut applicability = Applicability::MaybeIncorrect; - let suggestion = match (range.start, range.end, range.limits) { + let suggestion = match (range.start, range.end, range.ty.limits()) { (Some(start), Some(end), limits) => { - let ty = cx.typeck_results().expr_ty(start); + let element_ty = cx.typeck_results().expr_ty(start); let (start_snippet, _) = snippet_with_context(cx, start.span, span.ctxt(), "..", &mut applicability); let (end_snippet, _) = snippet_with_context(cx, end.span, span.ctxt(), "..", &mut applicability); let should_emit_every_value = if let Some(step_def_id) = cx.tcx.get_diagnostic_item(sym::range_step) - && implements_trait(cx, ty, step_def_id, &[]) + && implements_trait(cx, element_ty, step_def_id, &[]) + && range.ty.implements_into_iterator() { - true + Some(range.ty) } else { - false + None }; let should_emit_of_len = if limits == RangeLimits::HalfOpen && let Some(copy_def_id) = cx.tcx.lang_items().copy_trait() - && implements_trait(cx, ty, copy_def_id, &[]) + && implements_trait(cx, element_ty, copy_def_id, &[]) && let ExprKind::Lit(lit_kind) = end.kind && let LitKind::Int(.., suffix_type) = lit_kind.node && let LitIntType::Unsigned(UintTy::Usize) | LitIntType::Unsuffixed = suffix_type @@ -125,12 +127,11 @@ impl LateLintPass<'_> for SingleRangeInVecInit { false }; - if should_emit_every_value || should_emit_of_len { + if should_emit_every_value.is_some() || should_emit_of_len { Some(( - ty, + element_ty, start_snippet, end_snippet, - limits, should_emit_every_value, should_emit_of_len, )) @@ -154,18 +155,29 @@ impl LateLintPass<'_> for SingleRangeInVecInit { .map_or(sym::Range, |adt_def| cx.tcx.item_name(adt_def.did())) ), |diag| { - if let Some((ty, start_snippet, end_snippet, limits, should_emit_every_value, should_emit_of_len)) = - suggestion + if let Some((ty, start_snippet, end_snippet, should_emit_every_value, should_emit_of_len)) = suggestion { - if should_emit_every_value && !is_no_std_crate(cx) { - let range_op = match limits { + if let Some(range_ty) = should_emit_every_value + && !is_no_std_crate(cx) + { + let range_op = match range_ty.limits() { RangeLimits::HalfOpen => "..", RangeLimits::Closed => "..=", }; + + let collect_code = if range_ty.implements_iterator() { + format!("({start_snippet}{range_op}{end_snippet}).collect::>()") + } else { + // If the range type does not implement `Iterator` then we cannot just call + // `.collect()`. In that case, we use `from_iter()` rather than + // `.into_iter().collect::<...>()` because it is more concise. + format!("std::vec::Vec::<{ty}>::from_iter({start_snippet}{range_op}{end_snippet})") + }; + diag.span_suggestion( span, "if you wanted a `Vec` that contains the entire range, try", - format!("({start_snippet}{range_op}{end_snippet}).collect::>()"), + collect_code, applicability, ); } diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index df3ca09dd76df..2128ffb6d7d60 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -1,9 +1,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::res::{MaybeDef, MaybeQPath}; use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_context}; -use clippy_utils::{ - SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, method_calls, peel_blocks, sym, -}; +use clippy_utils::{SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, method_calls, sym}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; @@ -11,7 +9,6 @@ use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, LangItem, Node}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty; use rustc_session::declare_lint_pass; -use rustc_span::{Spanned, SyntaxContext}; declare_clippy_lint! { /// ### What it does @@ -96,7 +93,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Check if the string is transformed to byte array and casted back to string. + /// Check if the string is transformed to byte array and cast back to string. /// /// ### Why is this bad? /// It's unnecessary, the string can be used directly. @@ -220,27 +217,21 @@ declare_lint_pass!(TrimSplitWhitespace => [TRIM_SPLIT_WHITESPACE]); impl<'tcx> LateLintPass<'tcx> for StringAdd { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { - let ctxt = e.span.ctxt(); - if ctxt.in_external_macro(cx.sess().source_map()) { - return; - } match e.kind { - ExprKind::Binary( - Spanned { - node: BinOpKind::Add, .. - }, - left, - _, - ) if is_string(cx, left) => { - if !is_lint_allowed(cx, STRING_ADD_ASSIGN, e.hir_id) { - let parent = get_parent_expr(cx, e); - if let Some(p) = parent - && let ExprKind::Assign(target, _, _) = p.kind - // avoid duplicate matches - && SpanlessEq::new(cx).eq_expr(ctxt, target, left) - { - return; - } + ExprKind::Binary(op, lhs, _) + if let BinOpKind::Add = op.node + && cx.typeck_results().expr_ty(lhs).is_lang_item(cx, LangItem::String) + && let ctxt = e.span.ctxt() + && op.span.ctxt() == ctxt + && !ctxt.in_external_macro(cx.tcx.sess.source_map()) => + { + if !is_lint_allowed(cx, STRING_ADD_ASSIGN, e.hir_id) + && let Node::Expr(parent) = cx.tcx.parent_hir_node(e.hir_id) + && let ExprKind::Assign(assign_lhs, ..) = parent.kind + && parent.span.ctxt() == ctxt + && SpanlessEq::new(cx).eq_expr(ctxt, assign_lhs, lhs) + { + return; } span_lint( cx, @@ -249,7 +240,16 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd { "you added something to a string. Consider using `String::push_str()` instead", ); }, - ExprKind::Assign(target, src, _) if is_string(cx, target) && is_add(cx, ctxt, src, target) => { + ExprKind::Assign(lhs, rhs, _) + if let ExprKind::Binary(op, add_lhs, _) = rhs.kind + && let BinOpKind::Add = op.node + && cx.typeck_results().expr_ty(lhs).is_lang_item(cx, LangItem::String) + && let ctxt = e.span.ctxt() + && SpanlessEq::new(cx).eq_expr(ctxt, lhs, add_lhs) + && rhs.span.ctxt() == ctxt + && op.span.ctxt() == ctxt + && !ctxt.in_external_macro(cx.tcx.sess.source_map()) => + { span_lint( cx, STRING_ADD_ASSIGN, @@ -258,42 +258,27 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd { `String::push_str()` instead", ); }, - ExprKind::Index(target, _idx, _) => { - let e_ty = cx.typeck_results().expr_ty_adjusted(target).peel_refs(); - if e_ty.is_str() || e_ty.is_lang_item(cx, LangItem::String) { - span_lint( - cx, - STRING_SLICE, - e.span, - "indexing into a string may panic if the index is within a UTF-8 character", - ); - } + ExprKind::Index(base, ..) + if let ty::Ref(_, ty, _) = *cx.typeck_results().expr_ty_adjusted(base).kind() + && match *ty.kind() { + ty::Adt(def, _) => def.is_lang_item(cx, LangItem::String), + ty::Str => true, + _ => false, + } + && !e.span.in_external_macro(cx.tcx.sess.source_map()) => + { + span_lint( + cx, + STRING_SLICE, + e.span, + "indexing into a string may panic if the index is within a UTF-8 character", + ); }, _ => {}, } } } -fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - cx.typeck_results() - .expr_ty(e) - .peel_refs() - .is_lang_item(cx, LangItem::String) -} - -fn is_add(cx: &LateContext<'_>, ctxt: SyntaxContext, src: &Expr<'_>, target: &Expr<'_>) -> bool { - match peel_blocks(src).kind { - ExprKind::Binary( - Spanned { - node: BinOpKind::Add, .. - }, - left, - _, - ) => SpanlessEq::new(cx).eq_expr(ctxt, target, left), - _ => false, - } -} - // Max length a b"foo" string can take const MAX_LENGTH_BYTE_STRING_LIT: usize = 32; diff --git a/clippy_lints/src/strlen_on_c_strings.rs b/clippy_lints/src/strlen_on_c_strings.rs index 53038672d1ec4..0320f76f8772a 100644 --- a/clippy_lints/src/strlen_on_c_strings.rs +++ b/clippy_lints/src/strlen_on_c_strings.rs @@ -76,11 +76,13 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings { let ctxt = expr.span.ctxt(); let span = match cx.tcx.parent_hir_node(expr.hir_id) { - Node::Block(&Block { - rules: BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided), - span, - .. - }) if span.ctxt() == ctxt && !is_expr_unsafe(cx, self_arg) => span, + Node::Block( + block @ &Block { + rules: BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided), + span, + .. + }, + ) if span.ctxt() == ctxt && !is_expr_unsafe(cx, self_arg) && block.stmts.is_empty() => span, _ => expr.span, }; diff --git a/clippy_lints/src/suspicious_operation_groupings.rs b/clippy_lints/src/suspicious_operation_groupings.rs index ac2d3741338a0..02565198e4d2a 100644 --- a/clippy_lints/src/suspicious_operation_groupings.rs +++ b/clippy_lints/src/suspicious_operation_groupings.rs @@ -6,7 +6,7 @@ use rustc_ast::ast::{BinOpKind, Expr, ExprKind, StmtKind}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; -use rustc_session::declare_lint_pass; +use rustc_session::impl_lint_pass; use rustc_span::symbol::Ident; use rustc_span::{Span, Spanned}; @@ -63,9 +63,13 @@ declare_clippy_lint! { "groupings of binary operations that look suspiciously like typos" } -declare_lint_pass!(SuspiciousOperationGroupings => [ - SUSPICIOUS_OPERATION_GROUPINGS, -]); +impl_lint_pass!(SuspiciousOperationGroupings => [SUSPICIOUS_OPERATION_GROUPINGS]); + +#[derive(Default)] +pub struct SuspiciousOperationGroupings { + // Spans already linted. + linted_spans: FxHashSet, +} impl EarlyLintPass for SuspiciousOperationGroupings { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { @@ -74,7 +78,7 @@ impl EarlyLintPass for SuspiciousOperationGroupings { } if let Some(binops) = extract_related_binops(&expr.kind) { - check_binops(cx, &binops.iter().collect::>()); + check_binops(cx, &binops.iter().collect::>(), &mut self.linted_spans); let mut op_types = Vec::with_capacity(binops.len()); // We could use a hashmap, etc. to avoid being O(n*m) here, but @@ -90,13 +94,13 @@ impl EarlyLintPass for SuspiciousOperationGroupings { for op_type in op_types { let ops: Vec<_> = binops.iter().filter(|b| b.op == op_type).collect(); - check_binops(cx, &ops); + check_binops(cx, &ops, &mut self.linted_spans); } } } } -fn check_binops(cx: &EarlyContext<'_>, binops: &[&BinaryOp<'_>]) { +fn check_binops(cx: &EarlyContext<'_>, binops: &[&BinaryOp<'_>], linted_spans: &mut FxHashSet) { let binop_count = binops.len(); if binop_count < 2 { // Single binary operation expressions would likely be false @@ -153,7 +157,7 @@ fn check_binops(cx: &EarlyContext<'_>, binops: &[&BinaryOp<'_>]) { if let Some(expected_loc) = expected_ident_loc { match (no_difference_info, double_difference_info) { - (Some(i), None) => attempt_to_emit_no_difference_lint(cx, binops, i, expected_loc), + (Some(i), None) => attempt_to_emit_no_difference_lint(cx, binops, i, expected_loc, linted_spans), (None, Some((double_difference_index, ident_loc1, ident_loc2))) => { if one_ident_difference_count == binop_count - 1 && let Some(binop) = binops.get(double_difference_index) @@ -170,7 +174,7 @@ fn check_binops(cx: &EarlyContext<'_>, binops: &[&BinaryOp<'_>]) { if let Some(sugg) = ident_swap_sugg(cx, &paired_identifiers, binop, changed_loc, &mut applicability) { - emit_suggestion(cx, binop.span, sugg, applicability); + emit_suggestion(cx, binop.span, sugg, applicability, linted_spans); } } }, @@ -184,6 +188,7 @@ fn attempt_to_emit_no_difference_lint( binops: &[&BinaryOp<'_>], i: usize, expected_loc: IdentLocation, + linted_spans: &mut FxHashSet, ) { if let Some(binop) = binops.get(i).copied() { // We need to try and figure out which identifier we should @@ -210,6 +215,7 @@ fn attempt_to_emit_no_difference_lint( binop.span, replace_left_sugg(cx, binop, &sugg, &mut applicability), applicability, + linted_spans, ); return; } @@ -224,6 +230,7 @@ fn attempt_to_emit_no_difference_lint( binop.span, replace_right_sugg(cx, binop, &sugg, &mut applicability), applicability, + linted_spans, ); return; } @@ -231,7 +238,17 @@ fn attempt_to_emit_no_difference_lint( } } -fn emit_suggestion(cx: &EarlyContext<'_>, span: Span, sugg: String, applicability: Applicability) { +fn emit_suggestion( + cx: &EarlyContext<'_>, + span: Span, + sugg: String, + applicability: Applicability, + linted_spans: &mut FxHashSet, +) { + // Avoid cases already linted. + if !linted_spans.insert(span) { + return; + } span_lint_and_sugg( cx, SUSPICIOUS_OPERATION_GROUPINGS, diff --git a/clippy_lints/src/suspicious_xor_used_as_pow.rs b/clippy_lints/src/suspicious_xor_used_as_pow.rs index 37fdba91cc027..e3d96245289ad 100644 --- a/clippy_lints/src/suspicious_xor_used_as_pow.rs +++ b/clippy_lints/src/suspicious_xor_used_as_pow.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::numeric_literal::NumericLiteral; -use clippy_utils::source::snippet; +use clippy_utils::source::SpanExt; use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lexer::is_whitespace; +use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; declare_clippy_lint! { @@ -32,16 +32,23 @@ declare_lint_pass!(ConfusingXorAndPow => [SUSPICIOUS_XOR_USED_AS_POW]); impl LateLintPass<'_> for ConfusingXorAndPow { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if !expr.span.in_external_macro(cx.sess().source_map()) - && let ExprKind::Binary(op, left, right) = &expr.kind + if let ExprKind::Binary(op, left, right) = &expr.kind && op.node == BinOpKind::BitXor - && left.span.eq_ctxt(right.span) && let ExprKind::Lit(lit_left) = &left.kind && let ExprKind::Lit(lit_right) = &right.kind - && matches!(lit_right.node, LitKind::Int(..) | LitKind::Float(..)) - && matches!(lit_left.node, LitKind::Int(..) | LitKind::Float(..)) - && NumericLiteral::from_lit_kind(&snippet(cx, lit_right.span, ".."), &lit_right.node) - .is_some_and(|x| x.is_decimal()) + && matches!(lit_right.node, LitKind::Int(..)) + && matches!(lit_left.node, LitKind::Int(..)) + && let ctxt = expr.span.ctxt() + && ctxt == left.span.ctxt() + && ctxt == right.span.ctxt() + && ctxt == op.span.ctxt() + && !expr.span.in_external_macro(cx.tcx.sess.source_map()) + && let Some(lit_right_src) = lit_right.span.get_text(cx) + && lit_right_src + .trim_start_matches(|c| is_whitespace(c) || c == '(') + .strip_prefix('0') + .and_then(|src| src.as_bytes().first().copied()) + .is_none_or(|c| !matches!(c, b'x' | b'X' | b'o' | b'O' | b'b' | b'B')) { span_lint_and_then( cx, diff --git a/clippy_lints/src/transmute/missing_transmute_annotations.rs b/clippy_lints/src/transmute/missing_transmute_annotations.rs index 89627eded65f5..ddcc577cbd199 100644 --- a/clippy_lints/src/transmute/missing_transmute_annotations.rs +++ b/clippy_lints/src/transmute/missing_transmute_annotations.rs @@ -107,10 +107,13 @@ pub(super) fn check<'tcx>( fn ty_cannot_be_named(ty: Ty<'_>) -> bool { matches!( ty.kind(), - ty::Alias(_, ty::AliasTy { - kind: ty::Opaque { .. } | ty::Inherent { .. }, - .. - }) + ty::Alias( + _, + ty::AliasTy { + kind: ty::Opaque { .. } | ty::Inherent { .. }, + .. + } + ) ) } diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index 8bbecb5c19540..c12cb3846a540 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -1,16 +1,21 @@ +use arrayvec::ArrayVec; use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::res::MaybeResPath; -use clippy_utils::visitors::local_used_once; -use clippy_utils::{get_enclosing_block, is_from_proc_macro}; -use itertools::Itertools; +use clippy_utils::visitors::{Visitable, for_each_expr}; +use clippy_utils::{SpanlessEq, is_from_proc_macro}; +use core::ops::ControlFlow::{Break, Continue}; +use core::{iter, mem}; use rustc_ast::LitKind; -use rustc_hir::{Expr, ExprKind, Node, PatKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::{self, Ty}; +use rustc_ast::visit::{VisitorResult, try_visit, visit_opt, walk_list}; +use rustc_data_structures::packed::Pu128; +use rustc_hir::intravisit::Visitor; +use rustc_hir::{Arm, Expr, ExprKind, HirId, ImplItemKind, ItemKind, Node, PatKind, Stmt, TraitFn, TraitItemKind}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::{self, TyCtxt}; use rustc_session::impl_lint_pass; -use std::iter::once; +use rustc_span::sym; declare_clippy_lint! { /// ### What it does @@ -52,177 +57,255 @@ impl TupleArrayConversions { } } -impl LateLintPass<'_> for TupleArrayConversions { - fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - if expr.span.in_external_macro(cx.sess().source_map()) || !self.msrv.meets(cx, msrvs::TUPLE_ARRAY_CONVERSIONS) { - return; - } +/// The maximum size of a tuple/array for which `From` is implemented. +const MAX_CVT_COUNT: usize = 12; - match expr.kind { - ExprKind::Array(elements) if (1..=12).contains(&elements.len()) => check_array(cx, expr, elements), - ExprKind::Tup(elements) if (1..=12).contains(&elements.len()) => check_tuple(cx, expr, elements), - _ => {}, - } - } -} +impl LateLintPass<'_> for TupleArrayConversions { + #[expect(clippy::too_many_lines)] + fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) { + match e.kind { + ExprKind::Array([]) | ExprKind::Tup([]) => {}, + ExprKind::Array(es) | ExprKind::Tup(es) if es.len() > MAX_CVT_COUNT => {}, -fn check_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, elements: &'tcx [Expr<'tcx>]) { - let Some(ty) = cx.typeck_results().expr_ty(expr).builtin_index() else { - unreachable!("`expr` must be an array or slice due to `ExprKind::Array`"); - }; + // Create an array using every item in a tuple (e.g. `[x.0, x.1, x.2]`). + ExprKind::Array([first, rest @ ..]) if let ExprKind::Field(first_base, first_field) = first.kind => { + if first_field.name == sym::integer(0) + && let ctxt = e.span.ctxt() + && ctxt == first.span.ctxt() + && ctxt == first_field.span.ctxt() + // Check that the remaining elements are accesses to the expected field. + && let Some(bases) = rest.iter().enumerate().map(|(i, e)| { + if let ExprKind::Field(base, field) = e.kind + && field.name == sym::integer(i + 1) + && ctxt == e.span.ctxt() + && ctxt == field.span.ctxt() + { + Some(base) + } else { + None + } + }).collect::>>() + // Check that the source and destination types are the same and copyable. + && let ty::Tuple(src_tys) = *cx.typeck_results().expr_ty_adjusted(first_base).kind() + && src_tys.len() == rest.len() + 1 + && let ty::Array(dst_ty, _) = *cx.typeck_results().expr_ty(e).kind() + && src_tys.iter().all(|ty| ty == dst_ty) + && cx.tcx.type_is_copy_modulo_regions(cx.typing_env(), dst_ty) + // Check that all accesses are to the same base last as that can be a complex check. + && let mut eq = SpanlessEq::new(cx).deny_side_effects() + && bases.iter().all(|e| eq.eq_expr(ctxt, first_base, e)) + && self.msrv.meets(cx, msrvs::TUPLE_ARRAY_CONVERSIONS) + && !ctxt.in_external_macro(cx.tcx.sess.source_map()) + && !is_from_proc_macro(cx, e) + { + span_lint_and_help( + cx, + TUPLE_ARRAY_CONVERSIONS, + e.span, + "it looks like you're trying to convert a tuple to an array", + None, + "use `.into()` instead, or `<[T; N]>::from` if type annotations are needed", + ); + } + }, - if let [first, ..] = elements - && let Some(locals) = (match first.kind { - ExprKind::Field(_, _) => elements - .iter() - .enumerate() - .map(|(i, f)| -> Option<&'tcx Expr<'tcx>> { - let ExprKind::Field(lhs, ident) = f.kind else { - return None; - }; - (ident.name.as_str() == i.to_string()).then_some(lhs) - }) - .collect::>>(), - ExprKind::Path(_) => Some(elements.iter().collect()), - _ => None, - }) - && all_bindings_are_for_conv(cx, &[ty], elements, &locals, ToType::Array) - && !is_from_proc_macro(cx, expr) - { - span_lint_and_help( - cx, - TUPLE_ARRAY_CONVERSIONS, - expr.span, - "it looks like you're trying to convert a tuple to an array", - None, - "use `.into()` instead, or `<[T; N]>::from` if type annotations are needed", - ); - } -} + // Create a tuple using every item in an array (e.g. `(x[0], x[1], x[2])`). + ExprKind::Tup([first, rest @ ..]) if let ExprKind::Index(first_base, first_idx, _) = first.kind => { + if let ExprKind::Lit(idx_lit) = first_idx.kind + && let LitKind::Int(Pu128(0), _) = idx_lit.node + && let ctxt = e.span.ctxt() + && ctxt == first.span.ctxt() + && ctxt == first_idx.span.ctxt() + && ctxt == idx_lit.span.ctxt() + // Check that the remaining elements are array accesses with the expected index. + && let Some(bases) = rest.iter().enumerate().map(|(i, e)| { + if let ExprKind::Index(base, idx, _) = e.kind + && let ExprKind::Lit(idx_lit) = idx.kind + && let LitKind::Int(idx_num, _) = idx_lit.node + && idx_num == Pu128((i + 1) as u128) + && ctxt == e.span.ctxt() + && ctxt == idx_lit.span.ctxt() + { + Some(base) + } else { + None + } + }).collect::>>() + // Check that the source and destination types are the same and copyable. + && let ty::Array(src_ty, src_len) = *cx.typeck_results().expr_ty_adjusted(first_base).kind() + && src_len.try_to_target_usize(cx.tcx) == Some((rest.len() + 1) as u64) + && let ty::Tuple(dst_tys) = *cx.typeck_results().expr_ty(e).kind() + && dst_tys.iter().all(|ty| ty == src_ty) + && cx.tcx.type_is_copy_modulo_regions(cx.typing_env(), src_ty) + // Check that all accesses are to the same base last as that can be a complex check. + && let mut eq = SpanlessEq::new(cx).deny_side_effects() + && bases.iter().all(|e| eq.eq_expr(ctxt, first_base, e)) + && self.msrv.meets(cx, msrvs::TUPLE_ARRAY_CONVERSIONS) + && !ctxt.in_external_macro(cx.tcx.sess.source_map()) + && !is_from_proc_macro(cx, e) + { + span_lint_and_help( + cx, + TUPLE_ARRAY_CONVERSIONS, + e.span, + "it looks like you're trying to convert an array to a tuple", + None, + "use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed", + ); + } + }, -fn check_tuple<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, elements: &'tcx [Expr<'tcx>]) { - if let ty::Tuple(tys) = cx.typeck_results().expr_ty(expr).kind() - && let [first, ..] = elements - // Fix #11100 - && tys.iter().all_equal() - && let Some(locals) = (match first.kind { - ExprKind::Index(..) => elements - .iter() - .enumerate() - .map(|(i, i_expr)| -> Option<&'tcx Expr<'tcx>> { - if let ExprKind::Index(lhs, index, _) = i_expr.kind - && let ExprKind::Lit(lit) = index.kind - && let LitKind::Int(val, _) = lit.node - { - return (val == i as u128).then_some(lhs); + // Destructure an array/tuple and create the other by using all the items. + // e.g. `|(x, y, z)| [x, y, z]` + ExprKind::Array([first, rest @ ..]) | ExprKind::Tup([first, rest @ ..]) + if let Some((first_id, first_ident)) = first.res_local_id_and_ident() + && let ctxt = e.span.ctxt() + && ctxt == first.span.ctxt() + && ctxt == first_ident.span.ctxt() + // Collect all the remaining local IDs involved. + // This is done first so we don't go through `TyCtxt` unless needed. + && let Some(mut ids) = rest + .iter() + .map(|e| { + e.res_local_id_and_ident() + .filter(|&(_, ident)| ctxt == e.span.ctxt() && ctxt == ident.span.ctxt()) + .map(|(id, _)| id) + }) + .collect::>>() + // Check that all locals used are from a single destructuring in the same order. + // The iterator will be used later to get the enclosing scope for the bindings. + && let mut parent_iter = cx.tcx.hir_parent_iter(first_id) + && let Some((id_parent, Node::Pat(id_parent_pat))) = parent_iter.next() + && let PatKind::Tuple([first_pat, rest_pats @ ..], _) + | PatKind::Slice([first_pat, rest_pats @ ..], ..) = id_parent_pat.kind + && first_id == first_pat.hir_id + && let PatKind::Binding(.., None) = first_pat.kind + && iter::zip(&ids, rest_pats) + .all(|(&id, pat)| id == pat.hir_id && matches!(pat.kind, PatKind::Binding(.., None))) + // Check that the source and destination types are the same. + && let Some(src_ty) = match *cx.typeck_results().node_type(id_parent).kind() { + ty::Array(src_ty, src_len) + if matches!(e.kind, ExprKind::Tup(_)) + && src_len.try_to_target_usize(cx.tcx) == Some((rest.len() + 1) as u64) => + { + Some(src_ty) + }, + ty::Tuple(src_tys) + if let [src_ty, ref rest_tys @ ..] = **src_tys + && rest.len() == rest_tys.len() + && matches!(e.kind, ExprKind::Array(_)) + && rest_tys.iter().all(|&ty| src_ty == ty) => + { + Some(src_ty) + }, + _ => None, + } + && match *cx.typeck_results().expr_ty(e).kind() { + ty::Array(dst_ty, _) => dst_ty == src_ty, + ty::Tuple(dst_tys) => dst_tys.iter().all(|ty| src_ty == ty), + __ => false, } + && ctxt == id_parent_pat.span.ctxt() + // Check that each binding is used at most once. + && let Some(use_scope) = find_binding_use_scope(cx.tcx, parent_iter) + && let () = ids.push(first_id) + && let mut ids_used = [false; MAX_CVT_COUNT] + && let None = for_each_expr(cx.tcx, use_scope, |e| { + if let Some(id) = e.res_local_id() + && let Some(i) = ids.iter().position(|&x| id == x) + && mem::replace(&mut ids_used[i], true) + { + Break(()) + } else { + Continue(()) + } + }) + && !ctxt.in_external_macro(cx.tcx.sess.source_map()) + && !is_from_proc_macro(cx, e) => + { + let (msg, help) = if let ExprKind::Array(_) = e.kind { + ( + "it looks like you're trying to convert a tuple to an array", + "use `.into()` instead, or `<[T; N]>::from` if type annotations are needed", + ) + } else { + ( + "it looks like you're trying to convert an array to a tuple", + "use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed", + ) + }; + span_lint_and_help(cx, TUPLE_ARRAY_CONVERSIONS, e.span, msg, None, help); + }, - None - }) - .collect::>>(), - ExprKind::Path(_) => Some(elements.iter().collect()), - _ => None, - }) - && all_bindings_are_for_conv(cx, tys, elements, &locals, ToType::Tuple) - && !is_from_proc_macro(cx, expr) - { - span_lint_and_help( - cx, - TUPLE_ARRAY_CONVERSIONS, - expr.span, - "it looks like you're trying to convert an array to a tuple", - None, - "use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed", - ); + _ => {}, + } } } -/// Checks that every binding in `elements` comes from the same parent `Pat` with the kind if there -/// is a parent `Pat`. Returns false in any of the following cases: -/// * `kind` does not match `pat.kind` -/// * one or more elements in `elements` is not a binding -/// * one or more bindings does not have the same parent `Pat` -/// * one or more bindings are used after `expr` -/// * the bindings do not all have the same type -#[expect(clippy::cast_possible_truncation)] -fn all_bindings_are_for_conv<'tcx>( - cx: &LateContext<'tcx>, - final_tys: &[Ty<'tcx>], - elements: &[Expr<'_>], - locals: &[&Expr<'_>], - kind: ToType, -) -> bool { - let Some(locals) = locals.iter().map(|e| e.res_local_id()).collect::>>() else { - return false; - }; - let local_parents = locals.iter().map(|l| cx.tcx.parent_hir_node(*l)).collect::>(); - - local_parents - .iter() - .map(|node| match node { - Node::Pat(pat) => kind.eq(&pat.kind).then_some(pat.hir_id), - Node::LetStmt(l) => Some(l.hir_id), - _ => None, - }) - .all_equal() - && locals.iter().zip(local_parents.iter()).all(|(&l, &parent)| { - if let Node::LetStmt(_) = parent { - return true; - } - - let Some(b) = get_enclosing_block(cx, l) else { - return true; - }; - local_used_once(cx, b, l).is_some() - }) - && local_parents.first().is_some_and(|node| { - let Some(ty) = match node { - Node::Pat(pat) - if let PatKind::Tuple(pats, _) | PatKind::Slice(pats, None, []) = &pat.kind - && pats.iter().zip(locals.iter()).all(|(p, l)| { - if let PatKind::Binding(_, id, _, _) = p.kind { - id == *l - } else { - true - } - }) => - { - Some(pat.hir_id) - }, - Node::LetStmt(l) => Some(l.hir_id), - _ => None, - } - .map(|hir_id| cx.typeck_results().node_type(hir_id)) else { - return false; - }; - match (kind, ty.kind()) { - // Ensure the final type and the original type have the same length, and that there - // is no implicit `&mut`<=>`&` anywhere (#11100). Bit ugly, I know, but it works. - (ToType::Array, ty::Tuple(tys)) => { - tys.len() == elements.len() && tys.iter().chain(final_tys.iter().copied()).all_equal() - }, - (ToType::Tuple, ty::Array(ty, len)) => { - let Some(len) = len.try_to_target_usize(cx.tcx) else { - return false; - }; - len as usize == elements.len() && final_tys.iter().chain(once(ty)).all_equal() - }, - _ => false, - } - }) -} - #[derive(Clone, Copy)] -enum ToType { - Array, - Tuple, +enum BindingUseRange<'tcx> { + Arm(&'tcx Arm<'tcx>), + Param(&'tcx Expr<'tcx>), + LetStmt(&'tcx [Stmt<'tcx>], Option<&'tcx Expr<'tcx>>), + LetExpr(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>), } - -impl PartialEq> for ToType { - fn eq(&self, other: &PatKind<'_>) -> bool { +impl<'tcx> Visitable<'tcx> for BindingUseRange<'tcx> { + fn visit>(self, visitor: &mut V) -> V::Result { match self { - ToType::Array => matches!(other, PatKind::Tuple(_, _)), - ToType::Tuple => matches!(other, PatKind::Slice(_, _, _)), + Self::Arm(a) => visitor.visit_arm(a), + Self::Param(e) => visitor.visit_expr(e), + Self::LetStmt(stmts, e) => { + walk_list!(visitor, visit_stmt, stmts); + visit_opt!(visitor, visit_expr, e); + ::output() + }, + Self::LetExpr(cond, then) => { + try_visit!(visitor.visit_expr(cond)); + visitor.visit_expr(then) + }, + } + } +} + +/// Given a parent iterator from a binding node, finds the parts of the HIR tree which can +/// use that binding. +fn find_binding_use_scope<'tcx>( + tcx: TyCtxt<'tcx>, + mut iter: impl Iterator)>, +) -> Option> { + loop { + match iter.next() { + Some((_, Node::Pat(p))) if !matches!(p.kind, PatKind::Or(_)) => {}, + Some((_, Node::PatField(_))) => {}, + Some((_, Node::Arm(a))) => break Some(BindingUseRange::Arm(a)), + Some((_, Node::Param(_))) => { + let body = match iter.next() { + Some((_, Node::Expr(e))) if let ExprKind::Closure(c) = e.kind => c.body, + Some((_, Node::Item(i))) if let ItemKind::Fn { body, .. } = i.kind => body, + Some((_, Node::TraitItem(i))) if let TraitItemKind::Fn(_, TraitFn::Provided(body)) = i.kind => body, + Some((_, Node::ImplItem(i))) if let ImplItemKind::Fn(_, body) = i.kind => body, + _ => break None, + }; + break Some(BindingUseRange::Param(tcx.hir_body(body).value)); + }, + Some((_, Node::LetStmt(_))) + if let Some((id, Node::Stmt(_))) = iter.next() + && let Some((_, Node::Block(b))) = iter.next() + && let mut stmts = b.stmts.iter() + && stmts.any(|s| s.hir_id == id) => + { + break Some(BindingUseRange::LetStmt(stmts.as_slice(), b.expr)); + }, + Some((_, Node::Expr(e))) + if let ExprKind::Let(_) = e.kind + && let Some((cond, then)) = iter.find_map(|(_, n)| match n { + Node::Expr(e) if let ExprKind::If(cond, then, _) = e.kind => Some((cond, then)), + _ => None, + }) => + { + break Some(BindingUseRange::LetExpr(cond, then)); + }, + _ => break None, } } } diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index bef8b8fb4ee03..0c95c7f4859c8 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -108,39 +108,53 @@ fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) { } let string = snippet(cx, span, ""); + // All three lints here can only fire when the snippet contains a non-ASCII character. Note + // that the snippet can contain non-ASCII characters even when the literal's value does not, + // e.g. the literal produced by `file!()` inside a macro spans the whole macro invocation. + if string.is_ascii() { + return; + } + let is_raw = string.starts_with('r'); + if string.chars().any(|c| ['\u{200B}', '\u{ad}', '\u{2060}'].contains(&c)) { - #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] span_lint_and_then(cx, INVISIBLE_CHARACTERS, span, "invisible character detected", |diag| { - diag.span_suggestion( - span, - "consider replacing the string with", - string - .replace('\u{200B}', "\\u{200B}") - .replace('\u{ad}', "\\u{AD}") - .replace('\u{2060}', "\\u{2060}"), - Applicability::MachineApplicable, - ); + if is_raw { + diag.help("use a normal string literal instead of a raw one to escape the character"); + } else { + diag.span_suggestion( + span, + "consider replacing the string with", + string + .replace('\u{200B}', "\\u{200B}") + .replace('\u{ad}', "\\u{AD}") + .replace('\u{2060}', "\\u{2060}"), + Applicability::MachineApplicable, + ); + } }); } if string.chars().any(|c| c as u32 > 0x7F) { - #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] span_lint_and_then( cx, NON_ASCII_LITERAL, span, "literal non-ASCII character detected", |diag| { - diag.span_suggestion( - span, - "consider replacing the string with", - if is_lint_allowed(cx, UNICODE_NOT_NFC, id) { - escape(string.chars()) - } else { - escape(string.nfc()) - }, - Applicability::MachineApplicable, - ); + if is_raw { + diag.help("use a normal string literal instead of a raw one to escape the character"); + } else { + diag.span_suggestion( + span, + "consider replacing the string with", + if is_lint_allowed(cx, UNICODE_NOT_NFC, id) { + escape(string.chars()) + } else { + escape(string.nfc()) + }, + Applicability::MachineApplicable, + ); + } }, ); } diff --git a/clippy_lints/src/uninhabited_references.rs b/clippy_lints/src/uninhabited_references.rs index b342f37f0c5ff..96d385ff53235 100644 --- a/clippy_lints/src/uninhabited_references.rs +++ b/clippy_lints/src/uninhabited_references.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnRetTy, TyKind, UnOp}; -use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty; use rustc_session::declare_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; @@ -39,20 +39,19 @@ declare_lint_pass!(UninhabitedReferences => [UNINHABITED_REFERENCES]); impl LateLintPass<'_> for UninhabitedReferences { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) { - if expr.span.in_external_macro(cx.tcx.sess.source_map()) { - return; - } - - if let ExprKind::Unary(UnOp::Deref, _) = expr.kind { - let ty = cx.typeck_results().expr_ty_adjusted(expr); - if ty.is_privately_uninhabited(cx.tcx, cx.typing_env()) { - span_lint( - cx, - UNINHABITED_REFERENCES, - expr.span, - "dereferencing a reference to an uninhabited type is undefined behavior", - ); - } + if let ExprKind::Unary(UnOp::Deref, _) = expr.kind + && cx + .typeck_results() + .expr_ty_adjusted(expr) + .is_privately_uninhabited(cx.tcx, cx.typing_env()) + && !expr.span.in_external_macro(cx.tcx.sess.source_map()) + { + span_lint( + cx, + UNINHABITED_REFERENCES, + expr.span, + "dereferencing a reference to an uninhabited type is undefined behavior", + ); } } @@ -63,14 +62,17 @@ impl LateLintPass<'_> for UninhabitedReferences { fndecl: &'_ FnDecl<'tcx>, _: &'_ Body<'_>, span: Span, - _: LocalDefId, + def_id: LocalDefId, ) { - if span.in_external_macro(cx.tcx.sess.source_map()) || matches!(kind, FnKind::Closure) { - return; - } - if let FnRetTy::Return(hir_ty) = fndecl.output - && let TyKind::Ref(_, mut_ty) = hir_ty.kind - && lower_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.typing_env()) + if !matches!(kind, FnKind::Closure) + && let FnRetTy::Return(hir_ty) = fndecl.output + && let TyKind::Ref(..) = hir_ty.kind + && let sig = cx.tcx.fn_sig(def_id).instantiate_identity() + && let ty = sig.map(|x| cx.tcx.instantiate_bound_regions_with_erased(x.output())) + && let Ok(ty) = cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty) + && let ty::Ref(_, ty, _) = *ty.kind() + && ty.is_privately_uninhabited(cx.tcx, cx.typing_env()) + && !span.in_external_macro(cx.tcx.sess.source_map()) { span_lint( cx, diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 5d074208c029c..414dc55b61ba8 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -201,6 +201,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { if let Some(searcher) = self.searcher.take() { if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind + && !stmt.span.from_expansion() && let ExprKind::MethodCall(name, self_arg, [_], _) = expr.kind && self_arg.res_local_id() == Some(searcher.local_id) && name.ident.name == sym::push diff --git a/clippy_lints_internal/Cargo.toml b/clippy_lints_internal/Cargo.toml index 16b45322e30f1..5498f63f51db8 100644 --- a/clippy_lints_internal/Cargo.toml +++ b/clippy_lints_internal/Cargo.toml @@ -6,7 +6,7 @@ edition = "2024" [dependencies] clippy_config = { path = "../clippy_config" } clippy_utils = { path = "../clippy_utils" } -itertools = "0.12" +itertools = "0.15" regex = { version = "1.5" } rustc-semver = "1.1" diff --git a/clippy_lints_internal/src/lib.rs b/clippy_lints_internal/src/lib.rs index f75a9f67d0563..4931f8765bdd6 100644 --- a/clippy_lints_internal/src/lib.rs +++ b/clippy_lints_internal/src/lib.rs @@ -63,23 +63,23 @@ static LINTS: &[&Lint] = &[ pub fn register_lints(store: &mut LintStore) { store.register_lints(LINTS); - store.register_early_pass(Box::new(|| { + store.register_early_lint_pass(Box::new(|| { Box::new(unsorted_clippy_utils_paths::UnsortedClippyUtilsPaths) })); - store.register_early_pass(Box::new(|| Box::new(produce_ice::ProduceIce))); - store.register_late_pass(Box::new(|_| Box::new(collapsible_span_lint_calls::CollapsibleCalls))); - store.register_late_pass(Box::new(|_| Box::::default())); - store.register_late_pass(Box::new(|_| { + store.register_early_lint_pass(Box::new(|| Box::new(produce_ice::ProduceIce))); + store.register_late_lint_pass(Box::new(|_| Box::new(collapsible_span_lint_calls::CollapsibleCalls))); + store.register_late_lint_pass(Box::new(|_| Box::::default())); + store.register_late_lint_pass(Box::new(|_| { Box::::default() })); - store.register_late_pass(Box::new(|_| Box::new(unnecessary_def_path::UnnecessaryDefPath))); - store.register_late_pass(Box::new(|_| Box::new(outer_expn_data_pass::OuterExpnDataPass))); - store.register_late_pass(Box::new(|_| Box::new(msrv_attr_impl::MsrvAttrImpl))); - store.register_late_pass(Box::new(|_| { + store.register_late_lint_pass(Box::new(|_| Box::new(unnecessary_def_path::UnnecessaryDefPath))); + store.register_late_lint_pass(Box::new(|_| Box::new(outer_expn_data_pass::OuterExpnDataPass))); + store.register_late_lint_pass(Box::new(|_| Box::new(msrv_attr_impl::MsrvAttrImpl))); + store.register_late_lint_pass(Box::new(|_| { Box::new(almost_standard_lint_formulation::AlmostStandardFormulation::new()) })); - store.register_late_pass(Box::new(|_| Box::new(unusual_names::UnusualNames))); - store.register_late_pass(Box::new(|_| { + store.register_late_lint_pass(Box::new(|_| Box::new(unusual_names::UnusualNames))); + store.register_late_lint_pass(Box::new(|_| { Box::new(repeated_is_diagnostic_item::RepeatedIsDiagnosticItem) })); } diff --git a/clippy_test_deps/Cargo.lock b/clippy_test_deps/Cargo.lock index 33ee75ad49450..4708b523557b8 100644 --- a/clippy_test_deps/Cargo.lock +++ b/clippy_test_deps/Cargo.lock @@ -194,9 +194,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.12.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc" dependencies = [ "either", ] diff --git a/clippy_test_deps/Cargo.toml b/clippy_test_deps/Cargo.toml index e449b48bc4606..5c01214da0fcc 100644 --- a/clippy_test_deps/Cargo.toml +++ b/clippy_test_deps/Cargo.toml @@ -14,7 +14,7 @@ syn = { version = "2.0", features = ["full"] } futures = "0.3" parking_lot = "0.12" tokio = { version = "1", features = ["io-util"] } -itertools = "0.12" +itertools = "0.15" # Make sure we are not part of the rustc workspace. [workspace] diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index 0dcb116988bb8..c0beacf57878a 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_utils" -version = "0.1.98" +version = "0.1.99" edition = "2024" description = "Helpful tools for writing lints, provided as they are used in Clippy" repository = "https://github.com/rust-lang/rust-clippy" @@ -11,7 +11,7 @@ categories = ["development-tools"] [dependencies] arrayvec = { version = "0.7", default-features = false } -itertools = "0.12" +itertools = "0.15" # FIXME(f16_f128): remove when no longer needed for parsing rustc_apfloat = "0.2.0" serde = { version = "1.0", features = ["derive"] } diff --git a/clippy_utils/README.md b/clippy_utils/README.md index f322d03f18795..06e64040888d4 100644 --- a/clippy_utils/README.md +++ b/clippy_utils/README.md @@ -8,7 +8,7 @@ This crate is only guaranteed to build with this `nightly` toolchain: ``` -nightly-2026-06-25 +nightly-2026-07-09 ``` diff --git a/clippy_utils/src/ast_utils/mod.rs b/clippy_utils/src/ast_utils/mod.rs index fa93cf208c9d9..c89130fb647a4 100644 --- a/clippy_utils/src/ast_utils/mod.rs +++ b/clippy_utils/src/ast_utils/mod.rs @@ -5,6 +5,7 @@ #![allow(clippy::wildcard_imports, clippy::enum_glob_use)] use crate::{both, over}; +use rustc_ast::attr::data_structures::CfgEntry; use rustc_ast::{self as ast, HasAttrs, *}; use rustc_span::sym; use rustc_span::symbol::Ident; @@ -1042,7 +1043,7 @@ fn eq_delim_args(l: &DelimArgs, r: &DelimArgs) -> bool { && l.tokens.iter().zip(r.tokens.iter()).all(|(a, b)| a.eq_unspanned(b)) } -/// Checks whether `#[cfg(test)]` is directly applied to `item`. +/// Checks whether `item` is gated on `#[cfg(test)]`. pub fn is_cfg_test(item: &impl HasAttrs) -> bool { item.attrs().iter().any(|attr| { if attr.has_name(sym::cfg) @@ -1050,8 +1051,20 @@ pub fn is_cfg_test(item: &impl HasAttrs) -> bool { && item_list.iter().any(|item| item.has_name(sym::test)) { true + } else if attr.has_name(sym::cfg_trace) + && let AttrItemKind::Parsed(EarlyParsedAttribute::CfgTrace(cfg)) = &attr.get_normal_item().args + { + requires_test_cfg(cfg) } else { false } }) } + +fn requires_test_cfg(cfg: &CfgEntry) -> bool { + match cfg { + CfgEntry::NameValue { name: sym::test, .. } => true, + CfgEntry::All(subs, _) => subs.iter().any(requires_test_cfg), + _ => false, + } +} diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 11e6e32ba6c56..b6dc5dc38cd17 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -979,6 +979,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { } } + #[expect(clippy::too_many_lines)] fn binop(&self, op: BinOpKind, left: &Expr<'_>, right: &Expr<'_>) -> Option { let l = self.expr(left)?; let r = self.expr(right); @@ -1027,6 +1028,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { }, ty::Uint(ity) => { let bits = ity.bits(); + let mask = !0u128 >> (128 - bits); match op { BinOpKind::Add => l.checked_add(r).and_then(|n| ity.ensure_fits(n)).map(Constant::Int), @@ -1034,8 +1036,12 @@ impl<'tcx> ConstEvalCtxt<'tcx> { BinOpKind::Mul => l.checked_mul(r).and_then(|n| ity.ensure_fits(n)).map(Constant::Int), BinOpKind::Div => l.checked_div(r).map(Constant::Int), BinOpKind::Rem => l.checked_rem(r).map(Constant::Int), - BinOpKind::Shr if r < bits => l.checked_shr(r.try_into().ok()?).map(Constant::Int), - BinOpKind::Shl if r < bits => l.checked_shl(r.try_into().ok()?).map(Constant::Int), + BinOpKind::Shr if r < bits => { + l.checked_shr(r.try_into().ok()?).map(|x| Constant::Int(x & mask)) + }, + BinOpKind::Shl if r < bits => { + l.checked_shl(r.try_into().ok()?).map(|x| Constant::Int(x & mask)) + }, BinOpKind::BitXor => Some(Constant::Int(l ^ r)), BinOpKind::BitOr => Some(Constant::Int(l | r)), BinOpKind::BitAnd => Some(Constant::Int(l & r)), diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index 9c0b136e02b5c..fe0f14d3f95ae 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -203,73 +203,152 @@ impl<'hir> IfOrIfLet<'hir> { /// Represent a range akin to `ast::ExprKind::Range`. #[derive(Debug, Copy, Clone)] pub struct Range<'a> { + /// Type of the range, as an enum of only range types. + pub ty: RangeTy, /// The lower bound of the range, or `None` for ranges such as `..X`. pub start: Option<&'a Expr<'a>>, /// The upper bound of the range, or `None` for ranges such as `X..`. pub end: Option<&'a Expr<'a>>, - /// Whether the interval is open or closed. - pub limits: ast::RangeLimits, pub span: Span, } impl<'a> Range<'a> { /// Higher a `hir` range to something similar to `ast::ExprKind::Range`. - #[expect(clippy::similar_names)] pub fn hir(cx: &LateContext<'_>, expr: &'a Expr<'_>) -> Option> { let span = expr.range_span()?; - match expr.kind { + let (ty, start, end) = match expr.kind { ExprKind::Call(path, [arg1, arg2]) if let ExprKind::Path(qpath) = path.kind && cx.tcx.qpath_is_lang_item(qpath, hir::LangItem::RangeInclusiveNew) => { - Some(Range { - start: Some(arg1), - end: Some(arg2), - limits: ast::RangeLimits::Closed, - span, - }) + (RangeTy::OpsInclusive, Some(arg1), Some(arg2)) }, ExprKind::Struct(&qpath, fields, StructTailExpr::None) => match (cx.tcx.qpath_lang_item(qpath)?, fields) { - (hir::LangItem::RangeFull, []) => Some(Range { - start: None, - end: None, - limits: ast::RangeLimits::HalfOpen, - span, - }), - (hir::LangItem::RangeFrom, [field]) if field.ident.name == sym::start => Some(Range { - start: Some(field.expr), - end: None, - limits: ast::RangeLimits::HalfOpen, - span, - }), - (hir::LangItem::Range, [field1, field2]) => { - let (start, end) = match (field1.ident.name, field2.ident.name) { - (sym::start, sym::end) => (field1.expr, field2.expr), - (sym::end, sym::start) => (field2.expr, field1.expr), - _ => return None, - }; - Some(Range { - start: Some(start), - end: Some(end), - limits: ast::RangeLimits::HalfOpen, - span, - }) + (hir::LangItem::RangeFull, []) => (RangeTy::OpsFull, None, None), + (hir::LangItem::RangeFrom, [start]) if start.ident.name == sym::start => { + (RangeTy::OpsFrom, Some(start.expr), None) }, - (hir::LangItem::RangeToInclusive, [field]) if field.ident.name == sym::end => Some(Range { - start: None, - end: Some(field.expr), - limits: ast::RangeLimits::Closed, - span, - }), - (hir::LangItem::RangeTo, [field]) if field.ident.name == sym::end => Some(Range { - start: None, - end: Some(field.expr), - limits: ast::RangeLimits::HalfOpen, - span, - }), - _ => None, + (hir::LangItem::RangeFromCopy, [start]) if start.ident.name == sym::start => { + (RangeTy::RangeFrom, Some(start.expr), None) + }, + (hir::LangItem::Range, [start, end] | [end, start]) + if start.ident.name == sym::start && end.ident.name == sym::end => + { + (RangeTy::OpsRange, Some(start.expr), Some(end.expr)) + }, + (hir::LangItem::RangeCopy, [start, end] | [end, start]) + if start.ident.name == sym::start && end.ident.name == sym::end => + { + (RangeTy::RangeRange, Some(start.expr), Some(end.expr)) + }, + (hir::LangItem::RangeInclusiveCopy, [start, last] | [last, start]) + if start.ident.name == sym::start && last.ident.name == sym::last => + { + (RangeTy::RangeInclusive, Some(start.expr), Some(last.expr)) + }, + (hir::LangItem::RangeToInclusive, [end]) if end.ident.name == sym::end => { + (RangeTy::OpsToInclusive, None, Some(end.expr)) + }, + (hir::LangItem::RangeToInclusiveCopy, [last]) if last.ident.name == sym::last => { + (RangeTy::RangeToInclusive, None, Some(last.expr)) + }, + (hir::LangItem::RangeTo, [end]) if end.ident.name == sym::end => (RangeTy::OpsTo, None, Some(end.expr)), + _ => return None, }, - _ => None, + _ => return None, + }; + + Some(Range { ty, start, end, span }) + } +} + +/// A type that can appear as the type of a range expression. +/// +/// This is a component of [`Range`]. +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub enum RangeTy { + /// [`core::ops::RangeFrom`] + OpsFrom, + /// [`core::range::RangeFrom`] + RangeFrom, + + /// [`core::ops::RangeFull`] + OpsFull, + + /// [`core::ops::Range`] + OpsRange, + /// [`core::range::Range`] + RangeRange, + + /// [`core::ops::RangeInclusive`] + OpsInclusive, + /// [`core::range::RangeInclusive`] + RangeInclusive, + + /// [`core::ops::RangeTo`] + OpsTo, + + /// [`core::ops::RangeToInclusive`] + OpsToInclusive, + /// [`core::range::RangeToInclusive`] + RangeToInclusive, +} + +#[expect(clippy::match_same_arms, reason = "regularity over density")] +impl RangeTy { + /// Returns whether this type implements [`IntoIterator`] — that is, whether it is iterable — + /// presuming that its element type implements the `Step` trait. + pub fn implements_into_iterator(self) -> bool { + match self { + RangeTy::OpsFrom => true, + RangeTy::RangeFrom => true, + RangeTy::OpsRange => true, + RangeTy::RangeRange => true, + RangeTy::OpsInclusive => true, + RangeTy::RangeInclusive => true, + + RangeTy::OpsFull => false, + RangeTy::OpsTo => false, + RangeTy::OpsToInclusive => false, + RangeTy::RangeToInclusive => false, + } + } + + /// Returns whether this type implements [`Iterator`] directly, and [`IntoIterator`] via blanket + /// impl, presuming that its element type implements the `Step` trait. + pub fn implements_iterator(self) -> bool { + match self { + RangeTy::OpsFrom => true, + RangeTy::OpsRange => true, + RangeTy::OpsInclusive => true, + + // New range types don’t implement Iterator, only IntoIterator + RangeTy::RangeFrom => false, + RangeTy::RangeRange => false, + RangeTy::RangeInclusive => false, + + // Non-iterables + RangeTy::OpsFull => false, + RangeTy::OpsTo => false, + RangeTy::OpsToInclusive => false, + RangeTy::RangeToInclusive => false, + } + } + + pub fn limits(self) -> ast::RangeLimits { + match self { + RangeTy::RangeFrom => ast::RangeLimits::HalfOpen, + RangeTy::OpsRange => ast::RangeLimits::HalfOpen, + RangeTy::RangeRange => ast::RangeLimits::HalfOpen, + + RangeTy::OpsFrom => ast::RangeLimits::HalfOpen, + RangeTy::OpsTo => ast::RangeLimits::HalfOpen, + RangeTy::OpsFull => ast::RangeLimits::HalfOpen, + + RangeTy::OpsInclusive => ast::RangeLimits::Closed, + RangeTy::RangeInclusive => ast::RangeLimits::Closed, + RangeTy::OpsToInclusive => ast::RangeLimits::Closed, + RangeTy::RangeToInclusive => ast::RangeLimits::Closed, } } } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 0264c68776085..56a5e80df2df8 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -75,7 +75,7 @@ use core::mem; use core::ops::ControlFlow; use std::collections::hash_map::Entry; use std::iter::{once, repeat_n, zip}; -use std::sync::{Mutex, MutexGuard, OnceLock}; +use std::sync::{Mutex, OnceLock}; use itertools::Itertools; use rustc_abi::Integer; @@ -1330,10 +1330,10 @@ pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { /// Checks whether the given `Expr` is a range over the entire container. pub fn is_full_collection_range(cx: &LateContext<'_>, container: Option, expr: &Expr<'_>) -> bool { - if let Some(Range { start, end, limits, .. }) = Range::hir(cx, expr) { + if let Some(Range { start, end, ty, .. }) = Range::hir(cx, expr) { start.is_none_or(|start| is_integer_literal(start, 0)) && end.is_none_or(|end| { - if limits == RangeLimits::HalfOpen + if ty.limits() == RangeLimits::HalfOpen && let Some(container) = container && let ExprKind::MethodCall(seg, recv, [], _) = end.kind { @@ -2350,14 +2350,13 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { static TEST_ITEM_NAMES_CACHE: OnceLock>>> = OnceLock::new(); -/// Apply `f()` to the set of test item names. +/// Returns the names of the test items in the given module. /// The names are sorted using the default `Symbol` ordering. -fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl FnOnce(&[Symbol]) -> bool) -> bool { +fn test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId) -> Vec { let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default())); - let mut map: MutexGuard<'_, FxHashMap>> = cache.lock().unwrap(); - let value = map.entry(module); - match value { - Entry::Occupied(entry) => f(entry.get()), + let mut map = cache.lock().unwrap(); + match map.entry(module) { + Entry::Occupied(entry) => entry.get().clone(), Entry::Vacant(entry) => { let mut names = Vec::new(); for id in tcx.hir_module_free_items(module) { @@ -2373,7 +2372,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl FnOnce(& } } names.sort_unstable(); - f(entry.insert(names)) + entry.insert(names).clone() }, } } @@ -2382,23 +2381,25 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl FnOnce(& /// /// Note: Add `//@compile-flags: --test` to UI tests with a `#[test]` function pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool { - with_test_item_names(tcx, tcx.parent_module(id), |names| { - let node = tcx.hir_node(id); - once((id, node)) - .chain(tcx.hir_parent_iter(id)) - // Since you can nest functions we need to collect all until we leave - // function scope - .any(|(_id, node)| { - if let Node::Item(item) = node - && let ItemKind::Fn { ident, .. } = item.kind - { - // Note that we have sorted the item names in the visitor, - // so the binary_search gets the same as `contains`, but faster. - return names.binary_search(&ident.name).is_ok(); - } - false - }) - }) + let names = test_item_names(tcx, tcx.parent_module(id)); + // Without `--test` there are no test items, so the parent walk can never match. + if names.is_empty() { + return false; + } + once((id, tcx.hir_node(id))) + .chain(tcx.hir_parent_iter(id)) + // Since you can nest functions we need to collect all until we leave + // function scope + .any(|(_id, node)| { + if let Node::Item(item) = node + && let ItemKind::Fn { ident, .. } = item.kind + { + // Note that we have sorted the item names in the visitor, + // so the binary_search gets the same as `contains`, but faster. + return names.binary_search(&ident.name).is_ok(); + } + false + }) } /// Checks if `fn_def_id` has a `#[test]` attribute applied @@ -2412,9 +2413,9 @@ pub fn is_test_function(tcx: TyCtxt<'_>, fn_def_id: LocalDefId) -> bool { if let Node::Item(item) = tcx.hir_node(id) && let ItemKind::Fn { ident, .. } = item.kind { - with_test_item_names(tcx, tcx.parent_module(id), |names| { - names.binary_search(&ident.name).is_ok() - }) + test_item_names(tcx, tcx.parent_module(id)) + .binary_search(&ident.name) + .is_ok() } else { false } @@ -3257,7 +3258,10 @@ fn get_path_to_ty<'tcx>(tcx: TyCtxt<'tcx>, from: LocalDefId, ty: Ty<'tcx>, args: | rustc_ty::RawPtr(_, _) | rustc_ty::Ref(..) | rustc_ty::Slice(_) - | rustc_ty::Tuple(_) => format!("<{}>", EarlyBinder::bind(tcx, ty).instantiate(tcx, args).skip_norm_wip()), + | rustc_ty::Tuple(_) => format!( + "<{}>", + EarlyBinder::bind(tcx, ty).instantiate(tcx, args).skip_norm_wip() + ), _ => ty.to_string(), } } diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index d9b34ebfe21e4..1004db46ca49c 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -3,7 +3,8 @@ use rustc_ast::Attribute; use rustc_ast::attr::AttributeExt; use rustc_attr_parsing::parse_version; use rustc_data_structures::smallvec::SmallVec; -use rustc_hir::{HirId, RustcVersion}; +use rustc_hir::def_id::DefId; +use rustc_hir::{HirId, RustcVersion, StabilityLevel, StableSince}; use rustc_lint::LateContext; use rustc_middle::ty::TyCtxt; use rustc_session::Session; @@ -24,7 +25,7 @@ macro_rules! msrv_aliases { // names may refer to stabilized feature flags or library items msrv_aliases! { - 1,97,0 { ISOLATE_LOWEST_ONE } + 1,97,0 { ISOLATE_LOWEST_ONE, BIT_WIDTH } 1,93,0 { VEC_DEQUE_POP_BACK_IF, VEC_DEQUE_POP_FRONT_IF } 1,91,0 { DURATION_FROM_MINUTES_HOURS } 1,88,0 { LET_CHAINS, AS_CHUNKS } @@ -175,6 +176,25 @@ impl Msrv { _ => {}, } } + + pub fn is_stable(self, cx: &LateContext<'_>, def_id: DefId) -> bool { + cx.tcx.lookup_stability(def_id).is_none_or(|stability| { + if let StabilityLevel::Stable { since, .. } = stability.level { + let version = match since { + StableSince::Version(version) => version, + StableSince::Current => RustcVersion::CURRENT, + StableSince::Err(_) => return false, + }; + + self.meets(cx, version) + } else { + // Unstable fn. + // FIXME: can we check that the feature is enabled? + // Please see https://github.com/rust-lang/rust-clippy/pull/17309#discussion_r3486693263 for false-positive concerns. + false + } + }) + } } /// Tracks the current MSRV from `clippy.toml`, `Cargo.toml` or set via `#[clippy::msrv]` in early diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 5c61f424adf1a..0e94868144f05 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -86,10 +86,13 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, msrv: Msrv) ty::Ref(_, _, hir::Mutability::Mut) if !msrv.meets(cx, msrvs::CONST_MUT_REFS) => { return Err((span, "mutable references in const fn are unstable".into())); }, - ty::Alias(_, ty::AliasTy { - kind: ty::Opaque { .. }, - .. - }) => return Err((span, "`impl Trait` in const fn is unstable".into())), + ty::Alias( + _, + ty::AliasTy { + kind: ty::Opaque { .. }, + .. + }, + ) => return Err((span, "`impl Trait` in const fn is unstable".into())), ty::FnPtr(..) => { return Err((span, "function pointers in const fn are unstable".into())); }, diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index f194103ae2e88..5c1ae2ed8413d 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -133,7 +133,7 @@ impl<'a> Sugg<'a> { mut get_snippet: impl FnMut(Span) -> Cow<'a, str>, ) -> Self { if let Some(range) = higher::Range::hir(cx, expr) { - let op = AssocOp::Range(range.limits); + let op = AssocOp::Range(range.ty.limits()); let start = range.start.map_or("".into(), |expr| get_snippet(expr.span)); let end = range.end.map_or("".into(), |expr| get_snippet(expr.span)); @@ -715,19 +715,19 @@ pub trait DiagExt { applicability: Applicability, ); - /// Suggest to add an item before another. + /// Suggest to add an item after another. /// /// The item should not be indented (except for inner indentation). /// /// # Example /// /// ```rust,ignore - /// diag.suggest_prepend_item(cx, item, + /// diag.suggest_append_item(cx, item, /// "fn foo() { /// bar(); /// }"); /// ``` - fn suggest_prepend_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str, applicability: Applicability); + fn suggest_append_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str, applicability: Applicability); /// Suggest to completely remove an item. /// @@ -759,24 +759,19 @@ impl DiagExt for rustc_errors::Diag<'_, ()> { } } - fn suggest_prepend_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str, applicability: Applicability) { + fn suggest_append_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str, applicability: Applicability) { if let Some(indent) = indentation(cx, item) { - let span = item.with_hi(item.lo()); - - let mut first = true; - let new_item = new_item - .lines() - .map(|l| { - if first { - first = false; - format!("{l}\n") - } else { - format!("{indent}{l}\n") - } - }) - .collect::(); - - self.span_suggestion(span, msg.to_string(), format!("{new_item}\n{indent}"), applicability); + let span = item.shrink_to_hi(); + let mut new_item_code = String::new(); + for l in new_item.lines() { + writeln!(new_item_code, "{indent}{l}").unwrap(); + } + self.span_suggestion( + span, + msg.to_string(), + format!("\n\n{}", new_item_code.strip_suffix('\n').unwrap()), + applicability, + ); } } diff --git a/clippy_utils/src/sym.rs b/clippy_utils/src/sym.rs index 6053788c82b13..5da94bfda5e6c 100644 --- a/clippy_utils/src/sym.rs +++ b/clippy_utils/src/sym.rs @@ -40,6 +40,7 @@ generate! { AsyncReadExt, AsyncWriteExt, BACKSLASH_SINGLE_QUOTE: r"\'", + BITS, BTreeEntry, BTreeSet, Binary, diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index e4541eb2d6061..ca4ed5150257f 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -104,10 +104,13 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return true; } - if let ty::Alias(_, AliasTy { - kind: ty::Opaque { def_id }, - .. - }) = *inner_ty.kind() + if let ty::Alias( + _, + AliasTy { + kind: ty::Opaque { def_id }, + .. + }, + ) = *inner_ty.kind() { if !seen.insert(def_id) { return false; @@ -337,10 +340,13 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { is_must_use_ty(cx, *ty) }, ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Alias(_, AliasTy { - kind: ty::Opaque { def_id }, - .. - }) => { + ty::Alias( + _, + AliasTy { + kind: ty::Opaque { def_id }, + .. + }, + ) => { for (predicate, _) in cx.tcx.explicit_item_self_bounds(*def_id).skip_binder() { if let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() && find_attr!(cx.tcx, trait_predicate.trait_ref.def_id, MustUse { .. }) @@ -525,7 +531,7 @@ fn is_uninit_value_valid_for_layout<'tcx>(cx: &LateContext<'tcx>, layout: TyAndL match layout.layout.backend_repr { BackendRepr::Scalar(s) => s.is_uninit_valid(), - BackendRepr::ScalarPair { a, b, b_offset: _ } => a.is_uninit_valid() && b.is_uninit_valid(), + BackendRepr::ScalarPair { a, b, .. } => a.is_uninit_valid() && b.is_uninit_valid(), BackendRepr::SimdVector { element, count } => count == 0 || element.is_uninit_valid(), BackendRepr::SimdScalableVector { element, .. } => element.is_uninit_valid(), // Here validity is determined by the structural fields instead. @@ -716,11 +722,14 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option sig_from_bounds( + ty::Alias( + _, + AliasTy { + kind: ty::Opaque { def_id }, + args, + .. + }, + ) => sig_from_bounds( cx, ty, cx.tcx @@ -1174,7 +1183,10 @@ pub fn make_normalized_projection<'tcx>( ); return None; } - match tcx.try_normalize_erasing_regions(typing_env, Unnormalized::new_wip(Ty::new_alias(tcx, ty::IsRigid::No, ty))) { + match tcx.try_normalize_erasing_regions( + typing_env, + Unnormalized::new_wip(Ty::new_alias(tcx, ty::IsRigid::No, ty)), + ) { Ok(ty) => Some(ty), Err(e) => { debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); @@ -1276,10 +1288,13 @@ impl<'tcx> InteriorMut<'tcx> { .find_map(|f| self.interior_mut_ty_chain_inner(cx, f.ty(cx.tcx, args).skip_norm_wip(), depth)) } }, - ty::Alias(_, AliasTy { - kind: ty::Projection { .. }, - .. - }) => match cx + ty::Alias( + _, + AliasTy { + kind: ty::Projection { .. }, + .. + }, + ) => match cx .tcx .try_normalize_erasing_regions(cx.typing_env(), Unnormalized::new_wip(ty)) { @@ -1328,7 +1343,10 @@ pub fn make_normalized_projection_with_regions<'tcx>( } let cause = ObligationCause::dummy(); let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); - match infcx.at(&cause, param_env).query_normalize(Ty::new_alias(tcx, ty::IsRigid::No, ty)) { + match infcx + .at(&cause, param_env) + .query_normalize(Ty::new_alias(tcx, ty::IsRigid::No, ty)) + { Ok(ty) => Some(ty.value), Err(e) => { debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index ca1fa57cffc10..85f983f836d23 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -6,10 +6,10 @@ use crate::ty::needs_ordered_drop; use core::ops::ControlFlow; use rustc_ast::visit::{VisitorResult, try_visit}; use rustc_hir::def::{CtorKind, DefKind, Res}; -use rustc_hir::intravisit::{self, Visitor, walk_block, walk_expr}; +use rustc_hir::intravisit::{self, Visitor, walk_block, walk_expr, walk_qpath}; use rustc_hir::{ - self as hir, AmbigArg, AnonConst, Arm, Block, BlockCheckMode, Body, BodyId, CRATE_HIR_ID, Expr, ExprKind, HirId, - ItemId, ItemKind, LetExpr, Pat, QPath, Stmt, StructTailExpr, UnOp, UnsafeSource, + self as hir, AmbigArg, AnonConst, Arm, Block, BlockCheckMode, Body, BodyId, CRATE_HIR_ID, ConstBlock, Expr, + ExprKind, HirId, ItemId, ItemKind, LetExpr, Pat, QPath, Stmt, StructTailExpr, UnOp, UnsafeSource, }; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; @@ -322,71 +322,165 @@ pub fn is_local_used<'tcx>(cx: &LateContext<'tcx>, visitable: impl Visitable<'tc .is_some() } +/// Returns whether the given expression can be evaluated as a constant assuming that all its sub +/// expressions can be evaluated as constants. +fn is_const_evaluatable_helper<'tcx>(tcx: TyCtxt<'tcx>, typeck: &'tcx TypeckResults<'tcx>, e: &'tcx Expr<'_>) -> bool { + match e.kind { + ExprKind::Call( + &Expr { + kind: ExprKind::Path(ref p), + hir_id, + .. + }, + _, + ) if typeck + .qpath_res(p, hir_id) + .opt_def_id() + .is_some_and(|id| is_stable_const_fn_at(tcx, CRATE_HIR_ID, id, Msrv::default())) => + { + true + }, + ExprKind::MethodCall(..) + if typeck + .type_dependent_def_id(e.hir_id) + .is_some_and(|id| is_stable_const_fn_at(tcx, CRATE_HIR_ID, id, Msrv::default())) => + { + true + }, + ExprKind::Binary(_, lhs, rhs) + if typeck.expr_ty(lhs).peel_refs().is_primitive_ty() + && typeck.expr_ty(rhs).peel_refs().is_primitive_ty() => + { + true + }, + ExprKind::Unary(UnOp::Deref, e) if typeck.expr_ty(e).is_raw_ptr() => true, + ExprKind::Unary(_, e) if typeck.expr_ty(e).peel_refs().is_primitive_ty() => true, + ExprKind::Index(base, _, _) + if matches!(typeck.expr_ty(base).peel_refs().kind(), ty::Slice(_) | ty::Array(..)) => + { + true + }, + ExprKind::Path(ref p) + if matches!( + typeck.qpath_res(p, e.hir_id), + Res::Def( + DefKind::Const { .. } + | DefKind::AssocConst { .. } + | DefKind::AnonConst + | DefKind::ConstParam + | DefKind::Ctor(..) + | DefKind::Fn + | DefKind::AssocFn, + _ + ) | Res::SelfCtor(_) + ) => + { + true + }, + + ExprKind::AddrOf(..) + | ExprKind::Array(_) + | ExprKind::Block(..) + | ExprKind::Cast(..) + | ExprKind::ConstBlock(_) + | ExprKind::DropTemps(_) + | ExprKind::Field(..) + | ExprKind::If(..) + | ExprKind::Let(..) + | ExprKind::Lit(_) + | ExprKind::Match(..) + | ExprKind::Repeat(..) + | ExprKind::Struct(..) + | ExprKind::Tup(_) + | ExprKind::Type(..) + | ExprKind::UnsafeBinderCast(..) => true, + + _ => false, + } +} + /// Checks if the given expression can be evaluated as a constant at the specified node pub fn is_const_evaluatable<'tcx>(tcx: TyCtxt<'tcx>, typeck: &'tcx TypeckResults<'tcx>, e: &'tcx Expr<'_>) -> bool { for_each_expr(tcx, e, move |e| { - match e.kind { - ExprKind::ConstBlock(_) => return ControlFlow::Continue(Descend::No), - ExprKind::Call( - &Expr { - kind: ExprKind::Path(ref p), - hir_id, - .. - }, - _, - ) if typeck - .qpath_res(p, hir_id) - .opt_def_id() - .is_some_and(|id| is_stable_const_fn_at(tcx, CRATE_HIR_ID, id, Msrv::default())) => {}, - ExprKind::MethodCall(..) - if typeck - .type_dependent_def_id(e.hir_id) - .is_some_and(|id| is_stable_const_fn_at(tcx, CRATE_HIR_ID, id, Msrv::default())) => {}, - ExprKind::Binary(_, lhs, rhs) - if typeck.expr_ty(lhs).peel_refs().is_primitive_ty() - && typeck.expr_ty(rhs).peel_refs().is_primitive_ty() => {}, - ExprKind::Unary(UnOp::Deref, e) if typeck.expr_ty(e).is_raw_ptr() => (), - ExprKind::Unary(_, e) if typeck.expr_ty(e).peel_refs().is_primitive_ty() => (), - ExprKind::Index(base, _, _) - if matches!(typeck.expr_ty(base).peel_refs().kind(), ty::Slice(_) | ty::Array(..)) => {}, - ExprKind::Path(ref p) - if matches!( - typeck.qpath_res(p, e.hir_id), - Res::Def( - DefKind::Const { .. } - | DefKind::AssocConst { .. } - | DefKind::AnonConst - | DefKind::ConstParam - | DefKind::Ctor(..) - | DefKind::Fn - | DefKind::AssocFn, - _ - ) | Res::SelfCtor(_) - ) => {}, - - ExprKind::AddrOf(..) - | ExprKind::Array(_) - | ExprKind::Block(..) - | ExprKind::Cast(..) - | ExprKind::DropTemps(_) - | ExprKind::Field(..) - | ExprKind::If(..) - | ExprKind::Let(..) - | ExprKind::Lit(_) - | ExprKind::Match(..) - | ExprKind::Repeat(..) - | ExprKind::Struct(..) - | ExprKind::Tup(_) - | ExprKind::Type(..) - | ExprKind::UnsafeBinderCast(..) => {}, - - _ => return ControlFlow::Break(()), + if !is_const_evaluatable_helper(tcx, typeck, e) { + ControlFlow::Break(()) + } else if matches!(e.kind, ExprKind::ConstBlock(_)) { + ControlFlow::Continue(Descend::No) + } else { + ControlFlow::Continue(Descend::Yes) } - ControlFlow::Continue(Descend::Yes) }) .is_none() } +/// Checks if the given expression can be used as a const parameter. +/// +/// This is more strict than `is_const_evaluatable` as it requires that the expression does not +/// contain any type parameters or any operations on const parameters. +pub fn is_const_param_evaluatable<'tcx>( + tcx: TyCtxt<'tcx>, + typeck: &'tcx TypeckResults<'tcx>, + e: &'tcx Expr<'_>, +) -> bool { + struct V1<'tcx> { + tcx: TyCtxt<'tcx>, + typeck: &'tcx TypeckResults<'tcx>, + } + impl<'tcx> Visitor<'tcx> for V1<'tcx> { + type NestedFilter = nested_filter::OnlyBodies; + type Result = ControlFlow<()>; + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.tcx + } + fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) -> Self::Result { + if !is_const_evaluatable_helper(self.tcx, self.typeck, e) { + return ControlFlow::Break(()); + } + walk_expr(self, e) + } + fn visit_inline_const(&mut self, c: &'tcx ConstBlock) -> Self::Result { + V2(self.tcx).visit_inline_const(c) + } + fn visit_anon_const(&mut self, c: &'tcx AnonConst) -> Self::Result { + V2(self.tcx).visit_anon_const(c) + } + fn visit_qpath(&mut self, qpath: &'tcx QPath<'tcx>, id: HirId, _span: Span) -> Self::Result { + if matches!(qpath.basic_res(), Res::Def(DefKind::ConstParam | DefKind::TyParam, _)) { + return ControlFlow::Break(()); + } + walk_qpath(self, qpath, id) + } + } + + struct V2<'tcx>(TyCtxt<'tcx>); + impl<'tcx> Visitor<'tcx> for V2<'tcx> { + type NestedFilter = nested_filter::OnlyBodies; + type Result = ControlFlow<()>; + fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { + self.0 + } + fn visit_qpath(&mut self, qpath: &'tcx QPath<'tcx>, id: HirId, _span: Span) -> Self::Result { + if matches!(qpath.basic_res(), Res::Def(DefKind::ConstParam | DefKind::TyParam, _)) { + return ControlFlow::Break(()); + } + walk_qpath(self, qpath, id) + } + } + + // We have to work around limitations of `#![feature(generic_const_exprs)]` being unstable. + // A const parameter (e.g. `N` in `fn foo()`) can be used as is, but any + // expression involving a const parameter (e.g. `N * 2`) will be a compiler error. + // Any type parameter (e.g. `T` in `fn foo()`) will be a compiler error. + + if let ExprKind::Path(ref qpath) = e.kind + && matches!(qpath.basic_res(), Res::Def(DefKind::ConstParam, _)) + { + return true; + } + + V1 { tcx, typeck }.visit_expr(e).is_continue() +} + /// Checks if the given expression performs an unsafe operation outside of an unsafe block. pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { struct V<'a, 'tcx> { diff --git a/declare_clippy_lint/Cargo.toml b/declare_clippy_lint/Cargo.toml index 93def90352ada..0210344d11a6c 100644 --- a/declare_clippy_lint/Cargo.toml +++ b/declare_clippy_lint/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "declare_clippy_lint" -version = "0.1.98" +version = "0.1.99" edition = "2024" repository = "https://github.com/rust-lang/rust-clippy" license = "MIT OR Apache-2.0" diff --git a/lintcheck/Cargo.toml b/lintcheck/Cargo.toml index 197a8574af2d0..e4451af282732 100644 --- a/lintcheck/Cargo.toml +++ b/lintcheck/Cargo.toml @@ -16,7 +16,7 @@ clap = { version = "4.4", features = ["derive", "env"] } crossbeam-channel = "0.5.6" diff = "0.1.13" flate2 = "1.0" -itertools = "0.13" +itertools = "0.15" rayon = "1.5.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.85" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index ac044327aafe9..d6306869ba743 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,6 +1,6 @@ [toolchain] # begin autogenerated nightly -channel = "nightly-2026-06-25" +channel = "nightly-2026-07-09" # end autogenerated nightly components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] profile = "minimal" diff --git a/src/main.rs b/src/main.rs index 98b888444831a..4b158c27ebbff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,9 +42,8 @@ pub fn main() { process::exit(clippy_lints::explain( &lint.strip_prefix("clippy::").unwrap_or(&lint).replace('-', "_"), )); - } else { - show_help(); } + show_help(); return; } diff --git a/tests/integration.rs b/tests/integration.rs index 2cb82b8b380b5..4275292fd86e6 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -102,13 +102,13 @@ fn integration_test() { panic!("incompatible crate versions"); } else if stderr.contains("failed to run `rustc` to learn about target-specific information") { panic!("couldn't find librustc_driver, consider setting `LD_LIBRARY_PATH`"); - } else { - assert!( - !stderr.contains("toolchain") || !stderr.contains("is not installed"), - "missing required toolchain" - ); } + assert!( + !stderr.contains("toolchain") || !stderr.contains("is not installed"), + "missing required toolchain" + ); + match output.status.code() { Some(0) => println!("Compilation successful"), Some(code) => eprintln!("Compilation failed. Exit code: {code}"), diff --git a/tests/ui/bad_bit_masks.rs b/tests/ui/bad_bit_masks.rs new file mode 100644 index 0000000000000..d83060b28ab6c --- /dev/null +++ b/tests/ui/bad_bit_masks.rs @@ -0,0 +1,125 @@ +//@aux-build:proc_macros.rs + +#![warn(clippy::bad_bit_mask)] +#![expect(clippy::erasing_op, clippy::identity_op)] + +use core::hint::black_box; +use core::ops::BitAnd; +use proc_macros::{external, with_span}; + +fn main() { + let x = black_box(5u32); + + let _ = x & 0b0000 == 0b0000; //~ bad_bit_mask + let _ = x & 0b0000 == 0b0001; //~ bad_bit_mask + let _ = x & 0b0001 == 0b0000; + let _ = x & 0b0001 == 0b0001; + let _ = x & 0b0010 == 0b0001; //~ bad_bit_mask + let _ = x & 0b0001 == 0b0010; //~ bad_bit_mask + let _ = x & 0b0011 == 0b0001; + let _ = x & 0b0011 == 0b0010; + let _ = x & 0b0011 == 0b0011; + let _ = x & 0b0011 == 0b0100; //~ bad_bit_mask + let _ = x & 0b0100 == 0b0100; + let _ = x & 0b0110 == 0b0111; //~ bad_bit_mask + let _ = x & 0b0011 == 0b0101; //~ bad_bit_mask + let _ = x & 0b1111 == 0b1110; + let _ = x & 0b1111 == 0b1010; + + let _ = x | 0b0000 == 0b0000; + let _ = x | 0b0000 == 0b0001; + let _ = x | 0b0001 == 0b0000; //~ bad_bit_mask + let _ = x | 0b0001 == 0b0001; + let _ = x | 0b0010 == 0b0001; //~ bad_bit_mask + let _ = x | 0b0001 == 0b0010; //~ bad_bit_mask + let _ = x | 0b0011 == 0b0001; //~ bad_bit_mask + let _ = x | 0b0011 == 0b0010; //~ bad_bit_mask + let _ = x | 0b0011 == 0b0011; + let _ = x | 0b0011 == 0b0100; //~ bad_bit_mask + let _ = x | 0b0100 == 0b0100; + let _ = x | 0b0110 == 0b0111; + let _ = x | 0b0011 == 0b0101; //~ bad_bit_mask + let _ = x | 0b1111 == 0b1110; //~ bad_bit_mask + let _ = x | 0b1111 == 0b1010; //~ bad_bit_mask + + let _ = x & 0b0000 != 0b0000; //~ bad_bit_mask + let _ = x & 0b0000 != 0b0001; //~ bad_bit_mask + let _ = x & 0b0001 != 0b0000; + let _ = x & 0b0001 != 0b0001; + let _ = x & 0b0010 != 0b0001; //~ bad_bit_mask + let _ = x & 0b0001 != 0b0010; //~ bad_bit_mask + let _ = x & 0b0011 != 0b0001; + let _ = x & 0b0011 != 0b0010; + let _ = x & 0b0011 != 0b0011; + let _ = x & 0b0011 != 0b0100; //~ bad_bit_mask + let _ = x & 0b0100 != 0b0100; + let _ = x & 0b0110 != 0b0111; //~ bad_bit_mask + let _ = x & 0b0011 != 0b0101; //~ bad_bit_mask + let _ = x & 0b1111 != 0b1110; + let _ = x & 0b1111 != 0b1010; + + let _ = x | 0b0000 != 0b0000; + let _ = x | 0b0000 != 0b0001; + let _ = x | 0b0001 != 0b0000; //~ bad_bit_mask + let _ = x | 0b0001 != 0b0001; + let _ = x | 0b0010 != 0b0001; //~ bad_bit_mask + let _ = x | 0b0001 != 0b0010; //~ bad_bit_mask + let _ = x | 0b0011 != 0b0001; //~ bad_bit_mask + let _ = x | 0b0011 != 0b0010; //~ bad_bit_mask + let _ = x | 0b0011 != 0b0011; + let _ = x | 0b0011 != 0b0100; //~ bad_bit_mask + let _ = x | 0b0100 != 0b0100; + let _ = x | 0b0110 != 0b0111; + let _ = x | 0b0011 != 0b0101; //~ bad_bit_mask + let _ = x | 0b1111 != 0b1110; //~ bad_bit_mask + let _ = x | 0b1111 != 0b1010; //~ bad_bit_mask + + let _ = 0b0010 & x == 0b0001; //~ bad_bit_mask + let _ = 0b0001 == x & 0b0010; //~ bad_bit_mask + let _ = 0b0001 == 0b0010 & x; //~ bad_bit_mask + + let _ = x & (0b0100 | 0b0010) == (0b0111 ^ 0b1000); //~ bad_bit_mask + + external! { + let x = black_box(5u32); + let _ = x & 0b0010 == 0b0001; + } + with_span! { + sp + let x = black_box(5u32); + let _ = x & 0b0010 == 0b0001; + } + + { + const C: i32 = 0b0011; + + let x = black_box(5i32); + let _ = x & C == 0b0011; + let _ = x & C == 0b0100; //~ bad_bit_mask + let _ = x & 0b0001 == C; //~ bad_bit_mask + } + + { + // Bits shifted out. + let _ = black_box(1u8) & 0xf0 == 0x11 << 4; + let _ = black_box(1i8) & 0x70 == 0x11 << 4; + let _ = black_box(1u16) & 0xf000 == 0x11 << 12; + let _ = black_box(1i16) & 0x7000 == 0x11 << 12; + } + + { + struct S(u32); + impl BitAnd for S { + type Output = Self; + fn bitand(self, _: u32) -> Self { + self + } + } + impl PartialEq for S { + fn eq(&self, _: &u32) -> bool { + true + } + } + let _ = black_box(S(0)) & 0x1 != 0; + } +} diff --git a/tests/ui/bad_bit_masks.stderr b/tests/ui/bad_bit_masks.stderr new file mode 100644 index 0000000000000..c72dc8515cff8 --- /dev/null +++ b/tests/ui/bad_bit_masks.stderr @@ -0,0 +1,308 @@ +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:13:13 + | +LL | let _ = x & 0b0000 == 0b0000; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `_ & 0` is always equal to zero + = note: `-D clippy::bad-bit-mask` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bad_bit_mask)]` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:14:13 + | +LL | let _ = x & 0b0000 == 0b0001; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `_ & 0` is always equal to zero + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:17:13 + | +LL | let _ = x & 0b0010 == 0b0001; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` is missing bits contained in the compared constant `0x1` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:18:13 + | +LL | let _ = x & 0b0001 == 0b0010; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` is missing bits contained in the compared constant `0x2` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:22:13 + | +LL | let _ = x & 0b0011 == 0b0100; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` is missing bits contained in the compared constant `0x4` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:24:13 + | +LL | let _ = x & 0b0110 == 0b0111; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x6` is missing bits contained in the compared constant `0x7` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:25:13 + | +LL | let _ = x & 0b0011 == 0b0101; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` is missing bits contained in the compared constant `0x5` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:31:13 + | +LL | let _ = x | 0b0001 == 0b0000; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` has bits not contained in the compared constant `0x0` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:33:13 + | +LL | let _ = x | 0b0010 == 0b0001; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` has bits not contained in the compared constant `0x1` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:34:13 + | +LL | let _ = x | 0b0001 == 0b0010; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` has bits not contained in the compared constant `0x2` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:35:13 + | +LL | let _ = x | 0b0011 == 0b0001; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` has bits not contained in the compared constant `0x1` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:36:13 + | +LL | let _ = x | 0b0011 == 0b0010; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` has bits not contained in the compared constant `0x2` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:38:13 + | +LL | let _ = x | 0b0011 == 0b0100; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` has bits not contained in the compared constant `0x4` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:41:13 + | +LL | let _ = x | 0b0011 == 0b0101; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` has bits not contained in the compared constant `0x5` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:42:13 + | +LL | let _ = x | 0b1111 == 0b1110; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` has bits not contained in the compared constant `0xe` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:43:13 + | +LL | let _ = x | 0b1111 == 0b1010; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` has bits not contained in the compared constant `0xa` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:45:13 + | +LL | let _ = x & 0b0000 != 0b0000; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `_ & 0` is always equal to zero + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:46:13 + | +LL | let _ = x & 0b0000 != 0b0001; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `_ & 0` is always equal to zero + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:49:13 + | +LL | let _ = x & 0b0010 != 0b0001; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` is missing bits contained in the compared constant `0x1` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:50:13 + | +LL | let _ = x & 0b0001 != 0b0010; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` is missing bits contained in the compared constant `0x2` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:54:13 + | +LL | let _ = x & 0b0011 != 0b0100; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` is missing bits contained in the compared constant `0x4` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:56:13 + | +LL | let _ = x & 0b0110 != 0b0111; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x6` is missing bits contained in the compared constant `0x7` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:57:13 + | +LL | let _ = x & 0b0011 != 0b0101; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` is missing bits contained in the compared constant `0x5` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:63:13 + | +LL | let _ = x | 0b0001 != 0b0000; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` has bits not contained in the compared constant `0x0` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:65:13 + | +LL | let _ = x | 0b0010 != 0b0001; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` has bits not contained in the compared constant `0x1` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:66:13 + | +LL | let _ = x | 0b0001 != 0b0010; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` has bits not contained in the compared constant `0x2` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:67:13 + | +LL | let _ = x | 0b0011 != 0b0001; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` has bits not contained in the compared constant `0x1` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:68:13 + | +LL | let _ = x | 0b0011 != 0b0010; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` has bits not contained in the compared constant `0x2` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:70:13 + | +LL | let _ = x | 0b0011 != 0b0100; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` has bits not contained in the compared constant `0x4` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:73:13 + | +LL | let _ = x | 0b0011 != 0b0101; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` has bits not contained in the compared constant `0x5` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:74:13 + | +LL | let _ = x | 0b1111 != 0b1110; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` has bits not contained in the compared constant `0xe` + +error: this comparison is always true + --> tests/ui/bad_bit_masks.rs:75:13 + | +LL | let _ = x | 0b1111 != 0b1010; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` has bits not contained in the compared constant `0xa` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:77:13 + | +LL | let _ = 0b0010 & x == 0b0001; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` is missing bits contained in the compared constant `0x1` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:78:13 + | +LL | let _ = 0b0001 == x & 0b0010; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` is missing bits contained in the compared constant `0x1` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:79:13 + | +LL | let _ = 0b0001 == 0b0010 & x; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` is missing bits contained in the compared constant `0x1` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:81:13 + | +LL | let _ = x & (0b0100 | 0b0010) == (0b0111 ^ 0b1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x6` is missing bits contained in the compared constant `0xf` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:98:17 + | +LL | let _ = x & C == 0b0100; + | ^^^^^^^^^^^^^^^ + | + = note: `0x3` is missing bits contained in the compared constant `0x4` + +error: this comparison is always false + --> tests/ui/bad_bit_masks.rs:99:17 + | +LL | let _ = x & 0b0001 == C; + | ^^^^^^^^^^^^^^^ + | + = note: `0x1` is missing bits contained in the compared constant `0x3` + +error: aborting due to 38 previous errors + diff --git a/tests/ui/bit_masks.rs b/tests/ui/bit_masks.rs deleted file mode 100644 index 30dd8f912acfd..0000000000000 --- a/tests/ui/bit_masks.rs +++ /dev/null @@ -1,123 +0,0 @@ -const THREE_BITS: i64 = 7; -const EVEN_MORE_REDIRECTION: i64 = THREE_BITS; - -#[warn(clippy::bad_bit_mask)] -#[allow( - clippy::ineffective_bit_mask, - clippy::identity_op, - clippy::no_effect, - clippy::unnecessary_operation -)] -fn main() { - let x = 5; - - x & 0 == 0; - //~^ bad_bit_mask - //~| erasing_op - - x & 1 == 1; //ok, distinguishes bit 0 - x & 1 == 0; //ok, compared with zero - x & 2 == 1; - //~^ bad_bit_mask - - x | 0 == 0; //ok, equals x == 0 (maybe warn?) - x | 1 == 3; //ok, equals x == 2 || x == 3 - x | 3 == 3; //ok, equals x <= 3 - x | 3 == 2; - //~^ bad_bit_mask - - x & 1 > 1; - //~^ bad_bit_mask - - x & 2 > 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0 - x & 2 < 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0 - x | 1 > 1; // ok (if a bit silly), equals x > 1 - x | 2 > 1; - //~^ bad_bit_mask - - x | 2 <= 2; // ok (if a bit silly), equals x <= 2 - - x & 192 == 128; // ok, tests for bit 7 and not bit 6 - x & 0xffc0 == 0xfe80; // ok - - // this also now works with constants - x & THREE_BITS == 8; - //~^ bad_bit_mask - - x | EVEN_MORE_REDIRECTION < 7; - //~^ bad_bit_mask - - 0 & x == 0; - //~^ bad_bit_mask - //~| erasing_op - - 1 | x > 1; - - // and should now also match uncommon usage - 1 < 2 | x; - //~^ bad_bit_mask - - 2 == 3 | x; - //~^ bad_bit_mask - - 1 == x & 2; - //~^ bad_bit_mask - - x | 1 > 2; // no error, because we allowed ineffective bit masks - ineffective(); -} - -#[warn(clippy::ineffective_bit_mask)] -#[allow(clippy::bad_bit_mask, clippy::no_effect, clippy::unnecessary_operation)] -fn ineffective() { - let x = 5; - - x | 1 > 3; - //~^ ineffective_bit_mask - - x | 1 < 4; - //~^ ineffective_bit_mask - - x | 1 <= 3; - //~^ ineffective_bit_mask - - x | 1 >= 8; - //~^ ineffective_bit_mask - - x | 1 > 2; // not an error (yet), better written as x >= 2 - x | 1 >= 7; // not an error (yet), better written as x >= 6 - x | 3 > 4; // not an error (yet), better written as x >= 4 - x | 4 <= 19; -} - -mod issue16781 { - fn unsigned(x: u8) -> bool { - x & 0xf0 == 0x11 << 4 - } - - fn signed(x: i8) -> bool { - x & 0x70 == 0x11 << 4 - } -} - -mod issue16935 { - struct Wrapper(usize); - - impl std::ops::BitAnd for Wrapper { - type Output = Self; - - fn bitand(self, rhs: usize) -> Self::Output { - Self(self.0 & rhs) - } - } - - impl PartialEq for Wrapper { - fn eq(&self, other: &usize) -> bool { - self.0.eq(other) - } - } - - fn check(value: Wrapper) -> bool { - value & 0x1 != 0 - } -} diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr deleted file mode 100644 index 666ad671edee6..0000000000000 --- a/tests/ui/bit_masks.stderr +++ /dev/null @@ -1,112 +0,0 @@ -error: &-masking with zero - --> tests/ui/bit_masks.rs:14:5 - | -LL | x & 0 == 0; - | ^^^^^^^^^^ - | - = note: `-D clippy::bad-bit-mask` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::bad_bit_mask)]` - -error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/bit_masks.rs:14:5 - | -LL | x & 0 == 0; - | ^^^^^ - | - = note: `#[deny(clippy::erasing_op)]` on by default - -error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> tests/ui/bit_masks.rs:20:5 - | -LL | x & 2 == 1; - | ^^^^^^^^^^ - -error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> tests/ui/bit_masks.rs:26:5 - | -LL | x | 3 == 2; - | ^^^^^^^^^^ - -error: incompatible bit mask: `_ & 1` will never be higher than `1` - --> tests/ui/bit_masks.rs:29:5 - | -LL | x & 1 > 1; - | ^^^^^^^^^ - -error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> tests/ui/bit_masks.rs:35:5 - | -LL | x | 2 > 1; - | ^^^^^^^^^ - -error: incompatible bit mask: `_ & 7` can never be equal to `8` - --> tests/ui/bit_masks.rs:44:5 - | -LL | x & THREE_BITS == 8; - | ^^^^^^^^^^^^^^^^^^^ - -error: incompatible bit mask: `_ | 7` will never be lower than `7` - --> tests/ui/bit_masks.rs:47:5 - | -LL | x | EVEN_MORE_REDIRECTION < 7; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: &-masking with zero - --> tests/ui/bit_masks.rs:50:5 - | -LL | 0 & x == 0; - | ^^^^^^^^^^ - -error: this operation will always return zero. This is likely not the intended outcome - --> tests/ui/bit_masks.rs:50:5 - | -LL | 0 & x == 0; - | ^^^^^ - -error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> tests/ui/bit_masks.rs:57:5 - | -LL | 1 < 2 | x; - | ^^^^^^^^^ - -error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> tests/ui/bit_masks.rs:60:5 - | -LL | 2 == 3 | x; - | ^^^^^^^^^^ - -error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> tests/ui/bit_masks.rs:63:5 - | -LL | 1 == x & 2; - | ^^^^^^^^^^ - -error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> tests/ui/bit_masks.rs:75:5 - | -LL | x | 1 > 3; - | ^^^^^^^^^ - | - = note: `-D clippy::ineffective-bit-mask` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::ineffective_bit_mask)]` - -error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly - --> tests/ui/bit_masks.rs:78:5 - | -LL | x | 1 < 4; - | ^^^^^^^^^ - -error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> tests/ui/bit_masks.rs:81:5 - | -LL | x | 1 <= 3; - | ^^^^^^^^^^ - -error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly - --> tests/ui/bit_masks.rs:84:5 - | -LL | x | 1 >= 8; - | ^^^^^^^^^^ - -error: aborting due to 17 previous errors - diff --git a/tests/ui/borrow_as_ptr.fixed b/tests/ui/borrow_as_ptr.fixed index 439aea6f05b4f..9fce39c27604d 100644 --- a/tests/ui/borrow_as_ptr.fixed +++ b/tests/ui/borrow_as_ptr.fixed @@ -65,3 +65,9 @@ fn issue15389() { let _ = &var as *const u32; }; } + +fn issue17197() { + let x = 0u32; + // implicit cast doesn't lint in proc-macros + proc_macros::with_span!(span let _: *const _ = &x;); +} diff --git a/tests/ui/borrow_as_ptr.rs b/tests/ui/borrow_as_ptr.rs index b268f1e2df745..ae2fe9901f1cd 100644 --- a/tests/ui/borrow_as_ptr.rs +++ b/tests/ui/borrow_as_ptr.rs @@ -65,3 +65,9 @@ fn issue15389() { let _ = &var as *const u32; }; } + +fn issue17197() { + let x = 0u32; + // implicit cast doesn't lint in proc-macros + proc_macros::with_span!(span let _: *const _ = &x;); +} diff --git a/tests/ui/chunks_exact_to_as_chunks.rs b/tests/ui/chunks_exact_to_as_chunks.rs index 0d5f4d06043d1..cc1e352280fc4 100644 --- a/tests/ui/chunks_exact_to_as_chunks.rs +++ b/tests/ui/chunks_exact_to_as_chunks.rs @@ -1,5 +1,5 @@ #![warn(clippy::chunks_exact_to_as_chunks)] -#![allow(unused)] +#![allow(unused, clippy::redundant_closure_call)] fn main() { let slice = [1, 2, 3, 4, 5, 6, 7, 8]; @@ -40,4 +40,46 @@ fn main() { } else { slice.chunks_exact(y) }; + + fn foo(slice: &[u8]) { + // Should trigger - passing const parameters directly is allowed + + let _ = slice.chunks_exact(N); + //~^ chunks_exact_to_as_chunks + let _ = slice.chunks_exact({ + //~^ chunks_exact_to_as_chunks + const fn bar() -> usize { + M + } + bar::<5>() + }); + + // Should NOT trigger - expressions with const parameters are not allowed + + let _ = slice.chunks_exact(N * 2); + let _ = slice.chunks_exact(size_of::>()); + let _ = slice.chunks_exact(A::::A); + let _ = slice.chunks_exact((|| N)()); + let _ = slice.chunks_exact({ + const fn bar() -> usize { + M + } + bar::() + }); + } + struct A; + impl A { + const A: usize = N + 1; + } + + trait Trait { + const C: usize; + } + fn bar(slice: &[u8]) { + // Should NOT trigger - expressions in const arguments referencing generic parameters are not + // allowed + + let _ = slice.chunks_exact(T::C); + let _ = slice.chunks_exact(size_of::()); + } } diff --git a/tests/ui/chunks_exact_to_as_chunks.stderr b/tests/ui/chunks_exact_to_as_chunks.stderr index 628752f9bae71..28639c8bea9ba 100644 --- a/tests/ui/chunks_exact_to_as_chunks.stderr +++ b/tests/ui/chunks_exact_to_as_chunks.stderr @@ -50,7 +50,51 @@ help: consider using `as_chunks_mut::<4>()` instead | LL | let mut it = arr.chunks_exact_mut(4); | ^^^^^^^^^^^^^^^^^^^ - = note: you can access the chunks using `it.0.iter()`, and the remainder using `it.1` + = note: you can access the chunks using `it.0.iter_mut()`, and the remainder using `it.1` + +error: using `chunks_exact` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks.rs:47:23 + | +LL | let _ = slice.chunks_exact(N); + | ^^^^^^^^^^^^^^^ + | +help: consider using `as_chunks::()` instead + --> tests/ui/chunks_exact_to_as_chunks.rs:47:23 + | +LL | let _ = slice.chunks_exact(N); + | ^^^^^^^^^^^^^^^ + +error: using `chunks_exact` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks.rs:49:23 + | +LL | let _ = slice.chunks_exact({ + | _______________________^ +LL | | +LL | | const fn bar() -> usize { +LL | | M +LL | | } +LL | | bar::<5>() +LL | | }); + | |__________^ + | +help: consider using `as_chunks::<{ + + const fn bar() -> usize { + M + } + bar::<5>() + }>()` instead + --> tests/ui/chunks_exact_to_as_chunks.rs:49:23 + | +LL | let _ = slice.chunks_exact({ + | _______________________^ +LL | | +LL | | const fn bar() -> usize { +LL | | M +LL | | } +LL | | bar::<5>() +LL | | }); + | |__________^ -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors diff --git a/tests/ui/chunks_exact_to_as_chunks_fixable.fixed b/tests/ui/chunks_exact_to_as_chunks_fixable.fixed new file mode 100644 index 0000000000000..7e84ec50ff449 --- /dev/null +++ b/tests/ui/chunks_exact_to_as_chunks_fixable.fixed @@ -0,0 +1,34 @@ +#![warn(clippy::chunks_exact_to_as_chunks)] +#![allow(unused, clippy::deref_addrof)] + +fn main() { + let mut arr = [1, 2, 3, 4, 5, 6, 7, 8]; + + for _ in arr.as_chunks::<4>().0 {} + //~^ chunks_exact_to_as_chunks + for _ in arr.as_chunks_mut::<4>().0 {} + //~^ chunks_exact_to_as_chunks + for chunk in arr.as_chunks_mut::<4>().0.iter_mut().take(2) { + //~^ chunks_exact_to_as_chunks + chunk[0] += 1; // mutate chunks + } + + // All const expressions should produce valid Rust code + for _ in arr.as_chunks::<{ 1 + 1 }>().0 {} + //~^ chunks_exact_to_as_chunks + const CHUNK_SIZE: usize = 4; + for _ in arr.as_chunks::<{ CHUNK_SIZE + 1 }>().0 {} + //~^ chunks_exact_to_as_chunks + for _ in arr.as_chunks::<{ size_of::() }>().0 {} + //~^ chunks_exact_to_as_chunks + for _ in arr.as_chunks::<{ const { 1 } }>().0 {} + //~^ chunks_exact_to_as_chunks + for _ in arr.as_chunks::<{ unsafe { 1 } }>().0 {} + //~^ chunks_exact_to_as_chunks + struct A; + impl A { + const A: usize = 4; + } + for _ in arr.as_chunks::<{ A::A }>().0 {} + //~^ chunks_exact_to_as_chunks +} diff --git a/tests/ui/chunks_exact_to_as_chunks_fixable.rs b/tests/ui/chunks_exact_to_as_chunks_fixable.rs new file mode 100644 index 0000000000000..3af5d1f6eccf0 --- /dev/null +++ b/tests/ui/chunks_exact_to_as_chunks_fixable.rs @@ -0,0 +1,34 @@ +#![warn(clippy::chunks_exact_to_as_chunks)] +#![allow(unused, clippy::deref_addrof)] + +fn main() { + let mut arr = [1, 2, 3, 4, 5, 6, 7, 8]; + + for _ in arr.chunks_exact(4) {} + //~^ chunks_exact_to_as_chunks + for _ in arr.chunks_exact_mut(4) {} + //~^ chunks_exact_to_as_chunks + for chunk in arr.chunks_exact_mut(4).take(2) { + //~^ chunks_exact_to_as_chunks + chunk[0] += 1; // mutate chunks + } + + // All const expressions should produce valid Rust code + for _ in arr.chunks_exact(1 + 1) {} + //~^ chunks_exact_to_as_chunks + const CHUNK_SIZE: usize = 4; + for _ in arr.chunks_exact(CHUNK_SIZE + 1) {} + //~^ chunks_exact_to_as_chunks + for _ in arr.chunks_exact(size_of::()) {} + //~^ chunks_exact_to_as_chunks + for _ in arr.chunks_exact(const { 1 }) {} + //~^ chunks_exact_to_as_chunks + for _ in arr.chunks_exact(unsafe { 1 }) {} + //~^ chunks_exact_to_as_chunks + struct A; + impl A { + const A: usize = 4; + } + for _ in arr.chunks_exact(A::A) {} + //~^ chunks_exact_to_as_chunks +} diff --git a/tests/ui/chunks_exact_to_as_chunks_fixable.stderr b/tests/ui/chunks_exact_to_as_chunks_fixable.stderr new file mode 100644 index 0000000000000..3bf8de99dc759 --- /dev/null +++ b/tests/ui/chunks_exact_to_as_chunks_fixable.stderr @@ -0,0 +1,59 @@ +error: using `chunks_exact` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks_fixable.rs:7:18 + | +LL | for _ in arr.chunks_exact(4) {} + | ^^^^^^^^^^^^^^^ help: consider using `as_chunks` instead: `as_chunks::<4>().0` + | + = note: `-D clippy::chunks-exact-to-as-chunks` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::chunks_exact_to_as_chunks)]` + +error: using `chunks_exact_mut` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks_fixable.rs:9:18 + | +LL | for _ in arr.chunks_exact_mut(4) {} + | ^^^^^^^^^^^^^^^^^^^ help: consider using `as_chunks_mut` instead: `as_chunks_mut::<4>().0` + +error: using `chunks_exact_mut` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks_fixable.rs:11:22 + | +LL | for chunk in arr.chunks_exact_mut(4).take(2) { + | ^^^^^^^^^^^^^^^^^^^ help: consider using `as_chunks_mut` instead: `as_chunks_mut::<4>().0.iter_mut()` + +error: using `chunks_exact` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks_fixable.rs:17:18 + | +LL | for _ in arr.chunks_exact(1 + 1) {} + | ^^^^^^^^^^^^^^^^^^^ help: consider using `as_chunks` instead: `as_chunks::<{ 1 + 1 }>().0` + +error: using `chunks_exact` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks_fixable.rs:20:18 + | +LL | for _ in arr.chunks_exact(CHUNK_SIZE + 1) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `as_chunks` instead: `as_chunks::<{ CHUNK_SIZE + 1 }>().0` + +error: using `chunks_exact` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks_fixable.rs:22:18 + | +LL | for _ in arr.chunks_exact(size_of::()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `as_chunks` instead: `as_chunks::<{ size_of::() }>().0` + +error: using `chunks_exact` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks_fixable.rs:24:18 + | +LL | for _ in arr.chunks_exact(const { 1 }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `as_chunks` instead: `as_chunks::<{ const { 1 } }>().0` + +error: using `chunks_exact` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks_fixable.rs:26:18 + | +LL | for _ in arr.chunks_exact(unsafe { 1 }) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `as_chunks` instead: `as_chunks::<{ unsafe { 1 } }>().0` + +error: using `chunks_exact` with a constant chunk size + --> tests/ui/chunks_exact_to_as_chunks_fixable.rs:32:18 + | +LL | for _ in arr.chunks_exact(A::A) {} + | ^^^^^^^^^^^^^^^^^^ help: consider using `as_chunks` instead: `as_chunks::<{ A::A }>().0` + +error: aborting due to 9 previous errors + diff --git a/tests/ui/crashes/ice-17352.rs b/tests/ui/crashes/ice-17352.rs new file mode 100644 index 0000000000000..44b23b34b3ffc --- /dev/null +++ b/tests/ui/crashes/ice-17352.rs @@ -0,0 +1,6 @@ +//@ check-pass +#![warn(clippy::unnecessary_unwrap_unchecked)] + +fn issue17352(x: impl Fn() -> Option) { + _ = unsafe { x().unwrap_unchecked() }; +} diff --git a/tests/ui/declare_interior_mutable_const.rs b/tests/ui/declare_interior_mutable_const.rs index 326b6cce3d936..21a418f9ae5bd 100644 --- a/tests/ui/declare_interior_mutable_const.rs +++ b/tests/ui/declare_interior_mutable_const.rs @@ -19,11 +19,11 @@ const fn make_ptr() -> *const Cell { } const PTR: *const Cell = make_ptr(); -const fn casted_to_cell_ptr() -> *const Cell { +const fn cast_to_cell_ptr() -> *const Cell { const VALUE: u32 = 0; &VALUE as *const _ as *const Cell } -const TRANSMUTED_PTR: *const Cell = casted_to_cell_ptr(); +const TRANSMUTED_PTR: *const Cell = cast_to_cell_ptr(); const CELL_TUPLE: (bool, Cell) = (true, Cell::new(0)); //~ declare_interior_mutable_const const CELL_ARRAY: [Cell; 2] = [Cell::new(0), Cell::new(0)]; //~ declare_interior_mutable_const diff --git a/tests/ui/doc/doc_comment_double_space_linebreaks.fixed b/tests/ui/doc/doc_comment_double_space_linebreaks.fixed index c7d7433d2f8de..afe76c963afb5 100644 --- a/tests/ui/doc/doc_comment_double_space_linebreaks.fixed +++ b/tests/ui/doc/doc_comment_double_space_linebreaks.fixed @@ -5,7 +5,7 @@ #![expect(clippy::empty_docs)] //~v doc_comment_double_space_linebreaks -//! Should warn on double space linebreaks\ +//! Should warn on double space line breaks\ //! in file/module doc comment /// Should not warn on single-line doc comments @@ -35,12 +35,12 @@ fn normal_comment() { //~v doc_comment_double_space_linebreaks /// Should warn when doc comment uses double space\ -/// as a line-break, even when there are multiple\ +/// as a line break, even when there are multiple\ /// in a row fn double_space_doc_comment() {} -/// Should not warn when back-slash is used \ -/// as a line-break +/// Should not warn when backslash is used \ +/// as a line break fn back_slash_doc_comment() {} //~v doc_comment_double_space_linebreaks diff --git a/tests/ui/doc/doc_comment_double_space_linebreaks.rs b/tests/ui/doc/doc_comment_double_space_linebreaks.rs index d1159a07c81e0..5ad06c7ba67ee 100644 --- a/tests/ui/doc/doc_comment_double_space_linebreaks.rs +++ b/tests/ui/doc/doc_comment_double_space_linebreaks.rs @@ -5,7 +5,7 @@ #![expect(clippy::empty_docs)] //~v doc_comment_double_space_linebreaks -//! Should warn on double space linebreaks +//! Should warn on double space line breaks //! in file/module doc comment /// Should not warn on single-line doc comments @@ -35,12 +35,12 @@ fn normal_comment() { //~v doc_comment_double_space_linebreaks /// Should warn when doc comment uses double space -/// as a line-break, even when there are multiple +/// as a line break, even when there are multiple /// in a row fn double_space_doc_comment() {} -/// Should not warn when back-slash is used \ -/// as a line-break +/// Should not warn when backslash is used \ +/// as a line break fn back_slash_doc_comment() {} //~v doc_comment_double_space_linebreaks diff --git a/tests/ui/doc/doc_comment_double_space_linebreaks.stderr b/tests/ui/doc/doc_comment_double_space_linebreaks.stderr index 08c6956c3d003..65c36081b7829 100644 --- a/tests/ui/doc/doc_comment_double_space_linebreaks.stderr +++ b/tests/ui/doc/doc_comment_double_space_linebreaks.stderr @@ -1,8 +1,8 @@ error: doc comment uses two spaces for a hard line break - --> tests/ui/doc/doc_comment_double_space_linebreaks.rs:8:43 + --> tests/ui/doc/doc_comment_double_space_linebreaks.rs:8:44 | -LL | //! Should warn on double space linebreaks - | ^^ +LL | //! Should warn on double space line breaks + | ^^ | = help: replace this double space with a backslash: `\` = note: `-D clippy::doc-comment-double-space-linebreaks` implied by `-D warnings` @@ -13,7 +13,7 @@ error: doc comment uses two spaces for a hard line break | LL | /// Should warn when doc comment uses double space | ^^ -LL | /// as a line-break, even when there are multiple +LL | /// as a line break, even when there are multiple | ^^ | = help: replace this double space with a backslash: `\` diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index 0ac97c586dc52..20405a1233c46 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -658,3 +658,32 @@ fn issue16641() { (0..10).flat_map(|x| (0..10).map(&*closure)).count(); //~^ redundant_closure } + +mod issue_13094 { + fn issue_13094( + mat_a: &[Vec], + mat_b: &[Vec], + add: impl Fn(T, T) -> T, + mul: impl Fn(T, T) -> T, + ) -> Vec> + where + T: Clone, + { + // C(i,j) = Σ(0,k-1) A(i,k) * B(k,j) + let m = mat_a.len(); + let n = mat_b.len(); + (0..m) + .map(|i| { + (0..n) + .map(|j| { + (0..m) + .map(|k| mul(mat_a[i][k].clone(), mat_b[k][j].clone())) + .reduce(&add) + //~^ redundant_closure + .expect("Matrix must be qualified!") + }) + .collect() + }) + .collect() + } +} diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index c21fd13a7462c..4268810635fb4 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -658,3 +658,32 @@ fn issue16641() { (0..10).flat_map(|x| (0..10).map(|y| closure(y))).count(); //~^ redundant_closure } + +mod issue_13094 { + fn issue_13094( + mat_a: &[Vec], + mat_b: &[Vec], + add: impl Fn(T, T) -> T, + mul: impl Fn(T, T) -> T, + ) -> Vec> + where + T: Clone, + { + // C(i,j) = Σ(0,k-1) A(i,k) * B(k,j) + let m = mat_a.len(); + let n = mat_b.len(); + (0..m) + .map(|i| { + (0..n) + .map(|j| { + (0..m) + .map(|k| mul(mat_a[i][k].clone(), mat_b[k][j].clone())) + .reduce(|a, b| add(a, b)) + //~^ redundant_closure + .expect("Matrix must be qualified!") + }) + .collect() + }) + .collect() + } +} diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index 6707cc4908d79..91c864d0ae581 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -268,5 +268,11 @@ error: redundant closure LL | (0..10).flat_map(|x| (0..10).map(|y| closure(y))).count(); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&*closure` -error: aborting due to 44 previous errors +error: redundant closure + --> tests/ui/eta.rs:681:37 + | +LL | ... .reduce(|a, b| add(a, b)) + | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&add` + +error: aborting due to 45 previous errors diff --git a/tests/ui/filter_map_next_fixable.fixed b/tests/ui/filter_map_next.fixed similarity index 53% rename from tests/ui/filter_map_next_fixable.fixed rename to tests/ui/filter_map_next.fixed index 09c416041a4e9..cf2191515bea1 100644 --- a/tests/ui/filter_map_next_fixable.fixed +++ b/tests/ui/filter_map_next.fixed @@ -6,6 +6,27 @@ fn main() { let element: Option = a.iter().find_map(|s| s.parse().ok()); //~^ filter_map_next assert_eq!(element, Some(1)); + + #[rustfmt::skip] + let _: Option = vec![1, 2, 3, 4, 5, 6] + //~^ filter_map_next + + + .into_iter().find_map(|x| { + if x == 2 { + Some(x * 2) + } else { + None + } + }); + + let element: Option = a + // very important comment -- don't delete! + .iter().find_map(|s| { + // another extremely important comment + s.parse().ok() + }); + //~^^^^^^^^ filter_map_next } #[clippy::msrv = "1.29"] diff --git a/tests/ui/filter_map_next.rs b/tests/ui/filter_map_next.rs index 5414e01c87006..684413bc03c51 100644 --- a/tests/ui/filter_map_next.rs +++ b/tests/ui/filter_map_next.rs @@ -3,6 +3,10 @@ fn main() { let a = ["1", "lol", "3", "NaN", "5"]; + let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); + //~^ filter_map_next + assert_eq!(element, Some(1)); + #[rustfmt::skip] let _: Option = vec![1, 2, 3, 4, 5, 6] //~^ filter_map_next @@ -17,4 +21,27 @@ fn main() { } }) .next(); + + let element: Option = a + // very important comment -- don't delete! + .iter() + .filter_map(|s| { + // another extremely important comment + s.parse().ok() + }) + .next(); + //~^^^^^^^^ filter_map_next +} + +#[clippy::msrv = "1.29"] +fn msrv_1_29() { + let a = ["1", "lol", "3", "NaN", "5"]; + let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); +} + +#[clippy::msrv = "1.30"] +fn msrv_1_30() { + let a = ["1", "lol", "3", "NaN", "5"]; + let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); + //~^ filter_map_next } diff --git a/tests/ui/filter_map_next.stderr b/tests/ui/filter_map_next.stderr index 974bb946d46af..609b20679cf21 100644 --- a/tests/ui/filter_map_next.stderr +++ b/tests/ui/filter_map_next.stderr @@ -1,5 +1,19 @@ -error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead - --> tests/ui/filter_map_next.rs:7:26 +error: called `filter_map(..).next()` on an `Iterator` + --> tests/ui/filter_map_next.rs:6:32 + | +LL | let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::filter-map-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_map_next)]` +help: use `.find_map(..)` instead + | +LL - let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); +LL + let element: Option = a.iter().find_map(|s| s.parse().ok()); + | + +error: called `filter_map(..).next()` on an `Iterator` + --> tests/ui/filter_map_next.rs:11:26 | LL | let _: Option = vec![1, 2, 3, 4, 5, 6] | __________________________^ @@ -8,8 +22,55 @@ LL | | }) LL | | .next(); | |_______________^ | - = note: `-D clippy::filter-map-next` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::filter_map_next)]` +help: use `.find_map(..)` instead + | +LL ~ let _: Option = vec![1, 2, 3, 4, 5, 6] +LL + +LL + +LL + +LL + .into_iter().find_map(|x| { +LL + if x == 2 { +LL + Some(x * 2) +LL + } else { +LL + None +LL + } +LL ~ }); + | + +error: called `filter_map(..).next()` on an `Iterator` + --> tests/ui/filter_map_next.rs:25:32 + | +LL | let element: Option = a + | ________________________________^ +LL | | // very important comment -- don't delete! +LL | | .iter() +LL | | .filter_map(|s| { +... | +LL | | }) +LL | | .next(); + | |_______________^ + | +help: use `.find_map(..)` instead + | +LL ~ let element: Option = a +LL + // very important comment -- don't delete! +LL + .iter().find_map(|s| { +LL + // another extremely important comment +LL + s.parse().ok() +LL ~ }); + | + +error: called `filter_map(..).next()` on an `Iterator` + --> tests/ui/filter_map_next.rs:45:26 + | +LL | let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: use `.find_map(..)` instead + | +LL - let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); +LL + let _: Option = a.iter().find_map(|s| s.parse().ok()); + | -error: aborting due to 1 previous error +error: aborting due to 4 previous errors diff --git a/tests/ui/filter_map_next_fixable.rs b/tests/ui/filter_map_next_fixable.rs deleted file mode 100644 index 3d686ef41d917..0000000000000 --- a/tests/ui/filter_map_next_fixable.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![warn(clippy::filter_map_next)] - -fn main() { - let a = ["1", "lol", "3", "NaN", "5"]; - - let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); - //~^ filter_map_next - assert_eq!(element, Some(1)); -} - -#[clippy::msrv = "1.29"] -fn msrv_1_29() { - let a = ["1", "lol", "3", "NaN", "5"]; - let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); -} - -#[clippy::msrv = "1.30"] -fn msrv_1_30() { - let a = ["1", "lol", "3", "NaN", "5"]; - let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); - //~^ filter_map_next -} diff --git a/tests/ui/filter_map_next_fixable.stderr b/tests/ui/filter_map_next_fixable.stderr deleted file mode 100644 index 1002837732b86..0000000000000 --- a/tests/ui/filter_map_next_fixable.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead - --> tests/ui/filter_map_next_fixable.rs:6:32 - | -LL | let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.iter().find_map(|s| s.parse().ok())` - | - = note: `-D clippy::filter-map-next` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::filter_map_next)]` - -error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead - --> tests/ui/filter_map_next_fixable.rs:20:26 - | -LL | let _: Option = a.iter().filter_map(|s| s.parse().ok()).next(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.iter().find_map(|s| s.parse().ok())` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/ineffective_bit_masks.rs b/tests/ui/ineffective_bit_masks.rs new file mode 100644 index 0000000000000..79a6afad7b66c --- /dev/null +++ b/tests/ui/ineffective_bit_masks.rs @@ -0,0 +1,194 @@ +//@aux-build:proc_macros.rs + +#![warn(clippy::bad_bit_mask)] +#![expect( + unused_comparisons, + clippy::absurd_extreme_comparisons, + clippy::bad_bit_mask, + clippy::identity_op +)] + +use core::hint::black_box; +use proc_macros::{external, with_span}; + +fn main() { + let x = black_box(5u32); + + let _ = x | 0b00_0000 > 0b00_0000; //~ ineffective_bit_mask + let _ = x | 0b00_0001 > 0b00_0000; + let _ = x | 0b00_0001 > 0b00_0001; //~ ineffective_bit_mask + let _ = x | 0b00_0010 > 0b00_0001; + let _ = x | 0b00_0011 > 0b00_0001; + let _ = x | 0b00_0000 > 0b00_0011; //~ ineffective_bit_mask + let _ = x | 0b00_0001 > 0b00_0011; //~ ineffective_bit_mask + let _ = x | 0b00_0010 > 0b00_0011; //~ ineffective_bit_mask + let _ = x | 0b00_0011 > 0b00_0011; //~ ineffective_bit_mask + let _ = x | 0b00_0100 > 0b00_0011; + let _ = x | 0b00_0101 > 0b00_0011; + let _ = x | 0b00_0001 > 0b00_0111; //~ ineffective_bit_mask + let _ = x | 0b00_0010 > 0b00_0111; //~ ineffective_bit_mask + let _ = x | 0b00_0011 > 0b00_0111; //~ ineffective_bit_mask + let _ = x | 0b00_0100 > 0b00_0111; //~ ineffective_bit_mask + let _ = x | 0b00_1000 > 0b00_0111; + let _ = x | 0b00_1010 > 0b00_0111; + let _ = x | 0b00_0001 > 0b00_1111; //~ ineffective_bit_mask + let _ = x | 0b00_0010 > 0b00_1111; //~ ineffective_bit_mask + let _ = x | 0b00_0011 > 0b00_1111; //~ ineffective_bit_mask + let _ = x | 0b00_0100 > 0b00_1111; //~ ineffective_bit_mask + let _ = x | 0b00_0101 > 0b00_1111; //~ ineffective_bit_mask + let _ = x | 0b00_0110 > 0b00_1111; //~ ineffective_bit_mask + let _ = x | 0b00_0111 > 0b00_1111; //~ ineffective_bit_mask + let _ = x | 0b00_1000 > 0b00_1111; //~ ineffective_bit_mask + let _ = x | 0b00_1001 > 0b00_1111; //~ ineffective_bit_mask + let _ = x | 0b00_1111 > 0b10_1111; //~ ineffective_bit_mask + let _ = x | 0b01_0000 > 0b10_1111; + let _ = x | 0b01_1111 > 0b10_1111; + let _ = x | 0b10_0000 > 0b10_1111; + let _ = x | 0b11_1111 > 0b10_1111; + let _ = x | 0b00_1111 <= 0b10_1111; //~ ineffective_bit_mask + let _ = x | 0b11_0000 <= 0b10_1111; + + let _ = x ^ 0b00_0000 > 0b00_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0001 > 0b00_0000; + let _ = x ^ 0b00_0001 > 0b00_0001; //~ ineffective_bit_mask + let _ = x ^ 0b00_0010 > 0b00_0001; + let _ = x ^ 0b00_0011 > 0b00_0001; + let _ = x ^ 0b00_0000 > 0b00_0011; //~ ineffective_bit_mask + let _ = x ^ 0b00_0001 > 0b00_0011; //~ ineffective_bit_mask + let _ = x ^ 0b00_0010 > 0b00_0011; //~ ineffective_bit_mask + let _ = x ^ 0b00_0011 > 0b00_0011; //~ ineffective_bit_mask + let _ = x ^ 0b00_0100 > 0b00_0011; + let _ = x ^ 0b00_0101 > 0b00_0011; + let _ = x ^ 0b00_0001 > 0b00_0111; //~ ineffective_bit_mask + let _ = x ^ 0b00_0010 > 0b00_0111; //~ ineffective_bit_mask + let _ = x ^ 0b00_0011 > 0b00_0111; //~ ineffective_bit_mask + let _ = x ^ 0b00_0100 > 0b00_0111; //~ ineffective_bit_mask + let _ = x ^ 0b00_1000 > 0b00_0111; + let _ = x ^ 0b00_1010 > 0b00_0111; + let _ = x ^ 0b00_0001 > 0b00_1111; //~ ineffective_bit_mask + let _ = x ^ 0b00_0010 > 0b00_1111; //~ ineffective_bit_mask + let _ = x ^ 0b00_0011 > 0b00_1111; //~ ineffective_bit_mask + let _ = x ^ 0b00_0100 > 0b00_1111; //~ ineffective_bit_mask + let _ = x ^ 0b00_0101 > 0b00_1111; //~ ineffective_bit_mask + let _ = x ^ 0b00_0110 > 0b00_1111; //~ ineffective_bit_mask + let _ = x ^ 0b00_0111 > 0b00_1111; //~ ineffective_bit_mask + let _ = x ^ 0b00_1000 > 0b00_1111; //~ ineffective_bit_mask + let _ = x ^ 0b00_1001 > 0b00_1111; //~ ineffective_bit_mask + let _ = x ^ 0b00_1111 > 0b10_1111; //~ ineffective_bit_mask + let _ = x ^ 0b01_0000 > 0b10_1111; + let _ = x ^ 0b01_1111 > 0b10_1111; + let _ = x ^ 0b10_0000 > 0b10_1111; + let _ = x ^ 0b11_1111 > 0b10_1111; + let _ = x ^ 0b00_1111 <= 0b10_1111; //~ ineffective_bit_mask + let _ = x ^ 0b11_0000 <= 0b10_1111; + + let _ = x | 0b00_0000 < 0b00_0000; + let _ = x | 0b00_0001 < 0b00_0000; + let _ = x | 0b00_0001 < 0b00_0001; + let _ = x | 0b00_0010 < 0b00_0001; + let _ = x | 0b00_0011 < 0b00_0001; + let _ = x | 0b00_0000 < 0b00_0010; //~ ineffective_bit_mask + let _ = x | 0b00_0001 < 0b00_0010; //~ ineffective_bit_mask + let _ = x | 0b00_0010 < 0b00_0010; + let _ = x | 0b00_0011 < 0b00_0010; + let _ = x | 0b00_0000 < 0b00_0100; //~ ineffective_bit_mask + let _ = x | 0b00_0001 < 0b00_0100; //~ ineffective_bit_mask + let _ = x | 0b00_0010 < 0b00_0100; //~ ineffective_bit_mask + let _ = x | 0b00_0011 < 0b00_0100; //~ ineffective_bit_mask + let _ = x | 0b00_0100 < 0b00_0100; + let _ = x | 0b00_0101 < 0b00_0100; + let _ = x | 0b00_0001 < 0b00_1000; //~ ineffective_bit_mask + let _ = x | 0b00_0010 < 0b00_1000; //~ ineffective_bit_mask + let _ = x | 0b00_0011 < 0b00_1000; //~ ineffective_bit_mask + let _ = x | 0b00_0100 < 0b00_1000; //~ ineffective_bit_mask + let _ = x | 0b00_1000 < 0b00_1000; + let _ = x | 0b00_1010 < 0b00_1000; + let _ = x | 0b00_0001 < 0b01_0000; //~ ineffective_bit_mask + let _ = x | 0b00_0010 < 0b01_0000; //~ ineffective_bit_mask + let _ = x | 0b00_0011 < 0b01_0000; //~ ineffective_bit_mask + let _ = x | 0b00_0100 < 0b01_0000; //~ ineffective_bit_mask + let _ = x | 0b00_0101 < 0b01_0000; //~ ineffective_bit_mask + let _ = x | 0b00_0110 < 0b01_0000; //~ ineffective_bit_mask + let _ = x | 0b00_0111 < 0b01_0000; //~ ineffective_bit_mask + let _ = x | 0b00_1000 < 0b01_0000; //~ ineffective_bit_mask + let _ = x | 0b00_1001 < 0b01_0000; //~ ineffective_bit_mask + let _ = x | 0b00_1111 < 0b11_0000; //~ ineffective_bit_mask + let _ = x | 0b01_0000 < 0b11_0000; + let _ = x | 0b01_1111 < 0b11_0000; + let _ = x | 0b10_0000 < 0b11_0000; + let _ = x | 0b11_1111 < 0b11_0000; + let _ = x | 0b00_1111 >= 0b11_0000; //~ ineffective_bit_mask + let _ = x | 0b11_0000 >= 0b11_0000; + + let _ = x ^ 0b00_0000 < 0b00_0000; + let _ = x ^ 0b00_0001 < 0b00_0000; + let _ = x ^ 0b00_0001 < 0b00_0001; + let _ = x ^ 0b00_0010 < 0b00_0001; + let _ = x ^ 0b00_0011 < 0b00_0001; + let _ = x ^ 0b00_0000 < 0b00_0010; //~ ineffective_bit_mask + let _ = x ^ 0b00_0001 < 0b00_0010; //~ ineffective_bit_mask + let _ = x ^ 0b00_0010 < 0b00_0010; + let _ = x ^ 0b00_0011 < 0b00_0010; + let _ = x ^ 0b00_0000 < 0b00_0100; //~ ineffective_bit_mask + let _ = x ^ 0b00_0001 < 0b00_0100; //~ ineffective_bit_mask + let _ = x ^ 0b00_0010 < 0b00_0100; //~ ineffective_bit_mask + let _ = x ^ 0b00_0011 < 0b00_0100; //~ ineffective_bit_mask + let _ = x ^ 0b00_0100 < 0b00_0100; + let _ = x ^ 0b00_0101 < 0b00_0100; + let _ = x ^ 0b00_0001 < 0b00_1000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0010 < 0b00_1000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0011 < 0b00_1000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0100 < 0b00_1000; //~ ineffective_bit_mask + let _ = x ^ 0b00_1000 < 0b00_1000; + let _ = x ^ 0b00_1010 < 0b00_1000; + let _ = x ^ 0b00_0001 < 0b01_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0010 < 0b01_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0011 < 0b01_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0100 < 0b01_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0101 < 0b01_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0110 < 0b01_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_0111 < 0b01_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_1000 < 0b01_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_1001 < 0b01_0000; //~ ineffective_bit_mask + let _ = x ^ 0b00_1111 < 0b11_0000; //~ ineffective_bit_mask + let _ = x ^ 0b01_0000 < 0b11_0000; + let _ = x ^ 0b01_1111 < 0b11_0000; + let _ = x ^ 0b10_0000 < 0b11_0000; + let _ = x ^ 0b11_1111 < 0b11_0000; + let _ = x ^ 0b00_1111 >= 0b11_0000; //~ ineffective_bit_mask + let _ = x ^ 0b11_0000 >= 0b11_0000; + + let _ = x | 0x7fff_ffff > 0xffff_ffff; //~ ineffective_bit_mask + let _ = x | 0x8000_0000 > 0xffff_ffff; //~ ineffective_bit_mask + let _ = x | 0xffff_ffff > 0xffff_ffff; //~ ineffective_bit_mask + let _ = x ^ 0x7fff_ffff > 0xffff_ffff; //~ ineffective_bit_mask + let _ = x ^ 0x8000_0000 > 0xffff_ffff; //~ ineffective_bit_mask + let _ = x ^ 0xffff_ffff > 0xffff_ffff; //~ ineffective_bit_mask + + let _ = x | 0x7fff_ffff < 0x8000_0000; //~ ineffective_bit_mask + let _ = x | 0x8000_0000 < 0x8000_0000; + let _ = x ^ 0x7fff_ffff < 0x8000_0000; //~ ineffective_bit_mask + let _ = x ^ 0x8000_0000 < 0x8000_0000; + + let _ = x | 0b00_0001 > 0b00_0100; + let _ = x | 0b00_0010 > 0b00_0100; + let _ = x | 0b00_0011 > 0b00_0100; + let _ = x | 0b00_0100 > 0b00_0100; + let _ = x | 0b00_0101 > 0b00_0100; + + let _ = x | 0b00_0001 < 0b00_1011; + let _ = x | 0b00_0010 < 0b00_1011; + let _ = x | 0b00_0011 < 0b00_1011; + let _ = x | 0b00_0100 < 0b00_1011; + let _ = x | 0b00_0101 < 0b00_1011; + + external! { + let x = black_box(5u32); + let _ = x | 0b0001 > 0b00_0011; + } + with_span! { + sp + let x = black_box(5u32); + let _ = x | 0b0001 > 0b00_0011; + } +} diff --git a/tests/ui/ineffective_bit_masks.stderr b/tests/ui/ineffective_bit_masks.stderr new file mode 100644 index 0000000000000..39797793dae12 --- /dev/null +++ b/tests/ui/ineffective_bit_masks.stderr @@ -0,0 +1,739 @@ +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:17:13 + | +LL | let _ = x | 0b00_0000 > 0b00_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x0` contains only bits in the trailing ones of the compared constant `0x0` + = note: `#[deny(clippy::ineffective_bit_mask)]` on by default + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:19:13 + | +LL | let _ = x | 0b00_0001 > 0b00_0001; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing ones of the compared constant `0x1` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:22:13 + | +LL | let _ = x | 0b00_0000 > 0b00_0011; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x0` contains only bits in the trailing ones of the compared constant `0x3` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:23:13 + | +LL | let _ = x | 0b00_0001 > 0b00_0011; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing ones of the compared constant `0x3` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:24:13 + | +LL | let _ = x | 0b00_0010 > 0b00_0011; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing ones of the compared constant `0x3` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:25:13 + | +LL | let _ = x | 0b00_0011 > 0b00_0011; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing ones of the compared constant `0x3` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:28:13 + | +LL | let _ = x | 0b00_0001 > 0b00_0111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing ones of the compared constant `0x7` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:29:13 + | +LL | let _ = x | 0b00_0010 > 0b00_0111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing ones of the compared constant `0x7` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:30:13 + | +LL | let _ = x | 0b00_0011 > 0b00_0111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing ones of the compared constant `0x7` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:31:13 + | +LL | let _ = x | 0b00_0100 > 0b00_0111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x4` contains only bits in the trailing ones of the compared constant `0x7` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:34:13 + | +LL | let _ = x | 0b00_0001 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:35:13 + | +LL | let _ = x | 0b00_0010 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:36:13 + | +LL | let _ = x | 0b00_0011 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:37:13 + | +LL | let _ = x | 0b00_0100 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x4` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:38:13 + | +LL | let _ = x | 0b00_0101 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x5` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:39:13 + | +LL | let _ = x | 0b00_0110 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x6` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:40:13 + | +LL | let _ = x | 0b00_0111 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x7` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:41:13 + | +LL | let _ = x | 0b00_1000 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x8` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:42:13 + | +LL | let _ = x | 0b00_1001 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x9` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:43:13 + | +LL | let _ = x | 0b00_1111 > 0b10_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` contains only bits in the trailing ones of the compared constant `0x2f` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:48:13 + | +LL | let _ = x | 0b00_1111 <= 0b10_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` contains only bits in the trailing ones of the compared constant `0x2f` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:51:13 + | +LL | let _ = x ^ 0b00_0000 > 0b00_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x0` contains only bits in the trailing ones of the compared constant `0x0` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:53:13 + | +LL | let _ = x ^ 0b00_0001 > 0b00_0001; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing ones of the compared constant `0x1` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:56:13 + | +LL | let _ = x ^ 0b00_0000 > 0b00_0011; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x0` contains only bits in the trailing ones of the compared constant `0x3` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:57:13 + | +LL | let _ = x ^ 0b00_0001 > 0b00_0011; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing ones of the compared constant `0x3` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:58:13 + | +LL | let _ = x ^ 0b00_0010 > 0b00_0011; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing ones of the compared constant `0x3` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:59:13 + | +LL | let _ = x ^ 0b00_0011 > 0b00_0011; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing ones of the compared constant `0x3` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:62:13 + | +LL | let _ = x ^ 0b00_0001 > 0b00_0111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing ones of the compared constant `0x7` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:63:13 + | +LL | let _ = x ^ 0b00_0010 > 0b00_0111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing ones of the compared constant `0x7` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:64:13 + | +LL | let _ = x ^ 0b00_0011 > 0b00_0111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing ones of the compared constant `0x7` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:65:13 + | +LL | let _ = x ^ 0b00_0100 > 0b00_0111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x4` contains only bits in the trailing ones of the compared constant `0x7` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:68:13 + | +LL | let _ = x ^ 0b00_0001 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:69:13 + | +LL | let _ = x ^ 0b00_0010 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:70:13 + | +LL | let _ = x ^ 0b00_0011 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:71:13 + | +LL | let _ = x ^ 0b00_0100 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x4` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:72:13 + | +LL | let _ = x ^ 0b00_0101 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x5` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:73:13 + | +LL | let _ = x ^ 0b00_0110 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x6` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:74:13 + | +LL | let _ = x ^ 0b00_0111 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x7` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:75:13 + | +LL | let _ = x ^ 0b00_1000 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x8` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:76:13 + | +LL | let _ = x ^ 0b00_1001 > 0b00_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x9` contains only bits in the trailing ones of the compared constant `0xf` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:77:13 + | +LL | let _ = x ^ 0b00_1111 > 0b10_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` contains only bits in the trailing ones of the compared constant `0x2f` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:82:13 + | +LL | let _ = x ^ 0b00_1111 <= 0b10_1111; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` contains only bits in the trailing ones of the compared constant `0x2f` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:90:13 + | +LL | let _ = x | 0b00_0000 < 0b00_0010; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x0` contains only bits in the trailing zeros of the compared constant `0x2` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:91:13 + | +LL | let _ = x | 0b00_0001 < 0b00_0010; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing zeros of the compared constant `0x2` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:94:13 + | +LL | let _ = x | 0b00_0000 < 0b00_0100; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x0` contains only bits in the trailing zeros of the compared constant `0x4` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:95:13 + | +LL | let _ = x | 0b00_0001 < 0b00_0100; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing zeros of the compared constant `0x4` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:96:13 + | +LL | let _ = x | 0b00_0010 < 0b00_0100; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing zeros of the compared constant `0x4` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:97:13 + | +LL | let _ = x | 0b00_0011 < 0b00_0100; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing zeros of the compared constant `0x4` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:100:13 + | +LL | let _ = x | 0b00_0001 < 0b00_1000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing zeros of the compared constant `0x8` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:101:13 + | +LL | let _ = x | 0b00_0010 < 0b00_1000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing zeros of the compared constant `0x8` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:102:13 + | +LL | let _ = x | 0b00_0011 < 0b00_1000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing zeros of the compared constant `0x8` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:103:13 + | +LL | let _ = x | 0b00_0100 < 0b00_1000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x4` contains only bits in the trailing zeros of the compared constant `0x8` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:106:13 + | +LL | let _ = x | 0b00_0001 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:107:13 + | +LL | let _ = x | 0b00_0010 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:108:13 + | +LL | let _ = x | 0b00_0011 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:109:13 + | +LL | let _ = x | 0b00_0100 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x4` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:110:13 + | +LL | let _ = x | 0b00_0101 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x5` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:111:13 + | +LL | let _ = x | 0b00_0110 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x6` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:112:13 + | +LL | let _ = x | 0b00_0111 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x7` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:113:13 + | +LL | let _ = x | 0b00_1000 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x8` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:114:13 + | +LL | let _ = x | 0b00_1001 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x9` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:115:13 + | +LL | let _ = x | 0b00_1111 < 0b11_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` contains only bits in the trailing zeros of the compared constant `0x30` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:120:13 + | +LL | let _ = x | 0b00_1111 >= 0b11_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` contains only bits in the trailing zeros of the compared constant `0x30` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:128:13 + | +LL | let _ = x ^ 0b00_0000 < 0b00_0010; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x0` contains only bits in the trailing zeros of the compared constant `0x2` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:129:13 + | +LL | let _ = x ^ 0b00_0001 < 0b00_0010; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing zeros of the compared constant `0x2` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:132:13 + | +LL | let _ = x ^ 0b00_0000 < 0b00_0100; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x0` contains only bits in the trailing zeros of the compared constant `0x4` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:133:13 + | +LL | let _ = x ^ 0b00_0001 < 0b00_0100; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing zeros of the compared constant `0x4` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:134:13 + | +LL | let _ = x ^ 0b00_0010 < 0b00_0100; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing zeros of the compared constant `0x4` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:135:13 + | +LL | let _ = x ^ 0b00_0011 < 0b00_0100; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing zeros of the compared constant `0x4` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:138:13 + | +LL | let _ = x ^ 0b00_0001 < 0b00_1000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing zeros of the compared constant `0x8` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:139:13 + | +LL | let _ = x ^ 0b00_0010 < 0b00_1000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing zeros of the compared constant `0x8` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:140:13 + | +LL | let _ = x ^ 0b00_0011 < 0b00_1000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing zeros of the compared constant `0x8` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:141:13 + | +LL | let _ = x ^ 0b00_0100 < 0b00_1000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x4` contains only bits in the trailing zeros of the compared constant `0x8` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:144:13 + | +LL | let _ = x ^ 0b00_0001 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x1` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:145:13 + | +LL | let _ = x ^ 0b00_0010 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x2` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:146:13 + | +LL | let _ = x ^ 0b00_0011 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x3` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:147:13 + | +LL | let _ = x ^ 0b00_0100 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x4` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:148:13 + | +LL | let _ = x ^ 0b00_0101 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x5` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:149:13 + | +LL | let _ = x ^ 0b00_0110 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x6` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:150:13 + | +LL | let _ = x ^ 0b00_0111 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x7` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:151:13 + | +LL | let _ = x ^ 0b00_1000 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x8` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:152:13 + | +LL | let _ = x ^ 0b00_1001 < 0b01_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x9` contains only bits in the trailing zeros of the compared constant `0x10` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:153:13 + | +LL | let _ = x ^ 0b00_1111 < 0b11_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` contains only bits in the trailing zeros of the compared constant `0x30` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:158:13 + | +LL | let _ = x ^ 0b00_1111 >= 0b11_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xf` contains only bits in the trailing zeros of the compared constant `0x30` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:161:13 + | +LL | let _ = x | 0x7fff_ffff > 0xffff_ffff; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x7fffffff` contains only bits in the trailing ones of the compared constant `0xffffffff` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:162:13 + | +LL | let _ = x | 0x8000_0000 > 0xffff_ffff; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x80000000` contains only bits in the trailing ones of the compared constant `0xffffffff` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:163:13 + | +LL | let _ = x | 0xffff_ffff > 0xffff_ffff; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xffffffff` contains only bits in the trailing ones of the compared constant `0xffffffff` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:164:13 + | +LL | let _ = x ^ 0x7fff_ffff > 0xffff_ffff; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x7fffffff` contains only bits in the trailing ones of the compared constant `0xffffffff` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:165:13 + | +LL | let _ = x ^ 0x8000_0000 > 0xffff_ffff; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x80000000` contains only bits in the trailing ones of the compared constant `0xffffffff` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:166:13 + | +LL | let _ = x ^ 0xffff_ffff > 0xffff_ffff; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0xffffffff` contains only bits in the trailing ones of the compared constant `0xffffffff` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:168:13 + | +LL | let _ = x | 0x7fff_ffff < 0x8000_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x7fffffff` contains only bits in the trailing zeros of the compared constant `0x80000000` + +error: this comparison's result is unaffected by the bitwise operation + --> tests/ui/ineffective_bit_masks.rs:170:13 + | +LL | let _ = x ^ 0x7fff_ffff < 0x8000_0000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `0x7fffffff` contains only bits in the trailing zeros of the compared constant `0x80000000` + +error: aborting due to 92 previous errors + diff --git a/tests/ui/infinite_loops.rs b/tests/ui/infinite_loops.rs index 858c824d23838..88908fa7e9173 100644 --- a/tests/ui/infinite_loops.rs +++ b/tests/ui/infinite_loops.rs @@ -1,6 +1,7 @@ //@no-rustfix: multiple suggestions add `-> !` to the same fn //@aux-build:proc_macros.rs +#![feature(gen_blocks)] #![expect(clippy::never_loop, clippy::while_let_loop)] #![warn(clippy::infinite_loop)] @@ -589,4 +590,10 @@ mod issue16155 { } } +gen fn repeat_zeroes() -> u32 { + loop { + yield 0; + } +} + fn main() {} diff --git a/tests/ui/infinite_loops.stderr b/tests/ui/infinite_loops.stderr index 9c2b4667b979b..6005ca896109e 100644 --- a/tests/ui/infinite_loops.stderr +++ b/tests/ui/infinite_loops.stderr @@ -1,5 +1,5 @@ error: infinite loop detected - --> tests/ui/infinite_loops.rs:13:5 + --> tests/ui/infinite_loops.rs:14:5 | LL | / loop { LL | | @@ -16,7 +16,7 @@ LL | fn no_break() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:20:5 + --> tests/ui/infinite_loops.rs:21:5 | LL | / loop { LL | | @@ -33,7 +33,7 @@ LL | fn all_inf() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:22:9 + --> tests/ui/infinite_loops.rs:23:9 | LL | / loop { LL | | @@ -49,7 +49,7 @@ LL | fn all_inf() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:24:13 + --> tests/ui/infinite_loops.rs:25:13 | LL | / loop { LL | | @@ -64,7 +64,7 @@ LL | fn all_inf() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:38:5 + --> tests/ui/infinite_loops.rs:39:5 | LL | / loop { LL | | @@ -75,7 +75,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:51:5 + --> tests/ui/infinite_loops.rs:52:5 | LL | / loop { LL | | @@ -93,7 +93,7 @@ LL | fn no_break_never_ret_noise() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:95:5 + --> tests/ui/infinite_loops.rs:96:5 | LL | / loop { LL | | @@ -110,7 +110,7 @@ LL | fn break_inner_but_not_outer_1(cond: bool) -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:106:5 + --> tests/ui/infinite_loops.rs:107:5 | LL | / loop { LL | | @@ -127,7 +127,7 @@ LL | fn break_inner_but_not_outer_2(cond: bool) -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:120:9 + --> tests/ui/infinite_loops.rs:121:9 | LL | / loop { LL | | @@ -138,7 +138,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:143:9 + --> tests/ui/infinite_loops.rs:144:9 | LL | / loop { LL | | @@ -151,7 +151,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:183:5 + --> tests/ui/infinite_loops.rs:184:5 | LL | / loop { LL | | @@ -164,7 +164,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:224:5 + --> tests/ui/infinite_loops.rs:225:5 | LL | / loop { LL | | @@ -175,7 +175,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:229:5 + --> tests/ui/infinite_loops.rs:230:5 | LL | / loop { LL | | @@ -189,7 +189,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:334:9 + --> tests/ui/infinite_loops.rs:335:9 | LL | / loop { LL | | @@ -204,7 +204,7 @@ LL | fn problematic_trait_method() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:344:9 + --> tests/ui/infinite_loops.rs:345:9 | LL | / loop { LL | | @@ -219,7 +219,7 @@ LL | fn could_be_problematic() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:353:9 + --> tests/ui/infinite_loops.rs:354:9 | LL | / loop { LL | | @@ -234,7 +234,7 @@ LL | let _loop_forever = || -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:367:8 + --> tests/ui/infinite_loops.rs:368:8 | LL | Ok(loop { | ________^ @@ -246,7 +246,7 @@ LL | | }) = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:410:5 + --> tests/ui/infinite_loops.rs:411:5 | LL | / 'infinite: loop { LL | | @@ -263,7 +263,7 @@ LL | fn continue_outer() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:417:5 + --> tests/ui/infinite_loops.rs:418:5 | LL | / loop { LL | | @@ -279,7 +279,7 @@ LL | fn continue_outer() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:419:9 + --> tests/ui/infinite_loops.rs:420:9 | LL | / 'inner: loop { LL | | @@ -296,7 +296,7 @@ LL | fn continue_outer() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:428:5 + --> tests/ui/infinite_loops.rs:429:5 | LL | / loop { LL | | @@ -311,7 +311,7 @@ LL | fn continue_outer() -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:459:13 + --> tests/ui/infinite_loops.rs:460:13 | LL | / loop { LL | | @@ -322,7 +322,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:466:13 + --> tests/ui/infinite_loops.rs:467:13 | LL | / loop { LL | | @@ -333,7 +333,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:533:9 + --> tests/ui/infinite_loops.rs:534:9 | LL | / loop { LL | | std::future::pending().await @@ -343,7 +343,7 @@ LL | | } = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:545:32 + --> tests/ui/infinite_loops.rs:546:32 | LL | let true = cond else { loop {} }; | ^^^^^^^ @@ -351,7 +351,7 @@ LL | let true = cond else { loop {} }; = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:551:13 + --> tests/ui/infinite_loops.rs:552:13 | LL | loop {} | ^^^^^^^ @@ -359,7 +359,7 @@ LL | loop {} = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:559:21 + --> tests/ui/infinite_loops.rs:560:21 | LL | None => loop {}, | ^^^^^^^ @@ -367,7 +367,7 @@ LL | None => loop {}, = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:568:13 + --> tests/ui/infinite_loops.rs:569:13 | LL | loop {} | ^^^^^^^ @@ -375,7 +375,7 @@ LL | loop {} = help: if this is not intended, try adding a `break` or `return` to the loop error: infinite loop detected - --> tests/ui/infinite_loops.rs:576:13 + --> tests/ui/infinite_loops.rs:577:13 | LL | loop {} | ^^^^^^^ @@ -387,7 +387,7 @@ LL | fn all_branches_diverge_if(cond: bool) -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:579:13 + --> tests/ui/infinite_loops.rs:580:13 | LL | loop {} | ^^^^^^^ @@ -399,7 +399,7 @@ LL | fn all_branches_diverge_if(cond: bool) -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:586:24 + --> tests/ui/infinite_loops.rs:587:24 | LL | Some(_) => loop {}, | ^^^^^^^ @@ -411,7 +411,7 @@ LL | fn all_branches_diverge_match(x: Option) -> ! { | ++++ error: infinite loop detected - --> tests/ui/infinite_loops.rs:587:21 + --> tests/ui/infinite_loops.rs:588:21 | LL | None => loop {}, | ^^^^^^^ diff --git a/tests/ui/inline_modules_cfg_test.rs b/tests/ui/inline_modules_cfg_test.rs new file mode 100644 index 0000000000000..2964e2acb4438 --- /dev/null +++ b/tests/ui/inline_modules_cfg_test.rs @@ -0,0 +1,17 @@ +//@check-pass +//@compile-flags: --cfg test + +#![warn(clippy::inline_modules)] +#![allow(clippy::non_minimal_cfg)] + +fn main() {} + +#[cfg(test)] +mod tests { + mod nested {} +} + +#[cfg(all(test))] +mod tests_in_all { + mod nested {} +} diff --git a/tests/ui/invisible_characters_unfixable.rs b/tests/ui/invisible_characters_unfixable.rs new file mode 100644 index 0000000000000..cdd09374eb90b --- /dev/null +++ b/tests/ui/invisible_characters_unfixable.rs @@ -0,0 +1,16 @@ +//@no-rustfix +#![warn(clippy::invisible_characters)] +#![allow(dead_code)] + +fn invisible() { + print!(r"a ZWS >​< here"); + //~^ invisible_characters + print!(r"a SHY >­< here"); + //~^ invisible_characters + print!(r"a WJ >⁠< here"); + //~^ invisible_characters + print!(r#"a ZWS >​< between hashes"#); + //~^ invisible_characters +} + +fn main() {} diff --git a/tests/ui/invisible_characters_unfixable.stderr b/tests/ui/invisible_characters_unfixable.stderr new file mode 100644 index 0000000000000..3454247c64155 --- /dev/null +++ b/tests/ui/invisible_characters_unfixable.stderr @@ -0,0 +1,36 @@ +error: invisible character detected + --> tests/ui/invisible_characters_unfixable.rs:6:12 + | +LL | print!(r"a ZWS >​< here"); + | ^^^^^^^^^^^^^^^^ + | + = help: use a normal string literal instead of a raw one to escape the character + = note: `-D clippy::invisible-characters` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::invisible_characters)]` + +error: invisible character detected + --> tests/ui/invisible_characters_unfixable.rs:8:12 + | +LL | print!(r"a SHY >­< here"); + | ^^^^^^^^^^^^^^^^ + | + = help: use a normal string literal instead of a raw one to escape the character + +error: invisible character detected + --> tests/ui/invisible_characters_unfixable.rs:10:12 + | +LL | print!(r"a WJ >⁠< here"); + | ^^^^^^^^^^^^^^^ + | + = help: use a normal string literal instead of a raw one to escape the character + +error: invisible character detected + --> tests/ui/invisible_characters_unfixable.rs:12:12 + | +LL | print!(r#"a ZWS >​< between hashes"#); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: use a normal string literal instead of a raw one to escape the character + +error: aborting due to 4 previous errors + diff --git a/tests/ui/len_zero_unstable.fixed b/tests/ui/len_zero_unstable.fixed deleted file mode 100644 index 8d4e6c2cc006f..0000000000000 --- a/tests/ui/len_zero_unstable.fixed +++ /dev/null @@ -1,7 +0,0 @@ -#![warn(clippy::len_zero)] -#![feature(exact_size_is_empty)] - -fn issue15890(vertices: &mut dyn ExactSizeIterator) -> bool { - vertices.is_empty() - //~^ len_zero -} diff --git a/tests/ui/len_zero_unstable.rs b/tests/ui/len_zero_unstable.rs deleted file mode 100644 index f59056c5c55b1..0000000000000 --- a/tests/ui/len_zero_unstable.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![warn(clippy::len_zero)] -#![feature(exact_size_is_empty)] - -fn issue15890(vertices: &mut dyn ExactSizeIterator) -> bool { - vertices.len() == 0 - //~^ len_zero -} diff --git a/tests/ui/len_zero_unstable.stderr b/tests/ui/len_zero_unstable.stderr deleted file mode 100644 index 103ccf3dcbf5a..0000000000000 --- a/tests/ui/len_zero_unstable.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: length comparison to zero - --> tests/ui/len_zero_unstable.rs:5:5 - | -LL | vertices.len() == 0 - | ^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `vertices.is_empty()` - | - = note: `-D clippy::len-zero` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::len_zero)]` - -error: aborting due to 1 previous error - diff --git a/tests/ui/manual_bit_width.fixed b/tests/ui/manual_bit_width.fixed new file mode 100644 index 0000000000000..5e87aee4fbf19 --- /dev/null +++ b/tests/ui/manual_bit_width.fixed @@ -0,0 +1,59 @@ +#![warn(clippy::manual_bit_width)] + +use core::num::{self, NonZero, NonZeroI32, NonZeroU32}; + +fn main() { + // `T::BITS - x.leading_zeros()` + // unsigned + let w: u8 = 5; + let _ = w.bit_width(); //~ manual_bit_width + let w: u16 = 5; + let _ = w.bit_width(); //~ manual_bit_width + let w: u32 = 5; + let _ = w.bit_width(); //~ manual_bit_width + let w: u64 = 5; + let _ = w.bit_width(); //~ manual_bit_width + let w: usize = 5; + let _ = w.bit_width(); //~ manual_bit_width + + // signed + let x: i8 = -5; + let _ = x.cast_unsigned().bit_width(); //~ manual_bit_width + let x: i16 = -5; + let _ = x.cast_unsigned().bit_width(); //~ manual_bit_width + let x: i32 = -5; + let _ = x.cast_unsigned().bit_width(); //~ manual_bit_width + let x: i64 = -5; + let _ = x.cast_unsigned().bit_width(); //~ manual_bit_width + let x: isize = -5; + let _ = x.cast_unsigned().bit_width(); //~ manual_bit_width + + // `NonZero::::BITS - x.leading_zeros()` + // unsigned + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ manual_bit_width + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ manual_bit_width + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ manual_bit_width + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ manual_bit_width + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ manual_bit_width + + // signed + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ manual_bit_width + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ manual_bit_width + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ manual_bit_width + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ manual_bit_width + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ manual_bit_width + + // negative cases. + // left expression is a literal + let z: u32 = 1_000_000 - x.leading_zeros(); +} diff --git a/tests/ui/manual_bit_width.rs b/tests/ui/manual_bit_width.rs new file mode 100644 index 0000000000000..0444d55195c89 --- /dev/null +++ b/tests/ui/manual_bit_width.rs @@ -0,0 +1,59 @@ +#![warn(clippy::manual_bit_width)] + +use core::num::{self, NonZero, NonZeroI32, NonZeroU32}; + +fn main() { + // `T::BITS - x.leading_zeros()` + // unsigned + let w: u8 = 5; + let _ = u8::BITS - w.leading_zeros(); //~ manual_bit_width + let w: u16 = 5; + let _ = u16::BITS - w.leading_zeros(); //~ manual_bit_width + let w: u32 = 5; + let _ = u32::BITS - w.leading_zeros(); //~ manual_bit_width + let w: u64 = 5; + let _ = u64::BITS - w.leading_zeros(); //~ manual_bit_width + let w: usize = 5; + let _ = usize::BITS - w.leading_zeros(); //~ manual_bit_width + + // signed + let x: i8 = -5; + let _ = i8::BITS - x.leading_zeros(); //~ manual_bit_width + let x: i16 = -5; + let _ = i16::BITS - x.leading_zeros(); //~ manual_bit_width + let x: i32 = -5; + let _ = i32::BITS - x.leading_zeros(); //~ manual_bit_width + let x: i64 = -5; + let _ = i64::BITS - x.leading_zeros(); //~ manual_bit_width + let x: isize = -5; + let _ = isize::BITS - x.leading_zeros(); //~ manual_bit_width + + // `NonZero::::BITS - x.leading_zeros()` + // unsigned + let y = NonZero::::new(5).unwrap(); + let _ = NonZero::::BITS - y.leading_zeros(); //~ manual_bit_width + let y = NonZero::::new(5).unwrap(); + let _ = NonZero::::BITS - y.leading_zeros(); //~ manual_bit_width + let y = NonZero::::new(5).unwrap(); + let _ = NonZeroU32::BITS - y.leading_zeros(); //~ manual_bit_width + let y = NonZero::::new(5).unwrap(); + let _ = NonZero::::BITS - y.leading_zeros(); //~ manual_bit_width + let y = NonZero::::new(5).unwrap(); + let _ = num::NonZero::::BITS - y.leading_zeros(); //~ manual_bit_width + + // signed + let z = NonZero::::new(-5).unwrap(); + let _ = NonZero::::BITS - z.leading_zeros(); //~ manual_bit_width + let z = NonZero::::new(-5).unwrap(); + let _ = NonZero::::BITS - z.leading_zeros(); //~ manual_bit_width + let z = NonZero::::new(-5).unwrap(); + let _ = NonZeroI32::BITS - z.leading_zeros(); //~ manual_bit_width + let z = NonZero::::new(-5).unwrap(); + let _ = NonZero::::BITS - z.leading_zeros(); //~ manual_bit_width + let z = NonZero::::new(-5).unwrap(); + let _ = num::NonZero::::BITS - z.leading_zeros(); //~ manual_bit_width + + // negative cases. + // left expression is a literal + let z: u32 = 1_000_000 - x.leading_zeros(); +} diff --git a/tests/ui/manual_bit_width.stderr b/tests/ui/manual_bit_width.stderr new file mode 100644 index 0000000000000..74214f0d8d675 --- /dev/null +++ b/tests/ui/manual_bit_width.stderr @@ -0,0 +1,244 @@ +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:9:13 + | +LL | let _ = u8::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::manual-bit-width` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_bit_width)]` +help: try + | +LL - let _ = u8::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:11:13 + | +LL | let _ = u16::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = u16::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:13:13 + | +LL | let _ = u32::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = u32::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:15:13 + | +LL | let _ = u64::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = u64::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:17:13 + | +LL | let _ = usize::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = usize::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:21:13 + | +LL | let _ = i8::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = i8::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:23:13 + | +LL | let _ = i16::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = i16::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:25:13 + | +LL | let _ = i32::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = i32::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:27:13 + | +LL | let _ = i64::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = i64::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:29:13 + | +LL | let _ = isize::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = isize::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:34:13 + | +LL | let _ = NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:36:13 + | +LL | let _ = NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:38:13 + | +LL | let _ = NonZeroU32::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = NonZeroU32::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:40:13 + | +LL | let _ = NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:42:13 + | +LL | let _ = num::NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = num::NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:46:13 + | +LL | let _ = NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:48:13 + | +LL | let _ = NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:50:13 + | +LL | let _ = NonZeroI32::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = NonZeroI32::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:52:13 + | +LL | let _ = NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: manual implementation of `bit_width` + --> tests/ui/manual_bit_width.rs:54:13 + | +LL | let _ = num::NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | +LL - let _ = num::NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: aborting due to 20 previous errors + diff --git a/tests/ui/manual_c_str_literals.edition2021.fixed b/tests/ui/manual_c_str_literals.edition2021.fixed index 3ffaef0386cec..79b0892ef6bf0 100644 --- a/tests/ui/manual_c_str_literals.edition2021.fixed +++ b/tests/ui/manual_c_str_literals.edition2021.fixed @@ -45,6 +45,8 @@ fn main() { //~[edition2021]^ manual_c_str_literals c"foo\\0sdsd"; //~[edition2021]^ manual_c_str_literals + CStr::from_bytes_with_nul(b"foo\\0").unwrap(); + CStr::from_bytes_with_nul(b"bar\\x00").unwrap(); CStr::from_bytes_with_nul(br"foo\\0sdsd\0").unwrap(); CStr::from_bytes_with_nul(br"foo\x00").unwrap(); CStr::from_bytes_with_nul(br##"foo#a\0"##).unwrap(); @@ -53,8 +55,12 @@ fn main() { //~[edition2021]^ manual_c_str_literals unsafe { c"foo" }; //~[edition2021]^ manual_c_str_literals + unsafe { CStr::from_ptr(b"foo\\0".as_ptr().cast()) }; + unsafe { CStr::from_ptr(b"bar\\x00".as_ptr().cast()) }; let _: *const _ = c"foo".as_ptr(); //~[edition2021]^ manual_c_str_literals + let _: *const _ = b"foo\\0".as_ptr(); + let _: *const _ = b"bar\\x00".as_ptr(); let _: *const _ = c"foo".as_ptr(); //~[edition2021]^ manual_c_str_literals let _: *const _ = "foo".as_ptr(); // not a C-string diff --git a/tests/ui/manual_c_str_literals.edition2021.stderr b/tests/ui/manual_c_str_literals.edition2021.stderr index 2119bbc5b425f..0f9cf4be01fdc 100644 --- a/tests/ui/manual_c_str_literals.edition2021.stderr +++ b/tests/ui/manual_c_str_literals.edition2021.stderr @@ -32,52 +32,62 @@ LL | CStr::from_bytes_with_nul(b"foo\\0sdsd\0").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo\\0sdsd"` error: calling `CStr::from_ptr` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:52:14 + --> tests/ui/manual_c_str_literals.rs:54:14 | LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr().cast()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::from_ptr` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:54:14 + --> tests/ui/manual_c_str_literals.rs:56:14 | LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr() as *const _) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:56:23 + --> tests/ui/manual_c_str_literals.rs:60:23 | LL | let _: *const _ = b"foo\0".as_ptr(); | ^^^^^^^^ help: use a `c""` literal: `c"foo"` + | + = note: an additional cast may be needed, since the type of `c"".as_ptr()` and `b"".as_ptr()` can differ and is platform dependent error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:58:23 + --> tests/ui/manual_c_str_literals.rs:64:23 | LL | let _: *const _ = "foo\0".as_ptr(); | ^^^^^^^ help: use a `c""` literal: `c"foo"` + | + = note: an additional cast may be needed, since the type of `c"".as_ptr()` and `b"".as_ptr()` can differ and is platform dependent error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:62:23 + --> tests/ui/manual_c_str_literals.rs:68:23 | LL | let _: *const _ = b"foo\0".as_ptr().cast::(); | ^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:66:13 + --> tests/ui/manual_c_str_literals.rs:72:13 | LL | let _ = "电脑\\\0".as_ptr(); | ^^^^^^^^^^ help: use a `c""` literal: `c"电脑\\"` + | + = note: an additional cast may be needed, since the type of `c"".as_ptr()` and `b"".as_ptr()` can differ and is platform dependent error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:68:13 + --> tests/ui/manual_c_str_literals.rs:74:13 | LL | let _ = "电脑\0".as_ptr(); | ^^^^^^^^ help: use a `c""` literal: `c"电脑"` + | + = note: an additional cast may be needed, since the type of `c"".as_ptr()` and `b"".as_ptr()` can differ and is platform dependent error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:70:13 + --> tests/ui/manual_c_str_literals.rs:76:13 | LL | let _ = "电脑\x00".as_ptr(); | ^^^^^^^^^^ help: use a `c""` literal: `c"电脑"` + | + = note: an additional cast may be needed, since the type of `c"".as_ptr()` and `b"".as_ptr()` can differ and is platform dependent error: aborting due to 13 previous errors diff --git a/tests/ui/manual_c_str_literals.rs b/tests/ui/manual_c_str_literals.rs index ec3b8e5877245..440e8208c640b 100644 --- a/tests/ui/manual_c_str_literals.rs +++ b/tests/ui/manual_c_str_literals.rs @@ -45,6 +45,8 @@ fn main() { //~[edition2021]^ manual_c_str_literals CStr::from_bytes_with_nul(b"foo\\0sdsd\0").unwrap(); //~[edition2021]^ manual_c_str_literals + CStr::from_bytes_with_nul(b"foo\\0").unwrap(); + CStr::from_bytes_with_nul(b"bar\\x00").unwrap(); CStr::from_bytes_with_nul(br"foo\\0sdsd\0").unwrap(); CStr::from_bytes_with_nul(br"foo\x00").unwrap(); CStr::from_bytes_with_nul(br##"foo#a\0"##).unwrap(); @@ -53,8 +55,12 @@ fn main() { //~[edition2021]^ manual_c_str_literals unsafe { CStr::from_ptr(b"foo\0".as_ptr() as *const _) }; //~[edition2021]^ manual_c_str_literals + unsafe { CStr::from_ptr(b"foo\\0".as_ptr().cast()) }; + unsafe { CStr::from_ptr(b"bar\\x00".as_ptr().cast()) }; let _: *const _ = b"foo\0".as_ptr(); //~[edition2021]^ manual_c_str_literals + let _: *const _ = b"foo\\0".as_ptr(); + let _: *const _ = b"bar\\x00".as_ptr(); let _: *const _ = "foo\0".as_ptr(); //~[edition2021]^ manual_c_str_literals let _: *const _ = "foo".as_ptr(); // not a C-string diff --git a/tests/ui/manual_is_variant_and.fixed b/tests/ui/manual_is_variant_and.fixed index de79a7cb340dc..d042fe8988160 100644 --- a/tests/ui/manual_is_variant_and.fixed +++ b/tests/ui/manual_is_variant_and.fixed @@ -244,6 +244,19 @@ fn issue16419_msrv() { let _ = opt.is_some_and(then_fn) || opt.is_none(); } +#[clippy::msrv = "1.69"] +fn check_map_msrv_is_some_and(opt: Option) { + let _ = opt.map(|x| x > 0) == Some(true); + let _ = opt.map(|x| x > 0) != Some(false); +} + +#[clippy::msrv = "1.81"] +fn check_map_msrv_is_none_or(opt: Option) { + let _ = opt.is_some_and(|x| x > 0); + //~^ manual_is_variant_and + let _ = opt.map(|x| x > 0) != Some(false); +} + fn issue16518(opt: Option) { let condition = |x: &i32| *x > 10; diff --git a/tests/ui/manual_is_variant_and.rs b/tests/ui/manual_is_variant_and.rs index b7d4226814d3c..482c539cb62e5 100644 --- a/tests/ui/manual_is_variant_and.rs +++ b/tests/ui/manual_is_variant_and.rs @@ -253,6 +253,19 @@ fn issue16419_msrv() { let _ = opt.is_some_and(then_fn) || opt.is_none(); } +#[clippy::msrv = "1.69"] +fn check_map_msrv_is_some_and(opt: Option) { + let _ = opt.map(|x| x > 0) == Some(true); + let _ = opt.map(|x| x > 0) != Some(false); +} + +#[clippy::msrv = "1.81"] +fn check_map_msrv_is_none_or(opt: Option) { + let _ = opt.map(|x| x > 0) == Some(true); + //~^ manual_is_variant_and + let _ = opt.map(|x| x > 0) != Some(false); +} + fn issue16518(opt: Option) { let condition = |x: &i32| *x > 10; diff --git a/tests/ui/manual_is_variant_and.stderr b/tests/ui/manual_is_variant_and.stderr index 2b8288257d27a..daf7227863e94 100644 --- a/tests/ui/manual_is_variant_and.stderr +++ b/tests/ui/manual_is_variant_and.stderr @@ -234,29 +234,35 @@ error: manual implementation of `Option::is_none_or` LL | let _ = opt.is_some_and(then_fn) || opt.is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `opt.is_none_or(then_fn)` +error: called `.map() == Some()` + --> tests/ui/manual_is_variant_and.rs:264:13 + | +LL | let _ = opt.map(|x| x > 0) == Some(true); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `opt.is_some_and(|x| x > 0)` + error: manual implementation of `Option::is_some_and` - --> tests/ui/manual_is_variant_and.rs:259:5 + --> tests/ui/manual_is_variant_and.rs:272:5 | LL | opt.filter(|x| condition(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `opt.as_ref().is_some_and(|x| condition(x))` error: manual implementation of `Option::is_none_or` - --> tests/ui/manual_is_variant_and.rs:261:5 + --> tests/ui/manual_is_variant_and.rs:274:5 | LL | opt.filter(|x| condition(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `opt.as_ref().is_none_or(|x| !condition(x))` error: called `.ok().is_some_and(..)` on a `Result` value - --> tests/ui/manual_is_variant_and.rs:273:13 + --> tests/ui/manual_is_variant_and.rs:286:13 | LL | let _ = res.ok().is_some_and(|x| x > 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `is_ok_and` instead: `res.is_ok_and(|x| x > 0)` error: called `.ok().is_some_and(..)` on a `Result` value - --> tests/ui/manual_is_variant_and.rs:276:13 + --> tests/ui/manual_is_variant_and.rs:289:13 | LL | let _ = res.ok().is_some_and(|x| x > 0) || res.is_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `is_ok_and` instead: `res.is_ok_and(|x| x > 0)` -error: aborting due to 37 previous errors +error: aborting due to 38 previous errors diff --git a/tests/ui/match_same_arms_expect.rs b/tests/ui/match_same_arms_expect.rs new file mode 100644 index 0000000000000..43eb8416bf58c --- /dev/null +++ b/tests/ui/match_same_arms_expect.rs @@ -0,0 +1,18 @@ +//! An `#[expect(clippy::match_same_arms)]` on a match arm must still work when the lint is +//! allowed on an enclosing scope. +//@check-pass +#![allow(clippy::match_same_arms)] + +fn allowed_outer_expect_inner(x: u32) -> u32 { + match x { + #[expect(clippy::match_same_arms)] + 1 => 42, + #[expect(clippy::match_same_arms)] + 2 => 42, + _ => 0, + } +} + +fn main() { + allowed_outer_expect_inner(1); +} diff --git a/tests/ui/mismatched_bit_width_type.fixed b/tests/ui/mismatched_bit_width_type.fixed new file mode 100644 index 0000000000000..f2f313df9a3a0 --- /dev/null +++ b/tests/ui/mismatched_bit_width_type.fixed @@ -0,0 +1,79 @@ +#![warn(clippy::mismatched_bit_width_type)] + +use core::num::{self, NonZero, NonZeroI32, NonZeroU32}; + +fn main() { + // left and right ewpression have different calling types + // unsigned + let w: u8 = 5; + let _ = w.bit_width(); //~ mismatched_bit_width_type + let _ = w.bit_width(); //~ mismatched_bit_width_type + let w: u16 = 5; + let _ = w.bit_width(); //~ mismatched_bit_width_type + let _ = w.bit_width(); //~ mismatched_bit_width_type + let w: u32 = 5; + let _ = w.bit_width(); //~ mismatched_bit_width_type + let _ = w.bit_width(); //~ mismatched_bit_width_type + let w: u64 = 5; + let _ = w.bit_width(); //~ mismatched_bit_width_type + let _ = w.bit_width(); //~ mismatched_bit_width_type + let w: usize = 5; + let _ = w.bit_width(); //~ mismatched_bit_width_type + let _ = w.bit_width(); //~ mismatched_bit_width_type + + // signed + let x: i8 = -5; + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + let x: i16 = -5; + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + let x: i32 = -5; + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + let x: i64 = -5; + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + let x: isize = -5; + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + let _ = x.cast_unsigned().bit_width(); //~ mismatched_bit_width_type + + // `NonZero::::BITS - x.leading_zeros()` + // unsigned + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + let y = NonZero::::new(5).unwrap(); + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + let _ = y.bit_width().get(); //~ mismatched_bit_width_type + + // signed + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + let z = NonZero::::new(-5).unwrap(); + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + let _ = z.cast_unsigned().bit_width().get(); //~ mismatched_bit_width_type + + // negative case. + // left expression is a literal + let z: u32 = 1_000_000 - x.leading_zeros(); +} diff --git a/tests/ui/mismatched_bit_width_type.rs b/tests/ui/mismatched_bit_width_type.rs new file mode 100644 index 0000000000000..abd96ca52599c --- /dev/null +++ b/tests/ui/mismatched_bit_width_type.rs @@ -0,0 +1,79 @@ +#![warn(clippy::mismatched_bit_width_type)] + +use core::num::{self, NonZero, NonZeroI32, NonZeroU32}; + +fn main() { + // left and right ewpression have different calling types + // unsigned + let w: u8 = 5; + let _ = i8::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + let _ = u32::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + let w: u16 = 5; + let _ = i16::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + let _ = u8::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + let w: u32 = 5; + let _ = i32::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + let _ = isize::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + let w: u64 = 5; + let _ = i64::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + let _ = NonZero::::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + let w: usize = 5; + let _ = isize::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + let _ = NonZero::::BITS - w.leading_zeros(); //~ mismatched_bit_width_type + + // signed + let x: i8 = -5; + let _ = u8::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + let _ = i16::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + let x: i16 = -5; + let _ = u16::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + let _ = NonZero::::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + let x: i32 = -5; + let _ = u32::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + let _ = NonZero::::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + let x: i64 = -5; + let _ = u64::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + let _ = isize::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + let x: isize = -5; + let _ = usize::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + let _ = u32::BITS - x.leading_zeros(); //~ mismatched_bit_width_type + + // `NonZero::::BITS - x.leading_zeros()` + // unsigned + let y = NonZero::::new(5).unwrap(); + let _ = NonZero::::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + let _ = u8::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + let y = NonZero::::new(5).unwrap(); + let _ = NonZero::::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + let _ = i16::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + let y = NonZero::::new(5).unwrap(); + let _ = NonZeroI32::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + let _ = NonZero::::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + let y = NonZero::::new(5).unwrap(); + let _ = NonZero::::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + let _ = NonZero::::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + let y = NonZero::::new(5).unwrap(); + let _ = num::NonZero::::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + let _ = u64::BITS - y.leading_zeros(); //~ mismatched_bit_width_type + + // signed + let z = NonZero::::new(-5).unwrap(); + let _ = NonZero::::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + let _ = u8::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + let z = NonZero::::new(-5).unwrap(); + let _ = NonZero::::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + let _ = i16::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + let z = NonZero::::new(-5).unwrap(); + let _ = NonZeroU32::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + let _ = NonZero::::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + let z = NonZero::::new(-5).unwrap(); + let _ = NonZero::::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + let _ = NonZero::::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + let z = NonZero::::new(-5).unwrap(); + let _ = num::NonZero::::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + let _ = num::NonZero::::BITS - z.leading_zeros(); //~ mismatched_bit_width_type + + // negative case. + // left expression is a literal + let z: u32 = 1_000_000 - x.leading_zeros(); +} diff --git a/tests/ui/mismatched_bit_width_type.stderr b/tests/ui/mismatched_bit_width_type.stderr new file mode 100644 index 0000000000000..bdb7eed7db5ee --- /dev/null +++ b/tests/ui/mismatched_bit_width_type.stderr @@ -0,0 +1,524 @@ +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:9:13 + | +LL | let _ = i8::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` + = note: `-D clippy::mismatched-bit-width-type` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mismatched_bit_width_type)]` +help: if you meant to use `u8::BITS`, use + | +LL - let _ = i8::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:10:13 + | +LL | let _ = u32::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `u8::BITS`, use + | +LL - let _ = u32::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:12:13 + | +LL | let _ = i16::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `u16::BITS`, use + | +LL - let _ = i16::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:13:13 + | +LL | let _ = u8::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `u16::BITS`, use + | +LL - let _ = u8::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:15:13 + | +LL | let _ = i32::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `u32::BITS`, use + | +LL - let _ = i32::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:16:13 + | +LL | let _ = isize::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `u32::BITS`, use + | +LL - let _ = isize::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:18:13 + | +LL | let _ = i64::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `u64::BITS`, use + | +LL - let _ = i64::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:19:13 + | +LL | let _ = NonZero::::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `u64::BITS`, use + | +LL - let _ = NonZero::::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:21:13 + | +LL | let _ = isize::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `usize::BITS`, use + | +LL - let _ = isize::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:22:13 + | +LL | let _ = NonZero::::BITS - w.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `usize::BITS`, use + | +LL - let _ = NonZero::::BITS - w.leading_zeros(); +LL + let _ = w.bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:26:13 + | +LL | let _ = u8::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `i8::BITS`, use + | +LL - let _ = u8::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:27:13 + | +LL | let _ = i16::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `i8::BITS`, use + | +LL - let _ = i16::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:29:13 + | +LL | let _ = u16::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `i16::BITS`, use + | +LL - let _ = u16::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:30:13 + | +LL | let _ = NonZero::::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `i16::BITS`, use + | +LL - let _ = NonZero::::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:32:13 + | +LL | let _ = u32::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `i32::BITS`, use + | +LL - let _ = u32::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:33:13 + | +LL | let _ = NonZero::::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `i32::BITS`, use + | +LL - let _ = NonZero::::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:35:13 + | +LL | let _ = u64::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `i64::BITS`, use + | +LL - let _ = u64::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:36:13 + | +LL | let _ = isize::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `i64::BITS`, use + | +LL - let _ = isize::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:38:13 + | +LL | let _ = usize::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `isize::BITS`, use + | +LL - let _ = usize::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:39:13 + | +LL | let _ = u32::BITS - x.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `isize::BITS`, use + | +LL - let _ = u32::BITS - x.leading_zeros(); +LL + let _ = x.cast_unsigned().bit_width(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:44:13 + | +LL | let _ = NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:45:13 + | +LL | let _ = u8::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = u8::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:47:13 + | +LL | let _ = NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:48:13 + | +LL | let _ = i16::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = i16::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:50:13 + | +LL | let _ = NonZeroI32::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZeroI32::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:51:13 + | +LL | let _ = NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:53:13 + | +LL | let _ = NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:54:13 + | +LL | let _ = NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:56:13 + | +LL | let _ = num::NonZero::::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = num::NonZero::::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:57:13 + | +LL | let _ = u64::BITS - y.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = u64::BITS - y.leading_zeros(); +LL + let _ = y.bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:61:13 + | +LL | let _ = NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:62:13 + | +LL | let _ = u8::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = u8::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:64:13 + | +LL | let _ = NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:65:13 + | +LL | let _ = i16::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = i16::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:67:13 + | +LL | let _ = NonZeroU32::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZeroU32::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:68:13 + | +LL | let _ = NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:70:13 + | +LL | let _ = NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:71:13 + | +LL | let _ = NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:73:13 + | +LL | let _ = num::NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = num::NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: possible buggy implementation of `bit_width` + --> tests/ui/mismatched_bit_width_type.rs:74:13 + | +LL | let _ = num::NonZero::::BITS - z.leading_zeros(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: in order to calculate the bit width, `T::BITS` should match the type of the value calling `.leading_zeros()` +help: if you meant to use `std::num::NonZero::BITS`, use + | +LL - let _ = num::NonZero::::BITS - z.leading_zeros(); +LL + let _ = z.cast_unsigned().bit_width().get(); + | + +error: aborting due to 40 previous errors + diff --git a/tests/ui/missing_trait_methods.rs b/tests/ui/missing_trait_methods.rs index 90349a0de101f..15b68d91f2055 100644 --- a/tests/ui/missing_trait_methods.rs +++ b/tests/ui/missing_trait_methods.rs @@ -1,5 +1,6 @@ #![warn(clippy::missing_trait_methods)] #![expect(clippy::needless_lifetimes)] +#![allow(clippy::derive_ord_xor_partial_ord)] trait A { fn provided() {} @@ -69,3 +70,29 @@ impl PartialEq for Partial { todo!() } } + +#[clippy::msrv = "1.20.0"] +fn msrv0() { + #[derive(PartialEq, Eq, PartialOrd)] + struct S {} + + impl Ord for S { + fn cmp(&self, other: &S) -> std::cmp::Ordering { + unreachable!() + } + } +} + +#[clippy::msrv = "1.21.0"] +fn msrv1() { + #[derive(PartialEq, Eq, PartialOrd)] + struct S {} + + impl Ord for S { + //~^ missing_trait_methods + //~| missing_trait_methods + fn cmp(&self, other: &S) -> std::cmp::Ordering { + unreachable!() + } + } +} diff --git a/tests/ui/missing_trait_methods.stderr b/tests/ui/missing_trait_methods.stderr index e5155ad587cba..21e4dace7fe9b 100644 --- a/tests/ui/missing_trait_methods.stderr +++ b/tests/ui/missing_trait_methods.stderr @@ -1,11 +1,11 @@ error: missing trait method provided by default: `provided` - --> tests/ui/missing_trait_methods.rs:22:1 + --> tests/ui/missing_trait_methods.rs:23:1 | LL | impl A for Partial {} | ^^^^^^^^^^^^^^^^^^ | help: implement the method - --> tests/ui/missing_trait_methods.rs:5:5 + --> tests/ui/missing_trait_methods.rs:6:5 | LL | fn provided() {} | ^^^^^^^^^^^^^ @@ -13,60 +13,76 @@ LL | fn provided() {} = help: to override `-D warnings` add `#[allow(clippy::missing_trait_methods)]` error: missing trait method provided by default: `b` - --> tests/ui/missing_trait_methods.rs:25:1 + --> tests/ui/missing_trait_methods.rs:26:1 | LL | impl B for Partial { | ^^^^^^^^^^^^^^^^^^ | help: implement the method - --> tests/ui/missing_trait_methods.rs:15:5 + --> tests/ui/missing_trait_methods.rs:16:5 | LL | fn b<'a, T: AsRef<[u8]>>(a: &'a T) -> &'a [u8] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing trait method provided by default: `one` - --> tests/ui/missing_trait_methods.rs:59:1 + --> tests/ui/missing_trait_methods.rs:60:1 | LL | impl MissingMultiple for Partial {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: implement the method - --> tests/ui/missing_trait_methods.rs:54:5 + --> tests/ui/missing_trait_methods.rs:55:5 | LL | fn one() {} | ^^^^^^^^ error: missing trait method provided by default: `two` - --> tests/ui/missing_trait_methods.rs:59:1 + --> tests/ui/missing_trait_methods.rs:60:1 | LL | impl MissingMultiple for Partial {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: implement the method - --> tests/ui/missing_trait_methods.rs:55:5 + --> tests/ui/missing_trait_methods.rs:56:5 | LL | fn two() {} | ^^^^^^^^ error: missing trait method provided by default: `three` - --> tests/ui/missing_trait_methods.rs:59:1 + --> tests/ui/missing_trait_methods.rs:60:1 | LL | impl MissingMultiple for Partial {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: implement the method - --> tests/ui/missing_trait_methods.rs:56:5 + --> tests/ui/missing_trait_methods.rs:57:5 | LL | fn three() {} | ^^^^^^^^^^ error: missing trait method provided by default: `ne` - --> tests/ui/missing_trait_methods.rs:67:1 + --> tests/ui/missing_trait_methods.rs:68:1 | LL | impl PartialEq for Partial { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: implement the missing `ne` method of the `PartialEq` trait -error: aborting due to 6 previous errors +error: missing trait method provided by default: `max` + --> tests/ui/missing_trait_methods.rs:91:5 + | +LL | impl Ord for S { + | ^^^^^^^^^^^^^^ + | + = help: implement the missing `max` method of the `Ord` trait + +error: missing trait method provided by default: `min` + --> tests/ui/missing_trait_methods.rs:91:5 + | +LL | impl Ord for S { + | ^^^^^^^^^^^^^^ + | + = help: implement the missing `min` method of the `Ord` trait + +error: aborting due to 8 previous errors diff --git a/tests/ui/mut_mut.stderr b/tests/ui/mut_mut.stderr index 0a7a923e0f48f..a7b721539f80d 100644 --- a/tests/ui/mut_mut.stderr +++ b/tests/ui/mut_mut.stderr @@ -1,47 +1,87 @@ -error: a type of form `&mut &mut _` +error: multiple successive mutable references --> tests/ui/mut_mut.rs:8:11 | LL | fn fun(x: &mut &mut u32) { - | ^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut u32` + | ^^^^^^^^^^ | = note: `-D clippy::mut-mut` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::mut_mut)]` +help: use only a single mutable reference + | +LL - fn fun(x: &mut &mut u32) { +LL + fn fun(x: &mut u32) { + | -error: an expression of form `&mut &mut _` +error: multiple successive mutable borrows --> tests/ui/mut_mut.rs:24:17 | LL | let mut x = &mut &mut 1u32; - | ^^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut 1u32` + | ^^^^^^^^^^ + | +help: make only a single borrow + | +LL - let mut x = &mut &mut 1u32; +LL + let mut x = &mut 1u32; + | -error: this expression mutably borrows a mutable reference +error: borrow of a mutable reference --> tests/ui/mut_mut.rs:27:21 | LL | let mut y = &mut x; - | ^^^^^^ help: reborrow instead: `&mut *x` + | ^^^^^ + | +help: reborrow instead + | +LL | let mut y = &mut *x; + | + -error: an expression of form `&mut &mut _` +error: multiple successive mutable borrows --> tests/ui/mut_mut.rs:32:32 | LL | let y: &mut &mut u32 = &mut &mut 2; - | ^^^^^^^^^^^ help: remove the extra `&mut`: `&mut 2` + | ^^^^^^^^^^ + | +help: make only a single borrow + | +LL - let y: &mut &mut u32 = &mut &mut 2; +LL + let y: &mut &mut u32 = &mut 2; + | -error: a type of form `&mut &mut _` +error: multiple successive mutable references --> tests/ui/mut_mut.rs:32:16 | LL | let y: &mut &mut u32 = &mut &mut 2; - | ^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut u32` + | ^^^^^^^^^^ + | +help: use only a single mutable reference + | +LL - let y: &mut &mut u32 = &mut &mut 2; +LL + let y: &mut u32 = &mut &mut 2; + | -error: an expression of form `&mut &mut _` +error: multiple successive mutable borrows --> tests/ui/mut_mut.rs:38:37 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^^^^ help: remove the extra `&mut`s: `&mut 2` + | ^^^^^^^^^^^^^^^ + | +help: make only a single borrow + | +LL - let y: &mut &mut &mut u32 = &mut &mut &mut 2; +LL + let y: &mut &mut &mut u32 = &mut 2; + | -error: a type of form `&mut &mut _` +error: multiple successive mutable references --> tests/ui/mut_mut.rs:38:16 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; - | ^^^^^^^^^^^^^^^^^^ help: remove the extra `&mut`s: `&mut u32` + | ^^^^^^^^^^^^^^^ + | +help: use only a single mutable reference + | +LL - let y: &mut &mut &mut u32 = &mut &mut &mut 2; +LL + let y: &mut u32 = &mut &mut &mut 2; + | error: aborting due to 7 previous errors diff --git a/tests/ui/mut_mut_unfixable.stderr b/tests/ui/mut_mut_unfixable.stderr index 7e7fb801ce1e7..07cc965a8a172 100644 --- a/tests/ui/mut_mut_unfixable.stderr +++ b/tests/ui/mut_mut_unfixable.stderr @@ -1,41 +1,75 @@ -error: a type of form `&mut &mut _` +error: multiple successive mutable references --> tests/ui/mut_mut_unfixable.rs:8:11 | LL | fn fun(x: &mut &mut u32) -> bool { - | ^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut u32` + | ^^^^^^^^^^ | = note: `-D clippy::mut-mut` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::mut_mut)]` +help: use only a single mutable reference + | +LL - fn fun(x: &mut &mut u32) -> bool { +LL + fn fun(x: &mut u32) -> bool { + | -error: an expression of form `&mut &mut _` +error: multiple successive mutable borrows --> tests/ui/mut_mut_unfixable.rs:14:17 | LL | let mut x = &mut &mut 1u32; - | ^^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut 1u32` + | ^^^^^^^^^^ + | +help: make only a single borrow + | +LL - let mut x = &mut &mut 1u32; +LL + let mut x = &mut 1u32; + | -error: this expression mutably borrows a mutable reference +error: borrow of a mutable reference --> tests/ui/mut_mut_unfixable.rs:17:21 | LL | let mut y = &mut x; - | ^^^^^^ help: reborrow instead: `&mut *x` + | ^^^^^ + | +help: reborrow instead + | +LL | let mut y = &mut *x; + | + -error: an expression of form `&mut &mut _` +error: multiple successive mutable borrows --> tests/ui/mut_mut_unfixable.rs:23:17 | LL | let y = &mut &mut 2; - | ^^^^^^^^^^^ help: remove the extra `&mut`: `&mut 2` + | ^^^^^^^^^^ + | +help: make only a single borrow + | +LL - let y = &mut &mut 2; +LL + let y = &mut 2; + | -error: an expression of form `&mut &mut _` +error: multiple successive mutable borrows --> tests/ui/mut_mut_unfixable.rs:29:17 | LL | let y = &mut &mut &mut 2; - | ^^^^^^^^^^^^^^^^ help: remove the extra `&mut`s: `&mut 2` + | ^^^^^^^^^^^^^^^ + | +help: make only a single borrow + | +LL - let y = &mut &mut &mut 2; +LL + let y = &mut 2; + | -error: an expression of form `&mut &mut _` +error: multiple successive mutable borrows --> tests/ui/mut_mut_unfixable.rs:38:17 | LL | let y = &mut &mut x; - | ^^^^^^^^^^^ help: remove the extra `&mut`: `&mut x` + | ^^^^^^^^^^ + | +help: make only a single borrow + | +LL - let y = &mut &mut x; +LL + let y = &mut x; + | error: aborting due to 6 previous errors diff --git a/tests/ui/needless_bool/fixable.fixed b/tests/ui/needless_bool/fixable.fixed index c3eed4e3fd717..fbe69bd62a817 100644 --- a/tests/ui/needless_bool/fixable.fixed +++ b/tests/ui/needless_bool/fixable.fixed @@ -158,6 +158,24 @@ fn issue12846() { //~^ needless_bool } +fn operands_need_parentheses() { + let a = true; + let b = false; + let z = true; + + // parentheses are needed here + let _x = (a || b) && z; + //~^ needless_bool + let _x = (a || b) == z; + //~^ needless_bool + let _x = !(a || b); + //~^ needless_bool + + // parentheses are not needed here + let _x = a && z; + //~^ needless_bool +} + fn wrongly_unmangled_macros() { macro_rules! test_expr { ($val:expr) => { diff --git a/tests/ui/needless_bool/fixable.rs b/tests/ui/needless_bool/fixable.rs index 4571628be20ea..35c723c787e1c 100644 --- a/tests/ui/needless_bool/fixable.rs +++ b/tests/ui/needless_bool/fixable.rs @@ -218,6 +218,24 @@ fn issue12846() { //~^ needless_bool } +fn operands_need_parentheses() { + let a = true; + let b = false; + let z = true; + + // parentheses are needed here + let _x = if a || b { true } else { false } && z; + //~^ needless_bool + let _x = if a || b { true } else { false } == z; + //~^ needless_bool + let _x = !if a || b { true } else { false }; + //~^ needless_bool + + // parentheses are not needed here + let _x = if a { true } else { false } && z; + //~^ needless_bool +} + fn wrongly_unmangled_macros() { macro_rules! test_expr { ($val:expr) => { diff --git a/tests/ui/needless_bool/fixable.stderr b/tests/ui/needless_bool/fixable.stderr index f8cad52c2bbf2..a0a7cefd7dd7f 100644 --- a/tests/ui/needless_bool/fixable.stderr +++ b/tests/ui/needless_bool/fixable.stderr @@ -210,7 +210,31 @@ LL | let _x = if a { true } else { false }.then(|| todo!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `a` error: this if-then-else expression returns a bool literal - --> tests/ui/needless_bool/fixable.rs:229:5 + --> tests/ui/needless_bool/fixable.rs:227:14 + | +LL | let _x = if a || b { true } else { false } && z; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(a || b)` + +error: this if-then-else expression returns a bool literal + --> tests/ui/needless_bool/fixable.rs:229:14 + | +LL | let _x = if a || b { true } else { false } == z; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(a || b)` + +error: this if-then-else expression returns a bool literal + --> tests/ui/needless_bool/fixable.rs:231:15 + | +LL | let _x = !if a || b { true } else { false }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(a || b)` + +error: this if-then-else expression returns a bool literal + --> tests/ui/needless_bool/fixable.rs:235:14 + | +LL | let _x = if a { true } else { false } && z; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `a` + +error: this if-then-else expression returns a bool literal + --> tests/ui/needless_bool/fixable.rs:247:5 | LL | / if test_expr!(x) { LL | | true @@ -219,5 +243,5 @@ LL | | false LL | | }; | |_____^ help: you can reduce it to: `test_expr!(x)` -error: aborting due to 25 previous errors +error: aborting due to 29 previous errors diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index 54cad2e393fd4..fd17fbb7c0935 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -1,13 +1,9 @@ -#![allow( - unused, - non_local_definitions, - clippy::uninlined_format_args, - clippy::unnecessary_mut_passed, - clippy::unnecessary_to_owned, +#![warn(clippy::needless_borrow)] +#![expect( + clippy::needless_lifetimes, clippy::unnecessary_literal_unwrap, - clippy::needless_lifetimes + clippy::unnecessary_mut_passed )] -#![warn(clippy::needless_borrow)] fn main() { let a = 5; diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index b698c6bfc9695..a96252bcb3be8 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -1,13 +1,9 @@ -#![allow( - unused, - non_local_definitions, - clippy::uninlined_format_args, - clippy::unnecessary_mut_passed, - clippy::unnecessary_to_owned, +#![warn(clippy::needless_borrow)] +#![expect( + clippy::needless_lifetimes, clippy::unnecessary_literal_unwrap, - clippy::needless_lifetimes + clippy::unnecessary_mut_passed )] -#![warn(clippy::needless_borrow)] fn main() { let a = 5; diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index 172d36bd73a0a..e7a488b9ed924 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -1,5 +1,5 @@ error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:16:15 + --> tests/ui/needless_borrow.rs:12:15 | LL | let _ = x(&&a); // warn | ^^^ help: change this to: `&a` @@ -8,163 +8,163 @@ LL | let _ = x(&&a); // warn = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:22:13 + --> tests/ui/needless_borrow.rs:18:13 | LL | mut_ref(&mut &mut b); // warn | ^^^^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:36:13 + --> tests/ui/needless_borrow.rs:32:13 | LL | &&a | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:39:15 + --> tests/ui/needless_borrow.rs:35:15 | LL | 46 => &&a, | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:46:27 + --> tests/ui/needless_borrow.rs:42:27 | LL | break &ref_a; | ^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:54:15 + --> tests/ui/needless_borrow.rs:50:15 | LL | let _ = x(&&&a); | ^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:56:15 + --> tests/ui/needless_borrow.rs:52:15 | LL | let _ = x(&mut &&a); | ^^^^^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:58:15 + --> tests/ui/needless_borrow.rs:54:15 | LL | let _ = x(&&&mut b); | ^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:60:15 + --> tests/ui/needless_borrow.rs:56:15 | LL | let _ = x(&&ref_a); | ^^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:64:11 + --> tests/ui/needless_borrow.rs:60:11 | LL | x(&b); | ^^ help: change this to: `b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:72:13 + --> tests/ui/needless_borrow.rs:68:13 | LL | mut_ref(&mut x); | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:74:13 + --> tests/ui/needless_borrow.rs:70:13 | LL | mut_ref(&mut &mut x); | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:76:23 + --> tests/ui/needless_borrow.rs:72:23 | LL | let y: &mut i32 = &mut x; | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:78:23 + --> tests/ui/needless_borrow.rs:74:23 | LL | let y: &mut i32 = &mut &mut x; | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:88:14 + --> tests/ui/needless_borrow.rs:84:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:95:14 + --> tests/ui/needless_borrow.rs:91:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:108:13 + --> tests/ui/needless_borrow.rs:104:13 | LL | let _ = (&x).0; | ^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:119:5 + --> tests/ui/needless_borrow.rs:115:5 | LL | (&&()).foo(); | ^^^^^^ help: change this to: `(&())` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:129:5 + --> tests/ui/needless_borrow.rs:125:5 | LL | (&&5).foo(); | ^^^^^ help: change this to: `(&5)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:156:23 + --> tests/ui/needless_borrow.rs:152:23 | LL | let x: (&str,) = (&"",); | ^^^ help: change this to: `""` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:199:13 + --> tests/ui/needless_borrow.rs:195:13 | LL | (&self.f)() | ^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:209:13 + --> tests/ui/needless_borrow.rs:205:13 | LL | (&mut self.f)() | ^^^^^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:247:22 + --> tests/ui/needless_borrow.rs:243:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:255:22 + --> tests/ui/needless_borrow.rs:251:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:260:22 + --> tests/ui/needless_borrow.rs:256:22 | LL | let _ = &mut (&mut x.u).x; | ^^^^^^^^^^ help: change this to: `x.u` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:262:22 + --> tests/ui/needless_borrow.rs:258:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:284:23 + --> tests/ui/needless_borrow.rs:280:23 | LL | option.unwrap_or((&x.0,)); | ^^^^ help: change this to: `x.0` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:291:13 + --> tests/ui/needless_borrow.rs:287:13 | LL | let _ = (&slice).len(); | ^^^^^^^^ help: change this to: `slice` diff --git a/tests/ui/needless_borrow_pat.fixed b/tests/ui/needless_borrow_pat.fixed index 507186676c160..741283a755aa4 100644 --- a/tests/ui/needless_borrow_pat.fixed +++ b/tests/ui/needless_borrow_pat.fixed @@ -1,5 +1,6 @@ #![warn(clippy::needless_borrow)] -#![allow(clippy::needless_borrowed_reference, clippy::explicit_auto_deref)] +#![allow(clippy::needless_borrowed_reference)] +#![expect(clippy::explicit_auto_deref)] fn f1(_: &str) {} macro_rules! m1 { @@ -30,7 +31,6 @@ macro_rules! if_chain { }; } -#[allow(dead_code)] fn main() { let x = String::new(); @@ -160,7 +160,6 @@ impl T1 for S { } // Ok - used to error due to rustc bug -#[allow(dead_code)] #[derive(Debug)] enum Foo<'a> { Str(&'a str), diff --git a/tests/ui/needless_borrow_pat.rs b/tests/ui/needless_borrow_pat.rs index ef0f97301bcf2..b5b3f8b4cc30c 100644 --- a/tests/ui/needless_borrow_pat.rs +++ b/tests/ui/needless_borrow_pat.rs @@ -1,5 +1,6 @@ #![warn(clippy::needless_borrow)] -#![allow(clippy::needless_borrowed_reference, clippy::explicit_auto_deref)] +#![allow(clippy::needless_borrowed_reference)] +#![expect(clippy::explicit_auto_deref)] fn f1(_: &str) {} macro_rules! m1 { @@ -30,7 +31,6 @@ macro_rules! if_chain { }; } -#[allow(dead_code)] fn main() { let x = String::new(); @@ -160,7 +160,6 @@ impl T1 for S { } // Ok - used to error due to rustc bug -#[allow(dead_code)] #[derive(Debug)] enum Foo<'a> { Str(&'a str), diff --git a/tests/ui/needless_borrowed_ref.fixed b/tests/ui/needless_borrowed_ref.fixed index 94f8011185830..0db5ae5dbe54c 100644 --- a/tests/ui/needless_borrowed_ref.fixed +++ b/tests/ui/needless_borrowed_ref.fixed @@ -1,10 +1,8 @@ #![warn(clippy::needless_borrowed_reference)] -#![allow( - unused, +#![expect( irrefutable_let_patterns, non_shorthand_field_patterns, clippy::needless_borrow, - clippy::needless_ifs, clippy::unneeded_wildcard_pattern )] diff --git a/tests/ui/needless_borrowed_ref.rs b/tests/ui/needless_borrowed_ref.rs index 77334e07b25e4..95dcd1bbc7312 100644 --- a/tests/ui/needless_borrowed_ref.rs +++ b/tests/ui/needless_borrowed_ref.rs @@ -1,10 +1,8 @@ #![warn(clippy::needless_borrowed_reference)] -#![allow( - unused, +#![expect( irrefutable_let_patterns, non_shorthand_field_patterns, clippy::needless_borrow, - clippy::needless_ifs, clippy::unneeded_wildcard_pattern )] diff --git a/tests/ui/needless_borrowed_ref.stderr b/tests/ui/needless_borrowed_ref.stderr index f29789c66334a..980022715628d 100644 --- a/tests/ui/needless_borrowed_ref.stderr +++ b/tests/ui/needless_borrowed_ref.stderr @@ -1,5 +1,5 @@ error: this pattern takes a reference on something that is being dereferenced - --> tests/ui/needless_borrowed_ref.rs:31:34 + --> tests/ui/needless_borrowed_ref.rs:29:34 | LL | let _ = v.iter_mut().filter(|&ref a| a.is_empty()); | ^^^^^^ @@ -13,7 +13,7 @@ LL + let _ = v.iter_mut().filter(|a| a.is_empty()); | error: this pattern takes a reference on something that is being dereferenced - --> tests/ui/needless_borrowed_ref.rs:36:17 + --> tests/ui/needless_borrowed_ref.rs:34:17 | LL | if let Some(&ref v) = thingy {} | ^^^^^^ @@ -25,7 +25,7 @@ LL + if let Some(v) = thingy {} | error: this pattern takes a reference on something that is being dereferenced - --> tests/ui/needless_borrowed_ref.rs:39:14 + --> tests/ui/needless_borrowed_ref.rs:37:14 | LL | if let &[&ref a, ref b] = slice_of_refs {} | ^^^^^^ @@ -37,7 +37,7 @@ LL + if let &[a, ref b] = slice_of_refs {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:42:9 + --> tests/ui/needless_borrowed_ref.rs:40:9 | LL | let &[ref a, ..] = &array; | ^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + let [a, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:44:9 + --> tests/ui/needless_borrowed_ref.rs:42:9 | LL | let &[ref a, ref b, ..] = &array; | ^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let [a, b, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:47:12 + --> tests/ui/needless_borrowed_ref.rs:45:12 | LL | if let &[ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + if let [a, b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:49:12 + --> tests/ui/needless_borrowed_ref.rs:47:12 | LL | if let &[ref a, ref b] = &vec[..] {} | ^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + if let [a, b] = &vec[..] {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:52:12 + --> tests/ui/needless_borrowed_ref.rs:50:12 | LL | if let &[ref a, ref b, ..] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + if let [a, b, ..] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:54:12 + --> tests/ui/needless_borrowed_ref.rs:52:12 | LL | if let &[ref a, .., ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + if let [a, .., b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:56:12 + --> tests/ui/needless_borrowed_ref.rs:54:12 | LL | if let &[.., ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + if let [.., a, b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:59:12 + --> tests/ui/needless_borrowed_ref.rs:57:12 | LL | if let &[ref a, _] = slice {} | ^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + if let [a, _] = slice {} | error: dereferencing a tuple pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:62:12 + --> tests/ui/needless_borrowed_ref.rs:60:12 | LL | if let &(ref a, ref b, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + if let (a, b, c) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:64:12 + --> tests/ui/needless_borrowed_ref.rs:62:12 | LL | if let &(ref a, _, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + if let (a, _, c) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:66:12 + --> tests/ui/needless_borrowed_ref.rs:64:12 | LL | if let &(ref a, ..) = &tuple {} | ^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + if let (a, ..) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> tests/ui/needless_borrowed_ref.rs:69:12 + --> tests/ui/needless_borrowed_ref.rs:67:12 | LL | if let &TupleStruct(ref a, ..) = &tuple_struct {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + if let TupleStruct(a, ..) = &tuple_struct {} | error: dereferencing a struct pattern where every field's pattern takes a reference - --> tests/ui/needless_borrowed_ref.rs:72:12 + --> tests/ui/needless_borrowed_ref.rs:70:12 | LL | if let &Struct { | ____________^ @@ -202,7 +202,7 @@ LL ~ c: renamed, | error: dereferencing a struct pattern where every field's pattern takes a reference - --> tests/ui/needless_borrowed_ref.rs:80:12 + --> tests/ui/needless_borrowed_ref.rs:78:12 | LL | if let &Struct { ref a, b: _, .. } = &s {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_borrows_for_generic_args.fixed b/tests/ui/needless_borrows_for_generic_args.fixed index 8dea0d259772e..dfa85b262390f 100644 --- a/tests/ui/needless_borrows_for_generic_args.fixed +++ b/tests/ui/needless_borrows_for_generic_args.fixed @@ -1,8 +1,8 @@ #![warn(clippy::needless_borrows_for_generic_args)] -#![allow( - clippy::unnecessary_to_owned, +#![expect( + clippy::needless_borrow, clippy::unnecessary_literal_unwrap, - clippy::needless_borrow + clippy::unnecessary_to_owned )] use core::ops::Deref; @@ -128,7 +128,6 @@ fn main() { fn dont_warn(mut x: Iter) { takes_iter(&mut x); } - #[allow(unused_mut)] fn warn(mut x: &mut Iter) { takes_iter(x) //~^ needless_borrows_for_generic_args diff --git a/tests/ui/needless_borrows_for_generic_args.rs b/tests/ui/needless_borrows_for_generic_args.rs index bc2db6774e963..5ef3d732bf73f 100644 --- a/tests/ui/needless_borrows_for_generic_args.rs +++ b/tests/ui/needless_borrows_for_generic_args.rs @@ -1,8 +1,8 @@ #![warn(clippy::needless_borrows_for_generic_args)] -#![allow( - clippy::unnecessary_to_owned, +#![expect( + clippy::needless_borrow, clippy::unnecessary_literal_unwrap, - clippy::needless_borrow + clippy::unnecessary_to_owned )] use core::ops::Deref; @@ -128,7 +128,6 @@ fn main() { fn dont_warn(mut x: Iter) { takes_iter(&mut x); } - #[allow(unused_mut)] fn warn(mut x: &mut Iter) { takes_iter(&mut x) //~^ needless_borrows_for_generic_args diff --git a/tests/ui/needless_borrows_for_generic_args.stderr b/tests/ui/needless_borrows_for_generic_args.stderr index 8829854e30739..5f7a14ade2617 100644 --- a/tests/ui/needless_borrows_for_generic_args.stderr +++ b/tests/ui/needless_borrows_for_generic_args.stderr @@ -38,31 +38,31 @@ LL | multiple_constraints_normalizes_to_same(&X, X); | ^^ help: change this to: `X` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:133:24 + --> tests/ui/needless_borrows_for_generic_args.rs:132:24 | LL | takes_iter(&mut x) | ^^^^^^ help: change this to: `x` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:143:41 + --> tests/ui/needless_borrows_for_generic_args.rs:142:41 | LL | let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); | ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:255:13 + --> tests/ui/needless_borrows_for_generic_args.rs:254:13 | LL | foo(&a); | ^^ help: change this to: `a` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:340:11 + --> tests/ui/needless_borrows_for_generic_args.rs:339:11 | LL | f(&String::new()); // Lint, makes no difference | ^^^^^^^^^^^^^^ help: change this to: `String::new()` error: the borrowed expression implements the required traits - --> tests/ui/needless_borrows_for_generic_args.rs:345:11 + --> tests/ui/needless_borrows_for_generic_args.rs:344:11 | LL | f(&"".to_owned()); // Lint | ^^^^^^^^^^^^^^ help: change this to: `"".to_owned()` diff --git a/tests/ui/needless_character_iteration.fixed b/tests/ui/needless_character_iteration.fixed index e25db9bb590f7..b75020894ce5d 100644 --- a/tests/ui/needless_character_iteration.fixed +++ b/tests/ui/needless_character_iteration.fixed @@ -1,5 +1,6 @@ #![warn(clippy::needless_character_iteration)] -#![allow(clippy::map_identity, clippy::unnecessary_operation)] +#![allow(clippy::unnecessary_operation)] +#![expect(clippy::map_identity)] #[derive(Default)] struct S { diff --git a/tests/ui/needless_character_iteration.rs b/tests/ui/needless_character_iteration.rs index 9b184dab6bc82..df2f9f34f5927 100644 --- a/tests/ui/needless_character_iteration.rs +++ b/tests/ui/needless_character_iteration.rs @@ -1,5 +1,6 @@ #![warn(clippy::needless_character_iteration)] -#![allow(clippy::map_identity, clippy::unnecessary_operation)] +#![allow(clippy::unnecessary_operation)] +#![expect(clippy::map_identity)] #[derive(Default)] struct S { diff --git a/tests/ui/needless_character_iteration.stderr b/tests/ui/needless_character_iteration.stderr index 9954049966444..3cdf9de012e9f 100644 --- a/tests/ui/needless_character_iteration.stderr +++ b/tests/ui/needless_character_iteration.stderr @@ -1,5 +1,5 @@ error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:18:5 + --> tests/ui/needless_character_iteration.rs:19:5 | LL | "foo".chars().all(|c| c.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"foo".is_ascii()` @@ -8,37 +8,37 @@ LL | "foo".chars().all(|c| c.is_ascii()); = help: to override `-D warnings` add `#[allow(clippy::needless_character_iteration)]` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:21:5 + --> tests/ui/needless_character_iteration.rs:22:5 | LL | "foo".chars().any(|c| !c.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:24:5 + --> tests/ui/needless_character_iteration.rs:25:5 | LL | "foo".chars().all(|c| char::is_ascii(&c)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:27:5 + --> tests/ui/needless_character_iteration.rs:28:5 | LL | "foo".chars().any(|c| !char::is_ascii(&c)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:31:5 + --> tests/ui/needless_character_iteration.rs:32:5 | LL | s.chars().all(|c| c.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:34:5 + --> tests/ui/needless_character_iteration.rs:35:5 | LL | "foo".to_string().chars().any(|c| !c.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!"foo".to_string().is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:37:5 + --> tests/ui/needless_character_iteration.rs:38:5 | LL | / "foo".chars().all(|c| { LL | | @@ -49,7 +49,7 @@ LL | | }); | |______^ help: try: `"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:43:5 + --> tests/ui/needless_character_iteration.rs:44:5 | LL | / "foo".chars().any(|c| { LL | | @@ -60,7 +60,7 @@ LL | | }); | |______^ help: try: `!"foo".is_ascii()` error: checking if a string is ascii using iterators - --> tests/ui/needless_character_iteration.rs:50:5 + --> tests/ui/needless_character_iteration.rs:51:5 | LL | S::default().field().chars().all(|x| x.is_ascii()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `S::default().field().is_ascii()` diff --git a/tests/ui/needless_collect.fixed b/tests/ui/needless_collect.fixed index 2d59c1d42b051..ca25395e375bc 100644 --- a/tests/ui/needless_collect.fixed +++ b/tests/ui/needless_collect.fixed @@ -1,15 +1,8 @@ -#![allow( - unused, - clippy::needless_ifs, - clippy::suspicious_map, - clippy::iter_count, - clippy::manual_contains -)] +#![warn(clippy::needless_collect)] +#![allow(clippy::iter_cloned_collect, clippy::iter_next_slice)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList}; -#[warn(clippy::needless_collect)] -#[allow(unused_variables, clippy::iter_cloned_collect, clippy::iter_next_slice)] fn main() { let sample = [1; 5]; let len = sample.iter().count(); @@ -205,6 +198,10 @@ mod issue8055_regression { } } + #[expect( + clippy::needless_collect, + reason = "FIXME: proposed fix cannot determine type, see issue #17315" + )] fn foo() { Foo { inner: [].iter(), @@ -220,7 +217,6 @@ fn issue16270() { _ = &(1..3).collect::>()[..]; } -#[warn(clippy::needless_collect)] mod collect_push_then_iter { use std::collections::{BinaryHeap, LinkedList, VecDeque}; diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs index 346cddd88e703..4fafa2e9adf6b 100644 --- a/tests/ui/needless_collect.rs +++ b/tests/ui/needless_collect.rs @@ -1,15 +1,8 @@ -#![allow( - unused, - clippy::needless_ifs, - clippy::suspicious_map, - clippy::iter_count, - clippy::manual_contains -)] +#![warn(clippy::needless_collect)] +#![allow(clippy::iter_cloned_collect, clippy::iter_next_slice)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList}; -#[warn(clippy::needless_collect)] -#[allow(unused_variables, clippy::iter_cloned_collect, clippy::iter_next_slice)] fn main() { let sample = [1; 5]; let len = sample.iter().collect::>().len(); @@ -205,6 +198,10 @@ mod issue8055_regression { } } + #[expect( + clippy::needless_collect, + reason = "FIXME: proposed fix cannot determine type, see issue #17315" + )] fn foo() { Foo { inner: [].iter(), @@ -220,7 +217,6 @@ fn issue16270() { _ = &(1..3).collect::>()[..]; } -#[warn(clippy::needless_collect)] mod collect_push_then_iter { use std::collections::{BinaryHeap, LinkedList, VecDeque}; diff --git a/tests/ui/needless_collect.stderr b/tests/ui/needless_collect.stderr index b10312224c8ef..402a1fd19a7c7 100644 --- a/tests/ui/needless_collect.stderr +++ b/tests/ui/needless_collect.stderr @@ -1,5 +1,5 @@ error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:15:29 + --> tests/ui/needless_collect.rs:8:29 | LL | let len = sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` @@ -8,121 +8,121 @@ LL | let len = sample.iter().collect::>().len(); = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:17:22 + --> tests/ui/needless_collect.rs:10:22 | LL | if sample.iter().collect::>().is_empty() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:21:28 + --> tests/ui/needless_collect.rs:14:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:24:36 + --> tests/ui/needless_collect.rs:17:36 | LL | let _ = sample.iter().cloned().collect::>()[1]; | ^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `nth(1).unwrap()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:31:35 + --> tests/ui/needless_collect.rs:24:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:33:35 + --> tests/ui/needless_collect.rs:26:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:41:19 + --> tests/ui/needless_collect.rs:34:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:43:19 + --> tests/ui/needless_collect.rs:36:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:45:28 + --> tests/ui/needless_collect.rs:38:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:47:19 + --> tests/ui/needless_collect.rs:40:19 | LL | sample.iter().collect::>().contains(&&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &1)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:51:19 + --> tests/ui/needless_collect.rs:44:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:53:19 + --> tests/ui/needless_collect.rs:46:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:59:27 + --> tests/ui/needless_collect.rs:52:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:61:27 + --> tests/ui/needless_collect.rs:54:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:84:27 + --> tests/ui/needless_collect.rs:77:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:86:27 + --> tests/ui/needless_collect.rs:79:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:91:40 + --> tests/ui/needless_collect.rs:84:40 | LL | Vec::::new().extend((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:93:20 + --> tests/ui/needless_collect.rs:86:20 | LL | foo((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:95:49 + --> tests/ui/needless_collect.rs:88:49 | LL | bar((0..10).collect::>(), (0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:97:37 + --> tests/ui/needless_collect.rs:90:37 | LL | baz((0..10), (), ('a'..='z').collect::>()) | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:228:26 + --> tests/ui/needless_collect.rs:224:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ @@ -139,7 +139,7 @@ LL ~ iter.chain([1]).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:240:26 + --> tests/ui/needless_collect.rs:236:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ @@ -157,7 +157,7 @@ LL ~ iter.chain([1, 2]).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:248:26 + --> tests/ui/needless_collect.rs:244:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ @@ -174,7 +174,7 @@ LL ~ iter.chain([1]).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:268:27 + --> tests/ui/needless_collect.rs:264:27 | LL | let mut ll = iter.collect::>(); | ^^^^^^^ @@ -191,7 +191,7 @@ LL ~ iter.chain(s).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:275:26 + --> tests/ui/needless_collect.rs:271:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ @@ -209,7 +209,7 @@ LL ~ [1, 2].into_iter().chain(iter).map(|x| x + 1).collect() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect.rs:286:26 + --> tests/ui/needless_collect.rs:282:26 | LL | let mut v = iter.collect::>(); | ^^^^^^^ diff --git a/tests/ui/needless_collect_indirect.fixed b/tests/ui/needless_collect_indirect.fixed index 22b9bb6f6a20a..45104c34f7782 100644 --- a/tests/ui/needless_collect_indirect.fixed +++ b/tests/ui/needless_collect_indirect.fixed @@ -1,11 +1,6 @@ -#![allow( - clippy::uninlined_format_args, - clippy::useless_vec, - clippy::needless_ifs, - clippy::iter_next_slice, - clippy::iter_count -)] #![warn(clippy::needless_collect)] +#![allow(clippy::iter_count, clippy::iter_next_slice)] +#![expect(clippy::needless_ifs, clippy::useless_vec)] use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque}; diff --git a/tests/ui/needless_collect_indirect.rs b/tests/ui/needless_collect_indirect.rs index 20b7ae91a6b88..77ac9fe29ba5f 100644 --- a/tests/ui/needless_collect_indirect.rs +++ b/tests/ui/needless_collect_indirect.rs @@ -1,11 +1,6 @@ -#![allow( - clippy::uninlined_format_args, - clippy::useless_vec, - clippy::needless_ifs, - clippy::iter_next_slice, - clippy::iter_count -)] #![warn(clippy::needless_collect)] +#![allow(clippy::iter_count, clippy::iter_next_slice)] +#![expect(clippy::needless_ifs, clippy::useless_vec)] 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 d34f1c37558dc..c7bf1b14df804 100644 --- a/tests/ui/needless_collect_indirect.stderr +++ b/tests/ui/needless_collect_indirect.stderr @@ -1,5 +1,5 @@ error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:14:39 + --> tests/ui/needless_collect_indirect.rs:9:39 | LL | let indirect_iter = sample.iter().collect::>(); | ^^^^^^^ @@ -18,7 +18,7 @@ LL ~ sample.iter().map(|x| (x, x + 1)).collect::>(); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:18:38 + --> tests/ui/needless_collect_indirect.rs:13:38 | LL | let indirect_len = sample.iter().collect::>(); | ^^^^^^^ @@ -35,7 +35,7 @@ LL ~ sample.iter().count(); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:22:40 + --> tests/ui/needless_collect_indirect.rs:17:40 | LL | let indirect_empty = sample.iter().collect::>(); | ^^^^^^^ @@ -52,7 +52,7 @@ LL ~ sample.iter().next().is_none(); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:26:43 + --> tests/ui/needless_collect_indirect.rs:21:43 | LL | let indirect_contains = sample.iter().collect::>(); | ^^^^^^^ @@ -69,7 +69,7 @@ LL ~ sample.iter().any(|x| x == &5); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:40:48 + --> tests/ui/needless_collect_indirect.rs:35:48 | LL | let non_copy_contains = sample.into_iter().collect::>(); | ^^^^^^^ @@ -86,7 +86,7 @@ LL ~ sample.into_iter().any(|x| x == a); | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:71:51 + --> tests/ui/needless_collect_indirect.rs:66:51 | LL | let buffer: Vec<&str> = string.split('/').collect(); | ^^^^^^^ @@ -103,7 +103,7 @@ LL ~ string.split('/').count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:78:55 + --> tests/ui/needless_collect_indirect.rs:73:55 | LL | let indirect_len: VecDeque<_> = sample.iter().collect(); | ^^^^^^^ @@ -120,7 +120,7 @@ LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:85:57 + --> tests/ui/needless_collect_indirect.rs:80:57 | LL | let indirect_len: LinkedList<_> = sample.iter().collect(); | ^^^^^^^ @@ -137,7 +137,7 @@ LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:92:57 + --> tests/ui/needless_collect_indirect.rs:87:57 | LL | let indirect_len: BinaryHeap<_> = sample.iter().collect(); | ^^^^^^^ @@ -154,7 +154,7 @@ LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:154:59 + --> tests/ui/needless_collect_indirect.rs:149:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -172,7 +172,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:181:59 + --> tests/ui/needless_collect_indirect.rs:176:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -190,7 +190,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:212:63 + --> tests/ui/needless_collect_indirect.rs:207:63 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -208,7 +208,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:250:59 + --> tests/ui/needless_collect_indirect.rs:245:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -226,7 +226,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:277:26 + --> tests/ui/needless_collect_indirect.rs:272:26 | LL | let w = v.iter().collect::>(); | ^^^^^^^ @@ -244,7 +244,7 @@ LL ~ for _ in 0..v.iter().count() { | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:301:30 + --> tests/ui/needless_collect_indirect.rs:296:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ @@ -262,7 +262,7 @@ LL ~ while 1 == v.iter().count() { | error: avoid using `collect()` when not needed - --> tests/ui/needless_collect_indirect.rs:325:30 + --> tests/ui/needless_collect_indirect.rs:320:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index 3275dddf1a0f4..a8bd2cdcb4a72 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -1,5 +1,5 @@ #![warn(clippy::needless_continue)] -#![allow(clippy::uninlined_format_args)] +#![expect(clippy::uninlined_format_args)] macro_rules! zero { ($x:expr) => { diff --git a/tests/ui/needless_else.fixed b/tests/ui/needless_else.fixed index 0455910c3ee8c..6a9cca8f7c14c 100644 --- a/tests/ui/needless_else.fixed +++ b/tests/ui/needless_else.fixed @@ -1,6 +1,4 @@ -#![allow(unused)] #![warn(clippy::needless_else)] -#![allow(clippy::suspicious_else_formatting)] macro_rules! mac { ($test:expr) => { diff --git a/tests/ui/needless_else.rs b/tests/ui/needless_else.rs index 236ac631a49e5..968ca590e8f0e 100644 --- a/tests/ui/needless_else.rs +++ b/tests/ui/needless_else.rs @@ -1,6 +1,4 @@ -#![allow(unused)] #![warn(clippy::needless_else)] -#![allow(clippy::suspicious_else_formatting)] macro_rules! mac { ($test:expr) => { diff --git a/tests/ui/needless_else.stderr b/tests/ui/needless_else.stderr index 77ead31b31cc9..0b43ca4785257 100644 --- a/tests/ui/needless_else.stderr +++ b/tests/ui/needless_else.stderr @@ -1,5 +1,5 @@ error: this `else` branch is empty - --> tests/ui/needless_else.rs:23:7 + --> tests/ui/needless_else.rs:21:7 | LL | } else { | _______^ diff --git a/tests/ui/needless_for_each_fixable.fixed b/tests/ui/needless_for_each_fixable.fixed index 19b34f42af244..d6c7e42e13d32 100644 --- a/tests/ui/needless_for_each_fixable.fixed +++ b/tests/ui/needless_for_each_fixable.fixed @@ -1,6 +1,5 @@ #![warn(clippy::needless_for_each)] -#![allow(unused)] -#![allow( +#![expect( clippy::let_unit_value, clippy::match_single_binding, clippy::needless_return, diff --git a/tests/ui/needless_for_each_fixable.rs b/tests/ui/needless_for_each_fixable.rs index f04e2555a3702..9bb2e6cf07d24 100644 --- a/tests/ui/needless_for_each_fixable.rs +++ b/tests/ui/needless_for_each_fixable.rs @@ -1,6 +1,5 @@ #![warn(clippy::needless_for_each)] -#![allow(unused)] -#![allow( +#![expect( clippy::let_unit_value, clippy::match_single_binding, clippy::needless_return, diff --git a/tests/ui/needless_for_each_fixable.stderr b/tests/ui/needless_for_each_fixable.stderr index 121669d15072f..26d0da69c8559 100644 --- a/tests/ui/needless_for_each_fixable.stderr +++ b/tests/ui/needless_for_each_fixable.stderr @@ -1,5 +1,5 @@ error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:15:5 + --> tests/ui/needless_for_each_fixable.rs:14:5 | LL | / v.iter().for_each(|elem| { LL | | @@ -18,7 +18,7 @@ LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:19:5 + --> tests/ui/needless_for_each_fixable.rs:18:5 | LL | / v.into_iter().for_each(|elem| { LL | | @@ -35,7 +35,7 @@ LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:24:5 + --> tests/ui/needless_for_each_fixable.rs:23:5 | LL | / [1, 2, 3].iter().for_each(|elem| { LL | | @@ -52,7 +52,7 @@ LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:30:5 + --> tests/ui/needless_for_each_fixable.rs:29:5 | LL | / hash_map.iter().for_each(|(k, v)| { LL | | @@ -69,7 +69,7 @@ LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:34:5 + --> tests/ui/needless_for_each_fixable.rs:33:5 | LL | / hash_map.iter_mut().for_each(|(k, v)| { LL | | @@ -86,7 +86,7 @@ LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:38:5 + --> tests/ui/needless_for_each_fixable.rs:37:5 | LL | / hash_map.keys().for_each(|k| { LL | | @@ -103,7 +103,7 @@ LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:42:5 + --> tests/ui/needless_for_each_fixable.rs:41:5 | LL | / hash_map.values().for_each(|v| { LL | | @@ -120,7 +120,7 @@ LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:50:5 + --> tests/ui/needless_for_each_fixable.rs:49:5 | LL | / my_vec().iter().for_each(|elem| { LL | | @@ -137,25 +137,25 @@ LL + } | error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:135:9 + --> tests/ui/needless_for_each_fixable.rs:134:9 | LL | rows.iter().for_each(|x| _ = v.push(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in rows.iter() { _ = v.push(x) }` error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:142:9 + --> tests/ui/needless_for_each_fixable.rs:141:9 | LL | rows.iter().for_each(|x| do_something(x, 1u8)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in rows.iter() { do_something(x, 1u8); }` error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:149:5 + --> tests/ui/needless_for_each_fixable.rs:148:5 | LL | vec.iter().for_each(|v| println!("{v}")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for v in vec.iter() { println!("{v}"); }` error: needless use of `for_each` - --> tests/ui/needless_for_each_fixable.rs:155:5 + --> tests/ui/needless_for_each_fixable.rs:154:5 | LL | / vec.iter().for_each(|elem| { LL | | diff --git a/tests/ui/needless_for_each_unfixable.rs b/tests/ui/needless_for_each_unfixable.rs index 24ce5786b9104..1a7d0dba5f182 100644 --- a/tests/ui/needless_for_each_unfixable.rs +++ b/tests/ui/needless_for_each_unfixable.rs @@ -1,6 +1,6 @@ //@no-rustfix: overlapping suggestions #![warn(clippy::needless_for_each)] -#![allow(clippy::needless_return)] +#![expect(clippy::needless_return)] fn main() { let v: Vec = Vec::new(); diff --git a/tests/ui/needless_ifs.fixed b/tests/ui/needless_ifs.fixed index 89d5b1da7b3f0..a72c680fa7541 100644 --- a/tests/ui/needless_ifs.fixed +++ b/tests/ui/needless_ifs.fixed @@ -1,18 +1,17 @@ //@aux-build:proc_macros.rs +#![warn(clippy::needless_ifs)] #![allow( clippy::blocks_in_conditions, + clippy::no_effect, + clippy::short_circuit_statement, + clippy::unnecessary_operation +)] +#![expect( clippy::if_same_then_else, clippy::ifs_same_cond, - clippy::let_unit_value, clippy::needless_else, - clippy::no_effect, - clippy::nonminimal_bool, - clippy::short_circuit_statement, - clippy::unnecessary_operation, - clippy::redundant_pattern_matching, - unused + clippy::redundant_pattern_matching )] -#![warn(clippy::needless_ifs)] extern crate proc_macros; use proc_macros::{external, with_span}; @@ -97,8 +96,7 @@ fn main() { //~^ needless_ifs // Don't leave trailing attributes - #[allow(unused)] - true; + //~^ needless_ifs let () = if maybe_side_effect() {}; diff --git a/tests/ui/needless_ifs.rs b/tests/ui/needless_ifs.rs index 837eaaf9647b0..370d15a168f5c 100644 --- a/tests/ui/needless_ifs.rs +++ b/tests/ui/needless_ifs.rs @@ -1,18 +1,17 @@ //@aux-build:proc_macros.rs +#![warn(clippy::needless_ifs)] #![allow( clippy::blocks_in_conditions, + clippy::no_effect, + clippy::short_circuit_statement, + clippy::unnecessary_operation +)] +#![expect( clippy::if_same_then_else, clippy::ifs_same_cond, - clippy::let_unit_value, clippy::needless_else, - clippy::no_effect, - clippy::nonminimal_bool, - clippy::short_circuit_statement, - clippy::unnecessary_operation, - clippy::redundant_pattern_matching, - unused + clippy::redundant_pattern_matching )] -#![warn(clippy::needless_ifs)] extern crate proc_macros; use proc_macros::{external, with_span}; @@ -98,7 +97,6 @@ fn main() { //~^ needless_ifs // Don't leave trailing attributes - #[allow(unused)] if true {} //~^ needless_ifs diff --git a/tests/ui/needless_ifs.stderr b/tests/ui/needless_ifs.stderr index 7c7fcdc183668..8cd812dc3f37e 100644 --- a/tests/ui/needless_ifs.stderr +++ b/tests/ui/needless_ifs.stderr @@ -1,5 +1,5 @@ error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:25:5 + --> tests/ui/needless_ifs.rs:24:5 | LL | if (true) {} | ^^^^^^^^^^^^ help: you can remove it @@ -8,13 +8,13 @@ LL | if (true) {} = help: to override `-D warnings` add `#[allow(clippy::needless_ifs)]` error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:28:5 + --> tests/ui/needless_ifs.rs:27:5 | LL | if maybe_side_effect() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `maybe_side_effect();` error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:34:5 + --> tests/ui/needless_ifs.rs:33:5 | LL | / if { LL | | @@ -31,7 +31,7 @@ LL + }); | error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:49:5 + --> tests/ui/needless_ifs.rs:48:5 | LL | / if { LL | | @@ -57,37 +57,37 @@ LL + } && true); | error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:94:5 + --> tests/ui/needless_ifs.rs:93:5 | LL | if { maybe_side_effect() } {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() });` error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:97:5 + --> tests/ui/needless_ifs.rs:96:5 | LL | if { maybe_side_effect() } && true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() } && true);` error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:102:5 + --> tests/ui/needless_ifs.rs:100:5 | LL | if true {} - | ^^^^^^^^^^ help: you can remove it: `true;` + | ^^^^^^^^^^ help: you can remove it error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:109:5 + --> tests/ui/needless_ifs.rs:107:5 | LL | if matches!(2, 3) {} | ^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `matches!(2, 3);` error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:111:5 + --> tests/ui/needless_ifs.rs:109:5 | LL | if matches!(2, 3) == (2 * 2 == 5) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `matches!(2, 3) == (2 * 2 == 5);` error: this `if` branch is empty - --> tests/ui/needless_ifs.rs:121:5 + --> tests/ui/needless_ifs.rs:119:5 | LL | if true {␋} | ^^^^^^^^^^^ help: you can remove it diff --git a/tests/ui/needless_late_init.fixed b/tests/ui/needless_late_init.fixed index a5c9d435b3eea..4a39b4465ea1b 100644 --- a/tests/ui/needless_late_init.fixed +++ b/tests/ui/needless_late_init.fixed @@ -1,13 +1,7 @@ //@aux-build:proc_macros.rs -#![allow( - clippy::assign_op_pattern, - clippy::blocks_in_conditions, - clippy::let_and_return, - clippy::let_unit_value, - clippy::nonminimal_bool, - clippy::uninlined_format_args, - clippy::useless_vec -)] +#![warn(clippy::needless_late_init)] +#![allow(clippy::let_and_return)] +#![expect(clippy::blocks_in_conditions, clippy::let_unit_value, clippy::useless_vec)] extern crate proc_macros; diff --git a/tests/ui/needless_late_init.rs b/tests/ui/needless_late_init.rs index ee413814750c7..0d975acd5dbd0 100644 --- a/tests/ui/needless_late_init.rs +++ b/tests/ui/needless_late_init.rs @@ -1,13 +1,7 @@ //@aux-build:proc_macros.rs -#![allow( - clippy::assign_op_pattern, - clippy::blocks_in_conditions, - clippy::let_and_return, - clippy::let_unit_value, - clippy::nonminimal_bool, - clippy::uninlined_format_args, - clippy::useless_vec -)] +#![warn(clippy::needless_late_init)] +#![allow(clippy::let_and_return)] +#![expect(clippy::blocks_in_conditions, clippy::let_unit_value, clippy::useless_vec)] extern crate proc_macros; diff --git a/tests/ui/needless_late_init.stderr b/tests/ui/needless_late_init.stderr index 12bfc029d9488..d2976db7c806d 100644 --- a/tests/ui/needless_late_init.stderr +++ b/tests/ui/needless_late_init.stderr @@ -1,5 +1,5 @@ error: unneeded late initialization - --> tests/ui/needless_late_init.rs:25:5 + --> tests/ui/needless_late_init.rs:19:5 | LL | let a; | ^^^^^^ created here @@ -17,7 +17,7 @@ LL ~ let a = "zero"; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:29:5 + --> tests/ui/needless_late_init.rs:23:5 | LL | let b; | ^^^^^^ created here @@ -35,7 +35,7 @@ LL ~ let b = 1; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:31:5 + --> tests/ui/needless_late_init.rs:25:5 | LL | let c; | ^^^^^^ created here @@ -52,7 +52,7 @@ LL ~ let c = 2; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:36:5 + --> tests/ui/needless_late_init.rs:30:5 | LL | let d: usize; | ^^^^^^^^^^^^^ created here @@ -68,7 +68,7 @@ LL ~ let d: usize = 1; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:40:5 + --> tests/ui/needless_late_init.rs:34:5 | LL | let e; | ^^^^^^ created here @@ -84,7 +84,7 @@ LL ~ let e = format!("{}", d); | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:46:5 + --> tests/ui/needless_late_init.rs:40:5 | LL | let a; | ^^^^^^ @@ -103,7 +103,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:56:5 + --> tests/ui/needless_late_init.rs:50:5 | LL | let b; | ^^^^^^ @@ -120,7 +120,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:64:5 + --> tests/ui/needless_late_init.rs:58:5 | LL | let d; | ^^^^^^ @@ -138,7 +138,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:73:5 + --> tests/ui/needless_late_init.rs:67:5 | LL | let e; | ^^^^^^ @@ -155,7 +155,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:81:5 + --> tests/ui/needless_late_init.rs:75:5 | LL | let f; | ^^^^^^ @@ -169,7 +169,7 @@ LL ~ 1 => "three", | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:88:5 + --> tests/ui/needless_late_init.rs:82:5 | LL | let g: usize; | ^^^^^^^^^^^^^ @@ -186,7 +186,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:97:5 + --> tests/ui/needless_late_init.rs:91:5 | LL | let x; | ^^^^^^ created here @@ -203,7 +203,7 @@ LL ~ let x = 1; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:102:5 + --> tests/ui/needless_late_init.rs:96:5 | LL | let x; | ^^^^^^ created here @@ -220,7 +220,7 @@ LL ~ let x = SignificantDrop; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:107:5 + --> tests/ui/needless_late_init.rs:101:5 | LL | let x; | ^^^^^^ created here @@ -238,7 +238,7 @@ LL ~ let x = SignificantDrop; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:127:5 + --> tests/ui/needless_late_init.rs:121:5 | LL | let a; | ^^^^^^ @@ -257,7 +257,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:145:5 + --> tests/ui/needless_late_init.rs:139:5 | LL | let a; | ^^^^^^ @@ -276,7 +276,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:199:5 + --> tests/ui/needless_late_init.rs:193:5 | LL | let x; | ^^^^^^ @@ -295,7 +295,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:190:5 + --> tests/ui/needless_late_init.rs:184:5 | LL | / if true { LL | | @@ -319,7 +319,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:299:5 + --> tests/ui/needless_late_init.rs:293:5 | LL | let r; | ^^^^^^ created here @@ -335,7 +335,7 @@ LL ~ let r = 5; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:305:5 + --> tests/ui/needless_late_init.rs:299:5 | LL | let z; | ^^^^^^ @@ -352,7 +352,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:455:5 + --> tests/ui/needless_late_init.rs:449:5 | LL | let c; | ^^^^^^ @@ -373,7 +373,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:318:5 + --> tests/ui/needless_late_init.rs:312:5 | LL | / if true { LL | | @@ -397,7 +397,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:361:5 + --> tests/ui/needless_late_init.rs:355:5 | LL | / match 1 { LL | | @@ -428,7 +428,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:384:5 + --> tests/ui/needless_late_init.rs:378:5 | LL | / if true { LL | | @@ -455,7 +455,7 @@ LL ~ }; | error: unneeded late initialization - --> tests/ui/needless_late_init.rs:470:5 + --> tests/ui/needless_late_init.rs:464:5 | LL | / if true { LL | | diff --git a/tests/ui/needless_lifetimes.fixed b/tests/ui/needless_lifetimes.fixed index 90a07454b4d75..b4d22dc37aca5 100644 --- a/tests/ui/needless_lifetimes.fixed +++ b/tests/ui/needless_lifetimes.fixed @@ -1,16 +1,13 @@ //@aux-build:proc_macros.rs -#![warn(clippy::needless_lifetimes, clippy::elidable_lifetime_names)] -#![allow( - unused, +#![warn(clippy::needless_lifetimes)] +#![deny(clippy::elidable_lifetime_names)] +#![allow(mismatched_lifetime_syntaxes)] +#![expect( + dyn_drop, clippy::boxed_local, clippy::extra_unused_type_parameters, - clippy::needless_pass_by_value, - clippy::redundant_allocation, - clippy::unnecessary_wraps, - dyn_drop, - clippy::get_first, - mismatched_lifetime_syntaxes + clippy::get_first )] extern crate proc_macros; @@ -428,7 +425,6 @@ mod issue7296 { } mod pr_9743_false_negative_fix { - #![allow(unused)] fn foo(x: &u8, y: &'_ u8) {} //~^ needless_lifetimes @@ -438,7 +434,6 @@ mod pr_9743_false_negative_fix { } mod pr_9743_output_lifetime_checks { - #![allow(unused)] // lint: only one input fn one_input(x: &u8) -> &u8 { diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index 6df38897f42d8..a5a1b139d1e67 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -1,16 +1,13 @@ //@aux-build:proc_macros.rs -#![warn(clippy::needless_lifetimes, clippy::elidable_lifetime_names)] -#![allow( - unused, +#![warn(clippy::needless_lifetimes)] +#![deny(clippy::elidable_lifetime_names)] +#![allow(mismatched_lifetime_syntaxes)] +#![expect( + dyn_drop, clippy::boxed_local, clippy::extra_unused_type_parameters, - clippy::needless_pass_by_value, - clippy::redundant_allocation, - clippy::unnecessary_wraps, - dyn_drop, - clippy::get_first, - mismatched_lifetime_syntaxes + clippy::get_first )] extern crate proc_macros; @@ -428,7 +425,6 @@ mod issue7296 { } mod pr_9743_false_negative_fix { - #![allow(unused)] fn foo<'a>(x: &'a u8, y: &'_ u8) {} //~^ needless_lifetimes @@ -438,7 +434,6 @@ mod pr_9743_false_negative_fix { } mod pr_9743_output_lifetime_checks { - #![allow(unused)] // lint: only one input fn one_input<'a>(x: &'a u8) -> &'a u8 { diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index 138d0498c43e4..e71015cf166a1 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -1,5 +1,5 @@ error: the following explicit lifetimes could be elided: 'a, 'b - --> tests/ui/needless_lifetimes.rs:19:23 + --> tests/ui/needless_lifetimes.rs:16:23 | LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} | ^^ ^^ ^^ ^^ @@ -13,7 +13,7 @@ LL + fn distinct_lifetimes(_x: &u8, _y: &u8, _z: u8) {} | error: the following explicit lifetimes could be elided: 'a, 'b - --> tests/ui/needless_lifetimes.rs:22:24 + --> tests/ui/needless_lifetimes.rs:19:24 | LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} | ^^ ^^ ^^ ^^ @@ -25,7 +25,7 @@ LL + fn distinct_and_static(_x: &u8, _y: &u8, _z: &'static u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:33:15 + --> tests/ui/needless_lifetimes.rs:30:15 | LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { | ^^ ^^ ^^ @@ -37,7 +37,7 @@ LL + fn in_and_out(x: &u8, _y: u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'b - --> tests/ui/needless_lifetimes.rs:46:31 + --> tests/ui/needless_lifetimes.rs:43:31 | LL | fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { | ^^ ^^ @@ -49,7 +49,7 @@ LL + fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:54:27 + --> tests/ui/needless_lifetimes.rs:51:27 | LL | fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 { | ^^ ^^ @@ -61,7 +61,7 @@ LL + fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8 { | error: the following explicit lifetimes could be elided: 'b - --> tests/ui/needless_lifetimes.rs:72:26 + --> tests/ui/needless_lifetimes.rs:69:26 | LL | fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { | ^^ ^^ @@ -73,7 +73,7 @@ LL + fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:80:22 + --> tests/ui/needless_lifetimes.rs:77:22 | LL | fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> { | ^^ ^^ @@ -85,7 +85,7 @@ LL + fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:90:21 + --> tests/ui/needless_lifetimes.rs:87:21 | LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { | ^^ ^^ ^^ @@ -97,7 +97,7 @@ LL + fn deep_reference_3(x: &u8, _y: u8) -> Result<&u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:96:28 + --> tests/ui/needless_lifetimes.rs:93:28 | LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> | ^^ ^^ ^^ @@ -109,7 +109,7 @@ LL + fn where_clause_without_lt(x: &u8, _y: u8) -> Result<&u8, ()> | error: the following explicit lifetimes could be elided: 's - --> tests/ui/needless_lifetimes.rs:127:21 + --> tests/ui/needless_lifetimes.rs:124:21 | LL | fn self_and_out<'s>(&'s self) -> &'s u8 { | ^^ ^^ ^^ @@ -121,7 +121,7 @@ LL + fn self_and_out(&self) -> &u8 { | error: the following explicit lifetimes could be elided: 't - --> tests/ui/needless_lifetimes.rs:135:30 + --> tests/ui/needless_lifetimes.rs:132:30 | LL | fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { | ^^ ^^ @@ -133,7 +133,7 @@ LL + fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 { | error: the following explicit lifetimes could be elided: 's - --> tests/ui/needless_lifetimes.rs:143:26 + --> tests/ui/needless_lifetimes.rs:140:26 | LL | fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 { | ^^ ^^ @@ -145,7 +145,7 @@ LL + fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8 { | error: the following explicit lifetimes could be elided: 's, 't - --> tests/ui/needless_lifetimes.rs:148:29 + --> tests/ui/needless_lifetimes.rs:145:29 | LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} | ^^ ^^ ^^ ^^ @@ -157,7 +157,7 @@ LL + fn distinct_self_and_in(&self, _x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:172:21 + --> tests/ui/needless_lifetimes.rs:169:21 | LL | fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str { | ^^ ^^ @@ -169,7 +169,7 @@ LL + fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:188:22 + --> tests/ui/needless_lifetimes.rs:185:22 | LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { | ^^ ^^ ^^ @@ -181,7 +181,7 @@ LL + fn trait_obj_elided2(_arg: &dyn Drop) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:199:20 + --> tests/ui/needless_lifetimes.rs:196:20 | LL | fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str { | ^^ ^^ @@ -193,7 +193,7 @@ LL + fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:204:30 + --> tests/ui/needless_lifetimes.rs:201:30 | LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { | ^^ ^^ ^ @@ -205,7 +205,7 @@ LL + fn named_input_elided_output(_arg: &str) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:213:19 + --> tests/ui/needless_lifetimes.rs:210:19 | LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { | ^^ ^^ @@ -217,7 +217,7 @@ LL + fn trait_bound_ok>(_: &u8, _: T) { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:249:24 + --> tests/ui/needless_lifetimes.rs:246:24 | LL | fn needless_lt<'a>(x: &'a u8) {} | ^^ ^^ @@ -229,7 +229,7 @@ LL + fn needless_lt(x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:254:24 + --> tests/ui/needless_lifetimes.rs:251:24 | LL | fn needless_lt<'a>(_x: &'a u8) {} | ^^ ^^ @@ -241,7 +241,7 @@ LL + fn needless_lt(_x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:285:55 + --> tests/ui/needless_lifetimes.rs:282:55 | LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -253,7 +253,7 @@ LL + fn impl_trait_elidable_nested_anonymous_lifetimes(i: &i32, f: impl Fn(& | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:295:26 + --> tests/ui/needless_lifetimes.rs:292:26 | LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { | ^^ ^^ ^^ @@ -265,7 +265,7 @@ LL + fn generics_elidable &i32>(i: &i32, f: T) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:308:30 + --> tests/ui/needless_lifetimes.rs:305:30 | LL | fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32 | ^^ ^^ ^^ @@ -277,7 +277,7 @@ LL + fn where_clause_elidable(i: &i32, f: T) -> &i32 | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:324:28 + --> tests/ui/needless_lifetimes.rs:321:28 | LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -289,7 +289,7 @@ LL + fn pointer_fn_elidable(i: &i32, f: fn(&i32) -> &i32) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:338:28 + --> tests/ui/needless_lifetimes.rs:335:28 | LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { | ^^ ^^ @@ -301,7 +301,7 @@ LL + fn nested_fn_pointer_3(_: &i32) -> fn(fn(&i32) -> &i32) -> i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:342:28 + --> tests/ui/needless_lifetimes.rs:339:28 | LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { | ^^ ^^ @@ -313,7 +313,7 @@ LL + fn nested_fn_pointer_4(_: &i32) -> impl Fn(fn(&i32)) { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:365:21 + --> tests/ui/needless_lifetimes.rs:362:21 | LL | fn implicit<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -325,7 +325,7 @@ LL + fn implicit(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:369:25 + --> tests/ui/needless_lifetimes.rs:366:25 | LL | fn implicit_mut<'a>(&'a mut self) -> &'a () { | ^^ ^^ ^^ @@ -337,7 +337,7 @@ LL + fn implicit_mut(&mut self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:374:21 + --> tests/ui/needless_lifetimes.rs:371:21 | LL | fn explicit<'a>(self: &'a Arc) -> &'a () { | ^^ ^^ ^^ @@ -349,7 +349,7 @@ LL + fn explicit(self: &Arc) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:379:25 + --> tests/ui/needless_lifetimes.rs:376:25 | LL | fn explicit_mut<'a>(self: &'a mut Rc) -> &'a () { | ^^ ^^ ^^ @@ -361,7 +361,7 @@ LL + fn explicit_mut(self: &mut Rc) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:392:31 + --> tests/ui/needless_lifetimes.rs:389:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -373,7 +373,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:399:21 + --> tests/ui/needless_lifetimes.rs:396:21 | LL | fn implicit<'a>(&'a self) -> &'a (); | ^^ ^^ ^^ @@ -385,7 +385,7 @@ LL + fn implicit(&self) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:401:30 + --> tests/ui/needless_lifetimes.rs:398:30 | LL | fn implicit_provided<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -397,7 +397,7 @@ LL + fn implicit_provided(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:407:21 + --> tests/ui/needless_lifetimes.rs:404:21 | LL | fn explicit<'a>(self: &'a Arc) -> &'a (); | ^^ ^^ ^^ @@ -409,7 +409,7 @@ LL + fn explicit(self: &Arc) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:410:30 + --> tests/ui/needless_lifetimes.rs:407:30 | LL | fn explicit_provided<'a>(self: &'a Arc) -> &'a () { | ^^ ^^ ^^ @@ -421,7 +421,7 @@ LL + fn explicit_provided(self: &Arc) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:421:31 + --> tests/ui/needless_lifetimes.rs:418:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a (); | ^^ ^^ ^^ @@ -433,7 +433,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:423:40 + --> tests/ui/needless_lifetimes.rs:420:40 | LL | fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -445,7 +445,7 @@ LL + fn lifetime_elsewhere_provided(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:433:12 + --> tests/ui/needless_lifetimes.rs:429:12 | LL | fn foo<'a>(x: &'a u8, y: &'_ u8) {} | ^^ ^^ @@ -457,7 +457,7 @@ LL + fn foo(x: &u8, y: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:436:12 + --> tests/ui/needless_lifetimes.rs:432:12 | LL | fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {} | ^^ ^^ @@ -469,7 +469,7 @@ LL + fn bar(x: &u8, y: &'_ u8, z: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:444:18 + --> tests/ui/needless_lifetimes.rs:439:18 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ @@ -481,7 +481,7 @@ LL + fn one_input(x: &u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:450:42 + --> tests/ui/needless_lifetimes.rs:445:42 | LL | fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { | ^^ ^^ @@ -493,7 +493,7 @@ LL + fn multiple_inputs_output_not_elided<'b>(x: &u8, y: &'b u8, z: &'b u8) | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:467:22 + --> tests/ui/needless_lifetimes.rs:462:22 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ diff --git a/tests/ui/needless_match.fixed b/tests/ui/needless_match.fixed index 2d7b0fa2bb2c9..c4792c306e591 100644 --- a/tests/ui/needless_match.fixed +++ b/tests/ui/needless_match.fixed @@ -1,7 +1,5 @@ #![warn(clippy::needless_match)] -#![allow(clippy::manual_map, clippy::question_mark)] -#![allow(dead_code)] -#![allow(unused)] +#![expect(clippy::manual_map)] #[derive(Clone, Copy)] enum Simple { A, diff --git a/tests/ui/needless_match.rs b/tests/ui/needless_match.rs index 83e3e73feb6c5..92a4264025a35 100644 --- a/tests/ui/needless_match.rs +++ b/tests/ui/needless_match.rs @@ -1,7 +1,5 @@ #![warn(clippy::needless_match)] -#![allow(clippy::manual_map, clippy::question_mark)] -#![allow(dead_code)] -#![allow(unused)] +#![expect(clippy::manual_map)] #[derive(Clone, Copy)] enum Simple { A, diff --git a/tests/ui/needless_match.stderr b/tests/ui/needless_match.stderr index 5195ecdfa555e..b4ebd5a755a34 100644 --- a/tests/ui/needless_match.stderr +++ b/tests/ui/needless_match.stderr @@ -1,5 +1,5 @@ error: this match expression is unnecessary - --> tests/ui/needless_match.rs:15:18 + --> tests/ui/needless_match.rs:13:18 | LL | let _: i32 = match i { | __________________^ @@ -15,7 +15,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::needless_match)]` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:23:19 + --> tests/ui/needless_match.rs:21:19 | LL | let _: &str = match s { | ___________________^ @@ -27,7 +27,7 @@ LL | | }; | |_____^ help: replace it with: `s` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:33:21 + --> tests/ui/needless_match.rs:31:21 | LL | let _: Simple = match se { | _____________________^ @@ -40,7 +40,7 @@ LL | | }; | |_____^ help: replace it with: `se` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:56:26 + --> tests/ui/needless_match.rs:54:26 | LL | let _: Option = match x { | __________________________^ @@ -51,7 +51,7 @@ LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:73:31 + --> tests/ui/needless_match.rs:71:31 | LL | let _: Result = match Ok(1) { | _______________________________^ @@ -62,7 +62,7 @@ LL | | }; | |_____^ help: replace it with: `Ok(1)` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:78:31 + --> tests/ui/needless_match.rs:76:31 | LL | let _: Result = match func_ret_err(0_i32) { | _______________________________^ @@ -73,25 +73,25 @@ LL | | }; | |_____^ help: replace it with: `func_ret_err(0_i32)` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:92:13 + --> tests/ui/needless_match.rs:90:13 | LL | let _ = if let Some(a) = Some(1) { Some(a) } else { None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `Some(1)` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:128:31 + --> tests/ui/needless_match.rs:126:31 | LL | let _: Result = if let Err(e) = x { Err(e) } else { x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:130:31 + --> tests/ui/needless_match.rs:128:31 | LL | let _: Result = if let Ok(val) = x { Ok(val) } else { x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:138:21 + --> tests/ui/needless_match.rs:136:21 | LL | let _: Simple = if let Simple::A = x { | _____________________^ @@ -104,7 +104,7 @@ LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:178:26 + --> tests/ui/needless_match.rs:176:26 | LL | let _: Complex = match ce { | __________________________^ @@ -117,7 +117,7 @@ LL | | }; | |_________^ help: replace it with: `ce` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:263:17 + --> tests/ui/needless_match.rs:261:17 | LL | let _ = match e { | _________________^ @@ -128,7 +128,7 @@ LL | | }; | |_________^ help: replace it with: `e` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:270:17 + --> tests/ui/needless_match.rs:268:17 | LL | let _ = match e { | _________________^ @@ -140,7 +140,7 @@ LL | | }; | |_________^ help: replace it with: `e` error: this if-let expression is unnecessary - --> tests/ui/needless_match.rs:352:9 + --> tests/ui/needless_match.rs:350:9 | LL | / if let Some(num) = A { LL | | @@ -152,7 +152,7 @@ LL | | } | |_________^ help: replace it with: `A` error: this match expression is unnecessary - --> tests/ui/needless_match.rs:373:13 + --> tests/ui/needless_match.rs:371:13 | LL | let x = match t { | _____________^ diff --git a/tests/ui/needless_maybe_sized.fixed b/tests/ui/needless_maybe_sized.fixed index 92840a888ada5..807b88efbc8fe 100644 --- a/tests/ui/needless_maybe_sized.fixed +++ b/tests/ui/needless_maybe_sized.fixed @@ -1,7 +1,7 @@ //@aux-build:proc_macros.rs -#![allow(unused, clippy::multiple_bound_locations)] #![warn(clippy::needless_maybe_sized)] +#![allow(clippy::multiple_bound_locations)] extern crate proc_macros; use proc_macros::external; diff --git a/tests/ui/needless_maybe_sized.rs b/tests/ui/needless_maybe_sized.rs index 02242260af1fe..5c631f45fcb97 100644 --- a/tests/ui/needless_maybe_sized.rs +++ b/tests/ui/needless_maybe_sized.rs @@ -1,7 +1,7 @@ //@aux-build:proc_macros.rs -#![allow(unused, clippy::multiple_bound_locations)] #![warn(clippy::needless_maybe_sized)] +#![allow(clippy::multiple_bound_locations)] extern crate proc_macros; use proc_macros::external; diff --git a/tests/ui/needless_option_as_deref.fixed b/tests/ui/needless_option_as_deref.fixed index fd639f3b57fa7..5aec19b222528 100644 --- a/tests/ui/needless_option_as_deref.fixed +++ b/tests/ui/needless_option_as_deref.fixed @@ -1,6 +1,5 @@ -#![allow(unused)] #![warn(clippy::needless_option_as_deref)] -#![allow(clippy::useless_vec)] +#![expect(clippy::useless_vec)] fn main() { // should lint diff --git a/tests/ui/needless_option_as_deref.rs b/tests/ui/needless_option_as_deref.rs index cbf7935794b31..9c4bd6ad60aaf 100644 --- a/tests/ui/needless_option_as_deref.rs +++ b/tests/ui/needless_option_as_deref.rs @@ -1,6 +1,5 @@ -#![allow(unused)] #![warn(clippy::needless_option_as_deref)] -#![allow(clippy::useless_vec)] +#![expect(clippy::useless_vec)] fn main() { // should lint diff --git a/tests/ui/needless_option_as_deref.stderr b/tests/ui/needless_option_as_deref.stderr index bd19dc75eed60..a86bdfe5846db 100644 --- a/tests/ui/needless_option_as_deref.stderr +++ b/tests/ui/needless_option_as_deref.stderr @@ -1,5 +1,5 @@ error: derefed type is same as origin - --> tests/ui/needless_option_as_deref.rs:7:29 + --> tests/ui/needless_option_as_deref.rs:6:29 | LL | let _: Option<&usize> = Some(&1).as_deref(); | ^^^^^^^^^^^^^^^^^^^ help: try: `Some(&1)` @@ -8,13 +8,13 @@ LL | let _: Option<&usize> = Some(&1).as_deref(); = help: to override `-D warnings` add `#[allow(clippy::needless_option_as_deref)]` error: derefed type is same as origin - --> tests/ui/needless_option_as_deref.rs:9:33 + --> tests/ui/needless_option_as_deref.rs:8:33 | LL | let _: Option<&mut usize> = Some(&mut 1).as_deref_mut(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(&mut 1)` error: derefed type is same as origin - --> tests/ui/needless_option_as_deref.rs:14:13 + --> tests/ui/needless_option_as_deref.rs:13:13 | LL | let _ = x.as_deref_mut(); | ^^^^^^^^^^^^^^^^ help: try: `x` diff --git a/tests/ui/needless_parens_on_range_literals.fixed b/tests/ui/needless_parens_on_range_literals.fixed index 7abcbc0c6e32c..989dad8b8655e 100644 --- a/tests/ui/needless_parens_on_range_literals.fixed +++ b/tests/ui/needless_parens_on_range_literals.fixed @@ -1,7 +1,7 @@ //@edition:2018 #![warn(clippy::needless_parens_on_range_literals)] -#![allow(clippy::almost_complete_range)] +#![expect(clippy::almost_complete_range)] fn main() { let _ = 'a'..='z'; diff --git a/tests/ui/needless_parens_on_range_literals.rs b/tests/ui/needless_parens_on_range_literals.rs index 2a6f9305883bd..1c56ecd161aea 100644 --- a/tests/ui/needless_parens_on_range_literals.rs +++ b/tests/ui/needless_parens_on_range_literals.rs @@ -1,7 +1,7 @@ //@edition:2018 #![warn(clippy::needless_parens_on_range_literals)] -#![allow(clippy::almost_complete_range)] +#![expect(clippy::almost_complete_range)] fn main() { let _ = ('a')..=('z'); diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index bdad3e3d5b008..2ca8e06ee9b02 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -1,11 +1,5 @@ -#![allow( - clippy::if_same_then_else, - clippy::no_effect, - clippy::ptr_arg, - clippy::redundant_closure_call, - clippy::uninlined_format_args -)] #![warn(clippy::needless_pass_by_ref_mut)] +#![expect(clippy::no_effect, clippy::ptr_arg, clippy::redundant_closure_call)] //@no-rustfix use std::ptr::NonNull; diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index c427f4c3e42c4..208031497c04e 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -1,5 +1,5 @@ error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:12:11 + --> tests/ui/needless_pass_by_ref_mut.rs:6:11 | LL | fn foo(s: &mut Vec, b: &u32, x: &mut u32) { | ^----^^^^^^^^ @@ -10,7 +10,7 @@ LL | fn foo(s: &mut Vec, b: &u32, x: &mut u32) { = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:38:12 + --> tests/ui/needless_pass_by_ref_mut.rs:32:12 | LL | fn foo6(s: &mut Vec) { | ^----^^^^^^^^ @@ -18,7 +18,7 @@ LL | fn foo6(s: &mut Vec) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:49:12 + --> tests/ui/needless_pass_by_ref_mut.rs:43:12 | LL | fn bar(&mut self) {} | ^----^^^^ @@ -26,7 +26,7 @@ LL | fn bar(&mut self) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:52:29 + --> tests/ui/needless_pass_by_ref_mut.rs:46:29 | LL | fn mushroom(&self, vec: &mut Vec) -> usize { | ^----^^^^^^^^ @@ -34,7 +34,7 @@ LL | fn mushroom(&self, vec: &mut Vec) -> usize { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:130:16 + --> tests/ui/needless_pass_by_ref_mut.rs:124:16 | LL | async fn a1(x: &mut i32) { | ^----^^^ @@ -42,7 +42,7 @@ LL | async fn a1(x: &mut i32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:135:16 + --> tests/ui/needless_pass_by_ref_mut.rs:129:16 | LL | async fn a2(x: &mut i32, y: String) { | ^----^^^ @@ -50,7 +50,7 @@ LL | async fn a2(x: &mut i32, y: String) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:140:16 + --> tests/ui/needless_pass_by_ref_mut.rs:134:16 | LL | async fn a3(x: &mut i32, y: String, z: String) { | ^----^^^ @@ -58,7 +58,7 @@ LL | async fn a3(x: &mut i32, y: String, z: String) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:145:16 + --> tests/ui/needless_pass_by_ref_mut.rs:139:16 | LL | async fn a4(x: &mut i32, y: i32) { | ^----^^^ @@ -66,7 +66,7 @@ LL | async fn a4(x: &mut i32, y: i32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:150:24 + --> tests/ui/needless_pass_by_ref_mut.rs:144:24 | LL | async fn a5(x: i32, y: &mut i32) { | ^----^^^ @@ -74,7 +74,7 @@ LL | async fn a5(x: i32, y: &mut i32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:155:24 + --> tests/ui/needless_pass_by_ref_mut.rs:149:24 | LL | async fn a6(x: i32, y: &mut i32) { | ^----^^^ @@ -82,7 +82,7 @@ LL | async fn a6(x: i32, y: &mut i32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:160:32 + --> tests/ui/needless_pass_by_ref_mut.rs:154:32 | LL | async fn a7(x: i32, y: i32, z: &mut i32) { | ^----^^^ @@ -90,7 +90,7 @@ LL | async fn a7(x: i32, y: i32, z: &mut i32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:165:24 + --> tests/ui/needless_pass_by_ref_mut.rs:159:24 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^----^^^ @@ -98,7 +98,7 @@ LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:165:45 + --> tests/ui/needless_pass_by_ref_mut.rs:159:45 | LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | ^----^^^ @@ -106,7 +106,7 @@ LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:201:16 + --> tests/ui/needless_pass_by_ref_mut.rs:195:16 | LL | fn cfg_warn(s: &mut u32) {} | ^----^^^ @@ -116,7 +116,7 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:206:20 + --> tests/ui/needless_pass_by_ref_mut.rs:200:20 | LL | fn cfg_warn(s: &mut u32) {} | ^----^^^ @@ -126,7 +126,7 @@ LL | fn cfg_warn(s: &mut u32) {} = note: this is cfg-gated and may require further changes error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:219:39 + --> tests/ui/needless_pass_by_ref_mut.rs:213:39 | LL | async fn inner_async2(x: &mut i32, y: &mut u32) { | ^----^^^ @@ -134,7 +134,7 @@ LL | async fn inner_async2(x: &mut i32, y: &mut u32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:228:26 + --> tests/ui/needless_pass_by_ref_mut.rs:222:26 | LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | ^----^^^ @@ -142,7 +142,7 @@ LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:248:30 + --> tests/ui/needless_pass_by_ref_mut.rs:242:30 | LL | async fn call_in_closure1(n: &mut str) { | ^----^^^ @@ -150,7 +150,7 @@ LL | async fn call_in_closure1(n: &mut str) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:268:16 + --> tests/ui/needless_pass_by_ref_mut.rs:262:16 | LL | fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { | ^----^^^^^ @@ -158,7 +158,7 @@ LL | fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:280:22 + --> tests/ui/needless_pass_by_ref_mut.rs:274:22 | LL | async fn closure4(n: &mut usize) { | ^----^^^^^ @@ -166,7 +166,7 @@ LL | async fn closure4(n: &mut usize) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:335:12 + --> tests/ui/needless_pass_by_ref_mut.rs:329:12 | LL | fn bar(&mut self) {} | ^----^^^^ @@ -174,7 +174,7 @@ LL | fn bar(&mut self) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:338:18 + --> tests/ui/needless_pass_by_ref_mut.rs:332:18 | LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | ^----^^^^ @@ -182,7 +182,7 @@ LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:338:45 + --> tests/ui/needless_pass_by_ref_mut.rs:332:45 | LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | ^----^^^ @@ -190,7 +190,7 @@ LL | async fn foo(&mut self, u: &mut i32, v: &mut u32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:347:46 + --> tests/ui/needless_pass_by_ref_mut.rs:341:46 | LL | async fn foo2(&mut self, u: &mut i32, v: &mut u32) { | ^----^^^ @@ -198,7 +198,7 @@ LL | async fn foo2(&mut self, u: &mut i32, v: &mut u32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:364:18 + --> tests/ui/needless_pass_by_ref_mut.rs:358:18 | LL | fn _empty_tup(x: &mut (())) {} | ^^----^^^ @@ -206,7 +206,7 @@ LL | fn _empty_tup(x: &mut (())) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:366:19 + --> tests/ui/needless_pass_by_ref_mut.rs:360:19 | LL | fn _single_tup(x: &mut ((i32,))) {} | ^^----^^^^^^^ @@ -214,7 +214,7 @@ LL | fn _single_tup(x: &mut ((i32,))) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:368:18 + --> tests/ui/needless_pass_by_ref_mut.rs:362:18 | LL | fn _multi_tup(x: &mut ((i32, u32))) {} | ^^----^^^^^^^^^^^ @@ -222,7 +222,7 @@ LL | fn _multi_tup(x: &mut ((i32, u32))) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:370:11 + --> tests/ui/needless_pass_by_ref_mut.rs:364:11 | LL | fn _fn(x: &mut (fn())) {} | ^^----^^^^^ @@ -230,7 +230,7 @@ LL | fn _fn(x: &mut (fn())) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:373:23 + --> tests/ui/needless_pass_by_ref_mut.rs:367:23 | LL | fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} | ^----^^^^^^^^^^^^^^^^^^ @@ -238,7 +238,7 @@ LL | fn _extern_rust_fn(x: &mut extern "Rust" fn()) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:375:20 + --> tests/ui/needless_pass_by_ref_mut.rs:369:20 | LL | fn _extern_c_fn(x: &mut extern "C" fn()) {} | ^----^^^^^^^^^^^^^^^ @@ -246,7 +246,7 @@ LL | fn _extern_c_fn(x: &mut extern "C" fn()) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:377:18 + --> tests/ui/needless_pass_by_ref_mut.rs:371:18 | LL | fn _unsafe_fn(x: &mut unsafe fn()) {} | ^----^^^^^^^^^^^ @@ -254,7 +254,7 @@ LL | fn _unsafe_fn(x: &mut unsafe fn()) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:379:25 + --> tests/ui/needless_pass_by_ref_mut.rs:373:25 | LL | fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} | ^----^^^^^^^^^^^^^^^^^^^^^^ @@ -262,7 +262,7 @@ LL | fn _unsafe_extern_fn(x: &mut unsafe extern "C" fn()) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:381:20 + --> tests/ui/needless_pass_by_ref_mut.rs:375:20 | LL | fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} | ^----^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -270,7 +270,7 @@ LL | fn _fn_with_arg(x: &mut unsafe extern "C" fn(i32)) {} | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut.rs:383:20 + --> tests/ui/needless_pass_by_ref_mut.rs:377:20 | LL | fn _fn_with_ret(x: &mut unsafe extern "C" fn() -> (i32)) {} | ^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_pass_by_ref_mut2.fixed b/tests/ui/needless_pass_by_ref_mut2.fixed index c462f1cc8d87f..708c345fdca64 100644 --- a/tests/ui/needless_pass_by_ref_mut2.fixed +++ b/tests/ui/needless_pass_by_ref_mut2.fixed @@ -2,7 +2,6 @@ // they're used in `inner_async4` for some reasons... This test ensures that no // only `v` is marked as not used mutably in `inner_async4`. -#![allow(clippy::redundant_closure_call)] #![warn(clippy::needless_pass_by_ref_mut)] async fn inner_async3(x: &i32, y: &mut u32) { diff --git a/tests/ui/needless_pass_by_ref_mut2.rs b/tests/ui/needless_pass_by_ref_mut2.rs index b00f294c57f0c..a73f9828e577b 100644 --- a/tests/ui/needless_pass_by_ref_mut2.rs +++ b/tests/ui/needless_pass_by_ref_mut2.rs @@ -2,7 +2,6 @@ // they're used in `inner_async4` for some reasons... This test ensures that no // only `v` is marked as not used mutably in `inner_async4`. -#![allow(clippy::redundant_closure_call)] #![warn(clippy::needless_pass_by_ref_mut)] async fn inner_async3(x: &mut i32, y: &mut u32) { diff --git a/tests/ui/needless_pass_by_ref_mut2.stderr b/tests/ui/needless_pass_by_ref_mut2.stderr index aa5c412adb4d5..d5d457370f249 100644 --- a/tests/ui/needless_pass_by_ref_mut2.stderr +++ b/tests/ui/needless_pass_by_ref_mut2.stderr @@ -1,5 +1,5 @@ error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut2.rs:8:26 + --> tests/ui/needless_pass_by_ref_mut2.rs:7:26 | LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | ^----^^^ @@ -10,7 +10,7 @@ LL | async fn inner_async3(x: &mut i32, y: &mut u32) { = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut2.rs:17:39 + --> tests/ui/needless_pass_by_ref_mut2.rs:16:39 | LL | async fn inner_async4(u: &mut i32, v: &mut u32) { | ^----^^^ @@ -18,7 +18,7 @@ LL | async fn inner_async4(u: &mut i32, v: &mut u32) { | help: consider removing this `mut` error: this parameter is a mutable reference but is not used mutably - --> tests/ui/needless_pass_by_ref_mut2.rs:29:37 + --> tests/ui/needless_pass_by_ref_mut2.rs:28:37 | LL | fn issue16267<'a>(msg: &str, slice: &'a mut [i32]) -> &'a [i32] { | ^^^^----^^^^^ diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index aef7fff287058..d1a65e43e8100 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -1,13 +1,5 @@ #![warn(clippy::needless_pass_by_value)] -#![allow(dead_code)] -#![allow( - clippy::option_option, - clippy::redundant_clone, - clippy::redundant_pattern_matching, - clippy::single_match, - clippy::uninlined_format_args, - clippy::needless_lifetimes -)] +#![expect(clippy::needless_lifetimes, clippy::single_match)] //@no-rustfix use std::borrow::Borrow; use std::collections::HashSet; diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index e4381d1db53ad..72cc025f566e1 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -1,5 +1,5 @@ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:19:23 + --> tests/ui/needless_pass_by_value.rs:11:23 | LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec { | ^^^^^^ help: consider changing the type to: `&[T]` @@ -8,13 +8,13 @@ LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec tests/ui/needless_pass_by_value.rs:35:11 + --> tests/ui/needless_pass_by_value.rs:27:11 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:35:22 + --> tests/ui/needless_pass_by_value.rs:27:22 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^^ @@ -25,7 +25,7 @@ LL | fn bar(x: String, y: &Wrapper) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:44:71 + --> tests/ui/needless_pass_by_value.rs:36:71 | LL | fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { | ^ @@ -36,7 +36,7 @@ LL | fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: &V) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:58:18 + --> tests/ui/needless_pass_by_value.rs:50:18 | LL | fn test_match(x: Option>, y: Option>) { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL | fn test_match(x: Option>, y: Option>) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:73:24 + --> tests/ui/needless_pass_by_value.rs:65:24 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ @@ -58,7 +58,7 @@ LL | fn test_destructure(x: &Wrapper, y: Wrapper, z: Wrapper) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:73:36 + --> tests/ui/needless_pass_by_value.rs:65:36 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ @@ -69,7 +69,7 @@ LL | fn test_destructure(x: Wrapper, y: &Wrapper, z: Wrapper) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:92:49 + --> tests/ui/needless_pass_by_value.rs:84:49 | LL | fn test_blanket_ref(vals: T, serializable: S) {} | ^ @@ -80,7 +80,7 @@ LL | fn test_blanket_ref(vals: &T, serializable: S) {} | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:95:18 + --> tests/ui/needless_pass_by_value.rs:87:18 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ @@ -91,7 +91,7 @@ LL | fn issue_2114(s: &String, t: String, u: Vec, v: Vec) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:95:29 + --> tests/ui/needless_pass_by_value.rs:87:29 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ @@ -108,7 +108,7 @@ LL + let _ = t.to_string(); | error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:95:40 + --> tests/ui/needless_pass_by_value.rs:87:40 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ @@ -119,7 +119,7 @@ LL | fn issue_2114(s: String, t: String, u: &Vec, v: Vec) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:95:53 + --> tests/ui/needless_pass_by_value.rs:87:53 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ @@ -136,13 +136,13 @@ LL + let _ = v.to_owned(); | error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:113:12 + --> tests/ui/needless_pass_by_value.rs:105:12 | LL | s: String, | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:115:12 + --> tests/ui/needless_pass_by_value.rs:107:12 | LL | t: String, | ^^^^^^ @@ -153,7 +153,7 @@ LL | t: &String, | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:125:23 + --> tests/ui/needless_pass_by_value.rs:117:23 | LL | fn baz(&self, uu: U, ss: Self) {} | ^ @@ -164,7 +164,7 @@ LL | fn baz(&self, uu: &U, ss: Self) {} | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:125:30 + --> tests/ui/needless_pass_by_value.rs:117:30 | LL | fn baz(&self, uu: U, ss: Self) {} | ^^^^ @@ -175,13 +175,13 @@ LL | fn baz(&self, uu: U, ss: &Self) {} | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:149:24 + --> tests/ui/needless_pass_by_value.rs:141:24 | LL | fn bar_copy(x: u32, y: CopyWrapper) { | ^^^^^^^^^^^ | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:147:1 + --> tests/ui/needless_pass_by_value.rs:139:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ @@ -191,13 +191,13 @@ LL | fn bar_copy(x: u32, y: &CopyWrapper) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:157:29 + --> tests/ui/needless_pass_by_value.rs:149:29 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:147:1 + --> tests/ui/needless_pass_by_value.rs:139:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ @@ -207,13 +207,13 @@ LL | fn test_destructure_copy(x: &CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:157:45 + --> tests/ui/needless_pass_by_value.rs:149:45 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:147:1 + --> tests/ui/needless_pass_by_value.rs:139:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ @@ -223,13 +223,13 @@ LL | fn test_destructure_copy(x: CopyWrapper, y: &CopyWrapper, z: CopyWrapper) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:157:61 + --> tests/ui/needless_pass_by_value.rs:149:61 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:147:1 + --> tests/ui/needless_pass_by_value.rs:139:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ @@ -239,7 +239,7 @@ LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: &CopyWrapper) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:173:40 + --> tests/ui/needless_pass_by_value.rs:165:40 | LL | fn some_fun<'b, S: Bar<'b, ()>>(items: S) {} | ^ @@ -250,7 +250,7 @@ LL | fn some_fun<'b, S: Bar<'b, ()>>(items: &S) {} | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:179:20 + --> tests/ui/needless_pass_by_value.rs:171:20 | LL | fn more_fun(items: impl Club<'static, i32>) {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -261,7 +261,7 @@ LL | fn more_fun(items: &impl Club<'static, i32>) {} | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:194:24 + --> tests/ui/needless_pass_by_value.rs:186:24 | LL | fn option_inner_ref(x: Option) { | ^^^^^^^^^^^^^^ @@ -272,7 +272,7 @@ LL | fn option_inner_ref(x: Option<&String>) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:204:27 + --> tests/ui/needless_pass_by_value.rs:196:27 | LL | fn non_standard_option(x: non_standard::Option) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -283,7 +283,7 @@ LL | fn non_standard_option(x: &non_standard::Option) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:209:22 + --> tests/ui/needless_pass_by_value.rs:201:22 | LL | fn option_by_name(x: Option>>>) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -294,7 +294,7 @@ LL | fn option_by_name(x: Option tests/ui/needless_pass_by_value.rs:216:18 + --> tests/ui/needless_pass_by_value.rs:208:18 | LL | fn non_option(x: OptStr) { | ^^^^^^ @@ -305,7 +305,7 @@ LL | fn non_option(x: &OptStr) { | + error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:223:25 + --> tests/ui/needless_pass_by_value.rs:215:25 | LL | fn non_option_either(x: Opt) { | ^^^^^^^^^^^ diff --git a/tests/ui/needless_pub_self.fixed b/tests/ui/needless_pub_self.fixed index 7b4601ba8a370..8a2c443c47abf 100644 --- a/tests/ui/needless_pub_self.fixed +++ b/tests/ui/needless_pub_self.fixed @@ -1,7 +1,6 @@ //@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] -#![allow(unused)] #![warn(clippy::needless_pub_self)] #![no_main] #![rustfmt::skip] // rustfmt will remove `in`, understandable diff --git a/tests/ui/needless_pub_self.rs b/tests/ui/needless_pub_self.rs index f64a56c37989d..7bd2d028364f9 100644 --- a/tests/ui/needless_pub_self.rs +++ b/tests/ui/needless_pub_self.rs @@ -1,7 +1,6 @@ //@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] -#![allow(unused)] #![warn(clippy::needless_pub_self)] #![no_main] #![rustfmt::skip] // rustfmt will remove `in`, understandable diff --git a/tests/ui/needless_pub_self.stderr b/tests/ui/needless_pub_self.stderr index c362d11804ec1..17b69e09d202f 100644 --- a/tests/ui/needless_pub_self.stderr +++ b/tests/ui/needless_pub_self.stderr @@ -1,5 +1,5 @@ error: unnecessary `pub(self)` - --> tests/ui/needless_pub_self.rs:13:1 + --> tests/ui/needless_pub_self.rs:12:1 | LL | pub(self) fn a() {} | ^^^^^^^^^ @@ -9,7 +9,7 @@ LL | pub(self) fn a() {} = help: remove it error: unnecessary `pub(in self)` - --> tests/ui/needless_pub_self.rs:15:1 + --> tests/ui/needless_pub_self.rs:14:1 | LL | pub(in self) fn b() {} | ^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | pub(in self) fn b() {} = help: remove it error: unnecessary `pub(self)` - --> tests/ui/needless_pub_self.rs:22:5 + --> tests/ui/needless_pub_self.rs:21:5 | LL | pub(self) fn f() {} | ^^^^^^^^^ diff --git a/tests/ui/needless_question_mark.fixed b/tests/ui/needless_question_mark.fixed index 375c38771eb6d..c4e02c7ac6f61 100644 --- a/tests/ui/needless_question_mark.fixed +++ b/tests/ui/needless_question_mark.fixed @@ -1,11 +1,5 @@ #![warn(clippy::needless_question_mark)] -#![allow( - clippy::needless_return, - clippy::unnecessary_unwrap, - clippy::upper_case_acronyms, - dead_code, - unused_must_use -)] +#![expect(clippy::needless_return, clippy::unnecessary_unwrap)] struct TO { magic: Option, diff --git a/tests/ui/needless_question_mark.rs b/tests/ui/needless_question_mark.rs index 5f6bd0c0f166e..87843e3e11c83 100644 --- a/tests/ui/needless_question_mark.rs +++ b/tests/ui/needless_question_mark.rs @@ -1,11 +1,5 @@ #![warn(clippy::needless_question_mark)] -#![allow( - clippy::needless_return, - clippy::unnecessary_unwrap, - clippy::upper_case_acronyms, - dead_code, - unused_must_use -)] +#![expect(clippy::needless_return, clippy::unnecessary_unwrap)] struct TO { magic: Option, diff --git a/tests/ui/needless_question_mark.stderr b/tests/ui/needless_question_mark.stderr index 8516cee48e679..8e0a740cc0ab3 100644 --- a/tests/ui/needless_question_mark.stderr +++ b/tests/ui/needless_question_mark.stderr @@ -1,5 +1,5 @@ error: enclosing `Some` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:20:12 + --> tests/ui/needless_question_mark.rs:14:12 | LL | return Some(to.magic?); | ^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + return to.magic; | error: enclosing `Some` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:29:12 + --> tests/ui/needless_question_mark.rs:23:12 | LL | return Some(to.magic?) | ^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + return to.magic | error: enclosing `Some` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:35:5 + --> tests/ui/needless_question_mark.rs:29:5 | LL | Some(to.magic?) | ^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + to.magic | error: enclosing `Some` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:41:21 + --> tests/ui/needless_question_mark.rs:35:21 | LL | to.and_then(|t| Some(t.magic?)) | ^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + to.and_then(|t| t.magic) | error: enclosing `Some` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:51:9 + --> tests/ui/needless_question_mark.rs:45:9 | LL | Some(t.magic?) | ^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + t.magic | error: enclosing `Ok` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:57:12 + --> tests/ui/needless_question_mark.rs:51:12 | LL | return Ok(tr.magic?); | ^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + return tr.magic; | error: enclosing `Ok` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:65:12 + --> tests/ui/needless_question_mark.rs:59:12 | LL | return Ok(tr.magic?) | ^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + return tr.magic | error: enclosing `Ok` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:70:5 + --> tests/ui/needless_question_mark.rs:64:5 | LL | Ok(tr.magic?) | ^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + tr.magic | error: enclosing `Ok` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:75:21 + --> tests/ui/needless_question_mark.rs:69:21 | LL | tr.and_then(|t| Ok(t.magic?)) | ^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + tr.and_then(|t| t.magic) | error: enclosing `Ok` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:84:9 + --> tests/ui/needless_question_mark.rs:78:9 | LL | Ok(t.magic?) | ^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + t.magic | error: enclosing `Ok` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:92:16 + --> tests/ui/needless_question_mark.rs:86:16 | LL | return Ok(t.magic?); | ^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + return t.magic; | error: enclosing `Some` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:128:27 + --> tests/ui/needless_question_mark.rs:122:27 | LL | || -> Option<_> { Some(Some($expr)?) }() | ^^^^^^^^^^^^^^^^^^ @@ -149,7 +149,7 @@ LL + || -> Option<_> { Some($expr) }() | error: enclosing `Some` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:140:5 + --> tests/ui/needless_question_mark.rs:134:5 | LL | Some(to.magic?) | ^^^^^^^^^^^^^^^ @@ -161,7 +161,7 @@ LL + to.magic | error: enclosing `Ok` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:149:5 + --> tests/ui/needless_question_mark.rs:143:5 | LL | Ok(s.magic?) | ^^^^^^^^^^^^ @@ -173,7 +173,7 @@ LL + s.magic | error: enclosing `Some` and `?` operator are unneeded - --> tests/ui/needless_question_mark.rs:154:7 + --> tests/ui/needless_question_mark.rs:148:7 | LL | { Some(a?) } | ^^^^^^^^ diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs index ea4591d8b71ac..dcb7026266048 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -1,10 +1,5 @@ #![warn(clippy::needless_range_loop)] -#![allow( - clippy::uninlined_format_args, - clippy::unnecessary_literal_unwrap, - clippy::useless_vec, - clippy::manual_slice_fill -)] +#![expect(clippy::unnecessary_literal_unwrap, clippy::useless_vec)] //@no-rustfix static STATIC: [usize; 4] = [0, 1, 8, 16]; const CONST: [usize; 4] = [0, 1, 8, 16]; diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index 33a519d8a80d5..ab9693bb46d6b 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -1,5 +1,5 @@ error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:16:14 + --> tests/ui/needless_range_loop.rs:11:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + for in &vec { | error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:27:14 + --> tests/ui/needless_range_loop.rs:22:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + for in &vec { | error: the loop variable `j` is only used to index `STATIC` - --> tests/ui/needless_range_loop.rs:34:14 + --> tests/ui/needless_range_loop.rs:29:14 | LL | for j in 0..4 { | ^^^^ @@ -37,7 +37,7 @@ LL + for in &STATIC { | error: the loop variable `j` is only used to index `CONST` - --> tests/ui/needless_range_loop.rs:40:14 + --> tests/ui/needless_range_loop.rs:35:14 | LL | for j in 0..4 { | ^^^^ @@ -49,7 +49,7 @@ LL + for in &CONST { | error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:46:14 + --> tests/ui/needless_range_loop.rs:41:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + for (i, ) in vec.iter().enumerate() { | error: the loop variable `i` is only used to index `vec2` - --> tests/ui/needless_range_loop.rs:56:14 + --> tests/ui/needless_range_loop.rs:51:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + for in vec2.iter().take(vec.len()) { | error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:62:14 + --> tests/ui/needless_range_loop.rs:57:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + for in vec.iter().skip(5) { | error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:68:14 + --> tests/ui/needless_range_loop.rs:63:14 | LL | for i in 0..MAX_LEN { | ^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + for in vec.iter().take(MAX_LEN) { | error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:74:14 + --> tests/ui/needless_range_loop.rs:69:14 | LL | for i in 0..=MAX_LEN { | ^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + for in vec.iter().take(MAX_LEN + 1) { | error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:80:14 + --> tests/ui/needless_range_loop.rs:75:14 | LL | for i in 5..10 { | ^^^^^ @@ -121,7 +121,7 @@ LL + for in vec.iter().take(10).skip(5) { | error: the loop variable `i` is only used to index `vec` - --> tests/ui/needless_range_loop.rs:86:14 + --> tests/ui/needless_range_loop.rs:81:14 | LL | for i in 5..=10 { | ^^^^^^ @@ -133,7 +133,7 @@ LL + for in vec.iter().take(10 + 1).skip(5) { | error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:92:14 + --> tests/ui/needless_range_loop.rs:87:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + for (i, ) in vec.iter().enumerate().skip(5) { | error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:98:14 + --> tests/ui/needless_range_loop.rs:93:14 | LL | for i in 5..10 { | ^^^^^ @@ -157,7 +157,7 @@ LL + for (i, ) in vec.iter().enumerate().take(10).skip(5) { | error: the loop variable `i` is used to index `vec` - --> tests/ui/needless_range_loop.rs:105:14 + --> tests/ui/needless_range_loop.rs:100:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + for (i, ) in vec.iter_mut().enumerate() { | error: the loop variable `i` is used to index `a` - --> tests/ui/needless_range_loop.rs:235:14 + --> tests/ui/needless_range_loop.rs:230:14 | LL | for i in 0..MAX_LEN { | ^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + for (i, ) in a.iter().enumerate().take(MAX_LEN) { | error: the loop variable `i` is only used to index `a` - --> tests/ui/needless_range_loop.rs:240:14 + --> tests/ui/needless_range_loop.rs:235:14 | LL | for i in 0..MAX_LEN { | ^^^^^^^^^^ diff --git a/tests/ui/needless_range_loop2.rs b/tests/ui/needless_range_loop2.rs index 68784a8df19d3..333a4d8e5e767 100644 --- a/tests/ui/needless_range_loop2.rs +++ b/tests/ui/needless_range_loop2.rs @@ -1,5 +1,5 @@ #![warn(clippy::needless_range_loop)] -#![allow(clippy::useless_vec)] +#![expect(clippy::useless_vec)] //@no-rustfix fn calc_idx(i: usize) -> usize { (i + i + 20) % 4 diff --git a/tests/ui/needless_raw_string.fixed b/tests/ui/needless_raw_string.fixed index 88f9096db03cf..93225f56e377c 100644 --- a/tests/ui/needless_raw_string.fixed +++ b/tests/ui/needless_raw_string.fixed @@ -1,5 +1,5 @@ -#![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::needless_raw_strings)] +#![expect(clippy::needless_raw_string_hashes, clippy::no_effect)] fn main() { "aaa"; diff --git a/tests/ui/needless_raw_string.rs b/tests/ui/needless_raw_string.rs index 6913b8b755469..fcd32cd651123 100644 --- a/tests/ui/needless_raw_string.rs +++ b/tests/ui/needless_raw_string.rs @@ -1,5 +1,5 @@ -#![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::needless_raw_strings)] +#![expect(clippy::needless_raw_string_hashes, clippy::no_effect)] fn main() { r#"aaa"#; diff --git a/tests/ui/needless_raw_string_hashes.fixed b/tests/ui/needless_raw_string_hashes.fixed index bc7da202df4a9..0a2a684f5b0fa 100644 --- a/tests/ui/needless_raw_string_hashes.fixed +++ b/tests/ui/needless_raw_string_hashes.fixed @@ -1,5 +1,5 @@ -#![allow(clippy::no_effect, unused)] #![warn(clippy::needless_raw_string_hashes)] +#![expect(clippy::no_effect)] fn main() { r"\aaa"; diff --git a/tests/ui/needless_raw_string_hashes.rs b/tests/ui/needless_raw_string_hashes.rs index 3f2f92a4097c3..a793099c441b5 100644 --- a/tests/ui/needless_raw_string_hashes.rs +++ b/tests/ui/needless_raw_string_hashes.rs @@ -1,5 +1,5 @@ -#![allow(clippy::no_effect, unused)] #![warn(clippy::needless_raw_string_hashes)] +#![expect(clippy::no_effect)] fn main() { r#"\aaa"#; diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index f5f8bb21e815b..72986b9f8960a 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -1,15 +1,8 @@ //@aux-build:proc_macros.rs #![feature(yeet_expr)] -#![allow(unused)] -#![allow( - clippy::if_same_then_else, - clippy::single_match, - clippy::needless_bool, - clippy::equatable_if_let, - clippy::needless_else, - clippy::missing_safety_doc -)] #![warn(clippy::needless_return)] +#![allow(clippy::single_match)] +#![expect(clippy::if_same_then_else, clippy::missing_safety_doc, clippy::needless_bool)] extern crate proc_macros; use proc_macros::with_span; diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index 495516c1c2e5d..63b7a2524962b 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -1,15 +1,8 @@ //@aux-build:proc_macros.rs #![feature(yeet_expr)] -#![allow(unused)] -#![allow( - clippy::if_same_then_else, - clippy::single_match, - clippy::needless_bool, - clippy::equatable_if_let, - clippy::needless_else, - clippy::missing_safety_doc -)] #![warn(clippy::needless_return)] +#![allow(clippy::single_match)] +#![expect(clippy::if_same_then_else, clippy::missing_safety_doc, clippy::needless_bool)] extern crate proc_macros; use proc_macros::with_span; diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index 206bd8ee5af11..5292a776ad7c2 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -1,5 +1,5 @@ error: unneeded `return` statement - --> tests/ui/needless_return.rs:30:5 + --> tests/ui/needless_return.rs:23:5 | LL | return true; | ^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:35:5 + --> tests/ui/needless_return.rs:28:5 | LL | return true; | ^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:41:5 + --> tests/ui/needless_return.rs:34:5 | LL | return true;;; | ^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:47:5 + --> tests/ui/needless_return.rs:40:5 | LL | return true;; ; ; | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:53:9 + --> tests/ui/needless_return.rs:46:9 | LL | return true; | ^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:56:9 + --> tests/ui/needless_return.rs:49:9 | LL | return false; | ^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + false | error: unneeded `return` statement - --> tests/ui/needless_return.rs:63:17 + --> tests/ui/needless_return.rs:56:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + true => false, | error: unneeded `return` statement - --> tests/ui/needless_return.rs:66:13 + --> tests/ui/needless_return.rs:59:13 | LL | return true; | ^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:74:9 + --> tests/ui/needless_return.rs:67:9 | LL | return true; | ^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:77:16 + --> tests/ui/needless_return.rs:70:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + let _ = || true; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:82:5 + --> tests/ui/needless_return.rs:75:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:87:5 + --> tests/ui/needless_return.rs:80:5 | LL | return; | ^^^^^^ @@ -146,7 +146,7 @@ LL + fn test_void_fun() { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:93:9 + --> tests/ui/needless_return.rs:86:9 | LL | return; | ^^^^^^ @@ -159,7 +159,7 @@ LL + if b { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:96:9 + --> tests/ui/needless_return.rs:89:9 | LL | return; | ^^^^^^ @@ -172,7 +172,7 @@ LL + } else { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:104:14 + --> tests/ui/needless_return.rs:97:14 | LL | _ => return, | ^^^^^^ @@ -184,7 +184,7 @@ LL + _ => (), | error: unneeded `return` statement - --> tests/ui/needless_return.rs:114:13 + --> tests/ui/needless_return.rs:107:13 | LL | return; | ^^^^^^ @@ -197,7 +197,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:117:14 + --> tests/ui/needless_return.rs:110:14 | LL | _ => return, | ^^^^^^ @@ -209,7 +209,7 @@ LL + _ => (), | error: unneeded `return` statement - --> tests/ui/needless_return.rs:131:9 + --> tests/ui/needless_return.rs:124:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -221,7 +221,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:134:9 + --> tests/ui/needless_return.rs:127:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -233,7 +233,7 @@ LL + String::new() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:157:32 + --> tests/ui/needless_return.rs:150:32 | LL | bar.unwrap_or_else(|_| return) | ^^^^^^ @@ -245,7 +245,7 @@ LL + bar.unwrap_or_else(|_| {}) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:163:13 + --> tests/ui/needless_return.rs:156:13 | LL | return; | ^^^^^^ @@ -258,7 +258,7 @@ LL + let _ = || { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:166:20 + --> tests/ui/needless_return.rs:159:20 | LL | let _ = || return; | ^^^^^^ @@ -270,7 +270,7 @@ LL + let _ = || {}; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:173:32 + --> tests/ui/needless_return.rs:166:32 | LL | res.unwrap_or_else(|_| return Foo) | ^^^^^^^^^^ @@ -282,7 +282,7 @@ LL + res.unwrap_or_else(|_| Foo) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:183:5 + --> tests/ui/needless_return.rs:176:5 | LL | return true; | ^^^^^^^^^^^ @@ -294,7 +294,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:188:5 + --> tests/ui/needless_return.rs:181:5 | LL | return true; | ^^^^^^^^^^^ @@ -306,7 +306,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:194:9 + --> tests/ui/needless_return.rs:187:9 | LL | return true; | ^^^^^^^^^^^ @@ -318,7 +318,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:197:9 + --> tests/ui/needless_return.rs:190:9 | LL | return false; | ^^^^^^^^^^^^ @@ -330,7 +330,7 @@ LL + false | error: unneeded `return` statement - --> tests/ui/needless_return.rs:204:17 + --> tests/ui/needless_return.rs:197:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -342,7 +342,7 @@ LL + true => false, | error: unneeded `return` statement - --> tests/ui/needless_return.rs:207:13 + --> tests/ui/needless_return.rs:200:13 | LL | return true; | ^^^^^^^^^^^ @@ -354,7 +354,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:215:9 + --> tests/ui/needless_return.rs:208:9 | LL | return true; | ^^^^^^^^^^^ @@ -366,7 +366,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:218:16 + --> tests/ui/needless_return.rs:211:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -378,7 +378,7 @@ LL + let _ = || true; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:223:5 + --> tests/ui/needless_return.rs:216:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -390,7 +390,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:228:5 + --> tests/ui/needless_return.rs:221:5 | LL | return; | ^^^^^^ @@ -403,7 +403,7 @@ LL + async fn async_test_void_fun() { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:234:9 + --> tests/ui/needless_return.rs:227:9 | LL | return; | ^^^^^^ @@ -416,7 +416,7 @@ LL + if b { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:237:9 + --> tests/ui/needless_return.rs:230:9 | LL | return; | ^^^^^^ @@ -429,7 +429,7 @@ LL + } else { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:245:14 + --> tests/ui/needless_return.rs:238:14 | LL | _ => return, | ^^^^^^ @@ -441,7 +441,7 @@ LL + _ => (), | error: unneeded `return` statement - --> tests/ui/needless_return.rs:259:9 + --> tests/ui/needless_return.rs:252:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -453,7 +453,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:262:9 + --> tests/ui/needless_return.rs:255:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -465,7 +465,7 @@ LL + String::new() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:279:5 + --> tests/ui/needless_return.rs:272:5 | LL | return format!("Hello {}", "world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -477,7 +477,7 @@ LL + format!("Hello {}", "world!") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:321:9 + --> tests/ui/needless_return.rs:314:9 | LL | return true; | ^^^^^^^^^^^ @@ -492,7 +492,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:324:9 + --> tests/ui/needless_return.rs:317:9 | LL | return false; | ^^^^^^^^^^^^ @@ -505,7 +505,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:332:13 + --> tests/ui/needless_return.rs:325:13 | LL | return 10; | ^^^^^^^^^ @@ -520,7 +520,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:336:13 + --> tests/ui/needless_return.rs:329:13 | LL | return 100; | ^^^^^^^^^^ @@ -534,7 +534,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:345:9 + --> tests/ui/needless_return.rs:338:9 | LL | return 0; | ^^^^^^^^ @@ -547,7 +547,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:353:13 + --> tests/ui/needless_return.rs:346:13 | LL | return *(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -563,7 +563,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:356:13 + --> tests/ui/needless_return.rs:349:13 | LL | return !*(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -577,7 +577,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:365:9 + --> tests/ui/needless_return.rs:358:9 | LL | return; | ^^^^^^ @@ -590,7 +590,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:371:21 + --> tests/ui/needless_return.rs:364:21 | LL | let _ = 42; return; | ^^^^^^ @@ -602,7 +602,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:384:9 + --> tests/ui/needless_return.rs:377:9 | LL | return Ok(format!("ok!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -614,7 +614,7 @@ LL + Ok(format!("ok!")) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:387:9 + --> tests/ui/needless_return.rs:380:9 | LL | return Err(format!("err!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -626,7 +626,7 @@ LL + Err(format!("err!")) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:394:9 + --> tests/ui/needless_return.rs:387:9 | LL | return if true { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -638,7 +638,7 @@ LL + if true { 1 } else { 2 } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:399:9 + --> tests/ui/needless_return.rs:392:9 | LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -650,7 +650,7 @@ LL + (if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else | error: unneeded `return` statement - --> tests/ui/needless_return.rs:421:5 + --> tests/ui/needless_return.rs:414:5 | LL | return { "a".to_string() } + "b" + { "c" }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -662,7 +662,7 @@ LL + ({ "a".to_string() } + "b" + { "c" }) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:426:5 + --> tests/ui/needless_return.rs:419:5 | LL | return "".split("").next().unwrap().to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -674,7 +674,7 @@ LL + "".split("").next().unwrap().to_string() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:461:5 + --> tests/ui/needless_return.rs:454:5 | LL | return unsafe { todo() } as *const i32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -686,7 +686,7 @@ LL + (unsafe { todo() } as *const i32) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:468:13 + --> tests/ui/needless_return.rs:461:13 | LL | return 1; | ^^^^^^^^ @@ -698,7 +698,7 @@ LL + 1 | error: unneeded `return` statement - --> tests/ui/needless_return.rs:471:13 + --> tests/ui/needless_return.rs:464:13 | LL | return 2; | ^^^^^^^^ @@ -710,7 +710,7 @@ LL + 2 | error: unneeded `return` statement - --> tests/ui/needless_return.rs:474:13 + --> tests/ui/needless_return.rs:467:13 | LL | return 3; | ^^^^^^^^ @@ -722,7 +722,7 @@ LL + 3 | error: unneeded `return` statement - --> tests/ui/needless_return.rs:481:13 + --> tests/ui/needless_return.rs:474:13 | LL | return 1; | ^^^^^^^^ @@ -734,7 +734,7 @@ LL + 1 | error: unneeded `return` statement - --> tests/ui/needless_return.rs:486:13 + --> tests/ui/needless_return.rs:479:13 | LL | return 3; | ^^^^^^^^ @@ -746,7 +746,7 @@ LL + 3 | error: unneeded `return` statement - --> tests/ui/needless_return.rs:493:13 + --> tests/ui/needless_return.rs:486:13 | LL | return 1; | ^^^^^^^^ @@ -758,7 +758,7 @@ LL + 1 | error: unneeded `return` statement - --> tests/ui/needless_return.rs:498:13 + --> tests/ui/needless_return.rs:491:13 | LL | return 3; | ^^^^^^^^ @@ -770,7 +770,7 @@ LL + 3 | error: unneeded `return` statement - --> tests/ui/needless_return.rs:506:13 + --> tests/ui/needless_return.rs:499:13 | LL | return 1; | ^^^^^^^^ diff --git a/tests/ui/needless_return_with_question_mark.fixed b/tests/ui/needless_return_with_question_mark.fixed index a8e9f09fa5ecf..bd6c7a18722ea 100644 --- a/tests/ui/needless_return_with_question_mark.fixed +++ b/tests/ui/needless_return_with_question_mark.fixed @@ -1,12 +1,11 @@ //@aux-build:proc_macros.rs -#![allow( +#![warn(clippy::needless_return_with_question_mark)] +#![expect( + clippy::diverging_sub_expression, clippy::needless_return, clippy::no_effect, clippy::unit_arg, - clippy::useless_conversion, - clippy::diverging_sub_expression, - clippy::let_unit_value, - unused + clippy::useless_conversion )] #[macro_use] diff --git a/tests/ui/needless_return_with_question_mark.rs b/tests/ui/needless_return_with_question_mark.rs index aba7ffb273bce..a92dd92ab0bcd 100644 --- a/tests/ui/needless_return_with_question_mark.rs +++ b/tests/ui/needless_return_with_question_mark.rs @@ -1,12 +1,11 @@ //@aux-build:proc_macros.rs -#![allow( +#![warn(clippy::needless_return_with_question_mark)] +#![expect( + clippy::diverging_sub_expression, clippy::needless_return, clippy::no_effect, clippy::unit_arg, - clippy::useless_conversion, - clippy::diverging_sub_expression, - clippy::let_unit_value, - unused + clippy::useless_conversion )] #[macro_use] diff --git a/tests/ui/needless_return_with_question_mark.stderr b/tests/ui/needless_return_with_question_mark.stderr index d73a0e3fdc896..5aec5ec00b612 100644 --- a/tests/ui/needless_return_with_question_mark.stderr +++ b/tests/ui/needless_return_with_question_mark.stderr @@ -1,5 +1,5 @@ error: unneeded `return` statement with `?` operator - --> tests/ui/needless_return_with_question_mark.rs:29:5 + --> tests/ui/needless_return_with_question_mark.rs:28:5 | LL | return Err(())?; | ^^^^^^^ help: remove it @@ -8,25 +8,25 @@ LL | return Err(())?; = help: to override `-D warnings` add `#[allow(clippy::needless_return_with_question_mark)]` error: unneeded `return` statement with `?` operator - --> tests/ui/needless_return_with_question_mark.rs:70:9 + --> tests/ui/needless_return_with_question_mark.rs:69:9 | LL | return Err(())?; | ^^^^^^^ help: remove it error: unneeded `return` statement with `?` operator - --> tests/ui/needless_return_with_question_mark.rs:134:9 + --> tests/ui/needless_return_with_question_mark.rs:133:9 | LL | return Err(())?; | ^^^^^^^ help: remove it error: unneeded `return` statement with `?` operator - --> tests/ui/needless_return_with_question_mark.rs:143:13 + --> tests/ui/needless_return_with_question_mark.rs:142:13 | LL | return Err(())?; | ^^^^^^^ help: remove it error: unneeded `return` statement with `?` operator - --> tests/ui/needless_return_with_question_mark.rs:163:5 + --> tests/ui/needless_return_with_question_mark.rs:162:5 | LL | return Err(())?; | ^^^^^^^ help: remove it diff --git a/tests/ui/needless_splitn.fixed b/tests/ui/needless_splitn.fixed index bf5c1717ae53d..c6a180a00e5ed 100644 --- a/tests/ui/needless_splitn.fixed +++ b/tests/ui/needless_splitn.fixed @@ -1,11 +1,10 @@ //@edition:2018 #![warn(clippy::needless_splitn)] -#![allow(clippy::iter_skip_next, clippy::iter_nth_zero, clippy::manual_split_once)] +#![expect(clippy::iter_nth_zero, clippy::manual_split_once)] extern crate itertools; -#[allow(unused_imports)] use itertools::Itertools; fn main() { diff --git a/tests/ui/needless_splitn.rs b/tests/ui/needless_splitn.rs index fdfdcb9d5ca8a..d10430f7a6f9c 100644 --- a/tests/ui/needless_splitn.rs +++ b/tests/ui/needless_splitn.rs @@ -1,11 +1,10 @@ //@edition:2018 #![warn(clippy::needless_splitn)] -#![allow(clippy::iter_skip_next, clippy::iter_nth_zero, clippy::manual_split_once)] +#![expect(clippy::iter_nth_zero, clippy::manual_split_once)] extern crate itertools; -#[allow(unused_imports)] use itertools::Itertools; fn main() { diff --git a/tests/ui/needless_splitn.stderr b/tests/ui/needless_splitn.stderr index 49387793a1220..b71abb89ded39 100644 --- a/tests/ui/needless_splitn.stderr +++ b/tests/ui/needless_splitn.stderr @@ -1,5 +1,5 @@ error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:13:13 + --> tests/ui/needless_splitn.rs:12:13 | LL | let _ = str.splitn(2, '=').next(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` @@ -8,73 +8,73 @@ LL | let _ = str.splitn(2, '=').next(); = help: to override `-D warnings` add `#[allow(clippy::needless_splitn)]` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:15:13 + --> tests/ui/needless_splitn.rs:14:13 | LL | let _ = str.splitn(2, '=').nth(0); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:19:18 + --> tests/ui/needless_splitn.rs:18:18 | LL | let (_, _) = str.splitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:23:13 + --> tests/ui/needless_splitn.rs:22:13 | LL | let _ = str.rsplitn(2, '=').next(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:25:13 + --> tests/ui/needless_splitn.rs:24:13 | LL | let _ = str.rsplitn(2, '=').nth(0); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:29:18 + --> tests/ui/needless_splitn.rs:28:18 | LL | let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:32:13 + --> tests/ui/needless_splitn.rs:31:13 | LL | let _ = str.splitn(5, '=').next(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:34:13 + --> tests/ui/needless_splitn.rs:33:13 | LL | let _ = str.splitn(5, '=').nth(3); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:41:13 + --> tests/ui/needless_splitn.rs:40:13 | LL | let _ = s.splitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:43:13 + --> tests/ui/needless_splitn.rs:42:13 | LL | let _ = s.splitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:45:13 + --> tests/ui/needless_splitn.rs:44:13 | LL | let _ = s.rsplitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `rsplitn` - --> tests/ui/needless_splitn.rs:47:13 + --> tests/ui/needless_splitn.rs:46:13 | LL | let _ = s.rsplitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `splitn` - --> tests/ui/needless_splitn.rs:56:13 + --> tests/ui/needless_splitn.rs:55:13 | LL | let _ = "key=value".splitn(2, '=').nth(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split('=')` diff --git a/tests/ui/needless_type_cast.fixed b/tests/ui/needless_type_cast.fixed index 72eed32c4d736..921bff5ac6f53 100644 --- a/tests/ui/needless_type_cast.fixed +++ b/tests/ui/needless_type_cast.fixed @@ -1,5 +1,5 @@ #![warn(clippy::needless_type_cast)] -#![allow(clippy::no_effect, clippy::unnecessary_cast, unused)] +#![allow(clippy::unnecessary_cast)] fn takes_i32(x: i32) -> i32 { x diff --git a/tests/ui/needless_type_cast.rs b/tests/ui/needless_type_cast.rs index 31337575fcc31..d112916e3ad2f 100644 --- a/tests/ui/needless_type_cast.rs +++ b/tests/ui/needless_type_cast.rs @@ -1,5 +1,5 @@ #![warn(clippy::needless_type_cast)] -#![allow(clippy::no_effect, clippy::unnecessary_cast, unused)] +#![allow(clippy::unnecessary_cast)] fn takes_i32(x: i32) -> i32 { x diff --git a/tests/ui/needless_update.rs b/tests/ui/needless_update.rs index 62e3492343193..8a701e003ca8f 100644 --- a/tests/ui/needless_update.rs +++ b/tests/ui/needless_update.rs @@ -1,5 +1,5 @@ #![warn(clippy::needless_update)] -#![allow(clippy::no_effect, clippy::unnecessary_struct_initialization)] +#![expect(clippy::no_effect, clippy::unnecessary_struct_initialization)] struct S { pub a: i32, diff --git a/tests/ui/neg_multiply.fixed b/tests/ui/neg_multiply.fixed index 32d466e88fc8b..3c5734c941ad3 100644 --- a/tests/ui/neg_multiply.fixed +++ b/tests/ui/neg_multiply.fixed @@ -1,6 +1,6 @@ #![warn(clippy::neg_multiply)] -#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)] -#![allow(unused)] +#![allow(clippy::precedence)] +#![expect(clippy::no_effect)] use std::ops::Mul; diff --git a/tests/ui/neg_multiply.rs b/tests/ui/neg_multiply.rs index 241a72c6d990d..6364c35ea5efb 100644 --- a/tests/ui/neg_multiply.rs +++ b/tests/ui/neg_multiply.rs @@ -1,6 +1,6 @@ #![warn(clippy::neg_multiply)] -#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)] -#![allow(unused)] +#![allow(clippy::precedence)] +#![expect(clippy::no_effect)] use std::ops::Mul; diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index d61973f09b171..c134c9e53fd1d 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -1,6 +1,5 @@ #![feature(type_alias_impl_trait)] #![warn(clippy::new_ret_no_self)] -#![allow(dead_code)] fn main() {} diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index a758c746f9184..f96d3f3e891ad 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -1,5 +1,5 @@ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:50:5 + --> tests/ui/new_ret_no_self.rs:49:5 | LL | / pub fn new(_: String) -> impl R { LL | | @@ -12,7 +12,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::new_ret_no_self)]` error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:84:5 + --> tests/ui/new_ret_no_self.rs:83:5 | LL | / pub fn new() -> u32 { LL | | @@ -22,7 +22,7 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:95:5 + --> tests/ui/new_ret_no_self.rs:94:5 | LL | / pub fn new(_: String) -> u32 { LL | | @@ -32,7 +32,7 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:133:5 + --> tests/ui/new_ret_no_self.rs:132:5 | LL | / pub fn new() -> (u32, u32) { LL | | @@ -42,7 +42,7 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:162:5 + --> tests/ui/new_ret_no_self.rs:161:5 | LL | / pub fn new() -> *mut V { LL | | @@ -52,7 +52,7 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:182:5 + --> tests/ui/new_ret_no_self.rs:181:5 | LL | / pub fn new() -> Option { LL | | @@ -62,19 +62,19 @@ LL | | } | |_____^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:237:9 + --> tests/ui/new_ret_no_self.rs:236:9 | LL | fn new() -> String; | ^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:250:9 + --> tests/ui/new_ret_no_self.rs:249:9 | LL | fn new(_: String) -> String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:286:9 + --> tests/ui/new_ret_no_self.rs:285:9 | LL | / fn new() -> (u32, u32) { LL | | @@ -84,7 +84,7 @@ LL | | } | |_________^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:315:9 + --> tests/ui/new_ret_no_self.rs:314:9 | LL | / fn new() -> *mut V { LL | | @@ -94,7 +94,7 @@ LL | | } | |_________^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:387:9 + --> tests/ui/new_ret_no_self.rs:386:9 | LL | / fn new(t: T) -> impl Into { LL | | @@ -104,7 +104,7 @@ LL | | } | |_________^ error: methods called `new` usually return `Self` - --> tests/ui/new_ret_no_self.rs:408:9 + --> tests/ui/new_ret_no_self.rs:407:9 | LL | / fn new(t: T) -> impl Trait2<(), i32> { LL | | diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed index f6591820feeb5..a9710996f7df5 100644 --- a/tests/ui/new_without_default.fixed +++ b/tests/ui/new_without_default.fixed @@ -1,19 +1,8 @@ -#![allow( - clippy::missing_safety_doc, - clippy::extra_unused_lifetimes, - clippy::extra_unused_type_parameters, - clippy::needless_lifetimes -)] #![warn(clippy::new_without_default)] +#![expect(clippy::extra_unused_lifetimes, clippy::missing_safety_doc)] pub struct Foo; -impl Default for Foo { - fn default() -> Self { - Self::new() - } -} - impl Foo { pub fn new() -> Foo { //~^ new_without_default @@ -22,14 +11,14 @@ impl Foo { } } -pub struct Bar; - -impl Default for Bar { +impl Default for Foo { fn default() -> Self { Self::new() } } +pub struct Bar; + impl Bar { pub fn new() -> Self { //~^ new_without_default @@ -38,6 +27,12 @@ impl Bar { } } +impl Default for Bar { + fn default() -> Self { + Self::new() + } +} + pub struct Ok; impl Ok { @@ -96,12 +91,6 @@ pub struct LtKo<'a> { foo: &'a bool, } -impl<'c> Default for LtKo<'c> { - fn default() -> Self { - Self::new() - } -} - impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { //~^ new_without_default @@ -110,6 +99,12 @@ impl<'c> LtKo<'c> { } } +impl<'c> Default for LtKo<'c> { + fn default() -> Self { + Self::new() + } +} + struct Private; impl Private { @@ -136,12 +131,6 @@ impl PrivateItem { pub struct Const; -impl Default for Const { - fn default() -> Self { - Self::new() - } -} - impl Const { pub const fn new() -> Const { //~^ new_without_default @@ -149,6 +138,12 @@ impl Const { } // While Default is not const, it can still call const functions, so we should lint this } +impl Default for Const { + fn default() -> Self { + Self::new() + } +} + pub struct IgnoreGenericNew; impl IgnoreGenericNew { @@ -202,12 +197,6 @@ pub struct NewNotEqualToDerive { foo: i32, } -impl Default for NewNotEqualToDerive { - fn default() -> Self { - Self::new() - } -} - impl NewNotEqualToDerive { // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving. pub fn new() -> Self { @@ -217,14 +206,14 @@ impl NewNotEqualToDerive { } } -// see #6933 -pub struct FooGenerics(std::marker::PhantomData); -impl Default for FooGenerics { +impl Default for NewNotEqualToDerive { fn default() -> Self { Self::new() } } +// see #6933 +pub struct FooGenerics(std::marker::PhantomData); impl FooGenerics { pub fn new() -> Self { //~^ new_without_default @@ -233,13 +222,13 @@ impl FooGenerics { } } -pub struct BarGenerics(std::marker::PhantomData); -impl Default for BarGenerics { +impl Default for FooGenerics { fn default() -> Self { Self::new() } } +pub struct BarGenerics(std::marker::PhantomData); impl BarGenerics { pub fn new() -> Self { //~^ new_without_default @@ -248,17 +237,17 @@ impl BarGenerics { } } +impl Default for BarGenerics { + fn default() -> Self { + Self::new() + } +} + pub mod issue7220 { pub struct Foo { _bar: *mut T, } - impl Default for Foo { - fn default() -> Self { - Self::new() - } - } - impl Foo { pub fn new() -> Self { //~^ new_without_default @@ -266,6 +255,12 @@ pub mod issue7220 { todo!() } } + + impl Default for Foo { + fn default() -> Self { + Self::new() + } + } } // see issue #8152 @@ -303,15 +298,6 @@ where _kv: Option<(K, V)>, } -impl Default for MyStruct -where - K: std::hash::Hash + Eq + PartialEq, - { - fn default() -> Self { - Self::new() - } -} - impl MyStruct where K: std::hash::Hash + Eq + PartialEq, @@ -322,16 +308,18 @@ where } } -// From issue #14552, but with `#[cfg]`s that are actually `true` in the uitest context - -pub struct NewWithCfg; -#[cfg(not(test))] -impl Default for NewWithCfg { +impl Default for MyStruct +where + K: std::hash::Hash + Eq + PartialEq, + { fn default() -> Self { Self::new() } } +// From issue #14552, but with `#[cfg]`s that are actually `true` in the uitest context + +pub struct NewWithCfg; impl NewWithCfg { #[cfg(not(test))] pub fn new() -> Self { @@ -340,15 +328,14 @@ impl NewWithCfg { } } -pub struct NewWith2Cfgs; #[cfg(not(test))] -#[cfg(panic = "unwind")] -impl Default for NewWith2Cfgs { +impl Default for NewWithCfg { fn default() -> Self { Self::new() } } +pub struct NewWith2Cfgs; impl NewWith2Cfgs { #[cfg(not(test))] #[cfg(panic = "unwind")] @@ -358,13 +345,15 @@ impl NewWith2Cfgs { } } -pub struct NewWithExtraneous; -impl Default for NewWithExtraneous { +#[cfg(not(test))] +#[cfg(panic = "unwind")] +impl Default for NewWith2Cfgs { fn default() -> Self { Self::new() } } +pub struct NewWithExtraneous; impl NewWithExtraneous { #[inline] pub fn new() -> Self { @@ -373,14 +362,13 @@ impl NewWithExtraneous { } } -pub struct NewWithCfgAndExtraneous; -#[cfg(not(test))] -impl Default for NewWithCfgAndExtraneous { +impl Default for NewWithExtraneous { fn default() -> Self { Self::new() } } +pub struct NewWithCfgAndExtraneous; impl NewWithCfgAndExtraneous { #[cfg(not(test))] #[inline] @@ -390,6 +378,13 @@ impl NewWithCfgAndExtraneous { } } +#[cfg(not(test))] +impl Default for NewWithCfgAndExtraneous { + fn default() -> Self { + Self::new() + } +} + mod issue15778 { pub struct Foo(Vec); @@ -418,16 +413,6 @@ pub mod issue16255 { marker: PhantomData, } - impl Default for Foo - where - T: Display, - T: Clone, - { - fn default() -> Self { - Self::new() - } - } - impl Foo where T: Display, @@ -441,12 +426,9 @@ pub mod issue16255 { } } - pub struct Bar { - marker: PhantomData, - } - - impl Default for Bar + impl Default for Foo where + T: Display, T: Clone, { fn default() -> Self { @@ -454,6 +436,10 @@ pub mod issue16255 { } } + pub struct Bar { + marker: PhantomData, + } + impl Bar { pub fn new() -> Self //~^ new_without_default @@ -463,4 +449,39 @@ pub mod issue16255 { Self { marker: PhantomData } } } + + impl Default for Bar + where + T: Clone, + { + fn default() -> Self { + Self::new() + } + } +} + +pub mod issue17361 { + //! This test ensures that attributes applied to the impl block + //! containing `fn new()` do not get mistakenly applied to the + //! newly generated `Default` trait impl. This has been the + //! case because the `Default` trait impl was inserted right + //! before the existing impl block, but after the attributes. + + #![deny(clippy::unwrap_used, reason = "check that expect below stays put")] + + pub struct S; + + #[expect(clippy::unwrap_used, reason = "without it, new() fails to compile")] + impl S { + pub fn new() -> S { + //~^ new_without_default + std::hint::black_box(Some(S)).unwrap() + } + } + + impl Default for S { + fn default() -> Self { + Self::new() + } + } } diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index d3447f2e16b2e..d6a42036e4014 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -1,10 +1,5 @@ -#![allow( - clippy::missing_safety_doc, - clippy::extra_unused_lifetimes, - clippy::extra_unused_type_parameters, - clippy::needless_lifetimes -)] #![warn(clippy::new_without_default)] +#![expect(clippy::extra_unused_lifetimes, clippy::missing_safety_doc)] pub struct Foo; @@ -360,3 +355,23 @@ pub mod issue16255 { } } } + +pub mod issue17361 { + //! This test ensures that attributes applied to the impl block + //! containing `fn new()` do not get mistakenly applied to the + //! newly generated `Default` trait impl. This has been the + //! case because the `Default` trait impl was inserted right + //! before the existing impl block, but after the attributes. + + #![deny(clippy::unwrap_used, reason = "check that expect below stays put")] + + pub struct S; + + #[expect(clippy::unwrap_used, reason = "without it, new() fails to compile")] + impl S { + pub fn new() -> S { + //~^ new_without_default + std::hint::black_box(Some(S)).unwrap() + } + } +} diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 6c0f73d131853..63a9baa6c5a24 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -1,5 +1,5 @@ error: you should consider adding a `Default` implementation for `Foo` - --> tests/ui/new_without_default.rs:12:5 + --> tests/ui/new_without_default.rs:7:5 | LL | / pub fn new() -> Foo { LL | | @@ -12,6 +12,8 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::new_without_default)]` help: try adding this | +LL ~ } +LL + LL + impl Default for Foo { LL + fn default() -> Self { LL + Self::new() @@ -20,7 +22,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Bar` - --> tests/ui/new_without_default.rs:22:5 + --> tests/ui/new_without_default.rs:17:5 | LL | / pub fn new() -> Self { LL | | @@ -31,6 +33,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + impl Default for Bar { LL + fn default() -> Self { LL + Self::new() @@ -39,7 +43,7 @@ LL + } | error: you should consider adding a `Default` implementation for `LtKo<'c>` - --> tests/ui/new_without_default.rs:88:5 + --> tests/ui/new_without_default.rs:83:5 | LL | / pub fn new() -> LtKo<'c> { LL | | @@ -50,6 +54,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + impl<'c> Default for LtKo<'c> { LL + fn default() -> Self { LL + Self::new() @@ -58,7 +64,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Const` - --> tests/ui/new_without_default.rs:122:5 + --> tests/ui/new_without_default.rs:117:5 | LL | / pub const fn new() -> Const { LL | | @@ -68,6 +74,8 @@ LL | | } // While Default is not const, it can still call const functions, s | help: try adding this | +LL ~ } +LL + LL + impl Default for Const { LL + fn default() -> Self { LL + Self::new() @@ -76,7 +84,7 @@ LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> tests/ui/new_without_default.rs:183:5 + --> tests/ui/new_without_default.rs:178:5 | LL | / pub fn new() -> Self { LL | | @@ -87,6 +95,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + impl Default for NewNotEqualToDerive { LL + fn default() -> Self { LL + Self::new() @@ -95,7 +105,7 @@ LL + } | error: you should consider adding a `Default` implementation for `FooGenerics` - --> tests/ui/new_without_default.rs:193:5 + --> tests/ui/new_without_default.rs:188:5 | LL | / pub fn new() -> Self { LL | | @@ -106,6 +116,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + impl Default for FooGenerics { LL + fn default() -> Self { LL + Self::new() @@ -114,7 +126,7 @@ LL + } | error: you should consider adding a `Default` implementation for `BarGenerics` - --> tests/ui/new_without_default.rs:202:5 + --> tests/ui/new_without_default.rs:197:5 | LL | / pub fn new() -> Self { LL | | @@ -125,6 +137,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + impl Default for BarGenerics { LL + fn default() -> Self { LL + Self::new() @@ -133,7 +147,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo` - --> tests/ui/new_without_default.rs:215:9 + --> tests/ui/new_without_default.rs:210:9 | LL | / pub fn new() -> Self { LL | | @@ -144,17 +158,17 @@ LL | | } | help: try adding this | -LL ~ impl Default for Foo { +LL ~ } +LL + +LL + impl Default for Foo { LL + fn default() -> Self { LL + Self::new() LL + } LL + } -LL + -LL ~ impl Foo { | error: you should consider adding a `Default` implementation for `MyStruct` - --> tests/ui/new_without_default.rs:262:5 + --> tests/ui/new_without_default.rs:257:5 | LL | / pub fn new() -> Self { LL | | @@ -164,6 +178,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + impl Default for MyStruct LL + where LL + K: std::hash::Hash + Eq + PartialEq, @@ -175,7 +191,7 @@ LL + } | error: you should consider adding a `Default` implementation for `NewWithCfg` - --> tests/ui/new_without_default.rs:273:5 + --> tests/ui/new_without_default.rs:268:5 | LL | / pub fn new() -> Self { LL | | @@ -185,6 +201,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + #[cfg(not(test))] LL + impl Default for NewWithCfg { LL + fn default() -> Self { @@ -194,7 +212,7 @@ LL + } | error: you should consider adding a `Default` implementation for `NewWith2Cfgs` - --> tests/ui/new_without_default.rs:283:5 + --> tests/ui/new_without_default.rs:278:5 | LL | / pub fn new() -> Self { LL | | @@ -204,6 +222,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + #[cfg(not(test))] LL + #[cfg(panic = "unwind")] LL + impl Default for NewWith2Cfgs { @@ -214,7 +234,7 @@ LL + } | error: you should consider adding a `Default` implementation for `NewWithExtraneous` - --> tests/ui/new_without_default.rs:292:5 + --> tests/ui/new_without_default.rs:287:5 | LL | / pub fn new() -> Self { LL | | @@ -224,6 +244,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + impl Default for NewWithExtraneous { LL + fn default() -> Self { LL + Self::new() @@ -232,7 +254,7 @@ LL + } | error: you should consider adding a `Default` implementation for `NewWithCfgAndExtraneous` - --> tests/ui/new_without_default.rs:302:5 + --> tests/ui/new_without_default.rs:297:5 | LL | / pub fn new() -> Self { LL | | @@ -242,6 +264,8 @@ LL | | } | help: try adding this | +LL ~ } +LL + LL + #[cfg(not(test))] LL + impl Default for NewWithCfgAndExtraneous { LL + fn default() -> Self { @@ -251,7 +275,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo` - --> tests/ui/new_without_default.rs:340:9 + --> tests/ui/new_without_default.rs:335:9 | LL | / pub fn new() -> Self LL | | @@ -264,7 +288,9 @@ LL | | } | help: try adding this | -LL ~ impl Default for Foo +LL ~ } +LL + +LL + impl Default for Foo LL + where LL + T: Display, LL + T: Clone, @@ -273,12 +299,10 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } -LL + -LL ~ impl Foo | error: you should consider adding a `Default` implementation for `Bar` - --> tests/ui/new_without_default.rs:354:9 + --> tests/ui/new_without_default.rs:349:9 | LL | / pub fn new() -> Self LL | | @@ -291,7 +315,9 @@ LL | | } | help: try adding this | -LL ~ impl Default for Bar +LL ~ } +LL + +LL + impl Default for Bar LL + where LL + T: Clone, LL + { @@ -299,9 +325,27 @@ LL + fn default() -> Self { LL + Self::new() LL + } LL + } + | + +error: you should consider adding a `Default` implementation for `S` + --> tests/ui/new_without_default.rs:372:9 + | +LL | / pub fn new() -> S { +LL | | +LL | | std::hint::black_box(Some(S)).unwrap() +LL | | } + | |_________^ + | +help: try adding this + | +LL ~ } LL + -LL ~ impl Bar { +LL + impl Default for S { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } | -error: aborting due to 15 previous errors +error: aborting due to 16 previous errors diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index 4ab5bc9acdeeb..b4eea30f74b17 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -1,6 +1,6 @@ #![feature(fn_traits, unboxed_closures)] #![warn(clippy::no_effect_underscore_binding)] -#![allow( +#![expect( clippy::deref_addrof, clippy::redundant_field_names, clippy::uninlined_format_args, diff --git a/tests/ui/no_effect_return.rs b/tests/ui/no_effect_return.rs index 4ba2fe07785d0..75c98e59ffc58 100644 --- a/tests/ui/no_effect_return.rs +++ b/tests/ui/no_effect_return.rs @@ -1,5 +1,6 @@ //@no-rustfix: overlapping suggestions -#![allow(clippy::unused_unit, dead_code, unused)] +#![warn(clippy::no_effect)] +#![expect(clippy::unused_unit)] #![no_main] use std::ops::ControlFlow; diff --git a/tests/ui/no_effect_return.stderr b/tests/ui/no_effect_return.stderr index e7bf7e4cd4f43..6300ebfa2442f 100644 --- a/tests/ui/no_effect_return.stderr +++ b/tests/ui/no_effect_return.stderr @@ -1,5 +1,5 @@ error: statement with no effect - --> tests/ui/no_effect_return.rs:9:9 + --> tests/ui/no_effect_return.rs:10:9 | LL | 0u32; | -^^^^ @@ -10,7 +10,7 @@ LL | 0u32; = help: to override `-D warnings` add `#[allow(clippy::no_effect)]` error: statement with no effect - --> tests/ui/no_effect_return.rs:17:9 + --> tests/ui/no_effect_return.rs:18:9 | LL | 0u32; | -^^^^ @@ -18,7 +18,7 @@ LL | 0u32; | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:26:9 + --> tests/ui/no_effect_return.rs:27:9 | LL | 0i32 as C; | -^^^^^^^^^ @@ -26,19 +26,19 @@ LL | 0i32 as C; | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:35:9 + --> tests/ui/no_effect_return.rs:36:9 | LL | 0u128; | ^^^^^^ error: statement with no effect - --> tests/ui/no_effect_return.rs:46:9 + --> tests/ui/no_effect_return.rs:47:9 | LL | 0u16; | ^^^^^ error: statement with no effect - --> tests/ui/no_effect_return.rs:54:9 + --> tests/ui/no_effect_return.rs:55:9 | LL | [1u16]; | -^^^^^^ @@ -46,7 +46,7 @@ LL | [1u16]; | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:62:9 + --> tests/ui/no_effect_return.rs:63:9 | LL | ControlFlow::Break::<()>(()); | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,13 +54,13 @@ LL | ControlFlow::Break::<()>(()); | help: did you mean to return it?: `return` error: statement with no effect - --> tests/ui/no_effect_return.rs:80:9 + --> tests/ui/no_effect_return.rs:81:9 | LL | (); | ^^^ error: statement with no effect - --> tests/ui/no_effect_return.rs:89:9 + --> tests/ui/no_effect_return.rs:90:9 | LL | (); | ^^^ diff --git a/tests/ui/no_mangle_with_rust_abi.rs b/tests/ui/no_mangle_with_rust_abi.rs index f4248ffc0f4d0..4c61b742a0e67 100644 --- a/tests/ui/no_mangle_with_rust_abi.rs +++ b/tests/ui/no_mangle_with_rust_abi.rs @@ -1,5 +1,4 @@ //@no-rustfix: overlapping suggestions -#![allow(unused)] #![warn(clippy::no_mangle_with_rust_abi)] #[unsafe(no_mangle)] diff --git a/tests/ui/no_mangle_with_rust_abi.stderr b/tests/ui/no_mangle_with_rust_abi.stderr index 871f38e94b632..a3dd4ea9e985b 100644 --- a/tests/ui/no_mangle_with_rust_abi.stderr +++ b/tests/ui/no_mangle_with_rust_abi.stderr @@ -1,5 +1,5 @@ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:6:1 + --> tests/ui/no_mangle_with_rust_abi.rs:5:1 | LL | fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | extern "Rust" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:10:1 + --> tests/ui/no_mangle_with_rust_abi.rs:9:1 | LL | pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | pub extern "Rust" fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:16:1 + --> tests/ui/no_mangle_with_rust_abi.rs:15:1 | LL | pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | pub unsafe extern "Rust" fn rust_abi_fn_three(arg_one: u32, arg_two: usize) | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:22:1 + --> tests/ui/no_mangle_with_rust_abi.rs:21:1 | LL | unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | unsafe extern "Rust" fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:26:1 + --> tests/ui/no_mangle_with_rust_abi.rs:25:1 | LL | / fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( LL | | @@ -80,7 +80,7 @@ LL | extern "Rust" fn rust_abi_multiline_function_really_long_name_to_overflow_a | +++++++++++++ error: `#[unsafe(no_mangle)]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi.rs:52:5 + --> tests/ui/no_mangle_with_rust_abi.rs:51:5 | LL | pub(in super::r#fn) fn with_some_fn_around() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/no_mangle_with_rust_abi_2021.rs b/tests/ui/no_mangle_with_rust_abi_2021.rs index 3d5c70cad2f3e..e390e95460051 100644 --- a/tests/ui/no_mangle_with_rust_abi_2021.rs +++ b/tests/ui/no_mangle_with_rust_abi_2021.rs @@ -3,7 +3,6 @@ // Edition 2024 requires the use of #[unsafe(no_mangle)] //@no-rustfix: overlapping suggestions -#![allow(unused)] #![warn(clippy::no_mangle_with_rust_abi)] #[no_mangle] diff --git a/tests/ui/no_mangle_with_rust_abi_2021.stderr b/tests/ui/no_mangle_with_rust_abi_2021.stderr index abae8fafbeeef..e0d5e90460df1 100644 --- a/tests/ui/no_mangle_with_rust_abi_2021.stderr +++ b/tests/ui/no_mangle_with_rust_abi_2021.stderr @@ -1,5 +1,5 @@ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi_2021.rs:10:1 + --> tests/ui/no_mangle_with_rust_abi_2021.rs:9:1 | LL | fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | extern "Rust" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi_2021.rs:14:1 + --> tests/ui/no_mangle_with_rust_abi_2021.rs:13:1 | LL | pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | pub extern "Rust" fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi_2021.rs:20:1 + --> tests/ui/no_mangle_with_rust_abi_2021.rs:19:1 | LL | pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | pub unsafe extern "Rust" fn rust_abi_fn_three(arg_one: u32, arg_two: usize) | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi_2021.rs:26:1 + --> tests/ui/no_mangle_with_rust_abi_2021.rs:25:1 | LL | unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | unsafe extern "Rust" fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> tests/ui/no_mangle_with_rust_abi_2021.rs:30:1 + --> tests/ui/no_mangle_with_rust_abi_2021.rs:29:1 | LL | / fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( LL | | diff --git a/tests/ui/non_ascii_literal_unfixable.rs b/tests/ui/non_ascii_literal_unfixable.rs new file mode 100644 index 0000000000000..d5a5a62a8e826 --- /dev/null +++ b/tests/ui/non_ascii_literal_unfixable.rs @@ -0,0 +1,16 @@ +//@no-rustfix +#![warn(clippy::non_ascii_literal)] +#![allow(dead_code)] + +fn non_ascii() { + print!(r"€"); + //~^ non_ascii_literal + print!(r"Üben!"); + //~^ non_ascii_literal + print!(r"an en dash –"); + //~^ non_ascii_literal + print!(r#"€ between hashes"#); + //~^ non_ascii_literal +} + +fn main() {} diff --git a/tests/ui/non_ascii_literal_unfixable.stderr b/tests/ui/non_ascii_literal_unfixable.stderr new file mode 100644 index 0000000000000..28bb91b184025 --- /dev/null +++ b/tests/ui/non_ascii_literal_unfixable.stderr @@ -0,0 +1,36 @@ +error: literal non-ASCII character detected + --> tests/ui/non_ascii_literal_unfixable.rs:6:12 + | +LL | print!(r"€"); + | ^^^^ + | + = help: use a normal string literal instead of a raw one to escape the character + = note: `-D clippy::non-ascii-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_ascii_literal)]` + +error: literal non-ASCII character detected + --> tests/ui/non_ascii_literal_unfixable.rs:8:12 + | +LL | print!(r"Üben!"); + | ^^^^^^^^ + | + = help: use a normal string literal instead of a raw one to escape the character + +error: literal non-ASCII character detected + --> tests/ui/non_ascii_literal_unfixable.rs:10:12 + | +LL | print!(r"an en dash –"); + | ^^^^^^^^^^^^^^^ + | + = help: use a normal string literal instead of a raw one to escape the character + +error: literal non-ASCII character detected + --> tests/ui/non_ascii_literal_unfixable.rs:12:12 + | +LL | print!(r#"€ between hashes"#); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: use a normal string literal instead of a raw one to escape the character + +error: aborting due to 4 previous errors + diff --git a/tests/ui/non_canonical_clone_impl.fixed b/tests/ui/non_canonical_clone_impl.fixed index 3e2ffaf014680..466a1304e72c5 100644 --- a/tests/ui/non_canonical_clone_impl.fixed +++ b/tests/ui/non_canonical_clone_impl.fixed @@ -1,5 +1,5 @@ //@aux-build:proc_macro_derive.rs -#![allow(clippy::clone_on_copy, unused)] +#![expect(clippy::clone_on_copy)] #![allow(clippy::assigning_clones)] #![no_main] diff --git a/tests/ui/non_canonical_clone_impl.rs b/tests/ui/non_canonical_clone_impl.rs index abe3883207522..5f815b567dfc7 100644 --- a/tests/ui/non_canonical_clone_impl.rs +++ b/tests/ui/non_canonical_clone_impl.rs @@ -1,5 +1,5 @@ //@aux-build:proc_macro_derive.rs -#![allow(clippy::clone_on_copy, unused)] +#![expect(clippy::clone_on_copy)] #![allow(clippy::assigning_clones)] #![no_main] diff --git a/tests/ui/non_expressive_names.rs b/tests/ui/non_expressive_names.rs index 3f34dff563d26..1260d009ada0f 100644 --- a/tests/ui/non_expressive_names.rs +++ b/tests/ui/non_expressive_names.rs @@ -1,4 +1,5 @@ -#![allow(clippy::println_empty_string, non_snake_case, clippy::let_unit_value)] +#![warn(clippy::just_underscores_and_digits)] +#![expect(non_snake_case)] #[derive(Clone, Debug)] enum MaybeInst { diff --git a/tests/ui/non_expressive_names.stderr b/tests/ui/non_expressive_names.stderr index 11b12d2c5f103..3bd77a730fe78 100644 --- a/tests/ui/non_expressive_names.stderr +++ b/tests/ui/non_expressive_names.stderr @@ -1,5 +1,5 @@ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:27:9 + --> tests/ui/non_expressive_names.rs:28:9 | LL | let _1 = 1; | ^^ @@ -8,31 +8,31 @@ LL | let _1 = 1; = help: to override `-D warnings` add `#[allow(clippy::just_underscores_and_digits)]` error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:29:9 + --> tests/ui/non_expressive_names.rs:30:9 | LL | let ____1 = 1; | ^^^^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:31:9 + --> tests/ui/non_expressive_names.rs:32:9 | LL | let __1___2 = 12; | ^^^^^^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:53:13 + --> tests/ui/non_expressive_names.rs:54:13 | LL | let _1 = 1; | ^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:55:13 + --> tests/ui/non_expressive_names.rs:56:13 | LL | let ____1 = 1; | ^^^^^ error: consider choosing a more descriptive name - --> tests/ui/non_expressive_names.rs:57:13 + --> tests/ui/non_expressive_names.rs:58:13 | LL | let __1___2 = 12; | ^^^^^^^ diff --git a/tests/ui/non_minimal_cfg.fixed b/tests/ui/non_minimal_cfg.fixed index a2b69d0662ee9..c3b94bdf53f6a 100644 --- a/tests/ui/non_minimal_cfg.fixed +++ b/tests/ui/non_minimal_cfg.fixed @@ -1,5 +1,4 @@ -#![allow(unused)] - +#![warn(clippy::non_minimal_cfg)] #[cfg(windows)] //~^ non_minimal_cfg fn hermit() {} diff --git a/tests/ui/non_minimal_cfg.rs b/tests/ui/non_minimal_cfg.rs index 7178cd189c08d..e28d4fd756d5e 100644 --- a/tests/ui/non_minimal_cfg.rs +++ b/tests/ui/non_minimal_cfg.rs @@ -1,5 +1,4 @@ -#![allow(unused)] - +#![warn(clippy::non_minimal_cfg)] #[cfg(all(windows))] //~^ non_minimal_cfg fn hermit() {} diff --git a/tests/ui/non_minimal_cfg.stderr b/tests/ui/non_minimal_cfg.stderr index 3bf306dd89c2f..cd09972454a46 100644 --- a/tests/ui/non_minimal_cfg.stderr +++ b/tests/ui/non_minimal_cfg.stderr @@ -1,5 +1,5 @@ error: unneeded sub `cfg` when there is only one condition - --> tests/ui/non_minimal_cfg.rs:3:7 + --> tests/ui/non_minimal_cfg.rs:2:7 | LL | #[cfg(all(windows))] | ^^^^^^^^^^^^ help: try: `windows` @@ -8,19 +8,19 @@ LL | #[cfg(all(windows))] = help: to override `-D warnings` add `#[allow(clippy::non_minimal_cfg)]` error: unneeded sub `cfg` when there is only one condition - --> tests/ui/non_minimal_cfg.rs:7:7 + --> tests/ui/non_minimal_cfg.rs:6:7 | LL | #[cfg(any(windows))] | ^^^^^^^^^^^^ help: try: `windows` error: unneeded sub `cfg` when there is only one condition - --> tests/ui/non_minimal_cfg.rs:11:11 + --> tests/ui/non_minimal_cfg.rs:10:11 | LL | #[cfg(all(any(unix), all(not(windows))))] | ^^^^^^^^^ help: try: `unix` error: unneeded sub `cfg` when there is only one condition - --> tests/ui/non_minimal_cfg.rs:11:22 + --> tests/ui/non_minimal_cfg.rs:10:22 | LL | #[cfg(all(any(unix), all(not(windows))))] | ^^^^^^^^^^^^^^^^^ help: try: `not(windows)` diff --git a/tests/ui/non_minimal_cfg2.rs b/tests/ui/non_minimal_cfg2.rs index d073feedb1da2..11e28339aac16 100644 --- a/tests/ui/non_minimal_cfg2.rs +++ b/tests/ui/non_minimal_cfg2.rs @@ -1,9 +1,7 @@ -//@require-annotations-for-level: WARN -#![allow(unused)] +#![warn(clippy::non_minimal_cfg)] +//~v non_minimal_cfg #[cfg(all())] -//~^ ERROR: unneeded sub `cfg` when there is no condition -//~| NOTE: `-D clippy::non-minimal-cfg` implied by `-D warnings` fn all() {} fn main() {} diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.fixed b/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.fixed index d6c35d8097c51..cb783e72dd2c7 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.fixed +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.fixed @@ -2,7 +2,7 @@ //@aux-build:lazy_static.rs #![warn(clippy::non_std_lazy_statics)] -#![allow(static_mut_refs)] +#![expect(static_mut_refs)] use once_cell::sync::Lazy; diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs b/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs index 996ef050d6915..5681af42fd923 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.rs @@ -2,7 +2,7 @@ //@aux-build:lazy_static.rs #![warn(clippy::non_std_lazy_statics)] -#![allow(static_mut_refs)] +#![expect(static_mut_refs)] use once_cell::sync::Lazy; diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.rs b/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.rs index acc8c04678f50..e6532bd8057ea 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.rs +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_unfixable.rs @@ -3,7 +3,7 @@ //@no-rustfix #![warn(clippy::non_std_lazy_statics)] -#![allow(static_mut_refs)] +#![expect(static_mut_refs)] mod once_cell_lazy { use once_cell::sync::Lazy; diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index d040ba6ee83cb..85e74d74d7b9b 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -1,11 +1,10 @@ //@no-rustfix: overlapping suggestions -#![allow( - unused, +#![warn(clippy::nonminimal_bool)] +#![expect( clippy::diverging_sub_expression, clippy::needless_ifs, clippy::redundant_pattern_matching )] -#![warn(clippy::nonminimal_bool)] #![allow(clippy::useless_vec)] fn main() { diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index 29387cf31ee8b..5197f105da448 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:17:13 + --> tests/ui/nonminimal_bool.rs:16:13 | LL | let _ = !true; | ^^^^^ @@ -13,7 +13,7 @@ LL + let _ = false; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:20:13 + --> tests/ui/nonminimal_bool.rs:19:13 | LL | let _ = !false; | ^^^^^^ @@ -25,7 +25,7 @@ LL + let _ = true; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:23:13 + --> tests/ui/nonminimal_bool.rs:22:13 | LL | let _ = !!a; | ^^^ @@ -37,7 +37,7 @@ LL + let _ = a; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:26:13 + --> tests/ui/nonminimal_bool.rs:25:13 | LL | let _ = false || a; | ^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + let _ = a; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:32:13 + --> tests/ui/nonminimal_bool.rs:31:13 | LL | let _ = !(!a && b); | ^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let _ = a || !b; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:35:13 + --> tests/ui/nonminimal_bool.rs:34:13 | LL | let _ = !(!a || b); | ^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + let _ = a && !b; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:38:13 + --> tests/ui/nonminimal_bool.rs:37:13 | LL | let _ = !a && !(b && c); | ^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + let _ = !(a || b && c); | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:47:13 + --> tests/ui/nonminimal_bool.rs:46:13 | LL | let _ = a == b && c == 5 && a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL + let _ = a == b && c == 5; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:50:13 + --> tests/ui/nonminimal_bool.rs:49:13 | LL | let _ = a == b || c == 5 || a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -115,7 +115,7 @@ LL + let _ = a == b || c == 5; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:53:13 + --> tests/ui/nonminimal_bool.rs:52:13 | LL | let _ = a == b && c == 5 && b == a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -130,7 +130,7 @@ LL + let _ = a == b && c == 5; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:56:13 + --> tests/ui/nonminimal_bool.rs:55:13 | LL | let _ = a != b || !(a != b || c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + let _ = a != b || c != d; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:59:13 + --> tests/ui/nonminimal_bool.rs:58:13 | LL | let _ = a != b && !(a != b && c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -160,7 +160,7 @@ LL + let _ = a != b && c != d; | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:90:8 + --> tests/ui/nonminimal_bool.rs:89:8 | LL | if matches!(true, true) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -172,37 +172,37 @@ LL + if matches!(true, true) { | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:171:8 + --> tests/ui/nonminimal_bool.rs:170:8 | LL | if !(12 == a) {} | ^^^^^^^^^^ help: try: `(12 != a)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:173:8 + --> tests/ui/nonminimal_bool.rs:172:8 | LL | if !(a == 12) {} | ^^^^^^^^^^ help: try: `(a != 12)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:175:8 + --> tests/ui/nonminimal_bool.rs:174:8 | LL | if !(12 != a) {} | ^^^^^^^^^^ help: try: `(12 == a)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:177:8 + --> tests/ui/nonminimal_bool.rs:176:8 | LL | if !(a != 12) {} | ^^^^^^^^^^ help: try: `(a == 12)` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:182:8 + --> tests/ui/nonminimal_bool.rs:181:8 | LL | if !b == true {} | ^^^^^^^^^^ help: try: `b != true` error: equality checks against true are unnecessary - --> tests/ui/nonminimal_bool.rs:182:8 + --> tests/ui/nonminimal_bool.rs:181:8 | LL | if !b == true {} | ^^^^^^^^^^ help: try: `!b` @@ -211,55 +211,55 @@ LL | if !b == true {} = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:185:8 + --> tests/ui/nonminimal_bool.rs:184:8 | LL | if !b != true {} | ^^^^^^^^^^ help: try: `b == true` error: inequality checks against true can be replaced by a negation - --> tests/ui/nonminimal_bool.rs:185:8 + --> tests/ui/nonminimal_bool.rs:184:8 | LL | if !b != true {} | ^^^^^^^^^^ help: try: `b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:188:8 + --> tests/ui/nonminimal_bool.rs:187:8 | LL | if true == !b {} | ^^^^^^^^^^ help: try: `true != b` error: equality checks against true are unnecessary - --> tests/ui/nonminimal_bool.rs:188:8 + --> tests/ui/nonminimal_bool.rs:187:8 | LL | if true == !b {} | ^^^^^^^^^^ help: try: `!b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:191:8 + --> tests/ui/nonminimal_bool.rs:190:8 | LL | if true != !b {} | ^^^^^^^^^^ help: try: `true == b` error: inequality checks against true can be replaced by a negation - --> tests/ui/nonminimal_bool.rs:191:8 + --> tests/ui/nonminimal_bool.rs:190:8 | LL | if true != !b {} | ^^^^^^^^^^ help: try: `b` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:194:8 + --> tests/ui/nonminimal_bool.rs:193:8 | LL | if !b == !c {} | ^^^^^^^^ help: try: `b == c` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:196:8 + --> tests/ui/nonminimal_bool.rs:195:8 | LL | if !b != !c {} | ^^^^^^^^ help: try: `b != c` error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:212:8 + --> tests/ui/nonminimal_bool.rs:211:8 | LL | if !(a < 2.0 && !b) { | ^^^^^^^^^^^^^^^^ @@ -271,7 +271,7 @@ LL + if a >= 2.0 || b { | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:231:12 + --> tests/ui/nonminimal_bool.rs:230:12 | LL | if !(matches!(ty, TyKind::Ref(_, _, _)) && !is_mutable(&expr)) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -283,13 +283,13 @@ LL + if !matches!(ty, TyKind::Ref(_, _, _)) || is_mutable(&expr) { | error: this boolean expression can be simplified - --> tests/ui/nonminimal_bool.rs:251:8 + --> tests/ui/nonminimal_bool.rs:250:8 | LL | if !S != true {} | ^^^^^^^^^^ help: try: `S == true` error: inequality checks against true can be replaced by a negation - --> tests/ui/nonminimal_bool.rs:251:8 + --> tests/ui/nonminimal_bool.rs:250:8 | LL | if !S != true {} | ^^^^^^^^^^ help: try: `!!S` diff --git a/tests/ui/nonminimal_bool_methods.fixed b/tests/ui/nonminimal_bool_methods.fixed index 0de944f9edcfe..9ce11b8afb865 100644 --- a/tests/ui/nonminimal_bool_methods.fixed +++ b/tests/ui/nonminimal_bool_methods.fixed @@ -1,5 +1,5 @@ -#![allow(unused, clippy::diverging_sub_expression, clippy::needless_ifs)] #![warn(clippy::nonminimal_bool)] +#![expect(clippy::diverging_sub_expression, clippy::needless_ifs)] fn methods_with_negation() { let a: Option = unimplemented!(); diff --git a/tests/ui/nonminimal_bool_methods.rs b/tests/ui/nonminimal_bool_methods.rs index ac0bd6d8a4910..75ecafdc7c389 100644 --- a/tests/ui/nonminimal_bool_methods.rs +++ b/tests/ui/nonminimal_bool_methods.rs @@ -1,5 +1,5 @@ -#![allow(unused, clippy::diverging_sub_expression, clippy::needless_ifs)] #![warn(clippy::nonminimal_bool)] +#![expect(clippy::diverging_sub_expression, clippy::needless_ifs)] fn methods_with_negation() { let a: Option = unimplemented!(); diff --git a/tests/ui/obfuscated_if_else.fixed b/tests/ui/obfuscated_if_else.fixed index 6bdb170a4aa90..df0fabbf5ae48 100644 --- a/tests/ui/obfuscated_if_else.fixed +++ b/tests/ui/obfuscated_if_else.fixed @@ -1,7 +1,7 @@ #![warn(clippy::obfuscated_if_else)] #![allow( - clippy::unnecessary_lazy_evaluations, clippy::unit_arg, + clippy::unnecessary_lazy_evaluations, clippy::unused_unit, clippy::unwrap_or_default )] diff --git a/tests/ui/obfuscated_if_else.rs b/tests/ui/obfuscated_if_else.rs index f7b5ea8c01354..24197c7b2ab37 100644 --- a/tests/ui/obfuscated_if_else.rs +++ b/tests/ui/obfuscated_if_else.rs @@ -1,7 +1,7 @@ #![warn(clippy::obfuscated_if_else)] #![allow( - clippy::unnecessary_lazy_evaluations, clippy::unit_arg, + clippy::unnecessary_lazy_evaluations, clippy::unused_unit, clippy::unwrap_or_default )] diff --git a/tests/ui/ok_expect.fixed b/tests/ui/ok_expect.fixed index 2a05b8805e4d5..0101fd69d054c 100644 --- a/tests/ui/ok_expect.fixed +++ b/tests/ui/ok_expect.fixed @@ -1,4 +1,5 @@ -#![allow(clippy::unnecessary_literal_unwrap)] +#![warn(clippy::ok_expect)] +#![expect(clippy::unnecessary_literal_unwrap)] use std::io; diff --git a/tests/ui/ok_expect.rs b/tests/ui/ok_expect.rs index 3761aa26f6e81..98a74966062fc 100644 --- a/tests/ui/ok_expect.rs +++ b/tests/ui/ok_expect.rs @@ -1,4 +1,5 @@ -#![allow(clippy::unnecessary_literal_unwrap)] +#![warn(clippy::ok_expect)] +#![expect(clippy::unnecessary_literal_unwrap)] use std::io; diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr index 848a10e671dbf..2dc14f3db5755 100644 --- a/tests/ui/ok_expect.stderr +++ b/tests/ui/ok_expect.stderr @@ -1,5 +1,5 @@ error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:16:5 + --> tests/ui/ok_expect.rs:17:5 | LL | res.ok().expect("disaster!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + res.expect("disaster!"); | error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:19:5 + --> tests/ui/ok_expect.rs:20:5 | LL | / res.ok() LL | | .expect("longlonglonglonglonglonglonglonglonglonglonglonglonglong"); @@ -27,7 +27,7 @@ LL + res.expect("longlonglonglonglonglonglonglonglonglonglonglonglonglong"); | error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:24:5 + --> tests/ui/ok_expect.rs:25:5 | LL | / resres LL | | .ok() @@ -43,7 +43,7 @@ LL + resres.expect("longlonglonglonglonglonglonglonglonglonglonglonglonglong | error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:30:5 + --> tests/ui/ok_expect.rs:31:5 | LL | / std::process::Command::new("rustc") LL | | .arg("-vV") @@ -61,7 +61,7 @@ LL + .output().expect("failed to get rustc version"); | error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:42:5 + --> tests/ui/ok_expect.rs:43:5 | LL | res3.ok().expect("whoof"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + res3.expect("whoof"); | error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:46:5 + --> tests/ui/ok_expect.rs:47:5 | LL | res4.ok().expect("argh"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + res4.expect("argh"); | error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:50:5 + --> tests/ui/ok_expect.rs:51:5 | LL | res5.ok().expect("oops"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + res5.expect("oops"); | error: called `ok().expect()` on a `Result` value - --> tests/ui/ok_expect.rs:54:5 + --> tests/ui/ok_expect.rs:55:5 | LL | res6.ok().expect("meh"); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/only_used_in_recursion.rs b/tests/ui/only_used_in_recursion.rs index d58635969238b..0222ff1e899b2 100644 --- a/tests/ui/only_used_in_recursion.rs +++ b/tests/ui/only_used_in_recursion.rs @@ -1,5 +1,4 @@ -#![warn(clippy::only_used_in_recursion)] -#![warn(clippy::self_only_used_in_recursion)] +#![warn(clippy::only_used_in_recursion, clippy::self_only_used_in_recursion)] //@no-rustfix fn _simple(x: u32) -> u32 { x diff --git a/tests/ui/only_used_in_recursion.stderr b/tests/ui/only_used_in_recursion.stderr index 5d1e3e9c50fd9..fad9395541627 100644 --- a/tests/ui/only_used_in_recursion.stderr +++ b/tests/ui/only_used_in_recursion.stderr @@ -1,11 +1,11 @@ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:12:27 + --> tests/ui/only_used_in_recursion.rs:11:27 | LL | fn _one_unused(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:15:53 + --> tests/ui/only_used_in_recursion.rs:14:53 | LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) } | ^ @@ -13,121 +13,121 @@ LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) } = help: to override `-D warnings` add `#[allow(clippy::only_used_in_recursion)]` error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:18:27 + --> tests/ui/only_used_in_recursion.rs:17:27 | LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:22:53 + --> tests/ui/only_used_in_recursion.rs:21:53 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:18:35 + --> tests/ui/only_used_in_recursion.rs:17:35 | LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:22:56 + --> tests/ui/only_used_in_recursion.rs:21:56 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:25:26 + --> tests/ui/only_used_in_recursion.rs:24:26 | LL | fn _with_calc(flag: u32, a: i64) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:31:32 + --> tests/ui/only_used_in_recursion.rs:30:32 | LL | _with_calc(flag - 1, (-a + 10) * 5) | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:40:33 + --> tests/ui/only_used_in_recursion.rs:39:33 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:47:38 + --> tests/ui/only_used_in_recursion.rs:46:38 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:40:41 + --> tests/ui/only_used_in_recursion.rs:39:41 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:47:45 + --> tests/ui/only_used_in_recursion.rs:46:45 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:51:35 + --> tests/ui/only_used_in_recursion.rs:50:35 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:58:39 + --> tests/ui/only_used_in_recursion.rs:57:39 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:51:43 + --> tests/ui/only_used_in_recursion.rs:50:43 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:58:43 + --> tests/ui/only_used_in_recursion.rs:57:43 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:62:30 + --> tests/ui/only_used_in_recursion.rs:61:30 | LL | fn _not_primitive(flag: u32, b: String) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:65:56 + --> tests/ui/only_used_in_recursion.rs:64:56 | LL | if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:71:29 + --> tests/ui/only_used_in_recursion.rs:70:29 | LL | fn _method(flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:74:59 + --> tests/ui/only_used_in_recursion.rs:73:59 | LL | if flag == 0 { 0 } else { Self::_method(flag - 1, a) } | ^ error: `self` is only used in recursion - --> tests/ui/only_used_in_recursion.rs:77:22 + --> tests/ui/only_used_in_recursion.rs:76:22 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^^^^ | note: `self` used here - --> tests/ui/only_used_in_recursion.rs:81:35 + --> tests/ui/only_used_in_recursion.rs:80:35 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^^^^ @@ -135,61 +135,61 @@ LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } = help: to override `-D warnings` add `#[allow(clippy::self_only_used_in_recursion)]` error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:77:41 + --> tests/ui/only_used_in_recursion.rs:76:41 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:81:63 + --> tests/ui/only_used_in_recursion.rs:80:63 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:91:26 + --> tests/ui/only_used_in_recursion.rs:90:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:94:58 + --> tests/ui/only_used_in_recursion.rs:93:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:97:38 + --> tests/ui/only_used_in_recursion.rs:96:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:100:62 + --> tests/ui/only_used_in_recursion.rs:99:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:125:26 + --> tests/ui/only_used_in_recursion.rs:124:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:128:58 + --> tests/ui/only_used_in_recursion.rs:127:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> tests/ui/only_used_in_recursion.rs:131:38 + --> tests/ui/only_used_in_recursion.rs:130:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> tests/ui/only_used_in_recursion.rs:134:62 + --> tests/ui/only_used_in_recursion.rs:133:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ diff --git a/tests/ui/op_ref.fixed b/tests/ui/op_ref.fixed index fe4a48989b0fb..9c396e6ade503 100644 --- a/tests/ui/op_ref.fixed +++ b/tests/ui/op_ref.fixed @@ -1,5 +1,5 @@ -#![allow(unused_variables, clippy::disallowed_names)] #![warn(clippy::op_ref)] +#![expect(clippy::disallowed_names)] use std::collections::HashSet; use std::ops::{BitAnd, Mul}; diff --git a/tests/ui/op_ref.rs b/tests/ui/op_ref.rs index cd0d231497abc..b803a7cc09d95 100644 --- a/tests/ui/op_ref.rs +++ b/tests/ui/op_ref.rs @@ -1,5 +1,5 @@ -#![allow(unused_variables, clippy::disallowed_names)] #![warn(clippy::op_ref)] +#![expect(clippy::disallowed_names)] use std::collections::HashSet; use std::ops::{BitAnd, Mul}; diff --git a/tests/ui/open_options.rs b/tests/ui/open_options.rs index f2f6e6edb4de2..ebde82fa8f6cb 100644 --- a/tests/ui/open_options.rs +++ b/tests/ui/open_options.rs @@ -1,4 +1,3 @@ -#![allow(unused_must_use)] #![warn(clippy::nonsensical_open_options)] use std::fs::OpenOptions; diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr index 11b2d55fa0582..85b3e6a72fc49 100644 --- a/tests/ui/open_options.stderr +++ b/tests/ui/open_options.stderr @@ -1,5 +1,5 @@ error: file opened with `truncate` and `read` - --> tests/ui/open_options.rs:17:5 + --> tests/ui/open_options.rs:16:5 | LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,43 +8,43 @@ LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); = help: to override `-D warnings` add `#[allow(clippy::nonsensical_open_options)]` error: file opened with `append` and `truncate` - --> tests/ui/open_options.rs:20:5 + --> tests/ui/open_options.rs:19:5 | LL | OpenOptions::new().append(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `read` is called more than once - --> tests/ui/open_options.rs:23:35 + --> tests/ui/open_options.rs:22:35 | LL | OpenOptions::new().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^ error: the method `create` is called more than once - --> tests/ui/open_options.rs:29:10 + --> tests/ui/open_options.rs:28:10 | LL | .create(false) | ^^^^^^^^^^^^^ error: the method `write` is called more than once - --> tests/ui/open_options.rs:32:36 + --> tests/ui/open_options.rs:31:36 | LL | OpenOptions::new().write(true).write(false).open("foo.txt"); | ^^^^^^^^^^^^ error: the method `append` is called more than once - --> tests/ui/open_options.rs:35:37 + --> tests/ui/open_options.rs:34:37 | LL | OpenOptions::new().append(true).append(false).open("foo.txt"); | ^^^^^^^^^^^^^ error: the method `truncate` is called more than once - --> tests/ui/open_options.rs:38:39 + --> tests/ui/open_options.rs:37:39 | LL | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); | ^^^^^^^^^^^^^^^ error: the method `read` is called more than once - --> tests/ui/open_options.rs:41:41 + --> tests/ui/open_options.rs:40:41 | LL | std::fs::File::options().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^ diff --git a/tests/ui/option_as_ref_deref.fixed b/tests/ui/option_as_ref_deref.fixed index 9be89b5d484f6..d2b9c907e6c13 100644 --- a/tests/ui/option_as_ref_deref.fixed +++ b/tests/ui/option_as_ref_deref.fixed @@ -1,5 +1,5 @@ -#![allow(unused, clippy::redundant_clone, clippy::useless_vec)] #![warn(clippy::option_as_ref_deref)] +#![expect(clippy::useless_vec)] use std::ffi::{CString, OsString}; use std::ops::{Deref, DerefMut}; diff --git a/tests/ui/option_as_ref_deref.rs b/tests/ui/option_as_ref_deref.rs index d6b29e5e61b1f..9f7c8c53434b1 100644 --- a/tests/ui/option_as_ref_deref.rs +++ b/tests/ui/option_as_ref_deref.rs @@ -1,5 +1,5 @@ -#![allow(unused, clippy::redundant_clone, clippy::useless_vec)] #![warn(clippy::option_as_ref_deref)] +#![expect(clippy::useless_vec)] use std::ffi::{CString, OsString}; use std::ops::{Deref, DerefMut}; diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs index b8476830efe58..0dfe61277a2c1 100644 --- a/tests/ui/option_env_unwrap.rs +++ b/tests/ui/option_env_unwrap.rs @@ -1,6 +1,5 @@ //@aux-build:proc_macros.rs #![warn(clippy::option_env_unwrap)] -#![allow(clippy::map_flatten)] extern crate proc_macros; use proc_macros::{external, inline_macros}; diff --git a/tests/ui/option_env_unwrap.stderr b/tests/ui/option_env_unwrap.stderr index c14a3ea23ff3e..7026a5e9c3882 100644 --- a/tests/ui/option_env_unwrap.stderr +++ b/tests/ui/option_env_unwrap.stderr @@ -1,5 +1,5 @@ error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:10:13 + --> tests/ui/option_env_unwrap.rs:9:13 | LL | let _ = option_env!("PATH").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | let _ = option_env!("PATH").unwrap(); = help: to override `-D warnings` add `#[allow(clippy::option_env_unwrap)]` error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:12:13 + --> tests/ui/option_env_unwrap.rs:11:13 | LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:14:13 + --> tests/ui/option_env_unwrap.rs:13:13 | LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in you... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only work = help: consider using the `env!` macro instead error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:17:21 + --> tests/ui/option_env_unwrap.rs:16:21 | LL | let _ = inline!(option_env!($"PATH").unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let _ = inline!(option_env!($"PATH").unwrap()); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:19:21 + --> tests/ui/option_env_unwrap.rs:18:21 | LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH isn't set")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:21:13 + --> tests/ui/option_env_unwrap.rs:20:13 | LL | let _ = external!(option_env!($"PATH").unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | let _ = external!(option_env!($"PATH").unwrap()); = note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info) error: this will panic at run-time if the environment variable doesn't exist at compile-time - --> tests/ui/option_env_unwrap.rs:23:13 + --> tests/ui/option_env_unwrap.rs:22:13 | LL | let _ = external!(option_env!($"PATH").expect($"environment variable PATH isn't set")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/option_filter_map.fixed b/tests/ui/option_filter_map.fixed index b3191c6c1d46d..3e7cb35db952a 100644 --- a/tests/ui/option_filter_map.fixed +++ b/tests/ui/option_filter_map.fixed @@ -1,5 +1,6 @@ #![warn(clippy::option_filter_map)] -#![allow(clippy::map_flatten, clippy::some_filter, clippy::unnecessary_map_on_constructor)] +#![allow(clippy::map_flatten)] +#![expect(clippy::unnecessary_map_on_constructor)] fn main() { let _ = Some(Some(1)).flatten(); diff --git a/tests/ui/option_filter_map.rs b/tests/ui/option_filter_map.rs index 7d373f353688d..36fd0ac8cbfd7 100644 --- a/tests/ui/option_filter_map.rs +++ b/tests/ui/option_filter_map.rs @@ -1,5 +1,6 @@ #![warn(clippy::option_filter_map)] -#![allow(clippy::map_flatten, clippy::some_filter, clippy::unnecessary_map_on_constructor)] +#![allow(clippy::map_flatten)] +#![expect(clippy::unnecessary_map_on_constructor)] fn main() { let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); diff --git a/tests/ui/option_filter_map.stderr b/tests/ui/option_filter_map.stderr index df3c1f9d47b8a..deac2f0abb79e 100644 --- a/tests/ui/option_filter_map.stderr +++ b/tests/ui/option_filter_map.stderr @@ -1,5 +1,5 @@ error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:5:27 + --> tests/ui/option_filter_map.rs:6:27 | LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` @@ -8,37 +8,37 @@ LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); = help: to override `-D warnings` add `#[allow(clippy::option_filter_map)]` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:8:27 + --> tests/ui/option_filter_map.rs:9:27 | LL | let _ = Some(Some(1)).filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:11:35 + --> tests/ui/option_filter_map.rs:12:35 | LL | let _ = Some(1).map(odds_out).filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:14:35 + --> tests/ui/option_filter_map.rs:15:35 | LL | let _ = Some(1).map(odds_out).filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:17:39 + --> tests/ui/option_filter_map.rs:18:39 | LL | let _ = vec![Some(1)].into_iter().filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:20:39 + --> tests/ui/option_filter_map.rs:21:39 | LL | let _ = vec![Some(1)].into_iter().filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:26:10 + --> tests/ui/option_filter_map.rs:27:10 | LL | .filter(Option::is_some) | __________^ @@ -47,7 +47,7 @@ LL | | .map(Option::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> tests/ui/option_filter_map.rs:32:10 + --> tests/ui/option_filter_map.rs:33:10 | LL | .filter(|o| o.is_some()) | __________^ diff --git a/tests/ui/option_if_let_else.fixed b/tests/ui/option_if_let_else.fixed index 2c13ce5dae2a6..d614816136665 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -1,15 +1,10 @@ #![warn(clippy::option_if_let_else)] #![allow( - clippy::ref_option_ref, - clippy::equatable_if_let, - clippy::let_unit_value, - clippy::redundant_locals, - clippy::manual_midpoint, - clippy::manual_unwrap_or_default, clippy::manual_unwrap_or, - clippy::unnecessary_option_map_or_else, - clippy::map_or_identity + clippy::map_or_identity, + clippy::unnecessary_option_map_or_else )] +#![expect(clippy::let_unit_value, clippy::redundant_locals)] fn bad1(string: Option<&str>) -> (bool, &str) { string.map_or((false, "hello"), |x| (true, x)) @@ -227,7 +222,6 @@ fn main() { //~^ option_if_let_else } -#[allow(dead_code)] fn issue9742() -> Option<&'static str> { // should not lint because of guards match Some("foo ") { @@ -237,7 +231,7 @@ fn issue9742() -> Option<&'static str> { } mod issue10729 { - #![allow(clippy::unit_arg, dead_code)] + #![allow(clippy::unit_arg)] pub fn reproduce(initial: &Option) { // 👇 needs `.as_ref()` because initial is an `&Option<_>` diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index c41394a1e35e8..db83dfe0bd84a 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -1,15 +1,10 @@ #![warn(clippy::option_if_let_else)] #![allow( - clippy::ref_option_ref, - clippy::equatable_if_let, - clippy::let_unit_value, - clippy::redundant_locals, - clippy::manual_midpoint, - clippy::manual_unwrap_or_default, clippy::manual_unwrap_or, - clippy::unnecessary_option_map_or_else, - clippy::map_or_identity + clippy::map_or_identity, + clippy::unnecessary_option_map_or_else )] +#![expect(clippy::let_unit_value, clippy::redundant_locals)] fn bad1(string: Option<&str>) -> (bool, &str) { if let Some(x) = string { @@ -283,7 +278,6 @@ fn main() { //~^ option_if_let_else } -#[allow(dead_code)] fn issue9742() -> Option<&'static str> { // should not lint because of guards match Some("foo ") { @@ -293,7 +287,7 @@ fn issue9742() -> Option<&'static str> { } mod issue10729 { - #![allow(clippy::unit_arg, dead_code)] + #![allow(clippy::unit_arg)] pub fn reproduce(initial: &Option) { // 👇 needs `.as_ref()` because initial is an `&Option<_>` diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index 7e5df7c531105..a0838dccc69ec 100644 --- a/tests/ui/option_if_let_else.stderr +++ b/tests/ui/option_if_let_else.stderr @@ -1,5 +1,5 @@ error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:15:5 + --> tests/ui/option_if_let_else.rs:10:5 | LL | / if let Some(x) = string { LL | | @@ -13,19 +13,19 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::option_if_let_else)]` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:34:13 + --> tests/ui/option_if_let_else.rs:29:13 | LL | let _ = if let Some(s) = *string { s.len() } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:36:13 + --> tests/ui/option_if_let_else.rs:31:13 | LL | let _ = if let Some(s) = &num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:38:13 + --> tests/ui/option_if_let_else.rs:33:13 | LL | let _ = if let Some(s) = &mut num { | _____________^ @@ -47,13 +47,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:45:13 + --> tests/ui/option_if_let_else.rs:40:13 | LL | let _ = if let Some(ref s) = num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:47:13 + --> tests/ui/option_if_let_else.rs:42:13 | LL | let _ = if let Some(mut s) = num { | _____________^ @@ -75,7 +75,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:54:13 + --> tests/ui/option_if_let_else.rs:49:13 | LL | let _ = if let Some(ref mut s) = num { | _____________^ @@ -97,7 +97,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:64:5 + --> tests/ui/option_if_let_else.rs:59:5 | LL | / if let Some(x) = arg { LL | | @@ -118,7 +118,7 @@ LL + }) | error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:78:13 + --> tests/ui/option_if_let_else.rs:73:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -131,7 +131,7 @@ LL | | }; | |_____^ help: try: `arg.map_or_else(side_effect, |x| x)` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:88:13 + --> tests/ui/option_if_let_else.rs:83:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -154,7 +154,7 @@ LL ~ }, |x| x * x * x * x); | error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:122:13 + --> tests/ui/option_if_let_else.rs:117:13 | LL | / if let Some(idx) = s.find('.') { LL | | @@ -165,7 +165,7 @@ LL | | } | |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:134:5 + --> tests/ui/option_if_let_else.rs:129:5 | LL | / if let Ok(binding) = variable { LL | | @@ -189,7 +189,7 @@ LL + }) | error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:159:5 + --> tests/ui/option_if_let_else.rs:154:5 | LL | / match r { LL | | @@ -199,7 +199,7 @@ LL | | } | |_____^ help: try: `r.map_or_else(|_| Vec::new(), |s| s.to_owned())` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:168:5 + --> tests/ui/option_if_let_else.rs:163:5 | LL | / if let Ok(s) = r { s.to_owned() } LL | | @@ -207,13 +207,13 @@ LL | | else { Vec::new() } | |_______________________^ help: try: `r.map_or_else(|_| Vec::new(), |s| s.to_owned())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:175:13 + --> tests/ui/option_if_let_else.rs:170:13 | LL | let _ = if let Some(x) = optional { x + 2 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:186:13 + --> tests/ui/option_if_let_else.rs:181:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -235,13 +235,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:215:13 + --> tests/ui/option_if_let_else.rs:210:13 | LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:220:13 + --> tests/ui/option_if_let_else.rs:215:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -263,7 +263,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:260:13 + --> tests/ui/option_if_let_else.rs:255:13 | LL | let _ = match s { | _____________^ @@ -274,7 +274,7 @@ LL | | }; | |_____^ help: try: `s.map_or(1, |string| string.len())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:265:13 + --> tests/ui/option_if_let_else.rs:260:13 | LL | let _ = match Some(10) { | _____________^ @@ -285,7 +285,7 @@ LL | | }; | |_____^ help: try: `Some(10).map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:272:13 + --> tests/ui/option_if_let_else.rs:267:13 | LL | let _ = match res { | _____________^ @@ -296,7 +296,7 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:277:13 + --> tests/ui/option_if_let_else.rs:272:13 | LL | let _ = match res { | _____________^ @@ -307,13 +307,13 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:282:13 + --> tests/ui/option_if_let_else.rs:277:13 | LL | let _ = if let Ok(a) = res { a + 1 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:300:17 + --> tests/ui/option_if_let_else.rs:294:17 | LL | let _ = match initial { | _________________^ @@ -324,7 +324,7 @@ LL | | }; | |_________^ help: try: `initial.as_ref().map_or(42, |value| do_something(value))` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:308:17 + --> tests/ui/option_if_let_else.rs:302:17 | LL | let _ = match initial { | _________________^ @@ -335,7 +335,7 @@ LL | | }; | |_________^ help: try: `initial.as_mut().map_or(42, |value| do_something2(value))` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:332:24 + --> tests/ui/option_if_let_else.rs:326:24 | LL | let mut _hashmap = if let Some(hm) = &opt { | ________________________^ @@ -347,19 +347,19 @@ LL | | }; | |_____^ help: try: `opt.as_ref().map_or_else(HashMap::new, |hm| hm.clone())` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:339:19 + --> tests/ui/option_if_let_else.rs:333:19 | LL | let mut _hm = if let Some(hm) = &opt { hm.clone() } else { new_map!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.as_ref().map_or_else(|| new_map!(), |hm| hm.clone())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:390:22 + --> tests/ui/option_if_let_else.rs:384:22 | LL | let _ = unsafe { if let Some(o) = *opt_raw_ptr { o } else { 1 } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*opt_raw_ptr).map_or(1, |o| o)` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:396:13 + --> tests/ui/option_if_let_else.rs:390:13 | LL | let _ = match res { | _____________^ diff --git a/tests/ui/option_map_unit_fn_unfixable.rs b/tests/ui/option_map_unit_fn_unfixable.rs index a6d7ea4a4c8d9..8faeb8155cc24 100644 --- a/tests/ui/option_map_unit_fn_unfixable.rs +++ b/tests/ui/option_map_unit_fn_unfixable.rs @@ -1,6 +1,6 @@ //@no-rustfix #![warn(clippy::option_map_unit_fn)] -#![allow(clippy::unnecessary_wraps, clippy::unnecessary_map_on_constructor)] // only fires before the fix +#![expect(clippy::unnecessary_map_on_constructor)] fn do_nothing(_: T) {} diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index 1633161c4264e..db65a33ecdcfb 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -1,14 +1,10 @@ #![warn(clippy::or_fun_call)] #![allow( - clippy::borrow_as_ptr, - clippy::uninlined_format_args, - clippy::unnecessary_wraps, - clippy::unnecessary_literal_unwrap, - clippy::unnecessary_result_map_or_else, - clippy::unnecessary_option_map_or_else, clippy::map_or_identity, - clippy::useless_vec + clippy::unnecessary_option_map_or_else, + clippy::unnecessary_result_map_or_else )] +#![expect(clippy::unnecessary_literal_unwrap, clippy::useless_vec)] use std::collections::{BTreeMap, HashMap}; use std::time::Duration; @@ -198,7 +194,6 @@ fn f() -> Option<()> { mod issue6675 { unsafe fn ptr_to_ref<'a, T>(p: *const T) -> &'a T { unsafe { - #[allow(unused)] let x = vec![0; 1000]; // future-proofing, make this function expensive. &*p } diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index 55339348e2bc1..6c31be62f1f52 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -1,14 +1,10 @@ #![warn(clippy::or_fun_call)] #![allow( - clippy::borrow_as_ptr, - clippy::uninlined_format_args, - clippy::unnecessary_wraps, - clippy::unnecessary_literal_unwrap, - clippy::unnecessary_result_map_or_else, - clippy::unnecessary_option_map_or_else, clippy::map_or_identity, - clippy::useless_vec + clippy::unnecessary_option_map_or_else, + clippy::unnecessary_result_map_or_else )] +#![expect(clippy::unnecessary_literal_unwrap, clippy::useless_vec)] use std::collections::{BTreeMap, HashMap}; use std::time::Duration; @@ -198,7 +194,6 @@ fn f() -> Option<()> { mod issue6675 { unsafe fn ptr_to_ref<'a, T>(p: *const T) -> &'a T { unsafe { - #[allow(unused)] let x = vec![0; 1000]; // future-proofing, make this function expensive. &*p } diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 934af4656ea34..32d93bab3633b 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -1,5 +1,5 @@ error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:54:22 + --> tests/ui/or_fun_call.rs:50:22 | LL | with_constructor.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(make)` @@ -8,7 +8,7 @@ LL | with_constructor.unwrap_or(make()); = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:58:14 + --> tests/ui/or_fun_call.rs:54:14 | LL | with_new.unwrap_or(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` @@ -17,205 +17,205 @@ LL | with_new.unwrap_or(Vec::new()); = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:62:21 + --> tests/ui/or_fun_call.rs:58:21 | LL | with_const_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Vec::with_capacity(12))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:66:14 + --> tests/ui/or_fun_call.rs:62:14 | LL | with_err.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| make())` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:70:19 + --> tests/ui/or_fun_call.rs:66:19 | LL | with_err_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| Vec::with_capacity(12))` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:74:24 + --> tests/ui/or_fun_call.rs:70:24 | LL | with_default_trait.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:78:23 + --> tests/ui/or_fun_call.rs:74:23 | LL | with_default_type.unwrap_or(u64::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:98:18 + --> tests/ui/or_fun_call.rs:94:18 | LL | self_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(::default)` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:102:18 + --> tests/ui/or_fun_call.rs:98:18 | 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:106:14 + --> tests/ui/or_fun_call.rs:102:14 | LL | with_vec.unwrap_or(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:110:21 + --> tests/ui/or_fun_call.rs:106:21 | LL | without_default.unwrap_or(Foo::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(Foo::new)` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:114:19 + --> tests/ui/or_fun_call.rs:110:19 | 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:118:23 + --> tests/ui/or_fun_call.rs:114:23 | LL | map_vec.entry(42).or_insert(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> tests/ui/or_fun_call.rs:122:21 + --> tests/ui/or_fun_call.rs:118: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:126:25 + --> tests/ui/or_fun_call.rs:122:25 | LL | btree_vec.entry(42).or_insert(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:130:21 + --> tests/ui/or_fun_call.rs:126:21 | LL | let _ = stringy.unwrap_or(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `ok_or` - --> tests/ui/or_fun_call.rs:135:17 + --> tests/ui/or_fun_call.rs:131:17 | LL | let _ = opt.ok_or(format!("{} world.", hello)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ok_or_else(|| format!("{} world.", hello))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:140:21 + --> tests/ui/or_fun_call.rs:136:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:143:21 + --> tests/ui/or_fun_call.rs:139:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: function call inside of `or` - --> tests/ui/or_fun_call.rs:168:35 + --> tests/ui/or_fun_call.rs:164:35 | LL | let _ = Some("a".to_string()).or(Some("b".to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_else(|| Some("b".to_string()))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:211:18 + --> tests/ui/or_fun_call.rs:206:18 | LL | None.unwrap_or(ptr_to_ref(s)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| ptr_to_ref(s))` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:219:14 + --> tests/ui/or_fun_call.rs:214:14 | LL | None.unwrap_or(unsafe { ptr_to_ref(s) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:222:14 + --> tests/ui/or_fun_call.rs:217:14 | LL | None.unwrap_or( unsafe { ptr_to_ref(s) } ); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:298:25 + --> tests/ui/or_fun_call.rs:293:25 | LL | let _ = Some(4).map_or(g(), |v| v); | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(g, |v| v)` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:300:25 + --> tests/ui/or_fun_call.rs:295:25 | LL | let _ = Some(4).map_or(g(), f); | ^^^^^^^^^^^^^^ help: try: `map_or_else(g, f)` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:303:25 + --> tests/ui/or_fun_call.rs:298:25 | LL | let _ = Some(4).map_or("asd".to_string().len() as i32, f); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|| "asd".to_string().len() as i32, f)` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:334:18 + --> tests/ui/or_fun_call.rs:329:18 | LL | with_new.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:338:28 + --> tests/ui/or_fun_call.rs:333:28 | 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/or_fun_call.rs:342:27 + --> tests/ui/or_fun_call.rs:337:27 | 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/or_fun_call.rs:346:22 + --> tests/ui/or_fun_call.rs:341:22 | LL | real_default.unwrap_or_else(::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> tests/ui/or_fun_call.rs:350:23 + --> tests/ui/or_fun_call.rs:345:23 | LL | map.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert_with` to construct default value - --> tests/ui/or_fun_call.rs:354:25 + --> tests/ui/or_fun_call.rs:349:25 | LL | btree.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or_else` to construct default value - --> tests/ui/or_fun_call.rs:358:25 + --> tests/ui/or_fun_call.rs:353:25 | LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:400:17 + --> tests/ui/or_fun_call.rs:395:17 | LL | let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(f)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:405:17 + --> tests/ui/or_fun_call.rs:400:17 | LL | let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| f() + 1)` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:410:17 + --> tests/ui/or_fun_call.rs:405:17 | LL | let _ = opt.unwrap_or({ | _________________^ @@ -235,79 +235,79 @@ LL ~ }); | error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:416:17 + --> tests/ui/or_fun_call.rs:411:17 | LL | let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|| f() + 1, |v| v)` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:421:17 + --> tests/ui/or_fun_call.rs:416:17 | LL | let _ = opt.unwrap_or({ i32::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:428:21 + --> tests/ui/or_fun_call.rs:423:21 | LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:443:19 + --> tests/ui/or_fun_call.rs:438:19 | LL | let _ = x.map_or(g(), |v| v); | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|_| g(), |v| v)` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:445:19 + --> tests/ui/or_fun_call.rs:440:19 | LL | let _ = x.map_or(g(), f); | ^^^^^^^^^^^^^^ help: try: `map_or_else(|_| g(), f)` error: function call inside of `map_or` - --> tests/ui/or_fun_call.rs:448:19 + --> tests/ui/or_fun_call.rs:443:19 | LL | let _ = x.map_or("asd".to_string().len() as i32, f); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(|_| "asd".to_string().len() as i32, f)` error: function call inside of `get_or_insert` - --> tests/ui/or_fun_call.rs:459:15 + --> tests/ui/or_fun_call.rs:454:15 | LL | let _ = x.get_or_insert(g()); | ^^^^^^^^^^^^^^^^^^ help: try: `get_or_insert_with(g)` error: function call inside of `and` - --> tests/ui/or_fun_call.rs:469:15 + --> tests/ui/or_fun_call.rs:464:15 | LL | let _ = x.and(g()); | ^^^^^^^^ help: try: `and_then(|_| g())` error: function call inside of `and` - --> tests/ui/or_fun_call.rs:479:15 + --> tests/ui/or_fun_call.rs:474:15 | LL | let _ = x.and(g()); | ^^^^^^^^ help: try: `and_then(|_| g())` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:485:17 + --> tests/ui/or_fun_call.rs:480:17 | LL | let _ = opt.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: function call inside of `unwrap_or` - --> tests/ui/or_fun_call.rs:487:17 + --> tests/ui/or_fun_call.rs:482:17 | LL | let _ = res.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| Default::default())` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:493:17 + --> tests/ui/or_fun_call.rs:488:17 | LL | let _ = opt.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> tests/ui/or_fun_call.rs:495:17 + --> tests/ui/or_fun_call.rs:490:17 | LL | let _ = res.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` diff --git a/tests/ui/or_then_unwrap.fixed b/tests/ui/or_then_unwrap.fixed index 9660b82fe7d61..35b53bbb8116d 100644 --- a/tests/ui/or_then_unwrap.fixed +++ b/tests/ui/or_then_unwrap.fixed @@ -1,5 +1,6 @@ #![warn(clippy::or_then_unwrap)] -#![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)] +#![allow(clippy::unnecessary_literal_unwrap)] +#![expect(clippy::let_unit_value, clippy::map_identity)] struct SomeStruct; impl SomeStruct { diff --git a/tests/ui/or_then_unwrap.rs b/tests/ui/or_then_unwrap.rs index c387335211643..c3d68a0d3a443 100644 --- a/tests/ui/or_then_unwrap.rs +++ b/tests/ui/or_then_unwrap.rs @@ -1,5 +1,6 @@ #![warn(clippy::or_then_unwrap)] -#![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)] +#![allow(clippy::unnecessary_literal_unwrap)] +#![expect(clippy::let_unit_value, clippy::map_identity)] struct SomeStruct; impl SomeStruct { diff --git a/tests/ui/or_then_unwrap.stderr b/tests/ui/or_then_unwrap.stderr index 3e66b15edbd65..828e569571e8e 100644 --- a/tests/ui/or_then_unwrap.stderr +++ b/tests/ui/or_then_unwrap.stderr @@ -1,5 +1,5 @@ error: found `.or(Some(…)).unwrap()` - --> tests/ui/or_then_unwrap.rs:22:20 + --> tests/ui/or_then_unwrap.rs:23:20 | LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` @@ -8,19 +8,19 @@ LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint = help: to override `-D warnings` add `#[allow(clippy::or_then_unwrap)]` error: found `.or(Ok(…)).unwrap()` - --> tests/ui/or_then_unwrap.rs:27:20 + --> tests/ui/or_then_unwrap.rs:28:20 | LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` error: found `.or(Some(…)).unwrap()` - --> tests/ui/or_then_unwrap.rs:33:20 + --> tests/ui/or_then_unwrap.rs:34:20 | LL | let _ = option.or(Some(vec!["fallback"])).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or(vec!["fallback"])` error: found `.or(Some(…)).unwrap()` - --> tests/ui/or_then_unwrap.rs:39:31 + --> tests/ui/or_then_unwrap.rs:40:31 | LL | let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs index e1e0fa02a9371..fa2a8dab1306b 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ b/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -1,5 +1,5 @@ #![warn(clippy::out_of_bounds_indexing)] -#![allow(clippy::no_effect)] +#![expect(clippy::no_effect)] fn main() { let x = [1, 2, 3, 4]; diff --git a/tests/ui/out_of_bounds_indexing/simple.rs b/tests/ui/out_of_bounds_indexing/simple.rs index e613e527eee48..dbd00eabcef89 100644 --- a/tests/ui/out_of_bounds_indexing/simple.rs +++ b/tests/ui/out_of_bounds_indexing/simple.rs @@ -1,5 +1,5 @@ #![warn(clippy::out_of_bounds_indexing)] -#![allow(clippy::no_effect, clippy::unnecessary_operation)] +#![expect(clippy::no_effect, clippy::unnecessary_operation)] fn main() { let x = [1, 2, 3, 4]; diff --git a/tests/ui/overly_complex_bool_expr.fixed b/tests/ui/overly_complex_bool_expr.fixed index 6818f96725e78..6d129c906ecad 100644 --- a/tests/ui/overly_complex_bool_expr.fixed +++ b/tests/ui/overly_complex_bool_expr.fixed @@ -1,5 +1,5 @@ -#![allow(unused, clippy::diverging_sub_expression)] #![warn(clippy::overly_complex_bool_expr)] +#![expect(clippy::diverging_sub_expression)] fn main() { let a: bool = unimplemented!(); diff --git a/tests/ui/overly_complex_bool_expr.rs b/tests/ui/overly_complex_bool_expr.rs index f1cd9562a855a..1e01c84ec8da4 100644 --- a/tests/ui/overly_complex_bool_expr.rs +++ b/tests/ui/overly_complex_bool_expr.rs @@ -1,5 +1,5 @@ -#![allow(unused, clippy::diverging_sub_expression)] #![warn(clippy::overly_complex_bool_expr)] +#![expect(clippy::diverging_sub_expression)] fn main() { let a: bool = unimplemented!(); diff --git a/tests/ui/panic_in_result_fn.rs b/tests/ui/panic_in_result_fn.rs index 005e38db90216..26a4a61e5f82e 100644 --- a/tests/ui/panic_in_result_fn.rs +++ b/tests/ui/panic_in_result_fn.rs @@ -1,5 +1,5 @@ #![warn(clippy::panic_in_result_fn)] -#![allow(clippy::unnecessary_wraps)] +#![expect(clippy::unnecessary_wraps)] struct A; impl A { diff --git a/tests/ui/panic_in_result_fn_assertions.rs b/tests/ui/panic_in_result_fn_assertions.rs index 17b221044b1f2..879f25f5d68f5 100644 --- a/tests/ui/panic_in_result_fn_assertions.rs +++ b/tests/ui/panic_in_result_fn_assertions.rs @@ -1,5 +1,5 @@ #![warn(clippy::panic_in_result_fn)] -#![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)] +#![expect(clippy::uninlined_format_args, clippy::unnecessary_wraps)] struct A; diff --git a/tests/ui/panic_in_result_fn_debug_assertions.rs b/tests/ui/panic_in_result_fn_debug_assertions.rs index 9cce339f4d60d..23985eeaccbd8 100644 --- a/tests/ui/panic_in_result_fn_debug_assertions.rs +++ b/tests/ui/panic_in_result_fn_debug_assertions.rs @@ -1,7 +1,7 @@ //@ check-pass #![warn(clippy::panic_in_result_fn)] -#![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)] +#![expect(clippy::uninlined_format_args, clippy::unnecessary_wraps)] // debug_assert should never trigger the `panic_in_result_fn` lint diff --git a/tests/ui/panicking_macros.rs b/tests/ui/panicking_macros.rs index a9728d4708e6e..5f6941f1f4b06 100644 --- a/tests/ui/panicking_macros.rs +++ b/tests/ui/panicking_macros.rs @@ -1,5 +1,5 @@ -#![allow(clippy::assertions_on_constants, clippy::eq_op, clippy::let_unit_value)] -#![warn(clippy::unimplemented, clippy::unreachable, clippy::todo, clippy::panic)] +#![warn(clippy::panic, clippy::todo, clippy::unimplemented, clippy::unreachable)] +#![expect(clippy::assertions_on_constants, clippy::eq_op, clippy::let_unit_value)] extern crate core; diff --git a/tests/ui/panicking_overflow_checks.rs b/tests/ui/panicking_overflow_checks.rs index ecae3130fd505..de0aa70d3ff85 100644 --- a/tests/ui/panicking_overflow_checks.rs +++ b/tests/ui/panicking_overflow_checks.rs @@ -1,5 +1,5 @@ #![warn(clippy::panicking_overflow_checks)] -#![allow(clippy::needless_ifs)] +#![expect(clippy::needless_ifs)] fn test(a: u32, b: u32, c: u32) { if a + b < a {} diff --git a/tests/ui/partial_pub_fields.rs b/tests/ui/partial_pub_fields.rs index 27f4b2a0b4fcb..c4ed63b758c87 100644 --- a/tests/ui/partial_pub_fields.rs +++ b/tests/ui/partial_pub_fields.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::partial_pub_fields)] fn main() { diff --git a/tests/ui/partial_pub_fields.stderr b/tests/ui/partial_pub_fields.stderr index af3b2f7587578..2e74bf2cb47ec 100644 --- a/tests/ui/partial_pub_fields.stderr +++ b/tests/ui/partial_pub_fields.stderr @@ -1,5 +1,5 @@ error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:10:9 + --> tests/ui/partial_pub_fields.rs:9:9 | LL | pub paths: HashMap, | ^^^ @@ -9,7 +9,7 @@ LL | pub paths: HashMap, = help: to override `-D warnings` add `#[allow(clippy::partial_pub_fields)]` error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:17:9 + --> tests/ui/partial_pub_fields.rs:16:9 | LL | b: u8, | ^ @@ -17,7 +17,7 @@ LL | b: u8, = help: consider using public field here error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:21:27 + --> tests/ui/partial_pub_fields.rs:20:27 | LL | pub struct Point(i32, pub i32); | ^^^ @@ -25,7 +25,7 @@ LL | pub struct Point(i32, pub i32); = help: consider using private field here error: mixed usage of pub and non-pub fields - --> tests/ui/partial_pub_fields.rs:26:9 + --> tests/ui/partial_pub_fields.rs:25:9 | LL | pub pos: u32, | ^^^ diff --git a/tests/ui/partialeq_ne_impl.rs b/tests/ui/partialeq_ne_impl.rs index a3b2b68708ba8..343402f7a72c5 100644 --- a/tests/ui/partialeq_ne_impl.rs +++ b/tests/ui/partialeq_ne_impl.rs @@ -1,5 +1,4 @@ -#![allow(dead_code)] - +#![warn(clippy::partialeq_ne_impl)] struct Foo; impl PartialEq for Foo { diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr index 0f700654f7ccc..9353db1c90bf4 100644 --- a/tests/ui/partialeq_ne_impl.stderr +++ b/tests/ui/partialeq_ne_impl.stderr @@ -1,5 +1,5 @@ error: re-implementing `PartialEq::ne` is unnecessary - --> tests/ui/partialeq_ne_impl.rs:9:5 + --> tests/ui/partialeq_ne_impl.rs:8:5 | LL | fn ne(&self, _: &Foo) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/partialeq_to_none.fixed b/tests/ui/partialeq_to_none.fixed index 9288529423dd9..9f9edb2e24487 100644 --- a/tests/ui/partialeq_to_none.fixed +++ b/tests/ui/partialeq_to_none.fixed @@ -1,5 +1,5 @@ #![warn(clippy::partialeq_to_none)] -#![allow(clippy::eq_op, clippy::needless_ifs)] +#![expect(clippy::eq_op, clippy::needless_ifs)] struct Foobar; @@ -9,7 +9,6 @@ impl PartialEq> for Foobar { } } -#[allow(dead_code)] fn foo(f: Option) -> &'static str { if f.is_some() { "yay" } else { "nay" } //~^ partialeq_to_none diff --git a/tests/ui/partialeq_to_none.rs b/tests/ui/partialeq_to_none.rs index 7940251c18a2b..a82a33f154dd7 100644 --- a/tests/ui/partialeq_to_none.rs +++ b/tests/ui/partialeq_to_none.rs @@ -1,5 +1,5 @@ #![warn(clippy::partialeq_to_none)] -#![allow(clippy::eq_op, clippy::needless_ifs)] +#![expect(clippy::eq_op, clippy::needless_ifs)] struct Foobar; @@ -9,7 +9,6 @@ impl PartialEq> for Foobar { } } -#[allow(dead_code)] fn foo(f: Option) -> &'static str { if f != None { "yay" } else { "nay" } //~^ partialeq_to_none diff --git a/tests/ui/partialeq_to_none.stderr b/tests/ui/partialeq_to_none.stderr index b09bd7fa0f420..31b73051b0e46 100644 --- a/tests/ui/partialeq_to_none.stderr +++ b/tests/ui/partialeq_to_none.stderr @@ -1,5 +1,5 @@ error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:14:8 + --> tests/ui/partialeq_to_none.rs:13:8 | LL | if f != None { "yay" } else { "nay" } | ^^^^^^^^^ help: use `Option::is_some()` instead: `f.is_some()` @@ -8,55 +8,55 @@ LL | if f != None { "yay" } else { "nay" } = help: to override `-D warnings` add `#[allow(clippy::partialeq_to_none)]` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:45:13 + --> tests/ui/partialeq_to_none.rs:44:13 | LL | let _ = x == None; | ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:47:13 + --> tests/ui/partialeq_to_none.rs:46:13 | LL | let _ = x != None; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:49:13 + --> tests/ui/partialeq_to_none.rs:48:13 | LL | let _ = None == x; | ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:51:13 + --> tests/ui/partialeq_to_none.rs:50:13 | LL | let _ = None != x; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:54:8 + --> tests/ui/partialeq_to_none.rs:53:8 | LL | if foobar() == None {} | ^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `foobar().is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:57:8 + --> tests/ui/partialeq_to_none.rs:56:8 | LL | if bar().ok() != None {} | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `bar().ok().is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:60:13 + --> tests/ui/partialeq_to_none.rs:59:13 | LL | let _ = Some(1 + 2) != None; | ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `Some(1 + 2).is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:63:13 + --> tests/ui/partialeq_to_none.rs:62:13 | LL | let _ = { Some(0) } == None; | ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `{ Some(0) }.is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:66:13 + --> tests/ui/partialeq_to_none.rs:65:13 | LL | let _ = { | _____________^ @@ -80,31 +80,31 @@ LL ~ }.is_some(); | error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:77:13 + --> tests/ui/partialeq_to_none.rs:76:13 | LL | let _ = optref() == &&None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:79:13 + --> tests/ui/partialeq_to_none.rs:78:13 | LL | let _ = &&None != optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:81:13 + --> tests/ui/partialeq_to_none.rs:80:13 | LL | let _ = **optref() == None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:83:13 + --> tests/ui/partialeq_to_none.rs:82:13 | LL | let _ = &None != *optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> tests/ui/partialeq_to_none.rs:87:13 + --> tests/ui/partialeq_to_none.rs:86:13 | LL | let _ = None != *x; | ^^^^^^^^^^ help: use `Option::is_some()` instead: `(*x).is_some()` diff --git a/tests/ui/pattern_type_mismatch/mutability.rs b/tests/ui/pattern_type_mismatch/mutability.rs index 643d8fedda984..eacc86962d569 100644 --- a/tests/ui/pattern_type_mismatch/mutability.rs +++ b/tests/ui/pattern_type_mismatch/mutability.rs @@ -1,5 +1,5 @@ #![warn(clippy::pattern_type_mismatch)] -#![allow(clippy::single_match)] +#![expect(clippy::single_match)] fn main() {} diff --git a/tests/ui/pattern_type_mismatch/syntax.rs b/tests/ui/pattern_type_mismatch/syntax.rs index aa988a577df2b..852120b0105a5 100644 --- a/tests/ui/pattern_type_mismatch/syntax.rs +++ b/tests/ui/pattern_type_mismatch/syntax.rs @@ -1,5 +1,5 @@ #![warn(clippy::pattern_type_mismatch)] -#![allow( +#![expect( clippy::match_ref_pats, clippy::never_loop, clippy::redundant_pattern_matching, diff --git a/tests/ui/patterns.fixed b/tests/ui/patterns.fixed index a6dd5fd63a9f6..51225c5a1dee2 100644 --- a/tests/ui/patterns.fixed +++ b/tests/ui/patterns.fixed @@ -1,5 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(clippy::uninlined_format_args, clippy::single_match)] +#![warn(clippy::redundant_pattern)] +#![expect(clippy::single_match, clippy::uninlined_format_args)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/patterns.rs b/tests/ui/patterns.rs index 64bfbdecdac2b..667668319a47b 100644 --- a/tests/ui/patterns.rs +++ b/tests/ui/patterns.rs @@ -1,5 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(clippy::uninlined_format_args, clippy::single_match)] +#![warn(clippy::redundant_pattern)] +#![expect(clippy::single_match, clippy::uninlined_format_args)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/patterns.stderr b/tests/ui/patterns.stderr index ff5e1a8de90a4..20e385780f8bd 100644 --- a/tests/ui/patterns.stderr +++ b/tests/ui/patterns.stderr @@ -1,5 +1,5 @@ error: the `y @ _` pattern can be written as just `y` - --> tests/ui/patterns.rs:12:9 + --> tests/ui/patterns.rs:13:9 | LL | y @ _ => (), | ^^^^^ help: try: `y` @@ -8,13 +8,13 @@ LL | y @ _ => (), = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern)]` error: the `x @ _` pattern can be written as just `x` - --> tests/ui/patterns.rs:28:9 + --> tests/ui/patterns.rs:29:9 | LL | ref mut x @ _ => { | ^^^^^^^^^^^^^ help: try: `ref mut x` error: the `x @ _` pattern can be written as just `x` - --> tests/ui/patterns.rs:37:9 + --> tests/ui/patterns.rs:38:9 | LL | ref x @ _ => println!("vec: {:?}", x), | ^^^^^^^^^ help: try: `ref x` diff --git a/tests/ui/permissions_set_readonly_false.rs b/tests/ui/permissions_set_readonly_false.rs index ccca523da551c..bd4dff8bf1d06 100644 --- a/tests/ui/permissions_set_readonly_false.rs +++ b/tests/ui/permissions_set_readonly_false.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::permissions_set_readonly_false)] use std::fs::File; diff --git a/tests/ui/permissions_set_readonly_false.stderr b/tests/ui/permissions_set_readonly_false.stderr index 4e0a8e39db7f0..105a36799b4cb 100644 --- a/tests/ui/permissions_set_readonly_false.stderr +++ b/tests/ui/permissions_set_readonly_false.stderr @@ -1,5 +1,5 @@ error: call to `set_readonly` with argument `false` - --> tests/ui/permissions_set_readonly_false.rs:19:5 + --> tests/ui/permissions_set_readonly_false.rs:18:5 | LL | permissions.set_readonly(false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/precedence.fixed b/tests/ui/precedence.fixed index f0252c4484a5a..b9c67c0baa63b 100644 --- a/tests/ui/precedence.fixed +++ b/tests/ui/precedence.fixed @@ -1,12 +1,5 @@ #![warn(clippy::precedence)] -#![allow( - unused_must_use, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::clone_on_copy, - clippy::identity_op, - clippy::eq_op -)] +#![expect(clippy::clone_on_copy, clippy::eq_op, clippy::identity_op, clippy::no_effect)] macro_rules! trip { ($a:expr) => { diff --git a/tests/ui/precedence.rs b/tests/ui/precedence.rs index 5d47462114b85..8333f887f46e2 100644 --- a/tests/ui/precedence.rs +++ b/tests/ui/precedence.rs @@ -1,12 +1,5 @@ #![warn(clippy::precedence)] -#![allow( - unused_must_use, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::clone_on_copy, - clippy::identity_op, - clippy::eq_op -)] +#![expect(clippy::clone_on_copy, clippy::eq_op, clippy::identity_op, clippy::no_effect)] macro_rules! trip { ($a:expr) => { diff --git a/tests/ui/precedence.stderr b/tests/ui/precedence.stderr index f086cfe028904..080f48cb5ba18 100644 --- a/tests/ui/precedence.stderr +++ b/tests/ui/precedence.stderr @@ -1,5 +1,5 @@ error: operator precedence might not be obvious - --> tests/ui/precedence.rs:21:5 + --> tests/ui/precedence.rs:14:5 | LL | 1 << 2 + 3; | ^^^^^^^^^^ help: consider parenthesizing your expression: `1 << (2 + 3)` @@ -8,43 +8,43 @@ LL | 1 << 2 + 3; = help: to override `-D warnings` add `#[allow(clippy::precedence)]` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:23:5 + --> tests/ui/precedence.rs:16:5 | LL | 1 + 2 << 3; | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:25:5 + --> tests/ui/precedence.rs:18:5 | LL | 4 >> 1 + 1; | ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:27:5 + --> tests/ui/precedence.rs:20:5 | LL | 1 + 3 >> 2; | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:29:5 + --> tests/ui/precedence.rs:22:5 | LL | 1 ^ 1 - 1; | ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:31:5 + --> tests/ui/precedence.rs:24:5 | LL | 3 | 2 - 1; | ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)` error: operator precedence might not be obvious - --> tests/ui/precedence.rs:33:5 + --> tests/ui/precedence.rs:26:5 | LL | 3 & 5 - 2; | ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)` error: precedence might not be obvious - --> tests/ui/precedence.rs:56:13 + --> tests/ui/precedence.rs:49:13 | LL | let f = |x: W| -> _ { x }.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | let f = (|x: W| -> _ { x }).clone(); | + + error: precedence might not be obvious - --> tests/ui/precedence.rs:60:13 + --> tests/ui/precedence.rs:53:13 | LL | let f = move |x: W| -> _ { x }.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/precedence_bits.fixed b/tests/ui/precedence_bits.fixed index e0ce4a992bb12..20cde92bf3e53 100644 --- a/tests/ui/precedence_bits.fixed +++ b/tests/ui/precedence_bits.fixed @@ -1,12 +1,5 @@ #![warn(clippy::precedence_bits)] -#![allow( - unused_must_use, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::precedence -)] -#![allow(clippy::identity_op)] -#![allow(clippy::eq_op)] +#![expect(clippy::eq_op, clippy::identity_op, clippy::no_effect, clippy::precedence)] macro_rules! trip { ($a:expr) => { diff --git a/tests/ui/precedence_bits.rs b/tests/ui/precedence_bits.rs index 20d17e26c3554..b2613aac1b96e 100644 --- a/tests/ui/precedence_bits.rs +++ b/tests/ui/precedence_bits.rs @@ -1,12 +1,5 @@ #![warn(clippy::precedence_bits)] -#![allow( - unused_must_use, - clippy::no_effect, - clippy::unnecessary_operation, - clippy::precedence -)] -#![allow(clippy::identity_op)] -#![allow(clippy::eq_op)] +#![expect(clippy::eq_op, clippy::identity_op, clippy::no_effect, clippy::precedence)] macro_rules! trip { ($a:expr) => { diff --git a/tests/ui/precedence_bits.stderr b/tests/ui/precedence_bits.stderr index 9cbdca8956d64..28b2c22487c1e 100644 --- a/tests/ui/precedence_bits.stderr +++ b/tests/ui/precedence_bits.stderr @@ -1,5 +1,5 @@ error: operator precedence might not be obvious - --> tests/ui/precedence_bits.rs:28:5 + --> tests/ui/precedence_bits.rs:21:5 | LL | 0x0F00 & 0x00F0 << 4; | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `0x0F00 & (0x00F0 << 4)` @@ -8,19 +8,19 @@ LL | 0x0F00 & 0x00F0 << 4; = help: to override `-D warnings` add `#[allow(clippy::precedence_bits)]` error: operator precedence might not be obvious - --> tests/ui/precedence_bits.rs:30:5 + --> tests/ui/precedence_bits.rs:23:5 | LL | 0x0F00 & 0xF000 >> 4; | ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `0x0F00 & (0xF000 >> 4)` error: operator precedence might not be obvious - --> tests/ui/precedence_bits.rs:32:5 + --> tests/ui/precedence_bits.rs:25:5 | LL | 0x0F00 << 1 ^ 3; | ^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(0x0F00 << 1) ^ 3` error: operator precedence might not be obvious - --> tests/ui/precedence_bits.rs:34:5 + --> tests/ui/precedence_bits.rs:27:5 | LL | 0x0F00 << 1 | 2; | ^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(0x0F00 << 1) | 2` diff --git a/tests/ui/print_in_format_impl.rs b/tests/ui/print_in_format_impl.rs index 8bc7049212209..4abe420d9c04c 100644 --- a/tests/ui/print_in_format_impl.rs +++ b/tests/ui/print_in_format_impl.rs @@ -1,4 +1,3 @@ -#![allow(unused, clippy::print_literal, clippy::write_literal)] #![warn(clippy::print_in_format_impl)] use std::fmt::{Debug, Display, Error, Formatter}; //@no-rustfix diff --git a/tests/ui/print_in_format_impl.stderr b/tests/ui/print_in_format_impl.stderr index 91d6ce953849e..20e3ac82c09fd 100644 --- a/tests/ui/print_in_format_impl.stderr +++ b/tests/ui/print_in_format_impl.stderr @@ -1,5 +1,5 @@ error: use of `print!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:20:9 + --> tests/ui/print_in_format_impl.rs:19:9 | LL | print!("{}", 1); | ^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` @@ -8,37 +8,37 @@ LL | print!("{}", 1); = help: to override `-D warnings` add `#[allow(clippy::print_in_format_impl)]` error: use of `println!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:23:9 + --> tests/ui/print_in_format_impl.rs:22:9 | LL | println!("{}", 2); | ^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `eprint!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:26:9 + --> tests/ui/print_in_format_impl.rs:25:9 | LL | eprint!("{}", 3); | ^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `eprintln!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:29:9 + --> tests/ui/print_in_format_impl.rs:28:9 | LL | eprintln!("{}", 4); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `println!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:33:13 + --> tests/ui/print_in_format_impl.rs:32:13 | LL | println!("nested"); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `print!` in `Display` impl - --> tests/ui/print_in_format_impl.rs:48:9 + --> tests/ui/print_in_format_impl.rs:47:9 | LL | print!("Display"); | ^^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `println!` in `Debug` impl - --> tests/ui/print_in_format_impl.rs:60:9 + --> tests/ui/print_in_format_impl.rs:59:9 | LL | println!("UnnamedFormatter"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(..)` diff --git a/tests/ui/print_literal.fixed b/tests/ui/print_literal.fixed index 26139f9b67102..3baaa1877d1d0 100644 --- a/tests/ui/print_literal.fixed +++ b/tests/ui/print_literal.fixed @@ -1,5 +1,5 @@ #![warn(clippy::print_literal)] -#![allow(clippy::uninlined_format_args, clippy::literal_string_with_formatting_args)] +#![expect(clippy::literal_string_with_formatting_args, clippy::uninlined_format_args)] fn main() { // these should be fine diff --git a/tests/ui/print_literal.rs b/tests/ui/print_literal.rs index 7c4cf028e84cc..32a9476cdbf50 100644 --- a/tests/ui/print_literal.rs +++ b/tests/ui/print_literal.rs @@ -1,5 +1,5 @@ #![warn(clippy::print_literal)] -#![allow(clippy::uninlined_format_args, clippy::literal_string_with_formatting_args)] +#![expect(clippy::literal_string_with_formatting_args, clippy::uninlined_format_args)] fn main() { // these should be fine diff --git a/tests/ui/print_with_newline.fixed b/tests/ui/print_with_newline.fixed index 96c5ee4c1e92c..fa4667c6ac822 100644 --- a/tests/ui/print_with_newline.fixed +++ b/tests/ui/print_with_newline.fixed @@ -1,7 +1,5 @@ -// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 - -#![allow(clippy::print_literal)] #![warn(clippy::print_with_newline)] +#![expect(clippy::print_literal)] fn main() { println!("Hello"); diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs index 60d1e47883081..2757d23e1a2cb 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -1,7 +1,5 @@ -// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 - -#![allow(clippy::print_literal)] #![warn(clippy::print_with_newline)] +#![expect(clippy::print_literal)] fn main() { print!("Hello\n"); diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index 9ead0fca113bb..f1e84bbce1828 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -1,5 +1,5 @@ error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:7:5 + --> tests/ui/print_with_newline.rs:5:5 | LL | print!("Hello\n"); | ^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + println!("Hello"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:10:5 + --> tests/ui/print_with_newline.rs:8:5 | LL | print!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + println!("Hello {}", "world"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:13:5 + --> tests/ui/print_with_newline.rs:11:5 | LL | print!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + println!("Hello {} {}", "world", "#2"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:16:5 + --> tests/ui/print_with_newline.rs:14:5 | LL | print!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("{}", 1265); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:19:5 + --> tests/ui/print_with_newline.rs:17:5 | LL | print!("\n"); | ^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + println!(); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:42:5 + --> tests/ui/print_with_newline.rs:40:5 | LL | print!("\\\n"); | ^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + println!("\\"); | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:52:5 + --> tests/ui/print_with_newline.rs:50:5 | LL | / print!( LL | | @@ -90,7 +90,7 @@ LL ~ | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:57:5 + --> tests/ui/print_with_newline.rs:55:5 | LL | / print!( LL | | @@ -107,7 +107,7 @@ LL ~ | error: using `print!()` with a format string that ends in a single newline - --> tests/ui/print_with_newline.rs:67:5 + --> tests/ui/print_with_newline.rs:65:5 | LL | print!("\\r\n"); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/println_empty_string.fixed b/tests/ui/println_empty_string.fixed index 3a31cbc041340..a735795df432a 100644 --- a/tests/ui/println_empty_string.fixed +++ b/tests/ui/println_empty_string.fixed @@ -1,4 +1,5 @@ -#![allow(clippy::match_single_binding, clippy::unnecessary_trailing_comma)] +#![warn(clippy::println_empty_string)] +#![expect(clippy::match_single_binding)] fn main() { println!(); diff --git a/tests/ui/println_empty_string.rs b/tests/ui/println_empty_string.rs index 79309080131f9..d081338f02a11 100644 --- a/tests/ui/println_empty_string.rs +++ b/tests/ui/println_empty_string.rs @@ -1,4 +1,5 @@ -#![allow(clippy::match_single_binding, clippy::unnecessary_trailing_comma)] +#![warn(clippy::println_empty_string)] +#![expect(clippy::match_single_binding)] fn main() { println!(); diff --git a/tests/ui/println_empty_string.stderr b/tests/ui/println_empty_string.stderr index 82ef3378f1100..ed216ea5f39f1 100644 --- a/tests/ui/println_empty_string.stderr +++ b/tests/ui/println_empty_string.stderr @@ -1,5 +1,5 @@ error: empty string literal in `println!` - --> tests/ui/println_empty_string.rs:5:5 + --> tests/ui/println_empty_string.rs:6:5 | LL | println!(""); | ^^^^^^^^^--^ @@ -10,7 +10,7 @@ LL | println!(""); = help: to override `-D warnings` add `#[allow(clippy::println_empty_string)]` error: empty string literal in `println!` - --> tests/ui/println_empty_string.rs:9:14 + --> tests/ui/println_empty_string.rs:10:14 | LL | _ => println!(""), | ^^^^^^^^^--^ @@ -18,7 +18,7 @@ LL | _ => println!(""), | help: remove the empty string error: empty string literal in `eprintln!` - --> tests/ui/println_empty_string.rs:14:5 + --> tests/ui/println_empty_string.rs:15:5 | LL | eprintln!(""); | ^^^^^^^^^^--^ @@ -26,7 +26,7 @@ LL | eprintln!(""); | help: remove the empty string error: empty string literal in `eprintln!` - --> tests/ui/println_empty_string.rs:18:14 + --> tests/ui/println_empty_string.rs:19:14 | LL | _ => eprintln!(""), | ^^^^^^^^^^--^ @@ -34,7 +34,7 @@ LL | _ => eprintln!(""), | help: remove the empty string error: empty string literal in `println!` - --> tests/ui/println_empty_string.rs:26:5 + --> tests/ui/println_empty_string.rs:27:5 | LL | / println!( LL | |/ "\ @@ -47,7 +47,7 @@ LL | || ); | help: remove the empty string error: empty string literal in `println!` - --> tests/ui/println_empty_string.rs:34:14 + --> tests/ui/println_empty_string.rs:35:14 | LL | _ => println!("" ,), // there is a space between "" and comma | ^^^^^^^^^----^ @@ -55,7 +55,7 @@ LL | _ => println!("" ,), // there is a space between "" and comma | help: remove the empty string error: empty string literal in `eprintln!` - --> tests/ui/println_empty_string.rs:38:5 + --> tests/ui/println_empty_string.rs:39:5 | LL | eprintln!("" ,); // there is a tab between "" and comma | ^^^^^^^^^^-------^ @@ -63,7 +63,7 @@ LL | eprintln!("" ,); // there is a tab between "" and comma | help: remove the empty string error: empty string literal in `eprintln!` - --> tests/ui/println_empty_string.rs:42:14 + --> tests/ui/println_empty_string.rs:43:14 | LL | _ => eprintln!("" ,), // tab and space between "" and comma | ^^^^^^^^^^--------^ @@ -71,7 +71,7 @@ LL | _ => eprintln!("" ,), // tab and space between "" and comma | help: remove the empty string error: empty string literal in `println!` - --> tests/ui/println_empty_string.rs:49:5 + --> tests/ui/println_empty_string.rs:50:5 | LL | println!{""}; | ^^^^^^^^^--^ @@ -79,7 +79,7 @@ LL | println!{""}; | help: remove the empty string error: empty string literal in `println!` - --> tests/ui/println_empty_string.rs:52:5 + --> tests/ui/println_empty_string.rs:53:5 | LL | println![""]; | ^^^^^^^^^--^ @@ -87,7 +87,7 @@ LL | println![""]; | help: remove the empty string error: empty string literal in `eprintln!` - --> tests/ui/println_empty_string.rs:55:5 + --> tests/ui/println_empty_string.rs:56:5 | LL | eprintln!{""}; | ^^^^^^^^^^--^ @@ -95,7 +95,7 @@ LL | eprintln!{""}; | help: remove the empty string error: empty string literal in `eprintln!` - --> tests/ui/println_empty_string.rs:58:5 + --> tests/ui/println_empty_string.rs:59:5 | LL | eprintln![""]; | ^^^^^^^^^^--^ @@ -103,7 +103,7 @@ LL | eprintln![""]; | help: remove the empty string error: empty string literal in `println!` - --> tests/ui/println_empty_string.rs:62:14 + --> tests/ui/println_empty_string.rs:63:14 | LL | _ => println!{""}, | ^^^^^^^^^--^ @@ -111,7 +111,7 @@ LL | _ => println!{""}, | help: remove the empty string error: empty string literal in `println!` - --> tests/ui/println_empty_string.rs:67:14 + --> tests/ui/println_empty_string.rs:68:14 | LL | _ => println![""], | ^^^^^^^^^--^ diff --git a/tests/ui/println_empty_string_unfixable.rs b/tests/ui/println_empty_string_unfixable.rs index d6c30f627a58d..ac1153c975cff 100644 --- a/tests/ui/println_empty_string_unfixable.rs +++ b/tests/ui/println_empty_string_unfixable.rs @@ -1,4 +1,4 @@ -#![allow(clippy::match_single_binding)] +#![warn(clippy::println_empty_string)] // If there is a comment in the span of macro call, we don't provide an auto-fix suggestion. #[rustfmt::skip] diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index be14e0762ff42..5313e40655752 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -1,10 +1,3 @@ -#![allow( - unused, - clippy::many_single_char_names, - clippy::needless_lifetimes, - clippy::redundant_clone, - clippy::needless_pass_by_ref_mut -)] #![warn(clippy::ptr_arg)] //@no-rustfix use std::borrow::Cow; @@ -118,7 +111,6 @@ fn false_positive_capacity_too(x: &String) -> String { x.clone() } -#[allow(dead_code)] fn test_cow_with_ref(c: &Cow<[i32]>) {} //~^ ptr_arg diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index 08746460add1d..993a59a0dd678 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -1,5 +1,5 @@ error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:13:14 + --> tests/ui/ptr_arg.rs:6:14 | LL | fn do_vec(x: &Vec) { | ^^^^^^^^^ @@ -13,7 +13,7 @@ LL + fn do_vec(x: &[i64]) { | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:19:18 + --> tests/ui/ptr_arg.rs:12:18 | LL | fn do_vec_mut(x: &mut Vec) { | ^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + fn do_vec_mut(x: &mut [i64]) { | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:25:19 + --> tests/ui/ptr_arg.rs:18:19 | LL | fn do_vec_mut2(x: &mut Vec) { | ^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + fn do_vec_mut2(x: &mut [i64]) { | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:32:14 + --> tests/ui/ptr_arg.rs:25:14 | LL | fn do_str(x: &String) { | ^^^^^^^ @@ -49,7 +49,7 @@ LL + fn do_str(x: &str) { | error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:38:18 + --> tests/ui/ptr_arg.rs:31:18 | LL | fn do_str_mut(x: &mut String) { | ^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + fn do_str_mut(x: &mut str) { | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:44:15 + --> tests/ui/ptr_arg.rs:37:15 | LL | fn do_path(x: &PathBuf) { | ^^^^^^^^ @@ -73,7 +73,7 @@ LL + fn do_path(x: &Path) { | error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:50:19 + --> tests/ui/ptr_arg.rs:43:19 | LL | fn do_path_mut(x: &mut PathBuf) { | ^^^^^^^^^^^^ @@ -85,13 +85,13 @@ LL + fn do_path_mut(x: &mut Path) { | error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:60:18 + --> tests/ui/ptr_arg.rs:53:18 | LL | fn do_vec(x: &Vec); | ^^^^^^^^^ help: change this to: `&[i64]` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:75:14 + --> tests/ui/ptr_arg.rs:68:14 | LL | fn cloned(x: &Vec) -> Vec { | ^^^^^^^^ @@ -110,7 +110,7 @@ LL ~ x.to_owned() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:86:18 + --> tests/ui/ptr_arg.rs:79:18 | LL | fn str_cloned(x: &String) -> String { | ^^^^^^^ @@ -128,7 +128,7 @@ LL ~ x.to_owned() | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:96:19 + --> tests/ui/ptr_arg.rs:89:19 | LL | fn path_cloned(x: &PathBuf) -> PathBuf { | ^^^^^^^^ @@ -146,7 +146,7 @@ LL ~ x.to_path_buf() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:106:44 + --> tests/ui/ptr_arg.rs:99:44 | LL | fn false_positive_capacity(x: &Vec, y: &String) { | ^^^^^^^ @@ -162,13 +162,13 @@ LL ~ let c = y; | error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:122:25 + --> tests/ui/ptr_arg.rs:114:25 | LL | fn test_cow_with_ref(c: &Cow<[i32]>) {} | ^^^^^^^^^^^ help: change this to: `&[i32]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:152:64 + --> tests/ui/ptr_arg.rs:144:64 | LL | fn some_allowed(#[allow(clippy::ptr_arg)] v: &Vec, s: &String) {} | ^^^^^^^ @@ -180,7 +180,7 @@ LL + fn some_allowed(#[allow(clippy::ptr_arg)] v: &Vec, s: &str) {} | error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:182:21 + --> tests/ui/ptr_arg.rs:174:21 | LL | fn foo_vec(vec: &Vec) { | ^^^^^^^^ @@ -195,7 +195,7 @@ LL ~ let b = vec.to_owned().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:189:23 + --> tests/ui/ptr_arg.rs:181:23 | LL | fn foo_path(path: &PathBuf) { | ^^^^^^^^ @@ -210,7 +210,7 @@ LL ~ let d = path.to_path_buf().clone(); | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:196:21 + --> tests/ui/ptr_arg.rs:188:21 | LL | fn foo_str(str: &String) { | ^^^^^^^ @@ -225,7 +225,7 @@ LL ~ let f = str.to_owned().clone(); | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:204:29 + --> tests/ui/ptr_arg.rs:196:29 | LL | fn mut_vec_slice_methods(v: &mut Vec) { | ^^^^^^^^^^^^^ @@ -237,7 +237,7 @@ LL + fn mut_vec_slice_methods(v: &mut [u32]) { | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:268:17 + --> tests/ui/ptr_arg.rs:260:17 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^^ @@ -249,7 +249,7 @@ LL + fn dyn_trait(a: &mut [u32], b: &mut String, c: &mut PathBuf) { | error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:268:35 + --> tests/ui/ptr_arg.rs:260:35 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^ @@ -261,7 +261,7 @@ LL + fn dyn_trait(a: &mut Vec, b: &mut str, c: &mut PathBuf) { | error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:268:51 + --> tests/ui/ptr_arg.rs:260:51 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^ @@ -273,25 +273,25 @@ LL + fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut Path) { | error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:295:39 + --> tests/ui/ptr_arg.rs:287:39 | LL | fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { | ^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:302:36 + --> tests/ui/ptr_arg.rs:294:36 | LL | fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> tests/ui/ptr_arg.rs:307:40 + --> tests/ui/ptr_arg.rs:299:40 | LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:347:17 + --> tests/ui/ptr_arg.rs:339:17 | LL | fn good(v1: &String, v2: &String) { | ^^^^^^^ @@ -303,7 +303,7 @@ LL + fn good(v1: &str, v2: &String) { | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:347:30 + --> tests/ui/ptr_arg.rs:339:30 | LL | fn good(v1: &String, v2: &String) { | ^^^^^^^ @@ -315,7 +315,7 @@ LL + fn good(v1: &String, v2: &str) { | error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:363:20 + --> tests/ui/ptr_arg.rs:355:20 | LL | fn foo_used(x: &Vec) { | ^^^^^^^^^ @@ -327,7 +327,7 @@ LL + fn foo_used(x: &[i32]) { | error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:377:26 + --> tests/ui/ptr_arg.rs:369:26 | LL | fn foo_local_used(x: &Vec) { | ^^^^^^^^^ @@ -339,7 +339,7 @@ LL + fn foo_local_used(x: &[i32]) { | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:386:33 + --> tests/ui/ptr_arg.rs:378:33 | LL | fn foofoo(_x: &Vec, y: &String) { | ^^^^^^^ @@ -351,7 +351,7 @@ LL + fn foofoo(_x: &Vec, y: &str) { | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:407:20 + --> tests/ui/ptr_arg.rs:399:20 | LL | fn bar_used(x: &mut Vec) { | ^^^^^^^^^^^^^ @@ -363,7 +363,7 @@ LL + fn bar_used(x: &mut [u32]) { | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:421:26 + --> tests/ui/ptr_arg.rs:413:26 | LL | fn bar_local_used(x: &mut Vec) { | ^^^^^^^^^^^^^ @@ -375,7 +375,7 @@ LL + fn bar_local_used(x: &mut [u32]) { | error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> tests/ui/ptr_arg.rs:430:37 + --> tests/ui/ptr_arg.rs:422:37 | LL | fn barbar(_x: &mut Vec, y: &mut String) { | ^^^^^^^^^^^ @@ -387,7 +387,7 @@ LL + fn barbar(_x: &mut Vec, y: &mut str) { | error: eliding a lifetime that's named elsewhere is confusing - --> tests/ui/ptr_arg.rs:314:56 + --> tests/ui/ptr_arg.rs:306:56 | LL | fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str { | -- -- ^^^^ the same lifetime is elided here diff --git a/tests/ui/ptr_cast_constness.fixed b/tests/ui/ptr_cast_constness.fixed index cf57de53d9f3d..db284a0b6a9c3 100644 --- a/tests/ui/ptr_cast_constness.fixed +++ b/tests/ui/ptr_cast_constness.fixed @@ -1,12 +1,7 @@ //@aux-build:proc_macros.rs #![warn(clippy::ptr_cast_constness)] -#![allow( - clippy::transmute_ptr_to_ref, - clippy::unnecessary_cast, - unused, - clippy::missing_transmute_annotations -)] +#![expect(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast)] extern crate proc_macros; use proc_macros::{external, inline_macros}; diff --git a/tests/ui/ptr_cast_constness.rs b/tests/ui/ptr_cast_constness.rs index ea53a0fa8c50f..a374df64497bd 100644 --- a/tests/ui/ptr_cast_constness.rs +++ b/tests/ui/ptr_cast_constness.rs @@ -1,12 +1,7 @@ //@aux-build:proc_macros.rs #![warn(clippy::ptr_cast_constness)] -#![allow( - clippy::transmute_ptr_to_ref, - clippy::unnecessary_cast, - unused, - clippy::missing_transmute_annotations -)] +#![expect(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast)] extern crate proc_macros; use proc_macros::{external, inline_macros}; diff --git a/tests/ui/ptr_cast_constness.stderr b/tests/ui/ptr_cast_constness.stderr index 4adb5cc5ad7fe..3bd1c660211f1 100644 --- a/tests/ui/ptr_cast_constness.stderr +++ b/tests/ui/ptr_cast_constness.stderr @@ -1,5 +1,5 @@ error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:16:45 + --> tests/ui/ptr_cast_constness.rs:11:45 | LL | let _: &mut T = std::mem::transmute(p as *mut T); | ^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `p.cast_mut()` @@ -8,67 +8,67 @@ LL | let _: &mut T = std::mem::transmute(p as *mut T); = help: to override `-D warnings` add `#[allow(clippy::ptr_cast_constness)]` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:18:23 + --> tests/ui/ptr_cast_constness.rs:13:23 | LL | let _ = &mut *(p as *mut T); | ^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `p.cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:35:17 + --> tests/ui/ptr_cast_constness.rs:30:17 | LL | let _ = *ptr_ptr as *mut u32; | ^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `(*ptr_ptr).cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:39:13 + --> tests/ui/ptr_cast_constness.rs:34:13 | LL | let _ = ptr as *mut u32; | ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:41:13 + --> tests/ui/ptr_cast_constness.rs:36:13 | LL | let _ = mut_ptr as *const u32; | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:75:13 + --> tests/ui/ptr_cast_constness.rs:70:13 | LL | let _ = ptr as *mut u32; | ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:77:13 + --> tests/ui/ptr_cast_constness.rs:72:13 | LL | let _ = mut_ptr as *const u32; | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()` error: `as` casting to make a const null pointer into a mutable null pointer - --> tests/ui/ptr_cast_constness.rs:84:13 + --> tests/ui/ptr_cast_constness.rs:79:13 | LL | let _ = ptr::null::() as *mut String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null_mut()` directly instead: `std::ptr::null_mut::()` error: `as` casting to make a mutable null pointer into a const null pointer - --> tests/ui/ptr_cast_constness.rs:86:13 + --> tests/ui/ptr_cast_constness.rs:81:13 | LL | let _ = ptr::null_mut::() as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null()` directly instead: `std::ptr::null::()` error: changing constness of a null pointer - --> tests/ui/ptr_cast_constness.rs:88:13 + --> tests/ui/ptr_cast_constness.rs:83:13 | LL | let _ = ptr::null::().cast_mut(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null_mut()` directly instead: `std::ptr::null_mut::()` error: changing constness of a null pointer - --> tests/ui/ptr_cast_constness.rs:90:13 + --> tests/ui/ptr_cast_constness.rs:85:13 | LL | let _ = ptr::null_mut::().cast_const(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null()` directly instead: `std::ptr::null::()` error: `as` casting to make a const null pointer into a mutable null pointer - --> tests/ui/ptr_cast_constness.rs:94:21 + --> tests/ui/ptr_cast_constness.rs:89:21 | LL | let _ = inline!(ptr::null::() as *mut u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null_mut()` directly instead: `std::ptr::null_mut::()` @@ -76,7 +76,7 @@ LL | let _ = inline!(ptr::null::() as *mut u32); = note: this error originates in the macro `__inline_mac_fn_null_pointers` (in Nightly builds, run with -Z macro-backtrace for more info) error: changing constness of a null pointer - --> tests/ui/ptr_cast_constness.rs:96:21 + --> tests/ui/ptr_cast_constness.rs:91:21 | LL | let _ = inline!(ptr::null::().cast_mut()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `null_mut()` directly instead: `std::ptr::null_mut::()` @@ -84,13 +84,13 @@ LL | let _ = inline!(ptr::null::().cast_mut()); = note: this error originates in the macro `__inline_mac_fn_null_pointers` (in Nightly builds, run with -Z macro-backtrace for more info) error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:106:13 + --> tests/ui/ptr_cast_constness.rs:101:13 | LL | let _ = std::ptr::addr_of_mut!(local) as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `std::ptr::addr_of_mut!(local).cast_const()` error: `as` casting between raw pointers while changing only its constness - --> tests/ui/ptr_cast_constness.rs:112:26 + --> tests/ui/ptr_cast_constness.rs:107:26 | LL | let _ptr: *mut u32 = r as *const _ as *mut _; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `(r as *const u32).cast_mut()` diff --git a/tests/ui/ptr_eq.fixed b/tests/ui/ptr_eq.fixed index d3624a129b5fd..9629b3eea5870 100644 --- a/tests/ui/ptr_eq.fixed +++ b/tests/ui/ptr_eq.fixed @@ -1,5 +1,4 @@ #![warn(clippy::ptr_eq)] -#![allow(function_casts_as_integer)] macro_rules! mac { ($a:expr, $b:expr) => { diff --git a/tests/ui/ptr_eq.rs b/tests/ui/ptr_eq.rs index f06a99cabc814..2b741d8df4684 100644 --- a/tests/ui/ptr_eq.rs +++ b/tests/ui/ptr_eq.rs @@ -1,5 +1,4 @@ #![warn(clippy::ptr_eq)] -#![allow(function_casts_as_integer)] macro_rules! mac { ($a:expr, $b:expr) => { diff --git a/tests/ui/ptr_eq.stderr b/tests/ui/ptr_eq.stderr index f6be4c3f016b5..e7340624b5950 100644 --- a/tests/ui/ptr_eq.stderr +++ b/tests/ui/ptr_eq.stderr @@ -1,5 +1,5 @@ error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:23:13 + --> tests/ui/ptr_eq.rs:22:13 | LL | let _ = a as *const _ as usize == b as *const _ as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` @@ -8,31 +8,31 @@ LL | let _ = a as *const _ as usize == b as *const _ as usize; = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:25:13 + --> tests/ui/ptr_eq.rs:24:13 | LL | let _ = a as *const _ == b as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:51:13 + --> tests/ui/ptr_eq.rs:50:13 | LL | let _ = x as *const u32 == y as *mut u32 as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(x, y)` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:54:13 + --> tests/ui/ptr_eq.rs:53:13 | LL | let _ = x as *const u32 != y as *mut u32 as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!std::ptr::eq(x, y)` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:62:13 + --> tests/ui/ptr_eq.rs:61:13 | LL | let _ = mac!(cast a) as *const _ == mac!(cast b) as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(mac!(cast a), mac!(cast b))` error: use `std::ptr::eq` when comparing raw pointers - --> tests/ui/ptr_eq.rs:66:13 + --> tests/ui/ptr_eq.rs:65:13 | LL | let _ = mac!(cast a) as *const _ == mac!(cast b) as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(mac!(cast a), mac!(cast b))` diff --git a/tests/ui/ptr_offset_by_literal.fixed b/tests/ui/ptr_offset_by_literal.fixed index 174616b1e1513..035e76cdaf29b 100644 --- a/tests/ui/ptr_offset_by_literal.fixed +++ b/tests/ui/ptr_offset_by_literal.fixed @@ -1,5 +1,6 @@ #![warn(clippy::ptr_offset_by_literal)] -#![allow(clippy::inconsistent_digit_grouping, clippy::byte_char_slices)] +#![allow(clippy::inconsistent_digit_grouping)] +#![expect(clippy::byte_char_slices)] fn main() { let arr = [b'a', b'b', b'c']; diff --git a/tests/ui/ptr_offset_by_literal.rs b/tests/ui/ptr_offset_by_literal.rs index d3202cbff9826..6f6a5e52bf8aa 100644 --- a/tests/ui/ptr_offset_by_literal.rs +++ b/tests/ui/ptr_offset_by_literal.rs @@ -1,5 +1,6 @@ #![warn(clippy::ptr_offset_by_literal)] -#![allow(clippy::inconsistent_digit_grouping, clippy::byte_char_slices)] +#![allow(clippy::inconsistent_digit_grouping)] +#![expect(clippy::byte_char_slices)] fn main() { let arr = [b'a', b'b', b'c']; diff --git a/tests/ui/ptr_offset_by_literal.stderr b/tests/ui/ptr_offset_by_literal.stderr index f85fef87d55f2..93efaa29ab1ec 100644 --- a/tests/ui/ptr_offset_by_literal.stderr +++ b/tests/ui/ptr_offset_by_literal.stderr @@ -1,5 +1,5 @@ error: use of `offset` with zero - --> tests/ui/ptr_offset_by_literal.rs:12:17 + --> tests/ui/ptr_offset_by_literal.rs:13:17 | LL | let _ = ptr.offset(0); | ^^^---------- @@ -10,7 +10,7 @@ LL | let _ = ptr.offset(0); = help: to override `-D warnings` add `#[allow(clippy::ptr_offset_by_literal)]` error: use of `offset` with zero - --> tests/ui/ptr_offset_by_literal.rs:14:17 + --> tests/ui/ptr_offset_by_literal.rs:15:17 | LL | let _ = ptr.offset(-0); | ^^^----------- @@ -18,7 +18,7 @@ LL | let _ = ptr.offset(-0); | help: remove the call to `offset` error: use of `offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:17:17 + --> tests/ui/ptr_offset_by_literal.rs:18:17 | LL | let _ = ptr.offset(5); | ^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL + let _ = ptr.add(5); | error: use of `offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:19:17 + --> tests/ui/ptr_offset_by_literal.rs:20:17 | LL | let _ = ptr.offset(-5); | ^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL + let _ = ptr.sub(5); | error: use of `wrapping_offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:25:17 + --> tests/ui/ptr_offset_by_literal.rs:26:17 | LL | let _ = ptr.wrapping_offset(5isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL + let _ = ptr.wrapping_add(5); | error: use of `wrapping_offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:27:17 + --> tests/ui/ptr_offset_by_literal.rs:28:17 | LL | let _ = ptr.wrapping_offset(-5isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL + let _ = ptr.wrapping_sub(5); | error: use of `offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:30:17 + --> tests/ui/ptr_offset_by_literal.rs:31:17 | LL | let _ = ptr.offset(-(5)); | ^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL + let _ = ptr.sub(5); | error: use of `wrapping_offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:32:17 + --> tests/ui/ptr_offset_by_literal.rs:33:17 | LL | let _ = ptr.wrapping_offset(-(5)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL + let _ = ptr.wrapping_sub(5); | error: use of `offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:36:17 + --> tests/ui/ptr_offset_by_literal.rs:37:17 | LL | let _ = ptr.offset(2_147_483_647isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -102,7 +102,7 @@ LL + let _ = ptr.add(2_147_483_647); | error: use of `offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:38:17 + --> tests/ui/ptr_offset_by_literal.rs:39:17 | LL | let _ = ptr.offset(-2_147_483_648isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -114,7 +114,7 @@ LL + let _ = ptr.sub(2_147_483_648); | error: use of `offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:41:17 + --> tests/ui/ptr_offset_by_literal.rs:42:17 | LL | let _ = ptr.offset(5_0__isize); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -126,7 +126,7 @@ LL + let _ = ptr.add(5_0); | error: use of `offset` with a literal - --> tests/ui/ptr_offset_by_literal.rs:43:17 + --> tests/ui/ptr_offset_by_literal.rs:44:17 | LL | let _ = ptr.offset(-5_0__isize); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/ptr_offset_with_cast.fixed b/tests/ui/ptr_offset_with_cast.fixed index 42d1abeaa05a6..11738f051f62c 100644 --- a/tests/ui/ptr_offset_with_cast.fixed +++ b/tests/ui/ptr_offset_with_cast.fixed @@ -1,4 +1,5 @@ -#![expect(clippy::unnecessary_cast, clippy::useless_vec, clippy::needless_borrow)] +#![warn(clippy::ptr_offset_with_cast)] +#![expect(clippy::needless_borrow, clippy::unnecessary_cast, clippy::useless_vec)] fn main() { let vec = vec![b'a', b'b', b'c']; diff --git a/tests/ui/ptr_offset_with_cast.rs b/tests/ui/ptr_offset_with_cast.rs index 6d06a6af1fa2d..6512157dfd06d 100644 --- a/tests/ui/ptr_offset_with_cast.rs +++ b/tests/ui/ptr_offset_with_cast.rs @@ -1,4 +1,5 @@ -#![expect(clippy::unnecessary_cast, clippy::useless_vec, clippy::needless_borrow)] +#![warn(clippy::ptr_offset_with_cast)] +#![expect(clippy::needless_borrow, clippy::unnecessary_cast, clippy::useless_vec)] fn main() { let vec = vec![b'a', b'b', b'c']; diff --git a/tests/ui/ptr_offset_with_cast.stderr b/tests/ui/ptr_offset_with_cast.stderr index 022b3286c93b7..3aaa190a0ac18 100644 --- a/tests/ui/ptr_offset_with_cast.stderr +++ b/tests/ui/ptr_offset_with_cast.stderr @@ -1,5 +1,5 @@ -error: use of `offset` with a `usize` casted to an `isize` - --> tests/ui/ptr_offset_with_cast.rs:12:17 +error: use of `offset` with a `usize` cast to an `isize` + --> tests/ui/ptr_offset_with_cast.rs:13:17 | LL | let _ = ptr.offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,8 +12,8 @@ LL - let _ = ptr.offset(offset_usize as isize); LL + let _ = ptr.add(offset_usize); | -error: use of `wrapping_offset` with a `usize` casted to an `isize` - --> tests/ui/ptr_offset_with_cast.rs:17:17 +error: use of `wrapping_offset` with a `usize` cast to an `isize` + --> tests/ui/ptr_offset_with_cast.rs:18:17 | LL | let _ = ptr.wrapping_offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,8 +24,8 @@ LL - let _ = ptr.wrapping_offset(offset_usize as isize); LL + let _ = ptr.wrapping_add(offset_usize); | -error: use of `offset` with a `usize` casted to an `isize` - --> tests/ui/ptr_offset_with_cast.rs:25:17 +error: use of `offset` with a `usize` cast to an `isize` + --> tests/ui/ptr_offset_with_cast.rs:26:17 | LL | let _ = (&ptr).offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,8 +36,8 @@ LL - let _ = (&ptr).offset(offset_usize as isize); LL + let _ = (&ptr).add(offset_usize); | -error: use of `wrapping_offset` with a `usize` casted to an `isize` - --> tests/ui/ptr_offset_with_cast.rs:27:17 +error: use of `wrapping_offset` with a `usize` cast to an `isize` + --> tests/ui/ptr_offset_with_cast.rs:28:17 | LL | let _ = (&ptr).wrapping_offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/pub_use.rs b/tests/ui/pub_use.rs index be4d1b2a964bc..2e8877418a446 100644 --- a/tests/ui/pub_use.rs +++ b/tests/ui/pub_use.rs @@ -1,5 +1,4 @@ #![warn(clippy::pub_use)] -#![allow(unused_imports)] #![no_main] pub mod outer { diff --git a/tests/ui/pub_use.stderr b/tests/ui/pub_use.stderr index e332a864c5292..2abee7b98d39c 100644 --- a/tests/ui/pub_use.stderr +++ b/tests/ui/pub_use.stderr @@ -1,5 +1,5 @@ error: using `pub use` - --> tests/ui/pub_use.rs:10:5 + --> tests/ui/pub_use.rs:9:5 | LL | pub use inner::Test; | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/pub_with_shorthand.fixed b/tests/ui/pub_with_shorthand.fixed index 4036de8bbc0a6..308e9f6c99a71 100644 --- a/tests/ui/pub_with_shorthand.fixed +++ b/tests/ui/pub_with_shorthand.fixed @@ -1,8 +1,8 @@ //@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] -#![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_with_shorthand)] +#![expect(clippy::needless_pub_self)] #![no_main] #![rustfmt::skip] // rustfmt will remove `in`, understandable // but very annoying for our purposes! diff --git a/tests/ui/pub_with_shorthand.rs b/tests/ui/pub_with_shorthand.rs index fac4ba990447a..74db31d649c36 100644 --- a/tests/ui/pub_with_shorthand.rs +++ b/tests/ui/pub_with_shorthand.rs @@ -1,8 +1,8 @@ //@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] -#![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_with_shorthand)] +#![expect(clippy::needless_pub_self)] #![no_main] #![rustfmt::skip] // rustfmt will remove `in`, understandable // but very annoying for our purposes! diff --git a/tests/ui/pub_without_shorthand.fixed b/tests/ui/pub_without_shorthand.fixed index fbe3326400cbc..ff3a1b76e5663 100644 --- a/tests/ui/pub_without_shorthand.fixed +++ b/tests/ui/pub_without_shorthand.fixed @@ -1,8 +1,8 @@ //@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] -#![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_without_shorthand)] +#![expect(clippy::needless_pub_self)] #![no_main] #![rustfmt::skip] // rustfmt will remove `in`, understandable // but very annoying for our purposes! diff --git a/tests/ui/pub_without_shorthand.rs b/tests/ui/pub_without_shorthand.rs index fb756096c9d95..3536b488a2206 100644 --- a/tests/ui/pub_without_shorthand.rs +++ b/tests/ui/pub_without_shorthand.rs @@ -1,8 +1,8 @@ //@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] -#![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_without_shorthand)] +#![expect(clippy::needless_pub_self)] #![no_main] #![rustfmt::skip] // rustfmt will remove `in`, understandable // but very annoying for our purposes! diff --git a/tests/ui/question_mark.fixed b/tests/ui/question_mark.fixed index 786431bc1f539..32effaf99dddd 100644 --- a/tests/ui/question_mark.fixed +++ b/tests/ui/question_mark.fixed @@ -1,9 +1,10 @@ #![feature(try_blocks)] +#![warn(clippy::question_mark)] #![allow( - clippy::unnecessary_wraps, - clippy::no_effect, clippy::needless_return, - clippy::toplevel_ref_arg + clippy::no_effect, + clippy::toplevel_ref_arg, + clippy::unnecessary_wraps )] use std::sync::MutexGuard; @@ -404,7 +405,6 @@ fn issue_13417_mut(foo: &mut StructWithOptionString) -> Option { } #[allow(clippy::disallowed_names)] -#[allow(unused)] fn issue_13417_weirder(foo: &mut StructWithOptionString, mut bar: Option) -> Option<()> { let x @ y = foo.opt_x.as_ref()?; //~^^^ question_mark diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs index 7cbcc604eb591..18e8404dea22c 100644 --- a/tests/ui/question_mark.rs +++ b/tests/ui/question_mark.rs @@ -1,9 +1,10 @@ #![feature(try_blocks)] +#![warn(clippy::question_mark)] #![allow( - clippy::unnecessary_wraps, - clippy::no_effect, clippy::needless_return, - clippy::toplevel_ref_arg + clippy::no_effect, + clippy::toplevel_ref_arg, + clippy::unnecessary_wraps )] use std::sync::MutexGuard; @@ -492,7 +493,6 @@ fn issue_13417_mut(foo: &mut StructWithOptionString) -> Option { } #[allow(clippy::disallowed_names)] -#[allow(unused)] fn issue_13417_weirder(foo: &mut StructWithOptionString, mut bar: Option) -> Option<()> { let Some(ref x @ ref y) = foo.opt_x else { return None; diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr index 74fb2c45a2549..abb4c9531754f 100644 --- a/tests/ui/question_mark.stderr +++ b/tests/ui/question_mark.stderr @@ -1,5 +1,5 @@ error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:12:5 + --> tests/ui/question_mark.rs:13:5 | LL | / if a.is_none() { LL | | @@ -11,7 +11,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::question_mark)]` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:58:9 + --> tests/ui/question_mark.rs:59:9 | LL | / if (self.opt).is_none() { LL | | @@ -20,7 +20,7 @@ LL | | } | |_________^ help: replace it with: `(self.opt)?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:63:9 + --> tests/ui/question_mark.rs:64:9 | LL | / if self.opt.is_none() { LL | | @@ -29,7 +29,7 @@ LL | | } | |_________^ help: replace it with: `self.opt?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:68:17 + --> tests/ui/question_mark.rs:69:17 | LL | let _ = if self.opt.is_none() { | _________________^ @@ -41,7 +41,7 @@ LL | | }; | |_________^ help: replace it with: `Some(self.opt?)` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:75:17 + --> tests/ui/question_mark.rs:76:17 | LL | let _ = if let Some(x) = self.opt { | _________________^ @@ -53,7 +53,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:93:9 + --> tests/ui/question_mark.rs:94:9 | LL | / if self.opt.is_none() { LL | | @@ -62,7 +62,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:102:9 + --> tests/ui/question_mark.rs:103:9 | LL | / if self.opt.is_none() { LL | | @@ -71,7 +71,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:111:9 + --> tests/ui/question_mark.rs:112:9 | LL | / if self.opt.is_none() { LL | | @@ -80,7 +80,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:119:26 + --> tests/ui/question_mark.rs:120:26 | LL | let v: &Vec<_> = if let Some(ref v) = self.opt { | __________________________^ @@ -92,7 +92,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt.as_ref()?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:130:17 + --> tests/ui/question_mark.rs:131:17 | LL | let v = if let Some(v) = self.opt { | _________________^ @@ -104,7 +104,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:152:5 + --> tests/ui/question_mark.rs:153:5 | LL | / if f().is_none() { LL | | @@ -113,7 +113,7 @@ LL | | } | |_____^ help: replace it with: `f()?;` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:157:16 + --> tests/ui/question_mark.rs:158:16 | LL | let _val = match f() { | ________________^ @@ -124,7 +124,7 @@ LL | | }; | |_____^ help: try instead: `f()?` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:163:19 + --> tests/ui/question_mark.rs:164:19 | LL | let s: &str = match &Some(String::new()) { | ___________________^ @@ -135,7 +135,7 @@ LL | | }; | |_____^ help: try instead: `&Some(String::new())?` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:169:5 + --> tests/ui/question_mark.rs:170:5 | LL | / match f() { LL | | @@ -145,7 +145,7 @@ LL | | }; | |_____^ help: try instead: `f()?` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:175:5 + --> tests/ui/question_mark.rs:176:5 | LL | / match opt_none!() { LL | | @@ -155,7 +155,7 @@ LL | | }; | |_____^ help: try instead: `opt_none!()?` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:186:5 + --> tests/ui/question_mark.rs:187:5 | LL | / match f() { LL | | @@ -176,13 +176,13 @@ LL ~ }; | error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:203:13 + --> tests/ui/question_mark.rs:204:13 | LL | let _ = if let Ok(x) = x { x } else { return x }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:206:5 + --> tests/ui/question_mark.rs:207:5 | LL | / if x.is_err() { LL | | @@ -191,7 +191,7 @@ LL | | } | |_____^ help: replace it with: `x?;` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:211:16 + --> tests/ui/question_mark.rs:212:16 | LL | let _val = match func_returning_result() { | ________________^ @@ -202,7 +202,7 @@ LL | | }; | |_____^ help: try instead: `func_returning_result()?` error: this `match` expression can be replaced with `?` - --> tests/ui/question_mark.rs:217:5 + --> tests/ui/question_mark.rs:218:5 | LL | / match func_returning_result() { LL | | @@ -212,7 +212,7 @@ LL | | }; | |_____^ help: try instead: `func_returning_result()?` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:309:5 + --> tests/ui/question_mark.rs:310:5 | LL | / if let Err(err) = func_returning_result() { LL | | @@ -221,7 +221,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:317:5 + --> tests/ui/question_mark.rs:318:5 | LL | / if let Err(err) = func_returning_result() { LL | | @@ -230,7 +230,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:400:13 + --> tests/ui/question_mark.rs:401:13 | LL | / if a.is_none() { LL | | @@ -240,7 +240,7 @@ LL | | } | |_____________^ help: replace it with: `a?;` error: this `let...else` may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:461:5 + --> tests/ui/question_mark.rs:462:5 | LL | / let Some(v) = bar.foo.owned.clone() else { LL | | return None; @@ -248,7 +248,7 @@ LL | | }; | |______^ help: replace it with: `let v = bar.foo.owned.clone()?;` error: this `let...else` may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:476:5 + --> tests/ui/question_mark.rs:477:5 | LL | / let Some(ref x) = foo.opt_x else { LL | | return None; @@ -256,7 +256,7 @@ LL | | }; | |______^ help: replace it with: `let x = foo.opt_x.as_ref()?;` error: this `let...else` may be rewritten with the `?` operator - --> tests/ui/question_mark.rs:486:5 + --> tests/ui/question_mark.rs:487:5 | LL | / let Some(ref mut x) = foo.opt_x else { LL | | return None; diff --git a/tests/ui/question_mark_used.rs b/tests/ui/question_mark_used.rs index 9e204d1e9f3c2..978c4d7bf171d 100644 --- a/tests/ui/question_mark_used.rs +++ b/tests/ui/question_mark_used.rs @@ -1,6 +1,4 @@ // non rustfixable -#![allow(unreachable_code)] -#![allow(dead_code)] #![warn(clippy::question_mark_used)] fn other_function() -> Option { diff --git a/tests/ui/question_mark_used.stderr b/tests/ui/question_mark_used.stderr index 82f0d32504077..1a256ab2e45af 100644 --- a/tests/ui/question_mark_used.stderr +++ b/tests/ui/question_mark_used.stderr @@ -1,5 +1,5 @@ error: the `?` operator was used - --> tests/ui/question_mark_used.rs:11:5 + --> tests/ui/question_mark_used.rs:9:5 | LL | other_function()?; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/range.fixed b/tests/ui/range.fixed index c8e654600045e..80a74af3b031f 100644 --- a/tests/ui/range.fixed +++ b/tests/ui/range.fixed @@ -1,5 +1,4 @@ -#![allow(clippy::useless_vec)] -#[warn(clippy::range_zip_with_len)] +#![warn(clippy::range_zip_with_len)] fn main() { let v1: Vec = vec![1, 2, 3]; let v2: Vec = vec![4, 5]; @@ -21,7 +20,6 @@ fn main() { let _y = v1.iter().zip(0..v2.len()); // No error } -#[allow(unused)] fn no_panic_with_fake_range_types() { struct Range { foo: i32, diff --git a/tests/ui/range.rs b/tests/ui/range.rs index 352d517eabdd7..c948a6ec5c735 100644 --- a/tests/ui/range.rs +++ b/tests/ui/range.rs @@ -1,5 +1,4 @@ -#![allow(clippy::useless_vec)] -#[warn(clippy::range_zip_with_len)] +#![warn(clippy::range_zip_with_len)] fn main() { let v1: Vec = vec![1, 2, 3]; let v2: Vec = vec![4, 5]; @@ -21,7 +20,6 @@ fn main() { let _y = v1.iter().zip(0..v2.len()); // No error } -#[allow(unused)] fn no_panic_with_fake_range_types() { struct Range { foo: i32, diff --git a/tests/ui/range.stderr b/tests/ui/range.stderr index e3b2e3c90058f..34b0f7129c1d2 100644 --- a/tests/ui/range.stderr +++ b/tests/ui/range.stderr @@ -1,5 +1,5 @@ error: using `.zip()` with a range and `.len()` - --> tests/ui/range.rs:6:14 + --> tests/ui/range.rs:5:14 | LL | let _x = v1.iter().zip(0..v1.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,7 +14,7 @@ LL + let _x = v1.iter().enumerate(); | error: using `.zip()` with a range and `.len()` - --> tests/ui/range.rs:10:19 + --> tests/ui/range.rs:9:19 | LL | for (e, i) in v1.iter().zip(0..v1.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL + for (i, e) in v1.iter().enumerate() { | error: using `.zip()` with a range and `.len()` - --> tests/ui/range.rs:16:5 + --> tests/ui/range.rs:15:5 | LL | v1.iter().zip(0..v1.len()).for_each(|(e, i)| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/range_contains.fixed b/tests/ui/range_contains.fixed index 859f12d79d486..b76ad74d1dbea 100644 --- a/tests/ui/range_contains.fixed +++ b/tests/ui/range_contains.fixed @@ -1,10 +1,10 @@ #![warn(clippy::manual_range_contains)] -#![allow(unused)] -#![allow(clippy::no_effect)] -#![allow(clippy::short_circuit_statement)] -#![allow(clippy::unnecessary_operation)] -#![allow(clippy::impossible_comparisons)] -#![allow(clippy::redundant_comparisons)] +#![expect(clippy::impossible_comparisons, clippy::no_effect)] +#![allow( + clippy::redundant_comparisons, + clippy::short_circuit_statement, + clippy::unnecessary_operation +)] fn main() { let x = 9_i32; diff --git a/tests/ui/range_contains.rs b/tests/ui/range_contains.rs index b39767a85034b..dc1ad9a8242a7 100644 --- a/tests/ui/range_contains.rs +++ b/tests/ui/range_contains.rs @@ -1,10 +1,10 @@ #![warn(clippy::manual_range_contains)] -#![allow(unused)] -#![allow(clippy::no_effect)] -#![allow(clippy::short_circuit_statement)] -#![allow(clippy::unnecessary_operation)] -#![allow(clippy::impossible_comparisons)] -#![allow(clippy::redundant_comparisons)] +#![expect(clippy::impossible_comparisons, clippy::no_effect)] +#![allow( + clippy::redundant_comparisons, + clippy::short_circuit_statement, + clippy::unnecessary_operation +)] fn main() { let x = 9_i32; diff --git a/tests/ui/range_plus_minus_one.fixed b/tests/ui/range_plus_minus_one.fixed index 4c0cb86611973..c5198c15a3e41 100644 --- a/tests/ui/range_plus_minus_one.fixed +++ b/tests/ui/range_plus_minus_one.fixed @@ -1,6 +1,4 @@ #![warn(clippy::range_minus_one, clippy::range_plus_one)] -#![allow(unused_parens)] -#![allow(clippy::iter_with_drain)] use std::ops::{Index, IndexMut, Range, RangeBounds, RangeInclusive}; diff --git a/tests/ui/range_plus_minus_one.rs b/tests/ui/range_plus_minus_one.rs index c853d1f9387a2..697aa8bfe2efd 100644 --- a/tests/ui/range_plus_minus_one.rs +++ b/tests/ui/range_plus_minus_one.rs @@ -1,6 +1,4 @@ #![warn(clippy::range_minus_one, clippy::range_plus_one)] -#![allow(unused_parens)] -#![allow(clippy::iter_with_drain)] use std::ops::{Index, IndexMut, Range, RangeBounds, RangeInclusive}; diff --git a/tests/ui/range_plus_minus_one.stderr b/tests/ui/range_plus_minus_one.stderr index 93d74b1d840c9..993d96e231845 100644 --- a/tests/ui/range_plus_minus_one.stderr +++ b/tests/ui/range_plus_minus_one.stderr @@ -1,5 +1,5 @@ error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:31:14 + --> tests/ui/range_plus_minus_one.rs:29:14 | LL | for _ in 0..3 + 1 {} | ^^^^^^^^ help: use: `0..=3` @@ -8,73 +8,73 @@ LL | for _ in 0..3 + 1 {} = help: to override `-D warnings` add `#[allow(clippy::range_plus_one)]` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:35:14 + --> tests/ui/range_plus_minus_one.rs:33:14 | LL | for _ in 0..1 + 5 {} | ^^^^^^^^ help: use: `0..=5` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:39:14 + --> tests/ui/range_plus_minus_one.rs:37:14 | LL | for _ in 1..1 + 1 {} | ^^^^^^^^ help: use: `1..=1` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:46:14 + --> tests/ui/range_plus_minus_one.rs:44:14 | LL | for _ in 0..(1 + f()) {} | ^^^^^^^^^^^^ help: use: `0..=f()` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:68:6 + --> tests/ui/range_plus_minus_one.rs:66:6 | LL | (1..10 + 1).for_each(|_| {}); | ^^^^^^^^^ help: use: `1..=10` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:73:6 + --> tests/ui/range_plus_minus_one.rs:71:6 | LL | (1..10 + 1).into_iter().for_each(|_| {}); | ^^^^^^^^^ help: use: `1..=10` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:78:18 + --> tests/ui/range_plus_minus_one.rs:76:18 | LL | let _ = (1..10 + 1).start_bound(); | ^^^^^^^^^ help: use: `1..=10` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:84:16 + --> tests/ui/range_plus_minus_one.rs:82:16 | LL | let _ = &a[1..1 + 1]; | ^^^^^^^^ help: use: `1..=1` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:88:15 + --> tests/ui/range_plus_minus_one.rs:86:15 | LL | vec.drain(2..3 + 1); | ^^^^^^^^ help: use: `2..=3` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:92:14 + --> tests/ui/range_plus_minus_one.rs:90:14 | LL | take_arg(10..20 + 1); | ^^^^^^^^^^ help: use: `10..=20` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:96:16 + --> tests/ui/range_plus_minus_one.rs:94:16 | LL | take_arg({ 10..20 + 1 }); | ^^^^^^^^^^ help: use: `10..=20` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:110:7 + --> tests/ui/range_plus_minus_one.rs:108:7 | LL | a[0..2 + 1][0] = 1; | ^^^^^^^^ help: use: `0..=2` error: an exclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:178:6 + --> tests/ui/range_plus_minus_one.rs:176:6 | LL | (1..=n - 1).sum() | ^^^^^^^^^ help: use: `1..n` @@ -83,7 +83,7 @@ LL | (1..=n - 1).sum() = help: to override `-D warnings` add `#[allow(clippy::range_minus_one)]` error: an inclusive range would be more readable - --> tests/ui/range_plus_minus_one.rs:190:14 + --> tests/ui/range_plus_minus_one.rs:188:14 | LL | for _ in test!(x)..test!(x) + 1 { | ^^^^^^^^^^^^^^^^^^^^^^ help: use: `test!(x)..=test!(x)` diff --git a/tests/ui/range_unfixable.rs b/tests/ui/range_unfixable.rs index 259be23fa1e5a..6ecd0739fb42c 100644 --- a/tests/ui/range_unfixable.rs +++ b/tests/ui/range_unfixable.rs @@ -1,6 +1,5 @@ //@no-rustfix -#![allow(clippy::useless_vec)] -#[warn(clippy::range_zip_with_len)] +#![warn(clippy::range_zip_with_len)] fn main() { let v1: Vec = vec![1, 2, 3]; let v2: Vec = vec![4, 5]; diff --git a/tests/ui/range_unfixable.stderr b/tests/ui/range_unfixable.stderr index 3ddb0c2a991bf..14f183d96b28e 100644 --- a/tests/ui/range_unfixable.stderr +++ b/tests/ui/range_unfixable.stderr @@ -1,5 +1,5 @@ error: using `.zip()` with a range and `.len()` - --> tests/ui/range_unfixable.rs:10:5 + --> tests/ui/range_unfixable.rs:9:5 | LL | v1.iter().zip(0..v1.len()).filter(|(_, i)| *i < 2).for_each(|(e, i)| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/rc_clone_in_vec_init/arc.rs b/tests/ui/rc_clone_in_vec_init/arc.rs index ad5d131f34bc6..c261795375d7c 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.rs +++ b/tests/ui/rc_clone_in_vec_init/arc.rs @@ -1,6 +1,6 @@ //@no-rustfix: overlapping suggestions #![warn(clippy::rc_clone_in_vec_init)] -#![allow(clippy::useless_vec)] +#![expect(clippy::useless_vec)] use std::sync::{Arc, Mutex}; fn main() {} diff --git a/tests/ui/rc_clone_in_vec_init/rc.rs b/tests/ui/rc_clone_in_vec_init/rc.rs index d5af17c29e1d8..cc1a107a853a4 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.rs +++ b/tests/ui/rc_clone_in_vec_init/rc.rs @@ -1,6 +1,6 @@ //@no-rustfix: overlapping suggestions #![warn(clippy::rc_clone_in_vec_init)] -#![allow(clippy::useless_vec)] +#![expect(clippy::useless_vec)] use std::rc::Rc; use std::sync::Mutex; diff --git a/tests/ui/rc_clone_in_vec_init/weak.rs b/tests/ui/rc_clone_in_vec_init/weak.rs index add09b6ba859e..f0ae7431375f7 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.rs +++ b/tests/ui/rc_clone_in_vec_init/weak.rs @@ -1,6 +1,6 @@ //@no-rustfix: overlapping suggestions #![warn(clippy::rc_clone_in_vec_init)] -#![allow(clippy::useless_vec)] +#![expect(clippy::useless_vec)] use std::rc::{Rc, Weak as UnSyncWeak}; use std::sync::{Arc, Mutex, Weak as SyncWeak}; diff --git a/tests/ui/rc_mutex.rs b/tests/ui/rc_mutex.rs index c8700e13b11e5..43f6fae300d23 100644 --- a/tests/ui/rc_mutex.rs +++ b/tests/ui/rc_mutex.rs @@ -1,5 +1,5 @@ #![warn(clippy::rc_mutex)] -#![allow(unused, clippy::disallowed_names)] +#![expect(clippy::disallowed_names)] use std::rc::Rc; use std::sync::Mutex; diff --git a/tests/ui/read_line_without_trim.fixed b/tests/ui/read_line_without_trim.fixed index e7f208e78d203..bbb5d98f4c9b0 100644 --- a/tests/ui/read_line_without_trim.fixed +++ b/tests/ui/read_line_without_trim.fixed @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::read_line_without_trim)] fn main() { diff --git a/tests/ui/read_line_without_trim.rs b/tests/ui/read_line_without_trim.rs index 6664278b5a876..dba325fd08498 100644 --- a/tests/ui/read_line_without_trim.rs +++ b/tests/ui/read_line_without_trim.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::read_line_without_trim)] fn main() { diff --git a/tests/ui/read_line_without_trim.stderr b/tests/ui/read_line_without_trim.stderr index 5e5618111432a..55a19b06e8b6e 100644 --- a/tests/ui/read_line_without_trim.stderr +++ b/tests/ui/read_line_without_trim.stderr @@ -1,5 +1,5 @@ error: calling `.parse()` on a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:12:25 + --> tests/ui/read_line_without_trim.rs:11:25 | LL | let _x: i32 = input.parse().unwrap(); | ----- ^^^^^^^ @@ -7,7 +7,7 @@ LL | let _x: i32 = input.parse().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the checking to always fail - --> tests/ui/read_line_without_trim.rs:11:5 + --> tests/ui/read_line_without_trim.rs:10:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | std::io::stdin().read_line(&mut input).unwrap(); = help: to override `-D warnings` add `#[allow(clippy::read_line_without_trim)]` error: calling `.parse()` on a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:17:20 + --> tests/ui/read_line_without_trim.rs:16:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -23,13 +23,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the checking to always fail - --> tests/ui/read_line_without_trim.rs:16:5 + --> tests/ui/read_line_without_trim.rs:15:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` on a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:22:20 + --> tests/ui/read_line_without_trim.rs:21:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -37,13 +37,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the checking to always fail - --> tests/ui/read_line_without_trim.rs:21:5 + --> tests/ui/read_line_without_trim.rs:20:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` on a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:27:20 + --> tests/ui/read_line_without_trim.rs:26:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -51,13 +51,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the checking to always fail - --> tests/ui/read_line_without_trim.rs:26:5 + --> tests/ui/read_line_without_trim.rs:25:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` on a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:32:20 + --> tests/ui/read_line_without_trim.rs:31:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^^ @@ -65,13 +65,13 @@ LL | let _x = input.parse::().unwrap(); | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the checking to always fail - --> tests/ui/read_line_without_trim.rs:31:5 + --> tests/ui/read_line_without_trim.rs:30:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: comparing a string literal without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:43:8 + --> tests/ui/read_line_without_trim.rs:42:8 | LL | if input == "foo" { | -----^^^^^^^^^ @@ -79,13 +79,13 @@ LL | if input == "foo" { | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the comparison to always fail - --> tests/ui/read_line_without_trim.rs:42:5 + --> tests/ui/read_line_without_trim.rs:41:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: checking the end of a string without trimming the trailing newline character - --> tests/ui/read_line_without_trim.rs:50:8 + --> tests/ui/read_line_without_trim.rs:49:8 | LL | if input.ends_with("foo") { | -----^^^^^^^^^^^^^^^^^ @@ -93,7 +93,7 @@ LL | if input.ends_with("foo") { | help: try: `input.trim_end()` | note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause the parsing to always fail - --> tests/ui/read_line_without_trim.rs:49:5 + --> tests/ui/read_line_without_trim.rs:48:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/read_zero_byte_vec.rs b/tests/ui/read_zero_byte_vec.rs index 720276cb55488..36d0c9a684880 100644 --- a/tests/ui/read_zero_byte_vec.rs +++ b/tests/ui/read_zero_byte_vec.rs @@ -1,9 +1,5 @@ #![warn(clippy::read_zero_byte_vec)] -#![allow( - clippy::unused_io_amount, - clippy::needless_pass_by_ref_mut, - clippy::slow_vector_initialization -)] +#![expect(clippy::slow_vector_initialization, clippy::unused_io_amount)] use std::fs::File; use std::io; use std::io::prelude::*; diff --git a/tests/ui/read_zero_byte_vec.stderr b/tests/ui/read_zero_byte_vec.stderr index 8dd74592e4c15..4e5ac17a9c479 100644 --- a/tests/ui/read_zero_byte_vec.stderr +++ b/tests/ui/read_zero_byte_vec.stderr @@ -1,5 +1,5 @@ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:22:5 + --> tests/ui/read_zero_byte_vec.rs:18:5 | LL | f.read_exact(&mut data).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL ~ f.read_exact(&mut data).unwrap(); | error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:28:5 + --> tests/ui/read_zero_byte_vec.rs:24:5 | LL | f.read_exact(&mut data2)?; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,61 +25,61 @@ LL ~ f.read_exact(&mut data2)?; | error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:33:5 + --> tests/ui/read_zero_byte_vec.rs:29:5 | LL | f.read_exact(&mut data3)?; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:38:13 + --> tests/ui/read_zero_byte_vec.rs:34:13 | LL | let _ = f.read(&mut data4)?; | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:44:9 + --> tests/ui/read_zero_byte_vec.rs:40:9 | LL | f.read(&mut data5) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:51:9 + --> tests/ui/read_zero_byte_vec.rs:47:9 | LL | f.read(&mut data6) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:85:9 + --> tests/ui/read_zero_byte_vec.rs:81:9 | LL | f.read(&mut v)?; | ^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:95:5 + --> tests/ui/read_zero_byte_vec.rs:91:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:100:5 + --> tests/ui/read_zero_byte_vec.rs:96:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:107:5 + --> tests/ui/read_zero_byte_vec.rs:103:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:112:5 + --> tests/ui/read_zero_byte_vec.rs:108:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:131:30 + --> tests/ui/read_zero_byte_vec.rs:127:30 | LL | let num_bytes_received = stream_and_addr.0.read(&mut buf).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL ~ let num_bytes_received = stream_and_addr.0.read(&mut buf).unwrap(); | error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:136:30 + --> tests/ui/read_zero_byte_vec.rs:132:30 | LL | let num_bytes_received = stream_and_addr.0.read(&mut buf).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,7 +103,7 @@ LL ~ let num_bytes_received = stream_and_addr.0.read(&mut buf).unwrap(); | error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:141:32 + --> tests/ui/read_zero_byte_vec.rs:137:32 | LL | let num_bytes_received = { stream_and_addr.0.read(&mut buf) }.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -115,7 +115,7 @@ LL ~ let num_bytes_received = { stream_and_addr.0.read(&mut buf) }.unwrap(); | error: reading zero byte data to `Vec` - --> tests/ui/read_zero_byte_vec.rs:147:5 + --> tests/ui/read_zero_byte_vec.rs:143:5 | LL | f.read(&mut data).unwrap() | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/recursive_format_impl.rs b/tests/ui/recursive_format_impl.rs index 936d56877055e..56a42230a08da 100644 --- a/tests/ui/recursive_format_impl.rs +++ b/tests/ui/recursive_format_impl.rs @@ -1,11 +1,11 @@ #![warn(clippy::recursive_format_impl)] -#![allow( +#![expect( clippy::borrow_deref_ref, clippy::deref_addrof, clippy::inherent_to_string_shadow_display, - clippy::useless_borrows_in_formatting, clippy::to_string_in_format_args, - clippy::uninlined_format_args + clippy::uninlined_format_args, + clippy::useless_borrows_in_formatting )] use std::fmt; diff --git a/tests/ui/redundant_allocation.rs b/tests/ui/redundant_allocation.rs index 832f147c6ed53..0e831dcddadc4 100644 --- a/tests/ui/redundant_allocation.rs +++ b/tests/ui/redundant_allocation.rs @@ -1,4 +1,5 @@ -#![allow(clippy::boxed_local, clippy::disallowed_names)] +#![warn(clippy::redundant_allocation)] +#![expect(clippy::boxed_local, clippy::disallowed_names)] pub struct MyStruct; diff --git a/tests/ui/redundant_allocation.stderr b/tests/ui/redundant_allocation.stderr index 886ed2088c67b..44d30f95d7bc3 100644 --- a/tests/ui/redundant_allocation.stderr +++ b/tests/ui/redundant_allocation.stderr @@ -1,5 +1,5 @@ error: usage of `Box>` - --> tests/ui/redundant_allocation.rs:15:30 + --> tests/ui/redundant_allocation.rs:16:30 | LL | pub fn box_test6(foo: Box>) {} | ^^^^^^^^^^ @@ -10,7 +10,7 @@ LL | pub fn box_test6(foo: Box>) {} = help: to override `-D warnings` add `#[allow(clippy::redundant_allocation)]` error: usage of `Box>` - --> tests/ui/redundant_allocation.rs:18:30 + --> tests/ui/redundant_allocation.rs:19:30 | LL | pub fn box_test7(foo: Box>) {} | ^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | pub fn box_test7(foo: Box>) {} = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> tests/ui/redundant_allocation.rs:21:27 + --> tests/ui/redundant_allocation.rs:22:27 | LL | pub fn box_test8() -> Box>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | pub fn box_test8() -> Box>> { = help: consider using just `Box>` or `Rc>` error: usage of `Box>` - --> tests/ui/redundant_allocation.rs:27:30 + --> tests/ui/redundant_allocation.rs:28:30 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> tests/ui/redundant_allocation.rs:27:46 + --> tests/ui/redundant_allocation.rs:28:46 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box>` or `Arc>` error: usage of `Rc>` - --> tests/ui/redundant_allocation.rs:41:24 + --> tests/ui/redundant_allocation.rs:42:24 | LL | pub fn rc_test5(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | pub fn rc_test5(a: Rc>) {} = help: consider using just `Rc` or `Box` error: usage of `Rc>` - --> tests/ui/redundant_allocation.rs:44:24 + --> tests/ui/redundant_allocation.rs:45:24 | LL | pub fn rc_test7(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | pub fn rc_test7(a: Rc>) {} = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:47:26 + --> tests/ui/redundant_allocation.rs:48:26 | LL | pub fn rc_test8() -> Rc>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | pub fn rc_test8() -> Rc>> { = help: consider using just `Rc>` or `Box>` error: usage of `Rc>` - --> tests/ui/redundant_allocation.rs:53:29 + --> tests/ui/redundant_allocation.rs:54:29 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:53:44 + --> tests/ui/redundant_allocation.rs:54:44 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc>` or `Arc>` error: usage of `Arc>` - --> tests/ui/redundant_allocation.rs:67:25 + --> tests/ui/redundant_allocation.rs:68:25 | LL | pub fn arc_test5(a: Arc>) {} | ^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | pub fn arc_test5(a: Arc>) {} = help: consider using just `Arc` or `Box` error: usage of `Arc>` - --> tests/ui/redundant_allocation.rs:70:25 + --> tests/ui/redundant_allocation.rs:71:25 | LL | pub fn arc_test6(a: Arc>) {} | ^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL | pub fn arc_test6(a: Arc>) {} = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> tests/ui/redundant_allocation.rs:73:27 + --> tests/ui/redundant_allocation.rs:74:27 | LL | pub fn arc_test8() -> Arc>> { | ^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL | pub fn arc_test8() -> Arc>> { = help: consider using just `Arc>` or `Box>` error: usage of `Arc>` - --> tests/ui/redundant_allocation.rs:79:30 + --> tests/ui/redundant_allocation.rs:80:30 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^ @@ -127,7 +127,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> tests/ui/redundant_allocation.rs:79:45 + --> tests/ui/redundant_allocation.rs:80:45 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc>` or `Rc>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:104:27 + --> tests/ui/redundant_allocation.rs:105:27 | LL | pub fn test_rc_box(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | pub fn test_rc_box(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:137:31 + --> tests/ui/redundant_allocation.rs:138:31 | LL | pub fn test_rc_box_str(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | pub fn test_rc_box_str(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:140:33 + --> tests/ui/redundant_allocation.rs:141:33 | LL | pub fn test_rc_box_slice(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -163,7 +163,7 @@ LL | pub fn test_rc_box_slice(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:143:32 + --> tests/ui/redundant_allocation.rs:144:32 | LL | pub fn test_rc_box_path(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^ @@ -172,7 +172,7 @@ LL | pub fn test_rc_box_path(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> tests/ui/redundant_allocation.rs:146:34 + --> tests/ui/redundant_allocation.rs:147:34 | LL | pub fn test_rc_box_custom(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_allocation_fixable.fixed b/tests/ui/redundant_allocation_fixable.fixed index dbc6c0794d1a7..6d70d911f26fa 100644 --- a/tests/ui/redundant_allocation_fixable.fixed +++ b/tests/ui/redundant_allocation_fixable.fixed @@ -1,5 +1,5 @@ -#![allow(clippy::boxed_local, clippy::needless_pass_by_value)] -#![allow(clippy::disallowed_names)] +#![warn(clippy::redundant_allocation)] +#![expect(clippy::boxed_local, clippy::disallowed_names, clippy::needless_pass_by_value)] pub struct MyStruct; diff --git a/tests/ui/redundant_allocation_fixable.rs b/tests/ui/redundant_allocation_fixable.rs index 05b6429492ce7..c3ed9efd76928 100644 --- a/tests/ui/redundant_allocation_fixable.rs +++ b/tests/ui/redundant_allocation_fixable.rs @@ -1,5 +1,5 @@ -#![allow(clippy::boxed_local, clippy::needless_pass_by_value)] -#![allow(clippy::disallowed_names)] +#![warn(clippy::redundant_allocation)] +#![expect(clippy::boxed_local, clippy::disallowed_names, clippy::needless_pass_by_value)] pub struct MyStruct; diff --git a/tests/ui/redundant_as_str.fixed b/tests/ui/redundant_as_str.fixed index 4c5f7893d42e0..33a83bddb3b8a 100644 --- a/tests/ui/redundant_as_str.fixed +++ b/tests/ui/redundant_as_str.fixed @@ -1,5 +1,5 @@ #![warn(clippy::redundant_as_str)] -#![allow(clippy::const_is_empty)] +#![expect(clippy::const_is_empty)] fn main() { let string = "Hello, world!".to_owned(); diff --git a/tests/ui/redundant_as_str.rs b/tests/ui/redundant_as_str.rs index e3baec754595c..efcfc3a12d0dd 100644 --- a/tests/ui/redundant_as_str.rs +++ b/tests/ui/redundant_as_str.rs @@ -1,5 +1,5 @@ #![warn(clippy::redundant_as_str)] -#![allow(clippy::const_is_empty)] +#![expect(clippy::const_is_empty)] fn main() { let string = "Hello, world!".to_owned(); diff --git a/tests/ui/redundant_async_block.fixed b/tests/ui/redundant_async_block.fixed index 2f14f27e70562..ee47029cff0a5 100644 --- a/tests/ui/redundant_async_block.fixed +++ b/tests/ui/redundant_async_block.fixed @@ -1,5 +1,5 @@ -#![allow(unused, clippy::manual_async_fn)] #![warn(clippy::redundant_async_block)] +#![expect(clippy::manual_async_fn)] use std::future::{Future, IntoFuture}; diff --git a/tests/ui/redundant_async_block.rs b/tests/ui/redundant_async_block.rs index f5fe26b19cc8a..d8f090a204b3a 100644 --- a/tests/ui/redundant_async_block.rs +++ b/tests/ui/redundant_async_block.rs @@ -1,5 +1,5 @@ -#![allow(unused, clippy::manual_async_fn)] #![warn(clippy::redundant_async_block)] +#![expect(clippy::manual_async_fn)] use std::future::{Future, IntoFuture}; diff --git a/tests/ui/redundant_at_rest_pattern.fixed b/tests/ui/redundant_at_rest_pattern.fixed index 908b9051b7ef0..601cd3b91699d 100644 --- a/tests/ui/redundant_at_rest_pattern.fixed +++ b/tests/ui/redundant_at_rest_pattern.fixed @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(irrefutable_let_patterns, unused)] #![warn(clippy::redundant_at_rest_pattern)] +#![expect(irrefutable_let_patterns)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/redundant_at_rest_pattern.rs b/tests/ui/redundant_at_rest_pattern.rs index 0f19459773a94..92a22842bd04c 100644 --- a/tests/ui/redundant_at_rest_pattern.rs +++ b/tests/ui/redundant_at_rest_pattern.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(irrefutable_let_patterns, unused)] #![warn(clippy::redundant_at_rest_pattern)] +#![expect(irrefutable_let_patterns)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed index c1c389f7c4ed2..db38c1223c12d 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -1,6 +1,6 @@ // rustfix-only-machine-applicable #![warn(clippy::redundant_clone)] -#![allow( +#![expect( clippy::drop_non_drop, clippy::implicit_clone, clippy::pathbuf_init_then_push, diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs index 78d98762efc86..d9f66e74349a9 100644 --- a/tests/ui/redundant_clone.rs +++ b/tests/ui/redundant_clone.rs @@ -1,6 +1,6 @@ // rustfix-only-machine-applicable #![warn(clippy::redundant_clone)] -#![allow( +#![expect( clippy::drop_non_drop, clippy::implicit_clone, clippy::pathbuf_init_then_push, diff --git a/tests/ui/redundant_closure_call_fixable.fixed b/tests/ui/redundant_closure_call_fixable.fixed index d10063251accd..9f7482e52ccd9 100644 --- a/tests/ui/redundant_closure_call_fixable.fixed +++ b/tests/ui/redundant_closure_call_fixable.fixed @@ -1,4 +1,4 @@ -#![expect(unused)] +#![warn(clippy::redundant_closure_call)] #![expect(incomplete_features)] #![feature(ergonomic_clones)] diff --git a/tests/ui/redundant_closure_call_fixable.rs b/tests/ui/redundant_closure_call_fixable.rs index eccfb2e3c3a74..f75c44cd72b75 100644 --- a/tests/ui/redundant_closure_call_fixable.rs +++ b/tests/ui/redundant_closure_call_fixable.rs @@ -1,4 +1,4 @@ -#![expect(unused)] +#![warn(clippy::redundant_closure_call)] #![expect(incomplete_features)] #![feature(ergonomic_clones)] diff --git a/tests/ui/redundant_closure_call_late.rs b/tests/ui/redundant_closure_call_late.rs index ceb42dc0ce75d..0ab2e5511aa79 100644 --- a/tests/ui/redundant_closure_call_late.rs +++ b/tests/ui/redundant_closure_call_late.rs @@ -1,8 +1,7 @@ // non rustfixable, see redundant_closure_call_fixable.rs -#![expect(unused_assignments)] +#![warn(clippy::redundant_closure_call)] fn main() { - #[expect(unused_variables)] let mut i = 1; // don't lint here, the closure is used more than once @@ -30,7 +29,6 @@ fn main() { i = shadowed_closure(); // Fix FP in #5916 - #[expect(unused_variables)] let mut x; let create = || 2 * 2; x = create(); diff --git a/tests/ui/redundant_closure_call_late.stderr b/tests/ui/redundant_closure_call_late.stderr index 1455ec8c78a5c..9435e974b5f88 100644 --- a/tests/ui/redundant_closure_call_late.stderr +++ b/tests/ui/redundant_closure_call_late.stderr @@ -1,5 +1,5 @@ error: closure called just once immediately after it was declared - --> tests/ui/redundant_closure_call_late.rs:15:5 + --> tests/ui/redundant_closure_call_late.rs:14:5 | LL | i = redun_closure(); | ^^^^^^^^^^^^^^^^^^^ @@ -8,13 +8,13 @@ LL | i = redun_closure(); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: closure called just once immediately after it was declared - --> tests/ui/redundant_closure_call_late.rs:20:5 + --> tests/ui/redundant_closure_call_late.rs:19:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ error: closure called just once immediately after it was declared - --> tests/ui/redundant_closure_call_late.rs:24:5 + --> tests/ui/redundant_closure_call_late.rs:23:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_else.fixed b/tests/ui/redundant_else.fixed index 8a3279f50180b..328fb8d7a900f 100644 --- a/tests/ui/redundant_else.fixed +++ b/tests/ui/redundant_else.fixed @@ -1,161 +1,455 @@ +//@aux-build:proc_macros.rs + +#![feature(never_type)] #![warn(clippy::redundant_else)] -#![allow(clippy::needless_return, clippy::if_same_then_else, clippy::needless_late_init)] +#![expect(clippy::unnecessary_operation)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros, with_span}; + +use core::hint::black_box; +use core::ops::{Add, Deref, Not}; +#[inline_macros] fn main() { - loop { - // break - if foo() { - println!("Love your neighbor;"); - break; + // then syntactic diverge final expr. + { + if black_box(false) { + return; } //~^ redundant_else + black_box(0); - println!("yet don't pull down your hedge."); - // continue - if foo() { - println!("He that lies down with Dogs,"); - continue; + loop { + if black_box(false) { + break; + } + //~^ redundant_else + black_box(0); } - //~^ redundant_else - println!("shall rise up with fleas."); - // match block - if foo() { - match foo() { - 1 => break, - _ => return, + loop { + if black_box(false) { + continue; } + //~^ redundant_else + black_box(0); + } + } + + // then syntactic diverge final stmt. + { + if black_box(false) { + return; } //~^ redundant_else + black_box(0); - println!("You may delay, but time will not."); - } - // else if - if foo() { - return; - } else if foo() { - return; + loop { + if black_box(false) { + break; + } + //~^ redundant_else + black_box(0); + if black_box(false) { + continue; + } + //~^ redundant_else + black_box(0); + } } - //~^ redundant_else - println!("A fat kitchen makes a lean will."); - // let binding outside of block - let _ = { - if foo() { - return; + // then panic + { + if black_box(false) { + panic!(); } //~^ redundant_else + black_box(()); - 1 + if black_box(false) { + panic!("msg"); + } + //~^ redundant_else + black_box(0); + + if black_box(false) { + panic!("{}", 0); + } + //~^ redundant_else + black_box(0i32); }; - // else if with let binding outside of block - let _ = { - if foo() { + + // no semi on if + { + if black_box(false) { return; - } else if foo() { + } + //~^ redundant_else + black_box(0); + + if black_box(false) { return; } //~^ redundant_else + let _ = 0; + black_box(()); - 2 - }; - // inside if let - let _ = if let Some(1) = foo() { - let _ = 1; - if foo() { + if black_box(false) { + return; + } + //~^ redundant_else + { black_box(()) } + + if black_box(false) { return; } //~^ redundant_else + if black_box(true) { + black_box(0); + } - 1 - } else { - 1 + if black_box(false) { + return; + } + //~^ redundant_else + if black_box(true) { + // empty + } else { + black_box(()) + } + + if black_box(false) { + return; + } + //~^ redundant_else + match black_box(0) { + 0 => {}, + 1 => { + let _ = 0; + }, + _ => black_box(()), + } + + if black_box(false) { + return; + } + //~^ redundant_else + loop { + if black_box(true) { + break black_box(()); + } + } + + if black_box(false) { + return; + } + //~^ redundant_else + while black_box(true) { + if black_box(true) { + break; + } + } + + if black_box(false) { + return; + } + //~^ redundant_else + for _ in black_box(0..0) { + if black_box(true) { + break; + } + }; + + if black_box(false) { + return; + } + //~^ redundant_else + black_box(1) }; - // - // non-lint cases - // + // then nested block diverge + { + if black_box(false) { + { + let _ = black_box(0); + panic!() + } + } + //~^ redundant_else + black_box(0); - // sanity check - if foo() { - let _ = 1; - } else { - println!("Who is wise? He that learns from every one."); + if black_box(false) { + { + let _ = black_box(0); + return; + } + } + //~^ redundant_else + black_box(0); } - // else if without else - if foo() { - return; - } else if foo() { - foo() - }; - // nested if return - if foo() { - if foo() { + + // then nested branch diverge + { + loop { + if black_box(false) { + match black_box(0) { + 0 => return, + 1 => panic!(), + 2 => break, + _ => continue, + } + } + //~^ redundant_else + black_box(0); + } + + if black_box(false) { + if black_box(true) { + panic!(); + } + //~^ redundant_else return; } - } else { - foo() - }; - // match with non-breaking branch - if foo() { - match foo() { - 1 => foo(), - _ => return, - } - } else { - println!("Three may keep a secret, if two of them are dead."); + //~^ redundant_else + black_box(0); } - // let binding - let _ = if foo() { - return; - } else { - 1 - }; - // assign - let mut a; - a = if foo() { - return; - } else { - 1 - }; - // assign-op - a += if foo() { - return; - } else { - 1 - }; - // if return else if else - if foo() { - return; - } else if foo() { - 1 - } else { - 2 - }; - // if else if return else - if foo() { - 1 - } else if foo() { - return; - } else { - 2 - }; - // else if with let binding - let _ = if foo() { - return; - } else if foo() { - return; - } else { - 2 - }; - // inside function call - Box::new(if foo() { - return; - } else { - 1 - }); -} -fn foo() -> T { - unimplemented!("I'm not Santa Claus") + // if chain diverge + { + if black_box(false) { + panic!() + } else if black_box(true) { + return; + } else if black_box(true) { + let x = 0; + black_box(x + 2 * 55); + panic!(); + } + //~^ redundant_else + black_box(0); + } + + // then misc fn diverge + { + struct S; + impl Deref for S { + type Target = !; + fn deref(&self) -> &! { + panic!() + } + }; + impl Not for S { + type Output = !; + fn not(self) -> ! { + panic!() + } + } + impl Add for S { + type Output = !; + fn add(self, other: Self) -> ! { + panic!() + } + } + + if black_box(true) { + *S + } else if black_box(true) { + !S + } else if black_box(true) { + S + S + } else if black_box(true) { + S.not() + } else if black_box(true) { + S::add(S, S) + } + //~^ redundant_else + black_box(0); + + if black_box(true) { + *S; + } else if black_box(true) { + !S; + } else if black_box(true) { + S + S; + } else if black_box(true) { + S.not(); + } else if black_box(true) { + S::add(S, S); + } + //~^ redundant_else + black_box(0); + } + + // then no diverge + { + if black_box(true) { + black_box(1) + } else { + black_box(0) + }; + + if black_box(true) { + if black_box(true) { black_box(0) } else { return } + } else { + black_box(0) + }; + + if black_box(true) { + if black_box(true) { return } black_box(0) + //~^ redundant_else + } else { + black_box(0) + }; + + loop { + if black_box(true) { + match black_box(1) { + 0 => panic!(), + 1 => return, + 2 => break, + _ => { + if black_box(true) { + break; + } else if black_box(true) { + panic!() + } else if black_box(true) { + black_box(0) + } else { + return; + } + }, + } + } else { + black_box(0) + }; + } + } + + // nested in various weird positions + { + black_box(if black_box(true) { + return; + } else { + black_box(0) + }); + + let _ = if black_box(true) { + return; + } else { + black_box(0) + }; + + let _ = black_box([0, 1, 2].as_slice())[if black_box(true) { + return; + } else { + black_box(0) + }]; + + (if black_box(true) { + return; + } else { + black_box(0i32) + }) + .ilog2(); + + return if black_box(true) { + return; + } else { + black_box(()) + }; + + 1 + if black_box(true) { + return; + } else { + black_box(0) + }; + } + + // external macros + { + external! {{ + if black_box(true) { + return + } else { + black_box(0) + }; + }} + with_span! { + span + { + if black_box(true) { + return + } else { + black_box(0) + }; + } + } + } + + // internal macros + { + fn diverge() -> ! { + panic!() + } + + inline! {{ + if black_box(true) { + return + } + //~^ redundant_else + black_box(0); + + if black_box(true) { + return; + } + //~^ redundant_else + black_box(0); + + if black_box(true) { + if black_box(true) { + return; + } + //~^ redundant_else + let _ = (); + return + } + //~^ redundant_else + black_box(0); + + if black_box(true) { + #[expect(clippy::redundant_else)] + if black_box(true) { + return; + } else { + let _ = (); + return; + }; + } + //~^ redundant_else + black_box(0); + + if black_box(true) { + diverge(); + } else { + black_box(0); + } + + // Needs a semicolon in the suggestion due to the macro call + if black_box(true) { + return + } + //~^ redundant_else + inline!({ black_box(()); }); + + // Needs a semicolon in the suggestion due to the context switch + if black_box(true) { + return + } + //~^ redundant_else + $({ black_box(()) }); + + let _ = 0; + }}; + } } diff --git a/tests/ui/redundant_else.rs b/tests/ui/redundant_else.rs index 78abf4247a568..478b6277dbfc3 100644 --- a/tests/ui/redundant_else.rs +++ b/tests/ui/redundant_else.rs @@ -1,168 +1,489 @@ +//@aux-build:proc_macros.rs + +#![feature(never_type)] #![warn(clippy::redundant_else)] -#![allow(clippy::needless_return, clippy::if_same_then_else, clippy::needless_late_init)] +#![expect(clippy::unnecessary_operation)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros, with_span}; + +use core::hint::black_box; +use core::ops::{Add, Deref, Not}; +#[inline_macros] fn main() { - loop { - // break - if foo() { - println!("Love your neighbor;"); - break; + // then syntactic diverge final expr. + { + if black_box(false) { + return; } else { //~^ redundant_else + black_box(0) + }; + + loop { + if black_box(false) { + break; + } else { + //~^ redundant_else + black_box(0) + }; + } - println!("yet don't pull down your hedge."); + loop { + if black_box(false) { + continue; + } else { + //~^ redundant_else + black_box(0) + }; } - // continue - if foo() { - println!("He that lies down with Dogs,"); - continue; + } + + // then syntactic diverge final stmt. + { + if black_box(false) { + return; } else { //~^ redundant_else + black_box(0) + }; - println!("shall rise up with fleas."); + loop { + if black_box(false) { + break; + } else { + //~^ redundant_else + black_box(0) + }; + if black_box(false) { + continue; + } else { + //~^ redundant_else + black_box(0) + }; } - // match block - if foo() { - match foo() { - 1 => break, - _ => return, - } + } + + // then panic + { + if black_box(false) { + panic!(); + } else { + //~^ redundant_else + black_box(()) + }; + + if black_box(false) { + panic!("msg"); } else { //~^ redundant_else + black_box(0) + }; + + if black_box(false) { + panic!("{}", 0); + } else { + //~^ redundant_else + black_box(0i32) + }; + }; - println!("You may delay, but time will not."); + // no semi on if + { + if black_box(false) { + return; + } else { + //~^ redundant_else + black_box(0); } - } - // else if - if foo() { - return; - } else if foo() { - return; - } else { - //~^ redundant_else - - println!("A fat kitchen makes a lean will."); - } - // let binding outside of block - let _ = { - if foo() { + + if black_box(false) { + return; + } else { + //~^ redundant_else + let _ = 0; + black_box(()) + } + + if black_box(false) { return; } else { //~^ redundant_else + { black_box(()) } + } - 1 + if black_box(false) { + return; + } else { + //~^ redundant_else + if black_box(true) { + black_box(0); + } } - }; - // else if with let binding outside of block - let _ = { - if foo() { + + if black_box(false) { return; - } else if foo() { + } else { + //~^ redundant_else + if black_box(true) { + // empty + } else { + black_box(()) + } + } + + if black_box(false) { return; } else { //~^ redundant_else + match black_box(0) { + 0 => {}, + 1 => { + let _ = 0; + }, + _ => black_box(()), + } + } - 2 + if black_box(false) { + return; + } else { + //~^ redundant_else + loop { + if black_box(true) { + break black_box(()); + } + } } - }; - // inside if let - let _ = if let Some(1) = foo() { - let _ = 1; - if foo() { + + if black_box(false) { return; } else { //~^ redundant_else + while black_box(true) { + if black_box(true) { + break; + } + } + } - 1 + if black_box(false) { + return; + } else { + //~^ redundant_else + for _ in black_box(0..0) { + if black_box(true) { + break; + } + } + } + + if black_box(false) { + return; + } else { + //~^ redundant_else + black_box(1) } - } else { - 1 }; - // - // non-lint cases - // + // then nested block diverge + { + if black_box(false) { + { + let _ = black_box(0); + panic!() + } + } else { + //~^ redundant_else + black_box(0) + }; - // sanity check - if foo() { - let _ = 1; - } else { - println!("Who is wise? He that learns from every one."); + if black_box(false) { + { + let _ = black_box(0); + return; + } + } else { + //~^ redundant_else + black_box(0) + }; } - // else if without else - if foo() { - return; - } else if foo() { - foo() - }; - // nested if return - if foo() { - if foo() { + + // then nested branch diverge + { + loop { + if black_box(false) { + match black_box(0) { + 0 => return, + 1 => panic!(), + 2 => break, + _ => continue, + } + } else { + //~^ redundant_else + black_box(0) + }; + } + + if black_box(false) { + if black_box(true) { + panic!(); + } else { + //~^ redundant_else + return; + } + } else { + //~^ redundant_else + black_box(0) + }; + } + + // if chain diverge + { + if black_box(false) { + panic!() + } else if black_box(true) { return; + } else if black_box(true) { + let x = 0; + black_box(x + 2 * 55); + panic!(); + } else { + //~^ redundant_else + black_box(0) + }; + } + + // then misc fn diverge + { + struct S; + impl Deref for S { + type Target = !; + fn deref(&self) -> &! { + panic!() + } + }; + impl Not for S { + type Output = !; + fn not(self) -> ! { + panic!() + } } - } else { - foo() - }; - // match with non-breaking branch - if foo() { - match foo() { - 1 => foo(), - _ => return, - } - } else { - println!("Three may keep a secret, if two of them are dead."); + impl Add for S { + type Output = !; + fn add(self, other: Self) -> ! { + panic!() + } + } + + if black_box(true) { + *S + } else if black_box(true) { + !S + } else if black_box(true) { + S + S + } else if black_box(true) { + S.not() + } else if black_box(true) { + S::add(S, S) + } else { + //~^ redundant_else + black_box(0) + }; + + if black_box(true) { + *S; + } else if black_box(true) { + !S; + } else if black_box(true) { + S + S; + } else if black_box(true) { + S.not(); + } else if black_box(true) { + S::add(S, S); + } else { + //~^ redundant_else + black_box(0) + }; } - // let binding - let _ = if foo() { - return; - } else { - 1 - }; - // assign - let mut a; - a = if foo() { - return; - } else { - 1 - }; - // assign-op - a += if foo() { - return; - } else { - 1 - }; - // if return else if else - if foo() { - return; - } else if foo() { - 1 - } else { - 2 - }; - // if else if return else - if foo() { - 1 - } else if foo() { - return; - } else { - 2 - }; - // else if with let binding - let _ = if foo() { - return; - } else if foo() { - return; - } else { - 2 - }; - // inside function call - Box::new(if foo() { - return; - } else { - 1 - }); -} -fn foo() -> T { - unimplemented!("I'm not Santa Claus") + // then no diverge + { + if black_box(true) { + black_box(1) + } else { + black_box(0) + }; + + if black_box(true) { + if black_box(true) { black_box(0) } else { return } + } else { + black_box(0) + }; + + if black_box(true) { + if black_box(true) { return } else { black_box(0) } + //~^ redundant_else + } else { + black_box(0) + }; + + loop { + if black_box(true) { + match black_box(1) { + 0 => panic!(), + 1 => return, + 2 => break, + _ => { + if black_box(true) { + break; + } else if black_box(true) { + panic!() + } else if black_box(true) { + black_box(0) + } else { + return; + } + }, + } + } else { + black_box(0) + }; + } + } + + // nested in various weird positions + { + black_box(if black_box(true) { + return; + } else { + black_box(0) + }); + + let _ = if black_box(true) { + return; + } else { + black_box(0) + }; + + let _ = black_box([0, 1, 2].as_slice())[if black_box(true) { + return; + } else { + black_box(0) + }]; + + (if black_box(true) { + return; + } else { + black_box(0i32) + }) + .ilog2(); + + return if black_box(true) { + return; + } else { + black_box(()) + }; + + 1 + if black_box(true) { + return; + } else { + black_box(0) + }; + } + + // external macros + { + external! {{ + if black_box(true) { + return + } else { + black_box(0) + }; + }} + with_span! { + span + { + if black_box(true) { + return + } else { + black_box(0) + }; + } + } + } + + // internal macros + { + fn diverge() -> ! { + panic!() + } + + inline! {{ + if black_box(true) { + return + } else { + //~^ redundant_else + black_box(0); + } + + if black_box(true) { + return; + } else { + //~^ redundant_else + black_box(0); + } + + if black_box(true) { + if black_box(true) { + return; + } else { + //~^ redundant_else + let _ = (); + return + } + } else { + //~^ redundant_else + black_box(0); + } + + if black_box(true) { + #[expect(clippy::redundant_else)] + if black_box(true) { + return; + } else { + let _ = (); + return; + }; + } else { + //~^ redundant_else + black_box(0); + } + + if black_box(true) { + diverge(); + } else { + black_box(0); + } + + // Needs a semicolon in the suggestion due to the macro call + if black_box(true) { + return + } else { + //~^ redundant_else + inline!({ black_box(()); }) + } + + // Needs a semicolon in the suggestion due to the context switch + if black_box(true) { + return + } else { + //~^ redundant_else + $({ black_box(()) }) + } + + let _ = 0; + }}; + } } diff --git a/tests/ui/redundant_else.stderr b/tests/ui/redundant_else.stderr index 0902c97af0dd7..01112d5e0ea15 100644 --- a/tests/ui/redundant_else.stderr +++ b/tests/ui/redundant_else.stderr @@ -1,12 +1,11 @@ error: redundant else block - --> tests/ui/redundant_else.rs:10:10 + --> tests/ui/redundant_else.rs:19:10 | LL | } else { | __________^ LL | | -LL | | -LL | | println!("yet don't pull down your hedge."); -LL | | } +LL | | black_box(0) +LL | | }; | |_________^ | = note: `-D clippy::redundant-else` implied by `-D warnings` @@ -15,37 +14,170 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + -LL + println!("yet don't pull down your hedge."); +LL ~ black_box(0); | error: redundant else block - --> tests/ui/redundant_else.rs:19:10 + --> tests/ui/redundant_else.rs:27:14 + | +LL | } else { + | ______________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_____________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:36:14 + | +LL | } else { + | ______________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_____________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:47:10 | LL | } else { | __________^ LL | | +LL | | black_box(0) +LL | | }; + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:55:14 + | +LL | } else { + | ______________^ LL | | -LL | | println!("shall rise up with fleas."); -LL | | } +LL | | black_box(0) +LL | | }; + | |_____________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:61:14 + | +LL | } else { + | ______________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_____________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:72:10 + | +LL | } else { + | __________^ +LL | | +LL | | black_box(()) +LL | | }; + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(()); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:79:10 + | +LL | } else { + | __________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:86:10 + | +LL | } else { + | __________^ +LL | | +LL | | black_box(0i32) +LL | | }; | |_________^ | help: remove the `else` block and move the contents out | LL ~ } LL + -LL + -LL + println!("shall rise up with fleas."); +LL ~ black_box(0i32); | error: redundant else block - --> tests/ui/redundant_else.rs:30:10 + --> tests/ui/redundant_else.rs:96:10 | LL | } else { | __________^ LL | | +LL | | black_box(0); +LL | | } + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:103:10 + | +LL | } else { + | __________^ LL | | -LL | | println!("You may delay, but time will not."); +LL | | let _ = 0; +LL | | black_box(()) LL | | } | |_________^ | @@ -53,37 +185,79 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + -LL + println!("You may delay, but time will not."); +LL + let _ = 0; +LL + black_box(()); | error: redundant else block - --> tests/ui/redundant_else.rs:41:6 + --> tests/ui/redundant_else.rs:111:10 | -LL | } else { - | ______^ +LL | } else { + | __________^ LL | | +LL | | { black_box(()) } +LL | | } + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + { black_box(()) } + | + +error: redundant else block + --> tests/ui/redundant_else.rs:118:10 + | +LL | } else { + | __________^ LL | | -LL | | println!("A fat kitchen makes a lean will."); -LL | | } - | |_____^ +LL | | if black_box(true) { +LL | | black_box(0); +LL | | } +LL | | } + | |_________^ | help: remove the `else` block and move the contents out | -LL ~ } +LL ~ } LL + -LL + -LL + println!("A fat kitchen makes a lean will."); +LL + if black_box(true) { +LL + black_box(0); +LL + } | error: redundant else block - --> tests/ui/redundant_else.rs:50:10 + --> tests/ui/redundant_else.rs:127:10 | LL | } else { | __________^ LL | | +LL | | if black_box(true) { +... | +LL | | } + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + if black_box(true) { +LL + // empty +LL + } else { +LL + black_box(()) +LL + } + | + +error: redundant else block + --> tests/ui/redundant_else.rs:138:10 + | +LL | } else { + | __________^ LL | | -LL | | 1 +LL | | match black_box(0) { +LL | | 0 => {}, +... | LL | | } | |_________^ | @@ -91,18 +265,47 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + -LL + 1 +LL + match black_box(0) { +LL + 0 => {}, +LL + 1 => { +LL + let _ = 0; +LL + }, +LL + _ => black_box(()), +LL + } | error: redundant else block - --> tests/ui/redundant_else.rs:62:10 + --> tests/ui/redundant_else.rs:151:10 | LL | } else { | __________^ LL | | +LL | | loop { +LL | | if black_box(true) { +... | +LL | | } + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + loop { +LL + if black_box(true) { +LL + break black_box(()); +LL + } +LL + } + | + +error: redundant else block + --> tests/ui/redundant_else.rs:162:10 + | +LL | } else { + | __________^ LL | | -LL | | 2 +LL | | while black_box(true) { +LL | | if black_box(true) { +... | LL | | } | |_________^ | @@ -110,18 +313,43 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + -LL + 2 +LL + while black_box(true) { +LL + if black_box(true) { +LL + break; +LL + } +LL + } | error: redundant else block - --> tests/ui/redundant_else.rs:73:10 + --> tests/ui/redundant_else.rs:173:10 | LL | } else { | __________^ LL | | +LL | | for _ in black_box(0..0) { +LL | | if black_box(true) { +... | +LL | | } + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + for _ in black_box(0..0) { +LL + if black_box(true) { +LL + break; +LL + } +LL + }; + | + +error: redundant else block + --> tests/ui/redundant_else.rs:184:10 + | +LL | } else { + | __________^ LL | | -LL | | 1 +LL | | black_box(1) LL | | } | |_________^ | @@ -129,9 +357,278 @@ help: remove the `else` block and move the contents out | LL ~ } LL + -LL + -LL + 1 +LL + black_box(1) + | + +error: redundant else block + --> tests/ui/redundant_else.rs:197:10 + | +LL | } else { + | __________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:207:10 + | +LL | } else { + | __________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:223:14 + | +LL | } else { + | ______________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_____________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:236:10 + | +LL | } else { + | __________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:232:14 + | +LL | } else { + | ______________^ +LL | | +LL | | return; +LL | | } + | |_____________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + return; + | + +error: redundant else block + --> tests/ui/redundant_else.rs:252:10 + | +LL | } else { + | __________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:290:10 + | +LL | } else { + | __________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:305:10 + | +LL | } else { + | __________^ +LL | | +LL | | black_box(0) +LL | | }; + | |_________^ + | +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL ~ black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:326:42 + | +LL | if black_box(true) { return } else { black_box(0) } + | ^^^^^^^^^^^^^^^^^^^^^^ help: remove the `else` block and move the contents out: `black_box(0)` + +error: redundant else block + --> tests/ui/redundant_else.rs:426:14 + | +LL | } else { + | ______________^ +LL | | +LL | | black_box(0); +LL | | } + | |_____________^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:433:14 + | +LL | } else { + | ______________^ +LL | | +LL | | black_box(0); +LL | | } + | |_____________^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:446:14 + | +LL | } else { + | ______________^ +LL | | +LL | | black_box(0); +LL | | } + | |_____________^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:441:18 + | +LL | } else { + | __________________^ +LL | | +LL | | let _ = (); +LL | | return +LL | | } + | |_________________^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + let _ = (); +LL + return + | + +error: redundant else block + --> tests/ui/redundant_else.rs:459:14 + | +LL | } else { + | ______________^ +LL | | +LL | | black_box(0); +LL | | } + | |_____________^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + black_box(0); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:473:14 + | +LL | } else { + | ______________^ +LL | | +LL | | inline!({ black_box(()); }) +LL | | } + | |_____________^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + inline!({ black_box(()); }); + | + +error: redundant else block + --> tests/ui/redundant_else.rs:481:14 + | +LL | } else { + | ______________^ +LL | | +LL | | $({ black_box(()) }) +LL | | } + | |_____________^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove the `else` block and move the contents out + | +LL ~ } +LL + +LL + $({ black_box(()) }); | -error: aborting due to 7 previous errors +error: aborting due to 35 previous errors diff --git a/tests/ui/redundant_field_names.fixed b/tests/ui/redundant_field_names.fixed index 4c922030eb66b..0416735e18080 100644 --- a/tests/ui/redundant_field_names.fixed +++ b/tests/ui/redundant_field_names.fixed @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs #![warn(clippy::redundant_field_names)] -#![allow(clippy::extra_unused_type_parameters, clippy::no_effect, dead_code, unused_variables)] +#![expect(clippy::no_effect)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/redundant_field_names.rs b/tests/ui/redundant_field_names.rs index 7d03e269cf25e..4aa14fec4086c 100644 --- a/tests/ui/redundant_field_names.rs +++ b/tests/ui/redundant_field_names.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs #![warn(clippy::redundant_field_names)] -#![allow(clippy::extra_unused_type_parameters, clippy::no_effect, dead_code, unused_variables)] +#![expect(clippy::no_effect)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/redundant_guards.fixed b/tests/ui/redundant_guards.fixed index f433d8263023a..c5559d3562ec5 100644 --- a/tests/ui/redundant_guards.fixed +++ b/tests/ui/redundant_guards.fixed @@ -1,6 +1,7 @@ //@aux-build:proc_macros.rs -#![allow(clippy::no_effect, unused, clippy::single_match, invalid_nan_comparisons)] #![warn(clippy::redundant_guards)] +#![allow(clippy::single_match)] +#![expect(invalid_nan_comparisons)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/redundant_guards.rs b/tests/ui/redundant_guards.rs index 02115af75ed06..88bd226957aca 100644 --- a/tests/ui/redundant_guards.rs +++ b/tests/ui/redundant_guards.rs @@ -1,6 +1,7 @@ //@aux-build:proc_macros.rs -#![allow(clippy::no_effect, unused, clippy::single_match, invalid_nan_comparisons)] #![warn(clippy::redundant_guards)] +#![allow(clippy::single_match)] +#![expect(invalid_nan_comparisons)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/redundant_guards.stderr b/tests/ui/redundant_guards.stderr index c889d5a5697d9..cb7b9b119e20f 100644 --- a/tests/ui/redundant_guards.stderr +++ b/tests/ui/redundant_guards.stderr @@ -1,5 +1,5 @@ error: redundant guard - --> tests/ui/redundant_guards.rs:21:14 + --> tests/ui/redundant_guards.rs:22:14 | LL | x if x == 0.0 => todo!(), | ^^^^^^^^ @@ -13,7 +13,7 @@ LL + 0.0 => todo!(), | error: redundant guard - --> tests/ui/redundant_guards.rs:28:14 + --> tests/ui/redundant_guards.rs:29:14 | LL | x if x == FloatWrapper(0.0) => todo!(), | ^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + FloatWrapper(0.0) => todo!(), | error: redundant guard - --> tests/ui/redundant_guards.rs:44:20 + --> tests/ui/redundant_guards.rs:45:20 | LL | C(x, y) if let 1 = y => .., | ^^^^^^^^^ @@ -37,7 +37,7 @@ LL + C(x, 1) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:51:20 + --> tests/ui/redundant_guards.rs:52:20 | LL | Some(x) if matches!(x, Some(1) if true) => .., | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + Some(Some(1)) if true => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:53:20 + --> tests/ui/redundant_guards.rs:54:20 | LL | Some(x) if matches!(x, Some(1)) => { | ^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + Some(Some(1)) => { | error: redundant guard - --> tests/ui/redundant_guards.rs:58:20 + --> tests/ui/redundant_guards.rs:59:20 | LL | Some(x) if let Some(1) = x => .., | ^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + Some(Some(1)) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:60:20 + --> tests/ui/redundant_guards.rs:61:20 | LL | Some(x) if x == Some(2) => .., | ^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + Some(Some(2)) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:62:20 + --> tests/ui/redundant_guards.rs:63:20 | LL | Some(x) if Some(2) == x => .., | ^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + Some(Some(2)) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:88:20 + --> tests/ui/redundant_guards.rs:89:20 | LL | B { e } if matches!(e, Some(A(2))) => .., | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + B { e: Some(A(2)) } => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:126:20 + --> tests/ui/redundant_guards.rs:127:20 | LL | E::A(y) if y == "not from an or pattern" => {}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + E::A("not from an or pattern") => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:134:14 + --> tests/ui/redundant_guards.rs:135:14 | LL | x if matches!(x, Some(0)) => .., | ^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + Some(0) => .., | error: redundant guard - --> tests/ui/redundant_guards.rs:142:14 + --> tests/ui/redundant_guards.rs:143:14 | LL | i if i == -1 => {}, | ^^^^^^^ @@ -145,7 +145,7 @@ LL + -1 => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:144:14 + --> tests/ui/redundant_guards.rs:145:14 | LL | i if i == 1 => {}, | ^^^^^^ @@ -157,7 +157,7 @@ LL + 1 => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:207:28 + --> tests/ui/redundant_guards.rs:208:28 | LL | Some(ref x) if x == &1 => {}, | ^^^^^^^ @@ -169,7 +169,7 @@ LL + Some(1) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:209:28 + --> tests/ui/redundant_guards.rs:210:28 | LL | Some(ref x) if &1 == x => {}, | ^^^^^^^ @@ -181,7 +181,7 @@ LL + Some(1) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:211:28 + --> tests/ui/redundant_guards.rs:212:28 | LL | Some(ref x) if let &2 = x => {}, | ^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + Some(2) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:213:28 + --> tests/ui/redundant_guards.rs:214:28 | LL | Some(ref x) if matches!(x, &3) => {}, | ^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL + Some(3) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:234:32 + --> tests/ui/redundant_guards.rs:235:32 | LL | B { ref c, .. } if c == &1 => {}, | ^^^^^^^ @@ -217,7 +217,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:236:32 + --> tests/ui/redundant_guards.rs:237:32 | LL | B { ref c, .. } if &1 == c => {}, | ^^^^^^^ @@ -229,7 +229,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:238:32 + --> tests/ui/redundant_guards.rs:239:32 | LL | B { ref c, .. } if let &1 = c => {}, | ^^^^^^^^^^ @@ -241,7 +241,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:240:32 + --> tests/ui/redundant_guards.rs:241:32 | LL | B { ref c, .. } if matches!(c, &1) => {}, | ^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL + B { c: 1, .. } => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:251:26 + --> tests/ui/redundant_guards.rs:252:26 | LL | Some(Some(x)) if x.is_empty() => {}, | ^^^^^^^^^^^^ @@ -265,7 +265,7 @@ LL + Some(Some("")) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:263:26 + --> tests/ui/redundant_guards.rs:264:26 | LL | Some(Some(x)) if x.is_empty() => {}, | ^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL + Some(Some([])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:269:26 + --> tests/ui/redundant_guards.rs:270:26 | LL | Some(Some(x)) if x.is_empty() => {}, | ^^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL + Some(Some([])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:281:26 + --> tests/ui/redundant_guards.rs:282:26 | LL | Some(Some(x)) if x.starts_with(&[]) => {}, | ^^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL + Some(Some([..])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:287:26 + --> tests/ui/redundant_guards.rs:288:26 | LL | Some(Some(x)) if x.starts_with(&[1]) => {}, | ^^^^^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL + Some(Some([1, ..])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:293:26 + --> tests/ui/redundant_guards.rs:294:26 | LL | Some(Some(x)) if x.starts_with(&[1, 2]) => {}, | ^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL + Some(Some([1, 2, ..])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:299:26 + --> tests/ui/redundant_guards.rs:300:26 | LL | Some(Some(x)) if x.ends_with(&[1, 2]) => {}, | ^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL + Some(Some([.., 1, 2])) => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:322:18 + --> tests/ui/redundant_guards.rs:323:18 | LL | y if y.is_empty() => {}, | ^^^^^^^^^^^^ @@ -349,7 +349,7 @@ LL + "" => {}, | error: redundant guard - --> tests/ui/redundant_guards.rs:341:22 + --> tests/ui/redundant_guards.rs:342:22 | LL | y if y.is_empty() => {}, | ^^^^^^^^^^^^ diff --git a/tests/ui/redundant_locals.rs b/tests/ui/redundant_locals.rs index b66532dd22eec..6282703dab3dc 100644 --- a/tests/ui/redundant_locals.rs +++ b/tests/ui/redundant_locals.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(unused, clippy::no_effect, clippy::needless_pass_by_ref_mut)] #![warn(clippy::redundant_locals)] +#![expect(clippy::needless_pass_by_ref_mut, clippy::no_effect)] #![feature(coroutines, stmt_expr_attributes)] extern crate proc_macros; diff --git a/tests/ui/redundant_pattern_matching_drop_order.fixed b/tests/ui/redundant_pattern_matching_drop_order.fixed index 490948442e11f..05965fd020554 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.fixed +++ b/tests/ui/redundant_pattern_matching_drop_order.fixed @@ -1,11 +1,7 @@ // Issue #5746 #![warn(clippy::redundant_pattern_matching)] -#![allow( - clippy::if_same_then_else, - clippy::equatable_if_let, - clippy::needless_ifs, - clippy::needless_else -)] +#![allow(clippy::needless_ifs)] +#![expect(clippy::needless_else)] use std::task::Poll::{Pending, Ready}; fn main() { diff --git a/tests/ui/redundant_pattern_matching_drop_order.rs b/tests/ui/redundant_pattern_matching_drop_order.rs index d40fe84693b00..5e09cca989c5d 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.rs +++ b/tests/ui/redundant_pattern_matching_drop_order.rs @@ -1,11 +1,7 @@ // Issue #5746 #![warn(clippy::redundant_pattern_matching)] -#![allow( - clippy::if_same_then_else, - clippy::equatable_if_let, - clippy::needless_ifs, - clippy::needless_else -)] +#![allow(clippy::needless_ifs)] +#![expect(clippy::needless_else)] use std::task::Poll::{Pending, Ready}; fn main() { diff --git a/tests/ui/redundant_pattern_matching_drop_order.stderr b/tests/ui/redundant_pattern_matching_drop_order.stderr index 7f0171b8424ab..e2e6e0c53496d 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.stderr +++ b/tests/ui/redundant_pattern_matching_drop_order.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:15:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:11:12 | LL | if let Ok(_) = m.lock() {} | ^^^^^ @@ -15,7 +15,7 @@ LL + if m.lock().is_ok() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:17:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:13:12 | LL | if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {} | ^^^^^^ @@ -29,7 +29,7 @@ LL + if Err::<(), _>(m.lock().unwrap().0).is_err() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:21:16 + --> tests/ui/redundant_pattern_matching_drop_order.rs:17:16 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} | ^^^^^ @@ -43,7 +43,7 @@ LL + if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:24:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:20:12 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) { | ^^^^^ @@ -57,7 +57,7 @@ LL + if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:28:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:24:12 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} | ^^^^^ @@ -69,7 +69,7 @@ LL + if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:30:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:26:12 | LL | if let Err(_) = Err::, _>(()) {} | ^^^^^^ @@ -81,7 +81,7 @@ LL + if Err::, _>(()).is_err() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:33:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:29:12 | LL | if let Ok(_) = Ok::<_, ()>(String::new()) {} | ^^^^^ @@ -93,7 +93,7 @@ LL + if Ok::<_, ()>(String::new()).is_ok() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:35:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:31:12 | LL | if let Err(_) = Err::<(), _>((String::new(), ())) {} | ^^^^^^ @@ -105,7 +105,7 @@ LL + if Err::<(), _>((String::new(), ())).is_err() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:39:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:35:12 | LL | if let Some(_) = Some(m.lock()) {} | ^^^^^^^ @@ -119,7 +119,7 @@ LL + if Some(m.lock()).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:41:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:37:12 | LL | if let Some(_) = Some(m.lock().unwrap().0) {} | ^^^^^^^ @@ -133,7 +133,7 @@ LL + if Some(m.lock().unwrap().0).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:45:16 + --> tests/ui/redundant_pattern_matching_drop_order.rs:41:16 | LL | if let None = None::> {} | ^^^^ @@ -147,7 +147,7 @@ LL + if None::>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:48:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:44:12 | LL | if let None = None::> { | ^^^^ @@ -161,7 +161,7 @@ LL + if None::>.is_none() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:53:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:49:12 | LL | if let None = None::> {} | ^^^^ @@ -173,7 +173,7 @@ LL + if None::>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:56:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:52:12 | LL | if let Some(_) = Some(String::new()) {} | ^^^^^^^ @@ -185,7 +185,7 @@ LL + if Some(String::new()).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:58:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:54:12 | LL | if let Some(_) = Some((String::new(), ())) {} | ^^^^^^^ @@ -197,7 +197,7 @@ LL + if Some((String::new(), ())).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:62:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:58:12 | LL | if let Ready(_) = Ready(m.lock()) {} | ^^^^^^^^ @@ -211,7 +211,7 @@ LL + if Ready(m.lock()).is_ready() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:64:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:60:12 | LL | if let Ready(_) = Ready(m.lock().unwrap().0) {} | ^^^^^^^^ @@ -225,7 +225,7 @@ LL + if Ready(m.lock().unwrap().0).is_ready() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:68:16 + --> tests/ui/redundant_pattern_matching_drop_order.rs:64:16 | LL | if let Pending = Pending::> {} | ^^^^^^^ @@ -239,7 +239,7 @@ LL + if Pending::>.is_pending() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:71:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:67:12 | LL | if let Pending = Pending::> { | ^^^^^^^ @@ -253,7 +253,7 @@ LL + if Pending::>.is_pending() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:76:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:72:12 | LL | if let Pending = Pending::> {} | ^^^^^^^ @@ -265,7 +265,7 @@ LL + if Pending::>.is_pending() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:79:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:75:12 | LL | if let Ready(_) = Ready(String::new()) {} | ^^^^^^^^ @@ -277,7 +277,7 @@ LL + if Ready(String::new()).is_ready() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_drop_order.rs:81:12 + --> tests/ui/redundant_pattern_matching_drop_order.rs:77:12 | LL | if let Ready(_) = Ready((String::new(), ())) {} | ^^^^^^^^ diff --git a/tests/ui/redundant_pattern_matching_if_let_true.fixed b/tests/ui/redundant_pattern_matching_if_let_true.fixed index b746bfd1c3584..d4367feaa2a1a 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.fixed +++ b/tests/ui/redundant_pattern_matching_if_let_true.fixed @@ -1,5 +1,5 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow(clippy::needless_ifs, clippy::no_effect, clippy::nonminimal_bool)] +#![allow(clippy::needless_ifs, clippy::no_effect)] macro_rules! condition { () => { diff --git a/tests/ui/redundant_pattern_matching_if_let_true.rs b/tests/ui/redundant_pattern_matching_if_let_true.rs index 7be9f31e56bd6..f9987202fd724 100644 --- a/tests/ui/redundant_pattern_matching_if_let_true.rs +++ b/tests/ui/redundant_pattern_matching_if_let_true.rs @@ -1,5 +1,5 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow(clippy::needless_ifs, clippy::no_effect, clippy::nonminimal_bool)] +#![allow(clippy::needless_ifs, clippy::no_effect)] macro_rules! condition { () => { diff --git a/tests/ui/redundant_pattern_matching_ipaddr.fixed b/tests/ui/redundant_pattern_matching_ipaddr.fixed index 7c05eca1b70e5..cc3b7a6470acb 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.fixed +++ b/tests/ui/redundant_pattern_matching_ipaddr.fixed @@ -1,10 +1,5 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow( - clippy::match_like_matches_macro, - clippy::needless_bool, - clippy::needless_ifs, - clippy::uninlined_format_args -)] +#![expect(clippy::needless_ifs)] use std::net::IpAddr::{self, V4, V6}; use std::net::{Ipv4Addr, Ipv6Addr}; diff --git a/tests/ui/redundant_pattern_matching_ipaddr.rs b/tests/ui/redundant_pattern_matching_ipaddr.rs index 1d4abca492813..8fa1f58ffaaf8 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.rs +++ b/tests/ui/redundant_pattern_matching_ipaddr.rs @@ -1,10 +1,5 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow( - clippy::match_like_matches_macro, - clippy::needless_bool, - clippy::needless_ifs, - clippy::uninlined_format_args -)] +#![expect(clippy::needless_ifs)] use std::net::IpAddr::{self, V4, V6}; use std::net::{Ipv4Addr, Ipv6Addr}; diff --git a/tests/ui/redundant_pattern_matching_ipaddr.stderr b/tests/ui/redundant_pattern_matching_ipaddr.stderr index 9f65f85fad436..65a7e9d0f94dc 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.stderr +++ b/tests/ui/redundant_pattern_matching_ipaddr.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:14:12 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:9:12 | LL | if let V4(_) = &ipaddr {} | ^^^^^ @@ -13,7 +13,7 @@ LL + if ipaddr.is_ipv4() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:17:12 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:12:12 | LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ^^^^^ @@ -25,7 +25,7 @@ LL + if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:20:12 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:15:12 | LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ^^^^^ @@ -37,7 +37,7 @@ LL + if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:24:8 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:19:8 | LL | if matches!(V4(Ipv4Addr::LOCALHOST), V4(_)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:28:8 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:23:8 | LL | if matches!(V6(Ipv6Addr::LOCALHOST), V6(_)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:31:15 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:26:15 | LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ^^^^^ @@ -73,7 +73,7 @@ LL + while V4(Ipv4Addr::LOCALHOST).is_ipv4() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:34:15 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:29:15 | LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ^^^^^ @@ -85,7 +85,7 @@ LL + while V6(Ipv6Addr::LOCALHOST).is_ipv6() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:45:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:40:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | @@ -105,7 +105,7 @@ LL + V4(Ipv4Addr::LOCALHOST).is_ipv4(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:51:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:46:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | @@ -125,7 +125,7 @@ LL + V4(Ipv4Addr::LOCALHOST).is_ipv6(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:57:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:52:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | @@ -145,7 +145,7 @@ LL + V6(Ipv6Addr::LOCALHOST).is_ipv6(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:63:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:58:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | @@ -165,7 +165,7 @@ LL + V6(Ipv6Addr::LOCALHOST).is_ipv4(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:69:20 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:64:20 | LL | let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) { | ^^^^^ @@ -177,7 +177,7 @@ LL + let _ = if V4(Ipv4Addr::LOCALHOST).is_ipv4() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:78:20 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:73:20 | LL | let _ = if let V4(_) = gen_ipaddr() { | ^^^^^ @@ -189,7 +189,7 @@ LL + let _ = if gen_ipaddr().is_ipv4() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:81:19 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:76:19 | LL | } else if let V6(_) = gen_ipaddr() { | ^^^^^ @@ -201,7 +201,7 @@ LL + } else if gen_ipaddr().is_ipv6() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:94:12 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:89:12 | LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ^^^^^ @@ -213,7 +213,7 @@ LL + if V4(Ipv4Addr::LOCALHOST).is_ipv4() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:97:12 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:92:12 | LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ^^^^^ @@ -225,7 +225,7 @@ LL + if V6(Ipv6Addr::LOCALHOST).is_ipv6() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:100:15 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:95:15 | LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ^^^^^ @@ -237,7 +237,7 @@ LL + while V4(Ipv4Addr::LOCALHOST).is_ipv4() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:103:15 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:98:15 | LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ^^^^^ @@ -249,7 +249,7 @@ LL + while V6(Ipv6Addr::LOCALHOST).is_ipv6() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:106:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:101:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | @@ -269,7 +269,7 @@ LL + V4(Ipv4Addr::LOCALHOST).is_ipv4(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_ipaddr.rs:112:5 + --> tests/ui/redundant_pattern_matching_ipaddr.rs:107:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | diff --git a/tests/ui/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed index dbebc4e9793a8..8a6f1bb638765 100644 --- a/tests/ui/redundant_pattern_matching_option.fixed +++ b/tests/ui/redundant_pattern_matching_option.fixed @@ -1,11 +1,6 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow( - clippy::needless_bool, - clippy::needless_ifs, - clippy::match_like_matches_macro, - clippy::equatable_if_let, - clippy::if_same_then_else -)] +#![allow(clippy::needless_bool)] +#![expect(clippy::match_like_matches_macro, clippy::needless_ifs)] fn issue_11174(boolean: bool, maybe_some: Option) -> bool { maybe_some.is_none() && (!boolean) @@ -118,7 +113,7 @@ const fn issue6067() { None::<()>.is_none(); } -#[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)] +#[allow(clippy::deref_addrof, clippy::needless_borrow)] fn issue7921() { if (&None::<()>).is_none() {} //~^ redundant_pattern_matching diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs index b3bb74428a541..b2e087b5211c7 100644 --- a/tests/ui/redundant_pattern_matching_option.rs +++ b/tests/ui/redundant_pattern_matching_option.rs @@ -1,11 +1,6 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow( - clippy::needless_bool, - clippy::needless_ifs, - clippy::match_like_matches_macro, - clippy::equatable_if_let, - clippy::if_same_then_else -)] +#![allow(clippy::needless_bool)] +#![expect(clippy::match_like_matches_macro, clippy::needless_ifs)] fn issue_11174(boolean: bool, maybe_some: Option) -> bool { matches!(maybe_some, None if !boolean) @@ -138,7 +133,7 @@ const fn issue6067() { }; } -#[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)] +#[allow(clippy::deref_addrof, clippy::needless_borrow)] fn issue7921() { if let None = *(&None::<()>) {} //~^ redundant_pattern_matching diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr index 8f02838feb355..32d00715440fa 100644 --- a/tests/ui/redundant_pattern_matching_option.stderr +++ b/tests/ui/redundant_pattern_matching_option.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:11:5 + --> tests/ui/redundant_pattern_matching_option.rs:6:5 | LL | matches!(maybe_some, None if !boolean) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + maybe_some.is_none() && (!boolean) | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:16:13 + --> tests/ui/redundant_pattern_matching_option.rs:11:13 | LL | let _ = matches!(maybe_some, None if boolean || boolean2); // guard needs parentheses | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _ = maybe_some.is_none() && (boolean || boolean2); // guard needs p | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:32:12 + --> tests/ui/redundant_pattern_matching_option.rs:27:12 | LL | if let None = None::<()> {} | ^^^^ @@ -37,7 +37,7 @@ LL + if None::<()>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:35:12 + --> tests/ui/redundant_pattern_matching_option.rs:30:12 | LL | if let Some(_) = Some(42) {} | ^^^^^^^ @@ -49,7 +49,7 @@ LL + if Some(42).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:38:12 + --> tests/ui/redundant_pattern_matching_option.rs:33:12 | LL | if let Some(_) = Some(42) { | ^^^^^^^ @@ -61,7 +61,7 @@ LL + if Some(42).is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:45:15 + --> tests/ui/redundant_pattern_matching_option.rs:40:15 | LL | while let Some(_) = Some(42) {} | ^^^^^^^ @@ -73,7 +73,7 @@ LL + while Some(42).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:48:15 + --> tests/ui/redundant_pattern_matching_option.rs:43:15 | LL | while let None = Some(42) {} | ^^^^ @@ -85,7 +85,7 @@ LL + while Some(42).is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:51:15 + --> tests/ui/redundant_pattern_matching_option.rs:46:15 | LL | while let None = None::<()> {} | ^^^^ @@ -97,7 +97,7 @@ LL + while None::<()>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:55:15 + --> tests/ui/redundant_pattern_matching_option.rs:50:15 | LL | while let Some(_) = v.pop() { | ^^^^^^^ @@ -109,7 +109,7 @@ LL + while v.pop().is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:64:5 + --> tests/ui/redundant_pattern_matching_option.rs:59:5 | LL | / match Some(42) { LL | | @@ -129,7 +129,7 @@ LL + Some(42).is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:70:5 + --> tests/ui/redundant_pattern_matching_option.rs:65:5 | LL | / match None::<()> { LL | | @@ -149,7 +149,7 @@ LL + None::<()>.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:76:13 + --> tests/ui/redundant_pattern_matching_option.rs:71:13 | LL | let _ = match None::<()> { | _____________^ @@ -170,7 +170,7 @@ LL + let _ = None::<()>.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:83:20 + --> tests/ui/redundant_pattern_matching_option.rs:78:20 | LL | let _ = if let Some(_) = opt { true } else { false }; | ^^^^^^^ @@ -182,7 +182,7 @@ LL + let _ = if opt.is_some() { true } else { false }; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:90:20 + --> tests/ui/redundant_pattern_matching_option.rs:85:20 | LL | let _ = if let Some(_) = gen_opt() { | ^^^^^^^ @@ -194,7 +194,7 @@ LL + let _ = if gen_opt().is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:93:19 + --> tests/ui/redundant_pattern_matching_option.rs:88:19 | LL | } else if let None = gen_opt() { | ^^^^ @@ -206,7 +206,7 @@ LL + } else if gen_opt().is_none() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:100:12 + --> tests/ui/redundant_pattern_matching_option.rs:95:12 | LL | if let Some(..) = gen_opt() {} | ^^^^^^^^ @@ -218,7 +218,7 @@ LL + if gen_opt().is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:116:12 + --> tests/ui/redundant_pattern_matching_option.rs:111:12 | LL | if let Some(_) = Some(42) {} | ^^^^^^^ @@ -230,7 +230,7 @@ LL + if Some(42).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:119:12 + --> tests/ui/redundant_pattern_matching_option.rs:114:12 | LL | if let None = None::<()> {} | ^^^^ @@ -242,7 +242,7 @@ LL + if None::<()>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:122:15 + --> tests/ui/redundant_pattern_matching_option.rs:117:15 | LL | while let Some(_) = Some(42) {} | ^^^^^^^ @@ -254,7 +254,7 @@ LL + while Some(42).is_some() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:125:15 + --> tests/ui/redundant_pattern_matching_option.rs:120:15 | LL | while let None = None::<()> {} | ^^^^ @@ -266,7 +266,7 @@ LL + while None::<()>.is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:128:5 + --> tests/ui/redundant_pattern_matching_option.rs:123:5 | LL | / match Some(42) { LL | | @@ -286,7 +286,7 @@ LL + Some(42).is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:134:5 + --> tests/ui/redundant_pattern_matching_option.rs:129:5 | LL | / match None::<()> { LL | | @@ -306,7 +306,7 @@ LL + None::<()>.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:143:12 + --> tests/ui/redundant_pattern_matching_option.rs:138:12 | LL | if let None = *(&None::<()>) {} | ^^^^ @@ -318,7 +318,7 @@ LL + if (&None::<()>).is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:145:12 + --> tests/ui/redundant_pattern_matching_option.rs:140:12 | LL | if let None = *&None::<()> {} | ^^^^ @@ -330,7 +330,7 @@ LL + if (&None::<()>).is_none() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:152:5 + --> tests/ui/redundant_pattern_matching_option.rs:147:5 | LL | / match x { LL | | @@ -350,7 +350,7 @@ LL + x.is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:158:5 + --> tests/ui/redundant_pattern_matching_option.rs:153:5 | LL | / match x { LL | | @@ -370,7 +370,7 @@ LL + x.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:164:5 + --> tests/ui/redundant_pattern_matching_option.rs:159:5 | LL | / match x { LL | | @@ -390,7 +390,7 @@ LL + x.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:170:5 + --> tests/ui/redundant_pattern_matching_option.rs:165:5 | LL | / match x { LL | | @@ -410,7 +410,7 @@ LL + x.is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:186:13 + --> tests/ui/redundant_pattern_matching_option.rs:181:13 | LL | let _ = matches!(x, Some(_)); | ^^^^^^^^^^^^^^^^^^^^ @@ -422,7 +422,7 @@ LL + let _ = x.is_some(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:189:13 + --> tests/ui/redundant_pattern_matching_option.rs:184:13 | LL | let _ = matches!(x, None); | ^^^^^^^^^^^^^^^^^ @@ -434,7 +434,7 @@ LL + let _ = x.is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:200:17 + --> tests/ui/redundant_pattern_matching_option.rs:195:17 | LL | let _ = matches!(*p, None); | ^^^^^^^^^^^^^^^^^^ @@ -446,7 +446,7 @@ LL + let _ = (*p).is_none(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:208:16 + --> tests/ui/redundant_pattern_matching_option.rs:203:16 | LL | if let Some(_) = x? { | ^^^^^^^ @@ -458,7 +458,7 @@ LL + if x?.is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:228:16 + --> tests/ui/redundant_pattern_matching_option.rs:223:16 | LL | if let Some(_) = x.await { | ^^^^^^^ @@ -470,7 +470,7 @@ LL + if x.await.is_some() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:241:12 + --> tests/ui/redundant_pattern_matching_option.rs:236:12 | LL | if let Some(_) = (x! {}) {}; | ^^^^^^^ @@ -482,7 +482,7 @@ LL + if x! {}.is_some() {}; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_option.rs:243:15 + --> tests/ui/redundant_pattern_matching_option.rs:238:15 | LL | while let Some(_) = (x! {}) {} | ^^^^^^^ diff --git a/tests/ui/redundant_pattern_matching_poll.fixed b/tests/ui/redundant_pattern_matching_poll.fixed index 735c444bb45b5..1f9511d082e30 100644 --- a/tests/ui/redundant_pattern_matching_poll.fixed +++ b/tests/ui/redundant_pattern_matching_poll.fixed @@ -1,11 +1,6 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow( - clippy::needless_bool, - clippy::needless_ifs, - clippy::match_like_matches_macro, - clippy::equatable_if_let, - clippy::if_same_then_else -)] +#![allow(clippy::match_like_matches_macro, clippy::needless_bool)] +#![expect(clippy::needless_ifs)] use std::task::Poll::{self, Pending, Ready}; diff --git a/tests/ui/redundant_pattern_matching_poll.rs b/tests/ui/redundant_pattern_matching_poll.rs index eeca51e8be760..f2a3ada42de76 100644 --- a/tests/ui/redundant_pattern_matching_poll.rs +++ b/tests/ui/redundant_pattern_matching_poll.rs @@ -1,11 +1,6 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow( - clippy::needless_bool, - clippy::needless_ifs, - clippy::match_like_matches_macro, - clippy::equatable_if_let, - clippy::if_same_then_else -)] +#![allow(clippy::match_like_matches_macro, clippy::needless_bool)] +#![expect(clippy::needless_ifs)] use std::task::Poll::{self, Pending, Ready}; diff --git a/tests/ui/redundant_pattern_matching_poll.stderr b/tests/ui/redundant_pattern_matching_poll.stderr index 5b94965c06daa..6886b7d68354e 100644 --- a/tests/ui/redundant_pattern_matching_poll.stderr +++ b/tests/ui/redundant_pattern_matching_poll.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:13:12 + --> tests/ui/redundant_pattern_matching_poll.rs:8:12 | LL | if let Pending = Pending::<()> {} | ^^^^^^^ @@ -13,7 +13,7 @@ LL + if Pending::<()>.is_pending() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:16:12 + --> tests/ui/redundant_pattern_matching_poll.rs:11:12 | LL | if let Ready(_) = Ready(42) {} | ^^^^^^^^ @@ -25,7 +25,7 @@ LL + if Ready(42).is_ready() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:19:12 + --> tests/ui/redundant_pattern_matching_poll.rs:14:12 | LL | if let Ready(_) = Ready(42) { | ^^^^^^^^ @@ -37,7 +37,7 @@ LL + if Ready(42).is_ready() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:27:8 + --> tests/ui/redundant_pattern_matching_poll.rs:22:8 | LL | if matches!(Ready(42), Ready(_)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + if Ready(42).is_ready() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:31:8 + --> tests/ui/redundant_pattern_matching_poll.rs:26:8 | LL | if matches!(Pending::<()>, Pending) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + if Pending::<()>.is_pending() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:34:15 + --> tests/ui/redundant_pattern_matching_poll.rs:29:15 | LL | while let Ready(_) = Ready(42) {} | ^^^^^^^^ @@ -73,7 +73,7 @@ LL + while Ready(42).is_ready() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:37:15 + --> tests/ui/redundant_pattern_matching_poll.rs:32:15 | LL | while let Pending = Ready(42) {} | ^^^^^^^ @@ -85,7 +85,7 @@ LL + while Ready(42).is_pending() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:40:15 + --> tests/ui/redundant_pattern_matching_poll.rs:35:15 | LL | while let Pending = Pending::<()> {} | ^^^^^^^ @@ -97,7 +97,7 @@ LL + while Pending::<()>.is_pending() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:47:5 + --> tests/ui/redundant_pattern_matching_poll.rs:42:5 | LL | / match Ready(42) { LL | | @@ -117,7 +117,7 @@ LL + Ready(42).is_ready(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:53:5 + --> tests/ui/redundant_pattern_matching_poll.rs:48:5 | LL | / match Pending::<()> { LL | | @@ -137,7 +137,7 @@ LL + Pending::<()>.is_pending(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:59:13 + --> tests/ui/redundant_pattern_matching_poll.rs:54:13 | LL | let _ = match Pending::<()> { | _____________^ @@ -158,7 +158,7 @@ LL + let _ = Pending::<()>.is_pending(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:66:20 + --> tests/ui/redundant_pattern_matching_poll.rs:61:20 | LL | let _ = if let Ready(_) = poll { true } else { false }; | ^^^^^^^^ @@ -170,7 +170,7 @@ LL + let _ = if poll.is_ready() { true } else { false }; | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:71:20 + --> tests/ui/redundant_pattern_matching_poll.rs:66:20 | LL | let _ = if let Ready(_) = gen_poll() { | ^^^^^^^^ @@ -182,7 +182,7 @@ LL + let _ = if gen_poll().is_ready() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:74:19 + --> tests/ui/redundant_pattern_matching_poll.rs:69:19 | LL | } else if let Pending = gen_poll() { | ^^^^^^^ @@ -194,7 +194,7 @@ LL + } else if gen_poll().is_pending() { | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:91:12 + --> tests/ui/redundant_pattern_matching_poll.rs:86:12 | LL | if let Ready(_) = Ready(42) {} | ^^^^^^^^ @@ -206,7 +206,7 @@ LL + if Ready(42).is_ready() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:94:12 + --> tests/ui/redundant_pattern_matching_poll.rs:89:12 | LL | if let Pending = Pending::<()> {} | ^^^^^^^ @@ -218,7 +218,7 @@ LL + if Pending::<()>.is_pending() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:97:15 + --> tests/ui/redundant_pattern_matching_poll.rs:92:15 | LL | while let Ready(_) = Ready(42) {} | ^^^^^^^^ @@ -230,7 +230,7 @@ LL + while Ready(42).is_ready() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:100:15 + --> tests/ui/redundant_pattern_matching_poll.rs:95:15 | LL | while let Pending = Pending::<()> {} | ^^^^^^^ @@ -242,7 +242,7 @@ LL + while Pending::<()>.is_pending() {} | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:103:5 + --> tests/ui/redundant_pattern_matching_poll.rs:98:5 | LL | / match Ready(42) { LL | | @@ -262,7 +262,7 @@ LL + Ready(42).is_ready(); | error: redundant pattern matching - --> tests/ui/redundant_pattern_matching_poll.rs:109:5 + --> tests/ui/redundant_pattern_matching_poll.rs:104:5 | LL | / match Pending::<()> { LL | | diff --git a/tests/ui/redundant_pattern_matching_result.fixed b/tests/ui/redundant_pattern_matching_result.fixed index 8754d71aa6294..6259a1e55f7db 100644 --- a/tests/ui/redundant_pattern_matching_result.fixed +++ b/tests/ui/redundant_pattern_matching_result.fixed @@ -1,5 +1,5 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow(deprecated)] +#![expect(deprecated)] #![allow( clippy::if_same_then_else, clippy::match_like_matches_macro, diff --git a/tests/ui/redundant_pattern_matching_result.rs b/tests/ui/redundant_pattern_matching_result.rs index b83b02588fb67..af6dc58e5c67b 100644 --- a/tests/ui/redundant_pattern_matching_result.rs +++ b/tests/ui/redundant_pattern_matching_result.rs @@ -1,5 +1,5 @@ #![warn(clippy::redundant_pattern_matching)] -#![allow(deprecated)] +#![expect(deprecated)] #![allow( clippy::if_same_then_else, clippy::match_like_matches_macro, diff --git a/tests/ui/redundant_pub_crate.fixed b/tests/ui/redundant_pub_crate.fixed index 8a30fedede4a4..cf4e8fe305027 100644 --- a/tests/ui/redundant_pub_crate.fixed +++ b/tests/ui/redundant_pub_crate.fixed @@ -1,5 +1,4 @@ //@aux-build:proc_macros.rs -#![allow(dead_code)] #![warn(clippy::redundant_pub_crate)] mod m1 { @@ -142,12 +141,10 @@ mod m5 { pub use m4::*; mod issue_8732 { - #[allow(unused_macros)] macro_rules! some_macro { () => {}; } - #[allow(unused_imports)] pub(crate) use some_macro; // ok: macro exports are exempt } diff --git a/tests/ui/redundant_pub_crate.rs b/tests/ui/redundant_pub_crate.rs index 45ba13a63b2e2..d5677e1920d4a 100644 --- a/tests/ui/redundant_pub_crate.rs +++ b/tests/ui/redundant_pub_crate.rs @@ -1,5 +1,4 @@ //@aux-build:proc_macros.rs -#![allow(dead_code)] #![warn(clippy::redundant_pub_crate)] mod m1 { @@ -142,12 +141,10 @@ mod m5 { pub use m4::*; mod issue_8732 { - #[allow(unused_macros)] macro_rules! some_macro { () => {}; } - #[allow(unused_imports)] pub(crate) use some_macro; // ok: macro exports are exempt } diff --git a/tests/ui/redundant_pub_crate.stderr b/tests/ui/redundant_pub_crate.stderr index 4a47a321028d1..b6542e1db0902 100644 --- a/tests/ui/redundant_pub_crate.stderr +++ b/tests/ui/redundant_pub_crate.stderr @@ -1,5 +1,5 @@ error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:7:5 + --> tests/ui/redundant_pub_crate.rs:6:5 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -10,7 +10,7 @@ LL | pub(crate) fn g() {} // private due to m1 = help: to override `-D warnings` add `#[allow(clippy::redundant_pub_crate)]` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:14:9 + --> tests/ui/redundant_pub_crate.rs:13:9 | LL | pub(crate) fn g() {} // private due to m1_1 and m1 | ----------^^^^^ @@ -18,7 +18,7 @@ LL | pub(crate) fn g() {} // private due to m1_1 and m1 | help: consider using: `pub` error: pub(crate) module inside private module - --> tests/ui/redundant_pub_crate.rs:20:5 + --> tests/ui/redundant_pub_crate.rs:19:5 | LL | pub(crate) mod m1_2 { | ----------^^^^^^^^^ @@ -26,7 +26,7 @@ LL | pub(crate) mod m1_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:24:9 + --> tests/ui/redundant_pub_crate.rs:23:9 | LL | pub(crate) fn g() {} // private due to m1_2 and m1 | ----------^^^^^ @@ -34,7 +34,7 @@ LL | pub(crate) fn g() {} // private due to m1_2 and m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:32:9 + --> tests/ui/redundant_pub_crate.rs:31:9 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -42,7 +42,7 @@ LL | pub(crate) fn g() {} // private due to m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:41:5 + --> tests/ui/redundant_pub_crate.rs:40:5 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -50,7 +50,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:48:9 + --> tests/ui/redundant_pub_crate.rs:47:9 | LL | pub(crate) fn g() {} // private due to m2_1 | ----------^^^^^ @@ -58,7 +58,7 @@ LL | pub(crate) fn g() {} // private due to m2_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> tests/ui/redundant_pub_crate.rs:54:5 + --> tests/ui/redundant_pub_crate.rs:53:5 | LL | pub(crate) mod m2_2 { | ----------^^^^^^^^^ @@ -66,7 +66,7 @@ LL | pub(crate) mod m2_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:58:9 + --> tests/ui/redundant_pub_crate.rs:57:9 | LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | ----------^^^^^ @@ -74,7 +74,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:66:9 + --> tests/ui/redundant_pub_crate.rs:65:9 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -82,7 +82,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:80:9 + --> tests/ui/redundant_pub_crate.rs:79:9 | LL | pub(crate) fn g() {} // private due to m3_1 | ----------^^^^^ @@ -90,7 +90,7 @@ LL | pub(crate) fn g() {} // private due to m3_1 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:89:9 + --> tests/ui/redundant_pub_crate.rs:88:9 | LL | pub(crate) fn g() {} // already crate visible due to m3_2 | ----------^^^^^ @@ -98,7 +98,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m3_2 | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:104:5 + --> tests/ui/redundant_pub_crate.rs:103:5 | LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | ----------^^^^^ @@ -106,7 +106,7 @@ LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:111:9 + --> tests/ui/redundant_pub_crate.rs:110:9 | LL | pub(crate) fn g() {} // private due to m4_1 | ----------^^^^^ @@ -114,7 +114,7 @@ LL | pub(crate) fn g() {} // private due to m4_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> tests/ui/redundant_pub_crate.rs:117:5 + --> tests/ui/redundant_pub_crate.rs:116:5 | LL | pub(crate) mod m4_2 { | ----------^^^^^^^^^ @@ -122,7 +122,7 @@ LL | pub(crate) mod m4_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> tests/ui/redundant_pub_crate.rs:121:9 + --> tests/ui/redundant_pub_crate.rs:120:9 | LL | pub(crate) fn g() {} // private due to m4_2 | ----------^^^^^ @@ -130,7 +130,7 @@ LL | pub(crate) fn g() {} // private due to m4_2 | help: consider using: `pub` error: pub(crate) import inside private module - --> tests/ui/redundant_pub_crate.rs:137:5 + --> tests/ui/redundant_pub_crate.rs:136:5 | LL | pub(crate) use m5_1::*; | ----------^^^^^^^^^^^^^ @@ -138,7 +138,7 @@ LL | pub(crate) use m5_1::*; | help: consider using: `pub` error: pub(crate) import inside private module - --> tests/ui/redundant_pub_crate.rs:139:27 + --> tests/ui/redundant_pub_crate.rs:138:27 | LL | pub(crate) use m5_1::{*}; | ---------- ^ diff --git a/tests/ui/redundant_slicing.fixed b/tests/ui/redundant_slicing.fixed index 385a5d97cf1ab..2d194fa6f7b1d 100644 --- a/tests/ui/redundant_slicing.fixed +++ b/tests/ui/redundant_slicing.fixed @@ -1,5 +1,5 @@ -#![allow(unused, clippy::deref_by_slicing)] #![warn(clippy::redundant_slicing)] +#![expect(clippy::deref_by_slicing)] use std::io::Read; diff --git a/tests/ui/redundant_slicing.rs b/tests/ui/redundant_slicing.rs index 04f181da250dc..74fc86993a86e 100644 --- a/tests/ui/redundant_slicing.rs +++ b/tests/ui/redundant_slicing.rs @@ -1,5 +1,5 @@ -#![allow(unused, clippy::deref_by_slicing)] #![warn(clippy::redundant_slicing)] +#![expect(clippy::deref_by_slicing)] use std::io::Read; diff --git a/tests/ui/redundant_static_lifetimes.fixed b/tests/ui/redundant_static_lifetimes.fixed index 0a898032459f6..50fb1c455507a 100644 --- a/tests/ui/redundant_static_lifetimes.fixed +++ b/tests/ui/redundant_static_lifetimes.fixed @@ -1,4 +1,4 @@ -#![allow(unused)] +#![warn(clippy::redundant_static_lifetimes)] // FIXME(static_mut_refs): use raw pointers instead of references #![allow(static_mut_refs)] diff --git a/tests/ui/redundant_static_lifetimes.rs b/tests/ui/redundant_static_lifetimes.rs index fa45eff0f2626..64e7c65310636 100644 --- a/tests/ui/redundant_static_lifetimes.rs +++ b/tests/ui/redundant_static_lifetimes.rs @@ -1,4 +1,4 @@ -#![allow(unused)] +#![warn(clippy::redundant_static_lifetimes)] // FIXME(static_mut_refs): use raw pointers instead of references #![allow(static_mut_refs)] diff --git a/tests/ui/redundant_test_prefix.fixed b/tests/ui/redundant_test_prefix.fixed index b99771f0640ca..55044a6e59147 100644 --- a/tests/ui/redundant_test_prefix.fixed +++ b/tests/ui/redundant_test_prefix.fixed @@ -1,4 +1,3 @@ -#![allow(dead_code)] #![warn(clippy::redundant_test_prefix)] fn main() { diff --git a/tests/ui/redundant_test_prefix.rs b/tests/ui/redundant_test_prefix.rs index 3aec577cffa16..d7319bc2f4e10 100644 --- a/tests/ui/redundant_test_prefix.rs +++ b/tests/ui/redundant_test_prefix.rs @@ -1,4 +1,3 @@ -#![allow(dead_code)] #![warn(clippy::redundant_test_prefix)] fn main() { diff --git a/tests/ui/redundant_test_prefix.stderr b/tests/ui/redundant_test_prefix.stderr index d156af586df3f..fdb74ee472061 100644 --- a/tests/ui/redundant_test_prefix.stderr +++ b/tests/ui/redundant_test_prefix.stderr @@ -1,5 +1,5 @@ error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:17:4 + --> tests/ui/redundant_test_prefix.rs:16:4 | LL | fn test_f3() { | ^^^^^^^ help: consider removing the `test_` prefix: `f3` @@ -8,109 +8,109 @@ LL | fn test_f3() { = help: to override `-D warnings` add `#[allow(clippy::redundant_test_prefix)]` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:26:4 + --> tests/ui/redundant_test_prefix.rs:25:4 | LL | fn test_f4() { | ^^^^^^^ help: consider removing the `test_` prefix: `f4` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:39:4 + --> tests/ui/redundant_test_prefix.rs:38:4 | LL | fn test_f6() { | ^^^^^^^ help: consider removing the `test_` prefix: `f6` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:54:8 + --> tests/ui/redundant_test_prefix.rs:53:8 | LL | fn test_foo() { | ^^^^^^^^ help: consider removing the `test_` prefix: `foo` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:59:8 + --> tests/ui/redundant_test_prefix.rs:58:8 | LL | fn test_foo_with_call() { | ^^^^^^^^^^^^^^^^^^ help: consider removing the `test_` prefix: `foo_with_call` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:66:8 + --> tests/ui/redundant_test_prefix.rs:65:8 | LL | fn test_f1() { | ^^^^^^^ help: consider removing the `test_` prefix: `f1` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:71:8 + --> tests/ui/redundant_test_prefix.rs:70:8 | LL | fn test_f2() { | ^^^^^^^ help: consider removing the `test_` prefix: `f2` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:76:8 + --> tests/ui/redundant_test_prefix.rs:75:8 | LL | fn test_f3() { | ^^^^^^^ help: consider removing the `test_` prefix: `f3` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:81:8 + --> tests/ui/redundant_test_prefix.rs:80:8 | LL | fn test_f4() { | ^^^^^^^ help: consider removing the `test_` prefix: `f4` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:86:8 + --> tests/ui/redundant_test_prefix.rs:85:8 | LL | fn test_f5() { | ^^^^^^^ help: consider removing the `test_` prefix: `f5` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:91:8 + --> tests/ui/redundant_test_prefix.rs:90:8 | LL | fn test_f6() { | ^^^^^^^ help: consider removing the `test_` prefix: `f6` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:100:8 + --> tests/ui/redundant_test_prefix.rs:99:8 | LL | fn test_foo() { | ^^^^^^^^ help: consider removing the `test_` prefix: `foo` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:105:8 + --> tests/ui/redundant_test_prefix.rs:104:8 | LL | fn test_foo_with_call() { | ^^^^^^^^^^^^^^^^^^ help: consider removing the `test_` prefix: `foo_with_call` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:112:8 + --> tests/ui/redundant_test_prefix.rs:111:8 | LL | fn test_f1() { | ^^^^^^^ help: consider removing the `test_` prefix: `f1` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:117:8 + --> tests/ui/redundant_test_prefix.rs:116:8 | LL | fn test_f2() { | ^^^^^^^ help: consider removing the `test_` prefix: `f2` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:122:8 + --> tests/ui/redundant_test_prefix.rs:121:8 | LL | fn test_f3() { | ^^^^^^^ help: consider removing the `test_` prefix: `f3` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:127:8 + --> tests/ui/redundant_test_prefix.rs:126:8 | LL | fn test_f4() { | ^^^^^^^ help: consider removing the `test_` prefix: `f4` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:132:8 + --> tests/ui/redundant_test_prefix.rs:131:8 | LL | fn test_f5() { | ^^^^^^^ help: consider removing the `test_` prefix: `f5` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix.rs:137:8 + --> tests/ui/redundant_test_prefix.rs:136:8 | LL | fn test_f6() { | ^^^^^^^ help: consider removing the `test_` prefix: `f6` diff --git a/tests/ui/redundant_test_prefix_noautofix.rs b/tests/ui/redundant_test_prefix_unfixable.rs similarity index 99% rename from tests/ui/redundant_test_prefix_noautofix.rs rename to tests/ui/redundant_test_prefix_unfixable.rs index 6ad5d011d8b71..e520fe4a1a18e 100644 --- a/tests/ui/redundant_test_prefix_noautofix.rs +++ b/tests/ui/redundant_test_prefix_unfixable.rs @@ -1,6 +1,5 @@ //@no-rustfix: name conflicts -#![allow(dead_code)] #![warn(clippy::redundant_test_prefix)] fn main() { diff --git a/tests/ui/redundant_test_prefix_noautofix.stderr b/tests/ui/redundant_test_prefix_unfixable.stderr similarity index 77% rename from tests/ui/redundant_test_prefix_noautofix.stderr rename to tests/ui/redundant_test_prefix_unfixable.stderr index 6440faf1b3c83..decc0c192846e 100644 --- a/tests/ui/redundant_test_prefix_noautofix.stderr +++ b/tests/ui/redundant_test_prefix_unfixable.stderr @@ -1,5 +1,5 @@ error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:19:4 + --> tests/ui/redundant_test_prefix_unfixable.rs:18:4 | LL | fn test_f3() { | ^^^^^^^ help: consider removing the `test_` prefix: `f3` @@ -8,13 +8,13 @@ LL | fn test_f3() { = help: to override `-D warnings` add `#[allow(clippy::redundant_test_prefix)]` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:28:4 + --> tests/ui/redundant_test_prefix_unfixable.rs:27:4 | LL | fn test_f4() { | ^^^^^^^ help: consider removing the `test_` prefix: `f4` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:39:4 + --> tests/ui/redundant_test_prefix_unfixable.rs:38:4 | LL | fn test_f5() { | ^^^^^^^ @@ -26,7 +26,7 @@ LL + fn f5_works() { | error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:53:4 + --> tests/ui/redundant_test_prefix_unfixable.rs:52:4 | LL | fn test_f6() { | ^^^^^^^ @@ -38,13 +38,13 @@ LL + fn f6_works() { | error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:65:4 + --> tests/ui/redundant_test_prefix_unfixable.rs:64:4 | LL | fn test_f8() { | ^^^^^^^ help: consider removing the `test_` prefix: `f8` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:88:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:87:8 | LL | fn test_f() { | ^^^^^^ @@ -56,61 +56,61 @@ LL + fn f_works() { | error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:101:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:100:8 | LL | fn test_m3_2() { | ^^^^^^^^^ help: consider removing the `test_` prefix: `m3_2` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:114:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:113:8 | LL | fn test_foo() { | ^^^^^^^^ help: consider removing the `test_` prefix: `foo` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:119:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:118:8 | LL | fn test_foo_with_call() { | ^^^^^^^^^^^^^^^^^^ help: consider removing the `test_` prefix: `foo_with_call` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:126:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:125:8 | LL | fn test_f1() { | ^^^^^^^ help: consider removing the `test_` prefix: `f1` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:131:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:130:8 | LL | fn test_f2() { | ^^^^^^^ help: consider removing the `test_` prefix: `f2` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:136:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:135:8 | LL | fn test_f3() { | ^^^^^^^ help: consider removing the `test_` prefix: `f3` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:141:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:140:8 | LL | fn test_f4() { | ^^^^^^^ help: consider removing the `test_` prefix: `f4` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:146:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:145:8 | LL | fn test_f5() { | ^^^^^^^ help: consider removing the `test_` prefix: `f5` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:151:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:150:8 | LL | fn test_f6() { | ^^^^^^^ help: consider removing the `test_` prefix: `f6` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:156:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:155:8 | LL | fn test_1() { | ^^^^^^ @@ -118,7 +118,7 @@ LL | fn test_1() { = help: consider function renaming (just removing `test_` prefix will produce invalid function name) error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:163:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:162:8 | LL | fn test_const() { | ^^^^^^^^^^ @@ -126,7 +126,7 @@ LL | fn test_const() { = help: consider function renaming (just removing `test_` prefix will produce invalid function name) error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:170:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:169:8 | LL | fn test_async() { | ^^^^^^^^^^ @@ -134,7 +134,7 @@ LL | fn test_async() { = help: consider function renaming (just removing `test_` prefix will produce invalid function name) error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:177:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:176:8 | LL | fn test_yield() { | ^^^^^^^^^^ @@ -142,7 +142,7 @@ LL | fn test_yield() { = help: consider function renaming (just removing `test_` prefix will produce invalid function name) error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:184:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:183:8 | LL | fn test_() { | ^^^^^ @@ -150,55 +150,55 @@ LL | fn test_() { = help: consider function renaming (just removing `test_` prefix will produce invalid function name) error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:195:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:194:8 | LL | fn test_foo() { | ^^^^^^^^ help: consider removing the `test_` prefix: `foo` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:200:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:199:8 | LL | fn test_foo_with_call() { | ^^^^^^^^^^^^^^^^^^ help: consider removing the `test_` prefix: `foo_with_call` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:207:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:206:8 | LL | fn test_f1() { | ^^^^^^^ help: consider removing the `test_` prefix: `f1` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:212:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:211:8 | LL | fn test_f2() { | ^^^^^^^ help: consider removing the `test_` prefix: `f2` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:217:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:216:8 | LL | fn test_f3() { | ^^^^^^^ help: consider removing the `test_` prefix: `f3` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:222:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:221:8 | LL | fn test_f4() { | ^^^^^^^ help: consider removing the `test_` prefix: `f4` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:227:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:226:8 | LL | fn test_f5() { | ^^^^^^^ help: consider removing the `test_` prefix: `f5` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:232:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:231:8 | LL | fn test_f6() { | ^^^^^^^ help: consider removing the `test_` prefix: `f6` error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:237:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:236:8 | LL | fn test_1() { | ^^^^^^ @@ -206,7 +206,7 @@ LL | fn test_1() { = help: consider function renaming (just removing `test_` prefix will produce invalid function name) error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:244:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:243:8 | LL | fn test_const() { | ^^^^^^^^^^ @@ -214,7 +214,7 @@ LL | fn test_const() { = help: consider function renaming (just removing `test_` prefix will produce invalid function name) error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:251:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:250:8 | LL | fn test_async() { | ^^^^^^^^^^ @@ -222,7 +222,7 @@ LL | fn test_async() { = help: consider function renaming (just removing `test_` prefix will produce invalid function name) error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:258:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:257:8 | LL | fn test_yield() { | ^^^^^^^^^^ @@ -230,7 +230,7 @@ LL | fn test_yield() { = help: consider function renaming (just removing `test_` prefix will produce invalid function name) error: redundant `test_` prefix in test function name - --> tests/ui/redundant_test_prefix_noautofix.rs:265:8 + --> tests/ui/redundant_test_prefix_unfixable.rs:264:8 | LL | fn test_() { | ^^^^^ diff --git a/tests/ui/redundant_type_annotations.rs b/tests/ui/redundant_type_annotations.rs index 55c19d194a490..7106e2b547409 100644 --- a/tests/ui/redundant_type_annotations.rs +++ b/tests/ui/redundant_type_annotations.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::redundant_type_annotations)] #[derive(Debug, Default)] diff --git a/tests/ui/redundant_type_annotations.stderr b/tests/ui/redundant_type_annotations.stderr index d2f04cc4768e1..f736d7e9fe534 100644 --- a/tests/ui/redundant_type_annotations.stderr +++ b/tests/ui/redundant_type_annotations.stderr @@ -1,5 +1,5 @@ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:81:9 + --> tests/ui/redundant_type_annotations.rs:80:9 | LL | let v: u32 = self.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,97 +8,97 @@ LL | let v: u32 = self.return_an_int(); = help: to override `-D warnings` add `#[allow(clippy::redundant_type_annotations)]` error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:84:9 + --> tests/ui/redundant_type_annotations.rs:83:9 | LL | let v: &u32 = self.return_a_ref(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:87:9 + --> tests/ui/redundant_type_annotations.rs:86:9 | LL | let v: &Slice = self.return_a_ref_to_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:160:5 + --> tests/ui/redundant_type_annotations.rs:159:5 | LL | let _return: String = return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:163:5 + --> tests/ui/redundant_type_annotations.rs:162:5 | LL | let _return: Pie = return_a_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:166:5 + --> tests/ui/redundant_type_annotations.rs:165:5 | LL | let _return: Pizza = return_an_enum(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:169:5 + --> tests/ui/redundant_type_annotations.rs:168:5 | LL | let _return: u32 = return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:172:5 + --> tests/ui/redundant_type_annotations.rs:171:5 | LL | let _return: String = String::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:175:5 + --> tests/ui/redundant_type_annotations.rs:174:5 | LL | let new_pie: Pie = Pie::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:178:5 + --> tests/ui/redundant_type_annotations.rs:177:5 | LL | let _return: u32 = new_pie.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:181:5 + --> tests/ui/redundant_type_annotations.rs:180:5 | LL | let _return: u32 = Pie::associated_return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:184:5 + --> tests/ui/redundant_type_annotations.rs:183:5 | LL | let _return: String = Pie::associated_return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:191:5 + --> tests/ui/redundant_type_annotations.rs:190:5 | LL | let _var: u32 = u32::MAX; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:194:5 + --> tests/ui/redundant_type_annotations.rs:193:5 | LL | let _var: u32 = 5_u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:197:5 + --> tests/ui/redundant_type_annotations.rs:196:5 | LL | let _var: &str = "test"; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:200:5 + --> tests/ui/redundant_type_annotations.rs:199:5 | LL | let _var: &[u8; 4] = b"test"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> tests/ui/redundant_type_annotations.rs:203:5 + --> tests/ui/redundant_type_annotations.rs:202:5 | LL | let _var: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/ref_as_ptr.fixed b/tests/ui/ref_as_ptr.fixed index eadbb7c36415b..d00a2fd693f64 100644 --- a/tests/ui/ref_as_ptr.fixed +++ b/tests/ui/ref_as_ptr.fixed @@ -1,5 +1,5 @@ #![warn(clippy::ref_as_ptr)] -#![allow(clippy::unnecessary_mut_passed, clippy::needless_lifetimes)] +#![allow(clippy::unnecessary_mut_passed)] fn f(_: T) {} diff --git a/tests/ui/ref_as_ptr.rs b/tests/ui/ref_as_ptr.rs index ef96a3ff5693d..c9b87256290fa 100644 --- a/tests/ui/ref_as_ptr.rs +++ b/tests/ui/ref_as_ptr.rs @@ -1,5 +1,5 @@ #![warn(clippy::ref_as_ptr)] -#![allow(clippy::unnecessary_mut_passed, clippy::needless_lifetimes)] +#![allow(clippy::unnecessary_mut_passed)] fn f(_: T) {} diff --git a/tests/ui/ref_binding_to_reference.rs b/tests/ui/ref_binding_to_reference.rs index 365fd8edea789..a0f0b7b46ea42 100644 --- a/tests/ui/ref_binding_to_reference.rs +++ b/tests/ui/ref_binding_to_reference.rs @@ -1,7 +1,7 @@ // FIXME: run-rustfix waiting on multi-span suggestions //@no-rustfix #![warn(clippy::ref_binding_to_reference)] -#![allow(clippy::needless_borrowed_reference, clippy::explicit_auto_deref)] +#![expect(clippy::explicit_auto_deref, clippy::needless_borrowed_reference)] fn f1(_: &str) {} macro_rules! m2 { @@ -15,7 +15,6 @@ macro_rules! m3 { }; } -#[allow(dead_code)] fn main() { let x = String::new(); diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index c1adfab12bcba..d06ca7458527c 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -1,5 +1,5 @@ error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:30:14 + --> tests/ui/ref_binding_to_reference.rs:29:14 | LL | Some(ref x) => x, | ^^^^^ @@ -13,7 +13,7 @@ LL + Some(x) => &x, | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:37:14 + --> tests/ui/ref_binding_to_reference.rs:36:14 | LL | Some(ref x) => { | ^^^^^ @@ -29,7 +29,7 @@ LL ~ &x | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:49:14 + --> tests/ui/ref_binding_to_reference.rs:48:14 | LL | Some(ref x) => m2!(x), | ^^^^^ @@ -41,7 +41,7 @@ LL + Some(x) => m2!(&x), | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:55:15 + --> tests/ui/ref_binding_to_reference.rs:54:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ @@ -55,7 +55,7 @@ LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:63:12 + --> tests/ui/ref_binding_to_reference.rs:62:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -70,7 +70,7 @@ LL ~ x | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:72:11 + --> tests/ui/ref_binding_to_reference.rs:71:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -84,7 +84,7 @@ LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:82:11 + --> tests/ui/ref_binding_to_reference.rs:81:11 | LL | fn f(&ref x: &&String) { | ^^^^^ diff --git a/tests/ui/ref_option_ref.rs b/tests/ui/ref_option_ref.rs index 9632611f7df4d..7bcaddf4467c9 100644 --- a/tests/ui/ref_option_ref.rs +++ b/tests/ui/ref_option_ref.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::ref_option_ref)] //@no-rustfix // This lint is not tagged as run-rustfix because automatically diff --git a/tests/ui/ref_option_ref.stderr b/tests/ui/ref_option_ref.stderr index 25064a61ee88b..1dbd6244b1eee 100644 --- a/tests/ui/ref_option_ref.stderr +++ b/tests/ui/ref_option_ref.stderr @@ -1,5 +1,5 @@ error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:10:23 + --> tests/ui/ref_option_ref.rs:9:23 | LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); | ^^^^^^^^^^^^^ help: try: `Option<&i32>` @@ -8,61 +8,61 @@ LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); = help: to override `-D warnings` add `#[allow(clippy::ref_option_ref)]` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:14:18 + --> tests/ui/ref_option_ref.rs:13:18 | LL | const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD); | ^^^^^^^^^^^^^ help: try: `Option<&i32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:17:25 + --> tests/ui/ref_option_ref.rs:16:25 | LL | type RefOptRefU32<'a> = &'a Option<&'a u32>; | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:20:25 + --> tests/ui/ref_option_ref.rs:19:25 | LL | type RefOptRef<'a, T> = &'a Option<&'a T>; | ^^^^^^^^^^^^^^^^^ help: try: `Option<&'a T>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:23:14 + --> tests/ui/ref_option_ref.rs:22:14 | LL | fn foo(data: &Option<&u32>) {} | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:26:23 + --> tests/ui/ref_option_ref.rs:25:23 | LL | fn bar(data: &u32) -> &Option<&u32> { | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:33:11 + --> tests/ui/ref_option_ref.rs:32:11 | LL | data: &'a Option<&'a u32>, | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:37:32 + --> tests/ui/ref_option_ref.rs:36:32 | LL | struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:42:14 + --> tests/ui/ref_option_ref.rs:41:14 | LL | Variant2(&'a Option<&'a u32>), | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:52:14 + --> tests/ui/ref_option_ref.rs:51:14 | LL | type A = &'static Option<&'static Self>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'static Self>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> tests/ui/ref_option_ref.rs:59:12 + --> tests/ui/ref_option_ref.rs:58:12 | LL | let x: &Option<&u32> = &None; | ^^^^^^^^^^^^^ help: try: `Option<&u32>` diff --git a/tests/ui/ref_patterns.rs b/tests/ui/ref_patterns.rs index 3628cc3d537c0..00e05f037a8eb 100644 --- a/tests/ui/ref_patterns.rs +++ b/tests/ui/ref_patterns.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::ref_patterns)] fn use_in_pattern() { diff --git a/tests/ui/ref_patterns.stderr b/tests/ui/ref_patterns.stderr index 9e2d036e34838..af593835ea787 100644 --- a/tests/ui/ref_patterns.stderr +++ b/tests/ui/ref_patterns.stderr @@ -1,5 +1,5 @@ error: usage of ref pattern - --> tests/ui/ref_patterns.rs:8:14 + --> tests/ui/ref_patterns.rs:7:14 | LL | Some(ref opt) => {}, | ^^^^^^^ @@ -9,7 +9,7 @@ LL | Some(ref opt) => {}, = help: to override `-D warnings` add `#[allow(clippy::ref_patterns)]` error: usage of ref pattern - --> tests/ui/ref_patterns.rs:15:9 + --> tests/ui/ref_patterns.rs:14:9 | LL | let ref y = x; | ^^^^^ @@ -17,7 +17,7 @@ LL | let ref y = x; = help: consider using `&` for clarity instead error: usage of ref pattern - --> tests/ui/ref_patterns.rs:19:21 + --> tests/ui/ref_patterns.rs:18:21 | LL | fn use_in_parameter(ref x: i32) {} | ^^^^^ diff --git a/tests/ui/regex.rs b/tests/ui/regex.rs index 699256f22c01c..2e28017ab1170 100644 --- a/tests/ui/regex.rs +++ b/tests/ui/regex.rs @@ -1,12 +1,6 @@ //@require-annotations-for-level: WARN -#![allow( - unused, - clippy::needless_raw_strings, - clippy::needless_raw_string_hashes, - clippy::needless_borrow, - clippy::needless_borrows_for_generic_args -)] -#![warn(clippy::invalid_regex, clippy::trivial_regex, clippy::regex_creation_in_loops)] +#![warn(clippy::invalid_regex, clippy::regex_creation_in_loops, clippy::trivial_regex)] +#![expect(clippy::needless_borrows_for_generic_args)] extern crate regex; diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index aaec3bc142003..159e55baafb51 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -1,5 +1,5 @@ error: trivial regex - --> tests/ui/regex.rs:20:45 + --> tests/ui/regex.rs:14:45 | LL | let pipe_in_wrong_position = Regex::new("|"); | ^^^ @@ -9,7 +9,7 @@ LL | let pipe_in_wrong_position = Regex::new("|"); = help: to override `-D warnings` add `#[allow(clippy::trivial_regex)]` error: trivial regex - --> tests/ui/regex.rs:22:60 + --> tests/ui/regex.rs:16:60 | LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); | ^^^ @@ -17,7 +17,7 @@ LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); = help: the regex is unlikely to be useful as it is error: regex syntax error: invalid character class range, the start must be <= the end - --> tests/ui/regex.rs:24:42 + --> tests/ui/regex.rs:18:42 | LL | let wrong_char_ranice = Regex::new("[z-a]"); | ^^^ @@ -26,7 +26,7 @@ LL | let wrong_char_ranice = Regex::new("[z-a]"); = help: to override `-D warnings` add `#[allow(clippy::invalid_regex)]` error: regex syntax error: invalid character class range, the start must be <= the end - --> tests/ui/regex.rs:27:37 + --> tests/ui/regex.rs:21:37 | LL | let some_unicode = Regex::new("[é-è]"); | ^^^ @@ -35,13 +35,13 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:30:33 + --> tests/ui/regex.rs:24:33 | LL | let some_regex = Regex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ error: trivial regex - --> tests/ui/regex.rs:33:53 + --> tests/ui/regex.rs:27:53 | LL | let binary_pipe_in_wrong_position = BRegex::new("|"); | ^^^ @@ -52,7 +52,7 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:35:41 + --> tests/ui/regex.rs:29:41 | LL | let some_binary_regex = BRegex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:37:56 + --> tests/ui/regex.rs:31:56 | LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:50:37 + --> tests/ui/regex.rs:44:37 | LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -79,7 +79,7 @@ error: regex parse error: ( ^ error: unclosed group - --> tests/ui/regex.rs:52:39 + --> tests/ui/regex.rs:46:39 | LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ error: regex parse error: \b\c ^^ error: unrecognized escape sequence - --> tests/ui/regex.rs:60:42 + --> tests/ui/regex.rs:54:42 | LL | let escaped_string_span = Regex::new("\\b\\c"); | ^^^^^^^^ @@ -96,19 +96,19 @@ LL | let escaped_string_span = Regex::new("\\b\\c"); = help: consider using a raw string literal: `r".."` error: regex syntax error: duplicate flag - --> tests/ui/regex.rs:63:34 + --> tests/ui/regex.rs:57:34 | LL | let aux_span = Regex::new("(?ixi)"); | ^ ^ error: regex syntax error: pattern can match invalid UTF-8 - --> tests/ui/regex.rs:69:53 + --> tests/ui/regex.rs:63:53 | LL | let invalid_utf8_should_lint = Regex::new("(?-u)."); | ^ error: trivial regex - --> tests/ui/regex.rs:74:33 + --> tests/ui/regex.rs:68:33 | LL | let trivial_eq = Regex::new("^foobar$"); | ^^^^^^^^^^ @@ -116,7 +116,7 @@ LL | let trivial_eq = Regex::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> tests/ui/regex.rs:77:48 + --> tests/ui/regex.rs:71:48 | LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); | ^^^^^^^^^^ @@ -124,7 +124,7 @@ LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> tests/ui/regex.rs:80:42 + --> tests/ui/regex.rs:74:42 | LL | let trivial_starts_with = Regex::new("^foobar"); | ^^^^^^^^^ @@ -132,7 +132,7 @@ LL | let trivial_starts_with = Regex::new("^foobar"); = help: consider using `str::starts_with` error: trivial regex - --> tests/ui/regex.rs:83:40 + --> tests/ui/regex.rs:77:40 | LL | let trivial_ends_with = Regex::new("foobar$"); | ^^^^^^^^^ @@ -140,7 +140,7 @@ LL | let trivial_ends_with = Regex::new("foobar$"); = help: consider using `str::ends_with` error: trivial regex - --> tests/ui/regex.rs:86:39 + --> tests/ui/regex.rs:80:39 | LL | let trivial_contains = Regex::new("foobar"); | ^^^^^^^^ @@ -148,7 +148,7 @@ LL | let trivial_contains = Regex::new("foobar"); = help: consider using `str::contains` error: trivial regex - --> tests/ui/regex.rs:89:39 + --> tests/ui/regex.rs:83:39 | LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); | ^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); = help: consider using `str::contains` error: trivial regex - --> tests/ui/regex.rs:92:40 + --> tests/ui/regex.rs:86:40 | LL | let trivial_backslash = Regex::new("a\\.b"); | ^^^^^^^ @@ -164,7 +164,7 @@ LL | let trivial_backslash = Regex::new("a\\.b"); = help: consider using `str::contains` error: trivial regex - --> tests/ui/regex.rs:96:36 + --> tests/ui/regex.rs:90:36 | LL | let trivial_empty = Regex::new(""); | ^^ @@ -172,7 +172,7 @@ LL | let trivial_empty = Regex::new(""); = help: the regex is unlikely to be useful as it is error: trivial regex - --> tests/ui/regex.rs:99:36 + --> tests/ui/regex.rs:93:36 | LL | let trivial_empty = Regex::new("^"); | ^^^ @@ -180,7 +180,7 @@ LL | let trivial_empty = Regex::new("^"); = help: the regex is unlikely to be useful as it is error: trivial regex - --> tests/ui/regex.rs:102:36 + --> tests/ui/regex.rs:96:36 | LL | let trivial_empty = Regex::new("^$"); | ^^^^ @@ -188,7 +188,7 @@ LL | let trivial_empty = Regex::new("^$"); = help: consider using `str::is_empty` error: trivial regex - --> tests/ui/regex.rs:105:44 + --> tests/ui/regex.rs:99:44 | LL | let binary_trivial_empty = BRegex::new("^$"); | ^^^^ @@ -196,13 +196,13 @@ LL | let binary_trivial_empty = BRegex::new("^$"); = help: consider using `str::is_empty` error: compiling a regex in a loop - --> tests/ui/regex.rs:132:21 + --> tests/ui/regex.rs:126:21 | LL | let regex = Regex::new("a.b"); | ^^^^^^^^^^ | help: move the regex construction outside this loop - --> tests/ui/regex.rs:129:5 + --> tests/ui/regex.rs:123:5 | LL | loop { | ^^^^ @@ -210,37 +210,37 @@ LL | loop { = help: to override `-D warnings` add `#[allow(clippy::regex_creation_in_loops)]` error: compiling a regex in a loop - --> tests/ui/regex.rs:134:21 + --> tests/ui/regex.rs:128:21 | LL | let regex = BRegex::new("a.b"); | ^^^^^^^^^^^ | help: move the regex construction outside this loop - --> tests/ui/regex.rs:129:5 + --> tests/ui/regex.rs:123:5 | LL | loop { | ^^^^ error: compiling a regex in a loop - --> tests/ui/regex.rs:140:25 + --> tests/ui/regex.rs:134:25 | LL | let regex = Regex::new("a.b"); | ^^^^^^^^^^ | help: move the regex construction outside this loop - --> tests/ui/regex.rs:129:5 + --> tests/ui/regex.rs:123:5 | LL | loop { | ^^^^ error: compiling a regex in a loop - --> tests/ui/regex.rs:145:32 + --> tests/ui/regex.rs:139:32 | LL | let nested_regex = Regex::new("a.b"); | ^^^^^^^^^^ | help: move the regex construction outside this loop - --> tests/ui/regex.rs:144:9 + --> tests/ui/regex.rs:138:9 | LL | for _ in 0..10 { | ^^^^^^^^^^^^^^ diff --git a/tests/ui/repeat_vec_with_capacity.fixed b/tests/ui/repeat_vec_with_capacity.fixed index 8a3b0b4f193f9..db2b788d6e926 100644 --- a/tests/ui/repeat_vec_with_capacity.fixed +++ b/tests/ui/repeat_vec_with_capacity.fixed @@ -1,4 +1,3 @@ -#![allow(clippy::map_with_unused_argument_over_ranges)] #![warn(clippy::repeat_vec_with_capacity)] fn main() { diff --git a/tests/ui/repeat_vec_with_capacity.rs b/tests/ui/repeat_vec_with_capacity.rs index 011202d84757d..547c24aee3533 100644 --- a/tests/ui/repeat_vec_with_capacity.rs +++ b/tests/ui/repeat_vec_with_capacity.rs @@ -1,4 +1,3 @@ -#![allow(clippy::map_with_unused_argument_over_ranges)] #![warn(clippy::repeat_vec_with_capacity)] fn main() { diff --git a/tests/ui/repeat_vec_with_capacity.stderr b/tests/ui/repeat_vec_with_capacity.stderr index 05513a8859a42..3da26a12ae38a 100644 --- a/tests/ui/repeat_vec_with_capacity.stderr +++ b/tests/ui/repeat_vec_with_capacity.stderr @@ -1,5 +1,5 @@ error: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity - --> tests/ui/repeat_vec_with_capacity.rs:6:9 + --> tests/ui/repeat_vec_with_capacity.rs:5:9 | LL | vec![Vec::<()>::with_capacity(42); 123]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,7 +14,7 @@ LL + (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::>(); | error: repeating `Vec::with_capacity` using `vec![x; n]`, which does not retain capacity - --> tests/ui/repeat_vec_with_capacity.rs:12:9 + --> tests/ui/repeat_vec_with_capacity.rs:11:9 | LL | vec![Vec::<()>::with_capacity(42); n]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL + (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::>(); | error: repeating `Vec::with_capacity` using `iter::repeat`, which does not retain capacity - --> tests/ui/repeat_vec_with_capacity.rs:27:9 + --> tests/ui/repeat_vec_with_capacity.rs:26:9 | LL | std::iter::repeat(Vec::<()>::with_capacity(42)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/rest_pat_in_fully_bound_structs.fixed b/tests/ui/rest_pat_in_fully_bound_structs.fixed index ac200b3b19b74..6e33fda50dd9e 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.fixed +++ b/tests/ui/rest_pat_in_fully_bound_structs.fixed @@ -1,5 +1,5 @@ #![warn(clippy::rest_pat_in_fully_bound_structs)] -#![allow(clippy::struct_field_names)] +#![expect(clippy::struct_field_names)] struct A { a: i32, diff --git a/tests/ui/rest_pat_in_fully_bound_structs.rs b/tests/ui/rest_pat_in_fully_bound_structs.rs index bede01688972a..7007dfcf5ed46 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.rs +++ b/tests/ui/rest_pat_in_fully_bound_structs.rs @@ -1,5 +1,5 @@ #![warn(clippy::rest_pat_in_fully_bound_structs)] -#![allow(clippy::struct_field_names)] +#![expect(clippy::struct_field_names)] struct A { a: i32, diff --git a/tests/ui/result_filter_map.fixed b/tests/ui/result_filter_map.fixed index e8943dbc72da5..6b4186bcce26f 100644 --- a/tests/ui/result_filter_map.fixed +++ b/tests/ui/result_filter_map.fixed @@ -1,5 +1,5 @@ #![warn(clippy::result_filter_map)] -#![allow(clippy::map_flatten, clippy::unnecessary_map_on_constructor)] +#![allow(clippy::map_flatten)] fn odds_out(x: i32) -> Result { if x % 2 == 0 { Ok(x) } else { Err(()) } diff --git a/tests/ui/result_filter_map.rs b/tests/ui/result_filter_map.rs index ebd9c4288e3b7..4736942563309 100644 --- a/tests/ui/result_filter_map.rs +++ b/tests/ui/result_filter_map.rs @@ -1,5 +1,5 @@ #![warn(clippy::result_filter_map)] -#![allow(clippy::map_flatten, clippy::unnecessary_map_on_constructor)] +#![allow(clippy::map_flatten)] fn odds_out(x: i32) -> Result { if x % 2 == 0 { Ok(x) } else { Err(()) } diff --git a/tests/ui/result_large_err.rs b/tests/ui/result_large_err.rs index 0056c54ff5d42..70822bfa12308 100644 --- a/tests/ui/result_large_err.rs +++ b/tests/ui/result_large_err.rs @@ -1,7 +1,7 @@ //@ignore-bitwidth: 32 #![warn(clippy::result_large_err)] -#![allow(clippy::large_enum_variant)] +#![expect(clippy::large_enum_variant)] pub fn small_err() -> Result<(), u128> { Ok(()) diff --git a/tests/ui/result_map_unit_fn_unfixable.rs b/tests/ui/result_map_unit_fn_unfixable.rs index e3f5c7f996dad..8453e57d43fba 100644 --- a/tests/ui/result_map_unit_fn_unfixable.rs +++ b/tests/ui/result_map_unit_fn_unfixable.rs @@ -1,7 +1,7 @@ //@no-rustfix #![warn(clippy::result_map_unit_fn)] #![feature(never_type)] -#![allow(clippy::unnecessary_map_on_constructor)] +#![expect(clippy::unnecessary_map_on_constructor)] struct HasResult { field: Result, diff --git a/tests/ui/return_and_then.fixed b/tests/ui/return_and_then.fixed index be9a8e1da5c6b..a0a6314038aa6 100644 --- a/tests/ui/return_and_then.fixed +++ b/tests/ui/return_and_then.fixed @@ -1,5 +1,5 @@ #![warn(clippy::return_and_then)] -#![allow(clippy::manual_filter)] +#![expect(clippy::manual_filter)] fn main() { fn test_opt_block(opt: Option) -> Option { diff --git a/tests/ui/return_and_then.rs b/tests/ui/return_and_then.rs index 5d8372e418bf5..8ab52ed016dc1 100644 --- a/tests/ui/return_and_then.rs +++ b/tests/ui/return_and_then.rs @@ -1,5 +1,5 @@ #![warn(clippy::return_and_then)] -#![allow(clippy::manual_filter)] +#![expect(clippy::manual_filter)] fn main() { fn test_opt_block(opt: Option) -> Option { diff --git a/tests/ui/reversed_empty_ranges_fixable.fixed b/tests/ui/reversed_empty_ranges_fixable.fixed index 6c866aceed4f1..561e75e27ad2f 100644 --- a/tests/ui/reversed_empty_ranges_fixable.fixed +++ b/tests/ui/reversed_empty_ranges_fixable.fixed @@ -1,5 +1,5 @@ #![warn(clippy::reversed_empty_ranges)] -#![allow(clippy::uninlined_format_args)] +#![expect(clippy::uninlined_format_args)] const ANSWER: i32 = 42; diff --git a/tests/ui/reversed_empty_ranges_fixable.rs b/tests/ui/reversed_empty_ranges_fixable.rs index 4068bc393066b..cc175673b19b9 100644 --- a/tests/ui/reversed_empty_ranges_fixable.rs +++ b/tests/ui/reversed_empty_ranges_fixable.rs @@ -1,5 +1,5 @@ #![warn(clippy::reversed_empty_ranges)] -#![allow(clippy::uninlined_format_args)] +#![expect(clippy::uninlined_format_args)] const ANSWER: i32 = 42; diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.fixed b/tests/ui/reversed_empty_ranges_loops_fixable.fixed index 9fb46c9533cdd..e10eeca83f318 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.fixed +++ b/tests/ui/reversed_empty_ranges_loops_fixable.fixed @@ -1,5 +1,5 @@ #![warn(clippy::reversed_empty_ranges)] -#![allow(clippy::uninlined_format_args)] +#![expect(clippy::uninlined_format_args)] fn main() { const MAX_LEN: usize = 42; diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.rs b/tests/ui/reversed_empty_ranges_loops_fixable.rs index e51557bc2796a..64c376bbca28a 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_fixable.rs @@ -1,5 +1,5 @@ #![warn(clippy::reversed_empty_ranges)] -#![allow(clippy::uninlined_format_args)] +#![expect(clippy::uninlined_format_args)] fn main() { const MAX_LEN: usize = 42; diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.rs b/tests/ui/reversed_empty_ranges_loops_unfixable.rs index 00aa20d25bdad..f5f53a4bd077e 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.rs @@ -1,5 +1,5 @@ #![warn(clippy::reversed_empty_ranges)] -#![allow(clippy::uninlined_format_args)] +#![expect(clippy::uninlined_format_args)] fn main() { for i in 5..5 { diff --git a/tests/ui/same_functions_in_if_condition.rs b/tests/ui/same_functions_in_if_condition.rs index 3f205b322ab08..493a54aeac5ea 100644 --- a/tests/ui/same_functions_in_if_condition.rs +++ b/tests/ui/same_functions_in_if_condition.rs @@ -1,9 +1,6 @@ #![feature(adt_const_params)] -#![deny(clippy::same_functions_in_if_condition)] -// ifs_same_cond warning is different from `ifs_same_cond`. -// clippy::if_same_then_else, clippy::comparison_chain -- all empty blocks -#![allow(incomplete_features)] -#![allow(clippy::if_same_then_else, clippy::ifs_same_cond, clippy::uninlined_format_args)] +#![warn(clippy::same_functions_in_if_condition)] +#![expect(clippy::ifs_same_cond)] use std::marker::ConstParamTy; diff --git a/tests/ui/same_functions_in_if_condition.stderr b/tests/ui/same_functions_in_if_condition.stderr index 59f4511757d61..ad0d3f98f7d59 100644 --- a/tests/ui/same_functions_in_if_condition.stderr +++ b/tests/ui/same_functions_in_if_condition.stderr @@ -1,5 +1,5 @@ error: these `if` branches have the same function call - --> tests/ui/same_functions_in_if_condition.rs:33:8 + --> tests/ui/same_functions_in_if_condition.rs:30:8 | LL | if function() { | ^^^^^^^^^^ @@ -7,14 +7,11 @@ LL | LL | } else if function() { | ^^^^^^^^^^ | -note: the lint level is defined here - --> tests/ui/same_functions_in_if_condition.rs:2:9 - | -LL | #![deny(clippy::same_functions_in_if_condition)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::same-functions-in-if-condition` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::same_functions_in_if_condition)]` error: these `if` branches have the same function call - --> tests/ui/same_functions_in_if_condition.rs:38:8 + --> tests/ui/same_functions_in_if_condition.rs:35:8 | LL | if fn_arg(a) { | ^^^^^^^^^ @@ -23,7 +20,7 @@ LL | } else if fn_arg(a) { | ^^^^^^^^^ error: these `if` branches have the same function call - --> tests/ui/same_functions_in_if_condition.rs:43:8 + --> tests/ui/same_functions_in_if_condition.rs:40:8 | LL | if obj.method() { | ^^^^^^^^^^^^ @@ -32,7 +29,7 @@ LL | } else if obj.method() { | ^^^^^^^^^^^^ error: these `if` branches have the same function call - --> tests/ui/same_functions_in_if_condition.rs:48:8 + --> tests/ui/same_functions_in_if_condition.rs:45:8 | LL | if obj.method_arg(a) { | ^^^^^^^^^^^^^^^^^ @@ -41,7 +38,7 @@ LL | } else if obj.method_arg(a) { | ^^^^^^^^^^^^^^^^^ error: these `if` branches have the same function call - --> tests/ui/same_functions_in_if_condition.rs:54:8 + --> tests/ui/same_functions_in_if_condition.rs:51:8 | LL | if v.pop().is_none() { | ^^^^^^^^^^^^^^^^^ @@ -50,7 +47,7 @@ LL | } else if v.pop().is_none() { | ^^^^^^^^^^^^^^^^^ error: these `if` branches have the same function call - --> tests/ui/same_functions_in_if_condition.rs:59:8 + --> tests/ui/same_functions_in_if_condition.rs:56:8 | LL | if v.len() == 42 { | ^^^^^^^^^^^^^ diff --git a/tests/ui/same_name_method.rs b/tests/ui/same_name_method.rs index 43c664b1505fa..684cc2ff833fd 100644 --- a/tests/ui/same_name_method.rs +++ b/tests/ui/same_name_method.rs @@ -1,5 +1,5 @@ #![warn(clippy::same_name_method)] -#![allow(dead_code, non_camel_case_types)] +#![expect(non_camel_case_types)] trait T1 { fn foo() {} diff --git a/tests/ui/search_is_some.rs b/tests/ui/search_is_some.rs index 0a1e0b07d1eb6..3df2ce7a95a0d 100644 --- a/tests/ui/search_is_some.rs +++ b/tests/ui/search_is_some.rs @@ -1,8 +1,7 @@ //@aux-build:option_helpers.rs #![warn(clippy::search_is_some)] -#![allow(clippy::manual_pattern_char_comparison)] +#![expect(clippy::manual_pattern_char_comparison)] #![allow(clippy::useless_vec)] -#![allow(dead_code)] extern crate option_helpers; use option_helpers::IteratorFalsePositives; //@no-rustfix diff --git a/tests/ui/search_is_some.stderr b/tests/ui/search_is_some.stderr index ccbab5320ee24..f6e6cb1ec82cf 100644 --- a/tests/ui/search_is_some.stderr +++ b/tests/ui/search_is_some.stderr @@ -1,5 +1,5 @@ error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some.rs:21:20 + --> tests/ui/search_is_some.rs:20:20 | LL | let _ = (0..1).find(some_closure).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(some_closure)` @@ -8,7 +8,7 @@ LL | let _ = (0..1).find(some_closure).is_some(); = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some.rs:37:13 + --> tests/ui/search_is_some.rs:36:13 | LL | let _ = (0..1).find(some_closure).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(some_closure)` diff --git a/tests/ui/search_is_some_fixable_none.fixed b/tests/ui/search_is_some_fixable_none.fixed index 720ed385fb480..916b7e75fdebf 100644 --- a/tests/ui/search_is_some_fixable_none.fixed +++ b/tests/ui/search_is_some_fixable_none.fixed @@ -1,5 +1,6 @@ -#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec, clippy::manual_contains)] #![warn(clippy::search_is_some)] +#![allow(clippy::explicit_auto_deref, clippy::manual_contains)] +#![expect(clippy::useless_vec)] fn main() { let v = vec![3, 2, 1, 0, -1, -2, -3]; diff --git a/tests/ui/search_is_some_fixable_none.rs b/tests/ui/search_is_some_fixable_none.rs index 1cb5f9c399590..c5d6e80b70adc 100644 --- a/tests/ui/search_is_some_fixable_none.rs +++ b/tests/ui/search_is_some_fixable_none.rs @@ -1,5 +1,6 @@ -#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec, clippy::manual_contains)] #![warn(clippy::search_is_some)] +#![allow(clippy::explicit_auto_deref, clippy::manual_contains)] +#![expect(clippy::useless_vec)] fn main() { let v = vec![3, 2, 1, 0, -1, -2, -3]; diff --git a/tests/ui/search_is_some_fixable_none.stderr b/tests/ui/search_is_some_fixable_none.stderr index 909248357169f..64fb415549a7c 100644 --- a/tests/ui/search_is_some_fixable_none.stderr +++ b/tests/ui/search_is_some_fixable_none.stderr @@ -1,5 +1,5 @@ error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:9:13 + --> tests/ui/search_is_some_fixable_none.rs:10:13 | LL | let _ = v.iter().find(|&x| *x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x < 0)` @@ -8,49 +8,49 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_none(); = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:11:13 + --> tests/ui/search_is_some_fixable_none.rs:12:13 | LL | let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(|x| **y == x)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:14:13 + --> tests/ui/search_is_some_fixable_none.rs:15:13 | LL | let _ = (0..1).find(|x| *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(0..1).any(|x| x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:16:13 + --> tests/ui/search_is_some_fixable_none.rs:17:13 | LL | let _ = v.iter().find(|x| **x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:18:13 + --> tests/ui/search_is_some_fixable_none.rs:19:13 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(4..5).any(|x| x == 1 || x == 3 || x == 5)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:20:13 + --> tests/ui/search_is_some_fixable_none.rs:21:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:22:13 + --> tests/ui/search_is_some_fixable_none.rs:23:13 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:24:13 + --> tests/ui/search_is_some_fixable_none.rs:25:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:26:13 + --> tests/ui/search_is_some_fixable_none.rs:27:13 | LL | let _ = (1..3) | _____________^ @@ -60,7 +60,7 @@ LL | | .is_none(); | |__________________^ help: consider using: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:31:13 + --> tests/ui/search_is_some_fixable_none.rs:32:13 | LL | let _ = v | _____________^ @@ -82,13 +82,13 @@ LL ~ }); | error: called `is_none()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some_fixable_none.rs:40:13 + --> tests/ui/search_is_some_fixable_none.rs:41:13 | LL | let _ = v.iter().position(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some_fixable_none.rs:43:13 + --> tests/ui/search_is_some_fixable_none.rs:44:13 | LL | let _ = v | _____________^ @@ -110,13 +110,13 @@ LL ~ }); | error: called `is_none()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some_fixable_none.rs:52:13 + --> tests/ui/search_is_some_fixable_none.rs:53:13 | LL | let _ = v.iter().rposition(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some_fixable_none.rs:55:13 + --> tests/ui/search_is_some_fixable_none.rs:56:13 | LL | let _ = v | _____________^ @@ -138,79 +138,79 @@ LL ~ }); | error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:67:13 + --> tests/ui/search_is_some_fixable_none.rs:68:13 | LL | let _ = "hello world".find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:69:13 + --> tests/ui/search_is_some_fixable_none.rs:70:13 | LL | let _ = "hello world".find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:71:13 + --> tests/ui/search_is_some_fixable_none.rs:72:13 | LL | let _ = "hello world".find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!"hello world".contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:74:13 + --> tests/ui/search_is_some_fixable_none.rs:75:13 | LL | let _ = s1.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:76:13 + --> tests/ui/search_is_some_fixable_none.rs:77:13 | LL | let _ = s1.find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:78:13 + --> tests/ui/search_is_some_fixable_none.rs:79:13 | LL | let _ = s1.find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1.contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:81:13 + --> tests/ui/search_is_some_fixable_none.rs:82:13 | LL | let _ = s1[2..].find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:83:13 + --> tests/ui/search_is_some_fixable_none.rs:84:13 | LL | let _ = s1[2..].find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:85:13 + --> tests/ui/search_is_some_fixable_none.rs:86:13 | LL | let _ = s1[2..].find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s1[2..].contains(&s2[2..])` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:102:25 + --> tests/ui/search_is_some_fixable_none.rs:103:25 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!filter_hand.iter().any(|cc| c == &cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:119:30 + --> tests/ui/search_is_some_fixable_none.rs:120:30 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!filter_hand.iter().any(|cc| c == cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:131:17 + --> tests/ui/search_is_some_fixable_none.rs:132:17 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.foo == 1 && v.bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:135:17 + --> tests/ui/search_is_some_fixable_none.rs:136:17 | LL | let _ = vfoo | _________________^ @@ -228,55 +228,55 @@ LL ~ .iter().any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2); | error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:144:17 + --> tests/ui/search_is_some_fixable_none.rs:145:17 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|a| a[0] == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:151:17 + --> tests/ui/search_is_some_fixable_none.rs:152:17 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|sub| sub[1..4].len() == 3)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:170:17 + --> tests/ui/search_is_some_fixable_none.rs:171:17 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![ppx].iter().any(|ppp_x: &&u32| please(ppp_x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:172:17 + --> tests/ui/search_is_some_fixable_none.rs:173:17 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `![String::from("Hey hey")].iter().any(|s| s.len() == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:176:17 + --> tests/ui/search_is_some_fixable_none.rs:177:17 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:178:17 + --> tests/ui/search_is_some_fixable_none.rs:179:17 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x: &u32| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:182:17 + --> tests/ui/search_is_some_fixable_none.rs:183:17 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:185:17 + --> tests/ui/search_is_some_fixable_none.rs:186:17 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x: &u32| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:206:17 + --> tests/ui/search_is_some_fixable_none.rs:207:17 | LL | let _ = vfoo | _________________^ @@ -294,25 +294,25 @@ LL ~ .iter().any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] | error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:223:17 + --> tests/ui/search_is_some_fixable_none.rs:224:17 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.inner[0].bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:229:17 + --> tests/ui/search_is_some_fixable_none.rs:230:17 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|x| (**x)[0] == 9)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:243:17 + --> tests/ui/search_is_some_fixable_none.rs:244:17 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!vfoo.iter().any(|v| v.by_ref(&v.bar))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:248:17 + --> tests/ui/search_is_some_fixable_none.rs:249:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)] | _________________^ @@ -330,103 +330,103 @@ LL ~ .iter().any(|&&(&x, ref y)| x == *y); | error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:271:17 + --> tests/ui/search_is_some_fixable_none.rs:272:17 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|s| s[0].is_empty())` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:273:17 + --> tests/ui/search_is_some_fixable_none.rs:274:17 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|s| test_string_1(&s[0]))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:283:17 + --> tests/ui/search_is_some_fixable_none.rs:284:17 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| fp.field.is_power_of_two())` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:285:17 + --> tests/ui/search_is_some_fixable_none.rs:286:17 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| test_u32_1(fp.field))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:287:17 + --> tests/ui/search_is_some_fixable_none.rs:288:17 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|fp| test_u32_2(*fp.field))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:304:17 + --> tests/ui/search_is_some_fixable_none.rs:305:17 | LL | let _ = v.iter().find(|x| **x == 42).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:306:17 + --> tests/ui/search_is_some_fixable_none.rs:307:17 | LL | Foo.bar(v.iter().find(|x| **x == 42).is_none()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!v.iter().any(|x| *x == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:312:9 + --> tests/ui/search_is_some_fixable_none.rs:313:9 | LL | v.iter().find(|x| **x == 42).is_none().then(computations); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!v.iter().any(|x| *x == 42))` error: called `is_none()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_none.rs:318:9 + --> tests/ui/search_is_some_fixable_none.rs:319:9 | LL | v.iter().find(|x| **x == 42).is_none().then_some(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!v.iter().any(|x| *x == 42))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:324:17 + --> tests/ui/search_is_some_fixable_none.rs:325:17 | LL | let _ = s.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:326:17 + --> tests/ui/search_is_some_fixable_none.rs:327:17 | LL | Foo.bar(s.find("world").is_none()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:329:17 + --> tests/ui/search_is_some_fixable_none.rs:330:17 | LL | let _ = s.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:331:17 + --> tests/ui/search_is_some_fixable_none.rs:332:17 | LL | Foo.bar(s.find("world").is_none()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `!s.contains("world")` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:337:17 + --> tests/ui/search_is_some_fixable_none.rs:338:17 | LL | let _ = s.find("world").is_none().then(computations); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:340:17 + --> tests/ui/search_is_some_fixable_none.rs:341:17 | LL | let _ = s.find("world").is_none().then(computations); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:346:17 + --> tests/ui/search_is_some_fixable_none.rs:347:17 | LL | let _ = s.find("world").is_none().then_some(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` error: called `is_none()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_none.rs:349:17 + --> tests/ui/search_is_some_fixable_none.rs:350:17 | LL | let _ = s.find("world").is_none().then_some(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(!s.contains("world"))` diff --git a/tests/ui/search_is_some_fixable_some.fixed b/tests/ui/search_is_some_fixable_some.fixed index daae41c0c891b..69d6e8bfe1a29 100644 --- a/tests/ui/search_is_some_fixable_some.fixed +++ b/tests/ui/search_is_some_fixable_some.fixed @@ -1,5 +1,6 @@ -#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec, clippy::manual_contains)] #![warn(clippy::search_is_some)] +#![allow(clippy::explicit_auto_deref, clippy::manual_contains)] +#![expect(clippy::useless_vec)] fn main() { let v = vec![3, 2, 1, 0, -1, -2, -3]; diff --git a/tests/ui/search_is_some_fixable_some.rs b/tests/ui/search_is_some_fixable_some.rs index ead101a491a6a..b6038fce37d9b 100644 --- a/tests/ui/search_is_some_fixable_some.rs +++ b/tests/ui/search_is_some_fixable_some.rs @@ -1,5 +1,6 @@ -#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec, clippy::manual_contains)] #![warn(clippy::search_is_some)] +#![allow(clippy::explicit_auto_deref, clippy::manual_contains)] +#![expect(clippy::useless_vec)] fn main() { let v = vec![3, 2, 1, 0, -1, -2, -3]; diff --git a/tests/ui/search_is_some_fixable_some.stderr b/tests/ui/search_is_some_fixable_some.stderr index c56fe859aac09..90760242cd80a 100644 --- a/tests/ui/search_is_some_fixable_some.stderr +++ b/tests/ui/search_is_some_fixable_some.stderr @@ -1,5 +1,5 @@ error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:9:22 + --> tests/ui/search_is_some_fixable_some.rs:10:22 | LL | let _ = v.iter().find(|&x| *x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| *x < 0)` @@ -8,49 +8,49 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_some(); = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:11:20 + --> tests/ui/search_is_some_fixable_some.rs:12:20 | LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| **y == x)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:14:20 + --> tests/ui/search_is_some_fixable_some.rs:15:20 | LL | let _ = (0..1).find(|x| *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:16:22 + --> tests/ui/search_is_some_fixable_some.rs:17:22 | LL | let _ = v.iter().find(|x| **x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| *x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:18:20 + --> tests/ui/search_is_some_fixable_some.rs:19:20 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 1 || x == 3 || x == 5)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:20:20 + --> tests/ui/search_is_some_fixable_some.rs:21:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:22:20 + --> tests/ui/search_is_some_fixable_some.rs:23:20 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:24:20 + --> tests/ui/search_is_some_fixable_some.rs:25:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:27:10 + --> tests/ui/search_is_some_fixable_some.rs:28:10 | LL | .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) | __________^ @@ -59,7 +59,7 @@ LL | | .is_some(); | |__________________^ help: consider using: `any(|x| [1, 2, 3].contains(&x) || x == 0 || [4, 5, 6].contains(&x) || x == -1)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:33:10 + --> tests/ui/search_is_some_fixable_some.rs:34:10 | LL | .find(|&x| { | __________^ @@ -78,13 +78,13 @@ LL ~ }); | error: called `is_some()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some_fixable_some.rs:40:22 + --> tests/ui/search_is_some_fixable_some.rs:41:22 | LL | let _ = v.iter().position(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|&x| x < 0)` error: called `is_some()` after searching an `Iterator` with `position` - --> tests/ui/search_is_some_fixable_some.rs:45:10 + --> tests/ui/search_is_some_fixable_some.rs:46:10 | LL | .position(|&x| { | __________^ @@ -103,13 +103,13 @@ LL ~ }); | error: called `is_some()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some_fixable_some.rs:52:22 + --> tests/ui/search_is_some_fixable_some.rs:53:22 | LL | let _ = v.iter().rposition(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|&x| x < 0)` error: called `is_some()` after searching an `Iterator` with `rposition` - --> tests/ui/search_is_some_fixable_some.rs:57:10 + --> tests/ui/search_is_some_fixable_some.rs:58:10 | LL | .rposition(|&x| { | __________^ @@ -128,79 +128,79 @@ LL ~ }); | error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:66:27 + --> tests/ui/search_is_some_fixable_some.rs:67:27 | LL | let _ = "hello world".find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:68:27 + --> tests/ui/search_is_some_fixable_some.rs:69:27 | LL | let _ = "hello world".find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:70:27 + --> tests/ui/search_is_some_fixable_some.rs:71:27 | LL | let _ = "hello world".find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:73:16 + --> tests/ui/search_is_some_fixable_some.rs:74:16 | LL | let _ = s1.find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:75:16 + --> tests/ui/search_is_some_fixable_some.rs:76:16 | LL | let _ = s1.find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:77:16 + --> tests/ui/search_is_some_fixable_some.rs:78:16 | LL | let _ = s1.find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:80:21 + --> tests/ui/search_is_some_fixable_some.rs:81:21 | LL | let _ = s1[2..].find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:82:21 + --> tests/ui/search_is_some_fixable_some.rs:83:21 | LL | let _ = s1[2..].find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> tests/ui/search_is_some_fixable_some.rs:84:21 + --> tests/ui/search_is_some_fixable_some.rs:85:21 | LL | let _ = s1[2..].find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `contains(&s2[2..])` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:101:44 + --> tests/ui/search_is_some_fixable_some.rs:102:44 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|cc| c == &cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:118:49 + --> tests/ui/search_is_some_fixable_some.rs:119:49 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|cc| c == cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:130:29 + --> tests/ui/search_is_some_fixable_some.rs:131:29 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:136:14 + --> tests/ui/search_is_some_fixable_some.rs:137:14 | LL | .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) | ______________^ @@ -209,55 +209,55 @@ LL | | .is_some(); | |______________________^ help: consider using: `any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:143:29 + --> tests/ui/search_is_some_fixable_some.rs:144:29 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|a| a[0] == 42)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:150:29 + --> tests/ui/search_is_some_fixable_some.rs:151:29 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|sub| sub[1..4].len() == 3)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:169:30 + --> tests/ui/search_is_some_fixable_some.rs:170:30 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|ppp_x: &&u32| please(ppp_x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:171:50 + --> tests/ui/search_is_some_fixable_some.rs:172:50 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| s.len() == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:175:26 + --> tests/ui/search_is_some_fixable_some.rs:176:26 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:177:26 + --> tests/ui/search_is_some_fixable_some.rs:178:26 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:181:26 + --> tests/ui/search_is_some_fixable_some.rs:182:26 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:184:26 + --> tests/ui/search_is_some_fixable_some.rs:185:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:207:14 + --> tests/ui/search_is_some_fixable_some.rs:208:14 | LL | .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) | ______________^ @@ -266,25 +266,25 @@ LL | | .is_some(); | |______________________^ help: consider using: `any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:222:29 + --> tests/ui/search_is_some_fixable_some.rs:223:29 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.inner[0].bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:228:29 + --> tests/ui/search_is_some_fixable_some.rs:229:29 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x| (**x)[0] == 9)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:242:29 + --> tests/ui/search_is_some_fixable_some.rs:243:29 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|v| v.by_ref(&v.bar))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:249:14 + --> tests/ui/search_is_some_fixable_some.rs:250:14 | LL | .find(|&&&(&x, ref y)| x == *y) | ______________^ @@ -293,55 +293,55 @@ LL | | .is_some(); | |______________________^ help: consider using: `any(|&&(&x, ref y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:270:26 + --> tests/ui/search_is_some_fixable_some.rs:271:26 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| s[0].is_empty())` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:272:26 + --> tests/ui/search_is_some_fixable_some.rs:273:26 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|s| test_string_1(&s[0]))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:282:26 + --> tests/ui/search_is_some_fixable_some.rs:283:26 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| fp.field.is_power_of_two())` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:284:26 + --> tests/ui/search_is_some_fixable_some.rs:285:26 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| test_u32_1(fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:286:26 + --> tests/ui/search_is_some_fixable_some.rs:287:26 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|fp| test_u32_2(*fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:302:18 + --> tests/ui/search_is_some_fixable_some.rs:303:18 | LL | v.iter().find(|x: &&u32| func(x)).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| func(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:312:26 + --> tests/ui/search_is_some_fixable_some.rs:313:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_impl(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref_impl(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:316:26 + --> tests/ui/search_is_some_fixable_some.rs:317:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_dyn(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| arg_no_deref_dyn(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> tests/ui/search_is_some_fixable_some.rs:320:26 + --> tests/ui/search_is_some_fixable_some.rs:321:26 | LL | let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `any(|x: &u32| (*arg_no_deref_dyn)(&x))` diff --git a/tests/ui/seek_to_start_instead_of_rewind.fixed b/tests/ui/seek_to_start_instead_of_rewind.fixed index 87747eafc4430..ac9cf489f3fb3 100644 --- a/tests/ui/seek_to_start_instead_of_rewind.fixed +++ b/tests/ui/seek_to_start_instead_of_rewind.fixed @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::seek_to_start_instead_of_rewind)] use std::fs::OpenOptions; diff --git a/tests/ui/seek_to_start_instead_of_rewind.rs b/tests/ui/seek_to_start_instead_of_rewind.rs index e824a9b1ec317..05e6246cd8bb3 100644 --- a/tests/ui/seek_to_start_instead_of_rewind.rs +++ b/tests/ui/seek_to_start_instead_of_rewind.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::seek_to_start_instead_of_rewind)] use std::fs::OpenOptions; diff --git a/tests/ui/seek_to_start_instead_of_rewind.stderr b/tests/ui/seek_to_start_instead_of_rewind.stderr index 6c6575cc02f52..40d0db51d25c0 100644 --- a/tests/ui/seek_to_start_instead_of_rewind.stderr +++ b/tests/ui/seek_to_start_instead_of_rewind.stderr @@ -1,5 +1,5 @@ error: used `seek` to go to the start of the stream - --> tests/ui/seek_to_start_instead_of_rewind.rs:52:7 + --> tests/ui/seek_to_start_instead_of_rewind.rs:51:7 | LL | t.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` @@ -8,13 +8,13 @@ LL | t.seek(SeekFrom::Start(0)); = help: to override `-D warnings` add `#[allow(clippy::seek_to_start_instead_of_rewind)]` error: used `seek` to go to the start of the stream - --> tests/ui/seek_to_start_instead_of_rewind.rs:58:7 + --> tests/ui/seek_to_start_instead_of_rewind.rs:57:7 | LL | t.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` error: used `seek` to go to the start of the stream - --> tests/ui/seek_to_start_instead_of_rewind.rs:138:7 + --> tests/ui/seek_to_start_instead_of_rewind.rs:137:7 | LL | f.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` diff --git a/tests/ui/self_assignment.rs b/tests/ui/self_assignment.rs index 6e82b42cf6d70..7732b53f94fc4 100644 --- a/tests/ui/self_assignment.rs +++ b/tests/ui/self_assignment.rs @@ -1,5 +1,5 @@ #![warn(clippy::self_assignment)] -#![allow(clippy::useless_vec, clippy::needless_pass_by_ref_mut)] +#![expect(clippy::useless_vec)] pub struct S<'a> { a: i32, diff --git a/tests/ui/semicolon_if_nothing_returned.fixed b/tests/ui/semicolon_if_nothing_returned.fixed index 3de14e9d2595e..bbb81fea529bd 100644 --- a/tests/ui/semicolon_if_nothing_returned.fixed +++ b/tests/ui/semicolon_if_nothing_returned.fixed @@ -1,12 +1,8 @@ //@aux-build:proc_macro_attr.rs #![warn(clippy::semicolon_if_nothing_returned)] -#![allow( - clippy::redundant_closure, - clippy::uninlined_format_args, - clippy::needless_late_init, - clippy::empty_docs -)] +#![allow(clippy::needless_late_init)] +#![expect(clippy::empty_docs)] #[macro_use] extern crate proc_macro_attr; diff --git a/tests/ui/semicolon_if_nothing_returned.rs b/tests/ui/semicolon_if_nothing_returned.rs index 304f43fb457cf..d962f2ef6c411 100644 --- a/tests/ui/semicolon_if_nothing_returned.rs +++ b/tests/ui/semicolon_if_nothing_returned.rs @@ -1,12 +1,8 @@ //@aux-build:proc_macro_attr.rs #![warn(clippy::semicolon_if_nothing_returned)] -#![allow( - clippy::redundant_closure, - clippy::uninlined_format_args, - clippy::needless_late_init, - clippy::empty_docs -)] +#![allow(clippy::needless_late_init)] +#![expect(clippy::empty_docs)] #[macro_use] extern crate proc_macro_attr; diff --git a/tests/ui/semicolon_if_nothing_returned.stderr b/tests/ui/semicolon_if_nothing_returned.stderr index d7d117e05bdf7..8757f5e48220a 100644 --- a/tests/ui/semicolon_if_nothing_returned.stderr +++ b/tests/ui/semicolon_if_nothing_returned.stderr @@ -1,5 +1,5 @@ error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:18:5 + --> tests/ui/semicolon_if_nothing_returned.rs:14:5 | LL | println!("Hello") | ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");` @@ -8,25 +8,25 @@ LL | println!("Hello") = help: to override `-D warnings` add `#[allow(clippy::semicolon_if_nothing_returned)]` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:23:5 + --> tests/ui/semicolon_if_nothing_returned.rs:19:5 | LL | get_unit() | ^^^^^^^^^^ help: add a `;` here: `get_unit();` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:29:5 + --> tests/ui/semicolon_if_nothing_returned.rs:25:5 | LL | y = x + 1 | ^^^^^^^^^ help: add a `;` here: `y = x + 1;` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:36:9 + --> tests/ui/semicolon_if_nothing_returned.rs:32:9 | LL | hello() | ^^^^^^^ help: add a `;` here: `hello();` error: consider adding a `;` to the last statement for consistent formatting - --> tests/ui/semicolon_if_nothing_returned.rs:48:9 + --> tests/ui/semicolon_if_nothing_returned.rs:44:9 | LL | ptr::drop_in_place(s.as_mut_ptr()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());` diff --git a/tests/ui/semicolon_inside_block.fixed b/tests/ui/semicolon_inside_block.fixed index c7174881a4faf..c3afda0656336 100644 --- a/tests/ui/semicolon_inside_block.fixed +++ b/tests/ui/semicolon_inside_block.fixed @@ -1,12 +1,11 @@ -#![allow( - unused, - clippy::unused_unit, - clippy::unnecessary_operation, +#![warn(clippy::semicolon_inside_block)] +#![allow(clippy::unnecessary_operation)] +#![expect( + clippy::double_parens, clippy::no_effect, clippy::single_element_loop, - clippy::double_parens + clippy::unused_unit )] -#![warn(clippy::semicolon_inside_block)] #![feature(try_blocks)] macro_rules! m { diff --git a/tests/ui/semicolon_inside_block.rs b/tests/ui/semicolon_inside_block.rs index 25be9bee4f537..3163583a9cec2 100644 --- a/tests/ui/semicolon_inside_block.rs +++ b/tests/ui/semicolon_inside_block.rs @@ -1,12 +1,11 @@ -#![allow( - unused, - clippy::unused_unit, - clippy::unnecessary_operation, +#![warn(clippy::semicolon_inside_block)] +#![allow(clippy::unnecessary_operation)] +#![expect( + clippy::double_parens, clippy::no_effect, clippy::single_element_loop, - clippy::double_parens + clippy::unused_unit )] -#![warn(clippy::semicolon_inside_block)] #![feature(try_blocks)] macro_rules! m { diff --git a/tests/ui/semicolon_inside_block.stderr b/tests/ui/semicolon_inside_block.stderr index e165903742951..2046dd1c36be7 100644 --- a/tests/ui/semicolon_inside_block.stderr +++ b/tests/ui/semicolon_inside_block.stderr @@ -1,5 +1,5 @@ error: consider moving the `;` inside the block for consistent formatting - --> tests/ui/semicolon_inside_block.rs:40:5 + --> tests/ui/semicolon_inside_block.rs:39:5 | LL | { unit_fn_block() }; | ^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + { unit_fn_block(); } | error: consider moving the `;` inside the block for consistent formatting - --> tests/ui/semicolon_inside_block.rs:42:5 + --> tests/ui/semicolon_inside_block.rs:41:5 | LL | unsafe { unit_fn_block() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + unsafe { unit_fn_block(); } | error: consider moving the `;` inside the block for consistent formatting - --> tests/ui/semicolon_inside_block.rs:51:5 + --> tests/ui/semicolon_inside_block.rs:50:5 | LL | / { LL | | @@ -41,7 +41,7 @@ LL ~ } | error: consider moving the `;` inside the block for consistent formatting - --> tests/ui/semicolon_inside_block.rs:65:5 + --> tests/ui/semicolon_inside_block.rs:64:5 | LL | { m!(()) }; | ^^^^^^^^^^^ diff --git a/tests/ui/semicolon_inside_block_stmt_expr_attrs.fixed b/tests/ui/semicolon_inside_block_stmt_expr_attrs.fixed index 5b93a91da003a..457738f6d3218 100644 --- a/tests/ui/semicolon_inside_block_stmt_expr_attrs.fixed +++ b/tests/ui/semicolon_inside_block_stmt_expr_attrs.fixed @@ -1,8 +1,8 @@ // Test when the feature `stmt_expr_attributes` is enabled #![feature(stmt_expr_attributes)] -#![allow(clippy::no_effect)] #![warn(clippy::semicolon_inside_block)] +#![expect(clippy::no_effect)] pub fn issue15388() { #[rustfmt::skip] diff --git a/tests/ui/semicolon_inside_block_stmt_expr_attrs.rs b/tests/ui/semicolon_inside_block_stmt_expr_attrs.rs index aa2c0cb50299c..b6277ded7edd6 100644 --- a/tests/ui/semicolon_inside_block_stmt_expr_attrs.rs +++ b/tests/ui/semicolon_inside_block_stmt_expr_attrs.rs @@ -1,8 +1,8 @@ // Test when the feature `stmt_expr_attributes` is enabled #![feature(stmt_expr_attributes)] -#![allow(clippy::no_effect)] #![warn(clippy::semicolon_inside_block)] +#![expect(clippy::no_effect)] pub fn issue15388() { #[rustfmt::skip] diff --git a/tests/ui/semicolon_outside_block.fixed b/tests/ui/semicolon_outside_block.fixed index a3be80b492846..6939c6d01bf16 100644 --- a/tests/ui/semicolon_outside_block.fixed +++ b/tests/ui/semicolon_outside_block.fixed @@ -1,11 +1,10 @@ -#![allow( - unused, - clippy::unused_unit, - clippy::unnecessary_operation, +#![warn(clippy::semicolon_outside_block)] +#![expect( clippy::no_effect, - clippy::single_element_loop + clippy::single_element_loop, + clippy::unnecessary_operation, + clippy::unused_unit )] -#![warn(clippy::semicolon_outside_block)] macro_rules! m { (()) => { diff --git a/tests/ui/semicolon_outside_block.rs b/tests/ui/semicolon_outside_block.rs index 3b7bf68029f3a..33810142e8a00 100644 --- a/tests/ui/semicolon_outside_block.rs +++ b/tests/ui/semicolon_outside_block.rs @@ -1,11 +1,10 @@ -#![allow( - unused, - clippy::unused_unit, - clippy::unnecessary_operation, +#![warn(clippy::semicolon_outside_block)] +#![expect( clippy::no_effect, - clippy::single_element_loop + clippy::single_element_loop, + clippy::unnecessary_operation, + clippy::unused_unit )] -#![warn(clippy::semicolon_outside_block)] macro_rules! m { (()) => { diff --git a/tests/ui/semicolon_outside_block.stderr b/tests/ui/semicolon_outside_block.stderr index 18d6dc697f2e3..ab36ab38b2a8c 100644 --- a/tests/ui/semicolon_outside_block.stderr +++ b/tests/ui/semicolon_outside_block.stderr @@ -1,5 +1,5 @@ error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:41:5 + --> tests/ui/semicolon_outside_block.rs:40:5 | LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:43:5 + --> tests/ui/semicolon_outside_block.rs:42:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:53:5 + --> tests/ui/semicolon_outside_block.rs:52:5 | LL | / { LL | | @@ -41,7 +41,7 @@ LL ~ }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:64:5 + --> tests/ui/semicolon_outside_block.rs:63:5 | LL | { m!(()); } | ^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL + { m!(()) }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:87:5 + --> tests/ui/semicolon_outside_block.rs:86:5 | LL | / unsafe { LL | | @@ -68,7 +68,7 @@ LL ~ }; | error: consider moving the `;` outside the block for consistent formatting - --> tests/ui/semicolon_outside_block.rs:92:5 + --> tests/ui/semicolon_outside_block.rs:91:5 | LL | / { LL | | diff --git a/tests/ui/serde.rs b/tests/ui/serde.rs index 8ab1144e57006..1628380c4eb8a 100644 --- a/tests/ui/serde.rs +++ b/tests/ui/serde.rs @@ -1,5 +1,4 @@ #![warn(clippy::serde_api_misuse)] -#![allow(dead_code, clippy::needless_lifetimes)] extern crate serde; diff --git a/tests/ui/serde.stderr b/tests/ui/serde.stderr index 652248e3578c7..264ea09dd7221 100644 --- a/tests/ui/serde.stderr +++ b/tests/ui/serde.stderr @@ -1,5 +1,5 @@ error: you should not implement `visit_string` without also implementing `visit_str` - --> tests/ui/serde.rs:39:5 + --> tests/ui/serde.rs:38:5 | LL | / fn visit_string(self, _v: String) -> Result LL | | diff --git a/tests/ui/set_contains_or_insert.rs b/tests/ui/set_contains_or_insert.rs index b9480cd9172a5..585193cdfa840 100644 --- a/tests/ui/set_contains_or_insert.rs +++ b/tests/ui/set_contains_or_insert.rs @@ -1,7 +1,5 @@ -#![allow(unused)] -#![allow(clippy::nonminimal_bool)] -#![allow(clippy::needless_borrow)] #![warn(clippy::set_contains_or_insert)] +#![expect(clippy::needless_borrow)] use std::collections::{BTreeSet, HashSet}; diff --git a/tests/ui/set_contains_or_insert.stderr b/tests/ui/set_contains_or_insert.stderr index 85331514be7a1..e293cc7beed90 100644 --- a/tests/ui/set_contains_or_insert.stderr +++ b/tests/ui/set_contains_or_insert.stderr @@ -1,5 +1,5 @@ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:12:13 + --> tests/ui/set_contains_or_insert.rs:10:13 | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | set.insert(value); = help: to override `-D warnings` add `#[allow(clippy::set_contains_or_insert)]` error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:18:12 + --> tests/ui/set_contains_or_insert.rs:16:12 | LL | if set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:24:13 + --> tests/ui/set_contains_or_insert.rs:22:13 | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -29,7 +29,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:29:14 + --> tests/ui/set_contains_or_insert.rs:27:14 | LL | if !!set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:35:15 + --> tests/ui/set_contains_or_insert.rs:33:15 | LL | if (&set).contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:41:13 + --> tests/ui/set_contains_or_insert.rs:39:13 | LL | if !set.contains(borrow_value) { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | set.insert(*borrow_value); | ^^^^^^^^^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:47:20 + --> tests/ui/set_contains_or_insert.rs:45:20 | LL | if !borrow_set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | borrow_set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:86:13 + --> tests/ui/set_contains_or_insert.rs:84:13 | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -74,7 +74,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:92:12 + --> tests/ui/set_contains_or_insert.rs:90:12 | LL | if set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:98:13 + --> tests/ui/set_contains_or_insert.rs:96:13 | LL | if !set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:103:14 + --> tests/ui/set_contains_or_insert.rs:101:14 | LL | if !!set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -101,7 +101,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:109:15 + --> tests/ui/set_contains_or_insert.rs:107:15 | LL | if (&set).contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -110,7 +110,7 @@ LL | set.insert(value); | ^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:115:13 + --> tests/ui/set_contains_or_insert.rs:113:13 | LL | if !set.contains(borrow_value) { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -119,7 +119,7 @@ LL | set.insert(*borrow_value); | ^^^^^^^^^^^^^^^^^^^^^ error: usage of `BTreeSet::insert` after `BTreeSet::contains` - --> tests/ui/set_contains_or_insert.rs:121:20 + --> tests/ui/set_contains_or_insert.rs:119:20 | LL | if !borrow_set.contains(&value) { | ^^^^^^^^^^^^^^^^ @@ -128,7 +128,7 @@ LL | borrow_set.insert(value); | ^^^^^^^^^^^^^ error: usage of `HashSet::insert` after `HashSet::contains` - --> tests/ui/set_contains_or_insert.rs:176:11 + --> tests/ui/set_contains_or_insert.rs:174:11 | LL | if !s.contains(&v) { | ^^^^^^^^^^^^ diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs index d589bbc4affde..90953cda10107 100644 --- a/tests/ui/shadow.rs +++ b/tests/ui/shadow.rs @@ -1,12 +1,7 @@ //@aux-build:proc_macro_derive.rs -#![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)] -#![allow( - clippy::let_unit_value, - clippy::needless_ifs, - clippy::redundant_guards, - clippy::redundant_locals -)] +#![warn(clippy::shadow_reuse, clippy::shadow_same, clippy::shadow_unrelated)] +#![expect(clippy::let_unit_value, clippy::redundant_guards, clippy::redundant_locals)] extern crate proc_macro_derive; diff --git a/tests/ui/shadow.stderr b/tests/ui/shadow.stderr index 649f843575a7a..c356e4a130d06 100644 --- a/tests/ui/shadow.stderr +++ b/tests/ui/shadow.stderr @@ -1,11 +1,11 @@ error: `x` is shadowed by itself in `x` - --> tests/ui/shadow.rs:24:9 + --> tests/ui/shadow.rs:19:9 | LL | let x = x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:23:9 + --> tests/ui/shadow.rs:18:9 | LL | let x = 1; | ^ @@ -13,49 +13,49 @@ LL | let x = 1; = help: to override `-D warnings` add `#[allow(clippy::shadow_same)]` error: `mut x` is shadowed by itself in `&x` - --> tests/ui/shadow.rs:26:13 + --> tests/ui/shadow.rs:21:13 | LL | let mut x = &x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:24:9 + --> tests/ui/shadow.rs:19:9 | LL | let x = x; | ^ error: `x` is shadowed by itself in `&mut x` - --> tests/ui/shadow.rs:28:9 + --> tests/ui/shadow.rs:23:9 | LL | let x = &mut x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:26:9 + --> tests/ui/shadow.rs:21:9 | LL | let mut x = &x; | ^^^^^ error: `x` is shadowed by itself in `*x` - --> tests/ui/shadow.rs:30:9 + --> tests/ui/shadow.rs:25:9 | LL | let x = *x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:28:9 + --> tests/ui/shadow.rs:23:9 | LL | let x = &mut x; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:36:9 + --> tests/ui/shadow.rs:31:9 | LL | let x = x.0; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:35:9 + --> tests/ui/shadow.rs:30:9 | LL | let x = ([[0]], ()); | ^ @@ -63,97 +63,97 @@ LL | let x = ([[0]], ()); = help: to override `-D warnings` add `#[allow(clippy::shadow_reuse)]` error: `x` is shadowed - --> tests/ui/shadow.rs:38:9 + --> tests/ui/shadow.rs:33:9 | LL | let x = x[0]; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:36:9 + --> tests/ui/shadow.rs:31:9 | LL | let x = x.0; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:40:10 + --> tests/ui/shadow.rs:35:10 | LL | let [x] = x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:38:9 + --> tests/ui/shadow.rs:33:9 | LL | let x = x[0]; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:42:9 + --> tests/ui/shadow.rs:37:9 | LL | let x = Some(x); | ^ | note: previous binding is here - --> tests/ui/shadow.rs:40:10 + --> tests/ui/shadow.rs:35:10 | LL | let [x] = x; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:44:9 + --> tests/ui/shadow.rs:39:9 | LL | let x = foo(x); | ^ | note: previous binding is here - --> tests/ui/shadow.rs:42:9 + --> tests/ui/shadow.rs:37:9 | LL | let x = Some(x); | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:46:9 + --> tests/ui/shadow.rs:41:9 | LL | let x = || x; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:44:9 + --> tests/ui/shadow.rs:39:9 | LL | let x = foo(x); | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:48:9 + --> tests/ui/shadow.rs:43:9 | LL | let x = Some(1).map(|_| x)?; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:46:9 + --> tests/ui/shadow.rs:41:9 | LL | let x = || x; | ^ error: `y` is shadowed - --> tests/ui/shadow.rs:51:9 + --> tests/ui/shadow.rs:46:9 | LL | let y = match y { | ^ | note: previous binding is here - --> tests/ui/shadow.rs:50:9 + --> tests/ui/shadow.rs:45:9 | LL | let y = 1; | ^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:67:9 + --> tests/ui/shadow.rs:62:9 | LL | let x = 2; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:66:9 + --> tests/ui/shadow.rs:61:9 | LL | let x = 1; | ^ @@ -161,157 +161,157 @@ LL | let x = 1; = help: to override `-D warnings` add `#[allow(clippy::shadow_unrelated)]` error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:73:13 + --> tests/ui/shadow.rs:68:13 | LL | let x = 1; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:72:10 + --> tests/ui/shadow.rs:67:10 | LL | fn f(x: u32) { | ^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:79:14 + --> tests/ui/shadow.rs:74:14 | LL | Some(x) => { | ^ | note: previous binding is here - --> tests/ui/shadow.rs:76:9 + --> tests/ui/shadow.rs:71:9 | LL | let x = 1; | ^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:81:17 + --> tests/ui/shadow.rs:76:17 | LL | let x = 1; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:79:14 + --> tests/ui/shadow.rs:74:14 | LL | Some(x) => { | ^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:86:17 + --> tests/ui/shadow.rs:81:17 | LL | if let Some(x) = Some(1) {} | ^ | note: previous binding is here - --> tests/ui/shadow.rs:76:9 + --> tests/ui/shadow.rs:71:9 | LL | let x = 1; | ^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:88:20 + --> tests/ui/shadow.rs:83:20 | LL | while let Some(x) = Some(1) {} | ^ | note: previous binding is here - --> tests/ui/shadow.rs:76:9 + --> tests/ui/shadow.rs:71:9 | LL | let x = 1; | ^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:90:15 + --> tests/ui/shadow.rs:85:15 | LL | let _ = |[x]: [u32; 1]| { | ^ | note: previous binding is here - --> tests/ui/shadow.rs:76:9 + --> tests/ui/shadow.rs:71:9 | LL | let x = 1; | ^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:92:13 + --> tests/ui/shadow.rs:87:13 | LL | let x = 1; | ^ | note: previous binding is here - --> tests/ui/shadow.rs:90:15 + --> tests/ui/shadow.rs:85:15 | LL | let _ = |[x]: [u32; 1]| { | ^ error: `y` is shadowed - --> tests/ui/shadow.rs:96:17 + --> tests/ui/shadow.rs:91:17 | LL | if let Some(y) = y {} | ^ | note: previous binding is here - --> tests/ui/shadow.rs:95:9 + --> tests/ui/shadow.rs:90:9 | LL | let y = Some(1); | ^ error: `_b` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:133:9 + --> tests/ui/shadow.rs:128:9 | LL | let _b = _a; | ^^ | note: previous binding is here - --> tests/ui/shadow.rs:132:28 + --> tests/ui/shadow.rs:127:28 | LL | pub async fn foo2(_a: i32, _b: i64) { | ^^ error: `x` shadows a previous, unrelated binding - --> tests/ui/shadow.rs:140:21 + --> tests/ui/shadow.rs:135:21 | LL | if let Some(x) = Some(1) { x } else { 1 } | ^ | note: previous binding is here - --> tests/ui/shadow.rs:139:13 + --> tests/ui/shadow.rs:134:13 | LL | let x = 1; | ^ error: `x` is shadowed - --> tests/ui/shadow.rs:151:20 + --> tests/ui/shadow.rs:146:20 | LL | let z = x.map(|x| x + 1); | ^ | note: previous binding is here - --> tests/ui/shadow.rs:148:9 + --> tests/ui/shadow.rs:143:9 | LL | let x = Some(1); | ^ error: `i` is shadowed - --> tests/ui/shadow.rs:156:25 + --> tests/ui/shadow.rs:151:25 | LL | .map(|i| i.map(|i| i - 10)) | ^ | note: previous binding is here - --> tests/ui/shadow.rs:156:15 + --> tests/ui/shadow.rs:151:15 | LL | .map(|i| i.map(|i| i - 10)) | ^ error: `value` is shadowed by itself in `value` - --> tests/ui/shadow.rs:166:22 + --> tests/ui/shadow.rs:161:22 | LL | let Issue13795 { value, .. } = value; | ^^^^^ | note: previous binding is here - --> tests/ui/shadow.rs:165:15 + --> tests/ui/shadow.rs:160:15 | LL | fn issue13795(value: Issue13795) { | ^^^^^ diff --git a/tests/ui/short_circuit_statement.fixed b/tests/ui/short_circuit_statement.fixed index 133d296e259cf..00b85de2d5c24 100644 --- a/tests/ui/short_circuit_statement.fixed +++ b/tests/ui/short_circuit_statement.fixed @@ -1,5 +1,4 @@ #![warn(clippy::short_circuit_statement)] -#![allow(clippy::nonminimal_bool)] fn main() { if f() { g(); } diff --git a/tests/ui/short_circuit_statement.rs b/tests/ui/short_circuit_statement.rs index 4275ae64fdd65..eaedaadba758b 100644 --- a/tests/ui/short_circuit_statement.rs +++ b/tests/ui/short_circuit_statement.rs @@ -1,5 +1,4 @@ #![warn(clippy::short_circuit_statement)] -#![allow(clippy::nonminimal_bool)] fn main() { f() && g(); diff --git a/tests/ui/short_circuit_statement.stderr b/tests/ui/short_circuit_statement.stderr index acd28d41a33ae..4dc40fc7a1301 100644 --- a/tests/ui/short_circuit_statement.stderr +++ b/tests/ui/short_circuit_statement.stderr @@ -1,5 +1,5 @@ error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:5:5 + --> tests/ui/short_circuit_statement.rs:4:5 | LL | f() && g(); | ^^^^^^^^^^^ help: replace it with: `if f() { g(); }` @@ -8,37 +8,37 @@ LL | f() && g(); = help: to override `-D warnings` add `#[allow(clippy::short_circuit_statement)]` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:8:5 + --> tests/ui/short_circuit_statement.rs:7:5 | LL | f() || g(); | ^^^^^^^^^^^ help: replace it with: `if !f() { g(); }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:11:5 + --> tests/ui/short_circuit_statement.rs:10:5 | LL | 1 == 2 || g(); | ^^^^^^^^^^^^^^ help: replace it with: `if 1 != 2 { g(); }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:14:5 + --> tests/ui/short_circuit_statement.rs:13:5 | LL | (f() || g()) && (H * 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `if f() || g() { H * 2; }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:17:5 + --> tests/ui/short_circuit_statement.rs:16:5 | LL | (f() || g()) || (H * 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `if !(f() || g()) { H * 2; }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:32:5 + --> tests/ui/short_circuit_statement.rs:31:5 | LL | mac!() && mac!(); | ^^^^^^^^^^^^^^^^^ help: replace it with: `if mac!() { mac!(); }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> tests/ui/short_circuit_statement.rs:35:5 + --> tests/ui/short_circuit_statement.rs:34:5 | LL | mac!() || mac!(); | ^^^^^^^^^^^^^^^^^ help: replace it with: `if !mac!() { mac!(); }` diff --git a/tests/ui/should_impl_trait/corner_cases.rs b/tests/ui/should_impl_trait/corner_cases.rs index 53704f59cb999..724e0a7e4c5cc 100644 --- a/tests/ui/should_impl_trait/corner_cases.rs +++ b/tests/ui/should_impl_trait/corner_cases.rs @@ -1,16 +1,10 @@ //@ check-pass -#![allow( - clippy::missing_errors_doc, - clippy::needless_pass_by_value, - clippy::must_use_candidate, - clippy::unused_self, - clippy::needless_lifetimes, +#![warn(clippy::should_implement_trait)] +#![expect( clippy::missing_safety_doc, - clippy::wrong_self_convention, - clippy::missing_panics_doc, - clippy::return_self_not_must_use, - clippy::unused_async + clippy::needless_lifetimes, + clippy::wrong_self_convention )] use std::ops::Mul; diff --git a/tests/ui/should_impl_trait/method_list_1.edition2015.stderr b/tests/ui/should_impl_trait/method_list_1.edition2015.stderr index 0312fa8f04fae..aedebc64fee07 100644 --- a/tests/ui/should_impl_trait/method_list_1.edition2015.stderr +++ b/tests/ui/should_impl_trait/method_list_1.edition2015.stderr @@ -1,5 +1,5 @@ error: method `add` can be confused for the standard trait method `std::ops::Add::add` - --> tests/ui/should_impl_trait/method_list_1.rs:27:5 + --> tests/ui/should_impl_trait/method_list_1.rs:17:5 | LL | / pub fn add(self, other: T) -> T { LL | | @@ -13,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut` - --> tests/ui/should_impl_trait/method_list_1.rs:33:5 + --> tests/ui/should_impl_trait/method_list_1.rs:23:5 | LL | / pub fn as_mut(&mut self) -> &mut T { LL | | @@ -25,7 +25,7 @@ LL | | } = help: consider implementing the trait `std::convert::AsMut` or choosing a less ambiguous method name error: method `as_ref` can be confused for the standard trait method `std::convert::AsRef::as_ref` - --> tests/ui/should_impl_trait/method_list_1.rs:39:5 + --> tests/ui/should_impl_trait/method_list_1.rs:29:5 | LL | / pub fn as_ref(&self) -> &T { LL | | @@ -37,7 +37,7 @@ LL | | } = help: consider implementing the trait `std::convert::AsRef` or choosing a less ambiguous method name error: method `bitand` can be confused for the standard trait method `std::ops::BitAnd::bitand` - --> tests/ui/should_impl_trait/method_list_1.rs:45:5 + --> tests/ui/should_impl_trait/method_list_1.rs:35:5 | LL | / pub fn bitand(self, rhs: T) -> T { LL | | @@ -49,7 +49,7 @@ LL | | } = help: consider implementing the trait `std::ops::BitAnd` or choosing a less ambiguous method name error: method `bitor` can be confused for the standard trait method `std::ops::BitOr::bitor` - --> tests/ui/should_impl_trait/method_list_1.rs:51:5 + --> tests/ui/should_impl_trait/method_list_1.rs:41:5 | LL | / pub fn bitor(self, rhs: Self) -> Self { LL | | @@ -61,7 +61,7 @@ LL | | } = help: consider implementing the trait `std::ops::BitOr` or choosing a less ambiguous method name error: method `bitxor` can be confused for the standard trait method `std::ops::BitXor::bitxor` - --> tests/ui/should_impl_trait/method_list_1.rs:57:5 + --> tests/ui/should_impl_trait/method_list_1.rs:47:5 | LL | / pub fn bitxor(self, rhs: Self) -> Self { LL | | @@ -73,7 +73,7 @@ LL | | } = help: consider implementing the trait `std::ops::BitXor` or choosing a less ambiguous method name error: method `borrow` can be confused for the standard trait method `std::borrow::Borrow::borrow` - --> tests/ui/should_impl_trait/method_list_1.rs:63:5 + --> tests/ui/should_impl_trait/method_list_1.rs:53:5 | LL | / pub fn borrow(&self) -> &str { LL | | @@ -85,7 +85,7 @@ LL | | } = help: consider implementing the trait `std::borrow::Borrow` or choosing a less ambiguous method name error: method `borrow_mut` can be confused for the standard trait method `std::borrow::BorrowMut::borrow_mut` - --> tests/ui/should_impl_trait/method_list_1.rs:69:5 + --> tests/ui/should_impl_trait/method_list_1.rs:59:5 | LL | / pub fn borrow_mut(&mut self) -> &mut str { LL | | @@ -97,7 +97,7 @@ LL | | } = help: consider implementing the trait `std::borrow::BorrowMut` or choosing a less ambiguous method name error: method `clone` can be confused for the standard trait method `std::clone::Clone::clone` - --> tests/ui/should_impl_trait/method_list_1.rs:75:5 + --> tests/ui/should_impl_trait/method_list_1.rs:65:5 | LL | / pub fn clone(&self) -> Self { LL | | @@ -109,7 +109,7 @@ LL | | } = help: consider implementing the trait `std::clone::Clone` or choosing a less ambiguous method name error: method `cmp` can be confused for the standard trait method `std::cmp::Ord::cmp` - --> tests/ui/should_impl_trait/method_list_1.rs:81:5 + --> tests/ui/should_impl_trait/method_list_1.rs:71:5 | LL | / pub fn cmp(&self, other: &Self) -> Self { LL | | @@ -121,7 +121,7 @@ LL | | } = help: consider implementing the trait `std::cmp::Ord` or choosing a less ambiguous method name error: method `default` can be confused for the standard trait method `std::default::Default::default` - --> tests/ui/should_impl_trait/method_list_1.rs:87:5 + --> tests/ui/should_impl_trait/method_list_1.rs:77:5 | LL | / pub fn default() -> Self { LL | | @@ -133,7 +133,7 @@ LL | | } = help: consider implementing the trait `std::default::Default` or choosing a less ambiguous method name error: method `deref` can be confused for the standard trait method `std::ops::Deref::deref` - --> tests/ui/should_impl_trait/method_list_1.rs:93:5 + --> tests/ui/should_impl_trait/method_list_1.rs:83:5 | LL | / pub fn deref(&self) -> &Self { LL | | @@ -145,7 +145,7 @@ LL | | } = help: consider implementing the trait `std::ops::Deref` or choosing a less ambiguous method name error: method `deref_mut` can be confused for the standard trait method `std::ops::DerefMut::deref_mut` - --> tests/ui/should_impl_trait/method_list_1.rs:99:5 + --> tests/ui/should_impl_trait/method_list_1.rs:89:5 | LL | / pub fn deref_mut(&mut self) -> &mut Self { LL | | @@ -157,7 +157,7 @@ LL | | } = help: consider implementing the trait `std::ops::DerefMut` or choosing a less ambiguous method name error: method `div` can be confused for the standard trait method `std::ops::Div::div` - --> tests/ui/should_impl_trait/method_list_1.rs:105:5 + --> tests/ui/should_impl_trait/method_list_1.rs:95:5 | LL | / pub fn div(self, rhs: Self) -> Self { LL | | @@ -169,7 +169,7 @@ LL | | } = help: consider implementing the trait `std::ops::Div` or choosing a less ambiguous method name error: method `drop` can be confused for the standard trait method `std::ops::Drop::drop` - --> tests/ui/should_impl_trait/method_list_1.rs:111:5 + --> tests/ui/should_impl_trait/method_list_1.rs:101:5 | LL | / pub fn drop(&mut self) { LL | | diff --git a/tests/ui/should_impl_trait/method_list_1.edition2021.stderr b/tests/ui/should_impl_trait/method_list_1.edition2021.stderr index 0312fa8f04fae..aedebc64fee07 100644 --- a/tests/ui/should_impl_trait/method_list_1.edition2021.stderr +++ b/tests/ui/should_impl_trait/method_list_1.edition2021.stderr @@ -1,5 +1,5 @@ error: method `add` can be confused for the standard trait method `std::ops::Add::add` - --> tests/ui/should_impl_trait/method_list_1.rs:27:5 + --> tests/ui/should_impl_trait/method_list_1.rs:17:5 | LL | / pub fn add(self, other: T) -> T { LL | | @@ -13,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut` - --> tests/ui/should_impl_trait/method_list_1.rs:33:5 + --> tests/ui/should_impl_trait/method_list_1.rs:23:5 | LL | / pub fn as_mut(&mut self) -> &mut T { LL | | @@ -25,7 +25,7 @@ LL | | } = help: consider implementing the trait `std::convert::AsMut` or choosing a less ambiguous method name error: method `as_ref` can be confused for the standard trait method `std::convert::AsRef::as_ref` - --> tests/ui/should_impl_trait/method_list_1.rs:39:5 + --> tests/ui/should_impl_trait/method_list_1.rs:29:5 | LL | / pub fn as_ref(&self) -> &T { LL | | @@ -37,7 +37,7 @@ LL | | } = help: consider implementing the trait `std::convert::AsRef` or choosing a less ambiguous method name error: method `bitand` can be confused for the standard trait method `std::ops::BitAnd::bitand` - --> tests/ui/should_impl_trait/method_list_1.rs:45:5 + --> tests/ui/should_impl_trait/method_list_1.rs:35:5 | LL | / pub fn bitand(self, rhs: T) -> T { LL | | @@ -49,7 +49,7 @@ LL | | } = help: consider implementing the trait `std::ops::BitAnd` or choosing a less ambiguous method name error: method `bitor` can be confused for the standard trait method `std::ops::BitOr::bitor` - --> tests/ui/should_impl_trait/method_list_1.rs:51:5 + --> tests/ui/should_impl_trait/method_list_1.rs:41:5 | LL | / pub fn bitor(self, rhs: Self) -> Self { LL | | @@ -61,7 +61,7 @@ LL | | } = help: consider implementing the trait `std::ops::BitOr` or choosing a less ambiguous method name error: method `bitxor` can be confused for the standard trait method `std::ops::BitXor::bitxor` - --> tests/ui/should_impl_trait/method_list_1.rs:57:5 + --> tests/ui/should_impl_trait/method_list_1.rs:47:5 | LL | / pub fn bitxor(self, rhs: Self) -> Self { LL | | @@ -73,7 +73,7 @@ LL | | } = help: consider implementing the trait `std::ops::BitXor` or choosing a less ambiguous method name error: method `borrow` can be confused for the standard trait method `std::borrow::Borrow::borrow` - --> tests/ui/should_impl_trait/method_list_1.rs:63:5 + --> tests/ui/should_impl_trait/method_list_1.rs:53:5 | LL | / pub fn borrow(&self) -> &str { LL | | @@ -85,7 +85,7 @@ LL | | } = help: consider implementing the trait `std::borrow::Borrow` or choosing a less ambiguous method name error: method `borrow_mut` can be confused for the standard trait method `std::borrow::BorrowMut::borrow_mut` - --> tests/ui/should_impl_trait/method_list_1.rs:69:5 + --> tests/ui/should_impl_trait/method_list_1.rs:59:5 | LL | / pub fn borrow_mut(&mut self) -> &mut str { LL | | @@ -97,7 +97,7 @@ LL | | } = help: consider implementing the trait `std::borrow::BorrowMut` or choosing a less ambiguous method name error: method `clone` can be confused for the standard trait method `std::clone::Clone::clone` - --> tests/ui/should_impl_trait/method_list_1.rs:75:5 + --> tests/ui/should_impl_trait/method_list_1.rs:65:5 | LL | / pub fn clone(&self) -> Self { LL | | @@ -109,7 +109,7 @@ LL | | } = help: consider implementing the trait `std::clone::Clone` or choosing a less ambiguous method name error: method `cmp` can be confused for the standard trait method `std::cmp::Ord::cmp` - --> tests/ui/should_impl_trait/method_list_1.rs:81:5 + --> tests/ui/should_impl_trait/method_list_1.rs:71:5 | LL | / pub fn cmp(&self, other: &Self) -> Self { LL | | @@ -121,7 +121,7 @@ LL | | } = help: consider implementing the trait `std::cmp::Ord` or choosing a less ambiguous method name error: method `default` can be confused for the standard trait method `std::default::Default::default` - --> tests/ui/should_impl_trait/method_list_1.rs:87:5 + --> tests/ui/should_impl_trait/method_list_1.rs:77:5 | LL | / pub fn default() -> Self { LL | | @@ -133,7 +133,7 @@ LL | | } = help: consider implementing the trait `std::default::Default` or choosing a less ambiguous method name error: method `deref` can be confused for the standard trait method `std::ops::Deref::deref` - --> tests/ui/should_impl_trait/method_list_1.rs:93:5 + --> tests/ui/should_impl_trait/method_list_1.rs:83:5 | LL | / pub fn deref(&self) -> &Self { LL | | @@ -145,7 +145,7 @@ LL | | } = help: consider implementing the trait `std::ops::Deref` or choosing a less ambiguous method name error: method `deref_mut` can be confused for the standard trait method `std::ops::DerefMut::deref_mut` - --> tests/ui/should_impl_trait/method_list_1.rs:99:5 + --> tests/ui/should_impl_trait/method_list_1.rs:89:5 | LL | / pub fn deref_mut(&mut self) -> &mut Self { LL | | @@ -157,7 +157,7 @@ LL | | } = help: consider implementing the trait `std::ops::DerefMut` or choosing a less ambiguous method name error: method `div` can be confused for the standard trait method `std::ops::Div::div` - --> tests/ui/should_impl_trait/method_list_1.rs:105:5 + --> tests/ui/should_impl_trait/method_list_1.rs:95:5 | LL | / pub fn div(self, rhs: Self) -> Self { LL | | @@ -169,7 +169,7 @@ LL | | } = help: consider implementing the trait `std::ops::Div` or choosing a less ambiguous method name error: method `drop` can be confused for the standard trait method `std::ops::Drop::drop` - --> tests/ui/should_impl_trait/method_list_1.rs:111:5 + --> tests/ui/should_impl_trait/method_list_1.rs:101:5 | LL | / pub fn drop(&mut self) { LL | | diff --git a/tests/ui/should_impl_trait/method_list_1.rs b/tests/ui/should_impl_trait/method_list_1.rs index bbb04c0c5aa12..c737e9dd1e585 100644 --- a/tests/ui/should_impl_trait/method_list_1.rs +++ b/tests/ui/should_impl_trait/method_list_1.rs @@ -1,17 +1,7 @@ //@revisions: edition2015 edition2021 //@[edition2015] edition:2015 //@[edition2021] edition:2021 -#![allow( - clippy::missing_errors_doc, - clippy::needless_pass_by_value, - clippy::must_use_candidate, - clippy::unused_self, - clippy::needless_lifetimes, - clippy::missing_safety_doc, - clippy::wrong_self_convention, - clippy::missing_panics_doc, - clippy::return_self_not_must_use -)] +#![warn(clippy::should_implement_trait)] use std::ops::Mul; use std::rc::{self, Rc}; diff --git a/tests/ui/should_impl_trait/method_list_2.edition2015.stderr b/tests/ui/should_impl_trait/method_list_2.edition2015.stderr index 259815908fee0..bacd959d9ab69 100644 --- a/tests/ui/should_impl_trait/method_list_2.edition2015.stderr +++ b/tests/ui/should_impl_trait/method_list_2.edition2015.stderr @@ -1,5 +1,5 @@ error: method `eq` can be confused for the standard trait method `std::cmp::PartialEq::eq` - --> tests/ui/should_impl_trait/method_list_2.rs:28:5 + --> tests/ui/should_impl_trait/method_list_2.rs:18:5 | LL | / pub fn eq(&self, other: &Self) -> bool { LL | | @@ -13,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `from_str` can be confused for the standard trait method `std::str::FromStr::from_str` - --> tests/ui/should_impl_trait/method_list_2.rs:40:5 + --> tests/ui/should_impl_trait/method_list_2.rs:30:5 | LL | / pub fn from_str(s: &str) -> Result { LL | | @@ -25,7 +25,7 @@ LL | | } = help: consider implementing the trait `std::str::FromStr` or choosing a less ambiguous method name error: method `hash` can be confused for the standard trait method `std::hash::Hash::hash` - --> tests/ui/should_impl_trait/method_list_2.rs:46:5 + --> tests/ui/should_impl_trait/method_list_2.rs:36:5 | LL | / pub fn hash(&self, state: &mut T) { LL | | @@ -37,7 +37,7 @@ LL | | } = help: consider implementing the trait `std::hash::Hash` or choosing a less ambiguous method name error: method `index` can be confused for the standard trait method `std::ops::Index::index` - --> tests/ui/should_impl_trait/method_list_2.rs:52:5 + --> tests/ui/should_impl_trait/method_list_2.rs:42:5 | LL | / pub fn index(&self, index: usize) -> &Self { LL | | @@ -49,7 +49,7 @@ LL | | } = help: consider implementing the trait `std::ops::Index` or choosing a less ambiguous method name error: method `index_mut` can be confused for the standard trait method `std::ops::IndexMut::index_mut` - --> tests/ui/should_impl_trait/method_list_2.rs:58:5 + --> tests/ui/should_impl_trait/method_list_2.rs:48:5 | LL | / pub fn index_mut(&mut self, index: usize) -> &mut Self { LL | | @@ -61,7 +61,7 @@ LL | | } = help: consider implementing the trait `std::ops::IndexMut` or choosing a less ambiguous method name error: method `into_iter` can be confused for the standard trait method `std::iter::IntoIterator::into_iter` - --> tests/ui/should_impl_trait/method_list_2.rs:64:5 + --> tests/ui/should_impl_trait/method_list_2.rs:54:5 | LL | / pub fn into_iter(self) -> Self { LL | | @@ -73,7 +73,7 @@ LL | | } = help: consider implementing the trait `std::iter::IntoIterator` or choosing a less ambiguous method name error: method `mul` can be confused for the standard trait method `std::ops::Mul::mul` - --> tests/ui/should_impl_trait/method_list_2.rs:70:5 + --> tests/ui/should_impl_trait/method_list_2.rs:60:5 | LL | / pub fn mul(self, rhs: Self) -> Self { LL | | @@ -85,7 +85,7 @@ LL | | } = help: consider implementing the trait `std::ops::Mul` or choosing a less ambiguous method name error: method `neg` can be confused for the standard trait method `std::ops::Neg::neg` - --> tests/ui/should_impl_trait/method_list_2.rs:76:5 + --> tests/ui/should_impl_trait/method_list_2.rs:66:5 | LL | / pub fn neg(self) -> Self { LL | | @@ -97,7 +97,7 @@ LL | | } = help: consider implementing the trait `std::ops::Neg` or choosing a less ambiguous method name error: method `next` can be confused for the standard trait method `std::iter::Iterator::next` - --> tests/ui/should_impl_trait/method_list_2.rs:82:5 + --> tests/ui/should_impl_trait/method_list_2.rs:72:5 | LL | / pub fn next(&mut self) -> Option { LL | | @@ -109,7 +109,7 @@ LL | | } = help: consider implementing the trait `std::iter::Iterator` or choosing a less ambiguous method name error: method `not` can be confused for the standard trait method `std::ops::Not::not` - --> tests/ui/should_impl_trait/method_list_2.rs:88:5 + --> tests/ui/should_impl_trait/method_list_2.rs:78:5 | LL | / pub fn not(self) -> Self { LL | | @@ -121,7 +121,7 @@ LL | | } = help: consider implementing the trait `std::ops::Not` or choosing a less ambiguous method name error: method `rem` can be confused for the standard trait method `std::ops::Rem::rem` - --> tests/ui/should_impl_trait/method_list_2.rs:94:5 + --> tests/ui/should_impl_trait/method_list_2.rs:84:5 | LL | / pub fn rem(self, rhs: Self) -> Self { LL | | @@ -133,7 +133,7 @@ LL | | } = help: consider implementing the trait `std::ops::Rem` or choosing a less ambiguous method name error: method `shl` can be confused for the standard trait method `std::ops::Shl::shl` - --> tests/ui/should_impl_trait/method_list_2.rs:100:5 + --> tests/ui/should_impl_trait/method_list_2.rs:90:5 | LL | / pub fn shl(self, rhs: Self) -> Self { LL | | @@ -145,7 +145,7 @@ LL | | } = help: consider implementing the trait `std::ops::Shl` or choosing a less ambiguous method name error: method `shr` can be confused for the standard trait method `std::ops::Shr::shr` - --> tests/ui/should_impl_trait/method_list_2.rs:106:5 + --> tests/ui/should_impl_trait/method_list_2.rs:96:5 | LL | / pub fn shr(self, rhs: Self) -> Self { LL | | @@ -157,7 +157,7 @@ LL | | } = help: consider implementing the trait `std::ops::Shr` or choosing a less ambiguous method name error: method `sub` can be confused for the standard trait method `std::ops::Sub::sub` - --> tests/ui/should_impl_trait/method_list_2.rs:112:5 + --> tests/ui/should_impl_trait/method_list_2.rs:102:5 | LL | / pub fn sub(self, rhs: Self) -> Self { LL | | diff --git a/tests/ui/should_impl_trait/method_list_2.edition2021.stderr b/tests/ui/should_impl_trait/method_list_2.edition2021.stderr index 2f90b61e7a176..99ed9b5080d1c 100644 --- a/tests/ui/should_impl_trait/method_list_2.edition2021.stderr +++ b/tests/ui/should_impl_trait/method_list_2.edition2021.stderr @@ -1,5 +1,5 @@ error: method `eq` can be confused for the standard trait method `std::cmp::PartialEq::eq` - --> tests/ui/should_impl_trait/method_list_2.rs:28:5 + --> tests/ui/should_impl_trait/method_list_2.rs:18:5 | LL | / pub fn eq(&self, other: &Self) -> bool { LL | | @@ -13,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter` - --> tests/ui/should_impl_trait/method_list_2.rs:34:5 + --> tests/ui/should_impl_trait/method_list_2.rs:24:5 | LL | / pub fn from_iter(iter: T) -> Self { LL | | @@ -25,7 +25,7 @@ LL | | } = help: consider implementing the trait `std::iter::FromIterator` or choosing a less ambiguous method name error: method `from_str` can be confused for the standard trait method `std::str::FromStr::from_str` - --> tests/ui/should_impl_trait/method_list_2.rs:40:5 + --> tests/ui/should_impl_trait/method_list_2.rs:30:5 | LL | / pub fn from_str(s: &str) -> Result { LL | | @@ -37,7 +37,7 @@ LL | | } = help: consider implementing the trait `std::str::FromStr` or choosing a less ambiguous method name error: method `hash` can be confused for the standard trait method `std::hash::Hash::hash` - --> tests/ui/should_impl_trait/method_list_2.rs:46:5 + --> tests/ui/should_impl_trait/method_list_2.rs:36:5 | LL | / pub fn hash(&self, state: &mut T) { LL | | @@ -49,7 +49,7 @@ LL | | } = help: consider implementing the trait `std::hash::Hash` or choosing a less ambiguous method name error: method `index` can be confused for the standard trait method `std::ops::Index::index` - --> tests/ui/should_impl_trait/method_list_2.rs:52:5 + --> tests/ui/should_impl_trait/method_list_2.rs:42:5 | LL | / pub fn index(&self, index: usize) -> &Self { LL | | @@ -61,7 +61,7 @@ LL | | } = help: consider implementing the trait `std::ops::Index` or choosing a less ambiguous method name error: method `index_mut` can be confused for the standard trait method `std::ops::IndexMut::index_mut` - --> tests/ui/should_impl_trait/method_list_2.rs:58:5 + --> tests/ui/should_impl_trait/method_list_2.rs:48:5 | LL | / pub fn index_mut(&mut self, index: usize) -> &mut Self { LL | | @@ -73,7 +73,7 @@ LL | | } = help: consider implementing the trait `std::ops::IndexMut` or choosing a less ambiguous method name error: method `into_iter` can be confused for the standard trait method `std::iter::IntoIterator::into_iter` - --> tests/ui/should_impl_trait/method_list_2.rs:64:5 + --> tests/ui/should_impl_trait/method_list_2.rs:54:5 | LL | / pub fn into_iter(self) -> Self { LL | | @@ -85,7 +85,7 @@ LL | | } = help: consider implementing the trait `std::iter::IntoIterator` or choosing a less ambiguous method name error: method `mul` can be confused for the standard trait method `std::ops::Mul::mul` - --> tests/ui/should_impl_trait/method_list_2.rs:70:5 + --> tests/ui/should_impl_trait/method_list_2.rs:60:5 | LL | / pub fn mul(self, rhs: Self) -> Self { LL | | @@ -97,7 +97,7 @@ LL | | } = help: consider implementing the trait `std::ops::Mul` or choosing a less ambiguous method name error: method `neg` can be confused for the standard trait method `std::ops::Neg::neg` - --> tests/ui/should_impl_trait/method_list_2.rs:76:5 + --> tests/ui/should_impl_trait/method_list_2.rs:66:5 | LL | / pub fn neg(self) -> Self { LL | | @@ -109,7 +109,7 @@ LL | | } = help: consider implementing the trait `std::ops::Neg` or choosing a less ambiguous method name error: method `next` can be confused for the standard trait method `std::iter::Iterator::next` - --> tests/ui/should_impl_trait/method_list_2.rs:82:5 + --> tests/ui/should_impl_trait/method_list_2.rs:72:5 | LL | / pub fn next(&mut self) -> Option { LL | | @@ -121,7 +121,7 @@ LL | | } = help: consider implementing the trait `std::iter::Iterator` or choosing a less ambiguous method name error: method `not` can be confused for the standard trait method `std::ops::Not::not` - --> tests/ui/should_impl_trait/method_list_2.rs:88:5 + --> tests/ui/should_impl_trait/method_list_2.rs:78:5 | LL | / pub fn not(self) -> Self { LL | | @@ -133,7 +133,7 @@ LL | | } = help: consider implementing the trait `std::ops::Not` or choosing a less ambiguous method name error: method `rem` can be confused for the standard trait method `std::ops::Rem::rem` - --> tests/ui/should_impl_trait/method_list_2.rs:94:5 + --> tests/ui/should_impl_trait/method_list_2.rs:84:5 | LL | / pub fn rem(self, rhs: Self) -> Self { LL | | @@ -145,7 +145,7 @@ LL | | } = help: consider implementing the trait `std::ops::Rem` or choosing a less ambiguous method name error: method `shl` can be confused for the standard trait method `std::ops::Shl::shl` - --> tests/ui/should_impl_trait/method_list_2.rs:100:5 + --> tests/ui/should_impl_trait/method_list_2.rs:90:5 | LL | / pub fn shl(self, rhs: Self) -> Self { LL | | @@ -157,7 +157,7 @@ LL | | } = help: consider implementing the trait `std::ops::Shl` or choosing a less ambiguous method name error: method `shr` can be confused for the standard trait method `std::ops::Shr::shr` - --> tests/ui/should_impl_trait/method_list_2.rs:106:5 + --> tests/ui/should_impl_trait/method_list_2.rs:96:5 | LL | / pub fn shr(self, rhs: Self) -> Self { LL | | @@ -169,7 +169,7 @@ LL | | } = help: consider implementing the trait `std::ops::Shr` or choosing a less ambiguous method name error: method `sub` can be confused for the standard trait method `std::ops::Sub::sub` - --> tests/ui/should_impl_trait/method_list_2.rs:112:5 + --> tests/ui/should_impl_trait/method_list_2.rs:102:5 | LL | / pub fn sub(self, rhs: Self) -> Self { LL | | diff --git a/tests/ui/should_impl_trait/method_list_2.rs b/tests/ui/should_impl_trait/method_list_2.rs index 4c6d7df236ef6..465d3b2e122f1 100644 --- a/tests/ui/should_impl_trait/method_list_2.rs +++ b/tests/ui/should_impl_trait/method_list_2.rs @@ -1,17 +1,7 @@ //@revisions: edition2015 edition2021 //@[edition2015] edition:2015 //@[edition2021] edition:2021 -#![allow( - clippy::missing_errors_doc, - clippy::needless_pass_by_value, - clippy::must_use_candidate, - clippy::unused_self, - clippy::needless_lifetimes, - clippy::missing_safety_doc, - clippy::wrong_self_convention, - clippy::missing_panics_doc, - clippy::return_self_not_must_use -)] +#![warn(clippy::should_implement_trait)] use std::ops::Mul; use std::rc::{self, Rc}; diff --git a/tests/ui/significant_drop_in_scrutinee.rs b/tests/ui/significant_drop_in_scrutinee.rs index 78fc365bd5bb5..f9d33014c9587 100644 --- a/tests/ui/significant_drop_in_scrutinee.rs +++ b/tests/ui/significant_drop_in_scrutinee.rs @@ -1,13 +1,7 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 //@no-rustfix #![warn(clippy::significant_drop_in_scrutinee)] -#![allow(dead_code, unused_assignments)] -#![allow( - clippy::match_single_binding, - clippy::single_match, - clippy::uninlined_format_args, - clippy::needless_lifetimes -)] +#![expect(clippy::match_single_binding, clippy::single_match)] use std::num::ParseIntError; use std::ops::Deref; diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr index b32b249fd4296..24fe4571b670e 100644 --- a/tests/ui/significant_drop_in_scrutinee.stderr +++ b/tests/ui/significant_drop_in_scrutinee.stderr @@ -1,5 +1,5 @@ error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:60:11 + --> tests/ui/significant_drop_in_scrutinee.rs:54:11 | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:147:11 + --> tests/ui/significant_drop_in_scrutinee.rs:141:11 | LL | match s.lock_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:169:11 + --> tests/ui/significant_drop_in_scrutinee.rs:163:11 | LL | match s.lock_m_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:218:11 + --> tests/ui/significant_drop_in_scrutinee.rs:212:11 | LL | match counter.temp_increment().len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:242:16 + --> tests/ui/significant_drop_in_scrutinee.rs:236:16 | LL | match (mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL ~ match (value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:252:22 + --> tests/ui/significant_drop_in_scrutinee.rs:246:22 | LL | match (true, mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL ~ match (true, value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:263:16 + --> tests/ui/significant_drop_in_scrutinee.rs:257:16 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -139,7 +139,7 @@ LL ~ match (value, true, mutex2.lock().unwrap().s.len()) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:263:54 + --> tests/ui/significant_drop_in_scrutinee.rs:257:54 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -160,7 +160,7 @@ LL ~ match (mutex1.lock().unwrap().s.len(), true, value) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:316:11 + --> tests/ui/significant_drop_in_scrutinee.rs:310:11 | LL | match mutex.lock().unwrap().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -179,7 +179,7 @@ LL ~ match value > 1 { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:324:15 + --> tests/ui/significant_drop_in_scrutinee.rs:318:15 | LL | match 1 < mutex.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -198,7 +198,7 @@ LL ~ match 1 < value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:343:11 + --> tests/ui/significant_drop_in_scrutinee.rs:337:11 | LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -219,7 +219,7 @@ LL ~ match value < mutex2.lock().unwrap().s.len() { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:343:44 + --> tests/ui/significant_drop_in_scrutinee.rs:337:44 | LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL ~ match mutex1.lock().unwrap().s.len() < value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:356:11 + --> tests/ui/significant_drop_in_scrutinee.rs:350:11 | LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -261,7 +261,7 @@ LL ~ match value >= mutex2.lock().unwrap().s.len() { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:356:45 + --> tests/ui/significant_drop_in_scrutinee.rs:350:45 | LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -282,7 +282,7 @@ LL ~ match mutex1.lock().unwrap().s.len() >= value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:393:11 + --> tests/ui/significant_drop_in_scrutinee.rs:387:11 | LL | match get_mutex_guard().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL ~ match value > 1 { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:411:11 + --> tests/ui/significant_drop_in_scrutinee.rs:405:11 | LL | match match i { | ___________^ @@ -333,7 +333,7 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:438:11 + --> tests/ui/significant_drop_in_scrutinee.rs:432:11 | LL | match if i > 1 { | ___________^ @@ -366,7 +366,7 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:493:11 + --> tests/ui/significant_drop_in_scrutinee.rs:487:11 | LL | match s.lock().deref().deref() { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -384,7 +384,7 @@ LL ~ match (&value) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:542:11 + --> tests/ui/significant_drop_in_scrutinee.rs:536:11 | LL | match mutex.lock().unwrap().i = i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -403,7 +403,7 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:549:15 + --> tests/ui/significant_drop_in_scrutinee.rs:543:15 | LL | match i = mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -422,7 +422,7 @@ LL ~ match i = value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:556:11 + --> tests/ui/significant_drop_in_scrutinee.rs:550:11 | LL | match mutex.lock().unwrap().i += 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -441,7 +441,7 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:563:16 + --> tests/ui/significant_drop_in_scrutinee.rs:557:16 | LL | match i += mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -460,7 +460,7 @@ LL ~ match i += value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:627:11 + --> tests/ui/significant_drop_in_scrutinee.rs:621:11 | LL | match rwlock.read().unwrap().to_number() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -476,7 +476,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:654:11 + --> tests/ui/significant_drop_in_scrutinee.rs:648:11 | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -492,7 +492,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:716:11 + --> tests/ui/significant_drop_in_scrutinee.rs:710:11 | LL | match guard.take().len() { | ^^^^^^^^^^^^^^^^^^ @@ -508,7 +508,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression - --> tests/ui/significant_drop_in_scrutinee.rs:741:16 + --> tests/ui/significant_drop_in_scrutinee.rs:735:16 | LL | for val in mutex.lock().unwrap().copy_old_lifetime() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -524,7 +524,7 @@ LL ~ for val in value { | error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression - --> tests/ui/significant_drop_in_scrutinee.rs:780:17 + --> tests/ui/significant_drop_in_scrutinee.rs:774:17 | LL | for val in [mutex.lock().unwrap()[0], 2] { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -540,7 +540,7 @@ LL ~ for val in [value, 2] { | error: temporary with significant `Drop` in `if let` scrutinee will live until the end of the `if let` expression - --> tests/ui/significant_drop_in_scrutinee.rs:789:24 + --> tests/ui/significant_drop_in_scrutinee.rs:783:24 | LL | if let Some(val) = mutex.lock().unwrap().first().copied() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -556,7 +556,7 @@ LL ~ if let Some(val) = value { | error: temporary with significant `Drop` in `while let` scrutinee will live until the end of the `while let` expression - --> tests/ui/significant_drop_in_scrutinee.rs:804:27 + --> tests/ui/significant_drop_in_scrutinee.rs:798:27 | LL | while let Some(val) = mutex.lock().unwrap().pop() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -567,7 +567,7 @@ LL | } = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:815:11 + --> tests/ui/significant_drop_in_scrutinee.rs:809:11 | LL | match *foo_async(&mutex).await.unwrap() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -583,7 +583,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:835:19 + --> tests/ui/significant_drop_in_scrutinee.rs:829:19 | LL | let _ = match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/similar_names.rs b/tests/ui/similar_names.rs index 4b5e85d0d3203..771c333b076aa 100644 --- a/tests/ui/similar_names.rs +++ b/tests/ui/similar_names.rs @@ -1,11 +1,9 @@ #![warn(clippy::similar_names)] -#![allow( - unused, - clippy::println_empty_string, +#![expect( + clippy::diverging_sub_expression, clippy::empty_loop, clippy::never_loop, - clippy::diverging_sub_expression, - clippy::let_unit_value + clippy::println_empty_string )] struct Foo { diff --git a/tests/ui/similar_names.stderr b/tests/ui/similar_names.stderr index 7e8d0b2a2b756..ca7fcbd9fffdb 100644 --- a/tests/ui/similar_names.stderr +++ b/tests/ui/similar_names.stderr @@ -1,11 +1,11 @@ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:47:9 + --> tests/ui/similar_names.rs:45:9 | LL | let bluby: i32; | ^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:46:9 + --> tests/ui/similar_names.rs:44:9 | LL | let blubx: i32; | ^^^^^ @@ -13,61 +13,61 @@ LL | let blubx: i32; = help: to override `-D warnings` add `#[allow(clippy::similar_names)]` error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:51:9 + --> tests/ui/similar_names.rs:49:9 | LL | let ornange: i32; | ^^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:50:9 + --> tests/ui/similar_names.rs:48:9 | LL | let orange: i32; | ^^^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:56:9 + --> tests/ui/similar_names.rs:54:9 | LL | let coke: i32; | ^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:55:9 + --> tests/ui/similar_names.rs:53:9 | LL | let cake: i32; | ^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:78:9 + --> tests/ui/similar_names.rs:76:9 | LL | let xyzeabc: i32; | ^^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:76:9 + --> tests/ui/similar_names.rs:74:9 | LL | let xyz1abc: i32; | ^^^^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:83:9 + --> tests/ui/similar_names.rs:81:9 | LL | let parsee: i32; | ^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:81:9 + --> tests/ui/similar_names.rs:79:9 | LL | let parser: i32; | ^^^^^^ error: binding's name is too similar to existing binding - --> tests/ui/similar_names.rs:112:16 + --> tests/ui/similar_names.rs:110:16 | LL | bpple: sprang, | ^^^^^^ | note: existing binding defined here - --> tests/ui/similar_names.rs:111:16 + --> tests/ui/similar_names.rs:109:16 | LL | apple: spring, | ^^^^^^ diff --git a/tests/ui/single_call_fn.rs b/tests/ui/single_call_fn.rs index a1ecd7bc166cf..f1fa035a3c745 100644 --- a/tests/ui/single_call_fn.rs +++ b/tests/ui/single_call_fn.rs @@ -1,6 +1,5 @@ //@ignore-bitwidth: 32 //@aux-build:proc_macros.rs -#![allow(clippy::redundant_closure_call, unused)] #![warn(clippy::single_call_fn)] #![no_main] diff --git a/tests/ui/single_call_fn.stderr b/tests/ui/single_call_fn.stderr index 8dd90a1238522..f1f6c9b86791b 100644 --- a/tests/ui/single_call_fn.stderr +++ b/tests/ui/single_call_fn.stderr @@ -1,11 +1,11 @@ error: this function is only used once - --> tests/ui/single_call_fn.rs:13:1 + --> tests/ui/single_call_fn.rs:12:1 | LL | fn i() {} | ^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:20:13 + --> tests/ui/single_call_fn.rs:19:13 | LL | let a = i; | ^ @@ -13,19 +13,19 @@ LL | let a = i; = help: to override `-D warnings` add `#[allow(clippy::single_call_fn)]` error: this function is only used once - --> tests/ui/single_call_fn.rs:15:1 + --> tests/ui/single_call_fn.rs:14:1 | LL | fn j() {} | ^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:27:9 + --> tests/ui/single_call_fn.rs:26:9 | LL | j(); | ^ error: this function is only used once - --> tests/ui/single_call_fn.rs:36:1 + --> tests/ui/single_call_fn.rs:35:1 | LL | / fn c() { LL | | @@ -36,43 +36,43 @@ LL | | } | |_^ | note: used here - --> tests/ui/single_call_fn.rs:44:5 + --> tests/ui/single_call_fn.rs:43:5 | LL | c(); | ^ error: this function is only used once - --> tests/ui/single_call_fn.rs:47:1 + --> tests/ui/single_call_fn.rs:46:1 | LL | fn a() {} | ^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:51:5 + --> tests/ui/single_call_fn.rs:50:5 | LL | a(); | ^ error: this function is only used once - --> tests/ui/single_call_fn.rs:93:5 + --> tests/ui/single_call_fn.rs:92:5 | LL | fn default() {} | ^^^^^^^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:110:5 + --> tests/ui/single_call_fn.rs:109:5 | LL | T::default(); | ^^^^^^^^^^ error: this function is only used once - --> tests/ui/single_call_fn.rs:107:9 + --> tests/ui/single_call_fn.rs:106:9 | LL | fn foo() {} | ^^^^^^^^^^^ | note: used here - --> tests/ui/single_call_fn.rs:111:5 + --> tests/ui/single_call_fn.rs:110:5 | LL | S::foo(); | ^^^^^^ diff --git a/tests/ui/single_char_add_str.fixed b/tests/ui/single_char_add_str.fixed index b729cf8b2ca13..5fea41916e47e 100644 --- a/tests/ui/single_char_add_str.fixed +++ b/tests/ui/single_char_add_str.fixed @@ -1,5 +1,4 @@ #![warn(clippy::single_char_add_str)] -#![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes)] macro_rules! get_string { () => { diff --git a/tests/ui/single_char_add_str.rs b/tests/ui/single_char_add_str.rs index a768c47db391e..0130a33f52993 100644 --- a/tests/ui/single_char_add_str.rs +++ b/tests/ui/single_char_add_str.rs @@ -1,5 +1,4 @@ #![warn(clippy::single_char_add_str)] -#![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes)] macro_rules! get_string { () => { diff --git a/tests/ui/single_char_add_str.stderr b/tests/ui/single_char_add_str.stderr index a1fae93462c90..2f06c99ca19a4 100644 --- a/tests/ui/single_char_add_str.stderr +++ b/tests/ui/single_char_add_str.stderr @@ -1,5 +1,5 @@ error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:14:5 + --> tests/ui/single_char_add_str.rs:13:5 | LL | string.push_str("R"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('R')` @@ -8,121 +8,121 @@ LL | string.push_str("R"); = help: to override `-D warnings` add `#[allow(clippy::single_char_add_str)]` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:16:5 + --> tests/ui/single_char_add_str.rs:15:5 | LL | string.push_str("'"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\'')` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:22:5 + --> tests/ui/single_char_add_str.rs:21:5 | LL | string.push_str("\x52"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\x52')` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:24:5 + --> tests/ui/single_char_add_str.rs:23:5 | LL | string.push_str("\u{0052}"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\u{0052}')` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:26:5 + --> tests/ui/single_char_add_str.rs:25:5 | LL | string.push_str(r##"a"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('a')` error: calling `push_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:30:5 + --> tests/ui/single_char_add_str.rs:29:5 | LL | string.push_str(&c_ref.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` without `to_string()`: `string.push(*c_ref)` error: calling `push_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:33:5 + --> tests/ui/single_char_add_str.rs:32:5 | LL | string.push_str(&c.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` without `to_string()`: `string.push(c)` error: calling `push_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:35:5 + --> tests/ui/single_char_add_str.rs:34:5 | LL | string.push_str(&'a'.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` without `to_string()`: `string.push('a')` error: calling `push_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:38:5 + --> tests/ui/single_char_add_str.rs:37:5 | LL | get_string!().push_str("ö"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `get_string!().push('ö')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:44:5 + --> tests/ui/single_char_add_str.rs:43:5 | LL | string.insert_str(0, "R"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, 'R')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:46:5 + --> tests/ui/single_char_add_str.rs:45:5 | LL | string.insert_str(1, "'"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(1, '\'')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:52:5 + --> tests/ui/single_char_add_str.rs:51:5 | LL | string.insert_str(0, "\x52"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '\x52')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:54:5 + --> tests/ui/single_char_add_str.rs:53:5 | LL | string.insert_str(0, "\u{0052}"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '\u{0052}')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:57:5 + --> tests/ui/single_char_add_str.rs:56:5 | LL | string.insert_str(x, r##"a"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(x, 'a')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:60:5 + --> tests/ui/single_char_add_str.rs:59:5 | LL | string.insert_str(Y, r##"a"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, 'a')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:62:5 + --> tests/ui/single_char_add_str.rs:61:5 | LL | string.insert_str(Y, r##"""##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '"')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:64:5 + --> tests/ui/single_char_add_str.rs:63:5 | LL | string.insert_str(Y, r##"'"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '\'')` error: calling `insert_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:67:5 + --> tests/ui/single_char_add_str.rs:66:5 | LL | string.insert_str(0, &c_ref.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` without `to_string()`: `string.insert(0, *c_ref)` error: calling `insert_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:69:5 + --> tests/ui/single_char_add_str.rs:68:5 | LL | string.insert_str(0, &c.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` without `to_string()`: `string.insert(0, c)` error: calling `insert_str()` using a single-character converted to string - --> tests/ui/single_char_add_str.rs:71:5 + --> tests/ui/single_char_add_str.rs:70:5 | LL | string.insert_str(0, &'a'.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` without `to_string()`: `string.insert(0, 'a')` error: calling `insert_str()` using a single-character string literal - --> tests/ui/single_char_add_str.rs:74:5 + --> tests/ui/single_char_add_str.rs:73:5 | LL | get_string!().insert_str(1, "?"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `get_string!().insert(1, '?')` diff --git a/tests/ui/single_char_lifetime_names.rs b/tests/ui/single_char_lifetime_names.rs index f4dcf46b0e2d3..3fe5c5fb720cf 100644 --- a/tests/ui/single_char_lifetime_names.rs +++ b/tests/ui/single_char_lifetime_names.rs @@ -1,5 +1,4 @@ #![warn(clippy::single_char_lifetime_names)] -#![allow(clippy::let_unit_value)] // Lifetimes should only be linted when they're introduced struct DiagnosticCtx<'a, 'b> diff --git a/tests/ui/single_char_lifetime_names.stderr b/tests/ui/single_char_lifetime_names.stderr index 834b654baa572..ff9d039e7d51a 100644 --- a/tests/ui/single_char_lifetime_names.stderr +++ b/tests/ui/single_char_lifetime_names.stderr @@ -1,5 +1,5 @@ error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:5:22 + --> tests/ui/single_char_lifetime_names.rs:4:22 | LL | struct DiagnosticCtx<'a, 'b> | ^^ @@ -9,7 +9,7 @@ LL | struct DiagnosticCtx<'a, 'b> = help: to override `-D warnings` add `#[allow(clippy::single_char_lifetime_names)]` error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:5:26 + --> tests/ui/single_char_lifetime_names.rs:4:26 | LL | struct DiagnosticCtx<'a, 'b> | ^^ @@ -17,7 +17,7 @@ LL | struct DiagnosticCtx<'a, 'b> = help: use a more informative name error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:16:6 + --> tests/ui/single_char_lifetime_names.rs:15:6 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -25,7 +25,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:16:10 + --> tests/ui/single_char_lifetime_names.rs:15:10 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -33,7 +33,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> tests/ui/single_char_lifetime_names.rs:39:15 + --> tests/ui/single_char_lifetime_names.rs:38:15 | LL | fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) { | ^^ diff --git a/tests/ui/single_range_in_vec_init.new_range.1.fixed b/tests/ui/single_range_in_vec_init.new_range.1.fixed new file mode 100644 index 0000000000000..02a91e654a5cb --- /dev/null +++ b/tests/ui/single_range_in_vec_init.new_range.1.fixed @@ -0,0 +1,97 @@ +//@aux-build:proc_macros.rs +//@revisions: old_range new_range +//@[new_range] compile-flags: --cfg=new_range + +// When feature(new_range) stabilizes, this should be converted to testing +// old and new editions instead. +#![cfg_attr(new_range, feature(new_range))] +#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] +#![warn(clippy::single_range_in_vec_init)] + +#[macro_use] +extern crate proc_macros; + +macro_rules! a { + () => { + vec![0..200]; + }; +} + +fn awa(start: T, end: T) { + [start..end]; +} + +fn awa_vec(start: T, end: T) { + vec![start..end]; +} + +fn main() { + // Lint + std::vec::Vec::::from_iter(0..200); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0..200); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0u8..200); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0usize..200); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0..200usize); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0u8..200); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0usize..200); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0..200usize); + //~^ single_range_in_vec_init + // Only suggest collect + std::vec::Vec::::from_iter(0..200isize); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0..200isize); + //~^ single_range_in_vec_init + // Do not lint + [0..200, 0..100]; + vec![0..200, 0..100]; + [0.0..200.0]; + vec![0.0..200.0]; + // `Copy` is not implemented for `Range`, so this doesn't matter + // FIXME: [0..200; 2]; + // FIXME: [vec!0..200; 2]; + + // Unfortunately skips any macros + a!(); + + // Skip external macros and procedural macros + external! { + [0..200]; + vec![0..200]; + } + with_span! { + span + [0..200]; + vec![0..200]; + } +} + +fn issue16042() { + use std::ops::Range; + + let input = vec![Range { start: 0, end: 5 }]; +} + +fn issue16044() { + macro_rules! as_i32 { + ($x:expr) => { + $x as i32 + }; + } + + let input = std::vec::Vec::::from_iter(0..as_i32!(10)); + //~^ single_range_in_vec_init +} + +fn issue16508() { + std::vec::Vec::::from_iter(0..=10); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0..=10); + //~^ single_range_in_vec_init +} diff --git a/tests/ui/single_range_in_vec_init.new_range.2.fixed b/tests/ui/single_range_in_vec_init.new_range.2.fixed new file mode 100644 index 0000000000000..afd183ab87ac3 --- /dev/null +++ b/tests/ui/single_range_in_vec_init.new_range.2.fixed @@ -0,0 +1,97 @@ +//@aux-build:proc_macros.rs +//@revisions: old_range new_range +//@[new_range] compile-flags: --cfg=new_range + +// When feature(new_range) stabilizes, this should be converted to testing +// old and new editions instead. +#![cfg_attr(new_range, feature(new_range))] +#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] +#![warn(clippy::single_range_in_vec_init)] + +#[macro_use] +extern crate proc_macros; + +macro_rules! a { + () => { + vec![0..200]; + }; +} + +fn awa(start: T, end: T) { + [start..end]; +} + +fn awa_vec(start: T, end: T) { + vec![start..end]; +} + +fn main() { + // Lint + [0; 200]; + //~^ single_range_in_vec_init + vec![0; 200]; + //~^ single_range_in_vec_init + [0u8; 200]; + //~^ single_range_in_vec_init + [0usize; 200]; + //~^ single_range_in_vec_init + [0; 200usize]; + //~^ single_range_in_vec_init + vec![0u8; 200]; + //~^ single_range_in_vec_init + vec![0usize; 200]; + //~^ single_range_in_vec_init + vec![0; 200usize]; + //~^ single_range_in_vec_init + // Only suggest collect + std::vec::Vec::::from_iter(0..200isize); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0..200isize); + //~^ single_range_in_vec_init + // Do not lint + [0..200, 0..100]; + vec![0..200, 0..100]; + [0.0..200.0]; + vec![0.0..200.0]; + // `Copy` is not implemented for `Range`, so this doesn't matter + // FIXME: [0..200; 2]; + // FIXME: [vec!0..200; 2]; + + // Unfortunately skips any macros + a!(); + + // Skip external macros and procedural macros + external! { + [0..200]; + vec![0..200]; + } + with_span! { + span + [0..200]; + vec![0..200]; + } +} + +fn issue16042() { + use std::ops::Range; + + let input = vec![Range { start: 0, end: 5 }]; +} + +fn issue16044() { + macro_rules! as_i32 { + ($x:expr) => { + $x as i32 + }; + } + + let input = std::vec::Vec::::from_iter(0..as_i32!(10)); + //~^ single_range_in_vec_init +} + +fn issue16508() { + std::vec::Vec::::from_iter(0..=10); + //~^ single_range_in_vec_init + std::vec::Vec::::from_iter(0..=10); + //~^ single_range_in_vec_init +} diff --git a/tests/ui/single_range_in_vec_init.new_range.stderr b/tests/ui/single_range_in_vec_init.new_range.stderr new file mode 100644 index 0000000000000..f313de44bb273 --- /dev/null +++ b/tests/ui/single_range_in_vec_init.new_range.stderr @@ -0,0 +1,200 @@ +error: an array of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:30:5 + | +LL | [0..200]; + | ^^^^^^^^ + | + = note: `-D clippy::single-range-in-vec-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_range_in_vec_init)]` +help: if you wanted a `Vec` that contains the entire range, try + | +LL - [0..200]; +LL + std::vec::Vec::::from_iter(0..200); + | +help: if you wanted an array of len 200, try + | +LL - [0..200]; +LL + [0; 200]; + | + +error: a `Vec` of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:32:5 + | +LL | vec![0..200]; + | ^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - vec![0..200]; +LL + std::vec::Vec::::from_iter(0..200); + | +help: if you wanted a `Vec` of len 200, try + | +LL - vec![0..200]; +LL + vec![0; 200]; + | + +error: an array of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:34:5 + | +LL | [0u8..200]; + | ^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - [0u8..200]; +LL + std::vec::Vec::::from_iter(0u8..200); + | +help: if you wanted an array of len 200, try + | +LL - [0u8..200]; +LL + [0u8; 200]; + | + +error: an array of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:36:5 + | +LL | [0usize..200]; + | ^^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - [0usize..200]; +LL + std::vec::Vec::::from_iter(0usize..200); + | +help: if you wanted an array of len 200, try + | +LL - [0usize..200]; +LL + [0usize; 200]; + | + +error: an array of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:38:5 + | +LL | [0..200usize]; + | ^^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - [0..200usize]; +LL + std::vec::Vec::::from_iter(0..200usize); + | +help: if you wanted an array of len 200usize, try + | +LL - [0..200usize]; +LL + [0; 200usize]; + | + +error: a `Vec` of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:40:5 + | +LL | vec![0u8..200]; + | ^^^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - vec![0u8..200]; +LL + std::vec::Vec::::from_iter(0u8..200); + | +help: if you wanted a `Vec` of len 200, try + | +LL - vec![0u8..200]; +LL + vec![0u8; 200]; + | + +error: a `Vec` of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:42:5 + | +LL | vec![0usize..200]; + | ^^^^^^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - vec![0usize..200]; +LL + std::vec::Vec::::from_iter(0usize..200); + | +help: if you wanted a `Vec` of len 200, try + | +LL - vec![0usize..200]; +LL + vec![0usize; 200]; + | + +error: a `Vec` of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:44:5 + | +LL | vec![0..200usize]; + | ^^^^^^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - vec![0..200usize]; +LL + std::vec::Vec::::from_iter(0..200usize); + | +help: if you wanted a `Vec` of len 200usize, try + | +LL - vec![0..200usize]; +LL + vec![0; 200usize]; + | + +error: an array of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:47:5 + | +LL | [0..200isize]; + | ^^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - [0..200isize]; +LL + std::vec::Vec::::from_iter(0..200isize); + | + +error: a `Vec` of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:49:5 + | +LL | vec![0..200isize]; + | ^^^^^^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - vec![0..200isize]; +LL + std::vec::Vec::::from_iter(0..200isize); + | + +error: a `Vec` of `Range` that is only one element + --> tests/ui/single_range_in_vec_init.rs:88:17 + | +LL | let input = vec![0..as_i32!(10)]; + | ^^^^^^^^^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - let input = vec![0..as_i32!(10)]; +LL + let input = std::vec::Vec::::from_iter(0..as_i32!(10)); + | + +error: an array of `RangeInclusive` that is only one element + --> tests/ui/single_range_in_vec_init.rs:93:5 + | +LL | [0..=10]; + | ^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - [0..=10]; +LL + std::vec::Vec::::from_iter(0..=10); + | + +error: a `Vec` of `RangeInclusive` that is only one element + --> tests/ui/single_range_in_vec_init.rs:95:5 + | +LL | vec![0..=10]; + | ^^^^^^^^^^^^ + | +help: if you wanted a `Vec` that contains the entire range, try + | +LL - vec![0..=10]; +LL + std::vec::Vec::::from_iter(0..=10); + | + +error: aborting due to 13 previous errors + diff --git a/tests/ui/single_range_in_vec_init.1.fixed b/tests/ui/single_range_in_vec_init.old_range.1.fixed similarity index 90% rename from tests/ui/single_range_in_vec_init.1.fixed rename to tests/ui/single_range_in_vec_init.old_range.1.fixed index e0c1dba073d86..2e082cb7d7a90 100644 --- a/tests/ui/single_range_in_vec_init.1.fixed +++ b/tests/ui/single_range_in_vec_init.old_range.1.fixed @@ -1,4 +1,10 @@ //@aux-build:proc_macros.rs +//@revisions: old_range new_range +//@[new_range] compile-flags: --cfg=new_range + +// When feature(new_range) stabilizes, this should be converted to testing +// old and new editions instead. +#![cfg_attr(new_range, feature(new_range))] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] diff --git a/tests/ui/single_range_in_vec_init.2.fixed b/tests/ui/single_range_in_vec_init.old_range.2.fixed similarity index 89% rename from tests/ui/single_range_in_vec_init.2.fixed rename to tests/ui/single_range_in_vec_init.old_range.2.fixed index 5784702661926..ab297ccfa819f 100644 --- a/tests/ui/single_range_in_vec_init.2.fixed +++ b/tests/ui/single_range_in_vec_init.old_range.2.fixed @@ -1,4 +1,10 @@ //@aux-build:proc_macros.rs +//@revisions: old_range new_range +//@[new_range] compile-flags: --cfg=new_range + +// When feature(new_range) stabilizes, this should be converted to testing +// old and new editions instead. +#![cfg_attr(new_range, feature(new_range))] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] diff --git a/tests/ui/single_range_in_vec_init.stderr b/tests/ui/single_range_in_vec_init.old_range.stderr similarity index 93% rename from tests/ui/single_range_in_vec_init.stderr rename to tests/ui/single_range_in_vec_init.old_range.stderr index 1fec5119d8155..2700b1dd30e45 100644 --- a/tests/ui/single_range_in_vec_init.stderr +++ b/tests/ui/single_range_in_vec_init.old_range.stderr @@ -1,5 +1,5 @@ error: an array of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:24:5 + --> tests/ui/single_range_in_vec_init.rs:30:5 | LL | [0..200]; | ^^^^^^^^ @@ -18,7 +18,7 @@ LL + [0; 200]; | error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:26:5 + --> tests/ui/single_range_in_vec_init.rs:32:5 | LL | vec![0..200]; | ^^^^^^^^^^^^ @@ -35,7 +35,7 @@ LL + vec![0; 200]; | error: an array of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:28:5 + --> tests/ui/single_range_in_vec_init.rs:34:5 | LL | [0u8..200]; | ^^^^^^^^^^ @@ -52,7 +52,7 @@ LL + [0u8; 200]; | error: an array of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:30:5 + --> tests/ui/single_range_in_vec_init.rs:36:5 | LL | [0usize..200]; | ^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL + [0usize; 200]; | error: an array of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:32:5 + --> tests/ui/single_range_in_vec_init.rs:38:5 | LL | [0..200usize]; | ^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL + [0; 200usize]; | error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:34:5 + --> tests/ui/single_range_in_vec_init.rs:40:5 | LL | vec![0u8..200]; | ^^^^^^^^^^^^^^ @@ -103,7 +103,7 @@ LL + vec![0u8; 200]; | error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:36:5 + --> tests/ui/single_range_in_vec_init.rs:42:5 | LL | vec![0usize..200]; | ^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL + vec![0usize; 200]; | error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:38:5 + --> tests/ui/single_range_in_vec_init.rs:44:5 | LL | vec![0..200usize]; | ^^^^^^^^^^^^^^^^^ @@ -137,7 +137,7 @@ LL + vec![0; 200usize]; | error: an array of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:41:5 + --> tests/ui/single_range_in_vec_init.rs:47:5 | LL | [0..200isize]; | ^^^^^^^^^^^^^ @@ -149,7 +149,7 @@ LL + (0..200isize).collect::>(); | error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:43:5 + --> tests/ui/single_range_in_vec_init.rs:49:5 | LL | vec![0..200isize]; | ^^^^^^^^^^^^^^^^^ @@ -161,7 +161,7 @@ LL + (0..200isize).collect::>(); | error: a `Vec` of `Range` that is only one element - --> tests/ui/single_range_in_vec_init.rs:82:17 + --> tests/ui/single_range_in_vec_init.rs:88:17 | LL | let input = vec![0..as_i32!(10)]; | ^^^^^^^^^^^^^^^^^^^^ @@ -173,7 +173,7 @@ LL + let input = (0..as_i32!(10)).collect::>(); | error: an array of `RangeInclusive` that is only one element - --> tests/ui/single_range_in_vec_init.rs:87:5 + --> tests/ui/single_range_in_vec_init.rs:93:5 | LL | [0..=10]; | ^^^^^^^^ @@ -185,7 +185,7 @@ LL + (0..=10).collect::>(); | error: a `Vec` of `RangeInclusive` that is only one element - --> tests/ui/single_range_in_vec_init.rs:89:5 + --> tests/ui/single_range_in_vec_init.rs:95:5 | LL | vec![0..=10]; | ^^^^^^^^^^^^ diff --git a/tests/ui/single_range_in_vec_init.rs b/tests/ui/single_range_in_vec_init.rs index 3ff07c386d218..8fdeac1fc9a0d 100644 --- a/tests/ui/single_range_in_vec_init.rs +++ b/tests/ui/single_range_in_vec_init.rs @@ -1,4 +1,10 @@ //@aux-build:proc_macros.rs +//@revisions: old_range new_range +//@[new_range] compile-flags: --cfg=new_range + +// When feature(new_range) stabilizes, this should be converted to testing +// old and new editions instead. +#![cfg_attr(new_range, feature(new_range))] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] diff --git a/tests/ui/strlen_on_c_strings.fixed b/tests/ui/strlen_on_c_strings.fixed index 6604da70874d9..0cbf7cf76e852 100644 --- a/tests/ui/strlen_on_c_strings.fixed +++ b/tests/ui/strlen_on_c_strings.fixed @@ -18,21 +18,33 @@ fn main() { let _ = cstr.count_bytes(); //~^ ERROR: using `libc::strlen` on a `CStr` value + let _ = unsafe { + let x = 1; + cstr.count_bytes() + //~^ ERROR: using `libc::strlen` on a `CStr` value + }; + let pcstr: *const &CStr = &cstr; - let _ = unsafe { (*pcstr).count_bytes() }; - //~^ ERROR: using `libc::strlen` on a `CStr` value + let _ = unsafe { + (*pcstr).count_bytes() + //~^ ERROR: using `libc::strlen` on a `CStr` value + }; unsafe fn unsafe_identity(x: T) -> T { x } - let _ = unsafe { unsafe_identity(cstr).count_bytes() }; - //~^ ERROR: using `libc::strlen` on a `CStr` value + let _ = unsafe { + unsafe_identity(cstr).count_bytes() + //~^ ERROR: using `libc::strlen` on a `CStr` value + }; let _ = unsafe { unsafe_identity(cstr) }.count_bytes(); //~^ ERROR: using `libc::strlen` on a `CStr` value let f: unsafe fn(_) -> _ = unsafe_identity; - let _ = unsafe { f(cstr).count_bytes() }; - //~^ ERROR: using `libc::strlen` on a `CStr` value + let _ = unsafe { + f(cstr).count_bytes() + //~^ ERROR: using `libc::strlen` on a `CStr` value + }; } // make sure we lint types that _adjust_ to `CStr` diff --git a/tests/ui/strlen_on_c_strings.rs b/tests/ui/strlen_on_c_strings.rs index 11fbdf5850643..a4512553da5b1 100644 --- a/tests/ui/strlen_on_c_strings.rs +++ b/tests/ui/strlen_on_c_strings.rs @@ -18,21 +18,33 @@ fn main() { let _ = unsafe { strlen(cstr.as_ptr()) }; //~^ ERROR: using `libc::strlen` on a `CStr` value + let _ = unsafe { + let x = 1; + strlen(cstr.as_ptr()) + //~^ ERROR: using `libc::strlen` on a `CStr` value + }; + let pcstr: *const &CStr = &cstr; - let _ = unsafe { strlen((*pcstr).as_ptr()) }; - //~^ ERROR: using `libc::strlen` on a `CStr` value + let _ = unsafe { + strlen((*pcstr).as_ptr()) + //~^ ERROR: using `libc::strlen` on a `CStr` value + }; unsafe fn unsafe_identity(x: T) -> T { x } - let _ = unsafe { strlen(unsafe_identity(cstr).as_ptr()) }; - //~^ ERROR: using `libc::strlen` on a `CStr` value + let _ = unsafe { + strlen(unsafe_identity(cstr).as_ptr()) + //~^ ERROR: using `libc::strlen` on a `CStr` value + }; let _ = unsafe { strlen(unsafe { unsafe_identity(cstr) }.as_ptr()) }; //~^ ERROR: using `libc::strlen` on a `CStr` value let f: unsafe fn(_) -> _ = unsafe_identity; - let _ = unsafe { strlen(f(cstr).as_ptr()) }; - //~^ ERROR: using `libc::strlen` on a `CStr` value + let _ = unsafe { + strlen(f(cstr).as_ptr()) + //~^ ERROR: using `libc::strlen` on a `CStr` value + }; } // make sure we lint types that _adjust_ to `CStr` diff --git a/tests/ui/strlen_on_c_strings.stderr b/tests/ui/strlen_on_c_strings.stderr index 1f1b5ccdb0ef4..ddd6e64e77f77 100644 --- a/tests/ui/strlen_on_c_strings.stderr +++ b/tests/ui/strlen_on_c_strings.stderr @@ -20,70 +20,76 @@ LL | let _ = unsafe { strlen(cstr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.count_bytes()` error: using `libc::strlen` on a `CStr` value - --> tests/ui/strlen_on_c_strings.rs:22:22 + --> tests/ui/strlen_on_c_strings.rs:23:9 | -LL | let _ = unsafe { strlen((*pcstr).as_ptr()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(*pcstr).count_bytes()` +LL | strlen(cstr.as_ptr()) + | ^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.count_bytes()` error: using `libc::strlen` on a `CStr` value - --> tests/ui/strlen_on_c_strings.rs:28:22 + --> tests/ui/strlen_on_c_strings.rs:29:9 | -LL | let _ = unsafe { strlen(unsafe_identity(cstr).as_ptr()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `unsafe_identity(cstr).count_bytes()` +LL | strlen((*pcstr).as_ptr()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(*pcstr).count_bytes()` error: using `libc::strlen` on a `CStr` value - --> tests/ui/strlen_on_c_strings.rs:30:13 + --> tests/ui/strlen_on_c_strings.rs:37:9 + | +LL | strlen(unsafe_identity(cstr).as_ptr()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `unsafe_identity(cstr).count_bytes()` + +error: using `libc::strlen` on a `CStr` value + --> tests/ui/strlen_on_c_strings.rs:40:13 | LL | let _ = unsafe { strlen(unsafe { unsafe_identity(cstr) }.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `unsafe { unsafe_identity(cstr) }.count_bytes()` error: using `libc::strlen` on a `CStr` value - --> tests/ui/strlen_on_c_strings.rs:34:22 + --> tests/ui/strlen_on_c_strings.rs:45:9 | -LL | let _ = unsafe { strlen(f(cstr).as_ptr()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `f(cstr).count_bytes()` +LL | strlen(f(cstr).as_ptr()) + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `f(cstr).count_bytes()` error: using `libc::strlen` on a type that dereferences to `CStr` - --> tests/ui/strlen_on_c_strings.rs:40:13 + --> tests/ui/strlen_on_c_strings.rs:52:13 | LL | let _ = unsafe { libc::strlen(box_cstring.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `box_cstring.count_bytes()` error: using `libc::strlen` on a type that dereferences to `CStr` - --> tests/ui/strlen_on_c_strings.rs:42:13 + --> tests/ui/strlen_on_c_strings.rs:54:13 | LL | let _ = unsafe { libc::strlen(box_cstr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `box_cstr.count_bytes()` error: using `libc::strlen` on a type that dereferences to `CStr` - --> tests/ui/strlen_on_c_strings.rs:44:13 + --> tests/ui/strlen_on_c_strings.rs:56:13 | LL | let _ = unsafe { libc::strlen(arc_cstring.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `arc_cstring.count_bytes()` error: using `libc::strlen` on a `CStr` value - --> tests/ui/strlen_on_c_strings.rs:51:13 + --> tests/ui/strlen_on_c_strings.rs:63:13 | LL | let _ = unsafe { libc::strlen(cstr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.to_bytes().len()` error: using `libc::strlen` on a `CString` value - --> tests/ui/strlen_on_c_strings.rs:55:13 + --> tests/ui/strlen_on_c_strings.rs:67:13 | LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstring.to_bytes().len()` error: using `libc::strlen` on a `CStr` value - --> tests/ui/strlen_on_c_strings.rs:62:13 + --> tests/ui/strlen_on_c_strings.rs:74:13 | LL | let _ = unsafe { libc::strlen(cstr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstr.count_bytes()` error: using `libc::strlen` on a `CString` value - --> tests/ui/strlen_on_c_strings.rs:66:13 + --> tests/ui/strlen_on_c_strings.rs:78:13 | LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `cstring.count_bytes()` -error: aborting due to 14 previous errors +error: aborting due to 15 previous errors diff --git a/tests/ui/suspicious_operation_groupings.fixed b/tests/ui/suspicious_operation_groupings.fixed index fa680e537d305..faaae77b87f89 100644 --- a/tests/ui/suspicious_operation_groupings.fixed +++ b/tests/ui/suspicious_operation_groupings.fixed @@ -1,5 +1,3 @@ -//@compile-flags: -Zdeduplicate-diagnostics=yes - #![warn(clippy::suspicious_operation_groupings)] #![allow(dead_code, unused_parens, clippy::eq_op, clippy::manual_midpoint)] @@ -85,7 +83,6 @@ fn odd_number_of_pairs(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s2.b + s1.c * s2.c //~^ suspicious_operation_groupings - //~| suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_left(s1: &S, s2: &S) -> i32 { @@ -148,7 +145,6 @@ fn all_parens_balanced_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.c) + (s1.d * s2.d))) //~^ suspicious_operation_groupings - //~| suspicious_operation_groupings } fn all_parens_left_tree(s1: &S, s2: &S) -> i32 { diff --git a/tests/ui/suspicious_operation_groupings.rs b/tests/ui/suspicious_operation_groupings.rs index 4ffee640e8bda..cd660b55ca85e 100644 --- a/tests/ui/suspicious_operation_groupings.rs +++ b/tests/ui/suspicious_operation_groupings.rs @@ -1,5 +1,3 @@ -//@compile-flags: -Zdeduplicate-diagnostics=yes - #![warn(clippy::suspicious_operation_groupings)] #![allow(dead_code, unused_parens, clippy::eq_op, clippy::manual_midpoint)] @@ -85,7 +83,6 @@ fn odd_number_of_pairs(s1: &S, s2: &S) -> i32 { // There's no `s2.b` s1.a * s2.a + s1.b * s2.c + s1.c * s2.c //~^ suspicious_operation_groupings - //~| suspicious_operation_groupings } fn not_caught_by_eq_op_middle_change_left(s1: &S, s2: &S) -> i32 { @@ -148,7 +145,6 @@ fn all_parens_balanced_tree(s1: &S, s2: &S) -> i32 { // There's no `s2.c` (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) //~^ suspicious_operation_groupings - //~| suspicious_operation_groupings } fn all_parens_left_tree(s1: &S, s2: &S) -> i32 { diff --git a/tests/ui/suspicious_operation_groupings.stderr b/tests/ui/suspicious_operation_groupings.stderr index b640b2041cd3b..0231dbbbb2d13 100644 --- a/tests/ui/suspicious_operation_groupings.stderr +++ b/tests/ui/suspicious_operation_groupings.stderr @@ -1,5 +1,5 @@ error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:17:9 + --> tests/ui/suspicious_operation_groupings.rs:15:9 | LL | self.x == other.y && self.y == other.y && self.z == other.z | ^^^^^^^^^^^^^^^^^ help: did you mean: `self.x == other.x` @@ -8,154 +8,142 @@ LL | self.x == other.y && self.y == other.y && self.z == other.z = help: to override `-D warnings` add `#[allow(clippy::suspicious_operation_groupings)]` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:31:20 + --> tests/ui/suspicious_operation_groupings.rs:29:20 | LL | s1.a < s2.a && s1.a < s2.b | ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:80:33 + --> tests/ui/suspicious_operation_groupings.rs:78:33 | LL | s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:86:19 + --> tests/ui/suspicious_operation_groupings.rs:84:19 | LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:86:19 - | -LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c - | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` - -error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:93:19 + --> tests/ui/suspicious_operation_groupings.rs:90:19 | LL | s1.a * s2.a + s2.b * s2.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:99:19 + --> tests/ui/suspicious_operation_groupings.rs:96:19 | LL | s1.a * s2.a + s1.b * s1.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:105:5 + --> tests/ui/suspicious_operation_groupings.rs:102:5 | LL | s1.a * s1.a + s1.b * s2.b + s1.c * s2.c | ^^^^^^^^^^^ help: did you mean: `s1.a * s2.a` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:111:33 + --> tests/ui/suspicious_operation_groupings.rs:108:33 | LL | s1.a * s2.a + s1.b * s2.b + s1.c * s1.c | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:125:20 + --> tests/ui/suspicious_operation_groupings.rs:122:20 | LL | (s1.a * s2.a + s1.b * s1.b) | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:131:34 + --> tests/ui/suspicious_operation_groupings.rs:128:34 | LL | (s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:137:38 + --> tests/ui/suspicious_operation_groupings.rs:134:38 | LL | (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:143:39 + --> tests/ui/suspicious_operation_groupings.rs:140:39 | LL | ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:149:42 - | -LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) - | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` - -error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:149:42 + --> tests/ui/suspicious_operation_groupings.rs:146:42 | LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:156:40 + --> tests/ui/suspicious_operation_groupings.rs:152:40 | LL | (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b)) + (s1.d * s2.d)) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:162:40 + --> tests/ui/suspicious_operation_groupings.rs:158:40 | LL | ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d))) | ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:168:20 + --> tests/ui/suspicious_operation_groupings.rs:164:20 | LL | (s1.a * s2.a + s2.b * s2.b) / 2 | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:174:35 + --> tests/ui/suspicious_operation_groupings.rs:170:35 | LL | i32::swap_bytes(s1.a * s2.a + s2.b * s2.b) | ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:180:29 + --> tests/ui/suspicious_operation_groupings.rs:176:29 | LL | s1.a > 0 && s1.b > 0 && s1.d == s2.c && s1.d == s2.d | ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:186:17 + --> tests/ui/suspicious_operation_groupings.rs:182:17 | LL | s1.a > 0 && s1.d == s2.c && s1.b > 0 && s1.d == s2.d | ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:196:77 + --> tests/ui/suspicious_operation_groupings.rs:192:77 | LL | (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.1).0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `(n1.inner.2).0 == (n2.inner.2).0` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:211:25 + --> tests/ui/suspicious_operation_groupings.rs:207:25 | LL | s1.a <= s2.a && s1.a <= s2.b | ^^^^^^^^^^^^ help: did you mean: `s1.b <= s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:218:23 + --> tests/ui/suspicious_operation_groupings.rs:214:23 | LL | if s1.a < s2.a && s1.a < s2.b { | ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:226:48 + --> tests/ui/suspicious_operation_groupings.rs:222:48 | LL | -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.b) + -(-s1.d * -s2.d))) | ^^^^^^^^^^^^^ help: did you mean: `-s1.c * -s2.c` error: this sequence of operators looks suspiciously like a bug - --> tests/ui/suspicious_operation_groupings.rs:232:27 + --> tests/ui/suspicious_operation_groupings.rs:228:27 | LL | -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a }) | ^^^^^^^^^^^^^ help: did you mean: `-s1.b < -s2.b` -error: aborting due to 26 previous errors +error: aborting due to 24 previous errors diff --git a/tests/ui/tuple_array_conversions.rs b/tests/ui/tuple_array_conversions.rs index 17e6a252b2669..599019dca031d 100644 --- a/tests/ui/tuple_array_conversions.rs +++ b/tests/ui/tuple_array_conversions.rs @@ -13,6 +13,7 @@ fn main() { //~^ tuple_array_conversions let x = &[1, 2]; let x = (x[0], x[1]); + //~^ tuple_array_conversions let t1: &[(u32, u32)] = &[(1, 2), (3, 4)]; let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect(); @@ -115,6 +116,7 @@ fn msrv_juust_right() { //~^ tuple_array_conversions let x = &[1, 2]; let x = (x[0], x[1]); + //~^ tuple_array_conversions } fn issue16192() { diff --git a/tests/ui/tuple_array_conversions.stderr b/tests/ui/tuple_array_conversions.stderr index 4c15769b74875..212936b8bdd7f 100644 --- a/tests/ui/tuple_array_conversions.stderr +++ b/tests/ui/tuple_array_conversions.stderr @@ -16,8 +16,16 @@ LL | let x = [x.0, x.1]; | = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed +error: it looks like you're trying to convert an array to a tuple + --> tests/ui/tuple_array_conversions.rs:15:13 + | +LL | let x = (x[0], x[1]); + | ^^^^^^^^^^^^ + | + = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed + error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:18:53 + --> tests/ui/tuple_array_conversions.rs:19:53 | LL | let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect(); | ^^^^^^ @@ -25,7 +33,7 @@ LL | let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect(); = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:20:38 + --> tests/ui/tuple_array_conversions.rs:21:38 | LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); | ^^^^^^ @@ -33,7 +41,7 @@ LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> tests/ui/tuple_array_conversions.rs:22:55 + --> tests/ui/tuple_array_conversions.rs:23:55 | LL | let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect(); | ^^^^^^ @@ -41,7 +49,7 @@ LL | let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect(); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:24:38 + --> tests/ui/tuple_array_conversions.rs:25:38 | LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); | ^^^^^^ @@ -49,7 +57,7 @@ LL | t1.iter().for_each(|&(a, b)| _ = [a, b]); = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:63:22 + --> tests/ui/tuple_array_conversions.rs:64:22 | LL | let _: &[f64] = &[a, b]; | ^^^^^^ @@ -57,7 +65,7 @@ LL | let _: &[f64] = &[a, b]; = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> tests/ui/tuple_array_conversions.rs:67:5 + --> tests/ui/tuple_array_conversions.rs:68:5 | LL | (src, dest); | ^^^^^^^^^^^ @@ -65,7 +73,7 @@ LL | (src, dest); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> tests/ui/tuple_array_conversions.rs:112:13 + --> tests/ui/tuple_array_conversions.rs:113:13 | LL | let x = (x[0], x[1]); | ^^^^^^^^^^^^ @@ -73,7 +81,7 @@ LL | let x = (x[0], x[1]); = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed error: it looks like you're trying to convert a tuple to an array - --> tests/ui/tuple_array_conversions.rs:114:13 + --> tests/ui/tuple_array_conversions.rs:115:13 | LL | let x = [x.0, x.1]; | ^^^^^^^^^^ @@ -81,12 +89,20 @@ LL | let x = [x.0, x.1]; = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed error: it looks like you're trying to convert an array to a tuple - --> tests/ui/tuple_array_conversions.rs:139:18 + --> tests/ui/tuple_array_conversions.rs:118:13 + | +LL | let x = (x[0], x[1]); + | ^^^^^^^^^^^^ + | + = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed + +error: it looks like you're trying to convert an array to a tuple + --> tests/ui/tuple_array_conversions.rs:141:18 | LL | do_something((a, b)); | ^^^^^^ | = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed -error: aborting due to 11 previous errors +error: aborting due to 13 previous errors diff --git a/tests/ui/unicode.fixed b/tests/ui/unicode.fixed index 8fd25d1b48f5f..0a49b17005828 100644 --- a/tests/ui/unicode.fixed +++ b/tests/ui/unicode.fixed @@ -60,4 +60,39 @@ mod non_ascii_literal { } } +mod ascii_macro_with_non_ascii_value { + // The source is pure ASCII, but the value contains non-ASCII, invisible, and + // non-NFC characters. The lints check the source snippet, not the value, so + // none of them may fire here. + #![deny(clippy::invisible_characters, clippy::non_ascii_literal, clippy::unicode_not_nfc)] + + macro_rules! non_ascii_value { + () => { + "\u{00E9}\u{200B}a\u{0300}" + }; + } + + fn no_lint() { + let _ = non_ascii_value!(); + } +} + +mod ascii_value_from_non_ascii_snippet { + // The reverse: `file!()` produces an ASCII value (the file path), but the + // literal's span covers the whole macro invocation, so the snippet is + // non-ASCII and the lint must fire. Checking the value would miss it. + #![deny(clippy::non_ascii_literal)] + + macro_rules! with_location { + ($($arg:tt)*) => { + let _ = file!(); + }; + } + + fn lint() { + with_location!("h\u{e9}llo"); + //~^ non_ascii_literal + } +} + fn main() {} diff --git a/tests/ui/unicode.rs b/tests/ui/unicode.rs index 6447a704a3566..f1a1ab290aecc 100644 --- a/tests/ui/unicode.rs +++ b/tests/ui/unicode.rs @@ -60,4 +60,39 @@ mod non_ascii_literal { } } +mod ascii_macro_with_non_ascii_value { + // The source is pure ASCII, but the value contains non-ASCII, invisible, and + // non-NFC characters. The lints check the source snippet, not the value, so + // none of them may fire here. + #![deny(clippy::invisible_characters, clippy::non_ascii_literal, clippy::unicode_not_nfc)] + + macro_rules! non_ascii_value { + () => { + "\u{00E9}\u{200B}a\u{0300}" + }; + } + + fn no_lint() { + let _ = non_ascii_value!(); + } +} + +mod ascii_value_from_non_ascii_snippet { + // The reverse: `file!()` produces an ASCII value (the file path), but the + // literal's span covers the whole macro invocation, so the snippet is + // non-ASCII and the lint must fire. Checking the value would miss it. + #![deny(clippy::non_ascii_literal)] + + macro_rules! with_location { + ($($arg:tt)*) => { + let _ = file!(); + }; + } + + fn lint() { + with_location!("héllo"); + //~^ non_ascii_literal + } +} + fn main() {} diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index c761ec89602fc..32b0933913008 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -64,5 +64,17 @@ note: the lint level is defined here LL | #![deny(clippy::non_ascii_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 8 previous errors +error: literal non-ASCII character detected + --> tests/ui/unicode.rs:93:9 + | +LL | with_location!("héllo"); + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `with_location!("h\u{e9}llo")` + | +note: the lint level is defined here + --> tests/ui/unicode.rs:84:13 + | +LL | #![deny(clippy::non_ascii_literal)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 9 previous errors diff --git a/tests/ui/unnecessary_operation.fixed b/tests/ui/unnecessary_operation.fixed index db5409bc491e3..2b447e5c4a36d 100644 --- a/tests/ui/unnecessary_operation.fixed +++ b/tests/ui/unnecessary_operation.fixed @@ -157,3 +157,22 @@ fn issue15173_original(handler: impl FnOnce() -> MsU + Clone + 'static) { None }) as Box Option>; } + +mod issue12898 { + use futures::future; + async fn forever() -> ! { + // pretend there is an infinite loop here... + future::pending().await + } + pub async fn definitely_forever() -> ! { + future::join(forever(), forever()).await.0; + } + + pub async fn no_false_negative() -> ! { + fn never() -> ! { + unimplemented!() + } + never(); + //~^^^ unnecessary_operation + } +} diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs index a3e6c6288ada5..def14469c9bdc 100644 --- a/tests/ui/unnecessary_operation.rs +++ b/tests/ui/unnecessary_operation.rs @@ -163,3 +163,24 @@ fn issue15173_original(handler: impl FnOnce() -> MsU + Clone + 'static) { None }) as Box Option>; } + +mod issue12898 { + use futures::future; + async fn forever() -> ! { + // pretend there is an infinite loop here... + future::pending().await + } + pub async fn definitely_forever() -> ! { + future::join(forever(), forever()).await.0; + } + + pub async fn no_false_negative() -> ! { + fn never() -> ! { + unimplemented!() + } + { + never() + }; + //~^^^ unnecessary_operation + } +} diff --git a/tests/ui/unnecessary_operation.stderr b/tests/ui/unnecessary_operation.stderr index 3439ba2e33e55..55751cb08b136 100644 --- a/tests/ui/unnecessary_operation.stderr +++ b/tests/ui/unnecessary_operation.stderr @@ -127,5 +127,13 @@ error: unnecessary operation LL | [42, 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());` -error: aborting due to 20 previous errors +error: unnecessary operation + --> tests/ui/unnecessary_operation.rs:181:9 + | +LL | / { +LL | | never() +LL | | }; + | |__________^ help: statement can be reduced to: `never();` + +error: aborting due to 21 previous errors diff --git a/tests/ui/unnecessary_unwrap_unchecked.fixed b/tests/ui/unnecessary_unwrap_unchecked.fixed index 274bb7a00bfb0..fedd4327a4a3a 100644 --- a/tests/ui/unnecessary_unwrap_unchecked.fixed +++ b/tests/ui/unnecessary_unwrap_unchecked.fixed @@ -102,3 +102,72 @@ fn main() { unsafe { std::str::from_utf8(&[]).unwrap_unchecked() }; } } + +mod issue17349 { + pub enum Foo { + A, + B, + C, + } + + impl Foo { + pub const fn from_u8(value: u8) -> Option { + match value { + 0 => Some(Self::A), + 1 => Some(Self::B), + 2 => Some(Self::C), + _ => None, + } + } + + /// # Safety + /// + /// The value must be either 0, 1 or 2 + pub const unsafe fn from_u8_unchecked(value: u8) -> Self { + // Don't lint from inside the `_unchecked` associated function itself + unsafe { Self::from_u8(value).unwrap_unchecked() } + } + + pub const fn to_bool(&self) -> Option { + match self { + Self::A => Some(false), + Self::B => Some(true), + Self::C => None, + } + } + + /// # Safety + /// + /// The value must be either `Self::A` or `Self::B` + pub const unsafe fn to_bool_unchecked(&self) -> bool { + // Don't lint from inside the `_unchecked` method itself + unsafe { self.to_bool().unwrap_unchecked() } + } + } + + pub const fn from_u8(value: u8) -> Option { + Foo::from_u8(value) + } + + /// # Safety + /// + /// The value must be either 0, 1 or 2 + pub const unsafe fn from_u8_unchecked(value: u8) -> Foo { + // Don't lint from inside the `_unchecked` function itself + unsafe { from_u8(value).unwrap_unchecked() } + } + + pub fn from_u16(value: u16) -> Option { + Foo::from_u8(u8::try_from(value).ok()?) + } + + /// # Safety + /// + /// The value must be either 0, 1 or 2 + pub unsafe fn from_u16_unchecked(value: u16) -> Foo { + // Don't lint from inside the `_unchecked` function itself + // even in the presence of intermediate bodies. + let cl = || unsafe { from_u16(value).unwrap_unchecked() }; + cl() + } +} diff --git a/tests/ui/unnecessary_unwrap_unchecked.rs b/tests/ui/unnecessary_unwrap_unchecked.rs index 006a541365a58..b2249c73516c1 100644 --- a/tests/ui/unnecessary_unwrap_unchecked.rs +++ b/tests/ui/unnecessary_unwrap_unchecked.rs @@ -102,3 +102,72 @@ fn main() { unsafe { std::str::from_utf8(&[]).unwrap_unchecked() }; } } + +mod issue17349 { + pub enum Foo { + A, + B, + C, + } + + impl Foo { + pub const fn from_u8(value: u8) -> Option { + match value { + 0 => Some(Self::A), + 1 => Some(Self::B), + 2 => Some(Self::C), + _ => None, + } + } + + /// # Safety + /// + /// The value must be either 0, 1 or 2 + pub const unsafe fn from_u8_unchecked(value: u8) -> Self { + // Don't lint from inside the `_unchecked` associated function itself + unsafe { Self::from_u8(value).unwrap_unchecked() } + } + + pub const fn to_bool(&self) -> Option { + match self { + Self::A => Some(false), + Self::B => Some(true), + Self::C => None, + } + } + + /// # Safety + /// + /// The value must be either `Self::A` or `Self::B` + pub const unsafe fn to_bool_unchecked(&self) -> bool { + // Don't lint from inside the `_unchecked` method itself + unsafe { self.to_bool().unwrap_unchecked() } + } + } + + pub const fn from_u8(value: u8) -> Option { + Foo::from_u8(value) + } + + /// # Safety + /// + /// The value must be either 0, 1 or 2 + pub const unsafe fn from_u8_unchecked(value: u8) -> Foo { + // Don't lint from inside the `_unchecked` function itself + unsafe { from_u8(value).unwrap_unchecked() } + } + + pub fn from_u16(value: u16) -> Option { + Foo::from_u8(u8::try_from(value).ok()?) + } + + /// # Safety + /// + /// The value must be either 0, 1 or 2 + pub unsafe fn from_u16_unchecked(value: u16) -> Foo { + // Don't lint from inside the `_unchecked` function itself + // even in the presence of intermediate bodies. + let cl = || unsafe { from_u16(value).unwrap_unchecked() }; + cl() + } +} diff --git a/tests/ui/vec_init_then_push.rs b/tests/ui/vec_init_then_push.rs index a32187edfea61..f5b9dae47c759 100644 --- a/tests/ui/vec_init_then_push.rs +++ b/tests/ui/vec_init_then_push.rs @@ -126,3 +126,32 @@ fn f() { v.push((0i32, 0i32)); let y = v[0].0.abs(); } + +macro_rules! make_vec { + ($($e:expr),*) => {{ + let mut temp = Vec::new(); + $(temp.push($e);)* + temp + }}; +} + +macro_rules! push_each { + ($v:ident) => { + $v.push(1); + $v.push(2); + $v.push(3); + $v.push(4); + }; +} + +fn pushes_from_macro() -> Vec { + // no lint: the `Vec` and all the `push`es come from the macro expansion + make_vec![1, 2, 3, 4, 5] +} + +fn local_outside_but_pushes_from_macro() -> Vec { + // no lint: just `push`es came from a macro expansion + let mut v = Vec::new(); + push_each!(v); + v +} diff --git a/triagebot.toml b/triagebot.toml index 13ea2b250758c..f98831b42bfc2 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -99,7 +99,8 @@ users_on_vacation = [ "Alexendoo", "y21", "blyxyas", - "ada4a" + "ada4a", + "dswij" ] [assign.owners] From c49f7ddd42919d1eab9be10855d2e80f2b538f01 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 9 Jul 2026 20:53:18 +0200 Subject: [PATCH 20/63] Set myself on vacation --- triagebot.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/triagebot.toml b/triagebot.toml index 8da713e7eac54..67e9a2270a093 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -100,7 +100,8 @@ users_on_vacation = [ "y21", "blyxyas", "ada4a", - "dswij" + "dswij", + "samueltardieu" ] [assign.owners] From 9d78a79a7d2b641ac42e823c304740e0be6f02dc Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Thu, 9 Jul 2026 16:18:03 -0700 Subject: [PATCH 21/63] book adding_lints.md: update link to msrvs --- book/src/development/adding_lints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/development/adding_lints.md b/book/src/development/adding_lints.md index f28985d375f64..7a96d0631de6a 100644 --- a/book/src/development/adding_lints.md +++ b/book/src/development/adding_lints.md @@ -526,7 +526,7 @@ define_Conf! { } ``` -[`clippy_utils::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_config/msrvs/index.html +[`clippy_utils::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/msrvs/index.html Afterwards update the documentation for the book as described in [Adding configuration to a lint](#adding-configuration-to-a-lint). From f00e53ea21281c7316a8436f74507312f97e8ce3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 7 Jul 2026 10:55:57 +1000 Subject: [PATCH 22/63] Remove `tokens` field from some AST nodes Specifically, from `Block`, `Pat`, `Path`, `Ty`, `Visibility`. This field is usually `None`. It only gets filled in for paths that might later be re-tokenized via `TokenStream::from_ast`, e.g. because of macro or cfg use. All such cases go through a single place: `parse_nonterminal`. This commit changes `parse_nonterminal` to store the non-`None` lazy attr token stream *next* to the node in `ParseNtResult` (using the new `WithTokens` type) instead of *inside* the parsed node. Along with some minor changes to the relevant `HasTokens` and `HasAttrs` impls, this is enough for things to work. These AST nodes all shrink by 8 bytes, as do various other nodes that contain nodes of these types. A guide to the changes: - `compiler/rustc_ast/src/tokenstream.rs` has the new `WithTokens` type. - `compiler/rustc_parse/src/parser/nonterminal.rs`, `compiler/rustc_expand/src/mbe/transcribe.rs` and `compiler/rustc_parse/src/parser/mod.rs` have minor changes due to the changes to `ParseNtResult`. - `compiler/rustc_ast/src/ast_traits.rs` has the `HasTokens`/`HasAttrs` changes. - Everything else is just mechanical changes for the removal of the `tokens` field. --- clippy_lints/src/unnested_or_patterns.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index d1096a02fd634..26b666e58b019 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -382,7 +382,6 @@ fn take_pat(from: &mut Pat) -> Pat { id: DUMMY_NODE_ID, kind: Wild, span: DUMMY_SP, - tokens: None, }; mem::replace(from, dummy) } From edce117faea85e9cb34631bd26f431c5d05b911f Mon Sep 17 00:00:00 2001 From: Valdemar Erk Date: Fri, 6 Jun 2025 14:21:43 +0200 Subject: [PATCH 23/63] add new lints: `rest_pattern_accessible_field` and `unnecessary_rest_pattern` --- CHANGELOG.md | 2 + clippy_lints/src/declared_lints.rs | 2 + clippy_lints/src/lib.rs | 2 + .../src/rest_when_destructuring_struct.rs | 164 ++++++++++++++++++ clippy_utils/src/check_proc_macro.rs | 101 ++++++++++- tests/ui/auxiliary/non-exhaustive-struct.rs | 13 ++ tests/ui/rest_pattern_accessible_field.fixed | 108 ++++++++++++ tests/ui/rest_pattern_accessible_field.rs | 108 ++++++++++++ tests/ui/rest_pattern_accessible_field.stderr | 109 ++++++++++++ tests/ui/unnecessary_rest_pattern.fixed | 90 ++++++++++ tests/ui/unnecessary_rest_pattern.rs | 90 ++++++++++ tests/ui/unnecessary_rest_pattern.stderr | 52 ++++++ 12 files changed, 838 insertions(+), 3 deletions(-) create mode 100644 clippy_lints/src/rest_when_destructuring_struct.rs create mode 100644 tests/ui/auxiliary/non-exhaustive-struct.rs create mode 100644 tests/ui/rest_pattern_accessible_field.fixed create mode 100644 tests/ui/rest_pattern_accessible_field.rs create mode 100644 tests/ui/rest_pattern_accessible_field.stderr create mode 100644 tests/ui/unnecessary_rest_pattern.fixed create mode 100644 tests/ui/unnecessary_rest_pattern.rs create mode 100644 tests/ui/unnecessary_rest_pattern.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index b809638dfcf93..f893f393ed322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7286,6 +7286,7 @@ Released 2018-09-13 [`repr_packed_without_abi`]: https://rust-lang.github.io/rust-clippy/master/index.html#repr_packed_without_abi [`reserve_after_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#reserve_after_initialization [`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs +[`rest_pattern_accessible_field`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pattern_accessible_field [`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used [`result_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_filter_map [`result_large_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err @@ -7451,6 +7452,7 @@ Released 2018-09-13 [`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation [`unnecessary_option_map_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_option_map_or_else [`unnecessary_owned_empty_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_owned_empty_strings +[`unnecessary_rest_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_rest_pattern [`unnecessary_result_map_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_result_map_or_else [`unnecessary_safety_comment`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_comment [`unnecessary_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_doc diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 83ab6e31d2b26..4ca5ea8a062d6 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -684,6 +684,8 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[ crate::repeat_vec_with_capacity::REPEAT_VEC_WITH_CAPACITY_INFO, crate::replace_box::REPLACE_BOX_INFO, crate::reserve_after_initialization::RESERVE_AFTER_INITIALIZATION_INFO, + crate::rest_when_destructuring_struct::REST_PATTERN_ACCESSIBLE_FIELD_INFO, + crate::rest_when_destructuring_struct::UNNECESSARY_REST_PATTERN_INFO, crate::return_self_not_must_use::RETURN_SELF_NOT_MUST_USE_INFO, crate::returns::LET_AND_RETURN_INFO, crate::returns::NEEDLESS_RETURN_INFO, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 974abc30db0fd..f3d3432355a1f 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -326,6 +326,7 @@ mod regex; mod repeat_vec_with_capacity; mod replace_box; mod reserve_after_initialization; +mod rest_when_destructuring_struct; mod return_self_not_must_use; mod returns; mod same_length_and_capacity; @@ -859,6 +860,7 @@ rustc_lint::late_lint_methods!( WithCapacityZero: with_capacity_zero::WithCapacityZero = with_capacity_zero::WithCapacityZero, RefPatterns: ref_patterns::RefPatterns = ref_patterns::RefPatterns, RedundantElse: redundant_else::RedundantElse = redundant_else::RedundantElse, + RestWhenDestructuringStruct: rest_when_destructuring_struct::RestWhenDestructuringStruct = rest_when_destructuring_struct::RestWhenDestructuringStruct, // add late passes here, used by `cargo dev new_lint` ]] ); diff --git a/clippy_lints/src/rest_when_destructuring_struct.rs b/clippy_lints/src/rest_when_destructuring_struct.rs new file mode 100644 index 0000000000000..536d6803bc28d --- /dev/null +++ b/clippy_lints/src/rest_when_destructuring_struct.rs @@ -0,0 +1,164 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::is_from_proc_macro; +use rustc_errors::Applicability; +use rustc_lint::LateLintPass; +use rustc_middle::ty; +use rustc_session::declare_lint_pass; + +use std::fmt::Write as _; + +declare_clippy_lint! { + /// ### What it does + /// Disallow the use of rest patterns for accesible fields + /// + /// ### Why restrict this? + /// It might lead to unhandled fields when the struct changes. + /// + /// ### Example + /// ```no_run + /// struct S { + /// a: u8, + /// b: u8, + /// c: u8, + /// } + /// + /// let s = S { a: 1, b: 2, c: 3 }; + /// + /// let S { a, b, .. } = s; + /// ``` + /// Use instead: + /// ```no_run + /// struct S { + /// a: u8, + /// b: u8, + /// c: u8, + /// } + /// + /// let s = S { a: 1, b: 2, c: 3 }; + /// + /// let S { a, b, c: _ } = s; + /// ``` + #[clippy::version = "1.99.0"] + pub REST_PATTERN_ACCESSIBLE_FIELD, + restriction, + "rest pattern (`..`) used for accessible field" +} + +declare_clippy_lint! { + /// ### What it does + /// Disallow the use of rest patterns that don't capture any fields. + /// + /// ### Why restrict this? + /// It might lead to unhandled fields when the struct changes. + /// + /// ### Example + /// ```no_run + /// struct S { + /// a: u8, + /// b: u8, + /// c: u8, + /// } + /// + /// let s = S { a: 1, b: 2, c: 3 }; + /// + /// let S { a, b, c, .. } = s; + /// ``` + /// Use instead: + /// ```no_run + /// struct S { + /// a: u8, + /// b: u8, + /// c: u8, + /// } + /// + /// let s = S { a: 1, b: 2, c: 3 }; + /// + /// let S { a, b, c } = s; + /// ``` + #[clippy::version = "1.99.0"] + pub UNNECESSARY_REST_PATTERN, + restriction, + "unnecessary rest pattern (`..`) in destructuring expression" +} + +declare_lint_pass!(RestWhenDestructuringStruct => [ + REST_PATTERN_ACCESSIBLE_FIELD, + UNNECESSARY_REST_PATTERN, +]); + +impl<'tcx> LateLintPass<'tcx> for RestWhenDestructuringStruct { + fn check_pat(&mut self, cx: &rustc_lint::LateContext<'tcx>, pat: &'tcx rustc_hir::Pat<'tcx>) { + if let rustc_hir::PatKind::Struct(path, fields, Some(dotdot)) = pat.kind + && let qty = cx.typeck_results().qpath_res(&path, pat.hir_id) + && let ty = cx.typeck_results().pat_ty(pat) + && let ty::Adt(a, _) = ty.kind() + && let Some(vid) = qty.opt_def_id().map(|x| a.variant_index_with_id(x)) + && let Some(variant) = a.variants().get(vid) + { + let mut missing_suggestions = String::new(); + let mut needs_dotdot = variant.field_list_has_applicable_non_exhaustive(); + + for field in &variant.fields { + if field.vis.is_accessible_from(cx.tcx.parent_module(pat.hir_id), cx.tcx) { + if !fields.iter().any(|x| x.ident.name == field.name) { + if !missing_suggestions.is_empty() { + missing_suggestions.push_str(", "); + } + let _ = write!(missing_suggestions, "{}: _", field.name.as_str()); + } + } else { + needs_dotdot = true; + } + } + + // Filter out results from macros + if (missing_suggestions.is_empty() && needs_dotdot) + || pat.span.in_external_macro(cx.tcx.sess.source_map()) + || is_from_proc_macro(cx, pat) + { + return; + } + + if !missing_suggestions.is_empty() { + let suggestion_span = if needs_dotdot { + missing_suggestions.push_str(", "); + dotdot.shrink_to_lo() + } else { + dotdot + }; + + let message = if fields.is_empty() { + "consider explicitly ignoring fields with wildcard patterns (`x: _`)" + } else { + "consider explicitly ignoring remaining fields with wildcard patterns (`x: _`)" + }; + + span_lint_and_then( + cx, + REST_PATTERN_ACCESSIBLE_FIELD, + pat.span, + "struct destructuring with rest (`..`)", + |diag| { + diag.span_suggestion_verbose( + suggestion_span, + message, + &missing_suggestions, + Applicability::MachineApplicable, + ); + }, + ); + } else if !needs_dotdot { + let message = "consider removing the unnecessary rest pattern (`..`)"; + span_lint_and_then( + cx, + UNNECESSARY_REST_PATTERN, + pat.span, + "unnecessary rest pattern (`..`)", + |diag| { + diag.span_suggestion_verbose(dotdot, message, "", Applicability::MachineApplicable); + }, + ); + } + } + } +} diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 7400891f75b58..53a71d4fcbef3 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -16,15 +16,16 @@ use rustc_abi::ExternAbi; use rustc_ast as ast; use rustc_ast::AttrStyle; use rustc_ast::ast::{ - AttrKind, Attribute, GenericArgs, IntTy, LitIntType, LitKind, StrStyle, TraitObjectSyntax, UintTy, + AttrKind, Attribute, BindingMode, GenericArgs, IntTy, LitIntType, LitKind, StrStyle, TraitObjectSyntax, UintTy, }; use rustc_ast::token::CommentKind; use rustc_hir::intravisit::FnKind; use rustc_hir::{ Block, BlockCheckMode, Body, BoundConstness, BoundPolarity, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, FnRetTy, HirId, Impl, ImplItem, ImplItemImplKind, ImplItemKind, IsAuto, Item, ItemKind, Lit, LoopSource, - MatchSource, MutTy, Node, Path, PolyTraitRef, QPath, Safety, TraitBoundModifiers, TraitImplHeader, TraitItem, - TraitItemKind, TraitRef, Ty, TyKind, UnOp, UnsafeSource, Variant, VariantData, YieldSource, + MatchSource, MutTy, Node, PatExpr, PatExprKind, PatKind, Path, PolyTraitRef, QPath, Safety, TraitBoundModifiers, + TraitImplHeader, TraitItem, TraitItemKind, TraitRef, Ty, TyKind, UnOp, UnsafeSource, Variant, VariantData, + YieldSource, }; use rustc_lint::{EarlyContext, LateContext, LintContext}; use rustc_middle::ty::TyCtxt; @@ -589,6 +590,99 @@ fn ident_search_pat(ident: Ident) -> (Pat, Pat) { (Pat::Sym(ident.name), Pat::Sym(ident.name)) } +fn pat_search_pat(tcx: TyCtxt<'_>, pat: &rustc_hir::Pat<'_>) -> (Pat, Pat) { + match pat.kind { + // Tuple patterns cannot show up in proc-macro checks + PatKind::Missing | PatKind::Err(_) | PatKind::Tuple(_, _) => (Pat::Str(""), Pat::Str("")), + PatKind::Wild => (Pat::Sym(kw::Underscore), Pat::Sym(kw::Underscore)), + PatKind::Binding(binding_mode, _, ident, Some(end_pat)) => { + let start = if binding_mode == BindingMode::NONE { + ident_search_pat(ident).0 + } else { + Pat::Str(binding_mode.prefix_str()) + }; + + let (_, end) = pat_search_pat(tcx, end_pat); + (start, end) + }, + PatKind::Binding(binding_mode, _, ident, None) => { + let (s, end) = ident_search_pat(ident); + let start = if binding_mode == BindingMode::NONE { + s + } else { + Pat::Str(binding_mode.prefix_str()) + }; + + (start, end) + }, + PatKind::Struct(path, _, _) => { + let (start, _) = qpath_search_pat(&path); + (start, Pat::Str("}")) + }, + PatKind::TupleStruct(path, _, _) => { + let (start, _) = qpath_search_pat(&path); + // This pattern cannot show up in proc-macro checks + (start, Pat::Str("")) + }, + PatKind::Or(plist) => { + // documented invariant + debug_assert!(plist.len() >= 2); + let (start, _) = pat_search_pat(tcx, plist.first().unwrap()); + let (_, end) = pat_search_pat(tcx, plist.last().unwrap()); + (start, end) + }, + PatKind::Never => (Pat::Str("!"), Pat::Str("")), + PatKind::Box(p) => { + let (_, end) = pat_search_pat(tcx, p); + (Pat::Str("box"), end) + }, + PatKind::Deref(_) => (Pat::Str("deref!"), Pat::Str("")), + PatKind::Ref(p, _, _) => { + let (_, end) = pat_search_pat(tcx, p); + (Pat::Str("&"), end) + }, + PatKind::Expr(expr) => pat_expr_search_pat(expr), + PatKind::Guard(pat, guard) => { + let (start, _) = pat_search_pat(tcx, pat); + let (_, end) = expr_search_pat(tcx, guard); + (start, end) + }, + PatKind::Range(None, None, range) => match range { + rustc_hir::RangeEnd::Included => (Pat::Str("..="), Pat::Str("")), + rustc_hir::RangeEnd::Excluded => (Pat::Str(".."), Pat::Str("")), + }, + PatKind::Range(r_start, r_end, range) => { + let start = match r_start { + Some(e) => pat_expr_search_pat(e).0, + None => match range { + rustc_hir::RangeEnd::Included => Pat::Str("..="), + rustc_hir::RangeEnd::Excluded => Pat::Str(".."), + }, + }; + + let end = match r_end { + Some(e) => pat_expr_search_pat(e).1, + None => match range { + rustc_hir::RangeEnd::Included => Pat::Str("..="), + rustc_hir::RangeEnd::Excluded => Pat::Str(".."), + }, + }; + (start, end) + }, + PatKind::Slice(_, _, _) => (Pat::Str("["), Pat::Str("]")), + } +} + +fn pat_expr_search_pat(expr: &PatExpr<'_>) -> (Pat, Pat) { + match expr.kind { + PatExprKind::Lit { lit, negated } => { + let (start, end) = lit_search_pat(&lit.node); + if negated { (Pat::Str("!"), end) } else { (start, end) } + }, + PatExprKind::Path(path) => qpath_search_pat(&path), + } +} + pub trait WithSearchPat<'cx> { type Context: LintContext; fn search_pat(&self, cx: &Self::Context) -> (Pat, Pat); @@ -618,6 +712,7 @@ impl_with_search_pat!((_cx: LateContext<'tcx>, self: Ident) => ident_search_pat( impl_with_search_pat!((_cx: LateContext<'tcx>, self: Lit) => lit_search_pat(&self.node)); impl_with_search_pat!((_cx: LateContext<'tcx>, self: Path<'_>) => path_search_pat(self)); impl_with_search_pat!((_cx: LateContext<'tcx>, self: PolyTraitRef<'_>) => poly_trait_ref_search_pat(self)); +impl_with_search_pat!((cx: LateContext<'tcx>, self: rustc_hir::Pat<'_>) => pat_search_pat(cx.tcx, self)); impl_with_search_pat!((_cx: EarlyContext<'tcx>, self: Attribute) => attr_search_pat(self)); impl_with_search_pat!((_cx: EarlyContext<'tcx>, self: ast::Ty) => ast_ty_search_pat(self)); diff --git a/tests/ui/auxiliary/non-exhaustive-struct.rs b/tests/ui/auxiliary/non-exhaustive-struct.rs new file mode 100644 index 0000000000000..ed28cc0ebd45a --- /dev/null +++ b/tests/ui/auxiliary/non-exhaustive-struct.rs @@ -0,0 +1,13 @@ +#[non_exhaustive] +#[derive(Default)] +pub struct NonExhaustiveStruct { + pub field1: i32, + pub field2: i32, + _private: i32, +} + +#[non_exhaustive] +#[derive(Default)] +pub struct NonExhaustiveStructNoPrivateFields { + pub field: i32, +} diff --git a/tests/ui/rest_pattern_accessible_field.fixed b/tests/ui/rest_pattern_accessible_field.fixed new file mode 100644 index 0000000000000..d2bc2c1de8ec5 --- /dev/null +++ b/tests/ui/rest_pattern_accessible_field.fixed @@ -0,0 +1,108 @@ +//@aux-build:proc_macros.rs +//@aux-build:non-exhaustive-struct.rs +#![warn(clippy::rest_pattern_accessible_field)] +#![allow(clippy::unneeded_wildcard_pattern)] + +use non_exhaustive_struct::{NonExhaustiveStruct, NonExhaustiveStructNoPrivateFields}; + +struct S { + a: u8, + b: u8, + c: u8, +} + +#[derive(Default)] +#[non_exhaustive] +struct LocalNonExhaustive { + field: i32, +} + +enum E { + A { a1: u8, a2: u8 }, + B { b1: u8, b2: u8 }, + C {}, +} + +mod m { + #[derive(Default)] + pub struct Sm { + pub a: u8, + pub(crate) b: u8, + c: u8, + } +} + +fn main() { + let s = S { a: 1, b: 2, c: 3 }; + + let S { a, b, c: _ } = s; + //~^ rest_pattern_accessible_field + + let S { c, a: _, b: _ } = s; + //~^ rest_pattern_accessible_field + + let S { a, b, c, .. } = s; + + S { a: _, b: _, c: _ } = S { a: 1, b: 2, c: 3 }; + //~^ rest_pattern_accessible_field + + let e = E::A { a1: 1, a2: 2 }; + + match e { + E::A { a1, a2 } => (), + E::B { b1: _, b2: _ } => (), + //~^ rest_pattern_accessible_field + E::C { .. } => (), + } + + match e { + E::A { a1: _, a2: _ } => (), + E::B { b1: _, b2: _ } => (), + //~^ rest_pattern_accessible_field + E::C {} => (), + } + + proc_macros::external! { + let s1 = S { a: 1, b: 2, c: 3 }; + let S { a, b, .. } = s1; + } + + proc_macros::with_span! { + span + let s2 = S { a: 1, b: 2, c: 3 }; + let S { a, b, .. } = s2; + } + + let ne = NonExhaustiveStruct::default(); + let NonExhaustiveStruct { field1: _, field2: _, .. } = ne; + //~^ rest_pattern_accessible_field + + let ne = NonExhaustiveStruct::default(); + let NonExhaustiveStruct { + field1: _, field2: _, .. + } = ne; + + let ne = NonExhaustiveStructNoPrivateFields::default(); + let NonExhaustiveStructNoPrivateFields { field: _, .. } = ne; + //~^ rest_pattern_accessible_field + + let ne = NonExhaustiveStructNoPrivateFields::default(); + let NonExhaustiveStructNoPrivateFields { field: _, .. } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { field: _ } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { field: _, .. } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { field: _ } = ne; + //~^ rest_pattern_accessible_field + + use m::Sm; + + let Sm { a: _, b: _, .. } = Sm::default(); + //~^ rest_pattern_accessible_field + + let Sm { a: _, b: _, .. } = Sm::default(); +} diff --git a/tests/ui/rest_pattern_accessible_field.rs b/tests/ui/rest_pattern_accessible_field.rs new file mode 100644 index 0000000000000..0df08c9d0521c --- /dev/null +++ b/tests/ui/rest_pattern_accessible_field.rs @@ -0,0 +1,108 @@ +//@aux-build:proc_macros.rs +//@aux-build:non-exhaustive-struct.rs +#![warn(clippy::rest_pattern_accessible_field)] +#![allow(clippy::unneeded_wildcard_pattern)] + +use non_exhaustive_struct::{NonExhaustiveStruct, NonExhaustiveStructNoPrivateFields}; + +struct S { + a: u8, + b: u8, + c: u8, +} + +#[derive(Default)] +#[non_exhaustive] +struct LocalNonExhaustive { + field: i32, +} + +enum E { + A { a1: u8, a2: u8 }, + B { b1: u8, b2: u8 }, + C {}, +} + +mod m { + #[derive(Default)] + pub struct Sm { + pub a: u8, + pub(crate) b: u8, + c: u8, + } +} + +fn main() { + let s = S { a: 1, b: 2, c: 3 }; + + let S { a, b, .. } = s; + //~^ rest_pattern_accessible_field + + let S { c, .. } = s; + //~^ rest_pattern_accessible_field + + let S { a, b, c, .. } = s; + + S { a: _, b: _, .. } = S { a: 1, b: 2, c: 3 }; + //~^ rest_pattern_accessible_field + + let e = E::A { a1: 1, a2: 2 }; + + match e { + E::A { a1, a2 } => (), + E::B { .. } => (), + //~^ rest_pattern_accessible_field + E::C { .. } => (), + } + + match e { + E::A { a1: _, a2: _ } => (), + E::B { b1: _, .. } => (), + //~^ rest_pattern_accessible_field + E::C {} => (), + } + + proc_macros::external! { + let s1 = S { a: 1, b: 2, c: 3 }; + let S { a, b, .. } = s1; + } + + proc_macros::with_span! { + span + let s2 = S { a: 1, b: 2, c: 3 }; + let S { a, b, .. } = s2; + } + + let ne = NonExhaustiveStruct::default(); + let NonExhaustiveStruct { field1: _, .. } = ne; + //~^ rest_pattern_accessible_field + + let ne = NonExhaustiveStruct::default(); + let NonExhaustiveStruct { + field1: _, field2: _, .. + } = ne; + + let ne = NonExhaustiveStructNoPrivateFields::default(); + let NonExhaustiveStructNoPrivateFields { .. } = ne; + //~^ rest_pattern_accessible_field + + let ne = NonExhaustiveStructNoPrivateFields::default(); + let NonExhaustiveStructNoPrivateFields { field: _, .. } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { field: _ } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { field: _, .. } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { .. } = ne; + //~^ rest_pattern_accessible_field + + use m::Sm; + + let Sm { .. } = Sm::default(); + //~^ rest_pattern_accessible_field + + let Sm { a: _, b: _, .. } = Sm::default(); +} diff --git a/tests/ui/rest_pattern_accessible_field.stderr b/tests/ui/rest_pattern_accessible_field.stderr new file mode 100644 index 0000000000000..79b8a98ed253f --- /dev/null +++ b/tests/ui/rest_pattern_accessible_field.stderr @@ -0,0 +1,109 @@ +error: struct destructuring with rest (`..`) + --> tests/ui/rest_pattern_accessible_field.rs:38:9 + | +LL | let S { a, b, .. } = s; + | ^^^^^^^^^^^^^^ + | + = note: `-D clippy::rest-pattern-accessible-field` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rest_pattern_accessible_field)]` +help: consider explicitly ignoring remaining fields with wildcard patterns (`x: _`) + | +LL - let S { a, b, .. } = s; +LL + let S { a, b, c: _ } = s; + | + +error: struct destructuring with rest (`..`) + --> tests/ui/rest_pattern_accessible_field.rs:41:9 + | +LL | let S { c, .. } = s; + | ^^^^^^^^^^^ + | +help: consider explicitly ignoring remaining fields with wildcard patterns (`x: _`) + | +LL - let S { c, .. } = s; +LL + let S { c, a: _, b: _ } = s; + | + +error: struct destructuring with rest (`..`) + --> tests/ui/rest_pattern_accessible_field.rs:46:5 + | +LL | S { a: _, b: _, .. } = S { a: 1, b: 2, c: 3 }; + | ^^^^^^^^^^^^^^^^^^^^ + | +help: consider explicitly ignoring remaining fields with wildcard patterns (`x: _`) + | +LL - S { a: _, b: _, .. } = S { a: 1, b: 2, c: 3 }; +LL + S { a: _, b: _, c: _ } = S { a: 1, b: 2, c: 3 }; + | + +error: struct destructuring with rest (`..`) + --> tests/ui/rest_pattern_accessible_field.rs:53:9 + | +LL | E::B { .. } => (), + | ^^^^^^^^^^^ + | +help: consider explicitly ignoring fields with wildcard patterns (`x: _`) + | +LL - E::B { .. } => (), +LL + E::B { b1: _, b2: _ } => (), + | + +error: struct destructuring with rest (`..`) + --> tests/ui/rest_pattern_accessible_field.rs:60:9 + | +LL | E::B { b1: _, .. } => (), + | ^^^^^^^^^^^^^^^^^^ + | +help: consider explicitly ignoring remaining fields with wildcard patterns (`x: _`) + | +LL - E::B { b1: _, .. } => (), +LL + E::B { b1: _, b2: _ } => (), + | + +error: struct destructuring with rest (`..`) + --> tests/ui/rest_pattern_accessible_field.rs:77:9 + | +LL | let NonExhaustiveStruct { field1: _, .. } = ne; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider explicitly ignoring remaining fields with wildcard patterns (`x: _`) + | +LL | let NonExhaustiveStruct { field1: _, field2: _, .. } = ne; + | ++++++++++ + +error: struct destructuring with rest (`..`) + --> tests/ui/rest_pattern_accessible_field.rs:86:9 + | +LL | let NonExhaustiveStructNoPrivateFields { .. } = ne; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider explicitly ignoring fields with wildcard patterns (`x: _`) + | +LL | let NonExhaustiveStructNoPrivateFields { field: _, .. } = ne; + | +++++++++ + +error: struct destructuring with rest (`..`) + --> tests/ui/rest_pattern_accessible_field.rs:99:9 + | +LL | let LocalNonExhaustive { .. } = ne; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider explicitly ignoring fields with wildcard patterns (`x: _`) + | +LL - let LocalNonExhaustive { .. } = ne; +LL + let LocalNonExhaustive { field: _ } = ne; + | + +error: struct destructuring with rest (`..`) + --> tests/ui/rest_pattern_accessible_field.rs:104:9 + | +LL | let Sm { .. } = Sm::default(); + | ^^^^^^^^^ + | +help: consider explicitly ignoring fields with wildcard patterns (`x: _`) + | +LL | let Sm { a: _, b: _, .. } = Sm::default(); + | +++++++++++ + +error: aborting due to 9 previous errors + diff --git a/tests/ui/unnecessary_rest_pattern.fixed b/tests/ui/unnecessary_rest_pattern.fixed new file mode 100644 index 0000000000000..830f868226678 --- /dev/null +++ b/tests/ui/unnecessary_rest_pattern.fixed @@ -0,0 +1,90 @@ +//@aux-build:proc_macros.rs +//@aux-build:non-exhaustive-struct.rs +#![warn(clippy::unnecessary_rest_pattern)] +#![allow(clippy::unneeded_wildcard_pattern)] + +use non_exhaustive_struct::{NonExhaustiveStruct, NonExhaustiveStructNoPrivateFields}; + +struct S { + a: u8, + b: u8, + c: u8, +} + +#[derive(Default)] +#[non_exhaustive] +struct LocalNonExhaustive { + field: i32, +} + +enum E { + A { a1: u8, a2: u8 }, + B { b1: u8, b2: u8 }, + C {}, +} + +mod m { + #[derive(Default)] + pub struct Sm { + pub a: u8, + pub(crate) b: u8, + c: u8, + } +} + +fn main() { + let s = S { a: 1, b: 2, c: 3 }; + + let S { a, b, c, } = s; + //~^ unnecessary_rest_pattern + + let e = E::A { a1: 1, a2: 2 }; + + match e { + E::A { a1, a2 } => (), + E::B { b1, b2, } => (), + //~^ unnecessary_rest_pattern + E::C { } => (), + //~^ unnecessary_rest_pattern + } + + proc_macros::external! { + let s1 = S { a: 1, b: 2, c: 3 }; + let S { a, b, c, .. } = s1; + } + + proc_macros::with_span! { + span + let s2 = S { a: 1, b: 2, c: 3 }; + let S { a, b, c, .. } = s2; + } + + let ne = NonExhaustiveStruct::default(); + let NonExhaustiveStruct { field1: _, .. } = ne; + + let ne = NonExhaustiveStruct::default(); + let NonExhaustiveStruct { + field1: _, field2: _, .. + } = ne; + + let ne = NonExhaustiveStructNoPrivateFields::default(); + let NonExhaustiveStructNoPrivateFields { .. } = ne; + + let ne = NonExhaustiveStructNoPrivateFields::default(); + let NonExhaustiveStructNoPrivateFields { field: _, .. } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { field: _ } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { field: _, } = ne; + //~^ unnecessary_rest_pattern + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { .. } = ne; + + use m::Sm; + + let Sm { .. } = Sm::default(); + let Sm { a: _, b: _, .. } = Sm::default(); +} diff --git a/tests/ui/unnecessary_rest_pattern.rs b/tests/ui/unnecessary_rest_pattern.rs new file mode 100644 index 0000000000000..51ed4b1e18042 --- /dev/null +++ b/tests/ui/unnecessary_rest_pattern.rs @@ -0,0 +1,90 @@ +//@aux-build:proc_macros.rs +//@aux-build:non-exhaustive-struct.rs +#![warn(clippy::unnecessary_rest_pattern)] +#![allow(clippy::unneeded_wildcard_pattern)] + +use non_exhaustive_struct::{NonExhaustiveStruct, NonExhaustiveStructNoPrivateFields}; + +struct S { + a: u8, + b: u8, + c: u8, +} + +#[derive(Default)] +#[non_exhaustive] +struct LocalNonExhaustive { + field: i32, +} + +enum E { + A { a1: u8, a2: u8 }, + B { b1: u8, b2: u8 }, + C {}, +} + +mod m { + #[derive(Default)] + pub struct Sm { + pub a: u8, + pub(crate) b: u8, + c: u8, + } +} + +fn main() { + let s = S { a: 1, b: 2, c: 3 }; + + let S { a, b, c, .. } = s; + //~^ unnecessary_rest_pattern + + let e = E::A { a1: 1, a2: 2 }; + + match e { + E::A { a1, a2 } => (), + E::B { b1, b2, .. } => (), + //~^ unnecessary_rest_pattern + E::C { .. } => (), + //~^ unnecessary_rest_pattern + } + + proc_macros::external! { + let s1 = S { a: 1, b: 2, c: 3 }; + let S { a, b, c, .. } = s1; + } + + proc_macros::with_span! { + span + let s2 = S { a: 1, b: 2, c: 3 }; + let S { a, b, c, .. } = s2; + } + + let ne = NonExhaustiveStruct::default(); + let NonExhaustiveStruct { field1: _, .. } = ne; + + let ne = NonExhaustiveStruct::default(); + let NonExhaustiveStruct { + field1: _, field2: _, .. + } = ne; + + let ne = NonExhaustiveStructNoPrivateFields::default(); + let NonExhaustiveStructNoPrivateFields { .. } = ne; + + let ne = NonExhaustiveStructNoPrivateFields::default(); + let NonExhaustiveStructNoPrivateFields { field: _, .. } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { field: _ } = ne; + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { field: _, .. } = ne; + //~^ unnecessary_rest_pattern + + let ne = LocalNonExhaustive::default(); + let LocalNonExhaustive { .. } = ne; + + use m::Sm; + + let Sm { .. } = Sm::default(); + let Sm { a: _, b: _, .. } = Sm::default(); +} diff --git a/tests/ui/unnecessary_rest_pattern.stderr b/tests/ui/unnecessary_rest_pattern.stderr new file mode 100644 index 0000000000000..2c8e66f9d1034 --- /dev/null +++ b/tests/ui/unnecessary_rest_pattern.stderr @@ -0,0 +1,52 @@ +error: unnecessary rest pattern (`..`) + --> tests/ui/unnecessary_rest_pattern.rs:38:9 + | +LL | let S { a, b, c, .. } = s; + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::unnecessary-rest-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_rest_pattern)]` +help: consider removing the unnecessary rest pattern (`..`) + | +LL - let S { a, b, c, .. } = s; +LL + let S { a, b, c, } = s; + | + +error: unnecessary rest pattern (`..`) + --> tests/ui/unnecessary_rest_pattern.rs:45:9 + | +LL | E::B { b1, b2, .. } => (), + | ^^^^^^^^^^^^^^^^^^^ + | +help: consider removing the unnecessary rest pattern (`..`) + | +LL - E::B { b1, b2, .. } => (), +LL + E::B { b1, b2, } => (), + | + +error: unnecessary rest pattern (`..`) + --> tests/ui/unnecessary_rest_pattern.rs:47:9 + | +LL | E::C { .. } => (), + | ^^^^^^^^^^^ + | +help: consider removing the unnecessary rest pattern (`..`) + | +LL - E::C { .. } => (), +LL + E::C { } => (), + | + +error: unnecessary rest pattern (`..`) + --> tests/ui/unnecessary_rest_pattern.rs:80:9 + | +LL | let LocalNonExhaustive { field: _, .. } = ne; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider removing the unnecessary rest pattern (`..`) + | +LL - let LocalNonExhaustive { field: _, .. } = ne; +LL + let LocalNonExhaustive { field: _, } = ne; + | + +error: aborting due to 4 previous errors + From 5b6af2199a77c9dc171fdd83fd0fce53ab9ffa06 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khyperia@users.noreply.github.com> Date: Fri, 10 Jul 2026 09:16:18 +0200 Subject: [PATCH 24/63] merge DefKind::InlineConst into AnonConst --- clippy_lints/src/manual_float_methods.rs | 1 - clippy_lints/src/matches/match_wild_enum.rs | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index acd47fcd279db..de8edc03191fe 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -122,7 +122,6 @@ fn is_not_const(tcx: TyCtxt<'_>, def_id: DefId) -> bool { | DefKind::TyParam => true, DefKind::AnonConst - | DefKind::InlineConst | DefKind::Const { .. } | DefKind::ConstParam | DefKind::Static { .. } diff --git a/clippy_lints/src/matches/match_wild_enum.rs b/clippy_lints/src/matches/match_wild_enum.rs index 98530b7808076..69288e693e4b4 100644 --- a/clippy_lints/src/matches/match_wild_enum.rs +++ b/clippy_lints/src/matches/match_wild_enum.rs @@ -67,10 +67,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { }) => { // FIXME(clippy): don't you want to use the hir id of the peeled pat? let id = match cx.qpath_res(path, *hir_id) { - Res::Def( - DefKind::Const { .. } | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst, - _, - ) => return, + Res::Def(DefKind::Const { .. } | DefKind::ConstParam | DefKind::AnonConst, _) => return, Res::Def(_, id) => id, _ => return, }; From 66303a60c40b550c985451b74c79a902830a5556 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 21 May 2026 19:06:48 +0200 Subject: [PATCH 25/63] Attributes cleanup in tests [18/20] --- tests/ui/temporary_assignment.rs | 1 - tests/ui/temporary_assignment.stderr | 8 +- tests/ui/tests_outside_test_module.rs | 1 - tests/ui/tests_outside_test_module.stderr | 2 +- tests/ui/toplevel_ref_arg.fixed | 2 +- tests/ui/toplevel_ref_arg.rs | 2 +- tests/ui/toplevel_ref_arg_non_rustfix.rs | 1 - tests/ui/toplevel_ref_arg_non_rustfix.stderr | 4 +- tests/ui/trailing_empty_array.rs | 2 +- tests/ui/trailing_zeros.fixed | 1 - tests/ui/trailing_zeros.rs | 1 - tests/ui/trailing_zeros.stderr | 4 +- tests/ui/trait_duplication_in_bounds.fixed | 3 +- tests/ui/trait_duplication_in_bounds.rs | 3 +- tests/ui/trait_duplication_in_bounds.stderr | 29 ++-- .../trait_duplication_in_bounds_unfixable.rs | 4 +- ...ait_duplication_in_bounds_unfixable.stderr | 7 +- tests/ui/transmute.rs | 17 +- tests/ui/transmute.stderr | 34 ++-- tests/ui/transmute_collection.rs | 2 +- tests/ui/transmute_int_to_non_zero.fixed | 1 - tests/ui/transmute_int_to_non_zero.rs | 1 - tests/ui/transmute_int_to_non_zero.stderr | 20 +-- tests/ui/transmute_null_to_fn.rs | 4 +- tests/ui/transmute_null_to_fn.stderr | 12 +- tests/ui/transmute_ptr_to_ptr.fixed | 1 - tests/ui/transmute_ptr_to_ptr.rs | 1 - tests/ui/transmute_ptr_to_ptr.stderr | 40 ++--- tests/ui/transmute_ptr_to_ref.fixed | 6 +- tests/ui/transmute_ptr_to_ref.rs | 6 +- tests/ui/transmute_ptr_to_ref.stderr | 82 +++++----- tests/ui/transmute_ref_to_ref.fixed | 4 +- tests/ui/transmute_ref_to_ref.rs | 4 +- tests/ui/transmute_ref_to_ref.stderr | 7 +- tests/ui/transmute_ref_to_ref_no_std.fixed | 4 +- tests/ui/transmute_ref_to_ref_no_std.rs | 4 +- tests/ui/transmute_ref_to_ref_no_std.stderr | 7 +- tests/ui/transmute_undefined_repr.rs | 7 +- tests/ui/transmute_undefined_repr.stderr | 24 +-- .../transmutes_expressible_as_ptr_casts.fixed | 16 +- .../ui/transmutes_expressible_as_ptr_casts.rs | 16 +- ...transmutes_expressible_as_ptr_casts.stderr | 18 +-- tests/ui/transmuting_null.rs | 5 +- tests/ui/transmuting_null.stderr | 16 +- tests/ui/trim_split_whitespace.fixed | 3 +- tests/ui/trim_split_whitespace.rs | 3 +- tests/ui/trim_split_whitespace.stderr | 16 +- tests/ui/trivially_copy_pass_by_ref.fixed | 12 +- tests/ui/trivially_copy_pass_by_ref.rs | 12 +- tests/ui/trivially_copy_pass_by_ref.stderr | 43 +++-- tests/ui/try_err.fixed | 8 +- tests/ui/try_err.rs | 8 +- tests/ui/try_err.stderr | 29 ++-- tests/ui/tuple_array_conversions.rs | 2 +- tests/ui/type_complexity.rs | 2 +- tests/ui/type_repetition_in_bounds.rs | 8 +- tests/ui/type_repetition_in_bounds.stderr | 21 ++- tests/ui/unconditional_recursion.rs | 6 +- tests/ui/unicode.fixed | 14 +- tests/ui/unicode.rs | 14 +- tests/ui/unicode.stderr | 29 +--- tests/ui/uninhabited_references.rs | 1 - tests/ui/uninhabited_references.stderr | 8 +- tests/ui/uninit.rs | 3 +- tests/ui/uninit.stderr | 9 +- tests/ui/uninlined_format_args.fixed | 5 +- tests/ui/uninlined_format_args.rs | 5 +- tests/ui/uninlined_format_args.stderr | 150 +++++++++--------- ...nlined_format_args_panic.edition2018.fixed | 1 - ...lined_format_args_panic.edition2018.stderr | 2 +- ...nlined_format_args_panic.edition2021.fixed | 1 - ...lined_format_args_panic.edition2021.stderr | 18 +-- ...nlined_format_args_panic.edition2024.fixed | 1 - ...lined_format_args_panic.edition2024.stderr | 18 +-- tests/ui/uninlined_format_args_panic.rs | 1 - tests/ui/unit_arg.rs | 10 +- tests/ui/unit_arg.stderr | 26 +-- tests/ui/unit_arg_fixable.fixed | 2 - tests/ui/unit_arg_fixable.rs | 2 - tests/ui/unit_arg_fixable.stderr | 20 +-- tests/ui/unit_cmp.rs | 7 +- tests/ui/unit_cmp.stderr | 16 +- tests/ui/unit_hash.fixed | 1 - tests/ui/unit_hash.rs | 1 - tests/ui/unit_hash.stderr | 6 +- tests/ui/unit_return_expecting_ord.rs | 3 +- tests/ui/unit_return_expecting_ord.stderr | 12 +- tests/ui/unnecessary_cast.fixed | 9 +- tests/ui/unnecessary_cast.rs | 9 +- tests/ui/unnecessary_cast.stderr | 144 ++++++++--------- tests/ui/unnecessary_clippy_cfg.rs | 2 +- tests/ui/unnecessary_filter_map.rs | 4 +- tests/ui/unnecessary_filter_map.stderr | 10 +- 93 files changed, 522 insertions(+), 649 deletions(-) diff --git a/tests/ui/temporary_assignment.rs b/tests/ui/temporary_assignment.rs index ac9ed5d05f8fd..fae3be08b49e0 100644 --- a/tests/ui/temporary_assignment.rs +++ b/tests/ui/temporary_assignment.rs @@ -1,5 +1,4 @@ #![warn(clippy::temporary_assignment)] -#![allow(clippy::needless_lifetimes)] use std::ops::{Deref, DerefMut}; diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr index 5f6a540036302..7f8c859110c75 100644 --- a/tests/ui/temporary_assignment.stderr +++ b/tests/ui/temporary_assignment.stderr @@ -1,5 +1,5 @@ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:48:5 + --> tests/ui/temporary_assignment.rs:47:5 | LL | Struct { field: 0 }.field = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | Struct { field: 0 }.field = 1; = help: to override `-D warnings` add `#[allow(clippy::temporary_assignment)]` error: assignment to temporary - --> tests/ui/temporary_assignment.rs:51:5 + --> tests/ui/temporary_assignment.rs:50:5 | LL | / MultiStruct { LL | | @@ -18,13 +18,13 @@ LL | | .field = 1; | |______________^ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:57:5 + --> tests/ui/temporary_assignment.rs:56:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:60:5 + --> tests/ui/temporary_assignment.rs:59:5 | LL | (0, 0).0 = 1; | ^^^^^^^^^^^^ diff --git a/tests/ui/tests_outside_test_module.rs b/tests/ui/tests_outside_test_module.rs index 35126c46af083..0088cbd920e92 100644 --- a/tests/ui/tests_outside_test_module.rs +++ b/tests/ui/tests_outside_test_module.rs @@ -1,5 +1,4 @@ //@require-annotations-for-level: WARN -#![allow(unused)] #![warn(clippy::tests_outside_test_module)] fn main() { diff --git a/tests/ui/tests_outside_test_module.stderr b/tests/ui/tests_outside_test_module.stderr index 8602a63cc7a41..09feae6bf2aa7 100644 --- a/tests/ui/tests_outside_test_module.stderr +++ b/tests/ui/tests_outside_test_module.stderr @@ -1,5 +1,5 @@ error: this function marked with #[test] is outside a #[cfg(test)] module - --> tests/ui/tests_outside_test_module.rs:11:1 + --> tests/ui/tests_outside_test_module.rs:10:1 | LL | fn my_test() {} | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/toplevel_ref_arg.fixed b/tests/ui/toplevel_ref_arg.fixed index 11d4eaaefda02..d143a3cd625c3 100644 --- a/tests/ui/toplevel_ref_arg.fixed +++ b/tests/ui/toplevel_ref_arg.fixed @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs #![warn(clippy::toplevel_ref_arg)] -#![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)] +#![expect(clippy::uninlined_format_args, clippy::useless_vec)] extern crate proc_macros; use proc_macros::{external, inline_macros}; diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs index 957dd542f5a99..73d7b736f8a2e 100644 --- a/tests/ui/toplevel_ref_arg.rs +++ b/tests/ui/toplevel_ref_arg.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs #![warn(clippy::toplevel_ref_arg)] -#![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)] +#![expect(clippy::uninlined_format_args, clippy::useless_vec)] extern crate proc_macros; use proc_macros::{external, inline_macros}; diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.rs b/tests/ui/toplevel_ref_arg_non_rustfix.rs index 87c84a7ee14ab..33f33d287a154 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.rs +++ b/tests/ui/toplevel_ref_arg_non_rustfix.rs @@ -1,7 +1,6 @@ //@aux-build:proc_macros.rs #![warn(clippy::toplevel_ref_arg)] -#![allow(unused)] extern crate proc_macros; use proc_macros::{external, inline_macros}; diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/tests/ui/toplevel_ref_arg_non_rustfix.stderr index e17b2536874e0..828919b59ce22 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ b/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -1,5 +1,5 @@ error: `ref` directly on a function parameter does not prevent taking ownership of the passed argument. Consider using a reference type instead - --> tests/ui/toplevel_ref_arg_non_rustfix.rs:9:15 + --> tests/ui/toplevel_ref_arg_non_rustfix.rs:8:15 | LL | fn the_answer(ref mut x: u8) { | ^^^^^^^^^ @@ -8,7 +8,7 @@ LL | fn the_answer(ref mut x: u8) { = help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]` error: `ref` directly on a function parameter does not prevent taking ownership of the passed argument. Consider using a reference type instead - --> tests/ui/toplevel_ref_arg_non_rustfix.rs:21:24 + --> tests/ui/toplevel_ref_arg_non_rustfix.rs:20:24 | LL | fn fun_example(ref _x: usize) {} | ^^^^^^ diff --git a/tests/ui/trailing_empty_array.rs b/tests/ui/trailing_empty_array.rs index a8c3ffdb0dab3..c0ee31e55f600 100644 --- a/tests/ui/trailing_empty_array.rs +++ b/tests/ui/trailing_empty_array.rs @@ -1,5 +1,5 @@ #![warn(clippy::trailing_empty_array)] -#![allow(clippy::repr_packed_without_abi)] +#![expect(clippy::repr_packed_without_abi)] // Do lint: diff --git a/tests/ui/trailing_zeros.fixed b/tests/ui/trailing_zeros.fixed index 8c30b062fb183..cd4cd0f8cacb7 100644 --- a/tests/ui/trailing_zeros.fixed +++ b/tests/ui/trailing_zeros.fixed @@ -1,4 +1,3 @@ -#![allow(unused_parens)] #![warn(clippy::verbose_bit_mask)] fn main() { diff --git a/tests/ui/trailing_zeros.rs b/tests/ui/trailing_zeros.rs index 369a31557392c..c5038b612f6da 100644 --- a/tests/ui/trailing_zeros.rs +++ b/tests/ui/trailing_zeros.rs @@ -1,4 +1,3 @@ -#![allow(unused_parens)] #![warn(clippy::verbose_bit_mask)] fn main() { diff --git a/tests/ui/trailing_zeros.stderr b/tests/ui/trailing_zeros.stderr index 6f3e7aa1d762e..de951e2e75a26 100644 --- a/tests/ui/trailing_zeros.stderr +++ b/tests/ui/trailing_zeros.stderr @@ -1,5 +1,5 @@ error: bit mask could be simplified with a call to `trailing_zeros` - --> tests/ui/trailing_zeros.rs:6:13 + --> tests/ui/trailing_zeros.rs:5:13 | LL | let _ = (x & 0b1111 == 0); | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 4` @@ -8,7 +8,7 @@ LL | let _ = (x & 0b1111 == 0); = help: to override `-D warnings` add `#[allow(clippy::verbose_bit_mask)]` error: bit mask could be simplified with a call to `trailing_zeros` - --> tests/ui/trailing_zeros.rs:9:13 + --> tests/ui/trailing_zeros.rs:8:13 | LL | let _ = x & 0b1_1111 == 0; | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5` diff --git a/tests/ui/trait_duplication_in_bounds.fixed b/tests/ui/trait_duplication_in_bounds.fixed index 959f5db112655..658880e81e2e3 100644 --- a/tests/ui/trait_duplication_in_bounds.fixed +++ b/tests/ui/trait_duplication_in_bounds.fixed @@ -1,5 +1,4 @@ -#![deny(clippy::trait_duplication_in_bounds)] -#![allow(unused)] +#![warn(clippy::trait_duplication_in_bounds)] #![feature(const_trait_impl)] use std::any::Any; diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs index 9bfecf40fc03d..046a8ad8e597f 100644 --- a/tests/ui/trait_duplication_in_bounds.rs +++ b/tests/ui/trait_duplication_in_bounds.rs @@ -1,5 +1,4 @@ -#![deny(clippy::trait_duplication_in_bounds)] -#![allow(unused)] +#![warn(clippy::trait_duplication_in_bounds)] #![feature(const_trait_impl)] use std::any::Any; diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr index 93488ea8e74db..fb3887d22517f 100644 --- a/tests/ui/trait_duplication_in_bounds.stderr +++ b/tests/ui/trait_duplication_in_bounds.stderr @@ -1,71 +1,68 @@ error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:7:15 + --> tests/ui/trait_duplication_in_bounds.rs:6:15 | LL | fn bad_foo(arg0: T, argo1: U) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` | -note: the lint level is defined here - --> tests/ui/trait_duplication_in_bounds.rs:1:9 - | -LL | #![deny(clippy::trait_duplication_in_bounds)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::trait-duplication-in-bounds` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trait_duplication_in_bounds)]` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:14:8 + --> tests/ui/trait_duplication_in_bounds.rs:13:8 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:43:26 + --> tests/ui/trait_duplication_in_bounds.rs:42:26 | LL | trait BadSelfTraitBound: Clone + Clone + Clone { | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:51:15 + --> tests/ui/trait_duplication_in_bounds.rs:50:15 | LL | Self: Clone + Clone + Clone; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:66:24 + --> tests/ui/trait_duplication_in_bounds.rs:65:24 | LL | trait BadTraitBound { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:74:12 + --> tests/ui/trait_duplication_in_bounds.rs:73:12 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:108:19 + --> tests/ui/trait_duplication_in_bounds.rs:107:19 | LL | fn bad_generic + GenericTrait + GenericTrait>(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `GenericTrait + GenericTrait` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:117:22 + --> tests/ui/trait_duplication_in_bounds.rs:116:22 | LL | fn qualified_path(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::clone::Clone + foo::Clone` error: this trait bound is already specified in trait declaration - --> tests/ui/trait_duplication_in_bounds.rs:126:33 + --> tests/ui/trait_duplication_in_bounds.rs:125:33 | LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) { | ^^^^^^^^^^^^^^^^^ help: try: `Any + Send` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:173:36 + --> tests/ui/trait_duplication_in_bounds.rs:172:36 | LL | const fn const_trait_bounds_bad() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[const] ConstTrait` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:180:8 + --> tests/ui/trait_duplication_in_bounds.rs:179:8 | LL | T: IntoIterator + IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `IntoIterator` diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.rs b/tests/ui/trait_duplication_in_bounds_unfixable.rs index cf72ed844a78c..a519fb3651ef7 100644 --- a/tests/ui/trait_duplication_in_bounds_unfixable.rs +++ b/tests/ui/trait_duplication_in_bounds_unfixable.rs @@ -1,5 +1,5 @@ -#![deny(clippy::trait_duplication_in_bounds)] -#![allow(clippy::multiple_bound_locations)] +#![warn(clippy::trait_duplication_in_bounds)] +#![expect(clippy::multiple_bound_locations)] use std::collections::BTreeMap; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.stderr b/tests/ui/trait_duplication_in_bounds_unfixable.stderr index 546d39518e1fa..2a6c82efa92d5 100644 --- a/tests/ui/trait_duplication_in_bounds_unfixable.stderr +++ b/tests/ui/trait_duplication_in_bounds_unfixable.stderr @@ -5,11 +5,8 @@ LL | fn bad_foo(arg0: T, arg1: Z) | ^^^^^ | = help: consider removing this trait bound -note: the lint level is defined here - --> tests/ui/trait_duplication_in_bounds_unfixable.rs:1:9 - | -LL | #![deny(clippy::trait_duplication_in_bounds)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::trait-duplication-in-bounds` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trait_duplication_in_bounds)]` error: this trait bound is already specified in the where clause --> tests/ui/trait_duplication_in_bounds_unfixable.rs:7:23 diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index afb79deac20f8..36d794cedea11 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -1,13 +1,12 @@ #![feature(f128)] #![feature(f16)] -#![allow( - dead_code, - clippy::borrow_as_ptr, - unnecessary_transmutes, - integer_to_ptr_transmutes, - clippy::needless_lifetimes, - clippy::missing_transmute_annotations +#![warn( + clippy::crosspointer_transmute, + clippy::transmute_bytes_to_str, + clippy::transmute_int_to_bool, + clippy::useless_transmute )] +#![expect(integer_to_ptr_transmutes, clippy::needless_lifetimes)] //@no-rustfix extern crate core; @@ -23,7 +22,6 @@ fn my_vec() -> MyVec { } #[allow(clippy::needless_lifetimes, clippy::transmute_ptr_to_ptr)] -#[warn(clippy::useless_transmute)] unsafe fn _generic<'a, T, U: 'a>(t: &'a T) { unsafe { // FIXME: should lint @@ -42,7 +40,6 @@ unsafe fn _generic<'a, T, U: 'a>(t: &'a T) { } } -#[warn(clippy::useless_transmute)] fn useless() { unsafe { let _: Vec = core::mem::transmute(my_vec()); @@ -88,7 +85,6 @@ fn useless() { struct Usize(usize); -#[warn(clippy::crosspointer_transmute)] fn crosspointer() { let mut int: Usize = Usize(0); let int_const_ptr: *const Usize = &int as *const Usize; @@ -109,7 +105,6 @@ fn crosspointer() { } } -#[warn(clippy::transmute_int_to_bool)] fn int_to_bool() { let _: bool = unsafe { std::mem::transmute(0_u8) }; //~^ transmute_int_to_bool diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index 6f9a0b717fc90..0232d9ac04bbf 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -1,5 +1,5 @@ error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:34:27 + --> tests/ui/transmute.rs:32:27 | LL | let _: *const T = core::mem::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T` @@ -8,49 +8,49 @@ LL | let _: *const T = core::mem::transmute(t); = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:37:25 + --> tests/ui/transmute.rs:35:25 | LL | let _: *mut T = core::mem::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` error: transmute from a reference to a pointer - --> tests/ui/transmute.rs:40:27 + --> tests/ui/transmute.rs:38:27 | LL | let _: *const U = core::mem::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:48:27 + --> tests/ui/transmute.rs:45:27 | LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:51:27 + --> tests/ui/transmute.rs:48:27 | LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:54:27 + --> tests/ui/transmute.rs:51:27 | LL | let _: Vec = std::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:57:27 + --> tests/ui/transmute.rs:54:27 | LL | let _: Vec = std::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> tests/ui/transmute.rs:60:27 + --> tests/ui/transmute.rs:57:27 | LL | let _: Vec = my_transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`) - --> tests/ui/transmute.rs:98:24 + --> tests/ui/transmute.rs:94:24 | LL | let _: Usize = core::mem::transmute(int_const_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -59,25 +59,25 @@ LL | let _: Usize = core::mem::transmute(int_const_ptr); = help: to override `-D warnings` add `#[allow(clippy::crosspointer_transmute)]` error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) - --> tests/ui/transmute.rs:101:24 + --> tests/ui/transmute.rs:97:24 | LL | let _: Usize = core::mem::transmute(int_mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) - --> tests/ui/transmute.rs:104:31 + --> tests/ui/transmute.rs:100:31 | LL | let _: *const Usize = core::mem::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) - --> tests/ui/transmute.rs:107:29 + --> tests/ui/transmute.rs:103:29 | LL | let _: *mut Usize = core::mem::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a `u8` to a `bool` - --> tests/ui/transmute.rs:114:28 + --> tests/ui/transmute.rs:109:28 | LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` @@ -86,7 +86,7 @@ LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_bool)]` error: transmute from a `&[u8]` to a `&str` - --> tests/ui/transmute.rs:121:28 + --> tests/ui/transmute.rs:116:28 | LL | let _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(B).unwrap()` @@ -95,19 +95,19 @@ LL | let _: &str = unsafe { std::mem::transmute(B) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_bytes_to_str)]` error: transmute from a `&mut [u8]` to a `&mut str` - --> tests/ui/transmute.rs:124:32 + --> tests/ui/transmute.rs:119:32 | LL | let _: &mut str = unsafe { std::mem::transmute(mb) }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()` error: transmute from a `&[u8]` to a `&str` - --> tests/ui/transmute.rs:127:30 + --> tests/ui/transmute.rs:122:30 | LL | const _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_unchecked(B)` error: transmute from a `&[u8]` to a `&str` - --> tests/ui/transmute.rs:139:23 + --> tests/ui/transmute.rs:134:23 | LL | let _: &str = std::mem::transmute(take_ref!(b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(take_ref!(b)).unwrap()` diff --git a/tests/ui/transmute_collection.rs b/tests/ui/transmute_collection.rs index 74d7f5e38bf8d..31f62776467d6 100644 --- a/tests/ui/transmute_collection.rs +++ b/tests/ui/transmute_collection.rs @@ -1,5 +1,5 @@ #![warn(clippy::unsound_collection_transmute)] -#![allow(clippy::missing_transmute_annotations)] +#![expect(clippy::missing_transmute_annotations)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; use std::mem::{MaybeUninit, transmute}; diff --git a/tests/ui/transmute_int_to_non_zero.fixed b/tests/ui/transmute_int_to_non_zero.fixed index 273090fef3876..3072cd32f3900 100644 --- a/tests/ui/transmute_int_to_non_zero.fixed +++ b/tests/ui/transmute_int_to_non_zero.fixed @@ -1,5 +1,4 @@ #![warn(clippy::transmute_int_to_non_zero)] -#![allow(clippy::missing_transmute_annotations)] use core::num::NonZero; diff --git a/tests/ui/transmute_int_to_non_zero.rs b/tests/ui/transmute_int_to_non_zero.rs index f27bc9b42d426..446d3e632418b 100644 --- a/tests/ui/transmute_int_to_non_zero.rs +++ b/tests/ui/transmute_int_to_non_zero.rs @@ -1,5 +1,4 @@ #![warn(clippy::transmute_int_to_non_zero)] -#![allow(clippy::missing_transmute_annotations)] use core::num::NonZero; diff --git a/tests/ui/transmute_int_to_non_zero.stderr b/tests/ui/transmute_int_to_non_zero.stderr index 995ab11a5bc96..f43505c9e55f6 100644 --- a/tests/ui/transmute_int_to_non_zero.stderr +++ b/tests/ui/transmute_int_to_non_zero.stderr @@ -1,5 +1,5 @@ error: transmute from a `u8` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:19:35 + --> tests/ui/transmute_int_to_non_zero.rs:18:35 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u8)` @@ -8,55 +8,55 @@ LL | let _: NonZero = unsafe { std::mem::transmute(int_u8) }; = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_non_zero)]` error: transmute from a `u16` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:22:36 + --> tests/ui/transmute_int_to_non_zero.rs:21:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u16)` error: transmute from a `u32` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:25:36 + --> tests/ui/transmute_int_to_non_zero.rs:24:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u32)` error: transmute from a `u64` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:28:36 + --> tests/ui/transmute_int_to_non_zero.rs:27:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u64)` error: transmute from a `u128` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:31:37 + --> tests/ui/transmute_int_to_non_zero.rs:30:37 | LL | let _: NonZero = unsafe { std::mem::transmute(int_u128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u128)` error: transmute from a `i8` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:34:35 + --> tests/ui/transmute_int_to_non_zero.rs:33:35 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i8)` error: transmute from a `i16` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:37:36 + --> tests/ui/transmute_int_to_non_zero.rs:36:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i16)` error: transmute from a `i32` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:40:36 + --> tests/ui/transmute_int_to_non_zero.rs:39:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i32)` error: transmute from a `i64` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:43:36 + --> tests/ui/transmute_int_to_non_zero.rs:42:36 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i64)` error: transmute from a `i128` to a `NonZero` - --> tests/ui/transmute_int_to_non_zero.rs:46:37 + --> tests/ui/transmute_int_to_non_zero.rs:45:37 | LL | let _: NonZero = unsafe { std::mem::transmute(int_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i128)` diff --git a/tests/ui/transmute_null_to_fn.rs b/tests/ui/transmute_null_to_fn.rs index 9ce097d124ab8..f7ba6b6e7805b 100644 --- a/tests/ui/transmute_null_to_fn.rs +++ b/tests/ui/transmute_null_to_fn.rs @@ -1,7 +1,5 @@ -#![allow(dead_code)] #![warn(clippy::transmute_null_to_fn)] -#![allow(clippy::zero_ptr, clippy::missing_transmute_annotations)] -#![allow(clippy::manual_dangling_ptr)] +#![expect(clippy::manual_dangling_ptr, clippy::zero_ptr)] // Easy to lint because these only span one line. fn one_liners() { diff --git a/tests/ui/transmute_null_to_fn.stderr b/tests/ui/transmute_null_to_fn.stderr index b5b0d4ecc7c03..04ce23ca955a0 100644 --- a/tests/ui/transmute_null_to_fn.stderr +++ b/tests/ui/transmute_null_to_fn.stderr @@ -1,5 +1,5 @@ error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:9:23 + --> tests/ui/transmute_null_to_fn.rs:7:23 | LL | let _: fn() = std::mem::transmute(0 as *const ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -9,7 +9,7 @@ LL | let _: fn() = std::mem::transmute(0 as *const ()); = help: to override `-D warnings` add `#[allow(clippy::transmute_null_to_fn)]` error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:12:23 + --> tests/ui/transmute_null_to_fn.rs:10:23 | LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -17,7 +17,7 @@ LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:23:23 + --> tests/ui/transmute_null_to_fn.rs:21:23 | LL | let _: fn() = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -25,7 +25,7 @@ LL | let _: fn() = std::mem::transmute(ZPTR); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:33:23 + --> tests/ui/transmute_null_to_fn.rs:31:23 | LL | let _: fn() = std::mem::transmute(0 as *const u8 as *const ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -33,7 +33,7 @@ LL | let _: fn() = std::mem::transmute(0 as *const u8 as *const ()); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:36:23 + --> tests/ui/transmute_null_to_fn.rs:34:23 | LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -41,7 +41,7 @@ LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> tests/ui/transmute_null_to_fn.rs:39:23 + --> tests/ui/transmute_null_to_fn.rs:37:23 | LL | let _: fn() = std::mem::transmute(ZPTR as *const u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior diff --git a/tests/ui/transmute_ptr_to_ptr.fixed b/tests/ui/transmute_ptr_to_ptr.fixed index caba277db754d..1fc0c315435bc 100644 --- a/tests/ui/transmute_ptr_to_ptr.fixed +++ b/tests/ui/transmute_ptr_to_ptr.fixed @@ -1,5 +1,4 @@ #![warn(clippy::transmute_ptr_to_ptr)] -#![allow(clippy::borrow_as_ptr, clippy::missing_transmute_annotations)] use std::mem::transmute; diff --git a/tests/ui/transmute_ptr_to_ptr.rs b/tests/ui/transmute_ptr_to_ptr.rs index b3c2baf29c361..d2fc34db21f02 100644 --- a/tests/ui/transmute_ptr_to_ptr.rs +++ b/tests/ui/transmute_ptr_to_ptr.rs @@ -1,5 +1,4 @@ #![warn(clippy::transmute_ptr_to_ptr)] -#![allow(clippy::borrow_as_ptr, clippy::missing_transmute_annotations)] use std::mem::transmute; diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr index ba9e6df6c2d7c..aef67239eaf25 100644 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ b/tests/ui/transmute_ptr_to_ptr.stderr @@ -1,5 +1,5 @@ error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:39:29 + --> tests/ui/transmute_ptr_to_ptr.rs:38:29 | LL | let _: *const f32 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + let _: *const f32 = ptr.cast::(); | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:42:27 + --> tests/ui/transmute_ptr_to_ptr.rs:41:27 | LL | let _: *mut f32 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ @@ -25,37 +25,37 @@ LL + let _: *mut f32 = mut_ptr.cast::(); | error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:46:23 + --> tests/ui/transmute_ptr_to_ptr.rs:45:23 | LL | let _: &f32 = transmute(&1u32); | ^^^^^^^^^^^^^^^^ help: try: `&*(&1u32 as *const u32 as *const f32)` error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:49:23 + --> tests/ui/transmute_ptr_to_ptr.rs:48:23 | LL | let _: &f32 = transmute(&1f64); | ^^^^^^^^^^^^^^^^ help: try: `&*(&1f64 as *const f64 as *const f32)` error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:54:27 + --> tests/ui/transmute_ptr_to_ptr.rs:53:27 | LL | let _: &mut f32 = transmute(&mut 1u32); | ^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(&mut 1u32 as *mut u32 as *mut f32)` error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:57:37 + --> tests/ui/transmute_ptr_to_ptr.rs:56:37 | LL | let _: &GenericParam = transmute(&GenericParam { t: 1u32 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam)` error: transmute from a reference to a reference - --> tests/ui/transmute_ptr_to_ptr.rs:61:27 + --> tests/ui/transmute_ptr_to_ptr.rs:60:27 | LL | let u8_ref: &u8 = transmute(u64_ref); | ^^^^^^^^^^^^^^^^^^ help: try: `&*(u64_ref as *const u64 as *const u8)` error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:64:29 + --> tests/ui/transmute_ptr_to_ptr.rs:63:29 | LL | let _: *const u32 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL + let _: *const u32 = mut_ptr.cast_const(); | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:67:27 + --> tests/ui/transmute_ptr_to_ptr.rs:66:27 | LL | let _: *mut u32 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -79,7 +79,7 @@ LL + let _: *mut u32 = ptr.cast_mut(); | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:81:29 + --> tests/ui/transmute_ptr_to_ptr.rs:80:29 | LL | let _: *const f32 = transmute(Ptr(ptr)); | ^^^^^^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL + let _: *const f32 = Ptr(ptr).0.cast::(); | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:83:29 + --> tests/ui/transmute_ptr_to_ptr.rs:82:29 | LL | let _: *const f32 = transmute(PtrNamed { ptr }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,7 +103,7 @@ LL + let _: *const f32 = PtrNamed { ptr }.ptr.cast::(); | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:85:27 + --> tests/ui/transmute_ptr_to_ptr.rs:84:27 | LL | let _: *mut u32 = transmute(Ptr(ptr)); | ^^^^^^^^^^^^^^^^^^^ @@ -115,7 +115,7 @@ LL + let _: *mut u32 = Ptr(ptr).0.cast_mut(); | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:91:14 + --> tests/ui/transmute_ptr_to_ptr.rs:90:14 | LL | unsafe { transmute(v) } | ^^^^^^^^^^^^ @@ -127,7 +127,7 @@ LL + unsafe { v as *const &() } | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:108:28 + --> tests/ui/transmute_ptr_to_ptr.rs:107:28 | LL | let _: *const i8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -139,7 +139,7 @@ LL + let _: *const i8 = ptr as *const i8; | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:110:28 + --> tests/ui/transmute_ptr_to_ptr.rs:109:28 | LL | let _: *const i8 = transmute(Ptr8(ptr)); | ^^^^^^^^^^^^^^^^^^^^ @@ -151,7 +151,7 @@ LL + let _: *const i8 = Ptr8(ptr).0 as *const i8; | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:118:28 + --> tests/ui/transmute_ptr_to_ptr.rs:117:28 | LL | let _: *const i8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -163,7 +163,7 @@ LL + let _: *const i8 = ptr.cast::(); | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:126:26 + --> tests/ui/transmute_ptr_to_ptr.rs:125:26 | LL | let _: *mut u8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -175,7 +175,7 @@ LL + let _: *mut u8 = ptr as *mut u8; | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:128:28 + --> tests/ui/transmute_ptr_to_ptr.rs:127:28 | LL | let _: *const u8 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ @@ -187,7 +187,7 @@ LL + let _: *const u8 = mut_ptr as *const u8; | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:136:26 + --> tests/ui/transmute_ptr_to_ptr.rs:135:26 | LL | let _: *mut u8 = transmute(ptr); | ^^^^^^^^^^^^^^ @@ -199,7 +199,7 @@ LL + let _: *mut u8 = ptr.cast_mut(); | error: transmute from a pointer to a pointer - --> tests/ui/transmute_ptr_to_ptr.rs:138:28 + --> tests/ui/transmute_ptr_to_ptr.rs:137:28 | LL | let _: *const u8 = transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute_ptr_to_ref.fixed b/tests/ui/transmute_ptr_to_ref.fixed index 8de47031a4009..2044c3b14acb7 100644 --- a/tests/ui/transmute_ptr_to_ref.fixed +++ b/tests/ui/transmute_ptr_to_ref.fixed @@ -1,9 +1,5 @@ #![warn(clippy::transmute_ptr_to_ref)] -#![allow( - clippy::match_single_binding, - clippy::unnecessary_cast, - clippy::missing_transmute_annotations -)] +#![allow(clippy::missing_transmute_annotations, clippy::unnecessary_cast)] fn ptr_to_ref(p: *const T, m: *mut T, o: *const U, om: *mut U) { unsafe { diff --git a/tests/ui/transmute_ptr_to_ref.rs b/tests/ui/transmute_ptr_to_ref.rs index 52fe669de9355..3982a6929cf6e 100644 --- a/tests/ui/transmute_ptr_to_ref.rs +++ b/tests/ui/transmute_ptr_to_ref.rs @@ -1,9 +1,5 @@ #![warn(clippy::transmute_ptr_to_ref)] -#![allow( - clippy::match_single_binding, - clippy::unnecessary_cast, - clippy::missing_transmute_annotations -)] +#![allow(clippy::missing_transmute_annotations, clippy::unnecessary_cast)] fn ptr_to_ref(p: *const T, m: *mut T, o: *const U, om: *mut U) { unsafe { diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr index c0f0ca916761d..138eb94405446 100644 --- a/tests/ui/transmute_ptr_to_ref.stderr +++ b/tests/ui/transmute_ptr_to_ref.stderr @@ -1,5 +1,5 @@ error: transmute from a pointer type (`*const T`) to a reference type (`&T`) - --> tests/ui/transmute_ptr_to_ref.rs:10:21 + --> tests/ui/transmute_ptr_to_ref.rs:6:21 | LL | let _: &T = std::mem::transmute(p); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*p` @@ -8,241 +8,241 @@ LL | let _: &T = std::mem::transmute(p); = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ref)]` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> tests/ui/transmute_ptr_to_ref.rs:14:25 + --> tests/ui/transmute_ptr_to_ref.rs:10:25 | LL | let _: &mut T = std::mem::transmute(m); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *m` error: transmute from a pointer type (`*mut T`) to a reference type (`&T`) - --> tests/ui/transmute_ptr_to_ref.rs:18:21 + --> tests/ui/transmute_ptr_to_ref.rs:14:21 | LL | let _: &T = std::mem::transmute(m); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*m` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> tests/ui/transmute_ptr_to_ref.rs:22:25 + --> tests/ui/transmute_ptr_to_ref.rs:18:25 | LL | let _: &mut T = std::mem::transmute(p as *mut T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(p as *mut T)` error: transmute from a pointer type (`*const U`) to a reference type (`&T`) - --> tests/ui/transmute_ptr_to_ref.rs:26:21 + --> tests/ui/transmute_ptr_to_ref.rs:22:21 | LL | let _: &T = std::mem::transmute(o); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(o as *const T)` error: transmute from a pointer type (`*mut U`) to a reference type (`&mut T`) - --> tests/ui/transmute_ptr_to_ref.rs:30:25 + --> tests/ui/transmute_ptr_to_ref.rs:26:25 | LL | let _: &mut T = std::mem::transmute(om); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(om as *mut T)` error: transmute from a pointer type (`*mut U`) to a reference type (`&T`) - --> tests/ui/transmute_ptr_to_ref.rs:34:21 + --> tests/ui/transmute_ptr_to_ref.rs:30:21 | LL | let _: &T = std::mem::transmute(om); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)` error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<'_, u8>`) - --> tests/ui/transmute_ptr_to_ref.rs:46:32 + --> tests/ui/transmute_ptr_to_ref.rs:42:32 | LL | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::>()` error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<'_, &u8>`) - --> tests/ui/transmute_ptr_to_ref.rs:49:33 + --> tests/ui/transmute_ptr_to_ref.rs:45:33 | LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::>()` error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`) - --> tests/ui/transmute_ptr_to_ref.rs:54:14 + --> tests/ui/transmute_ptr_to_ref.rs:50:14 | LL | unsafe { std::mem::transmute::<_, Bar>(raw) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const u8)` error: transmute from a pointer type (`*const u32`) to a reference type (`&i32`) - --> tests/ui/transmute_ptr_to_ref.rs:82:23 + --> tests/ui/transmute_ptr_to_ref.rs:78:23 | LL | let _: &i32 = std::mem::transmute(w); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(w.0 as *const i32)` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:84:23 + --> tests/ui/transmute_ptr_to_ref.rs:80:23 | LL | let _: &u32 = std::mem::transmute(w); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*w.0` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:86:24 + --> tests/ui/transmute_ptr_to_ref.rs:82:24 | LL | let _: &&u32 = core::mem::transmute(x); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.ptr.cast::<&u32>()` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:91:17 + --> tests/ui/transmute_ptr_to_ref.rs:87:17 | LL | let _ = std::mem::transmute::<_, &u32>(w); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*w.0.cast::()` error: transmute from a pointer type (`*const [&str]`) to a reference type (`&[&str]`) - --> tests/ui/transmute_ptr_to_ref.rs:93:26 + --> tests/ui/transmute_ptr_to_ref.rs:89:26 | LL | let _: &[&str] = core::mem::transmute(v); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(v.0 as *const [&str])` error: transmute from a pointer type (`*const [i32]`) to a reference type (`&[i32]`) - --> tests/ui/transmute_ptr_to_ref.rs:95:17 + --> tests/ui/transmute_ptr_to_ref.rs:91:17 | LL | let _ = std::mem::transmute::<_, &[i32]>(u); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(u.0 as *const [i32])` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:97:24 + --> tests/ui/transmute_ptr_to_ref.rs:93:24 | LL | let _: &&u32 = std::mem::transmute(y); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.0.cast::<&u32>()` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:99:23 + --> tests/ui/transmute_ptr_to_ref.rs:95:23 | LL | let _: &u32 = std::mem::transmute(w + w); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(w + w).0` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:107:18 + --> tests/ui/transmute_ptr_to_ref.rs:103:18 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:109:18 + --> tests/ui/transmute_ptr_to_ref.rs:105:18 | LL | 1 => std::mem::transmute(y), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:111:18 + --> tests/ui/transmute_ptr_to_ref.rs:107:18 | LL | 2 => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:113:18 + --> tests/ui/transmute_ptr_to_ref.rs:109:18 | LL | _ => std::mem::transmute::<_, &&'b u32>(y), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&'b u32>()` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:124:23 + --> tests/ui/transmute_ptr_to_ref.rs:120:23 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:126:23 + --> tests/ui/transmute_ptr_to_ref.rs:122:23 | LL | let _: &u32 = std::mem::transmute::<_, &u32>(a); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a.cast::()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:129:18 + --> tests/ui/transmute_ptr_to_ref.rs:125:18 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:131:18 + --> tests/ui/transmute_ptr_to_ref.rs:127:18 | LL | _ => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:142:23 + --> tests/ui/transmute_ptr_to_ref.rs:138:23 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:144:23 + --> tests/ui/transmute_ptr_to_ref.rs:140:23 | LL | let _: &u32 = std::mem::transmute::<_, &u32>(a); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a as *const u32)` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:146:17 + --> tests/ui/transmute_ptr_to_ref.rs:142:17 | LL | let _ = std::mem::transmute::<_, &u32>(Ptr(a)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(Ptr(a).0 as *const u32)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:149:18 + --> tests/ui/transmute_ptr_to_ref.rs:145:18 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &u32)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:151:18 + --> tests/ui/transmute_ptr_to_ref.rs:147:18 | LL | 1 => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &'b u32)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:153:18 + --> tests/ui/transmute_ptr_to_ref.rs:149:18 | LL | 2 => std::mem::transmute(y), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(y.0 as *const () as *const &u32)` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> tests/ui/transmute_ptr_to_ref.rs:155:18 + --> tests/ui/transmute_ptr_to_ref.rs:151:18 | LL | _ => std::mem::transmute::<_, &&'b u32>(y), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(y.0 as *const () as *const &'b u32)` error: transmute from a pointer type (`*const [i32]`) to a reference type (`&[u32]`) - --> tests/ui/transmute_ptr_to_ref.rs:165:17 + --> tests/ui/transmute_ptr_to_ref.rs:161:17 | LL | let _ = core::mem::transmute::<_, &[u32]>(ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(ptr as *const [u32])` error: transmute from a pointer type (`*const [i32]`) to a reference type (`&[u32]`) - --> tests/ui/transmute_ptr_to_ref.rs:167:25 + --> tests/ui/transmute_ptr_to_ref.rs:163:25 | LL | let _: &[u32] = core::mem::transmute(ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(ptr as *const [u32])` error: transmute from a pointer type (`*const [&str]`) to a reference type (`&[&[u8]]`) - --> tests/ui/transmute_ptr_to_ref.rs:171:17 + --> tests/ui/transmute_ptr_to_ref.rs:167:17 | LL | let _ = core::mem::transmute::<_, &[&[u8]]>(a_s_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a_s_ptr as *const [&[u8]])` error: transmute from a pointer type (`*const [&str]`) to a reference type (`&[&[u8]]`) - --> tests/ui/transmute_ptr_to_ref.rs:173:27 + --> tests/ui/transmute_ptr_to_ref.rs:169:27 | LL | let _: &[&[u8]] = core::mem::transmute(a_s_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a_s_ptr as *const [&[u8]])` error: transmute from a pointer type (`*const [i32]`) to a reference type (`&[i32]`) - --> tests/ui/transmute_ptr_to_ref.rs:177:17 + --> tests/ui/transmute_ptr_to_ref.rs:173:17 | LL | let _ = core::mem::transmute::<_, &[i32]>(ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(ptr as *const [i32])` error: transmute from a pointer type (`*const [i32]`) to a reference type (`&[i32]`) - --> tests/ui/transmute_ptr_to_ref.rs:179:25 + --> tests/ui/transmute_ptr_to_ref.rs:175:25 | LL | let _: &[i32] = core::mem::transmute(ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*ptr` error: transmute from a pointer type (`*const [&str]`) to a reference type (`&[&str]`) - --> tests/ui/transmute_ptr_to_ref.rs:183:17 + --> tests/ui/transmute_ptr_to_ref.rs:179:17 | LL | let _ = core::mem::transmute::<_, &[&str]>(a_s_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a_s_ptr as *const [&str])` error: transmute from a pointer type (`*const [&str]`) to a reference type (`&[&str]`) - --> tests/ui/transmute_ptr_to_ref.rs:185:26 + --> tests/ui/transmute_ptr_to_ref.rs:181:26 | LL | let _: &[&str] = core::mem::transmute(a_s_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a_s_ptr as *const [&str])` diff --git a/tests/ui/transmute_ref_to_ref.fixed b/tests/ui/transmute_ref_to_ref.fixed index 0ec59ea810aed..e369e18d77ecd 100644 --- a/tests/ui/transmute_ref_to_ref.fixed +++ b/tests/ui/transmute_ref_to_ref.fixed @@ -1,5 +1,5 @@ -#![deny(clippy::transmute_ptr_to_ptr)] -#![allow(dead_code, clippy::missing_transmute_annotations, clippy::cast_slice_different_sizes)] +#![warn(clippy::transmute_ptr_to_ptr)] +#![allow(clippy::cast_slice_different_sizes)] fn main() { unsafe { diff --git a/tests/ui/transmute_ref_to_ref.rs b/tests/ui/transmute_ref_to_ref.rs index 78f3d1fe0bb24..35177b40fbca5 100644 --- a/tests/ui/transmute_ref_to_ref.rs +++ b/tests/ui/transmute_ref_to_ref.rs @@ -1,5 +1,5 @@ -#![deny(clippy::transmute_ptr_to_ptr)] -#![allow(dead_code, clippy::missing_transmute_annotations, clippy::cast_slice_different_sizes)] +#![warn(clippy::transmute_ptr_to_ptr)] +#![allow(clippy::cast_slice_different_sizes)] fn main() { unsafe { diff --git a/tests/ui/transmute_ref_to_ref.stderr b/tests/ui/transmute_ref_to_ref.stderr index 13ee64574f7b9..222a5d7e80710 100644 --- a/tests/ui/transmute_ref_to_ref.stderr +++ b/tests/ui/transmute_ref_to_ref.stderr @@ -4,11 +4,8 @@ error: transmute from a reference to a reference LL | let bools: &[bool] = unsafe { std::mem::transmute(single_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(single_u64 as *const [u64] as *const [bool])` | -note: the lint level is defined here - --> tests/ui/transmute_ref_to_ref.rs:1:9 - | -LL | #![deny(clippy::transmute_ptr_to_ptr)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` error: transmute from a reference to a reference --> tests/ui/transmute_ref_to_ref.rs:11:33 diff --git a/tests/ui/transmute_ref_to_ref_no_std.fixed b/tests/ui/transmute_ref_to_ref_no_std.fixed index 3a1c75f168546..319d305b5c1c6 100644 --- a/tests/ui/transmute_ref_to_ref_no_std.fixed +++ b/tests/ui/transmute_ref_to_ref_no_std.fixed @@ -1,5 +1,5 @@ -#![deny(clippy::transmute_ptr_to_ptr)] -#![allow(dead_code, clippy::missing_transmute_annotations, clippy::cast_slice_different_sizes)] +#![warn(clippy::transmute_ptr_to_ptr)] +#![allow(clippy::cast_slice_different_sizes)] #![feature(lang_items)] #![no_std] diff --git a/tests/ui/transmute_ref_to_ref_no_std.rs b/tests/ui/transmute_ref_to_ref_no_std.rs index 7ed885bbbb07e..1f6d01b7e6ebc 100644 --- a/tests/ui/transmute_ref_to_ref_no_std.rs +++ b/tests/ui/transmute_ref_to_ref_no_std.rs @@ -1,5 +1,5 @@ -#![deny(clippy::transmute_ptr_to_ptr)] -#![allow(dead_code, clippy::missing_transmute_annotations, clippy::cast_slice_different_sizes)] +#![warn(clippy::transmute_ptr_to_ptr)] +#![allow(clippy::cast_slice_different_sizes)] #![feature(lang_items)] #![no_std] diff --git a/tests/ui/transmute_ref_to_ref_no_std.stderr b/tests/ui/transmute_ref_to_ref_no_std.stderr index 136a9b21fb9e9..7c9b37f319cca 100644 --- a/tests/ui/transmute_ref_to_ref_no_std.stderr +++ b/tests/ui/transmute_ref_to_ref_no_std.stderr @@ -4,11 +4,8 @@ error: transmute from a reference to a reference LL | let bools: &[bool] = unsafe { core::mem::transmute(single_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(single_u64 as *const [u64] as *const [bool])` | -note: the lint level is defined here - --> tests/ui/transmute_ref_to_ref_no_std.rs:1:9 - | -LL | #![deny(clippy::transmute_ptr_to_ptr)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` error: transmute from a reference to a reference --> tests/ui/transmute_ref_to_ref_no_std.rs:23:33 diff --git a/tests/ui/transmute_undefined_repr.rs b/tests/ui/transmute_undefined_repr.rs index a449d6a4302f8..4a92f24af7ce1 100644 --- a/tests/ui/transmute_undefined_repr.rs +++ b/tests/ui/transmute_undefined_repr.rs @@ -1,10 +1,5 @@ #![warn(clippy::transmute_undefined_repr)] -#![allow( - clippy::unit_arg, - clippy::transmute_ptr_to_ref, - clippy::useless_transmute, - clippy::missing_transmute_annotations -)] +#![expect(clippy::transmute_ptr_to_ref, clippy::unit_arg)] use core::any::TypeId; use core::ffi::c_void; diff --git a/tests/ui/transmute_undefined_repr.stderr b/tests/ui/transmute_undefined_repr.stderr index a259ef784c782..4e208843f374e 100644 --- a/tests/ui/transmute_undefined_repr.stderr +++ b/tests/ui/transmute_undefined_repr.stderr @@ -1,5 +1,5 @@ error: transmute from `Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:34:33 + --> tests/ui/transmute_undefined_repr.rs:29:33 | LL | let _: Ty2C = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,13 +8,13 @@ LL | let _: Ty2C = transmute(value::>()); = help: to override `-D warnings` add `#[allow(clippy::transmute_undefined_repr)]` error: transmute into `Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:38:32 + --> tests/ui/transmute_undefined_repr.rs:33:32 | LL | let _: Ty2 = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `Ty>` to `Ty2`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:47:32 + --> tests/ui/transmute_undefined_repr.rs:42:32 | LL | let _: Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | let _: Ty2 = transmute(value::>>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty2` to `Ty>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:51:36 + --> tests/ui/transmute_undefined_repr.rs:46:36 | LL | let _: Ty> = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | let _: Ty> = transmute(value::>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty<&Ty2>` to `&Ty2`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:58:33 + --> tests/ui/transmute_undefined_repr.rs:53:33 | LL | let _: &Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL | let _: &Ty2 = transmute(value::>>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `&Ty2` to `Ty<&Ty2>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:62:37 + --> tests/ui/transmute_undefined_repr.rs:57:37 | LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `std::boxed::Box>` to `&mut Ty2`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:91:45 + --> tests/ui/transmute_undefined_repr.rs:86:45 | LL | let _: &'static mut Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | let _: &'static mut Ty2 = transmute(value::` to `std::boxed::Box>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:95:37 + --> tests/ui/transmute_undefined_repr.rs:90:37 | LL | let _: Box> = transmute(value::<&'static mut Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL | let _: Box> = transmute(value::<&'static mut Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:191:39 + --> tests/ui/transmute_undefined_repr.rs:186:39 | LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | let _: *const Ty2 = transmute(value::<*const Ty2C` has an undefined layout error: transmute from `*const Ty2` which has an undefined layout - --> tests/ui/transmute_undefined_repr.rs:195:50 + --> tests/ui/transmute_undefined_repr.rs:190:50 | LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -78,7 +78,7 @@ LL | let _: *const Ty2C> = transmute(value::<*const T = note: the contained type `Ty2` has an undefined layout error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:241:35 + --> tests/ui/transmute_undefined_repr.rs:236:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL | let _: Vec> = transmute(value::>>()); = note: two instances of the same generic type (`Vec`) may have different layouts error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> tests/ui/transmute_undefined_repr.rs:245:35 + --> tests/ui/transmute_undefined_repr.rs:240:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index f332e02a2d327..44a2db2aba64c 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -1,9 +1,11 @@ -#![warn(clippy::transmutes_expressible_as_ptr_casts)] -// These two warnings currently cover the cases transmutes_expressible_as_ptr_casts -// would otherwise be responsible for -#![warn(clippy::useless_transmute)] -#![warn(clippy::transmute_ptr_to_ptr)] -#![allow(unused, clippy::borrow_as_ptr, clippy::missing_transmute_annotations)] +// `clippy::transmutes_ptr_to_ptr` and `clippy::useless_transmute` currently cover the cases +// `transmutes_expressible_as_ptr_casts` would otherwise be responsible for +#![warn( + clippy::transmute_ptr_to_ptr, + clippy::transmutes_expressible_as_ptr_casts, + clippy::useless_transmute +)] +#![expect(clippy::missing_transmute_annotations)] #![allow(function_casts_as_integer)] use std::mem::{size_of, transmute}; @@ -92,7 +94,7 @@ fn issue_10449() { } // Pointers cannot be cast to integers in const contexts -#[allow( +#[expect( ptr_to_integer_transmute_in_consts, reason = "This is tested in the compiler test suite" )] diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index c29a42ddca53b..80d47017852b7 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -1,9 +1,11 @@ -#![warn(clippy::transmutes_expressible_as_ptr_casts)] -// These two warnings currently cover the cases transmutes_expressible_as_ptr_casts -// would otherwise be responsible for -#![warn(clippy::useless_transmute)] -#![warn(clippy::transmute_ptr_to_ptr)] -#![allow(unused, clippy::borrow_as_ptr, clippy::missing_transmute_annotations)] +// `clippy::transmutes_ptr_to_ptr` and `clippy::useless_transmute` currently cover the cases +// `transmutes_expressible_as_ptr_casts` would otherwise be responsible for +#![warn( + clippy::transmute_ptr_to_ptr, + clippy::transmutes_expressible_as_ptr_casts, + clippy::useless_transmute +)] +#![expect(clippy::missing_transmute_annotations)] #![allow(function_casts_as_integer)] use std::mem::{size_of, transmute}; @@ -92,7 +94,7 @@ fn issue_10449() { } // Pointers cannot be cast to integers in const contexts -#[allow( +#[expect( ptr_to_integer_transmute_in_consts, reason = "This is tested in the compiler test suite" )] diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 5ddc3de6a039f..bc0f0109886ad 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -1,5 +1,5 @@ error: transmute from a pointer to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:20:38 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:22:38 | LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + let _ptr_i8_transmute = unsafe { ptr_i32.cast::() }; | error: transmute from a pointer to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:27:46 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:29:46 | LL | let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u32]>(slice_ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _ptr_to_unsized_transmute = unsafe { slice_ptr as *const [u32] }; | error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:34:50 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:36:50 | LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` @@ -34,7 +34,7 @@ LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, us = help: to override `-D warnings` add `#[allow(clippy::transmutes_expressible_as_ptr_casts)]` error: transmute from a reference to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:41:41 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:43:41 | LL | let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]` @@ -43,31 +43,31 @@ LL | let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from `fn(usize) -> u8` to `*const usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:50:41 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:52:41 | LL | let _usize_ptr_transmute = unsafe { transmute:: u8, *const usize>(foo) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as *const usize` error: transmute from `fn(usize) -> u8` to `usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:55:49 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:57:49 | LL | let _usize_from_fn_ptr_transmute = unsafe { transmute:: u8, usize>(foo) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `foo as usize` error: transmute from `*const u32` to `usize` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:59:36 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:61:36 | LL | let _usize_from_ref = unsafe { transmute::<*const u32, usize>(&1u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&1u32 as *const u32 as usize` error: transmute from a reference to a pointer - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:71:14 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:73:14 | LL | unsafe { transmute::<&[i32; 1], *const u8>(in_param) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `in_param as *const [i32; 1] as *const u8` error: transmute from `fn()` to `*const u8` which could be expressed as a pointer cast instead - --> tests/ui/transmutes_expressible_as_ptr_casts.rs:90:28 + --> tests/ui/transmutes_expressible_as_ptr_casts.rs:92:28 | LL | let _x: u8 = unsafe { *std::mem::transmute::(f) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(f as *const u8)` diff --git a/tests/ui/transmuting_null.rs b/tests/ui/transmuting_null.rs index c2de798ab3082..b6ff746e98224 100644 --- a/tests/ui/transmuting_null.rs +++ b/tests/ui/transmuting_null.rs @@ -1,9 +1,6 @@ -#![allow(dead_code)] #![warn(clippy::transmuting_null)] -#![allow(clippy::zero_ptr)] +#![expect(clippy::manual_dangling_ptr, clippy::zero_ptr)] #![allow(clippy::transmute_ptr_to_ref)] -#![allow(clippy::eq_op, clippy::missing_transmute_annotations)] -#![allow(clippy::manual_dangling_ptr)] // Easy to lint because these only span one line. fn one_liners() { diff --git a/tests/ui/transmuting_null.stderr b/tests/ui/transmuting_null.stderr index 3c6c28f31d0db..c19dfcf9926b5 100644 --- a/tests/ui/transmuting_null.stderr +++ b/tests/ui/transmuting_null.stderr @@ -1,5 +1,5 @@ error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:11:23 + --> tests/ui/transmuting_null.rs:8:23 | LL | let _: &u64 = std::mem::transmute(0 as *const u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,43 +8,43 @@ LL | let _: &u64 = std::mem::transmute(0 as *const u64); = help: to override `-D warnings` add `#[allow(clippy::transmuting_null)]` error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:14:23 + --> tests/ui/transmuting_null.rs:11:23 | LL | let _: &u64 = std::mem::transmute(std::ptr::null::()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:25:23 + --> tests/ui/transmuting_null.rs:22:23 | LL | let _: &u64 = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:35:23 + --> tests/ui/transmuting_null.rs:32:23 | LL | let _: &u64 = std::mem::transmute(u64::MIN as *const u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:42:23 + --> tests/ui/transmuting_null.rs:39:23 | LL | let _: &u64 = std::mem::transmute({ 0 as *const u64 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:45:23 + --> tests/ui/transmuting_null.rs:42:23 | LL | let _: &u64 = std::mem::transmute(const { u64::MIN as *const u64 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:52:23 + --> tests/ui/transmuting_null.rs:49:23 | LL | let _: &u64 = std::mem::transmute(std::ptr::without_provenance::(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> tests/ui/transmuting_null.rs:55:23 + --> tests/ui/transmuting_null.rs:52:23 | LL | let _: &u64 = std::mem::transmute(std::ptr::without_provenance_mut::(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/trim_split_whitespace.fixed b/tests/ui/trim_split_whitespace.fixed index 434e91b7d9530..b5f3dd0ffde0b 100644 --- a/tests/ui/trim_split_whitespace.fixed +++ b/tests/ui/trim_split_whitespace.fixed @@ -1,5 +1,5 @@ #![warn(clippy::trim_split_whitespace)] -#![allow(clippy::let_unit_value)] +#![expect(clippy::let_unit_value)] struct Custom; impl Custom { @@ -39,7 +39,6 @@ impl std::ops::Deref for DerefStrAndCustomSplit { } } impl DerefStrAndCustomSplit { - #[allow(dead_code)] fn split_whitespace(self) {} } diff --git a/tests/ui/trim_split_whitespace.rs b/tests/ui/trim_split_whitespace.rs index b939ecdfba854..80a113367f086 100644 --- a/tests/ui/trim_split_whitespace.rs +++ b/tests/ui/trim_split_whitespace.rs @@ -1,5 +1,5 @@ #![warn(clippy::trim_split_whitespace)] -#![allow(clippy::let_unit_value)] +#![expect(clippy::let_unit_value)] struct Custom; impl Custom { @@ -39,7 +39,6 @@ impl std::ops::Deref for DerefStrAndCustomSplit { } } impl DerefStrAndCustomSplit { - #[allow(dead_code)] fn split_whitespace(self) {} } diff --git a/tests/ui/trim_split_whitespace.stderr b/tests/ui/trim_split_whitespace.stderr index f242dd8021156..9ad0be5d41818 100644 --- a/tests/ui/trim_split_whitespace.stderr +++ b/tests/ui/trim_split_whitespace.stderr @@ -1,5 +1,5 @@ error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:61:23 + --> tests/ui/trim_split_whitespace.rs:60:23 | LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` @@ -8,43 +8,43 @@ LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint = help: to override `-D warnings` add `#[allow(clippy::trim_split_whitespace)]` error: found call to `str::trim_start` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:64:23 + --> tests/ui/trim_split_whitespace.rs:63:23 | LL | let _ = " A B C ".trim_start().split_whitespace(); // should trigger lint | ^^^^^^^^^^^^^ help: remove `trim_start()` error: found call to `str::trim_end` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:67:23 + --> tests/ui/trim_split_whitespace.rs:66:23 | LL | let _ = " A B C ".trim_end().split_whitespace(); // should trigger lint | ^^^^^^^^^^^ help: remove `trim_end()` error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:72:37 + --> tests/ui/trim_split_whitespace.rs:71:37 | LL | let _ = (" A B C ").to_string().trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` error: found call to `str::trim_start` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:75:37 + --> tests/ui/trim_split_whitespace.rs:74:37 | LL | let _ = (" A B C ").to_string().trim_start().split_whitespace(); // should trigger lint | ^^^^^^^^^^^^^ help: remove `trim_start()` error: found call to `str::trim_end` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:78:37 + --> tests/ui/trim_split_whitespace.rs:77:37 | LL | let _ = (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint | ^^^^^^^^^^^ help: remove `trim_end()` error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:87:15 + --> tests/ui/trim_split_whitespace.rs:86:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` error: found call to `str::trim` before `str::split_whitespace` - --> tests/ui/trim_split_whitespace.rs:97:15 + --> tests/ui/trim_split_whitespace.rs:96:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` diff --git a/tests/ui/trivially_copy_pass_by_ref.fixed b/tests/ui/trivially_copy_pass_by_ref.fixed index 1a07f119398aa..637941ce950f5 100644 --- a/tests/ui/trivially_copy_pass_by_ref.fixed +++ b/tests/ui/trivially_copy_pass_by_ref.fixed @@ -1,14 +1,8 @@ //@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)" //@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)" -#![deny(clippy::trivially_copy_pass_by_ref)] -#![allow( - clippy::disallowed_names, - clippy::extra_unused_lifetimes, - clippy::needless_lifetimes, - clippy::needless_pass_by_ref_mut, - clippy::redundant_field_names, - clippy::uninlined_format_args -)] +#![warn(clippy::trivially_copy_pass_by_ref)] +#![allow(clippy::extra_unused_lifetimes)] +#![expect(clippy::disallowed_names, clippy::needless_lifetimes)] #[derive(Copy, Clone)] struct Foo(u32); diff --git a/tests/ui/trivially_copy_pass_by_ref.rs b/tests/ui/trivially_copy_pass_by_ref.rs index 07b1842bbf856..9cdfc32ec03ce 100644 --- a/tests/ui/trivially_copy_pass_by_ref.rs +++ b/tests/ui/trivially_copy_pass_by_ref.rs @@ -1,14 +1,8 @@ //@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)" //@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)" -#![deny(clippy::trivially_copy_pass_by_ref)] -#![allow( - clippy::disallowed_names, - clippy::extra_unused_lifetimes, - clippy::needless_lifetimes, - clippy::needless_pass_by_ref_mut, - clippy::redundant_field_names, - clippy::uninlined_format_args -)] +#![warn(clippy::trivially_copy_pass_by_ref)] +#![allow(clippy::extra_unused_lifetimes)] +#![expect(clippy::disallowed_names, clippy::needless_lifetimes)] #[derive(Copy, Clone)] struct Foo(u32); diff --git a/tests/ui/trivially_copy_pass_by_ref.stderr b/tests/ui/trivially_copy_pass_by_ref.stderr index 36247d3fe0b17..0a8bb545b5ddb 100644 --- a/tests/ui/trivially_copy_pass_by_ref.stderr +++ b/tests/ui/trivially_copy_pass_by_ref.stderr @@ -1,113 +1,110 @@ error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:54:11 + --> tests/ui/trivially_copy_pass_by_ref.rs:48:11 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` | -note: the lint level is defined here - --> tests/ui/trivially_copy_pass_by_ref.rs:3:9 - | -LL | #![deny(clippy::trivially_copy_pass_by_ref)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trivially_copy_pass_by_ref)]` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:54:20 + --> tests/ui/trivially_copy_pass_by_ref.rs:48:20 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:54:29 + --> tests/ui/trivially_copy_pass_by_ref.rs:48:29 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:64:12 + --> tests/ui/trivially_copy_pass_by_ref.rs:58:12 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^^ help: consider passing by value instead: `self` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:64:22 + --> tests/ui/trivially_copy_pass_by_ref.rs:58:22 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:64:31 + --> tests/ui/trivially_copy_pass_by_ref.rs:58:31 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:64:40 + --> tests/ui/trivially_copy_pass_by_ref.rs:58:40 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:70:16 + --> tests/ui/trivially_copy_pass_by_ref.rs:64:16 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:70:25 + --> tests/ui/trivially_copy_pass_by_ref.rs:64:25 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:70:34 + --> tests/ui/trivially_copy_pass_by_ref.rs:64:34 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:75:35 + --> tests/ui/trivially_copy_pass_by_ref.rs:69:35 | LL | fn bad_issue7518(self, other: &Self) {} | ^^^^^ help: consider passing by value instead: `Self` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:88:16 + --> tests/ui/trivially_copy_pass_by_ref.rs:82:16 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:88:25 + --> tests/ui/trivially_copy_pass_by_ref.rs:82:25 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:88:34 + --> tests/ui/trivially_copy_pass_by_ref.rs:82:34 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:95:33 + --> tests/ui/trivially_copy_pass_by_ref.rs:89:33 | LL | fn trait_method(&self, foo: &Foo); | ^^^^ help: consider passing by value instead: `Foo` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:133:21 + --> tests/ui/trivially_copy_pass_by_ref.rs:127:21 | LL | fn foo_never(x: &i32) { | ^^^^ help: consider passing by value instead: `i32` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:139:15 + --> tests/ui/trivially_copy_pass_by_ref.rs:133:15 | LL | fn foo(x: &i32) { | ^^^^ help: consider passing by value instead: `i32` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> tests/ui/trivially_copy_pass_by_ref.rs:165:36 + --> tests/ui/trivially_copy_pass_by_ref.rs:159:36 | LL | fn unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 { | ^^^^^^^ help: consider passing by value instead: `u32` diff --git a/tests/ui/try_err.fixed b/tests/ui/try_err.fixed index bec366f4fd604..415cf50b1ddaa 100644 --- a/tests/ui/try_err.fixed +++ b/tests/ui/try_err.fixed @@ -1,11 +1,7 @@ //@aux-build:proc_macros.rs #![feature(try_blocks)] -#![deny(clippy::try_err)] -#![allow( - clippy::unnecessary_wraps, - clippy::needless_question_mark, - clippy::needless_return_with_question_mark -)] +#![warn(clippy::try_err)] +#![allow(clippy::needless_return_with_question_mark)] extern crate proc_macros; use proc_macros::{external, inline_macros}; diff --git a/tests/ui/try_err.rs b/tests/ui/try_err.rs index 9c10acd2ce0ad..362d1a63b82c8 100644 --- a/tests/ui/try_err.rs +++ b/tests/ui/try_err.rs @@ -1,11 +1,7 @@ //@aux-build:proc_macros.rs #![feature(try_blocks)] -#![deny(clippy::try_err)] -#![allow( - clippy::unnecessary_wraps, - clippy::needless_question_mark, - clippy::needless_return_with_question_mark -)] +#![warn(clippy::try_err)] +#![allow(clippy::needless_return_with_question_mark)] extern crate proc_macros; use proc_macros::{external, inline_macros}; diff --git a/tests/ui/try_err.stderr b/tests/ui/try_err.stderr index 3ca51e9d88915..0b4c5ec0c5a17 100644 --- a/tests/ui/try_err.stderr +++ b/tests/ui/try_err.stderr @@ -1,35 +1,32 @@ error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:22:9 + --> tests/ui/try_err.rs:18:9 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err)` | -note: the lint level is defined here - --> tests/ui/try_err.rs:3:9 - | -LL | #![deny(clippy::try_err)] - | ^^^^^^^^^^^^^^^ + = note: `-D clippy::try-err` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::try_err)]` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:33:9 + --> tests/ui/try_err.rs:29:9 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err.into())` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:54:17 + --> tests/ui/try_err.rs:50:17 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err)` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:74:17 + --> tests/ui/try_err.rs:70:17 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err.into())` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:95:23 + --> tests/ui/try_err.rs:91:23 | LL | Err(_) => Err(1)?, | ^^^^^^^ help: try: `return Err(1)` @@ -37,7 +34,7 @@ LL | Err(_) => Err(1)?, = note: this error originates in the macro `__inline_mac_fn_calling_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:103:23 + --> tests/ui/try_err.rs:99:23 | LL | Err(_) => Err(inline!(1))?, | ^^^^^^^^^^^^^^^^ help: try: `return Err(inline!(1))` @@ -45,31 +42,31 @@ LL | Err(_) => Err(inline!(1))?, = note: this error originates in the macro `__inline_mac_fn_calling_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:124:9 + --> tests/ui/try_err.rs:120:9 | LL | Err(inline!(inline!(String::from("aasdfasdfasdfa"))))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Err(inline!(inline!(String::from("aasdfasdfasdfa"))))` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:132:9 + --> tests/ui/try_err.rs:128:9 | LL | Err(io::ErrorKind::WriteZero)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:135:9 + --> tests/ui/try_err.rs:131:9 | LL | Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:144:9 + --> tests/ui/try_err.rs:140:9 | LL | Err(io::ErrorKind::NotFound)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))` error: returning an `Err(_)` with the `?` operator - --> tests/ui/try_err.rs:154:16 + --> tests/ui/try_err.rs:150:16 | LL | return Err(42)?; | ^^^^^^^^ help: try: `Err(42)` diff --git a/tests/ui/tuple_array_conversions.rs b/tests/ui/tuple_array_conversions.rs index 599019dca031d..40b1720af1299 100644 --- a/tests/ui/tuple_array_conversions.rs +++ b/tests/ui/tuple_array_conversions.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(clippy::no_effect, clippy::useless_vec, unused)] #![warn(clippy::tuple_array_conversions)] +#![expect(clippy::no_effect, clippy::useless_vec)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/type_complexity.rs b/tests/ui/type_complexity.rs index 9d145516d6107..fcc4e7757feb4 100644 --- a/tests/ui/type_complexity.rs +++ b/tests/ui/type_complexity.rs @@ -1,5 +1,5 @@ #![feature(associated_type_defaults)] -#![allow(clippy::needless_pass_by_value, clippy::vec_box, clippy::useless_vec)] +#![warn(clippy::type_complexity)] type Alias = Vec>>; // no warning here diff --git a/tests/ui/type_repetition_in_bounds.rs b/tests/ui/type_repetition_in_bounds.rs index e75678d5fd93e..b1041e3053430 100644 --- a/tests/ui/type_repetition_in_bounds.rs +++ b/tests/ui/type_repetition_in_bounds.rs @@ -1,9 +1,5 @@ -#![deny(clippy::type_repetition_in_bounds)] -#![allow( - clippy::extra_unused_type_parameters, - clippy::multiple_bound_locations, - clippy::needless_maybe_sized -)] +#![warn(clippy::type_repetition_in_bounds)] +#![expect(clippy::multiple_bound_locations, clippy::needless_maybe_sized)] use serde::Deserialize; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; diff --git a/tests/ui/type_repetition_in_bounds.stderr b/tests/ui/type_repetition_in_bounds.stderr index de1b14da1985f..562d486a82982 100644 --- a/tests/ui/type_repetition_in_bounds.stderr +++ b/tests/ui/type_repetition_in_bounds.stderr @@ -1,18 +1,15 @@ error: type `T` has already been used as a bound predicate - --> tests/ui/type_repetition_in_bounds.rs:14:5 + --> tests/ui/type_repetition_in_bounds.rs:10:5 | LL | T: Clone, | ^^^^^^^^ | = help: consider combining the bounds: `T: Copy + Clone` -note: the lint level is defined here - --> tests/ui/type_repetition_in_bounds.rs:1:9 - | -LL | #![deny(clippy::type_repetition_in_bounds)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::type-repetition-in-bounds` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::type_repetition_in_bounds)]` error: type `Self` has already been used as a bound predicate - --> tests/ui/type_repetition_in_bounds.rs:32:5 + --> tests/ui/type_repetition_in_bounds.rs:28:5 | LL | Self: Copy + Default + Ord, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +17,7 @@ LL | Self: Copy + Default + Ord, = help: consider combining the bounds: `Self: Clone + Copy + Default + Ord` error: type `T` has already been used as a bound predicate - --> tests/ui/type_repetition_in_bounds.rs:107:5 + --> tests/ui/type_repetition_in_bounds.rs:103:5 | LL | T: Clone, | ^^^^^^^^ @@ -28,7 +25,7 @@ LL | T: Clone, = help: consider combining the bounds: `T: ?Sized + Clone` error: type `T` has already been used as a bound predicate - --> tests/ui/type_repetition_in_bounds.rs:113:5 + --> tests/ui/type_repetition_in_bounds.rs:109:5 | LL | T: ?Sized, | ^^^^^^^^^ @@ -36,7 +33,7 @@ LL | T: ?Sized, = help: consider combining the bounds: `T: Clone + ?Sized` error: type `T` has already been used as a bound predicate - --> tests/ui/type_repetition_in_bounds.rs:139:9 + --> tests/ui/type_repetition_in_bounds.rs:135:9 | LL | T: Trait, Box<[String]>, bool> + 'static, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +41,7 @@ LL | T: Trait, Box<[String]>, bool> + 'static, = help: consider combining the bounds: `T: ?Sized + Trait, Box<[String]>, bool> + 'static` error: type `K` has already been used as a bound predicate - --> tests/ui/type_repetition_in_bounds.rs:148:5 + --> tests/ui/type_repetition_in_bounds.rs:144:5 | LL | K: Clone, | ^^^^^^^^ @@ -52,7 +49,7 @@ LL | K: Clone, = help: consider combining the bounds: `K: 'a + Clone` error: type `Vec` has already been used as a bound predicate - --> tests/ui/type_repetition_in_bounds.rs:157:5 + --> tests/ui/type_repetition_in_bounds.rs:153:5 | LL | Vec: Clone, | ^^^^^^^^^^^^^ diff --git a/tests/ui/unconditional_recursion.rs b/tests/ui/unconditional_recursion.rs index 20b4198d63926..fb4f7b5035785 100644 --- a/tests/ui/unconditional_recursion.rs +++ b/tests/ui/unconditional_recursion.rs @@ -1,9 +1,9 @@ #![warn(clippy::unconditional_recursion)] -#![allow( - clippy::partialeq_ne_impl, +#![expect( clippy::default_constructed_unit_structs, + clippy::needless_lifetimes, clippy::only_used_in_recursion, - clippy::needless_lifetimes + clippy::partialeq_ne_impl )] enum Foo { diff --git a/tests/ui/unicode.fixed b/tests/ui/unicode.fixed index 0a49b17005828..40e062955ef39 100644 --- a/tests/ui/unicode.fixed +++ b/tests/ui/unicode.fixed @@ -1,7 +1,6 @@ -#![allow(dead_code)] - -#[warn(clippy::invisible_characters)] fn zero() { + #![warn(clippy::invisible_characters)] + print!("Here >\u{200B}< is a ZWS, and \u{200B}another"); //~^ invisible_characters print!("This\u{200B}is\u{200B}fine"); @@ -13,15 +12,16 @@ fn zero() { print!("This\u{2060}is\u{2060}fine"); } -#[warn(clippy::unicode_not_nfc)] fn canon() { + #![warn(clippy::unicode_not_nfc)] + print!("̀àh?"); //~^ unicode_not_nfc print!("a\u{0300}h?"); // also ok } mod non_ascii_literal { - #![deny(clippy::non_ascii_literal)] + #![warn(clippy::non_ascii_literal)] fn uni() { print!("\u{dc}ben!"); @@ -43,8 +43,6 @@ mod non_ascii_literal { } mod issue_8263 { - #![deny(clippy::non_ascii_literal)] - // Re-allow for a single test #[test] #[allow(clippy::non_ascii_literal)] @@ -81,7 +79,7 @@ mod ascii_value_from_non_ascii_snippet { // The reverse: `file!()` produces an ASCII value (the file path), but the // literal's span covers the whole macro invocation, so the snippet is // non-ASCII and the lint must fire. Checking the value would miss it. - #![deny(clippy::non_ascii_literal)] + #![warn(clippy::non_ascii_literal)] macro_rules! with_location { ($($arg:tt)*) => { diff --git a/tests/ui/unicode.rs b/tests/ui/unicode.rs index f1a1ab290aecc..876a3fee201eb 100644 --- a/tests/ui/unicode.rs +++ b/tests/ui/unicode.rs @@ -1,7 +1,6 @@ -#![allow(dead_code)] - -#[warn(clippy::invisible_characters)] fn zero() { + #![warn(clippy::invisible_characters)] + print!("Here >​< is a ZWS, and ​another"); //~^ invisible_characters print!("This\u{200B}is\u{200B}fine"); @@ -13,15 +12,16 @@ fn zero() { print!("This\u{2060}is\u{2060}fine"); } -#[warn(clippy::unicode_not_nfc)] fn canon() { + #![warn(clippy::unicode_not_nfc)] + print!("̀àh?"); //~^ unicode_not_nfc print!("a\u{0300}h?"); // also ok } mod non_ascii_literal { - #![deny(clippy::non_ascii_literal)] + #![warn(clippy::non_ascii_literal)] fn uni() { print!("Üben!"); @@ -43,8 +43,6 @@ mod non_ascii_literal { } mod issue_8263 { - #![deny(clippy::non_ascii_literal)] - // Re-allow for a single test #[test] #[allow(clippy::non_ascii_literal)] @@ -81,7 +79,7 @@ mod ascii_value_from_non_ascii_snippet { // The reverse: `file!()` produces an ASCII value (the file path), but the // literal's span covers the whole macro invocation, so the snippet is // non-ASCII and the lint must fire. Checking the value would miss it. - #![deny(clippy::non_ascii_literal)] + #![warn(clippy::non_ascii_literal)] macro_rules! with_location { ($($arg:tt)*) => { diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index 32b0933913008..ea6d90f3c7f3c 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -1,5 +1,5 @@ error: invisible character detected - --> tests/ui/unicode.rs:5:12 + --> tests/ui/unicode.rs:4:12 | LL | print!("Here >​< is a ZWS, and ​another"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{200B}< is a ZWS, and \u{200B}another"` @@ -8,13 +8,13 @@ LL | print!("Here >​< is a ZWS, and ​another"); = help: to override `-D warnings` add `#[allow(clippy::invisible_characters)]` error: invisible character detected - --> tests/ui/unicode.rs:8:12 + --> tests/ui/unicode.rs:7:12 | LL | print!("Here >­< is a SHY, and ­another"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{AD}< is a SHY, and \u{AD}another"` error: invisible character detected - --> tests/ui/unicode.rs:11:12 + --> tests/ui/unicode.rs:10:12 | LL | print!("Here >⁠< is a WJ, and ⁠another"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{2060}< is a WJ, and \u{2060}another"` @@ -34,11 +34,8 @@ error: literal non-ASCII character detected LL | print!("Üben!"); | ^^^^^^^ help: consider replacing the string with: `"\u{dc}ben!"` | -note: the lint level is defined here - --> tests/ui/unicode.rs:24:13 - | -LL | #![deny(clippy::non_ascii_literal)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::non-ascii-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_ascii_literal)]` error: literal non-ASCII character detected --> tests/ui/unicode.rs:34:36 @@ -53,28 +50,16 @@ LL | const _FULL_BLOCK: char = '▰'; | ^^^ help: consider replacing the string with: `'\u{25b0}'` error: literal non-ASCII character detected - --> tests/ui/unicode.rs:57:21 + --> tests/ui/unicode.rs:55:21 | LL | let _ = "悲しいかな、ここに日本語を書くことはできない。"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"\u{60b2}\u{3057}\u{3044}\u{304b}\u{306a}\u{3001}\u{3053}\u{3053}\u{306b}\u{65e5}\u{672c}\u{8a9e}\u{3092}\u{66f8}\u{304f}\u{3053}\u{3068}\u{306f}\u{3067}\u{304d}\u{306a}\u{3044}\u{3002}"` - | -note: the lint level is defined here - --> tests/ui/unicode.rs:46:17 - | -LL | #![deny(clippy::non_ascii_literal)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: literal non-ASCII character detected - --> tests/ui/unicode.rs:93:9 + --> tests/ui/unicode.rs:91:9 | LL | with_location!("héllo"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `with_location!("h\u{e9}llo")` - | -note: the lint level is defined here - --> tests/ui/unicode.rs:84:13 - | -LL | #![deny(clippy::non_ascii_literal)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 9 previous errors diff --git a/tests/ui/uninhabited_references.rs b/tests/ui/uninhabited_references.rs index 9b3616ad51871..2351fb6a2c4e6 100644 --- a/tests/ui/uninhabited_references.rs +++ b/tests/ui/uninhabited_references.rs @@ -1,5 +1,4 @@ #![warn(clippy::uninhabited_references)] -#![allow(clippy::missing_transmute_annotations)] #![feature(never_type)] fn ret_uninh_ref() -> &'static std::convert::Infallible { diff --git a/tests/ui/uninhabited_references.stderr b/tests/ui/uninhabited_references.stderr index ac05ab5bb4d40..0d29816fc51d9 100644 --- a/tests/ui/uninhabited_references.stderr +++ b/tests/ui/uninhabited_references.stderr @@ -1,5 +1,5 @@ error: dereferencing a reference to an uninhabited type would be undefined behavior - --> tests/ui/uninhabited_references.rs:5:23 + --> tests/ui/uninhabited_references.rs:4:23 | LL | fn ret_uninh_ref() -> &'static std::convert::Infallible { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | fn ret_uninh_ref() -> &'static std::convert::Infallible { = help: to override `-D warnings` add `#[allow(clippy::uninhabited_references)]` error: dereferencing a reference to an uninhabited type would be undefined behavior - --> tests/ui/uninhabited_references.rs:12:30 + --> tests/ui/uninhabited_references.rs:11:30 | LL | fn $name(x: &$ty) -> &$ty { | ^^^^ @@ -19,7 +19,7 @@ LL | ret_something!(id_never, !); = note: this error originates in the macro `ret_something` (in Nightly builds, run with -Z macro-backtrace for more info) error: dereferencing a reference to an uninhabited type is undefined behavior - --> tests/ui/uninhabited_references.rs:14:14 + --> tests/ui/uninhabited_references.rs:13:14 | LL | &*x | ^^ @@ -30,7 +30,7 @@ LL | ret_something!(id_never, !); = note: this error originates in the macro `ret_something` (in Nightly builds, run with -Z macro-backtrace for more info) error: dereferencing a reference to an uninhabited type is undefined behavior - --> tests/ui/uninhabited_references.rs:25:13 + --> tests/ui/uninhabited_references.rs:24:13 | LL | let _ = *x; | ^^ diff --git a/tests/ui/uninit.rs b/tests/ui/uninit.rs index f74248c8aea80..32d5a8cfc67cc 100644 --- a/tests/ui/uninit.rs +++ b/tests/ui/uninit.rs @@ -1,5 +1,6 @@ #![feature(stmt_expr_attributes)] -#![allow(clippy::let_unit_value, invalid_value)] +#![warn(clippy::uninit_assumed_init)] +#![expect(invalid_value)] use std::mem::MaybeUninit; diff --git a/tests/ui/uninit.stderr b/tests/ui/uninit.stderr index d6f54dd61ca0e..a18b0020661de 100644 --- a/tests/ui/uninit.stderr +++ b/tests/ui/uninit.stderr @@ -1,19 +1,20 @@ error: this call for this type may be undefined behavior - --> tests/ui/uninit.rs:12:29 + --> tests/ui/uninit.rs:13:29 | LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[deny(clippy::uninit_assumed_init)]` on by default + = note: `-D clippy::uninit-assumed-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninit_assumed_init)]` error: this call for this type may be undefined behavior - --> tests/ui/uninit.rs:34:29 + --> tests/ui/uninit.rs:35:29 | LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call for this type may be undefined behavior - --> tests/ui/uninit.rs:43:29 + --> tests/ui/uninit.rs:44:29 | LL | let _: T = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args.fixed b/tests/ui/uninlined_format_args.fixed index 2e84bbc106ac8..8d4de4f5bda25 100644 --- a/tests/ui/uninlined_format_args.fixed +++ b/tests/ui/uninlined_format_args.fixed @@ -1,9 +1,8 @@ //@aux-build:proc_macros.rs #![warn(clippy::uninlined_format_args)] -#![allow(named_arguments_used_positionally, unused)] -#![allow( - clippy::eq_op, +#![allow(named_arguments_used_positionally)] +#![expect( clippy::format_in_format_args, clippy::print_literal, clippy::unnecessary_literal_unwrap diff --git a/tests/ui/uninlined_format_args.rs b/tests/ui/uninlined_format_args.rs index 4368ce864474a..0af948dd0a4fa 100644 --- a/tests/ui/uninlined_format_args.rs +++ b/tests/ui/uninlined_format_args.rs @@ -1,9 +1,8 @@ //@aux-build:proc_macros.rs #![warn(clippy::uninlined_format_args)] -#![allow(named_arguments_used_positionally, unused)] -#![allow( - clippy::eq_op, +#![allow(named_arguments_used_positionally)] +#![expect( clippy::format_in_format_args, clippy::print_literal, clippy::unnecessary_literal_unwrap diff --git a/tests/ui/uninlined_format_args.stderr b/tests/ui/uninlined_format_args.stderr index 45994fdc9588f..8fc35af75036c 100644 --- a/tests/ui/uninlined_format_args.stderr +++ b/tests/ui/uninlined_format_args.stderr @@ -1,5 +1,5 @@ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:45:5 + --> tests/ui/uninlined_format_args.rs:44:5 | LL | println!("val='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:47:5 + --> tests/ui/uninlined_format_args.rs:46:5 | LL | println!("val='{ }'", local_i32); // 3 spaces | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + println!("val='{local_i32}'"); // 3 spaces | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:50:5 + --> tests/ui/uninlined_format_args.rs:49:5 | LL | println!("val='{ }'", local_i32); // tab | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + println!("val='{local_i32}'"); // tab | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:53:5 + --> tests/ui/uninlined_format_args.rs:52:5 | LL | println!("val='{ }'", local_i32); // space+tab | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("val='{local_i32}'"); // space+tab | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:56:5 + --> tests/ui/uninlined_format_args.rs:55:5 | LL | println!("val='{ }'", local_i32); // tab+space | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + println!("val='{local_i32}'"); // tab+space | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:59:5 + --> tests/ui/uninlined_format_args.rs:58:5 | LL | / println!( LL | | @@ -72,7 +72,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:65:5 + --> tests/ui/uninlined_format_args.rs:64:5 | LL | println!("{}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:67:5 + --> tests/ui/uninlined_format_args.rs:66:5 | LL | println!("{}", fn_arg); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + println!("{fn_arg}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:69:5 + --> tests/ui/uninlined_format_args.rs:68:5 | LL | println!("{:?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + println!("{local_i32:?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:71:5 + --> tests/ui/uninlined_format_args.rs:70:5 | LL | println!("{:#?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL + println!("{local_i32:#?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:73:5 + --> tests/ui/uninlined_format_args.rs:72:5 | LL | println!("{:4}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL + println!("{local_i32:4}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:75:5 + --> tests/ui/uninlined_format_args.rs:74:5 | LL | println!("{:04}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL + println!("{local_i32:04}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:77:5 + --> tests/ui/uninlined_format_args.rs:76:5 | LL | println!("{:<3}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL + println!("{local_i32:<3}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:79:5 + --> tests/ui/uninlined_format_args.rs:78:5 | LL | println!("{:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -168,7 +168,7 @@ LL + println!("{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:81:5 + --> tests/ui/uninlined_format_args.rs:80:5 | LL | println!("{:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -180,7 +180,7 @@ LL + println!("{local_f64:.1}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:86:5 + --> tests/ui/uninlined_format_args.rs:85:5 | LL | println!("{} {}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -192,7 +192,7 @@ LL + println!("{local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:89:5 + --> tests/ui/uninlined_format_args.rs:88:5 | LL | println!("{}", val); | ^^^^^^^^^^^^^^^^^^^ @@ -204,7 +204,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:91:5 + --> tests/ui/uninlined_format_args.rs:90:5 | LL | println!("{}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -216,7 +216,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:94:5 + --> tests/ui/uninlined_format_args.rs:93:5 | LL | println!("val='{\t }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -228,7 +228,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:96:5 + --> tests/ui/uninlined_format_args.rs:95:5 | LL | println!("val='{\n }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:98:5 + --> tests/ui/uninlined_format_args.rs:97:5 | LL | println!("val='{local_i32}'", local_i32 = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -252,7 +252,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:100:5 + --> tests/ui/uninlined_format_args.rs:99:5 | LL | println!("val='{local_i32}'", local_i32 = fn_arg); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -264,7 +264,7 @@ LL + println!("val='{fn_arg}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:102:5 + --> tests/ui/uninlined_format_args.rs:101:5 | LL | println!("{0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -276,7 +276,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:104:5 + --> tests/ui/uninlined_format_args.rs:103:5 | LL | println!("{0:?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -288,7 +288,7 @@ LL + println!("{local_i32:?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:106:5 + --> tests/ui/uninlined_format_args.rs:105:5 | LL | println!("{0:#?}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -300,7 +300,7 @@ LL + println!("{local_i32:#?}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:108:5 + --> tests/ui/uninlined_format_args.rs:107:5 | LL | println!("{0:04}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -312,7 +312,7 @@ LL + println!("{local_i32:04}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:110:5 + --> tests/ui/uninlined_format_args.rs:109:5 | LL | println!("{0:<3}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -324,7 +324,7 @@ LL + println!("{local_i32:<3}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:112:5 + --> tests/ui/uninlined_format_args.rs:111:5 | LL | println!("{0:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -336,7 +336,7 @@ LL + println!("{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:114:5 + --> tests/ui/uninlined_format_args.rs:113:5 | LL | println!("{0:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -348,7 +348,7 @@ LL + println!("{local_f64:.1}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:116:5 + --> tests/ui/uninlined_format_args.rs:115:5 | LL | println!("{0} {0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -360,7 +360,7 @@ LL + println!("{local_i32} {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:118:5 + --> tests/ui/uninlined_format_args.rs:117:5 | LL | println!("{1} {} {0} {}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -372,7 +372,7 @@ LL + println!("{local_f64} {local_i32} {local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:120:5 + --> tests/ui/uninlined_format_args.rs:119:5 | LL | println!("{0} {1}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -384,7 +384,7 @@ LL + println!("{local_i32} {local_f64}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:122:5 + --> tests/ui/uninlined_format_args.rs:121:5 | LL | println!("{1} {0}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -396,7 +396,7 @@ LL + println!("{local_f64} {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:124:5 + --> tests/ui/uninlined_format_args.rs:123:5 | LL | println!("{1} {0} {1} {0}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -408,7 +408,7 @@ LL + println!("{local_f64} {local_i32} {local_f64} {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:127:5 + --> tests/ui/uninlined_format_args.rs:126:5 | LL | println!("{v}", v = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -420,7 +420,7 @@ LL + println!("{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:129:5 + --> tests/ui/uninlined_format_args.rs:128:5 | LL | println!("{local_i32:0$}", width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -432,7 +432,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:131:5 + --> tests/ui/uninlined_format_args.rs:130:5 | LL | println!("{local_i32:w$}", w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -444,7 +444,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:133:5 + --> tests/ui/uninlined_format_args.rs:132:5 | LL | println!("{local_i32:.0$}", prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -456,7 +456,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:135:5 + --> tests/ui/uninlined_format_args.rs:134:5 | LL | println!("{local_i32:.p$}", p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -468,7 +468,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:137:5 + --> tests/ui/uninlined_format_args.rs:136:5 | LL | println!("{:0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -480,7 +480,7 @@ LL + println!("{val:val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:139:5 + --> tests/ui/uninlined_format_args.rs:138:5 | LL | println!("{0:0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -492,7 +492,7 @@ LL + println!("{val:val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:141:5 + --> tests/ui/uninlined_format_args.rs:140:5 | LL | println!("{:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -504,7 +504,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:143:5 + --> tests/ui/uninlined_format_args.rs:142:5 | LL | println!("{0:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -516,7 +516,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:145:5 + --> tests/ui/uninlined_format_args.rs:144:5 | LL | println!("{0:0$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -528,7 +528,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:147:5 + --> tests/ui/uninlined_format_args.rs:146:5 | LL | println!("{0:v$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -540,7 +540,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:149:5 + --> tests/ui/uninlined_format_args.rs:148:5 | LL | println!("{v:0$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -552,7 +552,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:151:5 + --> tests/ui/uninlined_format_args.rs:150:5 | LL | println!("{v:v$.0$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -564,7 +564,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:153:5 + --> tests/ui/uninlined_format_args.rs:152:5 | LL | println!("{v:0$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -576,7 +576,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:155:5 + --> tests/ui/uninlined_format_args.rs:154:5 | LL | println!("{v:v$.v$}", v = val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -588,7 +588,7 @@ LL + println!("{val:val$.val$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:157:5 + --> tests/ui/uninlined_format_args.rs:156:5 | LL | println!("{:0$}", width); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -600,7 +600,7 @@ LL + println!("{width:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:159:5 + --> tests/ui/uninlined_format_args.rs:158:5 | LL | println!("{:1$}", local_i32, width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -612,7 +612,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:161:5 + --> tests/ui/uninlined_format_args.rs:160:5 | LL | println!("{:w$}", w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -624,7 +624,7 @@ LL + println!("{width:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:163:5 + --> tests/ui/uninlined_format_args.rs:162:5 | LL | println!("{:w$}", local_i32, w = width); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -636,7 +636,7 @@ LL + println!("{local_i32:width$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:165:5 + --> tests/ui/uninlined_format_args.rs:164:5 | LL | println!("{:.0$}", prec); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -648,7 +648,7 @@ LL + println!("{prec:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:167:5 + --> tests/ui/uninlined_format_args.rs:166:5 | LL | println!("{:.1$}", local_i32, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -660,7 +660,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:169:5 + --> tests/ui/uninlined_format_args.rs:168:5 | LL | println!("{:.p$}", p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -672,7 +672,7 @@ LL + println!("{prec:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:171:5 + --> tests/ui/uninlined_format_args.rs:170:5 | LL | println!("{:.p$}", local_i32, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -684,7 +684,7 @@ LL + println!("{local_i32:.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:173:5 + --> tests/ui/uninlined_format_args.rs:172:5 | LL | println!("{:0$.1$}", width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -696,7 +696,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:175:5 + --> tests/ui/uninlined_format_args.rs:174:5 | LL | println!("{:0$.w$}", width, w = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -708,7 +708,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:177:5 + --> tests/ui/uninlined_format_args.rs:176:5 | LL | println!("{:1$.2$}", local_f64, width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -720,7 +720,7 @@ LL + println!("{local_f64:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:179:5 + --> tests/ui/uninlined_format_args.rs:178:5 | LL | println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -732,7 +732,7 @@ LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:181:5 + --> tests/ui/uninlined_format_args.rs:180:5 | LL | / println!( LL | | @@ -742,7 +742,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:193:5 + --> tests/ui/uninlined_format_args.rs:192:5 | LL | println!("Width = {}, value with width = {:0$}", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -754,7 +754,7 @@ LL + println!("Width = {local_i32}, value with width = {local_f64:local_i32$ | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:195:5 + --> tests/ui/uninlined_format_args.rs:194:5 | LL | println!("{:w$.p$}", local_i32, w = width, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -766,7 +766,7 @@ LL + println!("{local_i32:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:197:5 + --> tests/ui/uninlined_format_args.rs:196:5 | LL | println!("{:w$.p$}", w = width, p = prec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -778,7 +778,7 @@ LL + println!("{width:width$.prec$}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:217:5 + --> tests/ui/uninlined_format_args.rs:216:5 | LL | / println!( LL | | @@ -788,7 +788,7 @@ LL | | ); | |_____^ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:223:5 + --> tests/ui/uninlined_format_args.rs:222:5 | LL | println!("{}", /* comment with a comma , in it */ val); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -800,7 +800,7 @@ LL + println!("{val}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:230:9 + --> tests/ui/uninlined_format_args.rs:229:9 | LL | panic!("p1 {}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -812,7 +812,7 @@ LL + panic!("p1 {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:234:9 + --> tests/ui/uninlined_format_args.rs:233:9 | LL | panic!("p2 {0}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -824,7 +824,7 @@ LL + panic!("p2 {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:238:9 + --> tests/ui/uninlined_format_args.rs:237:9 | LL | panic!("p3 {local_i32}", local_i32 = local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -836,7 +836,7 @@ LL + panic!("p3 {local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:257:5 + --> tests/ui/uninlined_format_args.rs:256:5 | LL | println!("expand='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -848,7 +848,7 @@ LL + println!("expand='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:360:5 + --> tests/ui/uninlined_format_args.rs:359:5 | LL | usr_println!(true, "val='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -860,7 +860,7 @@ LL + usr_println!(true, "val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:362:5 + --> tests/ui/uninlined_format_args.rs:361:5 | LL | usr_println!(true, "{}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -872,7 +872,7 @@ LL + usr_println!(true, "{local_i32}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:364:5 + --> tests/ui/uninlined_format_args.rs:363:5 | LL | usr_println!(true, "{:#010x}", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -884,7 +884,7 @@ LL + usr_println!(true, "{local_i32:#010x}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args.rs:366:5 + --> tests/ui/uninlined_format_args.rs:365:5 | LL | usr_println!(true, "{:.1}", local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args_panic.edition2018.fixed b/tests/ui/uninlined_format_args_panic.edition2018.fixed index 6d0f76eaf2524..d44312129a13e 100644 --- a/tests/ui/uninlined_format_args_panic.edition2018.fixed +++ b/tests/ui/uninlined_format_args_panic.edition2018.fixed @@ -4,7 +4,6 @@ //@[edition2024] edition:2024 #![warn(clippy::uninlined_format_args)] -#![allow(clippy::literal_string_with_formatting_args)] fn main() { let var = 1; diff --git a/tests/ui/uninlined_format_args_panic.edition2018.stderr b/tests/ui/uninlined_format_args_panic.edition2018.stderr index 24afb3d35abee..4b154abac5bc0 100644 --- a/tests/ui/uninlined_format_args_panic.edition2018.stderr +++ b/tests/ui/uninlined_format_args_panic.edition2018.stderr @@ -1,5 +1,5 @@ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:12:5 + --> tests/ui/uninlined_format_args_panic.rs:11:5 | LL | println!("val='{}'", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args_panic.edition2021.fixed b/tests/ui/uninlined_format_args_panic.edition2021.fixed index ba741bfcd09d4..22b05c5422125 100644 --- a/tests/ui/uninlined_format_args_panic.edition2021.fixed +++ b/tests/ui/uninlined_format_args_panic.edition2021.fixed @@ -4,7 +4,6 @@ //@[edition2024] edition:2024 #![warn(clippy::uninlined_format_args)] -#![allow(clippy::literal_string_with_formatting_args)] fn main() { let var = 1; diff --git a/tests/ui/uninlined_format_args_panic.edition2021.stderr b/tests/ui/uninlined_format_args_panic.edition2021.stderr index dcf6747e2d649..a90998aaf06a2 100644 --- a/tests/ui/uninlined_format_args_panic.edition2021.stderr +++ b/tests/ui/uninlined_format_args_panic.edition2021.stderr @@ -1,5 +1,5 @@ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:12:5 + --> tests/ui/uninlined_format_args_panic.rs:11:5 | LL | println!("val='{}'", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + println!("val='{var}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:16:9 + --> tests/ui/uninlined_format_args_panic.rs:15:9 | LL | panic!("p1 {}", var); | ^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + panic!("p1 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:21:9 + --> tests/ui/uninlined_format_args_panic.rs:20:9 | LL | panic!("p2 {0}", var); | ^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + panic!("p2 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:26:9 + --> tests/ui/uninlined_format_args_panic.rs:25:9 | LL | panic!("p3 {var}", var = var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + panic!("p3 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:38:5 + --> tests/ui/uninlined_format_args_panic.rs:37:5 | LL | assert!(var == 1, "p5 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + assert!(var == 1, "p5 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:41:5 + --> tests/ui/uninlined_format_args_panic.rs:40:5 | LL | debug_assert!(var == 1, "p6 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + debug_assert!(var == 1, "p6 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:47:9 + --> tests/ui/uninlined_format_args_panic.rs:46:9 | LL | core::panic!("p7 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + core::panic!("p7 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:52:9 + --> tests/ui/uninlined_format_args_panic.rs:51:9 | LL | core::panic!("p8 {0}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + core::panic!("p8 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:57:9 + --> tests/ui/uninlined_format_args_panic.rs:56:9 | LL | core::panic!("p9 {var}", var = var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args_panic.edition2024.fixed b/tests/ui/uninlined_format_args_panic.edition2024.fixed index ba741bfcd09d4..22b05c5422125 100644 --- a/tests/ui/uninlined_format_args_panic.edition2024.fixed +++ b/tests/ui/uninlined_format_args_panic.edition2024.fixed @@ -4,7 +4,6 @@ //@[edition2024] edition:2024 #![warn(clippy::uninlined_format_args)] -#![allow(clippy::literal_string_with_formatting_args)] fn main() { let var = 1; diff --git a/tests/ui/uninlined_format_args_panic.edition2024.stderr b/tests/ui/uninlined_format_args_panic.edition2024.stderr index dcf6747e2d649..a90998aaf06a2 100644 --- a/tests/ui/uninlined_format_args_panic.edition2024.stderr +++ b/tests/ui/uninlined_format_args_panic.edition2024.stderr @@ -1,5 +1,5 @@ error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:12:5 + --> tests/ui/uninlined_format_args_panic.rs:11:5 | LL | println!("val='{}'", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + println!("val='{var}'"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:16:9 + --> tests/ui/uninlined_format_args_panic.rs:15:9 | LL | panic!("p1 {}", var); | ^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + panic!("p1 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:21:9 + --> tests/ui/uninlined_format_args_panic.rs:20:9 | LL | panic!("p2 {0}", var); | ^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + panic!("p2 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:26:9 + --> tests/ui/uninlined_format_args_panic.rs:25:9 | LL | panic!("p3 {var}", var = var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + panic!("p3 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:38:5 + --> tests/ui/uninlined_format_args_panic.rs:37:5 | LL | assert!(var == 1, "p5 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + assert!(var == 1, "p5 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:41:5 + --> tests/ui/uninlined_format_args_panic.rs:40:5 | LL | debug_assert!(var == 1, "p6 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + debug_assert!(var == 1, "p6 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:47:9 + --> tests/ui/uninlined_format_args_panic.rs:46:9 | LL | core::panic!("p7 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + core::panic!("p7 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:52:9 + --> tests/ui/uninlined_format_args_panic.rs:51:9 | LL | core::panic!("p8 {0}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + core::panic!("p8 {var}"); | error: variables can be used directly in the `format!` string - --> tests/ui/uninlined_format_args_panic.rs:57:9 + --> tests/ui/uninlined_format_args_panic.rs:56:9 | LL | core::panic!("p9 {var}", var = var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args_panic.rs b/tests/ui/uninlined_format_args_panic.rs index 7ee17d8fb16e2..f151f5da959ed 100644 --- a/tests/ui/uninlined_format_args_panic.rs +++ b/tests/ui/uninlined_format_args_panic.rs @@ -4,7 +4,6 @@ //@[edition2024] edition:2024 #![warn(clippy::uninlined_format_args)] -#![allow(clippy::literal_string_with_formatting_args)] fn main() { let var = 1; diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index 3cba0735b3623..fa9851db3d10a 100644 --- a/tests/ui/unit_arg.rs +++ b/tests/ui/unit_arg.rs @@ -1,16 +1,10 @@ //@aux-build: proc_macros.rs //@no-rustfix: overlapping suggestions #![warn(clippy::unit_arg)] -#![allow(unused_must_use, unused_variables)] -#![allow( - clippy::let_unit_value, +#![expect( clippy::needless_question_mark, clippy::never_loop, clippy::no_effect, - clippy::or_fun_call, - clippy::self_named_constructors, - clippy::uninlined_format_args, - clippy::unnecessary_wraps, clippy::unused_unit )] @@ -124,7 +118,6 @@ fn question_mark() -> Result<(), ()> { Ok(()) } -#[allow(dead_code)] mod issue_2945 { fn unit_fn() -> Result<(), i32> { Ok(()) @@ -135,7 +128,6 @@ mod issue_2945 { } } -#[allow(dead_code)] fn returning_expr() -> Option<()> { Some(foo(1)) //~^ unit_arg diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index ed13108631574..26e35fa616d4d 100644 --- a/tests/ui/unit_arg.stderr +++ b/tests/ui/unit_arg.stderr @@ -1,5 +1,5 @@ error: passing a unit value to a function - --> tests/ui/unit_arg.rs:63:5 + --> tests/ui/unit_arg.rs:57:5 | LL | / foo({ LL | | @@ -24,7 +24,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:67:5 + --> tests/ui/unit_arg.rs:61:5 | LL | foo(foo(1)); | ^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:69:5 + --> tests/ui/unit_arg.rs:63:5 | LL | / foo({ LL | | @@ -61,7 +61,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:75:5 + --> tests/ui/unit_arg.rs:69:5 | LL | / b.bar({ LL | | @@ -84,7 +84,7 @@ LL ~ b.bar(()); | error: passing unit values to a function - --> tests/ui/unit_arg.rs:79:5 + --> tests/ui/unit_arg.rs:73:5 | LL | taking_multiple_units(foo(0), foo(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> tests/ui/unit_arg.rs:81:5 + --> tests/ui/unit_arg.rs:75:5 | LL | / taking_multiple_units(foo(0), { LL | | @@ -123,7 +123,7 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> tests/ui/unit_arg.rs:86:5 + --> tests/ui/unit_arg.rs:80:5 | LL | / taking_multiple_units( LL | | @@ -162,7 +162,7 @@ LL ~ ); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:98:13 + --> tests/ui/unit_arg.rs:92:13 | LL | None.or(Some(foo(2))); | ^^^^^^^^^^^^ @@ -176,7 +176,7 @@ LL ~ }); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:102:5 + --> tests/ui/unit_arg.rs:96:5 | LL | foo(foo(())); | ^^^^^^^^^^^^ @@ -188,7 +188,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:140:5 + --> tests/ui/unit_arg.rs:132:5 | LL | Some(foo(1)) | ^^^^^^^^^^^^ @@ -200,19 +200,19 @@ LL + Some(()) | error: passing a unit value to a function - --> tests/ui/unit_arg.rs:168:5 + --> tests/ui/unit_arg.rs:160:5 | LL | fn_take_unit(mac!(def)); | ^^^^^^^^^^^^^^^^^^^^^^^ error: passing a unit value to a function - --> tests/ui/unit_arg.rs:170:5 + --> tests/ui/unit_arg.rs:162:5 | LL | fn_take_unit(mac!(func Default::default)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: passing a unit value to a function - --> tests/ui/unit_arg.rs:172:5 + --> tests/ui/unit_arg.rs:164:5 | LL | fn_take_unit(mac!(nonempty_block Default::default())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unit_arg_fixable.fixed b/tests/ui/unit_arg_fixable.fixed index 3bbc62ca0bca7..41af9263f9147 100644 --- a/tests/ui/unit_arg_fixable.fixed +++ b/tests/ui/unit_arg_fixable.fixed @@ -1,6 +1,4 @@ #![warn(clippy::unit_arg)] -#![allow(unused_must_use, unused_variables)] -#![allow(clippy::no_effect, clippy::uninlined_format_args)] use std::fmt::Debug; diff --git a/tests/ui/unit_arg_fixable.rs b/tests/ui/unit_arg_fixable.rs index 12d6cbcf61d92..02d39b0283013 100644 --- a/tests/ui/unit_arg_fixable.rs +++ b/tests/ui/unit_arg_fixable.rs @@ -1,6 +1,4 @@ #![warn(clippy::unit_arg)] -#![allow(unused_must_use, unused_variables)] -#![allow(clippy::no_effect, clippy::uninlined_format_args)] use std::fmt::Debug; diff --git a/tests/ui/unit_arg_fixable.stderr b/tests/ui/unit_arg_fixable.stderr index 9f6bc671bf55b..40eee8c2cc1c1 100644 --- a/tests/ui/unit_arg_fixable.stderr +++ b/tests/ui/unit_arg_fixable.stderr @@ -1,5 +1,5 @@ error: passing a unit value to a function - --> tests/ui/unit_arg_fixable.rs:16:5 + --> tests/ui/unit_arg_fixable.rs:14:5 | LL | foo({}); | ^^^^^^^ @@ -13,7 +13,7 @@ LL + foo(()); | error: passing a unit value to a function - --> tests/ui/unit_arg_fixable.rs:18:5 + --> tests/ui/unit_arg_fixable.rs:16:5 | LL | foo3({}, 2, 2); | ^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + foo3((), 2, 2); | error: passing unit values to a function - --> tests/ui/unit_arg_fixable.rs:20:5 + --> tests/ui/unit_arg_fixable.rs:18:5 | LL | taking_two_units({}, foo(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL ~ taking_two_units((), ()); | error: passing unit values to a function - --> tests/ui/unit_arg_fixable.rs:22:5 + --> tests/ui/unit_arg_fixable.rs:20:5 | LL | taking_three_units({}, foo(0), foo(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -50,7 +50,7 @@ LL ~ taking_three_units((), (), ()); | error: passing a unit value to a function - --> tests/ui/unit_arg_fixable.rs:33:5 + --> tests/ui/unit_arg_fixable.rs:31:5 | LL | fn_take_unit(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL + fn_take_unit(()); | error: passing a unit value to a function - --> tests/ui/unit_arg_fixable.rs:47:5 + --> tests/ui/unit_arg_fixable.rs:45:5 | LL | fn_take_unit(another_mac!()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -74,7 +74,7 @@ LL ~ fn_take_unit(()); | error: passing a unit value to a function - --> tests/ui/unit_arg_fixable.rs:49:5 + --> tests/ui/unit_arg_fixable.rs:47:5 | LL | fn_take_unit(another_mac!(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL ~ fn_take_unit(()); | error: passing a unit value to a function - --> tests/ui/unit_arg_fixable.rs:58:5 + --> tests/ui/unit_arg_fixable.rs:56:5 | LL | fn_take_unit(mac!(nondef Default::default())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -98,7 +98,7 @@ LL + fn_take_unit(mac!(nondef ())); | error: passing a unit value to a function - --> tests/ui/unit_arg_fixable.rs:60:5 + --> tests/ui/unit_arg_fixable.rs:58:5 | LL | fn_take_unit(mac!(empty_block)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -110,7 +110,7 @@ LL ~ fn_take_unit(()); | error: passing a unit value to a function - --> tests/ui/unit_arg_fixable.rs:67:5 + --> tests/ui/unit_arg_fixable.rs:65:5 | LL | fn_take_unit(def()); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unit_cmp.rs b/tests/ui/unit_cmp.rs index 839987a474cd0..6e2ae4bc0fb0d 100644 --- a/tests/ui/unit_cmp.rs +++ b/tests/ui/unit_cmp.rs @@ -1,10 +1,5 @@ #![warn(clippy::unit_cmp)] -#![allow( - clippy::no_effect, - clippy::unnecessary_operation, - clippy::derive_partial_eq_without_eq, - clippy::needless_ifs -)] +#![expect(clippy::needless_ifs, clippy::no_effect)] #[derive(PartialEq)] pub struct ContainsUnit(()); // should be fine diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index 21aa9dce1510f..1ac151442ebc3 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -1,5 +1,5 @@ error: ==-comparison of unit values detected. This will always be true - --> tests/ui/unit_cmp.rs:17:8 + --> tests/ui/unit_cmp.rs:12:8 | LL | if { | ________^ @@ -15,7 +15,7 @@ LL | | } {} = help: to override `-D warnings` add `#[allow(clippy::unit_cmp)]` error: >-comparison of unit values detected. This will always be false - --> tests/ui/unit_cmp.rs:25:8 + --> tests/ui/unit_cmp.rs:20:8 | LL | if { | ________^ @@ -28,7 +28,7 @@ LL | | } {} | |_____^ error: `assert_eq` of unit values detected. This will always succeed - --> tests/ui/unit_cmp.rs:33:5 + --> tests/ui/unit_cmp.rs:28:5 | LL | / assert_eq!( LL | | @@ -39,7 +39,7 @@ LL | | ); | |_____^ error: `debug_assert_eq` of unit values detected. This will always succeed - --> tests/ui/unit_cmp.rs:42:5 + --> tests/ui/unit_cmp.rs:37:5 | LL | / debug_assert_eq!( LL | | @@ -50,7 +50,7 @@ LL | | ); | |_____^ error: `assert_ne` of unit values detected. This will always fail - --> tests/ui/unit_cmp.rs:52:5 + --> tests/ui/unit_cmp.rs:47:5 | LL | / assert_ne!( LL | | @@ -61,7 +61,7 @@ LL | | ); | |_____^ error: `debug_assert_ne` of unit values detected. This will always fail - --> tests/ui/unit_cmp.rs:61:5 + --> tests/ui/unit_cmp.rs:56:5 | LL | / debug_assert_ne!( LL | | @@ -72,7 +72,7 @@ LL | | ); | |_____^ error: `assert_eq` of unit values detected. This will always succeed - --> tests/ui/unit_cmp.rs:74:5 + --> tests/ui/unit_cmp.rs:69:5 | LL | / assert_eq!( LL | | @@ -84,7 +84,7 @@ LL | | ); | |_____^ error: `assert_eq` of unit values detected. This will always succeed - --> tests/ui/unit_cmp.rs:81:5 + --> tests/ui/unit_cmp.rs:76:5 | LL | assert_eq!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unit_hash.fixed b/tests/ui/unit_hash.fixed index 25c90e6ddc4c2..409c78f6c38cd 100644 --- a/tests/ui/unit_hash.fixed +++ b/tests/ui/unit_hash.fixed @@ -1,5 +1,4 @@ #![warn(clippy::unit_hash)] -#![allow(clippy::let_unit_value)] use std::collections::hash_map::DefaultHasher; use std::hash::Hash; diff --git a/tests/ui/unit_hash.rs b/tests/ui/unit_hash.rs index b04cca6adf2a5..f7e0b1d23ab26 100644 --- a/tests/ui/unit_hash.rs +++ b/tests/ui/unit_hash.rs @@ -1,5 +1,4 @@ #![warn(clippy::unit_hash)] -#![allow(clippy::let_unit_value)] use std::collections::hash_map::DefaultHasher; use std::hash::Hash; diff --git a/tests/ui/unit_hash.stderr b/tests/ui/unit_hash.stderr index d1cabf89f8e71..410cd149e1df6 100644 --- a/tests/ui/unit_hash.stderr +++ b/tests/ui/unit_hash.stderr @@ -1,5 +1,5 @@ error: this call to `hash` on the unit type will do nothing - --> tests/ui/unit_hash.rs:19:23 + --> tests/ui/unit_hash.rs:18:23 | LL | Foo::Empty => ().hash(&mut state), | ^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` @@ -9,7 +9,7 @@ LL | Foo::Empty => ().hash(&mut state), = help: to override `-D warnings` add `#[allow(clippy::unit_hash)]` error: this call to `hash` on the unit type will do nothing - --> tests/ui/unit_hash.rs:25:5 + --> tests/ui/unit_hash.rs:24:5 | LL | res.hash(&mut state); | ^^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` @@ -17,7 +17,7 @@ LL | res.hash(&mut state); = note: the implementation of `Hash` for `()` is a no-op error: this call to `hash` on the unit type will do nothing - --> tests/ui/unit_hash.rs:29:5 + --> tests/ui/unit_hash.rs:28:5 | LL | do_nothing().hash(&mut state); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` diff --git a/tests/ui/unit_return_expecting_ord.rs b/tests/ui/unit_return_expecting_ord.rs index 74cd304726842..de067190fe389 100644 --- a/tests/ui/unit_return_expecting_ord.rs +++ b/tests/ui/unit_return_expecting_ord.rs @@ -1,7 +1,6 @@ #![warn(clippy::unit_return_expecting_ord)] -#![allow(clippy::needless_return)] +#![expect(clippy::needless_return, clippy::useless_vec)] #![allow(clippy::unused_unit)] -#![allow(clippy::useless_vec)] struct Struct { field: isize, diff --git a/tests/ui/unit_return_expecting_ord.stderr b/tests/ui/unit_return_expecting_ord.stderr index d5ce2fb0b51d9..548feada2117d 100644 --- a/tests/ui/unit_return_expecting_ord.stderr +++ b/tests/ui/unit_return_expecting_ord.stderr @@ -1,11 +1,11 @@ error: this closure returns the unit type which also implements Ord - --> tests/ui/unit_return_expecting_ord.rs:18:25 + --> tests/ui/unit_return_expecting_ord.rs:17:25 | LL | structs.sort_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> tests/ui/unit_return_expecting_ord.rs:21:24 + --> tests/ui/unit_return_expecting_ord.rs:20:24 | LL | double(s.field); | ^ @@ -13,25 +13,25 @@ LL | double(s.field); = help: to override `-D warnings` add `#[allow(clippy::unit_return_expecting_ord)]` error: this closure returns the unit type which also implements PartialOrd - --> tests/ui/unit_return_expecting_ord.rs:24:30 + --> tests/ui/unit_return_expecting_ord.rs:23:30 | LL | structs.is_sorted_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> tests/ui/unit_return_expecting_ord.rs:27:24 + --> tests/ui/unit_return_expecting_ord.rs:26:24 | LL | double(s.field); | ^ error: this closure returns the unit type which also implements PartialOrd - --> tests/ui/unit_return_expecting_ord.rs:29:30 + --> tests/ui/unit_return_expecting_ord.rs:28:30 | LL | structs.is_sorted_by_key(|s| { | ^^^ error: this closure returns the unit type which also implements Ord - --> tests/ui/unit_return_expecting_ord.rs:41:25 + --> tests/ui/unit_return_expecting_ord.rs:40:25 | LL | structs.sort_by_key(|s| unit(s.field)); | ^^^ diff --git a/tests/ui/unnecessary_cast.fixed b/tests/ui/unnecessary_cast.fixed index 9e07c52e82e67..1724d3d8c2f3b 100644 --- a/tests/ui/unnecessary_cast.fixed +++ b/tests/ui/unnecessary_cast.fixed @@ -1,15 +1,14 @@ //@aux-build:extern_fake_libc.rs #![feature(const_trait_impl, const_ops)] #![warn(clippy::unnecessary_cast)] -#![allow( +#![expect( + nonstandard_style, clippy::borrow_as_ptr, clippy::identity_op, clippy::multiple_bound_locations, clippy::no_effect, clippy::nonstandard_macro_braces, - clippy::unnecessary_operation, - nonstandard_style, - unused + clippy::unnecessary_operation )] extern crate extern_fake_libc; @@ -102,7 +101,6 @@ fn main() { // macro version macro_rules! foo { ($a:ident, $b:ident) => { - #[allow(unused)] pub fn $a() -> $b { 1 as $b } @@ -169,7 +167,6 @@ fn main() { type I32Alias = i32; mod fixable { - #![allow(dead_code)] fn main() { // casting integer literal to float is unnecessary diff --git a/tests/ui/unnecessary_cast.rs b/tests/ui/unnecessary_cast.rs index 43d3e56e365a2..3c2ba9777a569 100644 --- a/tests/ui/unnecessary_cast.rs +++ b/tests/ui/unnecessary_cast.rs @@ -1,15 +1,14 @@ //@aux-build:extern_fake_libc.rs #![feature(const_trait_impl, const_ops)] #![warn(clippy::unnecessary_cast)] -#![allow( +#![expect( + nonstandard_style, clippy::borrow_as_ptr, clippy::identity_op, clippy::multiple_bound_locations, clippy::no_effect, clippy::nonstandard_macro_braces, - clippy::unnecessary_operation, - nonstandard_style, - unused + clippy::unnecessary_operation )] extern crate extern_fake_libc; @@ -102,7 +101,6 @@ fn main() { // macro version macro_rules! foo { ($a:ident, $b:ident) => { - #[allow(unused)] pub fn $a() -> $b { 1 as $b } @@ -169,7 +167,6 @@ fn main() { type I32Alias = i32; mod fixable { - #![allow(dead_code)] fn main() { // casting integer literal to float is unnecessary diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr index 9807ae0341421..fd5c761efdad8 100644 --- a/tests/ui/unnecessary_cast.stderr +++ b/tests/ui/unnecessary_cast.stderr @@ -1,5 +1,5 @@ error: casting raw pointers to the same type and constness is unnecessary (`*const T` -> `*const T`) - --> tests/ui/unnecessary_cast.rs:21:5 + --> tests/ui/unnecessary_cast.rs:20:5 | LL | ptr as *const T | ^^^^^^^^^^^^^^^ help: try: `ptr` @@ -8,427 +8,427 @@ LL | ptr as *const T = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:57:5 + --> tests/ui/unnecessary_cast.rs:56:5 | LL | 1i32 as i32; | ^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:59:5 + --> tests/ui/unnecessary_cast.rs:58:5 | LL | 1f32 as f32; | ^^^^^^^^^^^ help: try: `1_f32` error: casting to the same type is unnecessary (`bool` -> `bool`) - --> tests/ui/unnecessary_cast.rs:61:5 + --> tests/ui/unnecessary_cast.rs:60:5 | LL | false as bool; | ^^^^^^^^^^^^^ help: try: `false` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:65:5 + --> tests/ui/unnecessary_cast.rs:64:5 | LL | -1_i32 as i32; | ^^^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:67:5 + --> tests/ui/unnecessary_cast.rs:66:5 | LL | - 1_i32 as i32; | ^^^^^^^^^^^^^^ help: try: `- 1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:69:5 + --> tests/ui/unnecessary_cast.rs:68:5 | LL | -1f32 as f32; | ^^^^^^^^^^^^ help: try: `-1_f32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:71:5 + --> tests/ui/unnecessary_cast.rs:70:5 | LL | 1_i32 as i32; | ^^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:73:5 + --> tests/ui/unnecessary_cast.rs:72:5 | LL | 1_f32 as f32; | ^^^^^^^^^^^^ help: try: `1_f32` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> tests/ui/unnecessary_cast.rs:76:22 + --> tests/ui/unnecessary_cast.rs:75:22 | LL | let _: *mut u8 = [1u8, 2].as_ptr() as *const u8 as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> tests/ui/unnecessary_cast.rs:79:5 + --> tests/ui/unnecessary_cast.rs:78:5 | LL | [1u8, 2].as_ptr() as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*mut u8` -> `*mut u8`) - --> tests/ui/unnecessary_cast.rs:82:5 + --> tests/ui/unnecessary_cast.rs:81:5 | LL | [1u8, 2].as_mut_ptr() as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_mut_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`) - --> tests/ui/unnecessary_cast.rs:94:5 + --> tests/ui/unnecessary_cast.rs:93:5 | LL | owo::([1u32].as_ptr()) as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `owo::([1u32].as_ptr())` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> tests/ui/unnecessary_cast.rs:96:5 + --> tests/ui/unnecessary_cast.rs:95:5 | LL | uwu::([1u32].as_ptr()) as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::([1u32].as_ptr())` error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`) - --> tests/ui/unnecessary_cast.rs:99:5 + --> tests/ui/unnecessary_cast.rs:98:5 | LL | uwu::([1u32].as_ptr()) as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::([1u32].as_ptr())` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> tests/ui/unnecessary_cast.rs:135:5 + --> tests/ui/unnecessary_cast.rs:133:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> tests/ui/unnecessary_cast.rs:138:5 + --> tests/ui/unnecessary_cast.rs:136:5 | LL | x as u32; | ^^^^^^^^ help: try: `x` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> tests/ui/unnecessary_cast.rs:140:5 + --> tests/ui/unnecessary_cast.rs:138:5 | LL | bbb() as u32; | ^^^^^^^^^^^^ help: try: `bbb()` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> tests/ui/unnecessary_cast.rs:143:5 + --> tests/ui/unnecessary_cast.rs:141:5 | LL | x as u32; | ^^^^^^^^ help: try: `x` error: casting integer literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:176:9 + --> tests/ui/unnecessary_cast.rs:173:9 | LL | 100 as f32; | ^^^^^^^^^^ help: try: `100_f32` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:178:9 + --> tests/ui/unnecessary_cast.rs:175:9 | LL | 100 as f64; | ^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:180:9 + --> tests/ui/unnecessary_cast.rs:177:9 | LL | 100_i32 as f64; | ^^^^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:182:17 + --> tests/ui/unnecessary_cast.rs:179:17 | LL | let _ = -100 as f32; | ^^^^^^^^^^^ help: try: `-100_f32` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:184:17 + --> tests/ui/unnecessary_cast.rs:181:17 | LL | let _ = -100 as f64; | ^^^^^^^^^^^ help: try: `-100_f64` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:186:17 + --> tests/ui/unnecessary_cast.rs:183:17 | LL | let _ = -100_i32 as f64; | ^^^^^^^^^^^^^^^ help: try: `-100_f64` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:188:9 + --> tests/ui/unnecessary_cast.rs:185:9 | LL | 100. as f32; | ^^^^^^^^^^^ help: try: `100_f32` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:190:9 + --> tests/ui/unnecessary_cast.rs:187:9 | LL | 100. as f64; | ^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `u32` is unnecessary - --> tests/ui/unnecessary_cast.rs:203:9 + --> tests/ui/unnecessary_cast.rs:200:9 | LL | 1 as u32; | ^^^^^^^^ help: try: `1_u32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:205:9 + --> tests/ui/unnecessary_cast.rs:202:9 | LL | 0x10 as i32; | ^^^^^^^^^^^ help: try: `0x10_i32` error: casting integer literal to `usize` is unnecessary - --> tests/ui/unnecessary_cast.rs:207:9 + --> tests/ui/unnecessary_cast.rs:204:9 | LL | 0b10 as usize; | ^^^^^^^^^^^^^ help: try: `0b10_usize` error: casting integer literal to `u16` is unnecessary - --> tests/ui/unnecessary_cast.rs:209:9 + --> tests/ui/unnecessary_cast.rs:206:9 | LL | 0o73 as u16; | ^^^^^^^^^^^ help: try: `0o73_u16` error: casting integer literal to `u32` is unnecessary - --> tests/ui/unnecessary_cast.rs:211:9 + --> tests/ui/unnecessary_cast.rs:208:9 | LL | 1_000_000_000 as u32; | ^^^^^^^^^^^^^^^^^^^^ help: try: `1_000_000_000_u32` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:214:9 + --> tests/ui/unnecessary_cast.rs:211:9 | LL | 1.0 as f64; | ^^^^^^^^^^ help: try: `1.0_f64` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:216:9 + --> tests/ui/unnecessary_cast.rs:213:9 | LL | 0.5 as f32; | ^^^^^^^^^^ help: try: `0.5_f32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:221:17 + --> tests/ui/unnecessary_cast.rs:218:17 | LL | let _ = -1 as i32; | ^^^^^^^^^ help: try: `-1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:223:17 + --> tests/ui/unnecessary_cast.rs:220:17 | LL | let _ = -1.0 as f32; | ^^^^^^^^^^^ help: try: `-1.0_f32` error: casting to the same type is unnecessary (`i32` -> `i32`) - --> tests/ui/unnecessary_cast.rs:230:18 + --> tests/ui/unnecessary_cast.rs:227:18 | LL | let _ = &(x as i32); | ^^^^^^^^^^ help: try: `{ x }` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:237:22 + --> tests/ui/unnecessary_cast.rs:234:22 | LL | let _: i32 = -(1) as i32; | ^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i64` is unnecessary - --> tests/ui/unnecessary_cast.rs:240:22 + --> tests/ui/unnecessary_cast.rs:237:22 | LL | let _: i64 = -(1) as i64; | ^^^^^^^^^^^ help: try: `-1_i64` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:248:22 + --> tests/ui/unnecessary_cast.rs:245:22 | LL | let _: f64 = (-8.0 as f64).exp(); | ^^^^^^^^^^^^^ help: try: `(-8.0_f64)` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:251:23 + --> tests/ui/unnecessary_cast.rs:248:23 | LL | let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior | ^^^^^^^^^^^^ help: try: `8.0_f64` error: casting to the same type is unnecessary (`f32` -> `f32`) - --> tests/ui/unnecessary_cast.rs:261:20 + --> tests/ui/unnecessary_cast.rs:258:20 | LL | let _num = foo() as f32; | ^^^^^^^^^^^^ help: try: `foo()` error: casting to the same type is unnecessary (`usize` -> `usize`) - --> tests/ui/unnecessary_cast.rs:272:9 + --> tests/ui/unnecessary_cast.rs:269:9 | LL | (*x as usize).pow(2) | ^^^^^^^^^^^^^ help: try: `(*x)` error: casting to the same type is unnecessary (`usize` -> `usize`) - --> tests/ui/unnecessary_cast.rs:280:31 + --> tests/ui/unnecessary_cast.rs:277:31 | LL | assert_eq!(vec.len(), x as usize); | ^^^^^^^^^^ help: try: `x` error: casting to the same type is unnecessary (`i64` -> `i64`) - --> tests/ui/unnecessary_cast.rs:283:17 + --> tests/ui/unnecessary_cast.rs:280:17 | LL | let _ = (5i32 as i64 as i64).abs(); | ^^^^^^^^^^^^^^^^^^^^ help: try: `(5i32 as i64)` error: casting to the same type is unnecessary (`i64` -> `i64`) - --> tests/ui/unnecessary_cast.rs:286:17 + --> tests/ui/unnecessary_cast.rs:283:17 | LL | let _ = 5i32 as i64 as i64; | ^^^^^^^^^^^^^^^^^^ help: try: `5i32 as i64` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:565:24 + --> tests/ui/unnecessary_cast.rs:562:24 | LL | id::>(1.0_f64.pow_like(2) as f64 * &a).view(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:569:26 + --> tests/ui/unnecessary_cast.rs:566:26 | LL | s.id::>(1.0_f64.pow_like(2) as f64 * &a).view(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:573:26 + --> tests/ui/unnecessary_cast.rs:570:26 | LL | wrap::>(1.0_f64.pow_like(2) as f64 * &a).inner.view(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:577:28 + --> tests/ui/unnecessary_cast.rs:574:28 | LL | s.wrap::>(1.0_f64.pow_like(2) as f64 * &a).inner.view(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:593:31 + --> tests/ui/unnecessary_cast.rs:590:31 | LL | let _ = receiver.take(1.0_f64.pow_like_single_impl(2) as f64).abs(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like_single_impl(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:603:20 + --> tests/ui/unnecessary_cast.rs:600:20 | LL | let _ = id(1.0_f64.powi(2) as f64).abs(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.powi(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:606:22 + --> tests/ui/unnecessary_cast.rs:603:22 | LL | let _ = wrap(1.0_f64.powi(2) as f64).inner.abs(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.powi(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:609:22 + --> tests/ui/unnecessary_cast.rs:606:22 | LL | let _ = s.id(1.0_f64.powi(2) as f64).abs(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.powi(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:612:24 + --> tests/ui/unnecessary_cast.rs:609:24 | LL | let _ = s.wrap(1.0_f64.powi(2) as f64).inner.abs(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.powi(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:615:20 + --> tests/ui/unnecessary_cast.rs:612:20 | LL | let _ = id(1.0_f64.powi(2) as f64 * &a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.powi(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:618:22 + --> tests/ui/unnecessary_cast.rs:615:22 | LL | let _ = s.id(1.0_f64.powi(2) as f64 * &a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.powi(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:631:17 + --> tests/ui/unnecessary_cast.rs:628:17 | LL | let _ = 1.0_f64.pow_like(0.5) as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like(0.5)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:634:17 + --> tests/ui/unnecessary_cast.rs:631:17 | LL | let _ = 1.0_f64.pow_like(2) as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:637:17 + --> tests/ui/unnecessary_cast.rs:634:17 | LL | let _ = (1.0_f64.powi(2) as f64).abs(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.powi(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:640:17 + --> tests/ui/unnecessary_cast.rs:637:17 | LL | let _ = ((Y + 2) as f64).abs(); | ^^^^^^^^^^^^^^^^ help: try: `((Y + 2))` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:643:18 + --> tests/ui/unnecessary_cast.rs:640:18 | LL | let _ = (1.0_f64.pow_like_single_impl(2) as f64 + 1.0_f64).abs(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like_single_impl(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:646:18 + --> tests/ui/unnecessary_cast.rs:643:18 | LL | let _ = (1.0_f64.pow_like_single_impl(2) as f64 + ONE).abs(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like_single_impl(2)` error: casting to the same type is unnecessary (`f64` -> `f64`) - --> tests/ui/unnecessary_cast.rs:649:18 + --> tests/ui/unnecessary_cast.rs:646:18 | LL | let _ = (1.0_f64.pow_like_single_impl(2) as f64 + one).abs(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1.0_f64.pow_like_single_impl(2)` error: casting raw pointers to the same type and constness is unnecessary (`*const *const u8` -> `*const *const u8`) - --> tests/ui/unnecessary_cast.rs:657:10 + --> tests/ui/unnecessary_cast.rs:654:10 | LL | *(&NONE as *const _ as *const _ as *const *const u8 as *const *const u8) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&NONE as *const _ as *const _ as *const *const u8)` error: casting integer literal to `u64` is unnecessary - --> tests/ui/unnecessary_cast.rs:665:45 + --> tests/ui/unnecessary_cast.rs:662:45 | LL | assert!(0x7f_ff_ff_ff_ff_ff_ff_ffu64 == (!0 as u64).overflowing_shr(1_u32).0); | ^^^^^^^^^^^ help: try: `(!0_u64)` error: casting to the same type is unnecessary (`u64` -> `u64`) - --> tests/ui/unnecessary_cast.rs:667:45 + --> tests/ui/unnecessary_cast.rs:664:45 | LL | assert!(0x7f_ff_ff_ff_ff_ff_ff_ffu64 == (!0_u64 as u64).overflowing_shr(1_u32).0); | ^^^^^^^^^^^^^^^ help: try: `(!0_u64)` error: casting integer literal to `u64` is unnecessary - --> tests/ui/unnecessary_cast.rs:670:46 + --> tests/ui/unnecessary_cast.rs:667:46 | LL | assert!(0x7f_ff_ff_ff_ff_ff_ff_ffu64 == (!0 as u64 + 0).overflowing_shr(1_u32).0); | ^^^^^^^^^ help: try: `!0_u64` error: casting integer literal to `u64` is unnecessary - --> tests/ui/unnecessary_cast.rs:672:48 + --> tests/ui/unnecessary_cast.rs:669:48 | LL | assert!(0x7f_ff_ff_ff_ff_ff_ff_ffu64 == (!(0 as u64 + 0)).overflowing_shr(1_u32).0); | ^^^^^^^^ help: try: `0_u64` error: casting integer literal to `u64` is unnecessary - --> tests/ui/unnecessary_cast.rs:675:54 + --> tests/ui/unnecessary_cast.rs:672:54 | LL | assert!(0x7f_ff_ff_ff_ff_ff_ff_ffu64 == identity(!0 as u64).overflowing_shr(1_u32).0); | ^^^^^^^^^ help: try: `!0_u64` error: casting integer literal to `u64` is unnecessary - --> tests/ui/unnecessary_cast.rs:678:56 + --> tests/ui/unnecessary_cast.rs:675:56 | LL | assert!(0x7f_ff_ff_ff_ff_ff_ff_ffu64 == (!identity(0 as u64)).overflowing_shr(1_u32).0); | ^^^^^^^^ help: try: `0_u64` error: casting integer literal to `u64` is unnecessary - --> tests/ui/unnecessary_cast.rs:680:54 + --> tests/ui/unnecessary_cast.rs:677:54 | LL | assert!(0x7f_ff_ff_ff_ff_ff_ff_ffu64 == identity(!0 as u64 + 0).overflowing_shr(1_u32).0); | ^^^^^^^^^ help: try: `!0_u64` diff --git a/tests/ui/unnecessary_clippy_cfg.rs b/tests/ui/unnecessary_clippy_cfg.rs index 65f67df79131e..0de8ccdf82a22 100644 --- a/tests/ui/unnecessary_clippy_cfg.rs +++ b/tests/ui/unnecessary_clippy_cfg.rs @@ -1,7 +1,7 @@ //@no-rustfix -#![allow(clippy::duplicated_attributes)] #![warn(clippy::unnecessary_clippy_cfg)] +#![expect(clippy::duplicated_attributes)] #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))] //~^ unnecessary_clippy_cfg #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))] diff --git a/tests/ui/unnecessary_filter_map.rs b/tests/ui/unnecessary_filter_map.rs index 85582c399ce5f..c09293d9fef51 100644 --- a/tests/ui/unnecessary_filter_map.rs +++ b/tests/ui/unnecessary_filter_map.rs @@ -1,4 +1,5 @@ -#![allow(clippy::redundant_closure)] +#![warn(clippy::unnecessary_filter_map)] +#![expect(clippy::redundant_closure)] fn main() { let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); @@ -54,7 +55,6 @@ mod comment_483920107 { impl S { fn foo(&mut self, server_errors: Vec) { - #[allow(unused_variables)] let errors: Vec = server_errors .into_iter() .filter_map(|se| match se.severity() { diff --git a/tests/ui/unnecessary_filter_map.stderr b/tests/ui/unnecessary_filter_map.stderr index 8c33c08c267d5..f5d090f8be633 100644 --- a/tests/ui/unnecessary_filter_map.stderr +++ b/tests/ui/unnecessary_filter_map.stderr @@ -1,5 +1,5 @@ error: this `.filter_map(..)` can be written more simply using `.filter(..)` - --> tests/ui/unnecessary_filter_map.rs:4:20 + --> tests/ui/unnecessary_filter_map.rs:5:20 | LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_filter_map)]` error: this `.filter_map(..)` can be written more simply using `.filter(..)` - --> tests/ui/unnecessary_filter_map.rs:7:20 + --> tests/ui/unnecessary_filter_map.rs:8:20 | LL | let _ = (0..4).filter_map(|x| { | ____________________^ @@ -21,7 +21,7 @@ LL | | }); | |______^ error: this `.filter_map(..)` can be written more simply using `.filter(..)` - --> tests/ui/unnecessary_filter_map.rs:15:20 + --> tests/ui/unnecessary_filter_map.rs:16:20 | LL | let _ = (0..4).filter_map(|x| match x { | ____________________^ @@ -32,13 +32,13 @@ LL | | }); | |______^ error: this `.filter_map(..)` can be written more simply using `.map(..)` - --> tests/ui/unnecessary_filter_map.rs:21:20 + --> tests/ui/unnecessary_filter_map.rs:22:20 | LL | let _ = (0..4).filter_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `.filter_map(..)` is unnecessary - --> tests/ui/unnecessary_filter_map.rs:28:46 + --> tests/ui/unnecessary_filter_map.rs:29:46 | LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x)); | ^^^^^^^^^^^^^^^^^^^^^^^ From 5f34b6de3fdae0296f5f801c917f20b222c4b999 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Thu, 9 Jul 2026 23:30:45 +0000 Subject: [PATCH 26/63] [Perf] Move `nonstandard_macro_braces` to pre-expansion --- clippy_lints/src/lib.rs | 3 + clippy_lints/src/nonstandard_macro_braces.rs | 206 +++++++++--------- .../conf_nonstandard_macro_braces.fixed | 5 +- .../conf_nonstandard_macro_braces.rs | 5 +- .../conf_nonstandard_macro_braces.stderr | 55 ++--- tests/ui/println_empty_string.fixed | 2 +- tests/ui/println_empty_string.rs | 2 +- tests/ui/unnecessary_trailing_comma.fixed | 1 + tests/ui/unnecessary_trailing_comma.rs | 1 + tests/ui/unnecessary_trailing_comma.stderr | 40 ++-- 10 files changed, 166 insertions(+), 154 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 974abc30db0fd..69aa28d9d67bc 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -456,6 +456,9 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co // Due to the architecture of the compiler, currently `cfg_attr` attributes on crate // level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass. store.register_pre_expansion_lint_pass(Box::new(move || Box::new(attrs::EarlyAttributes::new(conf)))); + store.register_pre_expansion_lint_pass(Box::new(move || { + Box::new(nonstandard_macro_braces::MacroBraces::new(conf)) + })); let format_args_storage = FormatArgsStorage::default(); let attr_storage = AttrStorage::default(); diff --git a/clippy_lints/src/nonstandard_macro_braces.rs b/clippy_lints/src/nonstandard_macro_braces.rs index e601d54cc4eda..149a24871e517 100644 --- a/clippy_lints/src/nonstandard_macro_braces.rs +++ b/clippy_lints/src/nonstandard_macro_braces.rs @@ -1,15 +1,17 @@ use clippy_config::Conf; use clippy_config::types::MacroMatcher; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::{SourceText, SpanExt}; use rustc_ast::ast; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_ast::token::{Delimiter, Token, TokenKind}; +use rustc_ast::tokenstream::{TokenStream, TokenTree}; +use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; -use rustc_hir::def_id::DefId; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::impl_lint_pass; use rustc_span::Span; -use rustc_span::hygiene::{ExpnKind, MacroKind}; + +use crate::rustc_lint::LintContext; +use clippy_utils::source::snippet_opt; declare_clippy_lint! { /// ### What it does @@ -29,127 +31,111 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.55.0"] pub NONSTANDARD_MACRO_BRACES, - nursery, + style, "check consistent use of braces in macro" } impl_lint_pass!(MacroBraces => [NONSTANDARD_MACRO_BRACES]); -struct MacroInfo { - callsite_span: Span, - callsite_snippet: SourceText, - old_open_brace: char, - braces: (char, char), -} - pub struct MacroBraces { - macro_braces: FxHashMap, - done: FxHashSet, + macro_braces: (FxHashMap, usize), + /// Spans for statement macro calls, they have special behaviour with semicolons + mac_stmt_spans: Vec, } impl MacroBraces { pub fn new(conf: &'static Conf) -> Self { Self { macro_braces: macro_braces(&conf.standard_macro_braces), - done: FxHashSet::default(), + mac_stmt_spans: Vec::new(), } } } impl EarlyLintPass for MacroBraces { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { - if let Some(MacroInfo { - callsite_span, - callsite_snippet, - braces, - .. - }) = is_offending_macro(cx, item.span, self) - { - emit_help(cx, &callsite_snippet, braces, callsite_span, false); - self.done.insert(callsite_span); - } - } - - fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) { - if let Some(MacroInfo { - callsite_span, - callsite_snippet, - braces, - old_open_brace, - }) = is_offending_macro(cx, stmt.span, self) + fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::MacCall) { + if let Some(last_segment) = mac.path.segments.last() + && let name = last_segment.ident.as_str() + && let Some(&braces) = self.macro_braces.0.get(name) + && let Some(snip) = snippet_opt(cx.sess(), mac.span().with_lo(last_segment.span().lo())) + && let Some(macro_args_str) = &snip.strip_prefix(name).and_then(|snip| snip.strip_prefix('!')) + && let Some(old_open_brace @ ('{' | '(' | '[')) = macro_args_str.trim_start().chars().next() + && old_open_brace != braces.0 { - // if we turn `macro!{}` into `macro!()`/`macro![]`, we'll no longer get the implicit - // trailing semicolon, see #9913 - // NOTE: `stmt.kind != StmtKind::MacCall` because `EarlyLintPass` happens after macro expansion - let add_semi = matches!(stmt.kind, ast::StmtKind::Expr(..)) && old_open_brace == '{'; - emit_help(cx, &callsite_snippet, braces, callsite_span, add_semi); - self.done.insert(callsite_span); + // Semicolons added for statements that previously ended in braces, see issue #9913 + let add_semi = self.mac_stmt_spans.iter().any(|s| *s == mac.span()); + emit_help( + cx, + &snippet_opt(cx.sess(), mac.span()).unwrap(), + braces, + mac.span(), + add_semi, + ); } } - fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - if let Some(MacroInfo { - callsite_span, - callsite_snippet, - braces, - .. - }) = is_offending_macro(cx, expr.span, self) + // See issue #9913 + fn check_stmt(&mut self, _: &EarlyContext<'_>, stmt: &ast::Stmt) { + if let ast::StmtKind::MacCall(mac_callstmt) = &stmt.kind + && let ast::MacCallStmt { + style: ast::MacStmtStyle::Braces, + .. + } = **mac_callstmt { - emit_help(cx, &callsite_snippet, braces, callsite_span, false); - self.done.insert(callsite_span); + self.mac_stmt_spans.push(mac_callstmt.mac.span()); } } - fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) { - if let Some(MacroInfo { - callsite_span, - braces, - callsite_snippet, - .. - }) = is_offending_macro(cx, ty.span, self) - { - emit_help(cx, &callsite_snippet, braces, callsite_span, false); - self.done.insert(callsite_span); + fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac: &ast::MacroDef) { + fn check_ts(cx: &EarlyContext<'_>, ts: &TokenStream, macro_braces: &FxHashMap) { + for (i, current_token) in ts.iter().enumerate() { + if let TokenTree::Delimited(_, _, _, token_stream) = current_token { + // Peel extra braces and parenthesis in macros! + check_ts(cx, token_stream, macro_braces); + } else + // |-TokenKind::Bang + // v + // println! { "Hi" } + // ^^^^^^^ + // | ^^^^^^^^ Brackets always come 1 token after TokenKind::Bang + // ident_token + if let TokenTree::Token( + Token { + kind: TokenKind::Ident(ident_token, _), + span: ident_span, + }, + _, + ) = current_token + && let Some(bang_token) = ts.get(i + 1) + && let Some(macro_args_token) = ts.get(i + 2) + && let TokenTree::Token( + Token { + kind: TokenKind::Bang, .. + }, + _, + ) = *bang_token + && let TokenTree::Delimited(delim_span, _, delim, _) = macro_args_token + // Span from ident_token to brackets (so, the full macro call) + && let snip_span = ident_span.with_hi(delim_span.close.hi()) + && let Some(snip) = snippet_opt(cx, snip_span) + && let Some(&braces) = macro_braces.get(ident_token.as_str()) + && let Some(old_open_brace) = match delim { + Delimiter::Brace => Some('{'), + Delimiter::Parenthesis => Some('('), + Delimiter::Bracket => Some('['), + Delimiter::Invisible(_) => None, + } + && old_open_brace != braces.0 + { + emit_help(cx, &snip, braces, snip_span, false); + } + } } - } -} - -fn is_offending_macro(cx: &EarlyContext<'_>, span: Span, mac_braces: &MacroBraces) -> Option { - let unnested_or_local = |span: Span| { - !span.from_expansion() - || span - .macro_backtrace() - .last() - .is_some_and(|e| e.macro_def_id.is_some_and(DefId::is_local)) - }; - let mut ctxt = span.ctxt(); - while !ctxt.is_root() { - let expn_data = ctxt.outer_expn_data(); - if let ExpnKind::Macro(MacroKind::Bang, mac_name) = expn_data.kind - && let name = mac_name.as_str() - && let Some(&braces) = mac_braces.macro_braces.get(name) - && let Some(snip) = expn_data.call_site.get_text(cx) - // we must check only invocation sites - // https://github.com/rust-lang/rust-clippy/issues/7422 - && let Some(macro_args_str) = snip.strip_prefix(name).and_then(|snip| snip.strip_prefix('!')) - && let Some(old_open_brace @ ('{' | '(' | '[')) = macro_args_str.trim_start().chars().next() - && old_open_brace != braces.0 - && unnested_or_local(expn_data.call_site) - && !mac_braces.done.contains(&expn_data.call_site) - { - return Some(MacroInfo { - callsite_span: expn_data.call_site, - callsite_snippet: snip, - old_open_brace, - braces, - }); + if mac.macro_rules { + check_ts(cx, &mac.body.tokens, &self.macro_braces.0); } - - ctxt = expn_data.call_site.ctxt(); } - - None } fn emit_help(cx: &EarlyContext<'_>, snip: &str, (open, close): (char, char), span: Span, add_semi: bool) { @@ -171,17 +157,21 @@ fn emit_help(cx: &EarlyContext<'_>, snip: &str, (open, close): (char, char), spa } } -fn macro_braces(conf: &[MacroMatcher]) -> FxHashMap { +fn macro_braces(conf: &[MacroMatcher]) -> (FxHashMap, usize) { + // TODO: Use `Symbol`s here, instead of strings. let mut braces = FxHashMap::from_iter( [ - ("print", ('(', ')')), - ("println", ('(', ')')), + ("assert_matches", ('(', ')')), + ("cfg_select", ('{', '}')), + ("debug_assert_matches", ('(', ')')), + ("format", ('(', ')')), + ("format_args", ('(', ')')), ("eprint", ('(', ')')), ("eprintln", ('(', ')')), + ("print", ('(', ')')), + ("println", ('(', ')')), ("write", ('(', ')')), ("writeln", ('(', ')')), - ("format", ('(', ')')), - ("format_args", ('(', ')')), ("vec", ('[', ']')), ("matches", ('(', ')')), ] @@ -191,5 +181,17 @@ fn macro_braces(conf: &[MacroMatcher]) -> FxHashMap { for it in conf { braces.insert(it.name.clone(), it.braces); } - braces + + #[expect( + rustc::potential_query_instability, + reason = "iteration order does not matter for `.max()`" + )] + #[expect(clippy::redundant_closure_for_method_calls, reason = "Clarity")] + let max_len = braces + .keys() + .map(|macro_name| macro_name.len()) + .max() + .expect("`braces` is non-empty"); + + (braces, max_len) } diff --git a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed index 3683e826aa925..07d7bc55d9183 100644 --- a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed +++ b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed @@ -15,10 +15,11 @@ proc_macro_derive::foo_bar!(); #[rustfmt::skip] macro_rules! test { - () => { + () => {{ + //~v nonstandard_macro_braces vec![0, 0, 0] //~^ nonstandard_macro_braces - }; + }}; } #[rustfmt::skip] diff --git a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs index c1779dceff172..9ec181c3fbd45 100644 --- a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs +++ b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs @@ -15,10 +15,11 @@ proc_macro_derive::foo_bar!(); #[rustfmt::skip] macro_rules! test { - () => { + () => {{ + //~v nonstandard_macro_braces vec!{0, 0, 0} //~^ nonstandard_macro_braces - }; + }}; } #[rustfmt::skip] diff --git a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr index 2488f7fa01e5b..de6d5e7cc243d 100644 --- a/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr +++ b/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr @@ -1,88 +1,91 @@ error: use of irregular braces for `vec!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:45:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:20:9 | -LL | let _ = vec! {1, 2, 3}; - | ^^^^^^^^^^^^^^ help: consider writing: `vec![1, 2, 3]` +LL | vec!{0, 0, 0} + | ^^^^^^^^^^^^^ help: consider writing: `vec![0, 0, 0]` | = note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::nonstandard_macro_braces)]` +error: use of irregular braces for `vec!` macro + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:46:13 + | +LL | let _ = vec! {1, 2, 3}; + | ^^^^^^^^^^^^^^ help: consider writing: `vec![1, 2, 3]` + error: use of irregular braces for `format!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:47:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:48:13 | LL | let _ = format!["ugh {} stop being such a good compiler", "hello"]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `format!("ugh {} stop being such a good compiler", "hello")` error: use of irregular braces for `matches!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:49:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:50:13 | LL | let _ = matches!{{}, ()}; | ^^^^^^^^^^^^^^^^ help: consider writing: `matches!({}, ())` error: use of irregular braces for `quote!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:51:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:52:13 | LL | let _ = quote!(let x = 1;); | ^^^^^^^^^^^^^^^^^^ help: consider writing: `quote!{let x = 1;}` error: use of irregular braces for `quote::quote!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:53:13 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:54:13 | LL | let _ = quote::quote!(match match match); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `quote::quote!{match match match}` -error: use of irregular braces for `vec!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:19:9 - | -LL | vec!{0, 0, 0} - | ^^^^^^^^^^^^^ help: consider writing: `vec![0, 0, 0]` -... -LL | let _ = test!(); // trigger when macro def is inside our own crate - | ------- in this macro invocation - | - = note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info) - error: use of irregular braces for `type_pos!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:63:12 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:64:12 | LL | let _: type_pos!(usize) = vec![]; | ^^^^^^^^^^^^^^^^ help: consider writing: `type_pos![usize]` error: use of irregular braces for `eprint!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:66:5 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:67:5 | LL | eprint!("test if user config overrides defaults"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `eprint!["test if user config overrides defaults"]` error: use of irregular braces for `println!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:75:5 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:76:5 | LL | println! {"hello world"} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `println!("hello world");` error: use of irregular braces for `println!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:83:5 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:84:5 | LL | println![]; | ^^^^^^^^^^ help: consider writing: `println!()` error: use of irregular braces for `println!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:85:5 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:86:5 | LL | println![""]; | ^^^^^^^^^^^^ help: consider writing: `println!("")` error: use of irregular braces for `println!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:87:5 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:88:5 | LL | println! {}; | ^^^^^^^^^^^ help: consider writing: `println!()` error: use of irregular braces for `println!` macro - --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:89:5 + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:90:5 | LL | println! {""}; | ^^^^^^^^^^^^^ help: consider writing: `println!("")` -error: aborting due to 13 previous errors +error: use of irregular braces for `vec!` macro + --> tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs:20:9 + | +LL | vec!{0, 0, 0} + | ^^^^^^^^^^^^^ help: consider writing: `vec![0, 0, 0]` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 14 previous errors diff --git a/tests/ui/println_empty_string.fixed b/tests/ui/println_empty_string.fixed index a735795df432a..32d46f07ac87d 100644 --- a/tests/ui/println_empty_string.fixed +++ b/tests/ui/println_empty_string.fixed @@ -1,5 +1,5 @@ #![warn(clippy::println_empty_string)] -#![expect(clippy::match_single_binding)] +#![expect(clippy::match_single_binding, clippy::nonstandard_macro_braces)] fn main() { println!(); diff --git a/tests/ui/println_empty_string.rs b/tests/ui/println_empty_string.rs index d081338f02a11..1d3912dc84c0b 100644 --- a/tests/ui/println_empty_string.rs +++ b/tests/ui/println_empty_string.rs @@ -1,5 +1,5 @@ #![warn(clippy::println_empty_string)] -#![expect(clippy::match_single_binding)] +#![expect(clippy::match_single_binding, clippy::nonstandard_macro_braces)] fn main() { println!(); diff --git a/tests/ui/unnecessary_trailing_comma.fixed b/tests/ui/unnecessary_trailing_comma.fixed index f418fe954d400..6e034c126fb07 100644 --- a/tests/ui/unnecessary_trailing_comma.fixed +++ b/tests/ui/unnecessary_trailing_comma.fixed @@ -1,5 +1,6 @@ // run-rustfix #![warn(clippy::unnecessary_trailing_comma)] +#![allow(clippy::nonstandard_macro_braces)] fn main() {} diff --git a/tests/ui/unnecessary_trailing_comma.rs b/tests/ui/unnecessary_trailing_comma.rs index 26770ffaeee18..5616ac254f1ad 100644 --- a/tests/ui/unnecessary_trailing_comma.rs +++ b/tests/ui/unnecessary_trailing_comma.rs @@ -1,5 +1,6 @@ // run-rustfix #![warn(clippy::unnecessary_trailing_comma)] +#![allow(clippy::nonstandard_macro_braces)] fn main() {} diff --git a/tests/ui/unnecessary_trailing_comma.stderr b/tests/ui/unnecessary_trailing_comma.stderr index 8ff7195a147b0..78c6476f6ef42 100644 --- a/tests/ui/unnecessary_trailing_comma.stderr +++ b/tests/ui/unnecessary_trailing_comma.stderr @@ -1,5 +1,5 @@ error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:10:19 + --> tests/ui/unnecessary_trailing_comma.rs:11:19 | LL | println!("Foo" , ); | ^^^ help: remove the trailing comma @@ -8,115 +8,115 @@ LL | println!("Foo" , ); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_trailing_comma)]` error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:11:19 + --> tests/ui/unnecessary_trailing_comma.rs:12:19 | LL | println!{"Foo" , }; | ^^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:12:19 + --> tests/ui/unnecessary_trailing_comma.rs:13:19 | LL | println!["Foo" , ]; | ^^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:13:27 + --> tests/ui/unnecessary_trailing_comma.rs:14:27 | LL | println!("Foo={}", 1 , ); | ^^^^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:14:36 + --> tests/ui/unnecessary_trailing_comma.rs:15:36 | LL | println!(concat!("b", "o", "o") , ); | ^^^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:15:22 + --> tests/ui/unnecessary_trailing_comma.rs:16:22 | LL | println!("Foo(,)",); | ^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:16:22 + --> tests/ui/unnecessary_trailing_comma.rs:17:22 | LL | println!("Foo[,]" , ); | ^^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:17:22 + --> tests/ui/unnecessary_trailing_comma.rs:18:22 | LL | println!["Foo(,)", ]; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:18:22 + --> tests/ui/unnecessary_trailing_comma.rs:19:22 | LL | println!["Foo[,]", ]; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:19:24 + --> tests/ui/unnecessary_trailing_comma.rs:20:24 | LL | println!["Foo{{,}}", ]; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:20:24 + --> tests/ui/unnecessary_trailing_comma.rs:21:24 | LL | println!{"Foo{{,}}", }; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:21:22 + --> tests/ui/unnecessary_trailing_comma.rs:22:22 | LL | println!{"Foo(,)", }; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:22:22 + --> tests/ui/unnecessary_trailing_comma.rs:23:22 | LL | println!{"Foo[,]", }; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:23:21 + --> tests/ui/unnecessary_trailing_comma.rs:24:21 | LL | println!["Foo(,", ]; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:24:21 + --> tests/ui/unnecessary_trailing_comma.rs:25:21 | LL | println!["Foo[,", ]; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:25:24 + --> tests/ui/unnecessary_trailing_comma.rs:26:24 | LL | println!["Foo{{,}}", ]; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:26:24 + --> tests/ui/unnecessary_trailing_comma.rs:27:24 | LL | println!{"Foo{{,}}", }; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:27:21 + --> tests/ui/unnecessary_trailing_comma.rs:28:21 | LL | println!{"Foo(,", }; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:28:21 + --> tests/ui/unnecessary_trailing_comma.rs:29:21 | LL | println!{"Foo[,", }; | ^^ help: remove the trailing comma error: unnecessary trailing comma - --> tests/ui/unnecessary_trailing_comma.rs:29:42 + --> tests/ui/unnecessary_trailing_comma.rs:30:42 | LL | println!(concat!("Foo", "=", "{}"), 1,); | ^ help: remove the trailing comma From 63f26788121bb20071f0f3cc726b607158f6c0d2 Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Mon, 6 Jul 2026 17:18:59 +0200 Subject: [PATCH 27/63] test(`ref_binding_to_reference`): enable autofix Multi-span suggestions work now! Unlike the lint, unfortunately. --- tests/ui/ref_binding_to_reference.fixed | 99 ++++++++++++++++++++++++ tests/ui/ref_binding_to_reference.rs | 16 ++-- tests/ui/ref_binding_to_reference.stderr | 42 ++-------- 3 files changed, 116 insertions(+), 41 deletions(-) create mode 100644 tests/ui/ref_binding_to_reference.fixed diff --git a/tests/ui/ref_binding_to_reference.fixed b/tests/ui/ref_binding_to_reference.fixed new file mode 100644 index 0000000000000..0a16bed4a43b6 --- /dev/null +++ b/tests/ui/ref_binding_to_reference.fixed @@ -0,0 +1,99 @@ +#![warn(clippy::ref_binding_to_reference)] +#![expect(clippy::explicit_auto_deref)] +#![allow(clippy::needless_borrowed_reference)] + +fn f1(_: &str) {} +macro_rules! m2 { + ($e:expr) => { + f1(*$e) + }; +} +macro_rules! m3 { + ($i:ident) => { + Some(ref $i) + }; +} + +fn main() { + let x = String::new(); + + // Ok, the pattern is from a macro + let _: &&String = match Some(&x) { + m3!(x) => x, + None => return, + }; + + // Err, reference to a &String + #[expect( + clippy::ref_binding_to_reference, + reason = "The suggestion doesn't compile, see https://github.com/rust-lang/rust-clippy/issues/17370" + )] + let _: &&String = match Some(&x) { + Some(ref x) => x, + None => return, + }; + + // Err, reference to a &String + #[expect( + clippy::ref_binding_to_reference, + reason = "The suggestion doesn't compile, see https://github.com/rust-lang/rust-clippy/issues/17370" + )] + let _: &&String = match Some(&x) { + Some(ref x) => { + f1(x); + f1(*x); + x + }, + None => return, + }; + + // Err, reference to a &String + match Some(&x) { + Some(x) => m2!(&x), + //~^ ref_binding_to_reference + None => return, + } + + // Err, reference to a &String + let _ = |&x: &&String| { + //~^ ref_binding_to_reference + + let _: &&String = &x; + }; +} + +// Err, reference to a &String +fn f2<'a>(&x: &&'a String) -> &'a String { + //~^ ref_binding_to_reference + + let _: &&String = &x; + x +} + +trait T1 { + // Err, reference to a &String + fn f(&x: &&String) { + //~^ ref_binding_to_reference + + let _: &&String = &x; + } +} + +struct S; +impl T1 for S { + // Err, reference to a &String + fn f(&x: &&String) { + //~^ ref_binding_to_reference + + let _: &&String = &x; + } +} + +fn check_expect_suppression() { + let x = String::new(); + #[expect(clippy::ref_binding_to_reference)] + let _: &&String = match Some(&x) { + Some(ref x) => x, + None => return, + }; +} diff --git a/tests/ui/ref_binding_to_reference.rs b/tests/ui/ref_binding_to_reference.rs index a0f0b7b46ea42..04d8c9e95cf33 100644 --- a/tests/ui/ref_binding_to_reference.rs +++ b/tests/ui/ref_binding_to_reference.rs @@ -1,7 +1,6 @@ -// FIXME: run-rustfix waiting on multi-span suggestions -//@no-rustfix #![warn(clippy::ref_binding_to_reference)] -#![expect(clippy::explicit_auto_deref, clippy::needless_borrowed_reference)] +#![expect(clippy::explicit_auto_deref)] +#![allow(clippy::needless_borrowed_reference)] fn f1(_: &str) {} macro_rules! m2 { @@ -25,17 +24,22 @@ fn main() { }; // Err, reference to a &String + #[expect( + clippy::ref_binding_to_reference, + reason = "The suggestion doesn't compile, see https://github.com/rust-lang/rust-clippy/issues/17370" + )] let _: &&String = match Some(&x) { Some(ref x) => x, - //~^ ref_binding_to_reference None => return, }; // Err, reference to a &String + #[expect( + clippy::ref_binding_to_reference, + reason = "The suggestion doesn't compile, see https://github.com/rust-lang/rust-clippy/issues/17370" + )] let _: &&String = match Some(&x) { Some(ref x) => { - //~^ ref_binding_to_reference - f1(x); f1(*x); x diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index d06ca7458527c..b16cccf6f2399 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -1,47 +1,19 @@ error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:29:14 + --> tests/ui/ref_binding_to_reference.rs:52:14 | -LL | Some(ref x) => x, +LL | Some(ref x) => m2!(x), | ^^^^^ | = note: `-D clippy::ref-binding-to-reference` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::ref_binding_to_reference)]` help: try | -LL - Some(ref x) => x, -LL + Some(x) => &x, - | - -error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:36:14 - | -LL | Some(ref x) => { - | ^^^^^ - | -help: try - | -LL ~ Some(x) => { -LL | -LL | -LL | f1(x); -LL ~ f1(x); -LL ~ &x - | - -error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:48:14 - | -LL | Some(ref x) => m2!(x), - | ^^^^^ - | -help: try - | LL - Some(ref x) => m2!(x), LL + Some(x) => m2!(&x), | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:54:15 + --> tests/ui/ref_binding_to_reference.rs:58:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ @@ -55,7 +27,7 @@ LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:62:12 + --> tests/ui/ref_binding_to_reference.rs:66:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -70,7 +42,7 @@ LL ~ x | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:71:11 + --> tests/ui/ref_binding_to_reference.rs:75:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -84,7 +56,7 @@ LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> tests/ui/ref_binding_to_reference.rs:81:11 + --> tests/ui/ref_binding_to_reference.rs:85:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -97,5 +69,5 @@ LL | LL ~ let _: &&String = &x; | -error: aborting due to 7 previous errors +error: aborting due to 5 previous errors From 4ad3b146bca4e302a982b5835414e927a92b38bd Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Mon, 6 Jul 2026 17:56:39 +0200 Subject: [PATCH 28/63] `tests_outside_test_module`: put code in backticks in the lint message --- clippy_lints/src/tests_outside_test_module.rs | 4 ++-- tests/ui/tests_outside_test_module.rs | 4 ++-- tests/ui/tests_outside_test_module.stderr | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/tests_outside_test_module.rs b/clippy_lints/src/tests_outside_test_module.rs index 3cd4fefffadf3..229b14ce41123 100644 --- a/clippy_lints/src/tests_outside_test_module.rs +++ b/clippy_lints/src/tests_outside_test_module.rs @@ -66,9 +66,9 @@ impl LateLintPass<'_> for TestsOutsideTestModule { cx, TESTS_OUTSIDE_TEST_MODULE, sp, - "this function marked with #[test] is outside a #[cfg(test)] module", + "this function marked with `#[test]` is outside a `#[cfg(test)]` module", |diag| { - diag.note("move it to a testing module marked with #[cfg(test)]"); + diag.note("move it to a testing module marked with `#[cfg(test)]`"); }, ); } diff --git a/tests/ui/tests_outside_test_module.rs b/tests/ui/tests_outside_test_module.rs index 0088cbd920e92..249240004cb5d 100644 --- a/tests/ui/tests_outside_test_module.rs +++ b/tests/ui/tests_outside_test_module.rs @@ -8,8 +8,8 @@ fn main() { // Should lint #[test] fn my_test() {} -//~^ ERROR: this function marked with #[test] is outside a #[cfg(test)] module -//~| NOTE: move it to a testing module marked with #[cfg(test)] +//~^ ERROR: this function marked with `#[test]` is outside a `#[cfg(test)]` module +//~| NOTE: move it to a testing module marked with `#[cfg(test)]` #[cfg(test)] mod tests { diff --git a/tests/ui/tests_outside_test_module.stderr b/tests/ui/tests_outside_test_module.stderr index 09feae6bf2aa7..dc0d168b9658e 100644 --- a/tests/ui/tests_outside_test_module.stderr +++ b/tests/ui/tests_outside_test_module.stderr @@ -1,10 +1,10 @@ -error: this function marked with #[test] is outside a #[cfg(test)] module +error: this function marked with `#[test]` is outside a `#[cfg(test)]` module --> tests/ui/tests_outside_test_module.rs:10:1 | LL | fn my_test() {} | ^^^^^^^^^^^^^^^ | - = note: move it to a testing module marked with #[cfg(test)] + = note: move it to a testing module marked with `#[cfg(test)]` = note: `-D clippy::tests-outside-test-module` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::tests_outside_test_module)]` From 9195a73dfeecb45f0660b0cbf7954d3a4af9f2b4 Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Fri, 10 Jul 2026 14:29:58 +0200 Subject: [PATCH 29/63] test(uninit_assumed_init): rename the test file to match lint name --- tests/ui/{uninit.rs => uninit_assumed_init.rs} | 0 tests/ui/{uninit.stderr => uninit_assumed_init.stderr} | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename tests/ui/{uninit.rs => uninit_assumed_init.rs} (100%) rename tests/ui/{uninit.stderr => uninit_assumed_init.stderr} (85%) diff --git a/tests/ui/uninit.rs b/tests/ui/uninit_assumed_init.rs similarity index 100% rename from tests/ui/uninit.rs rename to tests/ui/uninit_assumed_init.rs diff --git a/tests/ui/uninit.stderr b/tests/ui/uninit_assumed_init.stderr similarity index 85% rename from tests/ui/uninit.stderr rename to tests/ui/uninit_assumed_init.stderr index a18b0020661de..3531d4eb2c389 100644 --- a/tests/ui/uninit.stderr +++ b/tests/ui/uninit_assumed_init.stderr @@ -1,5 +1,5 @@ error: this call for this type may be undefined behavior - --> tests/ui/uninit.rs:13:29 + --> tests/ui/uninit_assumed_init.rs:13:29 | LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,13 +8,13 @@ LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; = help: to override `-D warnings` add `#[allow(clippy::uninit_assumed_init)]` error: this call for this type may be undefined behavior - --> tests/ui/uninit.rs:35:29 + --> tests/ui/uninit_assumed_init.rs:35:29 | LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call for this type may be undefined behavior - --> tests/ui/uninit.rs:44:29 + --> tests/ui/uninit_assumed_init.rs:44:29 | LL | let _: T = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 3b04453e8cf6e5f75b2a26804bca163d624935c8 Mon Sep 17 00:00:00 2001 From: "addie.sh" Date: Wed, 17 Jun 2026 21:29:10 +0200 Subject: [PATCH 30/63] place FnDef behind a binder, instantiate w/ Dummy --- clippy_lints/src/casts/confusing_method_to_numeric_cast.rs | 3 ++- clippy_lints/src/methods/map_clone.rs | 2 +- clippy_lints/src/methods/or_fun_call.rs | 2 +- clippy_lints/src/useless_conversion.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 7 ++++++- clippy_utils/src/ty/mod.rs | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/casts/confusing_method_to_numeric_cast.rs b/clippy_lints/src/casts/confusing_method_to_numeric_cast.rs index 1dbcfafd6b3d3..740326d2f9420 100644 --- a/clippy_lints/src/casts/confusing_method_to_numeric_cast.rs +++ b/clippy_lints/src/casts/confusing_method_to_numeric_cast.rs @@ -65,7 +65,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, if let ty::FnDef(def_id, generics) = cast_from.kind() && let Some(method_name) = cx.tcx.opt_item_name(*def_id) - && let Some((const_name, ty_name)) = get_const_name_and_ty_name(cx, method_name, *def_id, generics.as_slice()) + && let Some((const_name, ty_name)) = + get_const_name_and_ty_name(cx, method_name, *def_id, generics.no_bound_vars().unwrap().as_slice()) { let mut applicability = Applicability::MaybeIncorrect; let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability); diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index efbb094d49c79..b88a0fe2a7775 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -121,7 +121,7 @@ fn handle_path( && let Some(ty) = args.iter().find_map(|generic_arg| generic_arg.as_type()) && let ty::Ref(_, ty, Mutability::Not) = ty.kind() && let ty::FnDef(_, lst) = cx.typeck_results().expr_ty(arg).kind() - && lst.iter().all(|l| l.as_type() == Some(*ty)) + && lst.iter().all(|l| l.no_bound_vars().unwrap().as_type() == Some(*ty)) && !should_call_clone_as_function(cx, *ty) { lint_path(cx, e.span, recv.span, is_copy(cx, ty.peel_refs())); diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 6f9e817490c12..7b2f2e9389e14 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -161,7 +161,7 @@ fn check_unwrap_or_default( let output_ty = cx .tcx .fn_sig(def_id) - .instantiate(cx.tcx, args) + .instantiate(cx.tcx, args.no_bound_vars().unwrap()) .skip_norm_wip() .skip_binder() .output(); diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index dcff26f7d6443..2961ee7081533 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -187,7 +187,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { Some(sym::Into | sym::From) ) && let ty::FnDef(_, args) = cx.typeck_results().expr_ty(arg).kind() - && let &[from_ty, to_ty] = args.into_type_list(cx.tcx).as_slice() + && let &[from_ty, to_ty] = args.no_bound_vars().unwrap().into_type_list(cx.tcx).as_slice() && same_type_modulo_regions(from_ty, to_ty) { span_lint_and_then( diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 5c61f424adf1a..26adf25a348fc 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -369,7 +369,12 @@ fn check_terminator<'tcx>( // FIXME: when analyzing a function with generic parameters, we may not have enough information to // resolve to an instance. However, we could check if a host effect predicate can guarantee that // this can be made a `const` call. - let fn_def_id = match Instance::try_resolve(cx.tcx, cx.typing_env(), *fn_def_id, fn_substs) { + let fn_def_id = match Instance::try_resolve( + cx.tcx, + cx.typing_env(), + *fn_def_id, + fn_substs.no_bound_vars().unwrap(), + ) { Ok(Some(fn_inst)) => fn_inst.def_id(), Ok(None) => return Err((span, format!("cannot resolve instance for {func:?}").into())), Err(_) => return Err((span, format!("error during instance resolution of {func:?}").into())), diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index e4541eb2d6061..d7298b5de2a1b 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -713,7 +713,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig( - cx.tcx.fn_sig(id).instantiate(cx.tcx, subs).skip_norm_wip(), + cx.tcx.fn_sig(id).instantiate(cx.tcx, subs.no_bound_vars().unwrap()).skip_norm_wip(), Some(id), )), ty::Alias(_, AliasTy { From 518f8eac7027c4031f3e6efd915b9e5d50b295b2 Mon Sep 17 00:00:00 2001 From: Cory Gabrielsen Date: Tue, 19 May 2026 03:25:48 -0700 Subject: [PATCH 31/63] Add `definition_in_module_root` restriction lint Flags definitions (struct, enum, fn, impl, trait, etc.) in `mod.rs` files. Encourages putting each definition in its own named file so filenames are descriptive and unique. `lib.rs` and `main.rs` are not checked, since defining a small crate's API there is common and reasonable. Filenames are resolved through the source map so `#[path]` is handled by the real filename. `#[macro_export]` macros and inline modules are exempt. Items produced by macro expansion are skipped. Projects opting into this lint will typically also `allow(module_inception)`, since enforcing declarations-only in `mod.rs` makes `foo/foo.rs` the expected layout. Category: `restriction`. changelog: new lint: [`definition_in_module_root`] Co-authored-by: Samuel Tardieu --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/definition_in_module_root.rs | 161 ++++++++++++++++++ clippy_lints/src/lib.rs | 2 + .../fail_edge_cases/Cargo.stderr | 87 ++++++++++ .../fail_edge_cases/Cargo.toml | 5 + .../fail_edge_cases/src/edge_cases/mod.rs | 59 +++++++ .../fail_edge_cases/src/edge_cases/sub.rs | 6 + .../fail_edge_cases/src/lib.rs | 4 + .../fail_edge_cases/src/other.rs | 3 + .../fail_mod/Cargo.stderr | 64 +++++++ .../fail_mod/Cargo.toml | 5 + .../fail_mod/src/lib.rs | 3 + .../fail_mod/src/stuff/mod.rs | 21 +++ .../fail_path_attr/Cargo.stderr | 19 +++ .../fail_path_attr/Cargo.toml | 5 + .../fail_path_attr/src/custom/mod.rs | 2 + .../fail_path_attr/src/lib.rs | 5 + .../pass_bin/Cargo.toml | 5 + .../pass_bin/src/main.rs | 8 + .../pass_lib_with_definitions/Cargo.toml | 5 + .../pass_lib_with_definitions/src/lib.rs | 12 ++ .../pass_path_attr/Cargo.toml | 5 + .../pass_path_attr/src/custom/impl.rs | 2 + .../pass_path_attr/src/lib.rs | 5 + 25 files changed, 495 insertions(+) create mode 100644 clippy_lints/src/definition_in_module_root.rs create mode 100644 tests/ui-cargo/definition_in_module_root/fail_edge_cases/Cargo.stderr create mode 100644 tests/ui-cargo/definition_in_module_root/fail_edge_cases/Cargo.toml create mode 100644 tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/edge_cases/mod.rs create mode 100644 tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/edge_cases/sub.rs create mode 100644 tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/lib.rs create mode 100644 tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/other.rs create mode 100644 tests/ui-cargo/definition_in_module_root/fail_mod/Cargo.stderr create mode 100644 tests/ui-cargo/definition_in_module_root/fail_mod/Cargo.toml create mode 100644 tests/ui-cargo/definition_in_module_root/fail_mod/src/lib.rs create mode 100644 tests/ui-cargo/definition_in_module_root/fail_mod/src/stuff/mod.rs create mode 100644 tests/ui-cargo/definition_in_module_root/fail_path_attr/Cargo.stderr create mode 100644 tests/ui-cargo/definition_in_module_root/fail_path_attr/Cargo.toml create mode 100644 tests/ui-cargo/definition_in_module_root/fail_path_attr/src/custom/mod.rs create mode 100644 tests/ui-cargo/definition_in_module_root/fail_path_attr/src/lib.rs create mode 100644 tests/ui-cargo/definition_in_module_root/pass_bin/Cargo.toml create mode 100644 tests/ui-cargo/definition_in_module_root/pass_bin/src/main.rs create mode 100644 tests/ui-cargo/definition_in_module_root/pass_lib_with_definitions/Cargo.toml create mode 100644 tests/ui-cargo/definition_in_module_root/pass_lib_with_definitions/src/lib.rs create mode 100644 tests/ui-cargo/definition_in_module_root/pass_path_attr/Cargo.toml create mode 100644 tests/ui-cargo/definition_in_module_root/pass_path_attr/src/custom/impl.rs create mode 100644 tests/ui-cargo/definition_in_module_root/pass_path_attr/src/lib.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 95f26ee09bbe7..8a68adabf6fe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6730,6 +6730,7 @@ Released 2018-09-13 [`default_numeric_fallback`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback [`default_trait_access`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access [`default_union_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_union_representation +[`definition_in_module_root`]: https://rust-lang.github.io/rust-clippy/master/index.html#definition_in_module_root [`deprecated_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr [`deprecated_clippy_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_clippy_cfg_attr [`deprecated_semver`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_semver diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 516f6e775e08a..9f2a8e0763084 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -95,6 +95,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[ crate::default_instead_of_iter_empty::DEFAULT_INSTEAD_OF_ITER_EMPTY_INFO, crate::default_numeric_fallback::DEFAULT_NUMERIC_FALLBACK_INFO, crate::default_union_representation::DEFAULT_UNION_REPRESENTATION_INFO, + crate::definition_in_module_root::DEFINITION_IN_MODULE_ROOT_INFO, crate::dereference::EXPLICIT_AUTO_DEREF_INFO, crate::dereference::EXPLICIT_DEREF_METHODS_INFO, crate::dereference::NEEDLESS_BORROW_INFO, diff --git a/clippy_lints/src/definition_in_module_root.rs b/clippy_lints/src/definition_in_module_root.rs new file mode 100644 index 0000000000000..002dd91c86860 --- /dev/null +++ b/clippy_lints/src/definition_in_module_root.rs @@ -0,0 +1,161 @@ +use clippy_utils::diagnostics::span_lint_and_help; +use rustc_ast::ast::{self, Inline, ItemKind, ModKind}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_session::impl_lint_pass; +use rustc_span::{FileName, SourceFile, sym}; + +declare_clippy_lint! { + /// ### What it does + /// Checks for definitions (structs, functions, traits, etc.) in `mod.rs` + /// files. `lib.rs` and `main.rs` are not checked. + /// + /// ### Why restrict this? + /// `mod.rs` is well-suited to acting as a table of contents — listing + /// submodules and re-exports while leaving definitions to named files. + /// Naming each file after its primary definition keeps filenames + /// descriptive and unique, makes editor tabs and search results easier + /// to scan, and makes the filesystem tree mirror the module tree, so + /// the file layout is uniquely determined by the module structure. + /// + /// ### Example + /// ```ignore + /// // stuff/mod.rs + /// mod bar; + /// pub struct Foo { /* ... */ } + /// impl Foo { /* ... */ } + /// ``` + /// Use instead: + /// ```ignore + /// // stuff/mod.rs + /// mod bar; + /// mod foo; + /// pub use foo::Foo; + /// + /// // stuff/foo.rs + /// pub struct Foo { /* ... */ } + /// impl Foo { /* ... */ } + /// ``` + /// + /// ### Notes + /// This lint is most useful alongside `self_named_module_files`, which + /// requires `mod.rs` files; together they constrain `mod.rs` to + /// declarations only. Under `mod_module_files` (which forbids `mod.rs` + /// entirely) this lint has nothing to fire on. + /// + /// If a definition's name matches its parent module's name, moving it + /// produces `foo/foo.rs`, which `module_inception` flags — projects + /// in that situation typically also `allow(module_inception)`. + #[clippy::version = "1.99.0"] + pub DEFINITION_IN_MODULE_ROOT, + restriction, + "definitions in `mod.rs` should be in named files" +} + +impl_lint_pass!(DefinitionInModuleRoot => [DEFINITION_IN_MODULE_ROOT]); + +#[derive(Default)] +pub struct DefinitionInModuleRoot { + /// Stack tracking whether items at the current nesting level are in a + /// `mod.rs` file. When the stack is empty, we are at crate root depth + /// (not linted). + module_stack: Vec, +} + +impl EarlyLintPass for DefinitionInModuleRoot { + fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { + // Handle module items: push state for their children. + match &item.kind { + ItemKind::Mod(.., ModKind::Loaded(_, Inline::No { .. }, mod_spans, ..)) => { + let file = cx.sess().source_map().lookup_source_file(mod_spans.inner_span.lo()); + self.module_stack.push(is_mod_rs(&file)); + return; + }, + ItemKind::Mod(..) => { + // Inline module or unloaded — children are not in a root file. + self.module_stack.push(false); + return; + }, + _ => {}, + } + + // Skip items from macro expansion. + if item.span.from_expansion() { + return; + } + + // Only lint inside mod.rs files (not at crate root depth). + if !self.module_stack.last().copied().unwrap_or(false) { + return; + } + + let Some(kind) = definition_kind(item) else { + return; + }; + + let help = if let Some(ident) = item.kind.ident() { + format!("move {kind} `{ident}` to a dedicated file") + } else { + format!("move the {kind} to a dedicated file") + }; + + span_lint_and_help( + cx, + DEFINITION_IN_MODULE_ROOT, + item.span, + "definition in module root file", + None, + help, + ); + } + + fn check_item_post(&mut self, _: &EarlyContext<'_>, item: &ast::Item) { + if matches!(item.kind, ItemKind::Mod(..)) { + self.module_stack.pop(); + } + } +} + +/// Returns a human-readable kind string for flagged items, or `None` for +/// items that are allowed in root files (modules, imports, re-exports, +/// `#[macro_export]` macros). +fn definition_kind(item: &ast::Item) -> Option<&'static str> { + match &item.kind { + i @ (ItemKind::Struct(..) + | ItemKind::Enum(..) + | ItemKind::Union(..) + | ItemKind::Fn(..) + | ItemKind::Const(..) + | ItemKind::Static(..) + | ItemKind::Impl(..) + | ItemKind::Trait(..) + | ItemKind::TraitAlias(..) + | ItemKind::TyAlias(..) + | ItemKind::ForeignMod(..)) => Some(i.descr()), + i @ ItemKind::MacroDef(..) if !has_macro_export(item) => Some(i.descr()), + ItemKind::ExternCrate(..) + | ItemKind::Use(..) + | ItemKind::ConstBlock(..) + | ItemKind::Mod(..) + | ItemKind::GlobalAsm(..) + | ItemKind::MacCall(..) + | ItemKind::MacroDef(..) + | ItemKind::Delegation(..) + | ItemKind::DelegationMac(..) => None, + } +} + +/// Check if an item has `#[macro_export]`. +fn has_macro_export(item: &ast::Item) -> bool { + item.attrs.iter().any(|attr| attr.has_name(sym::macro_export)) +} + +/// Check if a source file is `mod.rs`. +fn is_mod_rs(file: &SourceFile) -> bool { + if let FileName::Real(name) = &file.name { + name.local_path() + .and_then(|p| p.file_name()) + .is_some_and(|n| n == "mod.rs") + } else { + false + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 7b190c2558880..bcf20fe33be51 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -102,6 +102,7 @@ mod default_constructed_unit_structs; mod default_instead_of_iter_empty; mod default_numeric_fallback; mod default_union_representation; +mod definition_in_module_root; mod dereference; mod derivable_impls; mod derive; @@ -542,6 +543,7 @@ rustc_lint::early_lint_methods!( CfgNotTest: cfg_not_test::CfgNotTest = cfg_not_test::CfgNotTest, EmptyLineAfter: empty_line_after::EmptyLineAfter = empty_line_after::EmptyLineAfter::new(), InlineTraitBounds: inline_trait_bounds::InlineTraitBounds = inline_trait_bounds::InlineTraitBounds::default(), + DefinitionInModuleRoot: definition_in_module_root::DefinitionInModuleRoot = definition_in_module_root::DefinitionInModuleRoot::default(), // add early passes here, used by `cargo dev new_lint` ]] ); diff --git a/tests/ui-cargo/definition_in_module_root/fail_edge_cases/Cargo.stderr b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/Cargo.stderr new file mode 100644 index 0000000000000..7ca757f959345 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/Cargo.stderr @@ -0,0 +1,87 @@ +error: definition in module root file + --> src/edge_cases/mod.rs:13:1 + | +13 | pub struct AboveMod; + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: move struct `AboveMod` to a dedicated file + = note: `-D clippy::definition-in-module-root` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::definition_in_module_root)]` + +error: definition in module root file + --> src/edge_cases/mod.rs:20:1 + | +20 | pub struct Foo; + | ^^^^^^^^^^^^^^^ + | + = help: move struct `Foo` to a dedicated file + +error: definition in module root file + --> src/edge_cases/mod.rs:23:1 + | +23 | pub struct Generic(T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: move struct `Generic` to a dedicated file + +error: definition in module root file + --> src/edge_cases/mod.rs:24:1 + | +24 | / impl Generic { +25 | | pub fn new(t: T) -> Self { +26 | | Self(t) +27 | | } +28 | | } + | |_^ + | + = help: move the implementation to a dedicated file + +error: definition in module root file + --> src/edge_cases/mod.rs:31:1 + | +31 | pub async fn frob() {} + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: move function `frob` to a dedicated file + +error: definition in module root file + --> src/edge_cases/mod.rs:34:1 + | +34 | / pub const fn cnst() -> u32 { +35 | | 0 +36 | | } + | |_^ + | + = help: move function `cnst` to a dedicated file + +error: definition in module root file + --> src/edge_cases/mod.rs:39:1 + | +39 | pub static FOO: u32 = 1; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: move static item `FOO` to a dedicated file + +error: definition in module root file + --> src/edge_cases/mod.rs:43:1 + | +43 | / macro_rules! local_macro { +44 | | () => {}; +45 | | } + | |_^ + | + = help: move macro definition `local_macro` to a dedicated file + +error: definition in module root file + --> src/edge_cases/mod.rs:48:1 + | +48 | / pub trait WithDefault { +49 | | fn default_method(&self) -> u32 { +50 | | 42 +51 | | } +52 | | } + | |_^ + | + = help: move trait `WithDefault` to a dedicated file + +error: could not compile `fail-edge-cases` (lib) due to 9 previous errors diff --git a/tests/ui-cargo/definition_in_module_root/fail_edge_cases/Cargo.toml b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/Cargo.toml new file mode 100644 index 0000000000000..450812cfec26f --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "fail-edge-cases" +version = "0.1.0" +edition = "2021" +publish = false diff --git a/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/edge_cases/mod.rs b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/edge_cases/mod.rs new file mode 100644 index 0000000000000..0e61bf50fd425 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/edge_cases/mod.rs @@ -0,0 +1,59 @@ +#![warn(clippy::definition_in_module_root)] + +// Case g: extern crate is a declaration → no fire. +extern crate alloc; + +// Case b: re-export of named item from sibling → no fire. +pub use super::other::Bar; + +// Case c: glob re-export → no fire. +pub use super::other::*; + +// Case j (top half): item right above `mod foo;` → fires. +pub struct AboveMod; + +// Case j: nested file module declaration → no fire (declaration only). +mod sub; + +// Case a: derive — struct fires once, derived impls do NOT fire (from_expansion). +#[derive(Clone, Debug)] +pub struct Foo; + +// Case d: generics — struct fires + impl block fires. +pub struct Generic(T); +impl Generic { + pub fn new(t: T) -> Self { + Self(t) + } +} + +// Case e: async fn fires as 'function'. +pub async fn frob() {} + +// Case f: const fn fires as 'function'. +pub const fn cnst() -> u32 { + 0 +} + +// Case h: static fires as 'static'. +pub static FOO: u32 = 1; + +// Case k: non-exported macro fires as 'macro'. +#[allow(unused_macros)] +macro_rules! local_macro { + () => {}; +} + +// Case l: trait with default method body fires once (not its inner items). +pub trait WithDefault { + fn default_method(&self) -> u32 { + 42 + } +} + +// Case i: inline module — children should NOT fire. +#[cfg(test)] +mod tests { + pub struct InsideInline; + pub fn t() {} +} diff --git a/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/edge_cases/sub.rs b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/edge_cases/sub.rs new file mode 100644 index 0000000000000..202b24fd77f99 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/edge_cases/sub.rs @@ -0,0 +1,6 @@ +// Sibling file referenced by `mod sub;` in edge_cases/mod.rs. +// Items here live in a non-mod.rs file → no fire even if they are definitions. +#[allow(dead_code)] +pub struct InSub; +#[allow(dead_code)] +pub fn in_sub() {} diff --git a/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/lib.rs b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/lib.rs new file mode 100644 index 0000000000000..09a5d92a57855 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/lib.rs @@ -0,0 +1,4 @@ +#![warn(clippy::definition_in_module_root)] + +pub mod edge_cases; +pub mod other; diff --git a/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/other.rs b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/other.rs new file mode 100644 index 0000000000000..b246a8a522470 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_edge_cases/src/other.rs @@ -0,0 +1,3 @@ +// Sibling module with items that the edge_cases mod.rs re-exports. +pub struct Bar; +pub fn helper() {} diff --git a/tests/ui-cargo/definition_in_module_root/fail_mod/Cargo.stderr b/tests/ui-cargo/definition_in_module_root/fail_mod/Cargo.stderr new file mode 100644 index 0000000000000..f2034397dec03 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_mod/Cargo.stderr @@ -0,0 +1,64 @@ +error: definition in module root file + --> src/stuff/mod.rs:4:1 + | +4 | pub struct Foo; + | ^^^^^^^^^^^^^^^ + | + = help: move struct `Foo` to a dedicated file + = note: `-D clippy::definition-in-module-root` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::definition_in_module_root)]` + +error: definition in module root file + --> src/stuff/mod.rs:5:1 + | +5 | / pub enum Bar { +6 | | A, +7 | | B, +8 | | } + | |_^ + | + = help: move enum `Bar` to a dedicated file + +error: definition in module root file + --> src/stuff/mod.rs:9:1 + | +9 | pub fn baz() {} + | ^^^^^^^^^^^^^^^ + | + = help: move function `baz` to a dedicated file + +error: definition in module root file + --> src/stuff/mod.rs:10:1 + | +10 | pub const QUUX: u32 = 1; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: move constant item `QUUX` to a dedicated file + +error: definition in module root file + --> src/stuff/mod.rs:11:1 + | +11 | pub trait Trait1 {} + | ^^^^^^^^^^^^^^^^^^^ + | + = help: move trait `Trait1` to a dedicated file + +error: definition in module root file + --> src/stuff/mod.rs:12:1 + | +12 | pub type Alias = std::result::Result; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: move type alias `Alias` to a dedicated file + +error: definition in module root file + --> src/stuff/mod.rs:13:1 + | +13 | / impl Foo { +14 | | pub fn method(&self) {} +15 | | } + | |_^ + | + = help: move the implementation to a dedicated file + +error: could not compile `fail-mod` (lib) due to 7 previous errors diff --git a/tests/ui-cargo/definition_in_module_root/fail_mod/Cargo.toml b/tests/ui-cargo/definition_in_module_root/fail_mod/Cargo.toml new file mode 100644 index 0000000000000..575ff58cadec5 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_mod/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "fail-mod" +version = "0.1.0" +edition = "2021" +publish = false diff --git a/tests/ui-cargo/definition_in_module_root/fail_mod/src/lib.rs b/tests/ui-cargo/definition_in_module_root/fail_mod/src/lib.rs new file mode 100644 index 0000000000000..3c232b85fae89 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_mod/src/lib.rs @@ -0,0 +1,3 @@ +#![warn(clippy::definition_in_module_root)] + +pub mod stuff; diff --git a/tests/ui-cargo/definition_in_module_root/fail_mod/src/stuff/mod.rs b/tests/ui-cargo/definition_in_module_root/fail_mod/src/stuff/mod.rs new file mode 100644 index 0000000000000..e52225e55856a --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_mod/src/stuff/mod.rs @@ -0,0 +1,21 @@ +#![warn(clippy::definition_in_module_root)] + +// Every definition kind should trigger the lint. +pub struct Foo; +pub enum Bar { + A, + B, +} +pub fn baz() {} +pub const QUUX: u32 = 1; +pub trait Trait1 {} +pub type Alias = std::result::Result; +impl Foo { + pub fn method(&self) {} +} + +// macro_export macros are allowed. +#[macro_export] +macro_rules! ok { + () => {}; +} diff --git a/tests/ui-cargo/definition_in_module_root/fail_path_attr/Cargo.stderr b/tests/ui-cargo/definition_in_module_root/fail_path_attr/Cargo.stderr new file mode 100644 index 0000000000000..1423f9145e99c --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_path_attr/Cargo.stderr @@ -0,0 +1,19 @@ +error: definition in module root file + --> src/custom/mod.rs:1:1 + | +1 | pub struct Foo; + | ^^^^^^^^^^^^^^^ + | + = help: move struct `Foo` to a dedicated file + = note: `-D clippy::definition-in-module-root` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::definition_in_module_root)]` + +error: definition in module root file + --> src/custom/mod.rs:2:1 + | +2 | pub fn bar() {} + | ^^^^^^^^^^^^^^^ + | + = help: move function `bar` to a dedicated file + +error: could not compile `fail-path-attr` (lib) due to 2 previous errors diff --git a/tests/ui-cargo/definition_in_module_root/fail_path_attr/Cargo.toml b/tests/ui-cargo/definition_in_module_root/fail_path_attr/Cargo.toml new file mode 100644 index 0000000000000..3f57a420e2f64 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_path_attr/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "fail-path-attr" +version = "0.1.0" +edition = "2021" +publish = false diff --git a/tests/ui-cargo/definition_in_module_root/fail_path_attr/src/custom/mod.rs b/tests/ui-cargo/definition_in_module_root/fail_path_attr/src/custom/mod.rs new file mode 100644 index 0000000000000..b12603cbeac85 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_path_attr/src/custom/mod.rs @@ -0,0 +1,2 @@ +pub struct Foo; +pub fn bar() {} diff --git a/tests/ui-cargo/definition_in_module_root/fail_path_attr/src/lib.rs b/tests/ui-cargo/definition_in_module_root/fail_path_attr/src/lib.rs new file mode 100644 index 0000000000000..8e7cd55b614d9 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/fail_path_attr/src/lib.rs @@ -0,0 +1,5 @@ +#![warn(clippy::definition_in_module_root)] + +// #[path] to a mod.rs — definitions inside should still trigger. +#[path = "custom/mod.rs"] +pub mod things; diff --git a/tests/ui-cargo/definition_in_module_root/pass_bin/Cargo.toml b/tests/ui-cargo/definition_in_module_root/pass_bin/Cargo.toml new file mode 100644 index 0000000000000..757e4f2068c16 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/pass_bin/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "pass-bin" +version = "0.1.0" +edition = "2021" +publish = false diff --git a/tests/ui-cargo/definition_in_module_root/pass_bin/src/main.rs b/tests/ui-cargo/definition_in_module_root/pass_bin/src/main.rs new file mode 100644 index 0000000000000..4e7b641104da9 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/pass_bin/src/main.rs @@ -0,0 +1,8 @@ +#![warn(clippy::definition_in_module_root)] + +// Definitions in main.rs are allowed — the lint only applies to mod.rs. +pub struct Foo; +pub fn bar() {} +pub const BAZ: u32 = 1; + +fn main() {} diff --git a/tests/ui-cargo/definition_in_module_root/pass_lib_with_definitions/Cargo.toml b/tests/ui-cargo/definition_in_module_root/pass_lib_with_definitions/Cargo.toml new file mode 100644 index 0000000000000..49d81d648aa27 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/pass_lib_with_definitions/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "pass-lib-with-definitions" +version = "0.1.0" +edition = "2021" +publish = false diff --git a/tests/ui-cargo/definition_in_module_root/pass_lib_with_definitions/src/lib.rs b/tests/ui-cargo/definition_in_module_root/pass_lib_with_definitions/src/lib.rs new file mode 100644 index 0000000000000..dbe20ce7bd27e --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/pass_lib_with_definitions/src/lib.rs @@ -0,0 +1,12 @@ +#![warn(clippy::definition_in_module_root)] + +// Definitions in lib.rs are allowed — the lint only applies to mod.rs. +pub struct Foo; +pub enum Bar { + A, + B, +} +pub fn baz() {} +pub const QUUX: u32 = 1; +pub trait Trait1 {} +pub type Alias = std::result::Result; diff --git a/tests/ui-cargo/definition_in_module_root/pass_path_attr/Cargo.toml b/tests/ui-cargo/definition_in_module_root/pass_path_attr/Cargo.toml new file mode 100644 index 0000000000000..d1ab114ffa855 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/pass_path_attr/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "pass-path-attr" +version = "0.1.0" +edition = "2021" +publish = false diff --git a/tests/ui-cargo/definition_in_module_root/pass_path_attr/src/custom/impl.rs b/tests/ui-cargo/definition_in_module_root/pass_path_attr/src/custom/impl.rs new file mode 100644 index 0000000000000..b12603cbeac85 --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/pass_path_attr/src/custom/impl.rs @@ -0,0 +1,2 @@ +pub struct Foo; +pub fn bar() {} diff --git a/tests/ui-cargo/definition_in_module_root/pass_path_attr/src/lib.rs b/tests/ui-cargo/definition_in_module_root/pass_path_attr/src/lib.rs new file mode 100644 index 0000000000000..2dd719a87877d --- /dev/null +++ b/tests/ui-cargo/definition_in_module_root/pass_path_attr/src/lib.rs @@ -0,0 +1,5 @@ +#![warn(clippy::definition_in_module_root)] + +// #[path] to a named file — definitions should not trigger. +#[path = "custom/impl.rs"] +pub mod things; From 1ababc2d65ff52db62dcf6814cc8a7cf49eb50d5 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 6 Jul 2026 17:03:22 +0200 Subject: [PATCH 32/63] Add `as _` when the imported trait is not directly used --- clippy_config/src/conf.rs | 10 +++++----- clippy_config/src/metadata.rs | 2 +- clippy_dev/src/dogfood.rs | 2 +- clippy_dev/src/fmt.rs | 6 +++--- clippy_dev/src/generate.rs | 4 ++-- clippy_dev/src/release.rs | 2 +- clippy_dev/src/sync.rs | 2 +- clippy_dev/src/utils.rs | 2 +- clippy_lints/src/almost_complete_range.rs | 2 +- clippy_lints/src/arc_with_non_send_sync.rs | 2 +- clippy_lints/src/as_conversions.rs | 2 +- clippy_lints/src/asm_syntax.rs | 2 +- clippy_lints/src/assertions_on_result_states.rs | 2 +- clippy_lints/src/assigning_clones.rs | 2 +- clippy_lints/src/attrs/allow_attributes.rs | 4 ++-- .../src/attrs/allow_attributes_without_reason.rs | 2 +- .../attrs/blanket_clippy_restriction_lints.rs | 2 +- clippy_lints/src/attrs/duplicated_attributes.rs | 2 +- clippy_lints/src/attrs/mixed_attributes_style.rs | 2 +- clippy_lints/src/attrs/mod.rs | 2 +- clippy_lints/src/attrs/non_minimal_cfg.rs | 2 +- clippy_lints/src/attrs/unnecessary_clippy_cfg.rs | 4 ++-- clippy_lints/src/attrs/useless_attribute.rs | 4 ++-- clippy_lints/src/bit_width.rs | 2 +- clippy_lints/src/blocks_in_conditions.rs | 2 +- clippy_lints/src/bool_assert_comparison.rs | 2 +- clippy_lints/src/booleans.rs | 4 ++-- clippy_lints/src/borrow_deref_ref.rs | 2 +- clippy_lints/src/box_default.rs | 6 +++--- clippy_lints/src/cargo/lint_groups_priority.rs | 2 +- .../src/cargo/multiple_crate_versions.rs | 2 +- clippy_lints/src/casts/as_ptr_cast_mut.rs | 2 +- clippy_lints/src/casts/as_underscore.rs | 2 +- clippy_lints/src/casts/cast_lossless.rs | 2 +- clippy_lints/src/casts/cast_ptr_alignment.rs | 2 +- .../src/casts/cast_slice_different_sizes.rs | 2 +- clippy_lints/src/casts/manual_dangling_ptr.rs | 4 ++-- clippy_lints/src/casts/mod.rs | 2 +- clippy_lints/src/casts/needless_type_cast.rs | 2 +- clippy_lints/src/casts/ptr_cast_constness.rs | 2 +- clippy_lints/src/casts/unnecessary_cast.rs | 4 ++-- clippy_lints/src/casts/zero_ptr.rs | 2 +- clippy_lints/src/checked_conversions.rs | 2 +- clippy_lints/src/cloned_ref_to_slice_refs.rs | 2 +- clippy_lints/src/cognitive_complexity.rs | 6 +++--- clippy_lints/src/collapsible_if.rs | 4 ++-- clippy_lints/src/collection_is_never_read.rs | 2 +- clippy_lints/src/dbg_macro.rs | 2 +- clippy_lints/src/default_numeric_fallback.rs | 2 +- clippy_lints/src/default_union_representation.rs | 2 +- clippy_lints/src/definition_in_module_root.rs | 2 +- clippy_lints/src/dereference.rs | 6 +++--- .../src/derive/derive_partial_eq_without_eq.rs | 2 +- clippy_lints/src/derive/mod.rs | 2 +- clippy_lints/src/disallowed_script_idents.rs | 4 ++-- clippy_lints/src/doc/broken_link.rs | 2 +- clippy_lints/src/doc/doc_suspicious_footnotes.rs | 2 +- clippy_lints/src/doc/lazy_continuation.rs | 2 +- clippy_lints/src/doc/markdown.rs | 2 +- clippy_lints/src/doc/missing_headers.rs | 2 +- clippy_lints/src/doc/mod.rs | 2 +- clippy_lints/src/double_parens.rs | 4 ++-- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/duplicate_mod.rs | 2 +- clippy_lints/src/duration_suboptimal_units.rs | 4 ++-- clippy_lints/src/else_if_without_else.rs | 2 +- clippy_lints/src/empty_line_after.rs | 6 +++--- clippy_lints/src/endian_bytes.rs | 4 ++-- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/equatable_if_let.rs | 2 +- clippy_lints/src/error_impl_error.rs | 2 +- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/eta_reduction.rs | 7 ++++--- clippy_lints/src/excessive_nesting.rs | 2 +- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/extra_unused_type_parameters.rs | 2 +- clippy_lints/src/fallible_impl_from.rs | 2 +- .../src/floating_point_arithmetic/mod.rs | 2 +- clippy_lints/src/format.rs | 2 +- clippy_lints/src/format_args.rs | 14 +++++++------- clippy_lints/src/format_impl.rs | 2 +- clippy_lints/src/format_push_string.rs | 4 ++-- clippy_lints/src/formatting.rs | 2 +- clippy_lints/src/four_forward_slashes.rs | 4 ++-- clippy_lints/src/from_over_into.rs | 4 ++-- clippy_lints/src/from_raw_with_void_ptr.rs | 2 +- clippy_lints/src/from_str_radix_10.rs | 2 +- clippy_lints/src/functions/must_use.rs | 2 +- .../src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- clippy_lints/src/functions/ref_option.rs | 2 +- clippy_lints/src/functions/result.rs | 4 ++-- clippy_lints/src/functions/too_many_lines.rs | 4 ++-- clippy_lints/src/future_not_send.rs | 10 +++++----- clippy_lints/src/if_let_mutex.rs | 2 +- clippy_lints/src/ifs/branches_sharing_code.rs | 4 ++-- clippy_lints/src/ifs/ifs_same_cond.rs | 2 +- clippy_lints/src/implicit_hasher.rs | 6 +++--- clippy_lints/src/implicit_return.rs | 2 +- clippy_lints/src/index_refutable_slice.rs | 2 +- clippy_lints/src/ineffective_open_options.rs | 4 ++-- clippy_lints/src/infinite_iter.rs | 2 +- clippy_lints/src/inherent_to_string.rs | 2 +- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/inline_trait_bounds.rs | 2 +- clippy_lints/src/items_after_statements.rs | 2 +- clippy_lints/src/items_after_test_module.rs | 2 +- clippy_lints/src/iter_over_hash_type.rs | 2 +- clippy_lints/src/iter_without_into_iter.rs | 2 +- clippy_lints/src/large_const_arrays.rs | 4 ++-- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/large_stack_frames.rs | 2 +- clippy_lints/src/legacy_numeric_constants.rs | 4 ++-- clippy_lints/src/len_without_is_empty.rs | 2 +- clippy_lints/src/len_zero.rs | 4 ++-- clippy_lints/src/let_if_seq.rs | 2 +- clippy_lints/src/let_underscore.rs | 2 +- clippy_lints/src/let_with_type_underscore.rs | 4 ++-- clippy_lints/src/lifetimes.rs | 6 +++--- clippy_lints/src/literal_representation.rs | 4 ++-- .../src/loops/char_indices_as_byte_indices.rs | 2 +- .../src/loops/explicit_into_iter_loop.rs | 2 +- clippy_lints/src/loops/explicit_iter_loop.rs | 2 +- clippy_lints/src/loops/for_kv_map.rs | 2 +- clippy_lints/src/loops/infinite_loop.rs | 2 +- clippy_lints/src/loops/iter_next_loop.rs | 2 +- clippy_lints/src/loops/manual_find.rs | 2 +- clippy_lints/src/loops/manual_flatten.rs | 2 +- clippy_lints/src/loops/manual_memcpy.rs | 2 +- clippy_lints/src/loops/missing_spin_loop.rs | 2 +- clippy_lints/src/loops/mod.rs | 2 +- clippy_lints/src/loops/mut_range_bound.rs | 2 +- clippy_lints/src/loops/same_item_push.rs | 2 +- clippy_lints/src/loops/unused_enumerate_index.rs | 4 ++-- clippy_lints/src/loops/utils.rs | 2 +- clippy_lints/src/loops/while_let_on_iterator.rs | 2 +- clippy_lints/src/macro_metavars_in_unsafe.rs | 4 ++-- clippy_lints/src/macro_use.rs | 2 +- clippy_lints/src/manual_abs_diff.rs | 2 +- clippy_lints/src/manual_assert.rs | 2 +- clippy_lints/src/manual_assert_eq.rs | 2 +- clippy_lints/src/manual_async_fn.rs | 2 +- clippy_lints/src/manual_clamp.rs | 4 ++-- clippy_lints/src/manual_float_methods.rs | 6 +++--- clippy_lints/src/manual_hash_one.rs | 4 ++-- clippy_lints/src/manual_ignore_case_cmp.rs | 2 +- clippy_lints/src/manual_ilog2.rs | 2 +- clippy_lints/src/manual_is_ascii_check.rs | 2 +- clippy_lints/src/manual_let_else.rs | 4 ++-- clippy_lints/src/manual_main_separator_str.rs | 2 +- clippy_lints/src/manual_non_exhaustive.rs | 2 +- clippy_lints/src/manual_option_as_slice.rs | 2 +- clippy_lints/src/manual_pop_if.rs | 2 +- clippy_lints/src/manual_range_patterns.rs | 4 ++-- clippy_lints/src/manual_rem_euclid.rs | 4 ++-- clippy_lints/src/manual_retain.rs | 2 +- clippy_lints/src/manual_take.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 2 +- clippy_lints/src/match_result_ok.rs | 2 +- clippy_lints/src/matches/collapsible_match.rs | 4 ++-- .../matches/infallible_destructuring_match.rs | 2 +- clippy_lints/src/matches/manual_filter.rs | 2 +- clippy_lints/src/matches/manual_map.rs | 2 +- clippy_lints/src/matches/manual_ok_err.rs | 2 +- clippy_lints/src/matches/manual_unwrap_or.rs | 2 +- clippy_lints/src/matches/manual_utils.rs | 2 +- clippy_lints/src/matches/match_same_arms.rs | 8 ++++---- clippy_lints/src/matches/match_single_binding.rs | 2 +- .../src/matches/match_str_case_mismatch.rs | 2 +- clippy_lints/src/matches/match_wild_enum.rs | 4 ++-- clippy_lints/src/matches/match_wild_err_arm.rs | 2 +- clippy_lints/src/matches/mod.rs | 4 ++-- clippy_lints/src/matches/needless_match.rs | 2 +- clippy_lints/src/matches/redundant_guards.rs | 2 +- .../src/matches/redundant_pattern_match.rs | 4 ++-- .../src/matches/significant_drop_in_scrutinee.rs | 4 ++-- clippy_lints/src/matches/single_match.rs | 2 +- clippy_lints/src/matches/try_err.rs | 2 +- clippy_lints/src/mem_replace.rs | 2 +- clippy_lints/src/methods/by_ref_peekable_peek.rs | 4 ++-- clippy_lints/src/methods/bytecount.rs | 2 +- clippy_lints/src/methods/bytes_count_to_len.rs | 2 +- clippy_lints/src/methods/bytes_nth.rs | 2 +- .../case_sensitive_file_extension_comparisons.rs | 4 ++-- clippy_lints/src/methods/chars_cmp.rs | 2 +- .../src/methods/chunks_exact_to_as_chunks.rs | 2 +- clippy_lints/src/methods/clear_with_drain.rs | 2 +- clippy_lints/src/methods/clone_on_ref_ptr.rs | 2 +- .../src/methods/cloned_instead_of_copied.rs | 2 +- .../src/methods/double_ended_iterator_last.rs | 2 +- clippy_lints/src/methods/drain_collect.rs | 2 +- clippy_lints/src/methods/expect_fun_call.rs | 2 +- clippy_lints/src/methods/extend_with_drain.rs | 2 +- clippy_lints/src/methods/filetype_is_file.rs | 2 +- clippy_lints/src/methods/filter_map.rs | 2 +- clippy_lints/src/methods/filter_map_bool_then.rs | 6 +++--- clippy_lints/src/methods/filter_map_identity.rs | 2 +- clippy_lints/src/methods/filter_map_next.rs | 2 +- clippy_lints/src/methods/flat_map_identity.rs | 2 +- clippy_lints/src/methods/flat_map_option.rs | 2 +- clippy_lints/src/methods/format_collect.rs | 2 +- clippy_lints/src/methods/get_first.rs | 2 +- clippy_lints/src/methods/implicit_clone.rs | 2 +- .../src/methods/inefficient_to_string.rs | 2 +- clippy_lints/src/methods/inspect_for_each.rs | 2 +- clippy_lints/src/methods/into_iter_on_ref.rs | 2 +- clippy_lints/src/methods/io_other_error.rs | 2 +- clippy_lints/src/methods/is_empty.rs | 4 ++-- clippy_lints/src/methods/iter_cloned_collect.rs | 2 +- clippy_lints/src/methods/iter_count.rs | 2 +- clippy_lints/src/methods/iter_filter.rs | 2 +- clippy_lints/src/methods/iter_kv_map.rs | 2 +- clippy_lints/src/methods/iter_next_slice.rs | 2 +- clippy_lints/src/methods/iter_nth.rs | 2 +- clippy_lints/src/methods/iter_nth_zero.rs | 2 +- clippy_lints/src/methods/iter_out_of_bounds.rs | 2 +- clippy_lints/src/methods/iter_skip_next.rs | 2 +- clippy_lints/src/methods/iter_skip_zero.rs | 2 +- clippy_lints/src/methods/iter_with_drain.rs | 2 +- .../src/methods/iterator_step_by_zero.rs | 2 +- clippy_lints/src/methods/join_absolute_paths.rs | 2 +- clippy_lints/src/methods/lines_filter_map_ok.rs | 2 +- clippy_lints/src/methods/manual_clear.rs | 2 +- clippy_lints/src/methods/manual_inspect.rs | 4 ++-- .../src/methods/manual_is_variant_and.rs | 2 +- clippy_lints/src/methods/manual_next_back.rs | 2 +- clippy_lints/src/methods/manual_ok_or.rs | 4 ++-- clippy_lints/src/methods/manual_option_zip.rs | 2 +- clippy_lints/src/methods/manual_repeat_n.rs | 2 +- .../src/methods/manual_saturating_arithmetic.rs | 4 ++-- clippy_lints/src/methods/manual_str_repeat.rs | 2 +- clippy_lints/src/methods/manual_try_fold.rs | 6 +++--- clippy_lints/src/methods/map_all_any_identity.rs | 4 ++-- clippy_lints/src/methods/map_clone.rs | 2 +- .../src/methods/map_collect_result_unit.rs | 2 +- clippy_lints/src/methods/map_err_ignore.rs | 2 +- clippy_lints/src/methods/map_flatten.rs | 2 +- clippy_lints/src/methods/map_identity.rs | 4 ++-- clippy_lints/src/methods/map_or_identity.rs | 2 +- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/methods/mut_mutex_lock.rs | 2 +- clippy_lints/src/methods/needless_as_bytes.rs | 2 +- .../src/methods/needless_character_iteration.rs | 4 ++-- clippy_lints/src/methods/needless_collect.rs | 2 +- .../src/methods/needless_option_as_deref.rs | 4 ++-- clippy_lints/src/methods/needless_option_take.rs | 2 +- clippy_lints/src/methods/no_effect_replace.rs | 2 +- clippy_lints/src/methods/ok_expect.rs | 2 +- clippy_lints/src/methods/open_options.rs | 2 +- clippy_lints/src/methods/option_as_ref_cloned.rs | 2 +- clippy_lints/src/methods/option_as_ref_deref.rs | 2 +- clippy_lints/src/methods/option_map_or_none.rs | 2 +- clippy_lints/src/methods/or_fun_call.rs | 2 +- clippy_lints/src/methods/or_then_unwrap.rs | 2 +- .../src/methods/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/methods/path_ends_with_ext.rs | 4 ++-- .../src/methods/ptr_offset_by_literal.rs | 2 +- clippy_lints/src/methods/range_zip_with_len.rs | 2 +- .../src/methods/read_line_without_trim.rs | 2 +- clippy_lints/src/methods/readonly_write_lock.rs | 2 +- clippy_lints/src/methods/repeat_once.rs | 2 +- .../src/methods/result_map_or_else_none.rs | 2 +- clippy_lints/src/methods/return_and_then.rs | 2 +- clippy_lints/src/methods/search_is_some.rs | 2 +- clippy_lints/src/methods/skip_while_next.rs | 2 +- .../src/methods/sliced_string_as_bytes.rs | 2 +- clippy_lints/src/methods/str_splitn.rs | 2 +- clippy_lints/src/methods/string_extend_chars.rs | 2 +- clippy_lints/src/methods/string_lit_chars_any.rs | 6 +++--- .../src/methods/suspicious_command_arg_space.rs | 2 +- clippy_lints/src/methods/suspicious_map.rs | 2 +- clippy_lints/src/methods/suspicious_to_owned.rs | 2 +- clippy_lints/src/methods/unbuffered_bytes.rs | 2 +- clippy_lints/src/methods/uninit_assumed_init.rs | 2 +- clippy_lints/src/methods/unit_hash.rs | 2 +- .../src/methods/unnecessary_filter_map.rs | 2 +- .../src/methods/unnecessary_first_then_check.rs | 2 +- clippy_lints/src/methods/unnecessary_fold.rs | 2 +- .../src/methods/unnecessary_get_then_check.rs | 4 ++-- .../src/methods/unnecessary_iter_cloned.rs | 6 +++--- clippy_lints/src/methods/unnecessary_join.rs | 2 +- .../src/methods/unnecessary_lazy_eval.rs | 2 +- .../src/methods/unnecessary_literal_unwrap.rs | 2 +- clippy_lints/src/methods/unnecessary_map_or.rs | 2 +- .../src/methods/unnecessary_map_or_else.rs | 2 +- clippy_lints/src/methods/unnecessary_sort_by.rs | 2 +- clippy_lints/src/methods/unnecessary_to_owned.rs | 6 +++--- .../src/methods/unnecessary_unwrap_unchecked.rs | 2 +- clippy_lints/src/methods/unwrap_expect_used.rs | 2 +- clippy_lints/src/methods/useless_asref.rs | 4 ++-- .../src/methods/useless_nonzero_new_unchecked.rs | 2 +- clippy_lints/src/methods/utils.rs | 2 +- clippy_lints/src/methods/vec_resize_to_zero.rs | 2 +- clippy_lints/src/methods/verbose_file_reads.rs | 2 +- clippy_lints/src/methods/waker_clone_wake.rs | 2 +- .../src/methods/wrong_self_convention.rs | 2 +- clippy_lints/src/methods/zst_offset.rs | 2 +- clippy_lints/src/minmax.rs | 2 +- clippy_lints/src/misc.rs | 2 +- clippy_lints/src/misc_early/mod.rs | 2 +- .../src/misc_early/redundant_at_rest_pattern.rs | 2 +- .../src/misc_early/unneeded_field_pattern.rs | 4 ++-- .../src/missing_enforced_import_rename.rs | 4 ++-- clippy_lints/src/missing_fields_in_debug.rs | 2 +- .../src/mixed_read_write_in_expression.rs | 2 +- clippy_lints/src/module_style.rs | 2 +- clippy_lints/src/multiple_bound_locations.rs | 2 +- clippy_lints/src/mutex_atomic.rs | 6 +++--- .../src/needless_borrows_for_generic_args.rs | 2 +- clippy_lints/src/needless_continue.rs | 2 +- clippy_lints/src/needless_else.rs | 2 +- clippy_lints/src/needless_for_each.rs | 2 +- clippy_lints/src/needless_ifs.rs | 4 ++-- clippy_lints/src/needless_late_init.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 6 +++--- clippy_lints/src/needless_question_mark.rs | 2 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 2 +- clippy_lints/src/new_without_default.rs | 4 ++-- clippy_lints/src/no_effect.rs | 6 +++--- clippy_lints/src/no_mangle_with_rust_abi.rs | 2 +- clippy_lints/src/non_canonical_impls.rs | 4 ++-- clippy_lints/src/non_copy_const.rs | 6 +++--- clippy_lints/src/non_expressive_names.rs | 2 +- clippy_lints/src/non_octal_unix_permissions.rs | 2 +- clippy_lints/src/non_std_lazy_statics.rs | 4 ++-- clippy_lints/src/nonstandard_macro_braces.rs | 2 +- clippy_lints/src/octal_escapes.rs | 6 +++--- clippy_lints/src/only_used_in_recursion.rs | 2 +- .../src/operators/arithmetic_side_effects.rs | 2 +- clippy_lints/src/operators/assign_op_pattern.rs | 2 +- clippy_lints/src/operators/cmp_owned.rs | 2 +- clippy_lints/src/operators/const_comparisons.rs | 2 +- .../src/operators/decimal_bitwise_operands.rs | 2 +- clippy_lints/src/operators/duration_subsec.rs | 2 +- clippy_lints/src/operators/integer_division.rs | 2 +- .../src/operators/invalid_upcast_comparisons.rs | 2 +- clippy_lints/src/operators/manual_div_ceil.rs | 2 +- .../src/operators/manual_isolate_lowest_one.rs | 2 +- .../src/operators/misrefactored_assign_op.rs | 2 +- clippy_lints/src/option_if_let_else.rs | 2 +- clippy_lints/src/panic_in_result_fn.rs | 2 +- clippy_lints/src/partialeq_to_none.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/pathbuf_init_then_push.rs | 6 +++--- clippy_lints/src/pattern_type_mismatch.rs | 2 +- .../src/permissions_set_readonly_false.rs | 2 +- clippy_lints/src/ptr/cmp_null.rs | 2 +- clippy_lints/src/ptr/ptr_arg.rs | 10 +++++----- clippy_lints/src/pub_underscore_fields.rs | 2 +- clippy_lints/src/question_mark.rs | 2 +- clippy_lints/src/ranges.rs | 4 ++-- clippy_lints/src/raw_strings.rs | 6 +++--- clippy_lints/src/redundant_clone.rs | 4 ++-- clippy_lints/src/redundant_closure_call.rs | 4 ++-- clippy_lints/src/redundant_else.rs | 2 +- clippy_lints/src/redundant_field_names.rs | 2 +- clippy_lints/src/redundant_locals.rs | 2 +- clippy_lints/src/redundant_slicing.rs | 2 +- clippy_lints/src/regex.rs | 4 ++-- clippy_lints/src/replace_box.rs | 2 +- clippy_lints/src/reserve_after_initialization.rs | 4 ++-- clippy_lints/src/return_self_not_must_use.rs | 2 +- clippy_lints/src/returns/let_and_return.rs | 4 ++-- clippy_lints/src/returns/needless_return.rs | 4 ++-- .../needless_return_with_question_mark.rs | 4 ++-- clippy_lints/src/same_length_and_capacity.rs | 2 +- clippy_lints/src/semicolon_block.rs | 4 ++-- .../src/semicolon_if_nothing_returned.rs | 2 +- clippy_lints/src/set_contains_or_insert.rs | 2 +- clippy_lints/src/shadow.rs | 2 +- clippy_lints/src/significant_drop_tightening.rs | 2 +- clippy_lints/src/single_call_fn.rs | 2 +- clippy_lints/src/single_char_lifetime_names.rs | 2 +- .../src/single_component_path_imports.rs | 2 +- clippy_lints/src/single_option_map.rs | 2 +- clippy_lints/src/single_range_in_vec_init.rs | 2 +- clippy_lints/src/size_of_ref.rs | 2 +- clippy_lints/src/slow_vector_initialization.rs | 2 +- clippy_lints/src/std_instead_of_core.rs | 2 +- clippy_lints/src/string_patterns.rs | 4 ++-- clippy_lints/src/strings.rs | 4 ++-- clippy_lints/src/strlen_on_c_strings.rs | 2 +- clippy_lints/src/suspicious_xor_used_as_pow.rs | 2 +- clippy_lints/src/swap.rs | 6 +++--- clippy_lints/src/swap_ptr_to_ref.rs | 2 +- clippy_lints/src/time_subtraction.rs | 2 +- clippy_lints/src/to_digit_is_some.rs | 2 +- clippy_lints/src/trait_bounds.rs | 4 ++-- .../src/transmute/transmute_null_to_fn.rs | 2 +- .../src/transmute/transmute_ptr_to_ptr.rs | 2 +- .../src/transmute/transmute_ptr_to_ref.rs | 2 +- clippy_lints/src/transmute/transmuting_null.rs | 2 +- clippy_lints/src/transmute/useless_transmute.rs | 2 +- clippy_lints/src/tuple_array_conversions.rs | 2 +- clippy_lints/src/types/box_collection.rs | 2 +- clippy_lints/src/types/option_option.rs | 2 +- clippy_lints/src/types/owned_cow.rs | 2 +- clippy_lints/src/types/rc_buffer.rs | 2 +- clippy_lints/src/types/rc_mutex.rs | 2 +- clippy_lints/src/types/redundant_allocation.rs | 4 ++-- clippy_lints/src/types/type_complexity.rs | 2 +- clippy_lints/src/types/vec_box.rs | 4 ++-- clippy_lints/src/unconditional_recursion.rs | 2 +- clippy_lints/src/undocumented_unsafe_blocks.rs | 4 ++-- clippy_lints/src/unicode.rs | 2 +- clippy_lints/src/uninit_vec.rs | 2 +- clippy_lints/src/unit_types/let_unit_value.rs | 2 +- clippy_lints/src/unit_types/unit_arg.rs | 2 +- clippy_lints/src/unnecessary_box_returns.rs | 2 +- clippy_lints/src/unnecessary_literal_bound.rs | 2 +- .../src/unnecessary_map_on_constructor.rs | 2 +- clippy_lints/src/unnecessary_mut_passed.rs | 2 +- .../src/unnecessary_owned_empty_strings.rs | 2 +- .../src/unnecessary_struct_initialization.rs | 2 +- clippy_lints/src/unnecessary_wraps.rs | 2 +- clippy_lints/src/unused_io_amount.rs | 2 +- clippy_lints/src/unused_peekable.rs | 2 +- clippy_lints/src/unused_result_ok.rs | 4 ++-- clippy_lints/src/unused_unit.rs | 2 +- clippy_lints/src/unwrap.rs | 4 ++-- clippy_lints/src/upper_case_acronyms.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_lints/src/useless_conversion.rs | 8 ++++---- clippy_lints/src/useless_vec.rs | 4 ++-- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/format_args_collector.rs | 4 ++-- clippy_lints/src/vec_init_then_push.rs | 4 ++-- clippy_lints/src/visibility.rs | 4 ++-- clippy_lints/src/volatile_composites.rs | 6 +++--- clippy_lints/src/wildcard_imports.rs | 2 +- clippy_lints/src/with_capacity_zero.rs | 2 +- clippy_lints/src/write/empty_string.rs | 2 +- clippy_lints/src/write/literal.rs | 2 +- clippy_lints/src/write/mod.rs | 2 +- clippy_lints/src/write/with_newline.rs | 4 ++-- clippy_lints/src/zero_repeat_side_effects.rs | 2 +- clippy_lints/src/zero_sized_map_values.rs | 4 ++-- clippy_lints/src/zombie_processes.rs | 2 +- .../src/collapsible_span_lint_calls.rs | 2 +- clippy_lints_internal/src/msrv_attr_impl.rs | 2 +- clippy_lints_internal/src/produce_ice.rs | 2 +- .../src/repeated_is_diagnostic_item.rs | 2 +- .../src/unnecessary_def_path.rs | 2 +- clippy_lints_internal/src/unusual_names.rs | 2 +- clippy_utils/src/attrs.rs | 4 ++-- clippy_utils/src/consts.rs | 6 +++--- clippy_utils/src/higher.rs | 2 +- clippy_utils/src/hir_utils.rs | 4 ++-- clippy_utils/src/lib.rs | 12 ++++++------ clippy_utils/src/macros.rs | 2 +- clippy_utils/src/mir/possible_borrower.rs | 2 +- clippy_utils/src/qualify_min_const_fn.rs | 2 +- clippy_utils/src/source.rs | 2 +- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/ty/mod.rs | 16 ++++++++-------- clippy_utils/src/ty/type_certainty/mod.rs | 4 ++-- clippy_utils/src/usage.rs | 2 +- clippy_utils/src/visitors.rs | 4 ++-- lintcheck/src/driver.rs | 2 +- lintcheck/src/json.rs | 2 +- lintcheck/src/popular_crates.rs | 2 +- lintcheck/src/recursive.rs | 2 +- src/driver.rs | 2 +- tests/compile-test.rs | 2 +- tests/config-metadata.rs | 2 +- tests/dogfood.rs | 4 ++-- 466 files changed, 635 insertions(+), 634 deletions(-) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 8a2795defc08f..1170b560c7f68 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -6,13 +6,13 @@ use crate::types::{ SourceItemOrderingTraitAssocItemKinds, SourceItemOrderingWithinModuleItemGroupings, TraitImplItemOrder, }; use clippy_utils::msrvs::Msrv; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_errors::Applicability; use rustc_session::Session; use rustc_span::edit_distance::edit_distance; -use rustc_span::{BytePos, Pos, SourceFile, Span, SyntaxContext}; -use serde::de::{IgnoredAny, IntoDeserializer, MapAccess, Visitor}; -use serde::{Deserialize, Deserializer, Serialize}; +use rustc_span::{BytePos, Pos as _, SourceFile, Span, SyntaxContext}; +use serde::de::{IgnoredAny, IntoDeserializer as _, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer as _, Serialize as _}; use std::collections::HashMap; use std::fmt::{Debug, Display, Formatter}; use std::ops::Range; @@ -1177,7 +1177,7 @@ impl serde::de::Error for FieldError { fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self { // List the available fields sorted and at least one per line, more if `CLIPPY_TERMINAL_WIDTH` is // set and allows it. - use fmt::Write; + use fmt::Write as _; let metadata = get_configuration_metadata(); let deprecated = metadata diff --git a/clippy_config/src/metadata.rs b/clippy_config/src/metadata.rs index 7cbd92a9b7100..6f91132a84fd5 100644 --- a/clippy_config/src/metadata.rs +++ b/clippy_config/src/metadata.rs @@ -1,4 +1,4 @@ -use itertools::Itertools; +use itertools::Itertools as _; use std::fmt; #[derive(Debug, Clone, Default)] diff --git a/clippy_dev/src/dogfood.rs b/clippy_dev/src/dogfood.rs index 9eb323eaef5aa..1adb846212f53 100644 --- a/clippy_dev/src/dogfood.rs +++ b/clippy_dev/src/dogfood.rs @@ -1,5 +1,5 @@ use crate::utils::{cargo_cmd, run_exit_on_err}; -use itertools::Itertools; +use itertools::Itertools as _; /// # Panics /// diff --git a/clippy_dev/src/fmt.rs b/clippy_dev/src/fmt.rs index 8a7150052f031..ba09dca6abd78 100644 --- a/clippy_dev/src/fmt.rs +++ b/clippy_dev/src/fmt.rs @@ -5,11 +5,11 @@ use crate::utils::{ ErrAction, FileUpdater, UpdateMode, UpdateStatus, expect_action, run_with_output, split_args_for_threads, walk_dir_no_dot_or_target, }; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_lexer::{FrontmatterAllowed, TokenKind, tokenize}; -use std::fmt::Write; +use std::fmt::Write as _; use std::fs; -use std::io::{self, Read}; +use std::io::{self, Read as _}; use std::ops::ControlFlow; use std::path::PathBuf; use std::process::{self, Command, Stdio}; diff --git a/clippy_dev/src/generate.rs b/clippy_dev/src/generate.rs index c35e718fa7913..f1c3375e1c7c1 100644 --- a/clippy_dev/src/generate.rs +++ b/clippy_dev/src/generate.rs @@ -2,9 +2,9 @@ use crate::parse::cursor::Cursor; use crate::parse::{Lint, LintData, LintPass, VecBuf}; use crate::utils::{FileUpdater, UpdateMode, UpdateStatus, slice_groups, update_text_region_fn}; use core::range::Range; -use itertools::Itertools; +use itertools::Itertools as _; use std::collections::HashSet; -use std::fmt::Write; +use std::fmt::Write as _; use std::path::{self, Path}; const GENERATED_FILE_COMMENT: &str = "// This file was generated by `cargo dev update_lints`.\n\ diff --git a/clippy_dev/src/release.rs b/clippy_dev/src/release.rs index d11070bab85bf..25d7d2a47025e 100644 --- a/clippy_dev/src/release.rs +++ b/clippy_dev/src/release.rs @@ -1,5 +1,5 @@ use crate::utils::{FileUpdater, UpdateStatus, Version, parse_cargo_package}; -use std::fmt::Write; +use std::fmt::Write as _; static CARGO_TOML_FILES: &[&str] = &[ "clippy_config/Cargo.toml", diff --git a/clippy_dev/src/sync.rs b/clippy_dev/src/sync.rs index 98fd72fc0bd1a..5bd5e5f0dfbd2 100644 --- a/clippy_dev/src/sync.rs +++ b/clippy_dev/src/sync.rs @@ -1,6 +1,6 @@ use crate::utils::{FileUpdater, update_text_region_fn}; use chrono::offset::Utc; -use std::fmt::Write; +use std::fmt::Write as _; pub fn update_nightly() { let date = Utc::now().format("%Y-%m-%d").to_string(); diff --git a/clippy_dev/src/utils.rs b/clippy_dev/src/utils.rs index 797eed7d59348..f10540e98ca74 100644 --- a/clippy_dev/src/utils.rs +++ b/clippy_dev/src/utils.rs @@ -7,7 +7,7 @@ use core::range::Range; use core::str::FromStr; use std::ffi::OsStr; use std::fs::{self, OpenOptions}; -use std::io::{self, Read as _, Seek as _, SeekFrom, Write}; +use std::io::{self, Read as _, Seek as _, SeekFrom, Write as _}; use std::path::{Path, PathBuf}; use std::process::{self, Command, Stdio}; use std::{env, thread}; diff --git a/clippy_lints/src/almost_complete_range.rs b/clippy_lints/src/almost_complete_range.rs index 2589703930239..82e68e160db92 100644 --- a/clippy_lints/src/almost_complete_range.rs +++ b/clippy_lints/src/almost_complete_range.rs @@ -4,7 +4,7 @@ use clippy_utils::msrvs::{self, MsrvStack}; use clippy_utils::source::{trim_span, walk_span_to_context}; use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/arc_with_non_send_sync.rs b/clippy_lints/src/arc_with_non_send_sync.rs index e449b06199d36..0c790a5343838 100644 --- a/clippy_lints/src/arc_with_non_send_sync.rs +++ b/clippy_lints/src/arc_with_non_send_sync.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::ty::implements_trait; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs index 27e304a848e33..f273a3d948c92 100644 --- a/clippy_lints/src/as_conversions.rs +++ b/clippy_lints/src/as_conversions.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/asm_syntax.rs b/clippy_lints/src/asm_syntax.rs index 3c5cf74d5a17f..db59221b78b6a 100644 --- a/clippy_lints/src/asm_syntax.rs +++ b/clippy_lints/src/asm_syntax.rs @@ -3,7 +3,7 @@ use std::fmt; use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast::ast::{Expr, ExprKind, InlineAsmOptions}; use rustc_ast::{InlineAsm, Item, ItemKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::Span; use rustc_target::asm::InlineAsmArch; diff --git a/clippy_lints/src/assertions_on_result_states.rs b/clippy_lints/src/assertions_on_result_states.rs index d48ef10c8cd25..d37e84a4b0116 100644 --- a/clippy_lints/src/assertions_on_result_states.rs +++ b/clippy_lints/src/assertions_on_result_states.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::{find_assert_args, root_macro_call_first_node}; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_context; use clippy_utils::sym; use clippy_utils::ty::{has_debug_impl, is_copy}; diff --git a/clippy_lints/src/assigning_clones.rs b/clippy_lints/src/assigning_clones.rs index 60bc9b2b5b853..d63135199aa7d 100644 --- a/clippy_lints/src/assigning_clones.rs +++ b/clippy_lints/src/assigning_clones.rs @@ -2,7 +2,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::mir::{PossibleBorrowerMap, enclosing_mir}; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::sugg::Sugg; use clippy_utils::{is_in_test, last_path_segment, local_is_initialized, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/attrs/allow_attributes.rs b/clippy_lints/src/attrs/allow_attributes.rs index 0235b130b6c01..60d9f892783c9 100644 --- a/clippy_lints/src/attrs/allow_attributes.rs +++ b/clippy_lints/src/attrs/allow_attributes.rs @@ -1,10 +1,10 @@ use super::ALLOW_ATTRIBUTES; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; -use rustc_ast::attr::AttributeExt; +use rustc_ast::attr::AttributeExt as _; use rustc_ast::{AttrStyle, Attribute}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, LintContext}; +use rustc_lint::{EarlyContext, LintContext as _}; // Separate each crate's features. pub fn check<'cx>(cx: &EarlyContext<'cx>, attr: &'cx Attribute) { diff --git a/clippy_lints/src/attrs/allow_attributes_without_reason.rs b/clippy_lints/src/attrs/allow_attributes_without_reason.rs index 5bf077990e1fe..d15863aa45d27 100644 --- a/clippy_lints/src/attrs/allow_attributes_without_reason.rs +++ b/clippy_lints/src/attrs/allow_attributes_without_reason.rs @@ -2,7 +2,7 @@ use super::{ALLOW_ATTRIBUTES_WITHOUT_REASON, Attribute}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; use rustc_ast::{MetaItemInner, MetaItemKind}; -use rustc_lint::{EarlyContext, LintContext}; +use rustc_lint::{EarlyContext, LintContext as _}; use rustc_span::sym; use rustc_span::symbol::Symbol; diff --git a/clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs b/clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs index 4d64eec25d273..10519023fa905 100644 --- a/clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs +++ b/clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs @@ -3,7 +3,7 @@ use super::utils::extract_clippy_lint; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then}; use clippy_utils::sym; use rustc_ast::MetaItemInner; -use rustc_lint::{EarlyContext, Level, LintContext}; +use rustc_lint::{EarlyContext, Level, LintContext as _}; use rustc_span::DUMMY_SP; use rustc_span::symbol::Symbol; diff --git a/clippy_lints/src/attrs/duplicated_attributes.rs b/clippy_lints/src/attrs/duplicated_attributes.rs index c956738edf0eb..c3a3dbc01cce8 100644 --- a/clippy_lints/src/attrs/duplicated_attributes.rs +++ b/clippy_lints/src/attrs/duplicated_attributes.rs @@ -1,6 +1,6 @@ use super::DUPLICATED_ATTRIBUTES; use clippy_utils::diagnostics::span_lint_and_then; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_ast::{Attribute, MetaItem}; use rustc_ast_pretty::pprust::path_to_string; use rustc_data_structures::fx::FxHashMap; diff --git a/clippy_lints/src/attrs/mixed_attributes_style.rs b/clippy_lints/src/attrs/mixed_attributes_style.rs index d71c8e9894bf7..943c64deb2bbf 100644 --- a/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -2,7 +2,7 @@ use super::MIXED_ATTRIBUTES_STYLE; use clippy_utils::diagnostics::span_lint; use rustc_ast::{AttrKind, AttrStyle, Attribute}; use rustc_data_structures::fx::FxHashSet; -use rustc_lint::{EarlyContext, LintContext}; +use rustc_lint::{EarlyContext, LintContext as _}; use rustc_span::source_map::SourceMap; use rustc_span::{SourceFile, Span, Symbol}; use std::sync::Arc; diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs index 78701b3368226..f41a23c4f5e63 100644 --- a/clippy_lints/src/attrs/mod.rs +++ b/clippy_lints/src/attrs/mod.rs @@ -19,7 +19,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::msrvs::{self, Msrv, MsrvStack}; use rustc_ast::{self as ast, AttrArgs, AttrItemKind, AttrKind, Attribute, MetaItemInner, MetaItemKind}; use rustc_hir::{ImplItem, ImplItemKind, Item, ItemKind, TraitFn, TraitItem, TraitItemKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::sym; use utils::is_lint_level; diff --git a/clippy_lints/src/attrs/non_minimal_cfg.rs b/clippy_lints/src/attrs/non_minimal_cfg.rs index 91e2689a14731..b2b112cc9cf4f 100644 --- a/clippy_lints/src/attrs/non_minimal_cfg.rs +++ b/clippy_lints/src/attrs/non_minimal_cfg.rs @@ -1,6 +1,6 @@ use super::{Attribute, NON_MINIMAL_CFG}; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_ast::{MetaItemInner, MetaItemKind}; use rustc_errors::Applicability; use rustc_lint::EarlyContext; diff --git a/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs b/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs index 4c97c03471aa9..9e9fbb2c52582 100644 --- a/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs +++ b/clippy_lints/src/attrs/unnecessary_clippy_cfg.rs @@ -1,7 +1,7 @@ use super::{Attribute, UNNECESSARY_CLIPPY_CFG}; use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg}; -use clippy_utils::source::SpanExt; -use itertools::Itertools; +use clippy_utils::source::SpanExt as _; +use itertools::Itertools as _; use rustc_ast::AttrStyle; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, Level}; diff --git a/clippy_lints/src/attrs/useless_attribute.rs b/clippy_lints/src/attrs/useless_attribute.rs index 60cdcd4a85817..c5df13416040f 100644 --- a/clippy_lints/src/attrs/useless_attribute.rs +++ b/clippy_lints/src/attrs/useless_attribute.rs @@ -1,11 +1,11 @@ use super::USELESS_ATTRIBUTE; use super::utils::{is_lint_level, is_word, namespace_and_lint}; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{SpanExt, first_line_of_span}; +use clippy_utils::source::{SpanExt as _, first_line_of_span}; use clippy_utils::sym; use rustc_ast::{Attribute, Item, ItemKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, LintContext}; +use rustc_lint::{EarlyContext, LintContext as _}; pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) { let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use)); diff --git a/clippy_lints/src/bit_width.rs b/clippy_lints/src/bit_width.rs index 3403d55494734..d1765a90ae1ef 100644 --- a/clippy_lints/src/bit_width.rs +++ b/clippy_lints/src/bit_width.rs @@ -5,7 +5,7 @@ use clippy_utils::source::snippet_with_context; use clippy_utils::{is_from_proc_macro, sym}; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, QPath}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::{self, Ty}; use rustc_session::impl_lint_pass; diff --git a/clippy_lints/src/blocks_in_conditions.rs b/clippy_lints/src/blocks_in_conditions.rs index 10fe1a4174f89..f952a3f7357c1 100644 --- a/clippy_lints/src/blocks_in_conditions.rs +++ b/clippy_lints/src/blocks_in_conditions.rs @@ -3,7 +3,7 @@ use clippy_utils::source::snippet_block_with_applicability; use clippy_utils::{contains_return, higher, is_from_proc_macro}; use rustc_errors::Applicability; use rustc_hir::{BlockCheckMode, Expr, ExprKind, MatchSource}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/bool_assert_comparison.rs b/clippy_lints/src/bool_assert_comparison.rs index 2752430c92224..8119da8cfc65a 100644 --- a/clippy_lints/src/bool_assert_comparison.rs +++ b/clippy_lints/src/bool_assert_comparison.rs @@ -7,7 +7,7 @@ use clippy_utils::ty::{implements_trait, is_copy}; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, Lit}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::{self, Ty, Unnormalized}; use rustc_session::declare_lint_pass; use rustc_span::symbol::Ident; diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index efd453b3276cc..e514799534c1e 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -2,8 +2,8 @@ use clippy_config::Conf; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; use clippy_utils::higher::has_let_expr; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::{SpanExt, snippet_with_context}; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::{SpanExt as _, snippet_with_context}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::implements_trait; use clippy_utils::{eq_expr_value, sym}; diff --git a/clippy_lints/src/borrow_deref_ref.rs b/clippy_lints/src/borrow_deref_ref.rs index 13ae80868d9b5..4c781da4ad1a6 100644 --- a/clippy_lints/src/borrow_deref_ref.rs +++ b/clippy_lints/src/borrow_deref_ref.rs @@ -1,6 +1,6 @@ use crate::reference::DEREF_ADDROF; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::ty::implements_trait; use clippy_utils::{ get_enclosing_closure, get_parent_expr, is_expr_temporary_value, is_from_proc_macro, is_lint_allowed, is_mutable, diff --git a/clippy_lints/src/box_default.rs b/clippy_lints/src/box_default.rs index 34b96b1d9d7a1..e509d2bf34083 100644 --- a/clippy_lints/src/box_default.rs +++ b/clippy_lints/src/box_default.rs @@ -1,13 +1,13 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::macros::macro_backtrace; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::ty::expr_sig; use clippy_utils::{is_default_equivalent, sym}; use rustc_errors::Applicability; use rustc_hir::def::Res; -use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty}; +use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt as _, walk_ty}; use rustc_hir::{AmbigArg, Block, Expr, ExprKind, HirId, LangItem, LetStmt, Node, QPath, Ty, TyKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/cargo/lint_groups_priority.rs b/clippy_lints/src/cargo/lint_groups_priority.rs index fbf5f72c53615..7c53a9e228145 100644 --- a/clippy_lints/src/cargo/lint_groups_priority.rs +++ b/clippy_lints/src/cargo/lint_groups_priority.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_lint::{LateContext, unerased_lint_store}; -use rustc_span::{BytePos, Pos, SourceFile, Span, SyntaxContext}; +use rustc_span::{BytePos, Pos as _, SourceFile, Span, SyntaxContext}; use std::ops::Range; use std::path::Path; use toml::Spanned; diff --git a/clippy_lints/src/cargo/multiple_crate_versions.rs b/clippy_lints/src/cargo/multiple_crate_versions.rs index 805bf4623f1f1..ee523fd6a24ba 100644 --- a/clippy_lints/src/cargo/multiple_crate_versions.rs +++ b/clippy_lints/src/cargo/multiple_crate_versions.rs @@ -1,6 +1,6 @@ use cargo_metadata::{DependencyKind, Metadata, Node, Package, PackageId}; use clippy_utils::diagnostics::span_lint; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def_id::LOCAL_CRATE; use rustc_lint::LateContext; diff --git a/clippy_lints/src/casts/as_ptr_cast_mut.rs b/clippy_lints/src/casts/as_ptr_cast_mut.rs index f23e789cf5d64..376ff0a2c8272 100644 --- a/clippy_lints/src/casts/as_ptr_cast_mut.rs +++ b/clippy_lints/src/casts/as_ptr_cast_mut.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/casts/as_underscore.rs b/clippy_lints/src/casts/as_underscore.rs index a73e48e5fd5d1..33ab43b2f95fb 100644 --- a/clippy_lints/src/casts/as_underscore.rs +++ b/clippy_lints/src/casts/as_underscore.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; use rustc_hir::{Expr, Ty, TyKind}; use rustc_lint::LateContext; -use rustc_middle::ty::IsSuggestable; +use rustc_middle::ty::IsSuggestable as _; use super::AS_UNDERSCORE; diff --git a/clippy_lints/src/casts/cast_lossless.rs b/clippy_lints/src/casts/cast_lossless.rs index d2bf6db751320..40e1040b685ec 100644 --- a/clippy_lints/src/casts/cast_lossless.rs +++ b/clippy_lints/src/casts/cast_lossless.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_in_const_context; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_isize_or_usize; use rustc_errors::Applicability; diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 69490fb23646d..d99cd4bd60a9d 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -3,7 +3,7 @@ use clippy_utils::ty::is_c_void; use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant, sym}; use rustc_hir::{Expr, ExprKind, GenericArg}; use rustc_lint::LateContext; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{self, Ty}; use super::CAST_PTR_ALIGNMENT; diff --git a/clippy_lints/src/casts/cast_slice_different_sizes.rs b/clippy_lints/src/casts/cast_slice_different_sizes.rs index a5b295c88b1c7..77f6abb35b5ae 100644 --- a/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -4,7 +4,7 @@ use clippy_utils::source; use rustc_ast::Mutability; use rustc_hir::{Expr, ExprKind, Node}; use rustc_lint::LateContext; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{self, Ty, TypeAndMut}; use super::CAST_SLICE_DIFFERENT_SIZES; diff --git a/clippy_lints/src/casts/manual_dangling_ptr.rs b/clippy_lints/src/casts/manual_dangling_ptr.rs index 36d63ce63195b..2b1b3c1b96fd3 100644 --- a/clippy_lints/src/casts/manual_dangling_ptr.rs +++ b/clippy_lints/src/casts/manual_dangling_ptr.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; -use clippy_utils::source::SpanExt; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; +use clippy_utils::source::SpanExt as _; use clippy_utils::{expr_or_init, std_or_core, sym}; use rustc_ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index de34b2691abc6..f720d6c493619 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -31,7 +31,7 @@ use clippy_config::Conf; use clippy_utils::is_hir_ty_cfg_dependant; use clippy_utils::msrvs::{self, Msrv}; use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/casts/needless_type_cast.rs b/clippy_lints/src/casts/needless_type_cast.rs index 5cfbffc6c3f66..09f72b18d18f0 100644 --- a/clippy_lints/src/casts/needless_type_cast.rs +++ b/clippy_lints/src/casts/needless_type_cast.rs @@ -8,7 +8,7 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BlockCheckMode, Body, Expr, ExprKind, HirId, LetStmt, PatKind, StmtKind, UnsafeSource}; use rustc_lint::LateContext; -use rustc_middle::ty::{Ty, TypeVisitableExt}; +use rustc_middle::ty::{Ty, TypeVisitableExt as _}; use rustc_span::Span; use super::NEEDLESS_TYPE_CAST; diff --git a/clippy_lints/src/casts/ptr_cast_constness.rs b/clippy_lints/src/casts/ptr_cast_constness.rs index c0f13f5e57823..b4f465795b5e1 100644 --- a/clippy_lints/src/casts/ptr_cast_constness.rs +++ b/clippy_lints/src/casts/ptr_cast_constness.rs @@ -6,7 +6,7 @@ use clippy_utils::{std_or_core, sym}; use rustc_errors::Applicability; use rustc_hir::{self as hir, Expr, ExprKind, QPath}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt as _}; use super::PTR_CAST_CONSTNESS; diff --git a/clippy_lints/src/casts/unnecessary_cast.rs b/clippy_lints/src/casts/unnecessary_cast.rs index c14bd056de393..c98fa1a5cba74 100644 --- a/clippy_lints/src/casts/unnecessary_cast.rs +++ b/clippy_lints/src/casts/unnecessary_cast.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::numeric_literal::NumericLiteral; use clippy_utils::res::MaybeResPath as _; -use clippy_utils::source::{SpanExt, snippet, snippet_with_applicability}; +use clippy_utils::source::{SpanExt as _, snippet, snippet_with_applicability}; use clippy_utils::sugg::has_enclosing_paren; use clippy_utils::visitors::{Visitable, for_each_expr_without_closures}; use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant, is_ty_alias, sym}; @@ -9,7 +9,7 @@ use rustc_ast::{LitFloatType, LitIntType, LitKind}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, ExprKind, FnRetTy, HirId, Lit, Node, Path, QPath, TyKind, UnOp}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, FloatTy, GenericArg, InferTy, Ty}; use rustc_span::Symbol; diff --git a/clippy_lints/src/casts/zero_ptr.rs b/clippy_lints/src/casts/zero_ptr.rs index 90290caf10bf7..7f63a7336b1b0 100644 --- a/clippy_lints/src/casts/zero_ptr.rs +++ b/clippy_lints/src/casts/zero_ptr.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::{is_in_const_context, is_integer_literal, std_or_core}; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability, Ty, TyKind}; diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index c80930f0b443f..a62fdf963f1b9 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -5,7 +5,7 @@ use clippy_utils::source::snippet_with_context; use clippy_utils::{SpanlessEq, is_in_const_context, is_integer_literal, sym}; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, QPath, TyKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::{Symbol, SyntaxContext}; diff --git a/clippy_lints/src/cloned_ref_to_slice_refs.rs b/clippy_lints/src/cloned_ref_to_slice_refs.rs index 24955ac3c6258..498775373050c 100644 --- a/clippy_lints/src/cloned_ref_to_slice_refs.rs +++ b/clippy_lints/src/cloned_ref_to_slice_refs.rs @@ -3,7 +3,7 @@ use std::ops::ControlFlow; use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::sugg::Sugg; use clippy_utils::visitors::is_const_evaluatable; use clippy_utils::{is_in_const_context, is_mutable, sym}; diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index c330ed3d5a0a4..81ff839408d34 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -1,13 +1,13 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::{IntoSpan, SpanExt}; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::{IntoSpan as _, SpanExt as _}; use clippy_utils::visitors::for_each_expr_without_closures; use clippy_utils::{LimitStack, get_async_fn_body, sym}; use core::ops::ControlFlow; use rustc_hir::intravisit::FnKind; use rustc_hir::{Attribute, Body, Expr, ExprKind, FnDecl}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::def_id::LocalDefId; diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index 6def41b775d1d..e25d58a9d8792 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -1,7 +1,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::msrvs::Msrv; -use clippy_utils::source::{IntoSpan as _, SpanExt, snippet, snippet_block_with_applicability}; +use clippy_utils::source::{IntoSpan as _, SpanExt as _, snippet, snippet_block_with_applicability}; use clippy_utils::{can_use_if_let_chains, span_contains_cfg, span_contains_non_whitespace, sym, tokenize_with_text}; use rustc_ast::{BinOpKind, MetaItemInner}; use rustc_errors::Applicability; @@ -336,7 +336,7 @@ fn span_extract_keyword(cx: &LateContext<'_>, span: Span, keyword: &str) -> Opti /// Peel the parentheses from an `if` expression, e.g. `((if true {} else {}))`. pub(super) fn peel_parens(cx: &LateContext<'_>, mut span: Span) -> (Span, Span, Span) { - use crate::rustc_span::Pos; + use crate::rustc_span::Pos as _; let start = span.shrink_to_lo(); let end = span.shrink_to_hi(); diff --git a/clippy_lints/src/collection_is_never_read.rs b/clippy_lints/src/collection_is_never_read.rs index 4ddd396c50ce4..5c70b0d880914 100644 --- a/clippy_lints/src/collection_is_never_read.rs +++ b/clippy_lints/src/collection_is_never_read.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::visitors::{Visitable, for_each_expr}; use clippy_utils::{get_enclosing_block, sym}; use core::ops::ControlFlow; diff --git a/clippy_lints/src/dbg_macro.rs b/clippy_lints/src/dbg_macro.rs index adc1c0a6c577c..62d59e95e6772 100644 --- a/clippy_lints/src/dbg_macro.rs +++ b/clippy_lints/src/dbg_macro.rs @@ -6,7 +6,7 @@ use clippy_utils::{is_in_test, sym}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::{Closure, ClosureKind, CoroutineKind, Expr, ExprKind, LetStmt, LocalSource, Node, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::{Span, SyntaxContext}; diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index 649d8449e431b..c088241b0c936 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -8,7 +8,7 @@ use rustc_hir::{ Block, Body, ConstContext, Expr, ExprKind, FnRetTy, HirId, Lit, Pat, PatExpr, PatExprKind, PatKind, Stmt, StmtKind, StructTailExpr, }; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::{self, FloatTy, IntTy, PolyFnSig, Ty}; use rustc_session::declare_lint_pass; use std::iter; diff --git a/clippy_lints/src/default_union_representation.rs b/clippy_lints/src/default_union_representation.rs index bfb246c5f848c..bd738b7f4cd86 100644 --- a/clippy_lints/src/default_union_representation.rs +++ b/clippy_lints/src/default_union_representation.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_hir::attrs::ReprAttr; use rustc_hir::{HirId, Item, ItemKind, find_attr}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{self, FieldDef}; use rustc_session::declare_lint_pass; diff --git a/clippy_lints/src/definition_in_module_root.rs b/clippy_lints/src/definition_in_module_root.rs index 002dd91c86860..4b454e282cc24 100644 --- a/clippy_lints/src/definition_in_module_root.rs +++ b/clippy_lints/src/definition_in_module_root.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{self, Inline, ItemKind, ModKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::{FileName, SourceFile, sym}; diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index fe1115443d790..cd1ad57ee828d 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::has_enclosing_paren; use clippy_utils::ty::{ @@ -12,14 +12,14 @@ use rustc_ast::util::parser::ExprPrecedence; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; -use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty}; +use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt as _, walk_ty}; use rustc_hir::{ self as hir, AmbigArg, BindingMode, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, Item, MatchSource, Mutability, Node, OwnerId, Pat, PatKind, Path, QPath, TyKind, UnOp, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; -use rustc_middle::ty::{self, AssocTag, Ty, TyCtxt, TypeVisitableExt, TypeckResults, Unnormalized}; +use rustc_middle::ty::{self, AssocTag, Ty, TyCtxt, TypeVisitableExt as _, TypeckResults, Unnormalized}; use rustc_session::impl_lint_pass; use rustc_span::{Span, Symbol, SyntaxContext}; use std::borrow::Cow; diff --git a/clippy_lints/src/derive/derive_partial_eq_without_eq.rs b/clippy_lints/src/derive/derive_partial_eq_without_eq.rs index 612d552a75408..6d31e19e49792 100644 --- a/clippy_lints/src/derive/derive_partial_eq_without_eq.rs +++ b/clippy_lints/src/derive/derive_partial_eq_without_eq.rs @@ -5,7 +5,7 @@ use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, HirId}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, ClauseKind, GenericParamDefKind, ParamEnv, TraitPredicate, Ty, TyCtxt, Upcast}; +use rustc_middle::ty::{self, ClauseKind, GenericParamDefKind, ParamEnv, TraitPredicate, Ty, TyCtxt, Upcast as _}; use rustc_span::{Span, sym}; use super::DERIVE_PARTIAL_EQ_WITHOUT_EQ; diff --git a/clippy_lints/src/derive/mod.rs b/clippy_lints/src/derive/mod.rs index d6f928d738cbd..96b1cb0890ac1 100644 --- a/clippy_lints/src/derive/mod.rs +++ b/clippy_lints/src/derive/mod.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use rustc_hir::def::Res; use rustc_hir::{Impl, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/disallowed_script_idents.rs b/clippy_lints/src/disallowed_script_idents.rs index d013e453ecc0a..aeced9e72fb5e 100644 --- a/clippy_lints/src/disallowed_script_idents.rs +++ b/clippy_lints/src/disallowed_script_idents.rs @@ -2,9 +2,9 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint; use rustc_ast::ast; use rustc_data_structures::fx::FxHashSet; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; -use unicode_script::{Script, UnicodeScript}; +use unicode_script::{Script, UnicodeScript as _}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/doc/broken_link.rs b/clippy_lints/src/doc/broken_link.rs index 2fa41d83915a4..6c7eae0170d0c 100644 --- a/clippy_lints/src/doc/broken_link.rs +++ b/clippy_lints/src/doc/broken_link.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_lint::LateContext; use rustc_resolve::rustdoc::pulldown_cmark::BrokenLink as PullDownBrokenLink; use rustc_resolve::rustdoc::{DocFragment, source_span_for_markdown_range}; -use rustc_span::{BytePos, Pos, Span}; +use rustc_span::{BytePos, Pos as _, Span}; use super::DOC_BROKEN_LINK; diff --git a/clippy_lints/src/doc/doc_suspicious_footnotes.rs b/clippy_lints/src/doc/doc_suspicious_footnotes.rs index dfa6c96378644..39e53dbedb580 100644 --- a/clippy_lints/src/doc/doc_suspicious_footnotes.rs +++ b/clippy_lints/src/doc/doc_suspicious_footnotes.rs @@ -4,7 +4,7 @@ use rustc_ast::token::{CommentKind, DocFragmentKind}; use rustc_errors::Applicability; use rustc_hir::attrs::AttributeKind; use rustc_hir::{AttrStyle, Attribute}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use std::ops::Range; diff --git a/clippy_lints/src/doc/lazy_continuation.rs b/clippy_lints/src/doc/lazy_continuation.rs index cb9d68224dbb8..470d8e1304127 100644 --- a/clippy_lints/src/doc/lazy_continuation.rs +++ b/clippy_lints/src/doc/lazy_continuation.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_errors::Applicability; use rustc_lint::LateContext; use rustc_span::BytePos; diff --git a/clippy_lints/src/doc/markdown.rs b/clippy_lints/src/doc/markdown.rs index 69c3b9150c300..1969ae5ef6d58 100644 --- a/clippy_lints/src/doc/markdown.rs +++ b/clippy_lints/src/doc/markdown.rs @@ -3,7 +3,7 @@ use clippy_utils::source::snippet_with_applicability; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_lint::LateContext; -use rustc_span::{BytePos, Pos, Span}; +use rustc_span::{BytePos, Pos as _, Span}; use url::Url; use crate::doc::{DOC_MARKDOWN, Fragments}; diff --git a/clippy_lints/src/doc/missing_headers.rs b/clippy_lints/src/doc/missing_headers.rs index 4139df9cd7997..5a69a5e0d2e84 100644 --- a/clippy_lints/src/doc/missing_headers.rs +++ b/clippy_lints/src/doc/missing_headers.rs @@ -1,7 +1,7 @@ use super::{DocHeaders, MISSING_ERRORS_DOC, MISSING_PANICS_DOC, MISSING_SAFETY_DOC, UNNECESSARY_SAFETY_DOC}; use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use clippy_utils::macros::{is_panic, root_macro_call_first_node}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::ty::implements_trait_with_env; use clippy_utils::visitors::for_each_expr; use clippy_utils::{fulfill_or_allowed, is_doc_hidden, is_inside_always_const_context, method_chain_args, return_ty}; diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 02e3332492d0f..cd86572b66928 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -7,7 +7,7 @@ use clippy_utils::{is_entrypoint_fn, is_trait_impl_item}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::{Attribute, FieldDef, ImplItemKind, ItemKind, Node, Safety, TraitItemKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext as _}; use rustc_resolve::rustdoc::pulldown_cmark::Event::{ Code, DisplayMath, End, FootnoteReference, HardBreak, Html, InlineHtml, InlineMath, Rule, SoftBreak, Start, TaskListMarker, Text, diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index daf65e090f6ac..81ad33a75e2f3 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::{SpanExt, snippet_with_applicability, snippet_with_context}; +use clippy_utils::source::{SpanExt as _, snippet_with_applicability, snippet_with_context}; use rustc_ast::ast::{Expr, ExprKind, MethodCall}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 5da76bc3095f2..560c365a988b7 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_must_use_func_call; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::ty::{is_copy, is_must_use_ty}; use rustc_hir::{Arm, Expr, ExprKind, LangItem, Node}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/duplicate_mod.rs b/clippy_lints/src/duplicate_mod.rs index 4b7ffc09b820c..265721bb066d2 100644 --- a/clippy_lints/src/duplicate_mod.rs +++ b/clippy_lints/src/duplicate_mod.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use rustc_ast::ast::{Crate, Inline, Item, ItemKind, ModKind}; use rustc_errors::MultiSpan; -use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext as _}; use rustc_middle::lint::UnstableLevelSpec; use rustc_session::impl_lint_pass; use rustc_span::{FileName, Span}; diff --git a/clippy_lints/src/duration_suboptimal_units.rs b/clippy_lints/src/duration_suboptimal_units.rs index ceb24709add30..bee3975cd5fc5 100644 --- a/clippy_lints/src/duration_suboptimal_units.rs +++ b/clippy_lints/src/duration_suboptimal_units.rs @@ -4,11 +4,11 @@ use clippy_config::Conf; use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, QPath, RustcVersion}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::{self, TyCtxt, UintTy}; use rustc_session::impl_lint_pass; use rustc_span::Symbol; diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index a38e853172f70..838b9063ef751 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast::ast::{Expr, ExprKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/empty_line_after.rs b/clippy_lints/src/empty_line_after.rs index f076c6d29138d..7d3d8cde2032d 100644 --- a/clippy_lints/src/empty_line_after.rs +++ b/clippy_lints/src/empty_line_after.rs @@ -1,14 +1,14 @@ use std::borrow::Cow; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{SpanExt, snippet_indent}; +use clippy_utils::source::{SpanExt as _, snippet_indent}; use clippy_utils::tokenize_with_text; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_ast::token::CommentKind; use rustc_ast::{AssocItemKind, AttrKind, AttrStyle, Attribute, Crate, Item, ItemKind, ModKind, NodeId}; use rustc_errors::{Applicability, Diag, SuggestionStyle}; use rustc_lexer::TokenKind; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::{BytePos, ExpnKind, Ident, InnerSpan, Span, SpanData, Symbol, kw, sym}; diff --git a/clippy_lints/src/endian_bytes.rs b/clippy_lints/src/endian_bytes.rs index d76729047cdc5..863c3b2ccdfbb 100644 --- a/clippy_lints/src/endian_bytes.rs +++ b/clippy_lints/src/endian_bytes.rs @@ -2,11 +2,11 @@ use crate::Lint; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{is_lint_allowed, sym}; use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::Ty; use rustc_session::declare_lint_pass; use rustc_span::Symbol; -use std::fmt::Write; +use std::fmt::Write as _; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index cba40abf04e17..2eb691cbc7a84 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -6,7 +6,7 @@ use clippy_utils::{ SpanlessEq, can_move_expr_to_closure_no_visit, desugar_await, higher, is_expr_final_block_expr, is_expr_used_or_unified, paths, peel_hir_expr_while, span_contains_non_whitespace, sym, }; -use core::fmt::{self, Write}; +use core::fmt::{self, Write as _}; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::hir_id::HirIdSet; diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index bd92e7e850870..1313f42d7ff58 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -2,7 +2,7 @@ use clippy_utils::consts::{Constant, mir_to_const}; use clippy_utils::diagnostics::span_lint; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::util::IntTypeExt; +use rustc_middle::ty::util::IntTypeExt as _; use rustc_middle::ty::{self, IntTy, UintTy}; use rustc_session::declare_lint_pass; diff --git a/clippy_lints/src/equatable_if_let.rs b/clippy_lints/src/equatable_if_let.rs index a92bfd45df0ce..ab5a24b230465 100644 --- a/clippy_lints/src/equatable_if_let.rs +++ b/clippy_lints/src/equatable_if_let.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet_with_context; use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, Pat, PatKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::Ty; use rustc_session::declare_lint_pass; diff --git a/clippy_lints/src/error_impl_error.rs b/clippy_lints/src/error_impl_error.rs index 4b9e3cee011c6..e9048ef0aaf95 100644 --- a/clippy_lints/src/error_impl_error.rs +++ b/clippy_lints/src/error_impl_error.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::{span_lint, span_lint_hir_and_then}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::sym; use clippy_utils::ty::implements_trait; use rustc_hir::def_id::{DefId, LocalDefId}; diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index e7df5fa020e34..a76fa0626ac5f 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -6,7 +6,7 @@ use rustc_hir::{Body, FnDecl, HirId, HirIdSet, PatKind, intravisit}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{self, TraitRef, Ty}; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 6248ba6e44da5..e1ad4649a5e3e 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -1,16 +1,17 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::higher::VecArgs; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::{snippet_opt, snippet_with_applicability}; use clippy_utils::usage::{local_used_after_expr, local_used_in}; use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate}; use rustc_errors::Applicability; use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, GenericArgs, Param, PatKind, QPath, Safety, TyKind, find_attr}; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::TyCtxtInferExt as _; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; use rustc_middle::ty::{ - self, Binder, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, Ty, TypeVisitableExt, TypeckResults, + self, Binder, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, Ty, TypeVisitableExt as _, + TypeckResults, }; use rustc_session::declare_lint_pass; use rustc_span::symbol::sym; diff --git a/clippy_lints/src/excessive_nesting.rs b/clippy_lints/src/excessive_nesting.rs index 58d00933a7851..0c88f3fd32285 100644 --- a/clippy_lints/src/excessive_nesting.rs +++ b/clippy_lints/src/excessive_nesting.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use rustc_ast::node_id::NodeSet; use rustc_ast::visit::{Visitor, walk_block, walk_item}; use rustc_ast::{Block, Crate, Inline, Item, ItemKind, ModKind, NodeId}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index a85025a48e5a8..e66eac117cda7 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::macros::{FormatArgsStorage, format_args_inputs_span}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_expn_of, is_in_test, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/extra_unused_type_parameters.rs b/clippy_lints/src/extra_unused_type_parameters.rs index a6f80da5dab9c..070b0d2fb0c0a 100644 --- a/clippy_lints/src/extra_unused_type_parameters.rs +++ b/clippy_lints/src/extra_unused_type_parameters.rs @@ -8,7 +8,7 @@ use rustc_hir::{ AmbigArg, BodyId, ExprKind, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, ItemKind, PredicateOrigin, Ty, WherePredicate, WherePredicateKind, }; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::hir::nested_filter; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index bd2bd66284648..a2d02b6747d7c 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::{is_panic, root_macro_call_first_node}; use clippy_utils::method_chain_args; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; diff --git a/clippy_lints/src/floating_point_arithmetic/mod.rs b/clippy_lints/src/floating_point_arithmetic/mod.rs index 0833761b32dc7..82b08a9e7d212 100644 --- a/clippy_lints/src/floating_point_arithmetic/mod.rs +++ b/clippy_lints/src/floating_point_arithmetic/mod.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::{is_in_const_context, is_no_std_crate, sym}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index f13278d91ce7f..a045bada6d35a 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::macros::{FormatArgsStorage, find_format_arg_expr, first_node_in_macro, matching_root_macro_call}; -use clippy_utils::source::{SpanExt, snippet_with_context}; +use clippy_utils::source::{SpanExt as _, snippet_with_context}; use clippy_utils::sugg::Sugg; use rustc_ast::{FormatArgsPiece, FormatOptions, FormatTrait}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index 9014302fb8ea6..eca754095f080 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -9,11 +9,11 @@ use clippy_utils::macros::{ root_macro_call_first_node, }; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::{SpanExt, snippet, snippet_opt}; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::{SpanExt as _, snippet, snippet_opt}; use clippy_utils::ty::implements_trait; use clippy_utils::{is_from_proc_macro, is_in_test, peel_hir_expr_while, sym, trait_ref_of_method}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_ast::FormatTrait::{Binary, Debug, Display, LowerExp, LowerHex, Octal, Pointer, UpperExp, UpperHex}; use rustc_ast::{ BorrowKind, FormatArgPosition, FormatArgPositionKind, FormatArgsPiece, FormatArgumentKind, FormatCount, @@ -23,13 +23,13 @@ use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; use rustc_errors::SuggestionStyle::{CompletelyHidden, ShowCode}; use rustc_hir::{Expr, ExprKind, LangItem, RustcVersion, find_attr}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind}; -use rustc_middle::ty::{self, GenericArg, List, TraitRef, Ty, TyCtxt, Unnormalized, Upcast}; +use rustc_middle::ty::{self, GenericArg, List, TraitRef, Ty, TyCtxt, Unnormalized, Upcast as _}; use rustc_session::impl_lint_pass; use rustc_span::edition::Edition::Edition2021; -use rustc_span::{BytePos, Pos, Span, Symbol}; -use rustc_trait_selection::infer::TyCtxtInferExt; +use rustc_span::{BytePos, Pos as _, Span, Symbol}; +use rustc_trait_selection::infer::TyCtxtInferExt as _; use rustc_trait_selection::traits::{Obligation, ObligationCause, Selection, SelectionContext}; declare_clippy_lint! { diff --git a/clippy_lints/src/format_impl.rs b/clippy_lints/src/format_impl.rs index 4d0a324a2a39c..850e0a1ab5441 100644 --- a/clippy_lints/src/format_impl.rs +++ b/clippy_lints/src/format_impl.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::macros::{FormatArgsStorage, find_format_arg_expr, is_format_macro, root_macro_call_first_node}; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::{get_parent_as_impl, peel_ref_operators, sym}; use rustc_ast::{FormatArgsPiece, FormatTrait}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/format_push_string.rs b/clippy_lints/src/format_push_string.rs index d5a7cffe9e6c8..9a092729762dd 100644 --- a/clippy_lints/src/format_push_string.rs +++ b/clippy_lints/src/format_push_string.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::{FormatArgsStorage, format_args_inputs_span, root_macro_call_first_node}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::{std_or_core, sym}; use rustc_errors::Applicability; use rustc_hir::{AssignOpKind, Expr, ExprKind, LangItem, MatchSource}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 87e290cf03579..39106e0fcd4cd 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note}; use clippy_utils::is_span_if; use clippy_utils::source::snippet_opt; use rustc_ast::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/four_forward_slashes.rs b/clippy_lints/src/four_forward_slashes.rs index c64e742592080..d188dc011e942 100644 --- a/clippy_lints/src/four_forward_slashes.rs +++ b/clippy_lints/src/four_forward_slashes.rs @@ -1,9 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::SpanExt as _; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_errors::Applicability; use rustc_hir::Item; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/from_over_into.rs b/clippy_lints/src/from_over_into.rs index 7c2dc59f66d5b..f52e962e6c2bb 100644 --- a/clippy_lints/src/from_over_into.rs +++ b/clippy_lints/src/from_over_into.rs @@ -4,8 +4,8 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::span_is_local; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeResPath as _; +use clippy_utils::source::SpanExt as _; use rustc_errors::Applicability; use rustc_hir::intravisit::{Visitor, walk_path}; use rustc_hir::{ diff --git a/clippy_lints/src/from_raw_with_void_ptr.rs b/clippy_lints/src/from_raw_with_void_ptr.rs index 5c6d6607a0aa2..b419b43190a21 100644 --- a/clippy_lints/src/from_raw_with_void_ptr.rs +++ b/clippy_lints/src/from_raw_with_void_ptr.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::sym; use clippy_utils::ty::is_c_void; use rustc_hir::def_id::DefId; diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index df8a35d9658b0..5540c50906e2b 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sugg::Sugg; use clippy_utils::{is_in_const_context, is_integer_literal, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 1dc23df6706ca..e7b7b18967a07 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -4,7 +4,7 @@ use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::def_id::DefIdSet; use rustc_hir::{self as hir, Attribute, QPath, find_attr}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::{self, Ty}; use rustc_span::{Span, sym}; diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index f3952b2687a56..ce1b62250a45f 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use rustc_hir::{self as hir, HirId, HirIdSet, intravisit}; use rustc_lint::LateContext; use rustc_middle::ty; diff --git a/clippy_lints/src/functions/ref_option.rs b/clippy_lints/src/functions/ref_option.rs index 1727f50b521a6..d63488af4d17a 100644 --- a/clippy_lints/src/functions/ref_option.rs +++ b/clippy_lints/src/functions/ref_option.rs @@ -6,7 +6,7 @@ use clippy_utils::{is_from_proc_macro, is_trait_impl_item}; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{self as hir, FnDecl, HirId}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::{self, Mutability, Ty}; use rustc_span::Span; use rustc_span::def_id::LocalDefId; diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index 816f2cac8429b..6a7013e0f1737 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -1,8 +1,8 @@ use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_errors::Diag; use rustc_hir as hir; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::{self, Ty}; use rustc_span::def_id::DefIdSet; use rustc_span::{Span, sym}; diff --git a/clippy_lints/src/functions/too_many_lines.rs b/clippy_lints/src/functions/too_many_lines.rs index a5fed9f03a620..ad6cca0eb4a6f 100644 --- a/clippy_lints/src/functions/too_many_lines.rs +++ b/clippy_lints/src/functions/too_many_lines.rs @@ -1,9 +1,9 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::FnKind; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_span::Span; use super::TOO_MANY_LINES; diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 9af3d72bcffa9..3194b08fea1d0 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -4,17 +4,17 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::return_ty; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl}; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::TyCtxtInferExt as _; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::print::PrintTraitRefExt; +use rustc_middle::ty::print::PrintTraitRefExt as _; use rustc_middle::ty::{ - self, AliasTy, Binder, ClauseKind, PredicateKind, Ty, TyCtxt, TypeVisitable, TypeVisitableExt, TypeVisitor, - Unnormalized, + self, AliasTy, Binder, ClauseKind, PredicateKind, Ty, TyCtxt, TypeVisitable as _, TypeVisitableExt as _, + TypeVisitor, Unnormalized, }; use rustc_session::declare_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::{Span, sym}; -use rustc_trait_selection::error_reporting::InferCtxtErrorExt; +use rustc_trait_selection::error_reporting::InferCtxtErrorExt as _; use rustc_trait_selection::traits::{self, FulfillmentError, ObligationCtxt}; declare_clippy_lint! { diff --git a/clippy_lints/src/if_let_mutex.rs b/clippy_lints/src/if_let_mutex.rs index 38fda71fccf2f..d03fa1472e252 100644 --- a/clippy_lints/src/if_let_mutex.rs +++ b/clippy_lints/src/if_let_mutex.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::visitors::for_each_expr_without_closures; use clippy_utils::{eq_expr_value, higher, sym}; use core::ops::ControlFlow; diff --git a/clippy_lints/src/ifs/branches_sharing_code.rs b/clippy_lints/src/ifs/branches_sharing_code.rs index 2701cdaa394da..4db4ae9e2b809 100644 --- a/clippy_lints/src/ifs/branches_sharing_code.rs +++ b/clippy_lints/src/ifs/branches_sharing_code.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeResPath; -use clippy_utils::source::{IntoSpan, SpanExt, first_line_of_span, indent_of, reindent_multiline, snippet}; +use clippy_utils::res::MaybeResPath as _; +use clippy_utils::source::{IntoSpan as _, SpanExt as _, first_line_of_span, indent_of, reindent_multiline, snippet}; use clippy_utils::ty::needs_ordered_drop; use clippy_utils::visitors::for_each_expr_without_closures; use clippy_utils::{ diff --git a/clippy_lints/src/ifs/ifs_same_cond.rs b/clippy_lints/src/ifs/ifs_same_cond.rs index ac010a9314b3c..fd9bbc1d7e7ab 100644 --- a/clippy_lints/src/ifs/ifs_same_cond.rs +++ b/clippy_lints/src/ifs/ifs_same_cond.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::ty::InteriorMut; use clippy_utils::{SpanlessEq, eq_expr_value, find_binding_init, hash_expr, search_same}; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/implicit_hasher.rs b/clippy_lints/src/implicit_hasher.rs index bf2c7a007644c..c0236370b3d8a 100644 --- a/clippy_lints/src/implicit_hasher.rs +++ b/clippy_lints/src/implicit_hasher.rs @@ -1,9 +1,9 @@ use std::borrow::Cow; use std::collections::BTreeMap; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_errors::{Applicability, Diag}; -use rustc_hir::intravisit::{Visitor, VisitorExt, walk_body, walk_expr, walk_ty}; +use rustc_hir::intravisit::{Visitor, VisitorExt as _, walk_body, walk_expr, walk_ty}; use rustc_hir::{self as hir, AmbigArg, Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; @@ -13,7 +13,7 @@ use rustc_session::declare_lint_pass; use rustc_span::Span; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{IntoSpan, SpanExt, snippet, snippet_with_context}; +use clippy_utils::source::{IntoSpan as _, SpanExt as _, snippet, snippet_with_context}; use clippy_utils::sym; declare_clippy_lint! { diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index 6ed478b2708a3..6494331846f0f 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -6,7 +6,7 @@ use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, FnRetTy, HirId}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::{Span, SyntaxContext}; diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index b1f03babb9fa5..f9a210a879bee 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -4,7 +4,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::higher::IfLet; use clippy_utils::is_lint_allowed; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::ty::is_copy; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/ineffective_open_options.rs b/clippy_lints/src/ineffective_open_options.rs index aae847031bf64..7c52b4b9e3648 100644 --- a/clippy_lints/src/ineffective_open_options.rs +++ b/clippy_lints/src/ineffective_open_options.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::SpanExt as _; use clippy_utils::{peel_blocks, peel_hir_expr_while, sym}; use rustc_ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index 8b0a4b4d78d9a..93372747ce7c3 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::ty::implements_trait; use clippy_utils::{higher, sym}; use rustc_hir::{BorrowKind, Closure, Expr, ExprKind}; diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index afe2a1033ceeb..e01200329e8e2 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::ty::implements_trait; use clippy_utils::{return_ty, trait_ref_of_method}; use rustc_abi::ExternAbi; diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index 2da13b57aec44..f2370a3392796 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::sugg::DiagExt; +use clippy_utils::sugg::DiagExt as _; use rustc_errors::Applicability; use rustc_hir::{TraitFn, TraitItem, TraitItemKind, find_attr}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/inline_trait_bounds.rs b/clippy_lints/src/inline_trait_bounds.rs index 87e63e8732fe8..4babe0ce3fc9e 100644 --- a/clippy_lints/src/inline_trait_bounds.rs +++ b/clippy_lints/src/inline_trait_bounds.rs @@ -5,7 +5,7 @@ use rustc_ast::ast::{Fn, FnRetTy, GenericParam, GenericParamKind}; use rustc_ast::visit::{FnCtxt, FnKind}; use rustc_ast::{HasAttrs as _, NodeId}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index 021d43cefdda6..afb8863f1b942 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_hir; use rustc_hir::{Block, ItemKind, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/items_after_test_module.rs b/clippy_lints/src/items_after_test_module.rs index f83bcb3cf4076..979fa0c16600a 100644 --- a/clippy_lints/src/items_after_test_module.rs +++ b/clippy_lints/src/items_after_test_module.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::{fulfill_or_allowed, is_cfg_test, is_from_proc_macro}; use rustc_errors::{Applicability, SuggestionStyle}; use rustc_hir::{HirId, Item, ItemKind, Mod}; diff --git a/clippy_lints/src/iter_over_hash_type.rs b/clippy_lints/src/iter_over_hash_type.rs index aec863af47717..1813d682dde56 100644 --- a/clippy_lints/src/iter_over_hash_type.rs +++ b/clippy_lints/src/iter_over_hash_type.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::higher::ForLoop; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; diff --git a/clippy_lints/src/iter_without_into_iter.rs b/clippy_lints/src/iter_without_into_iter.rs index fc0a725e06335..6165959fd4f26 100644 --- a/clippy_lints/src/iter_without_into_iter.rs +++ b/clippy_lints/src/iter_without_into_iter.rs @@ -5,7 +5,7 @@ use clippy_utils::{get_parent_as_impl, sym}; use rustc_ast::Mutability; use rustc_errors::Applicability; use rustc_hir::{FnRetTy, ImplItemKind, ImplicitSelfKind, ItemKind, TyKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::{self, Ty}; use rustc_session::declare_lint_pass; diff --git a/clippy_lints/src/large_const_arrays.rs b/clippy_lints/src/large_const_arrays.rs index 9835c1decceee..a2acd54ba44f3 100644 --- a/clippy_lints/src/large_const_arrays.rs +++ b/clippy_lints/src/large_const_arrays.rs @@ -3,10 +3,10 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{self, Ty, Unnormalized}; use rustc_session::impl_lint_pass; -use rustc_span::{BytePos, Pos, Span}; +use rustc_span::{BytePos, Pos as _, Span}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 9b0b65cd02c7f..f304673ccecde 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -8,7 +8,7 @@ use clippy_utils::{is_from_proc_macro, sym}; use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/large_stack_frames.rs b/clippy_lints/src/large_stack_frames.rs index dec3f3bcae895..54c9ad38f3489 100644 --- a/clippy_lints/src/large_stack_frames.rs +++ b/clippy_lints/src/large_stack_frames.rs @@ -2,7 +2,7 @@ use std::{fmt, ops}; use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, is_in_test}; use rustc_errors::Diag; use rustc_hir::def_id::LocalDefId; diff --git a/clippy_lints/src/legacy_numeric_constants.rs b/clippy_lints/src/legacy_numeric_constants.rs index 48e1414defadf..3ba2c0ceba3fa 100644 --- a/clippy_lints/src/legacy_numeric_constants.rs +++ b/clippy_lints/src/legacy_numeric_constants.rs @@ -1,13 +1,13 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::{is_from_proc_macro, sym}; use hir::def_id::DefId; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::{ExprKind, Item, ItemKind, QPath, UseKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Symbol; use rustc_span::symbol::kw; diff --git a/clippy_lints/src/len_without_is_empty.rs b/clippy_lints/src/len_without_is_empty.rs index d947fa77d80e7..0e80fc3242808 100644 --- a/clippy_lints/src/len_without_is_empty.rs +++ b/clippy_lints/src/len_without_is_empty.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::{fulfill_or_allowed, get_parent_as_impl, sym}; use rustc_data_structures::unord::UnordItems; use rustc_hir::def::Res; diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index cb0565ef60e5a..1feac584c8878 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -1,8 +1,8 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::Msrv; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; -use clippy_utils::source::{SpanExt, snippet_with_context}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; +use clippy_utils::source::{SpanExt as _, snippet_with_context}; use clippy_utils::sugg::{Sugg, has_enclosing_paren}; use clippy_utils::ty::implements_trait; use clippy_utils::{parent_item_name, peel_ref_operators, sym}; diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index dc7a916614be3..be65eaac3b5b8 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet_with_context; use clippy_utils::visitors::is_local_used; use rustc_errors::Applicability; diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index 3f8bd2223876f..ca69f92aeda8b 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -3,7 +3,7 @@ use clippy_utils::ty::{implements_trait, is_must_use_ty}; use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths}; use rustc_hir::{LetStmt, LocalSource, PatKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{GenericArgKind, IsSuggestable}; +use rustc_middle::ty::{GenericArgKind, IsSuggestable as _}; use rustc_session::declare_lint_pass; use rustc_span::{BytePos, Span}; diff --git a/clippy_lints/src/let_with_type_underscore.rs b/clippy_lints/src/let_with_type_underscore.rs index 3f4b59382ca15..99d9b5d6011a4 100644 --- a/clippy_lints/src/let_with_type_underscore.rs +++ b/clippy_lints/src/let_with_type_underscore.rs @@ -1,9 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; -use clippy_utils::source::{IntoSpan, SpanExt}; +use clippy_utils::source::{IntoSpan as _, SpanExt as _}; use rustc_ast::{Local, TyKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 3e58448af5266..26a7e56a38eca 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -2,14 +2,14 @@ use clippy_config::Conf; use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::{is_from_proc_macro, trait_ref_of_method}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_ast::visit::{try_visit, walk_list}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_errors::Applicability; use rustc_hir::FnRetTy::Return; use rustc_hir::intravisit::nested_filter::{self as hir_nested_filter, NestedFilter}; use rustc_hir::intravisit::{ - Visitor, VisitorExt, walk_fn_decl, walk_generic_args, walk_generic_param, walk_generics, walk_impl_item_ref, + Visitor, VisitorExt as _, walk_fn_decl, walk_generic_args, walk_generic_param, walk_generics, walk_impl_item_ref, walk_param_bound, walk_poly_trait_ref, walk_trait_ref, walk_ty, walk_unambig_ty, walk_where_predicate, }; use rustc_hir::{ @@ -18,7 +18,7 @@ use rustc_hir::{ PolyTraitRef, PredicateOrigin, TraitFn, TraitItem, TraitItemKind, TraitRef, Ty, TyKind, WhereBoundPredicate, WherePredicate, WherePredicateKind, lang_items, }; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::hir::nested_filter as middle_nested_filter; use rustc_middle::ty::TyCtxt; use rustc_session::impl_lint_pass; diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 4e7ff879ae590..f6e0fa784baa6 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -1,11 +1,11 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::numeric_literal::{NumericLiteral, Radix}; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_ast::ast::{Expr, ExprKind, LitKind}; use rustc_ast::token; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; use std::iter; diff --git a/clippy_lints/src/loops/char_indices_as_byte_indices.rs b/clippy_lints/src/loops/char_indices_as_byte_indices.rs index f4d71d0524b22..9231f341b72aa 100644 --- a/clippy_lints/src/loops/char_indices_as_byte_indices.rs +++ b/clippy_lints/src/loops/char_indices_as_byte_indices.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::visitors::for_each_expr; use clippy_utils::{eq_expr_value, higher, sym}; use rustc_errors::{Applicability, MultiSpan}; diff --git a/clippy_lints/src/loops/explicit_into_iter_loop.rs b/clippy_lints/src/loops/explicit_into_iter_loop.rs index daca78e344748..036d666d458bd 100644 --- a/clippy_lints/src/loops/explicit_into_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_into_iter_loop.rs @@ -1,6 +1,6 @@ use super::EXPLICIT_INTO_ITER_LOOP; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_context; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/loops/explicit_iter_loop.rs b/clippy_lints/src/loops/explicit_iter_loop.rs index a189bd7b717e9..37a0c4e13c0e2 100644 --- a/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/clippy_lints/src/loops/explicit_iter_loop.rs @@ -1,7 +1,7 @@ use super::EXPLICIT_ITER_LOOP; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use clippy_utils::sym; use clippy_utils::ty::{ diff --git a/clippy_lints/src/loops/for_kv_map.rs b/clippy_lints/src/loops/for_kv_map.rs index d28029790732b..046aafbca195e 100644 --- a/clippy_lints/src/loops/for_kv_map.rs +++ b/clippy_lints/src/loops/for_kv_map.rs @@ -1,6 +1,6 @@ use super::FOR_KV_MAP; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::{snippet_with_applicability, walk_span_to_context}; use clippy_utils::{pat_is_wild, sugg}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/loops/infinite_loop.rs b/clippy_lints/src/loops/infinite_loop.rs index dbd9deff1c2b6..404ff33838b15 100644 --- a/clippy_lints/src/loops/infinite_loop.rs +++ b/clippy_lints/src/loops/infinite_loop.rs @@ -7,7 +7,7 @@ use rustc_hir::{ self as hir, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnRetTy, FnSig, Node, TyKind, }; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_span::sym; use super::INFINITE_LOOP; diff --git a/clippy_lints/src/loops/iter_next_loop.rs b/clippy_lints/src/loops/iter_next_loop.rs index 8a4644cdf5efd..8b85f9dde6c92 100644 --- a/clippy_lints/src/loops/iter_next_loop.rs +++ b/clippy_lints/src/loops/iter_next_loop.rs @@ -1,6 +1,6 @@ use super::ITER_NEXT_LOOP; use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use rustc_hir::Expr; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/loops/manual_find.rs b/clippy_lints/src/loops/manual_find.rs index d94dcfab23c73..9664fe17aecd1 100644 --- a/clippy_lints/src/loops/manual_find.rs +++ b/clippy_lints/src/loops/manual_find.rs @@ -1,7 +1,7 @@ use super::MANUAL_FIND; use super::utils::make_iterator_snippet; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::implements_trait; use clippy_utils::usage::contains_return_break_continue_macro; diff --git a/clippy_lints/src/loops/manual_flatten.rs b/clippy_lints/src/loops/manual_flatten.rs index 2c89afc739745..d0fdd2131307a 100644 --- a/clippy_lints/src/loops/manual_flatten.rs +++ b/clippy_lints/src/loops/manual_flatten.rs @@ -2,7 +2,7 @@ use super::MANUAL_FLATTEN; use super::utils::make_iterator_snippet; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::{indent_of, reindent_multiline, snippet_with_applicability}; use clippy_utils::visitors::is_local_used; use clippy_utils::{higher, is_refutable, peel_blocks_with_stmt, span_contains_comment}; diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index eb1987806416f..ec0c4fb23390b 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -1,6 +1,6 @@ use super::{IncrementVisitor, InitializeVisitor, MANUAL_MEMCPY}; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet; use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_copy; diff --git a/clippy_lints/src/loops/missing_spin_loop.rs b/clippy_lints/src/loops/missing_spin_loop.rs index ca8383070d70f..0052418ad088c 100644 --- a/clippy_lints/src/loops/missing_spin_loop.rs +++ b/clippy_lints/src/loops/missing_spin_loop.rs @@ -1,6 +1,6 @@ use super::MISSING_SPIN_LOOP; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::std_or_core; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, ExprKind}; diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index 017d795cd992b..4c7a241f2e444 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -27,7 +27,7 @@ mod while_let_on_iterator; use clippy_config::Conf; use clippy_utils::msrvs::Msrv; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::{higher, sym}; use rustc_ast::Label; use rustc_hir::{Expr, ExprKind, LoopSource, Pat}; diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs index 6ab7bb628eca5..10af083c195e2 100644 --- a/clippy_lints/src/loops/mut_range_bound.rs +++ b/clippy_lints/src/loops/mut_range_bound.rs @@ -1,6 +1,6 @@ use super::MUT_RANGE_BOUND; use clippy_utils::diagnostics::span_lint_and_note; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::{get_enclosing_block, higher}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Node, PatKind}; diff --git a/clippy_lints/src/loops/same_item_push.rs b/clippy_lints/src/loops/same_item_push.rs index ba309d94608c4..5e133cb79ce96 100644 --- a/clippy_lints/src/loops/same_item_push.rs +++ b/clippy_lints/src/loops/same_item_push.rs @@ -1,7 +1,7 @@ use super::SAME_ITEM_PUSH; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::Msrv; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_context; use clippy_utils::ty::implements_trait; use clippy_utils::{msrvs, std_or_core, sym}; diff --git a/clippy_lints/src/loops/unused_enumerate_index.rs b/clippy_lints/src/loops/unused_enumerate_index.rs index b80efdae9294c..3d46991d1c224 100644 --- a/clippy_lints/src/loops/unused_enumerate_index.rs +++ b/clippy_lints/src/loops/unused_enumerate_index.rs @@ -1,7 +1,7 @@ use super::UNUSED_ENUMERATE_INDEX; use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::{SpanExt, walk_span_to_context}; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::{SpanExt as _, walk_span_to_context}; use clippy_utils::{expr_or_init, pat_is_wild, sym}; use rustc_errors::Applicability; use rustc_hir::{Closure, Expr, ExprKind, Pat, PatKind, TyKind}; diff --git a/clippy_lints/src/loops/utils.rs b/clippy_lints/src/loops/utils.rs index 81e868b3b7ba7..25a2ba93d9064 100644 --- a/clippy_lints/src/loops/utils.rs +++ b/clippy_lints/src/loops/utils.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::ty::{has_iter_method, implements_trait}; use clippy_utils::{get_parent_expr, is_integer_literal, sugg}; use rustc_ast::ast::{LitIntType, LitKind}; diff --git a/clippy_lints/src/loops/while_let_on_iterator.rs b/clippy_lints/src/loops/while_let_on_iterator.rs index fc0789894cc2c..68b4865de4752 100644 --- a/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/clippy_lints/src/loops/while_let_on_iterator.rs @@ -2,7 +2,7 @@ use std::ops::ControlFlow; use super::WHILE_LET_ON_ITERATOR; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::visitors::is_res_used; use clippy_utils::{as_some_pattern, get_enclosing_loop_or_multi_call_closure, higher, is_refutable}; diff --git a/clippy_lints/src/macro_metavars_in_unsafe.rs b/clippy_lints/src/macro_metavars_in_unsafe.rs index 8ff6de283557f..2a68c582effc2 100644 --- a/clippy_lints/src/macro_metavars_in_unsafe.rs +++ b/clippy_lints/src/macro_metavars_in_unsafe.rs @@ -1,11 +1,11 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::is_lint_allowed; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{Visitor, walk_block, walk_expr, walk_stmt}; use rustc_hir::{BlockCheckMode, Expr, ExprKind, HirId, Stmt, UnsafeSource, find_attr}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::{Span, SyntaxContext}; use std::collections::BTreeMap; diff --git a/clippy_lints/src/macro_use.rs b/clippy_lints/src/macro_use.rs index 6eda0fa257a98..e746ea9cbfc7b 100644 --- a/clippy_lints/src/macro_use.rs +++ b/clippy_lints/src/macro_use.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{self as hir, AmbigArg, find_attr}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; use rustc_span::edition::Edition; diff --git a/clippy_lints/src/manual_abs_diff.rs b/clippy_lints/src/manual_abs_diff.rs index b3c2e93a077fc..f36d3ad837080 100644 --- a/clippy_lints/src/manual_abs_diff.rs +++ b/clippy_lints/src/manual_abs_diff.rs @@ -2,7 +2,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::higher::If; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sugg::Sugg; use clippy_utils::ty::peel_and_count_ty_refs; use clippy_utils::{eq_expr_value, peel_blocks, span_contains_comment, sym}; diff --git a/clippy_lints/src/manual_assert.rs b/clippy_lints/src/manual_assert.rs index c77133130ba4d..2a0711d8ebbce 100644 --- a/clippy_lints/src/manual_assert.rs +++ b/clippy_lints/src/manual_assert.rs @@ -4,7 +4,7 @@ use clippy_utils::source::{indent_of, reindent_multiline}; use clippy_utils::{higher, is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/manual_assert_eq.rs b/clippy_lints/src/manual_assert_eq.rs index d1770d2e95a66..2f90a7fac474f 100644 --- a/clippy_lints/src/manual_assert_eq.rs +++ b/clippy_lints/src/manual_assert_eq.rs @@ -6,7 +6,7 @@ use clippy_utils::ty::implements_trait; use clippy_utils::{is_in_const_context, sym}; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs index 161834914b309..de07cea28bf56 100644 --- a/clippy_lints/src/manual_async_fn.rs +++ b/clippy_lints/src/manual_async_fn.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{SpanExt, position_before_rarrow, snippet_block}; +use clippy_utils::source::{SpanExt as _, position_before_rarrow, snippet_block}; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{ diff --git a/clippy_lints/src/manual_clamp.rs b/clippy_lints/src/manual_clamp.rs index c81fa2e2b3b27..a1a9266deaf96 100644 --- a/clippy_lints/src/manual_clamp.rs +++ b/clippy_lints/src/manual_clamp.rs @@ -3,12 +3,12 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::higher::If; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeResPath, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::implements_trait; use clippy_utils::visitors::is_const_evaluatable; use clippy_utils::{eq_expr_value, is_in_const_context, peel_blocks, peel_blocks_with_stmt, sym}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_errors::{Applicability, Diag}; use rustc_hir::def::Res; use rustc_hir::{Arm, BinOpKind, Block, Expr, ExprKind, HirId, PatKind, PathSegment, PrimTy, QPath, StmtKind}; diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index acd47fcd279db..83960f0e7ed1f 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -3,13 +3,13 @@ use clippy_utils::consts::ConstEvalCtxt; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeResPath as _; +use clippy_utils::source::SpanExt as _; use rustc_errors::Applicability; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_hir::{BinOpKind, Constness, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, Lint, LintContext}; +use rustc_lint::{LateContext, LateLintPass, Lint, LintContext as _}; use rustc_middle::ty::TyCtxt; use rustc_session::impl_lint_pass; diff --git a/clippy_lints/src/manual_hash_one.rs b/clippy_lints/src/manual_hash_one.rs index 33370194d4e7c..b3f256556c697 100644 --- a/clippy_lints/src/manual_hash_one.rs +++ b/clippy_lints/src/manual_hash_one.rs @@ -1,8 +1,8 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeResPath, MaybeTypeckRes}; -use clippy_utils::source::SpanExt; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _, MaybeTypeckRes as _}; +use clippy_utils::source::SpanExt as _; use clippy_utils::sym; use clippy_utils::visitors::{is_local_used, local_used_once}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/manual_ignore_case_cmp.rs b/clippy_lints/src/manual_ignore_case_cmp.rs index 1c20a8f81efbd..b214ace2e584f 100644 --- a/clippy_lints/src/manual_ignore_case_cmp.rs +++ b/clippy_lints/src/manual_ignore_case_cmp.rs @@ -1,6 +1,6 @@ use crate::manual_ignore_case_cmp::MatchType::{Literal, ToAscii}; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use clippy_utils::sym; use rustc_ast::LitKind; diff --git a/clippy_lints/src/manual_ilog2.rs b/clippy_lints/src/manual_ilog2.rs index 2c368f15d6705..a9a2878b72e6b 100644 --- a/clippy_lints/src/manual_ilog2.rs +++ b/clippy_lints/src/manual_ilog2.rs @@ -7,7 +7,7 @@ use rustc_ast::LitKind; use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty; use rustc_session::impl_lint_pass; diff --git a/clippy_lints/src/manual_is_ascii_check.rs b/clippy_lints/src/manual_is_ascii_check.rs index 996b00466de7d..63841ecf89471 100644 --- a/clippy_lints/src/manual_is_ascii_check.rs +++ b/clippy_lints/src/manual_is_ascii_check.rs @@ -2,7 +2,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::matching_root_macro_call; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::sugg::Sugg; use clippy_utils::{higher, is_in_const_context, peel_ref_operators, sym}; use rustc_ast::LitKind::{Byte, Char}; diff --git a/clippy_lints/src/manual_let_else.rs b/clippy_lints/src/manual_let_else.rs index 8b92c3b8cbeb5..7bccc30b9e95c 100644 --- a/clippy_lints/src/manual_let_else.rs +++ b/clippy_lints/src/manual_let_else.rs @@ -2,7 +2,7 @@ use crate::question_mark::{QUESTION_MARK, QuestionMark}; use clippy_config::types::MatchLintBehaviour; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::higher::IfLetOrMatch; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::source::snippet_with_context; use clippy_utils::{is_lint_allowed, is_never_expr, is_wild, msrvs, pat_and_expr_can_be_question_mark, peel_blocks}; use rustc_ast::BindingMode; @@ -12,7 +12,7 @@ use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::{ Arm, BlockCheckMode, Expr, ExprKind, MatchSource, Pat, PatExpr, PatExprKind, PatKind, QPath, Stmt, StmtKind, }; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_span::Span; use rustc_span::symbol::{Symbol, sym}; use std::slice; diff --git a/clippy_lints/src/manual_main_separator_str.rs b/clippy_lints/src/manual_main_separator_str.rs index 47e98d68bc830..6ebbe0d59f5dc 100644 --- a/clippy_lints/src/manual_main_separator_str.rs +++ b/clippy_lints/src/manual_main_separator_str.rs @@ -1,7 +1,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::{peel_hir_expr_refs, sym}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; diff --git a/clippy_lints/src/manual_non_exhaustive.rs b/clippy_lints/src/manual_non_exhaustive.rs index 84b30a40e1bde..97db6340791f2 100644 --- a/clippy_lints/src/manual_non_exhaustive.rs +++ b/clippy_lints/src/manual_non_exhaustive.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::is_doc_hidden; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::snippet_indent; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; diff --git a/clippy_lints/src/manual_option_as_slice.rs b/clippy_lints/src/manual_option_as_slice.rs index a851f1ea48db4..d78a008fd6d45 100644 --- a/clippy_lints/src/manual_option_as_slice.rs +++ b/clippy_lints/src/manual_option_as_slice.rs @@ -1,7 +1,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::Msrv; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_context; use clippy_utils::{as_some_pattern, is_none_pattern, msrvs, peel_hir_expr_refs, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/manual_pop_if.rs b/clippy_lints/src/manual_pop_if.rs index f29403d1a9060..a372452797500 100644 --- a/clippy_lints/src/manual_pop_if.rs +++ b/clippy_lints/src/manual_pop_if.rs @@ -1,7 +1,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use clippy_utils::visitors::{for_each_expr_without_closures, is_local_used}; use clippy_utils::{eq_expr_value, is_else_clause, is_lang_item_or_ctor, span_contains_non_whitespace, sym}; diff --git a/clippy_lints/src/manual_range_patterns.rs b/clippy_lints/src/manual_range_patterns.rs index 94a3f2b1f15f9..00b5a194a4aac 100644 --- a/clippy_lints/src/manual_range_patterns.rs +++ b/clippy_lints/src/manual_range_patterns.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_ast::LitKind; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::{PatExpr, PatExprKind, PatKind, RangeEnd}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::{DUMMY_SP, Span}; diff --git a/clippy_lints/src/manual_rem_euclid.rs b/clippy_lints/src/manual_rem_euclid.rs index 3ee92dca5303c..7338ede88a8e6 100644 --- a/clippy_lints/src/manual_rem_euclid.rs +++ b/clippy_lints/src/manual_rem_euclid.rs @@ -3,11 +3,11 @@ use clippy_utils::consts::{ConstEvalCtxt, FullInt}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_in_const_context; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet_with_context; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, Node, TyKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::SyntaxContext; diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index bc2e67de99d85..df17eb2066b91 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -1,7 +1,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet; use clippy_utils::{SpanlessEq, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/manual_take.rs b/clippy_lints/src/manual_take.rs index dec2a641231a0..ea4a1c554cc29 100644 --- a/clippy_lints/src/manual_take.rs +++ b/clippy_lints/src/manual_take.rs @@ -6,7 +6,7 @@ use clippy_utils::source::snippet_with_context; use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, ExprKind, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 5089bd9e14e4a..86a175aa2a645 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_context}; use clippy_utils::{iter_input_pats, method_chain_args}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/match_result_ok.rs b/clippy_lints/src/match_result_ok.rs index 1ebbd209ae52d..ad4bc210463d9 100644 --- a/clippy_lints/src/match_result_ok.rs +++ b/clippy_lints/src/match_result_ok.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use clippy_utils::{as_some_pattern, higher, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/matches/collapsible_match.rs b/clippy_lints/src/matches/collapsible_match.rs index 2eb15928f25aa..0124f80524f69 100644 --- a/clippy_lints/src/matches/collapsible_match.rs +++ b/clippy_lints/src/matches/collapsible_match.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::higher::{If, IfLetOrMatch}; use clippy_utils::msrvs::Msrv; -use clippy_utils::res::{MaybeDef, MaybeResPath}; -use clippy_utils::source::{IntoSpan, SpanExt, snippet}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; +use clippy_utils::source::{IntoSpan as _, SpanExt as _, snippet}; use clippy_utils::usage::mutated_variables; use clippy_utils::visitors::is_local_used; use clippy_utils::{SpanlessEq, get_ref_operators, is_unit_expr, peel_blocks_with_stmt, peel_ref_operators}; diff --git a/clippy_lints/src/matches/infallible_destructuring_match.rs b/clippy_lints/src/matches/infallible_destructuring_match.rs index 84befc17b1206..520f4784c444c 100644 --- a/clippy_lints/src/matches/infallible_destructuring_match.rs +++ b/clippy_lints/src/matches/infallible_destructuring_match.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{peel_blocks, strip_pat_refs}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/matches/manual_filter.rs b/clippy_lints/src/matches/manual_filter.rs index 9c2d60eb9c575..6d8f27684c0ab 100644 --- a/clippy_lints/src/matches/manual_filter.rs +++ b/clippy_lints/src/matches/manual_filter.rs @@ -1,6 +1,6 @@ use clippy_utils::as_some_expr; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_context; use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_copy; diff --git a/clippy_lints/src/matches/manual_map.rs b/clippy_lints/src/matches/manual_map.rs index f111da60bbd5b..5e8d69a5b4e8b 100644 --- a/clippy_lints/src/matches/manual_map.rs +++ b/clippy_lints/src/matches/manual_map.rs @@ -2,7 +2,7 @@ use super::MANUAL_MAP; use super::manual_utils::{SomeExpr, check_with}; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use rustc_hir::LangItem::OptionSome; use rustc_hir::{Arm, Block, BlockCheckMode, Expr, ExprKind, Pat, UnsafeSource}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/matches/manual_ok_err.rs b/clippy_lints/src/matches/manual_ok_err.rs index abbf60019c5c0..c599099d3ce42 100644 --- a/clippy_lints/src/matches/manual_ok_err.rs +++ b/clippy_lints/src/matches/manual_ok_err.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::{indent_of, reindent_multiline}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{option_arg_ty, peel_and_count_ty_refs}; diff --git a/clippy_lints/src/matches/manual_unwrap_or.rs b/clippy_lints/src/matches/manual_unwrap_or.rs index e317056e29809..a08329036dc1a 100644 --- a/clippy_lints/src/matches/manual_unwrap_or.rs +++ b/clippy_lints/src/matches/manual_unwrap_or.rs @@ -1,5 +1,5 @@ use clippy_utils::consts::ConstEvalCtxt; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _}; use clippy_utils::source::{SpanExt as _, indent_of, reindent_multiline}; use rustc_ast::{BindingMode, ByRef}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/matches/manual_utils.rs b/clippy_lints/src/matches/manual_utils.rs index 26fd936767aa7..aa91369a1f0cd 100644 --- a/clippy_lints/src/matches/manual_utils.rs +++ b/clippy_lints/src/matches/manual_utils.rs @@ -1,6 +1,6 @@ use crate::map_unit_fn::OPTION_MAP_UNIT_FN; use crate::matches::MATCH_AS_REF; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{is_copy, is_unsafe_fn, peel_and_count_ty_refs}; diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index f500f21246bdb..df93f142fddaa 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -1,17 +1,17 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeResPath; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeResPath as _; +use clippy_utils::source::SpanExt as _; use clippy_utils::{SpanlessEq, fulfill_or_allowed, hash_expr, is_lint_allowed, search_same}; use core::cmp::Ordering; use core::{iter, slice}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_arena::DroplessArena; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{Arm, Expr, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatExpr, PatExprKind, PatKind, RangeEnd}; use rustc_lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::{self, TypeckResults}; use rustc_span::{ByteSymbol, ErrorGuaranteed, Span, Symbol, SyntaxContext}; diff --git a/clippy_lints/src/matches/match_single_binding.rs b/clippy_lints/src/matches/match_single_binding.rs index 3c0fad01835f6..2a15d732939c3 100644 --- a/clippy_lints/src/matches/match_single_binding.rs +++ b/clippy_lints/src/matches/match_single_binding.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::macros::HirNode; +use clippy_utils::macros::HirNode as _; use clippy_utils::source::{indent_of, reindent_multiline, snippet, snippet_block_with_context, snippet_with_context}; use clippy_utils::{is_expr_identity_of_pat, is_refutable, peel_blocks}; use rustc_data_structures::fx::FxHashSet; diff --git a/clippy_lints/src/matches/match_str_case_mismatch.rs b/clippy_lints/src/matches/match_str_case_mismatch.rs index 3f8f2dc0e132d..874feb9b4b189 100644 --- a/clippy_lints/src/matches/match_str_case_mismatch.rs +++ b/clippy_lints/src/matches/match_str_case_mismatch.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/matches/match_wild_enum.rs b/clippy_lints/src/matches/match_wild_enum.rs index 98530b7808076..b084466266fd6 100644 --- a/clippy_lints/src/matches/match_wild_enum.rs +++ b/clippy_lints/src/matches/match_wild_enum.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::SpanExt as _; use clippy_utils::{is_refutable, peel_hir_pat_refs, recurse_or_patterns}; use rustc_errors::Applicability; use rustc_hir::def::{CtorKind, DefKind, Res}; diff --git a/clippy_lints/src/matches/match_wild_err_arm.rs b/clippy_lints/src/matches/match_wild_err_arm.rs index e38ba801c0bf7..c5e725b8456d5 100644 --- a/clippy_lints/src/matches/match_wild_err_arm.rs +++ b/clippy_lints/src/matches/match_wild_err_arm.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::macros::{is_panic, root_macro_call}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::visitors::is_local_used; use clippy_utils::{is_in_const_context, is_wild, peel_blocks_with_stmt}; use rustc_hir::{Arm, Expr, PatKind}; diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index 7b9d10cccfef0..fa4c0166e4a98 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -26,13 +26,13 @@ mod wild_in_or_pats; use clippy_config::Conf; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::{ higher, is_direct_expn_of, is_in_const_context, is_lint_allowed, is_span_match, sym, tokenize_with_text, }; use rustc_hir::{Arm, Expr, ExprKind, LetStmt, MatchSource, Pat, PatKind}; use rustc_lexer::{TokenKind, is_whitespace}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/matches/needless_match.rs b/clippy_lints/src/matches/needless_match.rs index 0151aa8ef15ef..cdf4ce04a4fba 100644 --- a/clippy_lints/src/matches/needless_match.rs +++ b/clippy_lints/src/matches/needless_match.rs @@ -1,6 +1,6 @@ use super::NEEDLESS_MATCH; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::same_type_modulo_regions; use clippy_utils::{ diff --git a/clippy_lints/src/matches/redundant_guards.rs b/clippy_lints/src/matches/redundant_guards.rs index fa8b6a65a2038..427921f38c79f 100644 --- a/clippy_lints/src/matches/redundant_guards.rs +++ b/clippy_lints/src/matches/redundant_guards.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::matching_root_macro_call; use clippy_utils::msrvs::Msrv; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet; use clippy_utils::visitors::{for_each_expr_without_closures, is_local_used}; use clippy_utils::{is_in_const_context, sym}; diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index b10c6c0ac5934..04eadbe722091 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -1,6 +1,6 @@ use super::REDUNDANT_PATTERN_MATCHING; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::sugg::{Sugg, make_unop}; use clippy_utils::ty::needs_ordered_drop; use clippy_utils::visitors::{any_temporaries_need_ordered_drop, for_each_expr_without_closures}; @@ -13,7 +13,7 @@ use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatExpr, PatExprKind, PatKind, Q use rustc_lint::LateContext; use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_span::{Span, Symbol, kw}; -use std::fmt::Write; +use std::fmt::Write as _; use std::ops::ControlFlow; pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index ae7702105462f..db1e4f2717bd9 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -5,14 +5,14 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{first_line_of_span, indent_of, snippet}; use clippy_utils::ty::{for_each_top_level_late_bound_region, is_copy}; use clippy_utils::{get_builtin_attr, is_lint_allowed, sym}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_ast::Mutability; use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::{Visitor, walk_expr}; use rustc_hir::{Arm, Expr, ExprKind, MatchSource}; use rustc_lint::LateContext; -use rustc_middle::ty::{GenericArgKind, RegionKind, Ty, TypeVisitableExt}; +use rustc_middle::ty::{GenericArgKind, RegionKind, Ty, TypeVisitableExt as _}; use rustc_span::Span; use super::SIGNIFICANT_DROP_IN_SCRUTINEE; diff --git a/clippy_lints/src/matches/single_match.rs b/clippy_lints/src/matches/single_match.rs index 7c740ababb060..4a1e2090224d2 100644 --- a/clippy_lints/src/matches/single_match.rs +++ b/clippy_lints/src/matches/single_match.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::{ - SpanExt, expr_block, snippet, snippet_block_with_context, snippet_with_applicability, snippet_with_context, + SpanExt as _, expr_block, snippet, snippet_block_with_context, snippet_with_applicability, snippet_with_context, }; use clippy_utils::ty::{implements_trait, peel_and_count_ty_refs}; use clippy_utils::{is_lint_allowed, is_unit_expr, peel_blocks, peel_hir_pat_refs, peel_n_hir_expr_refs, sym}; diff --git a/clippy_lints/src/matches/try_err.rs b/clippy_lints/src/matches/try_err.rs index 401b8468135bc..81dc46a2fa992 100644 --- a/clippy_lints/src/matches/try_err.rs +++ b/clippy_lints/src/matches/try_err.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::get_parent_expr; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::option_arg_ty; use rustc_errors::Applicability; diff --git a/clippy_lints/src/mem_replace.rs b/clippy_lints/src/mem_replace.rs index 0d417c25ef0e1..21fc3a905e045 100644 --- a/clippy_lints/src/mem_replace.rs +++ b/clippy_lints/src/mem_replace.rs @@ -1,7 +1,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_non_aggregate_primitive_type; diff --git a/clippy_lints/src/methods/by_ref_peekable_peek.rs b/clippy_lints/src/methods/by_ref_peekable_peek.rs index 1faaf2c9c8e43..e727a77d1ae27 100644 --- a/clippy_lints/src/methods/by_ref_peekable_peek.rs +++ b/clippy_lints/src/methods/by_ref_peekable_peek.rs @@ -1,6 +1,6 @@ -use crate::clippy_utils::res::MaybeTypeckRes; +use crate::clippy_utils::res::MaybeTypeckRes as _; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath as _}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::sugg::Sugg; use clippy_utils::sym; use clippy_utils::ty::implements_trait; diff --git a/clippy_lints/src/methods/bytecount.rs b/clippy_lints/src/methods/bytecount.rs index 2ad7facf64d88..2a81abac4896a 100644 --- a/clippy_lints/src/methods/bytecount.rs +++ b/clippy_lints/src/methods/bytecount.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::visitors::is_local_used; use clippy_utils::{peel_blocks, peel_ref_operators, strip_pat_refs, sym}; diff --git a/clippy_lints/src/methods/bytes_count_to_len.rs b/clippy_lints/src/methods/bytes_count_to_len.rs index 5abdd82f1cde2..abf551590573b 100644 --- a/clippy_lints/src/methods/bytes_count_to_len.rs +++ b/clippy_lints/src/methods/bytes_count_to_len.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/bytes_nth.rs b/clippy_lints/src/methods/bytes_nth.rs index 0a3ea3005e72b..c0db96fd8becf 100644 --- a/clippy_lints/src/methods/bytes_nth.rs +++ b/clippy_lints/src/methods/bytes_nth.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sym; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs index b6694ad5148ba..894af02176954 100644 --- a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::{SpanExt, indent_of, reindent_multiline}; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::{SpanExt as _, indent_of, reindent_multiline}; use clippy_utils::sym; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/chars_cmp.rs b/clippy_lints/src/methods/chars_cmp.rs index 4b0fc7eba8e34..046b616e81324 100644 --- a/clippy_lints/src/methods/chars_cmp.rs +++ b/clippy_lints/src/methods/chars_cmp.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::method_chain_args; -use clippy_utils::res::MaybeQPath; +use clippy_utils::res::MaybeQPath as _; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/chunks_exact_to_as_chunks.rs b/clippy_lints/src/methods/chunks_exact_to_as_chunks.rs index ec9fbd4432ab0..04da7257a29ec 100644 --- a/clippy_lints/src/methods/chunks_exact_to_as_chunks.rs +++ b/clippy_lints/src/methods/chunks_exact_to_as_chunks.rs @@ -1,7 +1,7 @@ use super::CHUNKS_EXACT_TO_AS_CHUNKS; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_context; use clippy_utils::visitors::is_const_param_evaluatable; use clippy_utils::{get_expr_use_site, sym}; diff --git a/clippy_lints/src/methods/clear_with_drain.rs b/clippy_lints/src/methods/clear_with_drain.rs index 0b6ead0747a80..6ef89788fbf82 100644 --- a/clippy_lints/src/methods/clear_with_drain.rs +++ b/clippy_lints/src/methods/clear_with_drain.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::{is_full_collection_range, sym}; use rustc_errors::Applicability; use rustc_hir::{Expr, LangItem}; diff --git a/clippy_lints/src/methods/clone_on_ref_ptr.rs b/clippy_lints/src/methods/clone_on_ref_ptr.rs index de32b0476d205..de3d4a0781a74 100644 --- a/clippy_lints/src/methods/clone_on_ref_ptr.rs +++ b/clippy_lints/src/methods/clone_on_ref_ptr.rs @@ -4,7 +4,7 @@ use clippy_utils::ty::peel_and_count_ty_refs; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; -use rustc_middle::ty::{self, IsSuggestable}; +use rustc_middle::ty::{self, IsSuggestable as _}; use rustc_span::symbol::sym; use super::CLONE_ON_REF_PTR; diff --git a/clippy_lints/src/methods/cloned_instead_of_copied.rs b/clippy_lints/src/methods/cloned_instead_of_copied.rs index d80d6f7810f53..aecc3bf748ea5 100644 --- a/clippy_lints/src/methods/cloned_instead_of_copied.rs +++ b/clippy_lints/src/methods/cloned_instead_of_copied.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::ty::{get_iterator_item_ty, is_copy}; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/methods/double_ended_iterator_last.rs b/clippy_lints/src/methods/double_ended_iterator_last.rs index 8ba8264b713c4..e30082681756a 100644 --- a/clippy_lints/src/methods/double_ended_iterator_last.rs +++ b/clippy_lints/src/methods/double_ended_iterator_last.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::ty::{has_non_owning_mutable_access, implements_trait}; use clippy_utils::{is_mutable, path_to_local_with_projections, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/drain_collect.rs b/clippy_lints/src/methods/drain_collect.rs index 2b4b200904b2e..12e14bf25134d 100644 --- a/clippy_lints/src/methods/drain_collect.rs +++ b/clippy_lints/src/methods/drain_collect.rs @@ -1,6 +1,6 @@ use crate::methods::DRAIN_COLLECT; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet; use clippy_utils::{is_full_collection_range, std_or_core, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/expect_fun_call.rs b/clippy_lints/src/methods/expect_fun_call.rs index 97a03f9868b1d..609cab45d42d1 100644 --- a/clippy_lints/src/methods/expect_fun_call.rs +++ b/clippy_lints/src/methods/expect_fun_call.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::macros::{FormatArgsStorage, format_args_inputs_span, root_macro_call_first_node}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::visitors::for_each_expr; use clippy_utils::{contains_return, is_inside_always_const_context, peel_blocks, sym}; diff --git a/clippy_lints/src/methods/extend_with_drain.rs b/clippy_lints/src/methods/extend_with_drain.rs index 829c1226a859e..af8128104f859 100644 --- a/clippy_lints/src/methods/extend_with_drain.rs +++ b/clippy_lints/src/methods/extend_with_drain.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sym; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/filetype_is_file.rs b/clippy_lints/src/methods/filetype_is_file.rs index 15f3adf3405e5..bd25f0a0011b6 100644 --- a/clippy_lints/src/methods/filetype_is_file.rs +++ b/clippy_lints/src/methods/filetype_is_file.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::{get_parent_expr, sym}; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/filter_map.rs b/clippy_lints/src/methods/filter_map.rs index 9ddc3d1bf1d8e..f42b73fce6bdc 100644 --- a/clippy_lints/src/methods/filter_map.rs +++ b/clippy_lints/src/methods/filter_map.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::macros::{is_panic, matching_root_macro_call, root_macro_call}; -use clippy_utils::res::{MaybeDef, MaybeResPath, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::source::{indent_of, reindent_multiline, snippet}; use clippy_utils::{SpanlessEq, higher, peel_blocks, sym}; use hir::{Body, HirId, MatchSource, Pat}; diff --git a/clippy_lints/src/methods/filter_map_bool_then.rs b/clippy_lints/src/methods/filter_map_bool_then.rs index 419a7e0ed877d..67c18c046cd17 100644 --- a/clippy_lints/src/methods/filter_map_bool_then.rs +++ b/clippy_lints/src/methods/filter_map_bool_then.rs @@ -1,14 +1,14 @@ use super::FILTER_MAP_BOOL_THEN; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; -use clippy_utils::source::{SpanExt, snippet_with_context}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; +use clippy_utils::source::{SpanExt as _, snippet_with_context}; use clippy_utils::ty::is_copy; use clippy_utils::{CaptureKind, can_move_expr_to_closure, contains_return, is_from_proc_macro, peel_blocks, sym}; use rustc_ast::Mutability; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, HirId, Param, Pat}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::Binder; use rustc_middle::ty::adjustment::Adjust; use rustc_span::Span; diff --git a/clippy_lints/src/methods/filter_map_identity.rs b/clippy_lints/src/methods/filter_map_identity.rs index c6e30710eef90..8bc29315e647a 100644 --- a/clippy_lints/src/methods/filter_map_identity.rs +++ b/clippy_lints/src/methods/filter_map_identity.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::{is_expr_identity_function, is_expr_untyped_identity_function}; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/filter_map_next.rs b/clippy_lints/src/methods/filter_map_next.rs index 9e55732830bc6..4eec1f30509b9 100644 --- a/clippy_lints/src/methods/filter_map_next.rs +++ b/clippy_lints/src/methods/filter_map_next.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/methods/flat_map_identity.rs b/clippy_lints/src/methods/flat_map_identity.rs index 043adb8434a0d..bc75b9d1c40e2 100644 --- a/clippy_lints/src/methods/flat_map_identity.rs +++ b/clippy_lints/src/methods/flat_map_identity.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_expr_untyped_identity_function; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/flat_map_option.rs b/clippy_lints/src/methods/flat_map_option.rs index fb0e8f9d91b5a..3a185ac6f3a84 100644 --- a/clippy_lints/src/methods/flat_map_option.rs +++ b/clippy_lints/src/methods/flat_map_option.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/format_collect.rs b/clippy_lints/src/methods/format_collect.rs index 7b2fe00d32188..b85e203e4d2e2 100644 --- a/clippy_lints/src/methods/format_collect.rs +++ b/clippy_lints/src/methods/format_collect.rs @@ -1,7 +1,7 @@ use super::FORMAT_COLLECT; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::{is_format_macro, root_macro_call_first_node}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_hir::{Expr, ExprKind, LangItem}; use rustc_lint::LateContext; use rustc_span::Span; diff --git a/clippy_lints/src/methods/get_first.rs b/clippy_lints/src/methods/get_first.rs index c3598eb59478a..f49aeabdf2193 100644 --- a/clippy_lints/src/methods/get_first.rs +++ b/clippy_lints/src/methods/get_first.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sym; use rustc_ast::LitKind; diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 768612d6bbdc1..fecd3c74fe7b2 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use clippy_utils::sym; use clippy_utils::ty::{implements_trait, peel_and_count_ty_refs}; diff --git a/clippy_lints/src/methods/inefficient_to_string.rs b/clippy_lints/src/methods/inefficient_to_string.rs index 374639985bee0..8e9781f668995 100644 --- a/clippy_lints/src/methods/inefficient_to_string.rs +++ b/clippy_lints/src/methods/inefficient_to_string.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sym; use clippy_utils::ty::peel_and_count_ty_refs; diff --git a/clippy_lints/src/methods/inspect_for_each.rs b/clippy_lints/src/methods/inspect_for_each.rs index 194ddf45e6f11..7628665db116c 100644 --- a/clippy_lints/src/methods/inspect_for_each.rs +++ b/clippy_lints/src/methods/inspect_for_each.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::{Span, sym}; diff --git a/clippy_lints/src/methods/into_iter_on_ref.rs b/clippy_lints/src/methods/into_iter_on_ref.rs index 5a062732721e5..297ec4f5427f9 100644 --- a/clippy_lints/src/methods/into_iter_on_ref.rs +++ b/clippy_lints/src/methods/into_iter_on_ref.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::ty::has_iter_method; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/io_other_error.rs b/clippy_lints/src/methods/io_other_error.rs index d9735f2941409..76830b359eee3 100644 --- a/clippy_lints/src/methods/io_other_error.rs +++ b/clippy_lints/src/methods/io_other_error.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::{expr_or_init, sym}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, QPath}; diff --git a/clippy_lints/src/methods/is_empty.rs b/clippy_lints/src/methods/is_empty.rs index cfda39ed08ff1..adb6beb8072db 100644 --- a/clippy_lints/src/methods/is_empty.rs +++ b/clippy_lints/src/methods/is_empty.rs @@ -1,10 +1,10 @@ use clippy_utils::consts::ConstEvalCtxt; use clippy_utils::diagnostics::span_lint; use clippy_utils::macros::{is_assert_macro, root_macro_call}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::{find_binding_init, get_parent_expr, is_inside_always_const_context}; use rustc_hir::{Expr, HirId, find_attr}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use super::CONST_IS_EMPTY; diff --git a/clippy_lints/src/methods/iter_cloned_collect.rs b/clippy_lints/src/methods/iter_cloned_collect.rs index 484d00e94f450..a0b4702f6688b 100644 --- a/clippy_lints/src/methods/iter_cloned_collect.rs +++ b/clippy_lints/src/methods/iter_cloned_collect.rs @@ -1,6 +1,6 @@ use crate::methods::utils::derefs_to_slice; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::ty::get_iterator_item_ty; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/methods/iter_count.rs b/clippy_lints/src/methods/iter_count.rs index 18278446bf610..b42ebab048f61 100644 --- a/clippy_lints/src/methods/iter_count.rs +++ b/clippy_lints/src/methods/iter_count.rs @@ -1,6 +1,6 @@ use super::utils::derefs_to_slice; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sym; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/iter_filter.rs b/clippy_lints/src/methods/iter_filter.rs index 3aa666145b86a..99d23a34cd95b 100644 --- a/clippy_lints/src/methods/iter_filter.rs +++ b/clippy_lints/src/methods/iter_filter.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::ty::get_iterator_item_ty; use hir::ExprKind; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/iter_kv_map.rs b/clippy_lints/src/methods/iter_kv_map.rs index 283b9b5fc5b4c..f8a8277d82d71 100644 --- a/clippy_lints/src/methods/iter_kv_map.rs +++ b/clippy_lints/src/methods/iter_kv_map.rs @@ -1,7 +1,7 @@ use super::ITER_KV_MAP; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::{pat_is_wild, sym}; use rustc_hir::{Body, Expr, ExprKind, PatKind}; diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs index ff467cb63414d..6de87114fc991 100644 --- a/clippy_lints/src/methods/iter_next_slice.rs +++ b/clippy_lints/src/methods/iter_next_slice.rs @@ -1,7 +1,7 @@ use super::ITER_NEXT_SLICE; use super::utils::derefs_to_slice; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{get_parent_expr, higher}; use rustc_ast::ast; diff --git a/clippy_lints/src/methods/iter_nth.rs b/clippy_lints/src/methods/iter_nth.rs index 6d1ee32e50269..0e11c248025a6 100644 --- a/clippy_lints/src/methods/iter_nth.rs +++ b/clippy_lints/src/methods/iter_nth.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/iter_nth_zero.rs b/clippy_lints/src/methods/iter_nth_zero.rs index e0107b75e4142..3417d689c7ff2 100644 --- a/clippy_lints/src/methods/iter_nth_zero.rs +++ b/clippy_lints/src/methods/iter_nth_zero.rs @@ -1,7 +1,7 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_lang_item_or_ctor; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_applicability; use hir::{LangItem, OwnerNode}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/iter_out_of_bounds.rs b/clippy_lints/src/methods/iter_out_of_bounds.rs index b0e805815bc9b..7ec9021af11d8 100644 --- a/clippy_lints/src/methods/iter_out_of_bounds.rs +++ b/clippy_lints/src/methods/iter_out_of_bounds.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_note; use clippy_utils::higher::VecArgs; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::{expr_or_init, sym}; use rustc_ast::LitKind; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/methods/iter_skip_next.rs b/clippy_lints/src/methods/iter_skip_next.rs index 661188c90ed61..918e68a092cba 100644 --- a/clippy_lints/src/methods/iter_skip_next.rs +++ b/clippy_lints/src/methods/iter_skip_next.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/iter_skip_zero.rs b/clippy_lints/src/methods/iter_skip_zero.rs index cae31e7c9606e..0f59367dc5f3e 100644 --- a/clippy_lints/src/methods/iter_skip_zero.rs +++ b/clippy_lints/src/methods/iter_skip_zero.rs @@ -1,7 +1,7 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/iter_with_drain.rs b/clippy_lints/src/methods/iter_with_drain.rs index 2ef09fa3f8d2c..782e703bc055f 100644 --- a/clippy_lints/src/methods/iter_with_drain.rs +++ b/clippy_lints/src/methods/iter_with_drain.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::{is_full_collection_range, sym}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/methods/iterator_step_by_zero.rs b/clippy_lints/src/methods/iterator_step_by_zero.rs index 11dde2429adfa..289252a4bf0ad 100644 --- a/clippy_lints/src/methods/iterator_step_by_zero.rs +++ b/clippy_lints/src/methods/iterator_step_by_zero.rs @@ -1,6 +1,6 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/join_absolute_paths.rs b/clippy_lints/src/methods/join_absolute_paths.rs index fe3ca632d6e35..cc387fee1f318 100644 --- a/clippy_lints/src/methods/join_absolute_paths.rs +++ b/clippy_lints/src/methods/join_absolute_paths.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet; use clippy_utils::{expr_or_init, sym}; use rustc_ast::ast::{LitKind, StrStyle}; diff --git a/clippy_lints/src/methods/lines_filter_map_ok.rs b/clippy_lints/src/methods/lines_filter_map_ok.rs index baf5b6f93f637..607979719f894 100644 --- a/clippy_lints/src/methods/lines_filter_map_ok.rs +++ b/clippy_lints/src/methods/lines_filter_map_ok.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeResPath, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir::{Body, Closure, Expr, ExprKind}; diff --git a/clippy_lints/src/methods/manual_clear.rs b/clippy_lints/src/methods/manual_clear.rs index dbf1c85add55d..025788b83b5b9 100644 --- a/clippy_lints/src/methods/manual_clear.rs +++ b/clippy_lints/src/methods/manual_clear.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::{is_integer_literal, sym}; use rustc_errors::Applicability; use rustc_hir::{Expr, LangItem}; diff --git a/clippy_lints/src/methods/manual_inspect.rs b/clippy_lints/src/methods/manual_inspect.rs index 5ef8450da93bc..aff6477c32547 100644 --- a/clippy_lints/src/methods/manual_inspect.rs +++ b/clippy_lints/src/methods/manual_inspect.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeResPath}; -use clippy_utils::source::{IntoSpan, SpanExt}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; +use clippy_utils::source::{IntoSpan as _, SpanExt as _}; use clippy_utils::ty::get_field_by_name; use clippy_utils::visitors::{for_each_expr, for_each_expr_without_closures}; use clippy_utils::{ExprUseNode, get_expr_use_site, sym}; diff --git a/clippy_lints/src/methods/manual_is_variant_and.rs b/clippy_lints/src/methods/manual_is_variant_and.rs index 8a0da622982c6..bd2b1ba299185 100644 --- a/clippy_lints/src/methods/manual_is_variant_and.rs +++ b/clippy_lints/src/methods/manual_is_variant_and.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::Sugg; use clippy_utils::{SpanlessEq, get_parent_expr, sym}; diff --git a/clippy_lints/src/methods/manual_next_back.rs b/clippy_lints/src/methods/manual_next_back.rs index 221c7f08c923c..ddb67e3801aae 100644 --- a/clippy_lints/src/methods/manual_next_back.rs +++ b/clippy_lints/src/methods/manual_next_back.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::sym; use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/manual_ok_or.rs b/clippy_lints/src/methods/manual_ok_or.rs index 050b28b3babd7..b010f7a8996fa 100644 --- a/clippy_lints/src/methods/manual_ok_or.rs +++ b/clippy_lints/src/methods/manual_ok_or.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; -use clippy_utils::source::{SpanExt, indent_of, reindent_multiline}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _}; +use clippy_utils::source::{SpanExt as _, indent_of, reindent_multiline}; use rustc_errors::Applicability; use rustc_hir::LangItem::{ResultErr, ResultOk}; use rustc_hir::{Expr, ExprKind, PatKind}; diff --git a/clippy_lints/src/methods/manual_option_zip.rs b/clippy_lints/src/methods/manual_option_zip.rs index 538f8a2fe93dc..e168beddf57b6 100644 --- a/clippy_lints/src/methods/manual_option_zip.rs +++ b/clippy_lints/src/methods/manual_option_zip.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::eager_or_lazy::switch_to_eager_eval; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::peel_blocks; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::usage::local_used_in; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/manual_repeat_n.rs b/clippy_lints/src/methods/manual_repeat_n.rs index 6f65fc48b38af..9520c7ad96cf4 100644 --- a/clippy_lints/src/methods/manual_repeat_n.rs +++ b/clippy_lints/src/methods/manual_repeat_n.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::{snippet, snippet_with_context}; use clippy_utils::{fn_def_id, get_expr_use_site, std_or_core, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index a3dd967bd77a9..742d7e1fbec72 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sym; use rustc_ast::ast; @@ -8,7 +8,7 @@ use rustc_hir::def::Res; use rustc_hir::{self as hir, Expr}; use rustc_lint::LateContext; use rustc_middle::ty::Ty; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_span::Symbol; pub fn check_unwrap_or( diff --git a/clippy_lints/src/methods/manual_str_repeat.rs b/clippy_lints/src/methods/manual_str_repeat.rs index 457549d1091c0..d04e224adf7af 100644 --- a/clippy_lints/src/methods/manual_str_repeat.rs +++ b/clippy_lints/src/methods/manual_str_repeat.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::Sugg; use clippy_utils::sym; diff --git a/clippy_lints/src/methods/manual_try_fold.rs b/clippy_lints/src/methods/manual_try_fold.rs index 6ef7abffb0b2f..e79162800cc49 100644 --- a/clippy_lints/src/methods/manual_try_fold.rs +++ b/clippy_lints/src/methods/manual_try_fold.rs @@ -1,13 +1,13 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_from_proc_macro; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; -use clippy_utils::source::SpanExt; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; +use clippy_utils::source::SpanExt as _; use clippy_utils::ty::implements_trait; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_span::{Span, sym}; use super::MANUAL_TRY_FOLD; diff --git a/clippy_lints/src/methods/map_all_any_identity.rs b/clippy_lints/src/methods/map_all_any_identity.rs index 14a9752d3bded..4ac9647f4141f 100644 --- a/clippy_lints/src/methods/map_all_any_identity.rs +++ b/clippy_lints/src/methods/map_all_any_identity.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_expr_identity_function; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; -use clippy_utils::source::SpanExt; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; +use clippy_utils::source::SpanExt as _; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/map_clone.rs b/clippy_lints/src/methods/map_clone.rs index efbb094d49c79..3d3fdc4f72b6e 100644 --- a/clippy_lints/src/methods/map_clone.rs +++ b/clippy_lints/src/methods/map_clone.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::peel_blocks; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{is_copy, should_call_clone_as_function}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/map_collect_result_unit.rs b/clippy_lints/src/methods/map_collect_result_unit.rs index 1112fbc2a1c74..6f556fe592af8 100644 --- a/clippy_lints/src/methods/map_collect_result_unit.rs +++ b/clippy_lints/src/methods/map_collect_result_unit.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/map_err_ignore.rs b/clippy_lints/src/methods/map_err_ignore.rs index 96b8b9dc03227..9868d1a60d0a8 100644 --- a/clippy_lints/src/methods/map_err_ignore.rs +++ b/clippy_lints/src/methods/map_err_ignore.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_hir::{CaptureBy, Closure, Expr, ExprKind, PatKind}; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/map_flatten.rs b/clippy_lints/src/methods/map_flatten.rs index b654548cc2050..cb2880c8c7123 100644 --- a/clippy_lints/src/methods/map_flatten.rs +++ b/clippy_lints/src/methods/map_flatten.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::span_contains_comment; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/map_identity.rs b/clippy_lints/src/methods/map_identity.rs index fa394526bdf1e..a4c084623e3b0 100644 --- a/clippy_lints/src/methods/map_identity.rs +++ b/clippy_lints/src/methods/map_identity.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_copy; use clippy_utils::{is_expr_untyped_identity_function, is_mutable, path_to_local_with_projections}; use rustc_errors::Applicability; use rustc_hir::{self as hir, ExprKind, Node, PatKind}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_span::{Span, Symbol, sym}; use super::MAP_IDENTITY; diff --git a/clippy_lints/src/methods/map_or_identity.rs b/clippy_lints/src/methods/map_or_identity.rs index e4e5fa5420105..a43751b6f94cf 100644 --- a/clippy_lints/src/methods/map_or_identity.rs +++ b/clippy_lints/src/methods/map_or_identity.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_expr_identity_function; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index ddb2fba94bba9..53bcd319bc861 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -158,11 +158,11 @@ use clippy_config::Conf; use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::macros::FormatArgsStorage; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::{contains_return, iter_input_pats, peel_blocks, sym}; use rustc_data_structures::fx::FxHashSet; use rustc_hir::{self as hir, Expr, ExprKind, Node, Stmt, StmtKind, TraitItem, TraitItemKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::TraitRef; use rustc_session::impl_lint_pass; use rustc_span::{Span, Symbol}; diff --git a/clippy_lints/src/methods/mut_mutex_lock.rs b/clippy_lints/src/methods/mut_mutex_lock.rs index c9264e747b56d..4ef9169e4daf2 100644 --- a/clippy_lints/src/methods/mut_mutex_lock.rs +++ b/clippy_lints/src/methods/mut_mutex_lock.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::expr_custom_deref_adjustment; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::ty::peel_and_count_ty_refs; use rustc_errors::Applicability; use rustc_hir::{Expr, Mutability}; diff --git a/clippy_lints/src/methods/needless_as_bytes.rs b/clippy_lints/src/methods/needless_as_bytes.rs index 22baad40b4496..6a20d401419ff 100644 --- a/clippy_lints/src/methods/needless_as_bytes.rs +++ b/clippy_lints/src/methods/needless_as_bytes.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sugg::Sugg; use rustc_errors::Applicability; use rustc_hir::{Expr, LangItem}; diff --git a/clippy_lints/src/methods/needless_character_iteration.rs b/clippy_lints/src/methods/needless_character_iteration.rs index 20468784aae7a..aac4a344f5f99 100644 --- a/clippy_lints/src/methods/needless_character_iteration.rs +++ b/clippy_lints/src/methods/needless_character_iteration.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _}; use rustc_errors::Applicability; use rustc_hir::{Closure, Expr, ExprKind, HirId, StmtKind, UnOp}; use rustc_lint::LateContext; @@ -8,7 +8,7 @@ use rustc_span::Span; use super::NEEDLESS_CHARACTER_ITERATION; use super::utils::get_last_chain_binding_hir_id; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::{peel_blocks, sym}; fn peels_expr_ref<'a, 'tcx>(mut expr: &'a Expr<'tcx>) -> &'a Expr<'tcx> { diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index e5acaf383fa0d..068505861b64e 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -3,7 +3,7 @@ use std::ops::ControlFlow; use super::NEEDLESS_COLLECT; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; -use clippy_utils::res::{MaybeDef, MaybeResPath, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{has_non_owning_mutable_access, make_normalized_projection, make_projection}; diff --git a/clippy_lints/src/methods/needless_option_as_deref.rs b/clippy_lints/src/methods/needless_option_as_deref.rs index 7626cdb5a5fe8..b8e6a5f50d50b 100644 --- a/clippy_lints/src/methods/needless_option_as_deref.rs +++ b/clippy_lints/src/methods/needless_option_as_deref.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; -use clippy_utils::source::SpanExt; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; +use clippy_utils::source::SpanExt as _; use clippy_utils::sym; use clippy_utils::usage::local_used_after_expr; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/needless_option_take.rs b/clippy_lints/src/methods/needless_option_take.rs index 1622fdb88bd53..98cc7f4aeaf02 100644 --- a/clippy_lints/src/methods/needless_option_take.rs +++ b/clippy_lints/src/methods/needless_option_take.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/no_effect_replace.rs b/clippy_lints/src/methods/no_effect_replace.rs index 2afda2956beb6..667608cf992ef 100644 --- a/clippy_lints/src/methods/no_effect_replace.rs +++ b/clippy_lints/src/methods/no_effect_replace.rs @@ -1,6 +1,6 @@ use clippy_utils::SpanlessEq; use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_ast::LitKind; use rustc_hir::{ExprKind, LangItem}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/ok_expect.rs b/clippy_lints/src/methods/ok_expect.rs index 5f1cae130daed..4982506036ef6 100644 --- a/clippy_lints/src/methods/ok_expect.rs +++ b/clippy_lints/src/methods/ok_expect.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::has_debug_impl; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::{self, Ty}; use rustc_span::sym; diff --git a/clippy_lints/src/methods/open_options.rs b/clippy_lints/src/methods/open_options.rs index 3ce28e41e6b78..d4c52c56a1a80 100644 --- a/clippy_lints/src/methods/open_options.rs +++ b/clippy_lints/src/methods/open_options.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_data_structures::fx::FxHashMap; use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; diff --git a/clippy_lints/src/methods/option_as_ref_cloned.rs b/clippy_lints/src/methods/option_as_ref_cloned.rs index 156c624488eba..745c791e788d1 100644 --- a/clippy_lints/src/methods/option_as_ref_cloned.rs +++ b/clippy_lints/src/methods/option_as_ref_cloned.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/methods/option_as_ref_deref.rs b/clippy_lints/src/methods/option_as_ref_deref.rs index a52f3c1be26e9..31f294ff27d37 100644 --- a/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/clippy_lints/src/methods/option_as_ref_deref.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet; use clippy_utils::{peel_blocks, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/option_map_or_none.rs b/clippy_lints/src/methods/option_map_or_none.rs index 817388915f189..98c8e15756931 100644 --- a/clippy_lints/src/methods/option_map_or_none.rs +++ b/clippy_lints/src/methods/option_map_or_none.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_none_expr; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 6f9e817490c12..f4579f72e99cd 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -4,7 +4,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::eager_or_lazy::switch_to_lazy_eval; use clippy_utils::higher::VecArgs; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use clippy_utils::ty::{expr_type_is_certain, implements_trait}; use clippy_utils::visitors::for_each_expr; diff --git a/clippy_lints/src/methods/or_then_unwrap.rs b/clippy_lints/src/methods/or_then_unwrap.rs index 448ab621a7ce6..3be6e8b62ec99 100644 --- a/clippy_lints/src/methods/or_then_unwrap.rs +++ b/clippy_lints/src/methods/or_then_unwrap.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::lang_items::LangItem; diff --git a/clippy_lints/src/methods/path_buf_push_overwrite.rs b/clippy_lints/src/methods/path_buf_push_overwrite.rs index 923e4ea4dd975..14b26aee49bf2 100644 --- a/clippy_lints/src/methods/path_buf_push_overwrite.rs +++ b/clippy_lints/src/methods/path_buf_push_overwrite.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/path_ends_with_ext.rs b/clippy_lints/src/methods/path_ends_with_ext.rs index ffba244dcf61c..7e25c240e6d9b 100644 --- a/clippy_lints/src/methods/path_ends_with_ext.rs +++ b/clippy_lints/src/methods/path_ends_with_ext.rs @@ -1,7 +1,7 @@ use super::PATH_ENDS_WITH_EXT; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet; use clippy_utils::sym; use rustc_ast::{LitKind, StrStyle}; @@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; -use std::fmt::Write; +use std::fmt::Write as _; pub const DEFAULT_ALLOWED_DOTFILES: &[&str] = &[ "git", "svn", "gem", "npm", "vim", "env", "rnd", "ssh", "vnc", "smb", "nvm", "bin", diff --git a/clippy_lints/src/methods/ptr_offset_by_literal.rs b/clippy_lints/src/methods/ptr_offset_by_literal.rs index 25d7f05f9a10a..9b4617538ad4a 100644 --- a/clippy_lints/src/methods/ptr_offset_by_literal.rs +++ b/clippy_lints/src/methods/ptr_offset_by_literal.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::sym; use rustc_ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/range_zip_with_len.rs b/clippy_lints/src/methods/range_zip_with_len.rs index b01adbf4d58af..20220f83620ec 100644 --- a/clippy_lints/src/methods/range_zip_with_len.rs +++ b/clippy_lints/src/methods/range_zip_with_len.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::{SpanExt as _, snippet_with_applicability}; use clippy_utils::{SpanlessEq, get_parent_expr, higher, is_integer_literal, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/read_line_without_trim.rs b/clippy_lints/src/methods/read_line_without_trim.rs index a6dfbada53483..fd5764ba197c5 100644 --- a/clippy_lints/src/methods/read_line_without_trim.rs +++ b/clippy_lints/src/methods/read_line_without_trim.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet; use clippy_utils::visitors::for_each_local_use_after_expr; use clippy_utils::{get_parent_expr, sym}; diff --git a/clippy_lints/src/methods/readonly_write_lock.rs b/clippy_lints/src/methods/readonly_write_lock.rs index b89aa8dfb4db1..c3af145266483 100644 --- a/clippy_lints/src/methods/readonly_write_lock.rs +++ b/clippy_lints/src/methods/readonly_write_lock.rs @@ -1,7 +1,7 @@ use super::READONLY_WRITE_LOCK; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::mir::{enclosing_mir, visit_local_usage}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, Node, PatKind}; diff --git a/clippy_lints/src/methods/repeat_once.rs b/clippy_lints/src/methods/repeat_once.rs index 57a7254605f93..6fe19a932d545 100644 --- a/clippy_lints/src/methods/repeat_once.rs +++ b/clippy_lints/src/methods/repeat_once.rs @@ -1,6 +1,6 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::{Expr, LangItem}; diff --git a/clippy_lints/src/methods/result_map_or_else_none.rs b/clippy_lints/src/methods/result_map_or_else_none.rs index d5477b9be4c1e..7cf30bb4e9c08 100644 --- a/clippy_lints/src/methods/result_map_or_else_none.rs +++ b/clippy_lints/src/methods/result_map_or_else_none.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::source::snippet; use clippy_utils::{is_none_expr, peel_blocks}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/return_and_then.rs b/clippy_lints/src/methods/return_and_then.rs index 8f47306c89479..404ad551919f5 100644 --- a/clippy_lints/src/methods/return_and_then.rs +++ b/clippy_lints/src/methods/return_and_then.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_errors::Applicability; use rustc_hir::{self as hir, Node}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index 8732eba6d4e87..9e9d53cabbb0d 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::sugg::deref_closure_args; use clippy_utils::{is_receiver_of_method_call, strip_pat_refs, sym}; diff --git a/clippy_lints/src/methods/skip_while_next.rs b/clippy_lints/src/methods/skip_while_next.rs index 2452c499b9cee..2420d6de9540f 100644 --- a/clippy_lints/src/methods/skip_while_next.rs +++ b/clippy_lints/src/methods/skip_while_next.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::sym; diff --git a/clippy_lints/src/methods/sliced_string_as_bytes.rs b/clippy_lints/src/methods/sliced_string_as_bytes.rs index fb124f3605b94..f581384ca5415 100644 --- a/clippy_lints/src/methods/sliced_string_as_bytes.rs +++ b/clippy_lints/src/methods/sliced_string_as_bytes.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::higher; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem}; diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 13782a492cbc5..6d319dcd1e678 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -1,7 +1,7 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_context; use clippy_utils::usage::local_used_after_expr; use clippy_utils::visitors::{Descend, for_each_expr}; diff --git a/clippy_lints/src/methods/string_extend_chars.rs b/clippy_lints/src/methods/string_extend_chars.rs index 1fc0633f4f959..f531abed813ce 100644 --- a/clippy_lints/src/methods/string_extend_chars.rs +++ b/clippy_lints/src/methods/string_extend_chars.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{method_chain_args, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/string_lit_chars_any.rs b/clippy_lints/src/methods/string_lit_chars_any.rs index 53c695e378476..a438873c9ee6d 100644 --- a/clippy_lints/src/methods/string_lit_chars_any.rs +++ b/clippy_lints/src/methods/string_lit_chars_any.rs @@ -1,9 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeResPath, MaybeTypeckRes}; -use clippy_utils::source::SpanExt; -use itertools::Itertools; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _, MaybeTypeckRes as _}; +use clippy_utils::source::SpanExt as _; +use itertools::Itertools as _; use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, Param, PatKind}; diff --git a/clippy_lints/src/methods/suspicious_command_arg_space.rs b/clippy_lints/src/methods/suspicious_command_arg_space.rs index b4ea2e62b3c1f..185baf592f2e1 100644 --- a/clippy_lints/src/methods/suspicious_command_arg_space.rs +++ b/clippy_lints/src/methods/suspicious_command_arg_space.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_ast as ast; use rustc_errors::{Applicability, Diag}; diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs index ece97c1f758c0..35cd23c49ecef 100644 --- a/clippy_lints/src/methods/suspicious_map.rs +++ b/clippy_lints/src/methods/suspicious_map.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::expr_or_init; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::usage::mutated_variables; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/suspicious_to_owned.rs b/clippy_lints/src/methods/suspicious_to_owned.rs index 5d0fd6ca4c80f..c064e707404ca 100644 --- a/clippy_lints/src/methods/suspicious_to_owned.rs +++ b/clippy_lints/src/methods/suspicious_to_owned.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/unbuffered_bytes.rs b/clippy_lints/src/methods/unbuffered_bytes.rs index b86ba39d7b6c9..46d8c0771b68b 100644 --- a/clippy_lints/src/methods/unbuffered_bytes.rs +++ b/clippy_lints/src/methods/unbuffered_bytes.rs @@ -1,6 +1,6 @@ use super::UNBUFFERED_BYTES; use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::sym; use clippy_utils::ty::implements_trait; use rustc_hir as hir; diff --git a/clippy_lints/src/methods/uninit_assumed_init.rs b/clippy_lints/src/methods/uninit_assumed_init.rs index 5e247a50358e6..4c82c268405f3 100644 --- a/clippy_lints/src/methods/uninit_assumed_init.rs +++ b/clippy_lints/src/methods/uninit_assumed_init.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::ty::is_uninit_value_valid_for_ty; use rustc_hir as hir; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/unit_hash.rs b/clippy_lints/src/methods/unit_hash.rs index fb447a99abdce..57cfcc16c3695 100644 --- a/clippy_lints/src/methods/unit_hash.rs +++ b/clippy_lints/src/methods/unit_hash.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 54f3fe4105198..b93be0772c925 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -1,6 +1,6 @@ use super::utils::clone_or_copy_needed; use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::ty::{is_copy, option_arg_ty}; use clippy_utils::usage::mutated_variables; use clippy_utils::visitors::{Descend, for_each_expr_without_closures}; diff --git a/clippy_lints/src/methods/unnecessary_first_then_check.rs b/clippy_lints/src/methods/unnecessary_first_then_check.rs index 43dac249f7440..43421fd320680 100644 --- a/clippy_lints/src/methods/unnecessary_first_then_check.rs +++ b/clippy_lints/src/methods/unnecessary_first_then_check.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/methods/unnecessary_fold.rs b/clippy_lints/src/methods/unnecessary_fold.rs index 15337082c03a5..12f1e25ca117b 100644 --- a/clippy_lints/src/methods/unnecessary_fold.rs +++ b/clippy_lints/src/methods/unnecessary_fold.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_context; use clippy_utils::{DefinedTy, ExprUseNode, get_expr_use_site, peel_blocks, strip_pat_refs}; use rustc_ast::ast; diff --git a/clippy_lints/src/methods/unnecessary_get_then_check.rs b/clippy_lints/src/methods/unnecessary_get_then_check.rs index b622a219f35dc..f9d5e9cc6906a 100644 --- a/clippy_lints/src/methods/unnecessary_get_then_check.rs +++ b/clippy_lints/src/methods/unnecessary_get_then_check.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::SpanExt as _; use clippy_utils::sym; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/unnecessary_iter_cloned.rs b/clippy_lints/src/methods/unnecessary_iter_cloned.rs index 5b19c43f1b32f..841ff38b8e193 100644 --- a/clippy_lints/src/methods/unnecessary_iter_cloned.rs +++ b/clippy_lints/src/methods/unnecessary_iter_cloned.rs @@ -1,13 +1,13 @@ use super::utils::clone_or_copy_needed; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::higher::ForLoop; -use clippy_utils::res::MaybeResPath; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeResPath as _; +use clippy_utils::source::SpanExt as _; use clippy_utils::ty::{get_iterator_item_ty, implements_trait}; use clippy_utils::visitors::for_each_expr_without_closures; use clippy_utils::{can_mut_borrow_both, fn_def_id, get_parent_expr}; use core::ops::ControlFlow; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{BindingMode, Expr, ExprKind, Node, PatKind}; diff --git a/clippy_lints/src/methods/unnecessary_join.rs b/clippy_lints/src/methods/unnecessary_join.rs index 3290bdd778243..193406942f3f8 100644 --- a/clippy_lints/src/methods/unnecessary_join.rs +++ b/clippy_lints/src/methods/unnecessary_join.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem}; diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs index 0b3c8146b9f76..3a60548feeb25 100644 --- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs +++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::{eager_or_lazy, is_from_proc_macro, usage}; use hir::FnRetTy; diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs index fdd335c762013..ebba91a8a0296 100644 --- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs +++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::{is_none_expr, last_path_segment, sym}; use rustc_errors::Applicability; use rustc_hir::{self as hir, AmbigArg}; diff --git a/clippy_lints/src/methods/unnecessary_map_or.rs b/clippy_lints/src/methods/unnecessary_map_or.rs index b9af391843876..f8906bb23282d 100644 --- a/clippy_lints/src/methods/unnecessary_map_or.rs +++ b/clippy_lints/src/methods/unnecessary_map_or.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::eager_or_lazy::switch_to_eager_eval; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::sugg::{Sugg, make_binop}; use clippy_utils::ty::{implements_trait, is_copy}; use clippy_utils::visitors::is_local_used; diff --git a/clippy_lints/src/methods/unnecessary_map_or_else.rs b/clippy_lints/src/methods/unnecessary_map_or_else.rs index 7c1c31d2bd381..6ce11e6bba230 100644 --- a/clippy_lints/src/methods/unnecessary_map_or_else.rs +++ b/clippy_lints/src/methods/unnecessary_map_or_else.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_expr_identity_function; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::Expr; diff --git a/clippy_lints/src/methods/unnecessary_sort_by.rs b/clippy_lints/src/methods/unnecessary_sort_by.rs index 60bc4de69237a..48333cd2d85f3 100644 --- a/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::std_or_core; use clippy_utils::sugg::Sugg; diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs index 9c6f307cc6594..0cb68b936e98a 100644 --- a/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -2,8 +2,8 @@ use super::implicit_clone::is_clone_like; use super::unnecessary_iter_cloned::{self, is_into_iter}; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::{SpanExt, snippet, snippet_with_context}; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::{SpanExt as _, snippet, snippet_with_context}; use clippy_utils::ty::{get_iterator_item_ty, implements_trait, is_copy, peel_and_count_ty_refs}; use clippy_utils::visitors::find_all_ret_expressions; use clippy_utils::{fn_def_id, get_parent_expr, is_expr_temporary_value, return_ty, sym}; @@ -11,7 +11,7 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node}; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::TyCtxtInferExt as _; use rustc_lint::LateContext; use rustc_middle::mir::Mutability; use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind, OverloadedDeref}; diff --git a/clippy_lints/src/methods/unnecessary_unwrap_unchecked.rs b/clippy_lints/src/methods/unnecessary_unwrap_unchecked.rs index 0a13bffa733e2..34bd124001a81 100644 --- a/clippy_lints/src/methods/unnecessary_unwrap_unchecked.rs +++ b/clippy_lints/src/methods/unnecessary_unwrap_unchecked.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeQPath; +use clippy_utils::res::MaybeQPath as _; use clippy_utils::ty::{option_or_result_arg_ty, same_type_modulo_regions}; use clippy_utils::{is_from_proc_macro, last_path_segment, over}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/unwrap_expect_used.rs b/clippy_lints/src/methods/unwrap_expect_used.rs index ad7b0fc47cf3a..325d4f3c23318 100644 --- a/clippy_lints/src/methods/unwrap_expect_used.rs +++ b/clippy_lints/src/methods/unwrap_expect_used.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::ty::is_never_like; use clippy_utils::{is_in_test, is_inside_always_const_context, is_lint_allowed}; use rustc_hir::Expr; diff --git a/clippy_lints/src/methods/useless_asref.rs b/clippy_lints/src/methods/useless_asref.rs index 3737249a40cb0..2eac3ffba3246 100644 --- a/clippy_lints/src/methods/useless_asref.rs +++ b/clippy_lints/src/methods/useless_asref.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::{implements_trait, peel_and_count_ty_refs, should_call_clone_as_function}; use clippy_utils::{get_parent_expr, peel_blocks, strip_pat_refs}; @@ -8,7 +8,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{self as hir, LangItem, Node}; use rustc_lint::LateContext; use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; -use rustc_middle::ty::{Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor}; +use rustc_middle::ty::{Ty, TyCtxt, TypeSuperVisitable as _, TypeVisitable as _, TypeVisitor}; use rustc_span::{Span, Symbol, sym}; use core::ops::ControlFlow; diff --git a/clippy_lints/src/methods/useless_nonzero_new_unchecked.rs b/clippy_lints/src/methods/useless_nonzero_new_unchecked.rs index c6f54159c7a78..8054302c91be4 100644 --- a/clippy_lints/src/methods/useless_nonzero_new_unchecked.rs +++ b/clippy_lints/src/methods/useless_nonzero_new_unchecked.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::is_inside_always_const_context; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, Node, QPath, UnsafeSource}; diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index 33346d867ffee..9e7764fa19c80 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::{get_parent_expr, usage}; use rustc_hir::intravisit::{Visitor, walk_expr}; use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, Mutability, Pat, QPath, Stmt, StmtKind}; diff --git a/clippy_lints/src/methods/vec_resize_to_zero.rs b/clippy_lints/src/methods/vec_resize_to_zero.rs index eed2ebebc0281..f6e57c5d1fd5f 100644 --- a/clippy_lints/src/methods/vec_resize_to_zero.rs +++ b/clippy_lints/src/methods/vec_resize_to_zero.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_ast::LitKind; use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/verbose_file_reads.rs b/clippy_lints/src/methods/verbose_file_reads.rs index b67e084a35332..fa967337e9421 100644 --- a/clippy_lints/src/methods/verbose_file_reads.rs +++ b/clippy_lints/src/methods/verbose_file_reads.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::sym; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/methods/waker_clone_wake.rs b/clippy_lints/src/methods/waker_clone_wake.rs index bb26c2d935784..0506b4627c5a4 100644 --- a/clippy_lints/src/methods/waker_clone_wake.rs +++ b/clippy_lints/src/methods/waker_clone_wake.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sym; use rustc_errors::Applicability; diff --git a/clippy_lints/src/methods/wrong_self_convention.rs b/clippy_lints/src/methods/wrong_self_convention.rs index 439a1af93cadc..ade9509f1fa88 100644 --- a/clippy_lints/src/methods/wrong_self_convention.rs +++ b/clippy_lints/src/methods/wrong_self_convention.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::is_copy; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_lint::LateContext; use rustc_middle::ty::Ty; use rustc_span::{Span, Symbol}; diff --git a/clippy_lints/src/methods/zst_offset.rs b/clippy_lints/src/methods/zst_offset.rs index 941afb9e2a988..3efb267328984 100644 --- a/clippy_lints/src/methods/zst_offset.rs +++ b/clippy_lints/src/methods/zst_offset.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_middle::ty; diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index 74da699e3c006..97dabf4fb5a66 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -1,6 +1,6 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::sym; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 0bfb28d6b8bf4..6167fb0fa0c84 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -4,7 +4,7 @@ use clippy_utils::{SpanlessEq, fulfill_or_allowed, get_parent_expr, in_automatic use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{BinOpKind, Expr, ExprKind, QPath, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index 79e56b7de41f8..144200ef98705 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -10,7 +10,7 @@ mod zero_prefixed_literal; use clippy_utils::source::snippet_opt; use rustc_ast::ast::{Expr, ExprKind, Generics, LitFloatType, LitIntType, LitKind, Pat}; use rustc_ast::token; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/misc_early/redundant_at_rest_pattern.rs b/clippy_lints/src/misc_early/redundant_at_rest_pattern.rs index f2cf93465c0d7..69068e658024f 100644 --- a/clippy_lints/src/misc_early/redundant_at_rest_pattern.rs +++ b/clippy_lints/src/misc_early/redundant_at_rest_pattern.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use rustc_ast::{Pat, PatKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, LintContext}; +use rustc_lint::{EarlyContext, LintContext as _}; use super::REDUNDANT_AT_REST_PATTERN; diff --git a/clippy_lints/src/misc_early/unneeded_field_pattern.rs b/clippy_lints/src/misc_early/unneeded_field_pattern.rs index 5bc437cf24f4c..04f57feaf4907 100644 --- a/clippy_lints/src/misc_early/unneeded_field_pattern.rs +++ b/clippy_lints/src/misc_early/unneeded_field_pattern.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; -use clippy_utils::source::SpanExt; -use itertools::Itertools; +use clippy_utils::source::SpanExt as _; +use itertools::Itertools as _; use rustc_ast::ast::{Pat, PatKind}; use rustc_lint::EarlyContext; diff --git a/clippy_lints/src/missing_enforced_import_rename.rs b/clippy_lints/src/missing_enforced_import_rename.rs index 36a2a7f4b406c..c8e3226ea22e9 100644 --- a/clippy_lints/src/missing_enforced_import_rename.rs +++ b/clippy_lints/src/missing_enforced_import_rename.rs @@ -1,12 +1,12 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::paths::{PathNS, lookup_path_str}; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::def_id::DefIdMap; use rustc_hir::{Item, ItemKind, UseKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::TyCtxt; use rustc_session::impl_lint_pass; use rustc_span::Symbol; diff --git a/clippy_lints/src/missing_fields_in_debug.rs b/clippy_lints/src/missing_fields_in_debug.rs index 657da09f5ca2b..6497e3283b392 100644 --- a/clippy_lints/src/missing_fields_in_debug.rs +++ b/clippy_lints/src/missing_fields_in_debug.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::sym; use clippy_utils::visitors::{Visitable, for_each_expr}; use rustc_ast::LitKind; diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index 99561e60f725a..6cf3ce25a23b0 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; use clippy_utils::macros::root_macro_call_first_node; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::{get_parent_expr, sym}; use rustc_hir::intravisit::{Visitor, walk_expr}; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, LetStmt, Node, Stmt, StmtKind}; diff --git a/clippy_lints/src/module_style.rs b/clippy_lints/src/module_style.rs index 9058968866e52..27f48cbf789c7 100644 --- a/clippy_lints/src/module_style.rs +++ b/clippy_lints/src/module_style.rs @@ -2,7 +2,7 @@ use clippy_utils::ast_utils::is_cfg_test; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; use rustc_ast::ast::{self, Inline, ItemKind, ModKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::def_id::LOCAL_CRATE; use rustc_span::{FileName, Ident, SourceFile, Span, SyntaxContext, sym}; diff --git a/clippy_lints/src/multiple_bound_locations.rs b/clippy_lints/src/multiple_bound_locations.rs index a78f53188ba8b..2f0e404ad1a34 100644 --- a/clippy_lints/src/multiple_bound_locations.rs +++ b/clippy_lints/src/multiple_bound_locations.rs @@ -6,7 +6,7 @@ use rustc_session::declare_lint_pass; use rustc_span::Span; use clippy_utils::diagnostics::span_lint; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/mutex_atomic.rs b/clippy_lints/src/mutex_atomic.rs index 6d9950579fb24..fb9b60c25f78f 100644 --- a/clippy_lints/src/mutex_atomic.rs +++ b/clippy_lints/src/mutex_atomic.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::{IntoSpan, SpanExt}; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::{IntoSpan as _, SpanExt as _}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::ty_from_hir_ty; use rustc_errors::{Applicability, Diag}; use rustc_hir::{self as hir, Expr, ExprKind, Item, ItemKind, LetStmt, QPath}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::mir::Mutability; use rustc_middle::ty::{self, IntTy, Ty, UintTy}; use rustc_session::declare_lint_pass; diff --git a/clippy_lints/src/needless_borrows_for_generic_args.rs b/clippy_lints/src/needless_borrows_for_generic_args.rs index b82c6c171e37f..96b74c9f5cb4c 100644 --- a/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -10,7 +10,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{Body, Expr, ExprKind, Mutability, Path, QPath}; use rustc_index::bit_set::DenseBitSet; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::TyCtxtInferExt as _; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::{Rvalue, StatementKind}; use rustc_middle::ty::{ diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs index d1d0d31ed91a5..0cdde66c69ca6 100644 --- a/clippy_lints/src/needless_continue.rs +++ b/clippy_lints/src/needless_continue.rs @@ -4,7 +4,7 @@ use clippy_utils::source::{indent_of, snippet_block, snippet_with_context}; use rustc_ast::Label; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, ExprKind, HirId, LoopSource, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::{ExpnKind, Span}; diff --git a/clippy_lints/src/needless_else.rs b/clippy_lints/src/needless_else.rs index 299860ac1e037..69975618d3d8b 100644 --- a/clippy_lints/src/needless_else.rs +++ b/clippy_lints/src/needless_else.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::{IntoSpan, SpanExt}; +use clippy_utils::source::{IntoSpan as _, SpanExt as _}; use rustc_ast::ast::{Expr, ExprKind}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 55a5a16c00991..d20add9f57403 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -1,4 +1,4 @@ -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use rustc_errors::Applicability; use rustc_hir::intravisit::{Visitor, walk_expr}; use rustc_hir::{Block, BlockCheckMode, Closure, Expr, ExprKind, Stmt, StmtKind, TyKind}; diff --git a/clippy_lints/src/needless_ifs.rs b/clippy_lints/src/needless_ifs.rs index 48d15056f7291..b7dcd7a784f72 100644 --- a/clippy_lints/src/needless_ifs.rs +++ b/clippy_lints/src/needless_ifs.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::higher::If; use clippy_utils::is_from_proc_macro; -use clippy_utils::source::{SpanExt, walk_span_to_context}; +use clippy_utils::source::{SpanExt as _, walk_span_to_context}; use rustc_errors::Applicability; use rustc_hir::{ExprKind, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index 69184d1894025..874ff8410989c 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -1,6 +1,6 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::needs_ordered_drop; use clippy_utils::visitors::{for_each_expr, for_each_expr_without_closures, is_local_used}; diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 34d86c1b60248..b0e11baa745a5 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath}; -use clippy_utils::source::{SpanExt, snippet}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; +use clippy_utils::source::{SpanExt as _, snippet}; use clippy_utils::ty::{implements_trait, implements_trait_with_env_from_iter, is_copy}; use clippy_utils::visitors::{Descend, for_each_expr_without_closures}; use clippy_utils::{is_self, peel_hir_ty_options, strip_pat_refs, sym}; @@ -14,7 +14,7 @@ use rustc_hir::{ use rustc_hir_typeck::expr_use_visitor as euv; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt as _}; use rustc_session::declare_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index 29c45168b61e5..933700f5f9e18 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::res::MaybeQPath; +use clippy_utils::res::MaybeQPath as _; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Block, Body, Expr, ExprKind, LangItem, MatchSource}; diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index 4f62ba2e58db2..cfe9fd284e453 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::implements_trait; use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::sym; diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 7a3c304a3ad3f..31479a4d08df3 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -1,12 +1,12 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::return_ty; use clippy_utils::source::{indent_of, reindent_multiline, snippet_with_applicability}; -use clippy_utils::sugg::DiagExt; +use clippy_utils::sugg::DiagExt as _; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::attrs::AttributeKind; use rustc_hir::{Attribute, HirIdSet}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::AssocKind; use rustc_session::impl_lint_pass; use rustc_span::sym; diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index e471d42679fc5..d5a68b14b3377 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then}; -use clippy_utils::res::MaybeResPath; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeResPath as _; +use clippy_utils::source::SpanExt as _; use clippy_utils::ty::{expr_type_is_certain, has_drop}; use clippy_utils::{in_automatically_derived, is_inside_always_const_context, is_lint_allowed, peel_blocks}; use rustc_errors::Applicability; @@ -9,7 +9,7 @@ use rustc_hir::{ BinOpKind, BlockCheckMode, Expr, ExprKind, HirId, HirIdMap, ItemKind, LocalSource, Node, PatKind, Stmt, StmtKind, StructTailExpr, UnsafeSource, is_range_literal, }; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; use std::ops::Deref; diff --git a/clippy_lints/src/no_mangle_with_rust_abi.rs b/clippy_lints/src/no_mangle_with_rust_abi.rs index 760a5a920542b..e03ea557b84f9 100644 --- a/clippy_lints/src/no_mangle_with_rust_abi.rs +++ b/clippy_lints/src/no_mangle_with_rust_abi.rs @@ -6,7 +6,7 @@ use rustc_hir::attrs::AttributeKind; use rustc_hir::{Attribute, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; -use rustc_span::{BytePos, Pos}; +use rustc_span::{BytePos, Pos as _}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/non_canonical_impls.rs b/clippy_lints/src/non_canonical_impls.rs index 4729270d6a92d..60408adc31b62 100644 --- a/clippy_lints/src/non_canonical_impls.rs +++ b/clippy_lints/src/non_canonical_impls.rs @@ -1,12 +1,12 @@ use super::implicit_return::IMPLICIT_RETURN; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::ty::implements_trait; use clippy_utils::{is_from_proc_macro, is_lint_allowed, last_path_segment, std_or_core}; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{Block, Body, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, LangItem, Stmt, StmtKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::{TyCtxt, TypeckResults}; use rustc_session::impl_lint_pass; use rustc_span::sym; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index daff99aa3cb33..a15a52bdd4e9b 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -31,12 +31,12 @@ use rustc_hir::{ ConstArgKind, ConstItemRhs, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, Node, StructTailExpr, TraitItem, TraitItemKind, UnOp, }; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::mir::{ConstValue, UnevaluatedConst}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind}; use rustc_middle::ty::{ - self, EarlyBinder, GenericArgs, GenericArgsRef, Instance, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeckResults, - TypingEnv, Unnormalized, + self, EarlyBinder, GenericArgs, GenericArgsRef, Instance, Ty, TyCtxt, TypeFolder, TypeSuperFoldable as _, + TypeckResults, TypingEnv, Unnormalized, }; use rustc_session::impl_lint_pass; use rustc_span::DUMMY_SP; diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 21ddefb249ca7..bbaf4c5c07af0 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -4,7 +4,7 @@ use rustc_ast::ast::{ self, Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, Pat, PatKind, }; use rustc_ast::visit::{Visitor, walk_block, walk_expr, walk_pat}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::{Span, sym}; diff --git a/clippy_lints/src/non_octal_unix_permissions.rs b/clippy_lints/src/non_octal_unix_permissions.rs index cf19cd9fc81d5..f726a7bc9ef60 100644 --- a/clippy_lints/src/non_octal_unix_permissions.rs +++ b/clippy_lints/src/non_octal_unix_permissions.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::{SpanExt, snippet_with_applicability}; +use clippy_utils::source::{SpanExt as _, snippet_with_applicability}; use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/non_std_lazy_statics.rs b/clippy_lints/src/non_std_lazy_statics.rs index 2755e3add760e..745e31cb7e7ac 100644 --- a/clippy_lints/src/non_std_lazy_statics.rs +++ b/clippy_lints/src/non_std_lazy_statics.rs @@ -2,7 +2,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::{span_lint, span_lint_hir_and_then}; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::paths::{self, PathNS, find_crates, lookup_path_str}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::visitors::for_each_expr; use clippy_utils::{fn_def_id, is_no_std_crate, sym}; use rustc_data_structures::fx::FxIndexMap; @@ -10,7 +10,7 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::{self as hir, BodyId, Expr, ExprKind, HirId, Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/nonstandard_macro_braces.rs b/clippy_lints/src/nonstandard_macro_braces.rs index 149a24871e517..1052f13cd3b04 100644 --- a/clippy_lints/src/nonstandard_macro_braces.rs +++ b/clippy_lints/src/nonstandard_macro_braces.rs @@ -10,7 +10,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::impl_lint_pass; use rustc_span::Span; -use crate::rustc_lint::LintContext; +use crate::rustc_lint::LintContext as _; use clippy_utils::source::snippet_opt; declare_clippy_lint! { diff --git a/clippy_lints/src/octal_escapes.rs b/clippy_lints/src/octal_escapes.rs index 5735c23a62ac8..a7c22dbefd060 100644 --- a/clippy_lints/src/octal_escapes.rs +++ b/clippy_lints/src/octal_escapes.rs @@ -1,11 +1,11 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_ast::token::LitKind; use rustc_ast::{Expr, ExprKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::declare_lint_pass; -use rustc_span::{BytePos, Pos, SpanData}; +use rustc_span::{BytePos, Pos as _, SpanData}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/only_used_in_recursion.rs b/clippy_lints/src/only_used_in_recursion.rs index 2bb5615cfb767..77c21531d5689 100644 --- a/clippy_lints/src/only_used_in_recursion.rs +++ b/clippy_lints/src/only_used_in_recursion.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::get_expr_use_or_unification_node; -use clippy_utils::res::{MaybeQPath, MaybeResPath}; +use clippy_utils::res::{MaybeQPath as _, MaybeResPath as _}; use core::cell::Cell; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; diff --git a/clippy_lints/src/operators/arithmetic_side_effects.rs b/clippy_lints/src/operators/arithmetic_side_effects.rs index 6891ecb0cf9d8..ec2cf8c0df06f 100644 --- a/clippy_lints/src/operators/arithmetic_side_effects.rs +++ b/clippy_lints/src/operators/arithmetic_side_effects.rs @@ -3,7 +3,7 @@ use crate::clippy_utils::res::MaybeQPath as _; use clippy_config::Conf; use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::{expr_or_init, is_from_proc_macro, is_lint_allowed, peel_hir_expr_refs, peel_hir_expr_unary, sym}; use rustc_ast as ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index fa391fad589fe..6a4c56296cc5a 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::Msrv; use clippy_utils::qualify_min_const_fn::is_stable_const_fn; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::ty::implements_trait; use clippy_utils::visitors::for_each_expr_without_closures; use clippy_utils::{binop_traits, eq_expr_value, is_in_const_context, trait_ref_of_method}; diff --git a/clippy_lints/src/operators/cmp_owned.rs b/clippy_lints/src/operators/cmp_owned.rs index fa1ce43d53b42..968f6ad679b59 100644 --- a/clippy_lints/src/operators/cmp_owned.rs +++ b/clippy_lints/src/operators/cmp_owned.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeQPath; +use clippy_utils::res::MaybeQPath as _; use clippy_utils::source::snippet_with_context; use clippy_utils::sym; use clippy_utils::ty::{implements_trait, is_copy}; diff --git a/clippy_lints/src/operators/const_comparisons.rs b/clippy_lints/src/operators/const_comparisons.rs index 85128f9114e6b..2d01bccc0fa64 100644 --- a/clippy_lints/src/operators/const_comparisons.rs +++ b/clippy_lints/src/operators/const_comparisons.rs @@ -5,7 +5,7 @@ use std::cmp::Ordering; use clippy_utils::consts::{ConstEvalCtxt, Constant}; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_middle::ty::layout::HasTyCtxt; +use rustc_middle::ty::layout::HasTyCtxt as _; use rustc_middle::ty::{Ty, TypeckResults}; use rustc_span::{Span, Spanned}; diff --git a/clippy_lints/src/operators/decimal_bitwise_operands.rs b/clippy_lints/src/operators/decimal_bitwise_operands.rs index 08e56e4516c52..c35f18d7a610e 100644 --- a/clippy_lints/src/operators/decimal_bitwise_operands.rs +++ b/clippy_lints/src/operators/decimal_bitwise_operands.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::numeric_literal; use clippy_utils::numeric_literal::NumericLiteral; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_ast::LitKind; use rustc_data_structures::packed::Pu128; use rustc_hir::{BinOpKind, Expr, ExprKind}; diff --git a/clippy_lints/src/operators/duration_subsec.rs b/clippy_lints/src/operators/duration_subsec.rs index 4a1da7e07a888..a6329b02868c0 100644 --- a/clippy_lints/src/operators/duration_subsec.rs +++ b/clippy_lints/src/operators/duration_subsec.rs @@ -1,6 +1,6 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sym; use rustc_errors::Applicability; diff --git a/clippy_lints/src/operators/integer_division.rs b/clippy_lints/src/operators/integer_division.rs index 1620312474e99..f6c9276c16d02 100644 --- a/clippy_lints/src/operators/integer_division.rs +++ b/clippy_lints/src/operators/integer_division.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::symbol::sym; diff --git a/clippy_lints/src/operators/invalid_upcast_comparisons.rs b/clippy_lints/src/operators/invalid_upcast_comparisons.rs index b32848a323375..ce37e415413e1 100644 --- a/clippy_lints/src/operators/invalid_upcast_comparisons.rs +++ b/clippy_lints/src/operators/invalid_upcast_comparisons.rs @@ -1,7 +1,7 @@ use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::LateContext; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{self, IntTy, UintTy}; use rustc_span::Span; diff --git a/clippy_lints/src/operators/manual_div_ceil.rs b/clippy_lints/src/operators/manual_div_ceil.rs index 57f5a046cb061..2e5900948301c 100644 --- a/clippy_lints/src/operators/manual_div_ceil.rs +++ b/clippy_lints/src/operators/manual_div_ceil.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::sugg::{Sugg, has_enclosing_paren}; use clippy_utils::{SpanlessEq, sym}; use rustc_ast::{BinOpKind, LitIntType, LitKind, UnOp}; diff --git a/clippy_lints/src/operators/manual_isolate_lowest_one.rs b/clippy_lints/src/operators/manual_isolate_lowest_one.rs index f62514ce99a63..0a706bd166ff2 100644 --- a/clippy_lints/src/operators/manual_isolate_lowest_one.rs +++ b/clippy_lints/src/operators/manual_isolate_lowest_one.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::sugg::Sugg; use clippy_utils::sym; use rustc_ast::BinOpKind; diff --git a/clippy_lints/src/operators/misrefactored_assign_op.rs b/clippy_lints/src/operators/misrefactored_assign_op.rs index 8a2cdf430927b..105c012a7cc8f 100644 --- a/clippy_lints/src/operators/misrefactored_assign_op.rs +++ b/clippy_lints/src/operators/misrefactored_assign_op.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::{eq_expr_value, sugg}; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 85cf483fce90d..2be50f811e88f 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sugg::Sugg; use clippy_utils::ty::is_copy; use clippy_utils::{ diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index fa7a5d8feb380..08c316af42b00 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::{is_panic, root_macro_call_first_node}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::visitors::{Descend, for_each_expr}; use clippy_utils::{is_inside_always_const_context, return_ty}; use core::ops::ControlFlow; diff --git a/clippy_lints/src/partialeq_to_none.rs b/clippy_lints/src/partialeq_to_none.rs index 72d2fdeda21c9..7f940d39f1610 100644 --- a/clippy_lints/src/partialeq_to_none.rs +++ b/clippy_lints/src/partialeq_to_none.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::{peel_hir_expr_refs, peel_ref_operators, sugg}; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind, LangItem}; diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 039da4cc4757a..0bfee9af5324b 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -14,7 +14,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{BindingMode, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, Node, PatKind, find_attr}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, PointerCoercion}; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{self, BoundVarIndexKind, RegionKind, TyCtxt}; use rustc_session::impl_lint_pass; use rustc_span::def_id::LocalDefId; diff --git a/clippy_lints/src/pathbuf_init_then_push.rs b/clippy_lints/src/pathbuf_init_then_push.rs index 473718c5419f1..4b8a3a5ef554f 100644 --- a/clippy_lints/src/pathbuf_init_then_push.rs +++ b/clippy_lints/src/pathbuf_init_then_push.rs @@ -1,12 +1,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; -use clippy_utils::source::{SpanExt, snippet}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; +use clippy_utils::source::{SpanExt as _, snippet}; use clippy_utils::sym; use rustc_ast::{LitKind, StrStyle}; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind, TyKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::{Span, Symbol}; diff --git a/clippy_lints/src/pattern_type_mismatch.rs b/clippy_lints/src/pattern_type_mismatch.rs index 4197680dd0472..e328de609e8cf 100644 --- a/clippy_lints/src/pattern_type_mismatch.rs +++ b/clippy_lints/src/pattern_type_mismatch.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_hir::{ Body, Expr, ExprKind, FnDecl, LetExpr, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind, intravisit, }; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty; use rustc_session::declare_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/permissions_set_readonly_false.rs b/clippy_lints/src/permissions_set_readonly_false.rs index a888ee5462949..00e6df84a51d3 100644 --- a/clippy_lints/src/permissions_set_readonly_false.rs +++ b/clippy_lints/src/permissions_set_readonly_false.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_ast::ast::LitKind; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/ptr/cmp_null.rs b/clippy_lints/src/ptr/cmp_null.rs index 5e1c62316b7d3..903b560022a3f 100644 --- a/clippy_lints/src/ptr/cmp_null.rs +++ b/clippy_lints/src/ptr/cmp_null.rs @@ -1,6 +1,6 @@ use super::CMP_NULL; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::sugg::Sugg; use clippy_utils::{is_lint_allowed, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/ptr/ptr_arg.rs b/clippy_lints/src/ptr/ptr_arg.rs index 200ab8f8418f1..39ae879143081 100644 --- a/clippy_lints/src/ptr/ptr_arg.rs +++ b/clippy_lints/src/ptr/ptr_arg.rs @@ -1,7 +1,7 @@ use super::PTR_ARG; use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::res::MaybeResPath; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeResPath as _; +use clippy_utils::source::SpanExt as _; use clippy_utils::{VEC_METHODS_SHADOWING_SLICE_METHODS, get_expr_use_or_unification_node, is_lint_allowed, sym}; use hir::LifetimeKind; use rustc_abi::ExternAbi; @@ -12,7 +12,7 @@ use rustc_hir::{ self as hir, AnonConst, BindingMode, Body, Expr, ExprKind, FnSig, GenericArg, Lifetime, Mutability, Node, OwnerId, Param, PatKind, QPath, TyKind, }; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::TyCtxtInferExt as _; use rustc_infer::traits::{Obligation, ObligationCause}; use rustc_lint::LateContext; use rustc_middle::hir::nested_filter; @@ -137,7 +137,7 @@ struct RefPrefix { } impl fmt::Display for RefPrefix { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use fmt::Write; + use fmt::Write as _; f.write_char('&')?; if !self.lt.is_anonymous() { self.lt.ident.fmt(f)?; @@ -150,7 +150,7 @@ impl fmt::Display for RefPrefix { struct DerefTyDisplay<'a, 'tcx>(&'a LateContext<'tcx>, &'a DerefTy<'tcx>); impl fmt::Display for DerefTyDisplay<'_, '_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use std::fmt::Write; + use std::fmt::Write as _; match self.1 { DerefTy::Str => f.write_str("str"), DerefTy::Path => f.write_str("Path"), diff --git a/clippy_lints/src/pub_underscore_fields.rs b/clippy_lints/src/pub_underscore_fields.rs index 92d1bf505bfaf..f5a52187540d1 100644 --- a/clippy_lints/src/pub_underscore_fields.rs +++ b/clippy_lints/src/pub_underscore_fields.rs @@ -2,7 +2,7 @@ use clippy_config::Conf; use clippy_config::types::PubUnderscoreFieldsBehaviour; use clippy_utils::attrs::is_doc_hidden; use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::sym::PhantomPinned; use rustc_hir::{FieldDef, Item, ItemKind, LangItem}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 7f95adba870d7..1c6189e8a205e 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -4,7 +4,7 @@ use clippy_config::Conf; use clippy_config::types::MatchLintBehaviour; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _}; use clippy_utils::source::{indent_of, reindent_multiline, snippet_with_applicability, snippet_with_context}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::{implements_trait, is_copy}; diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 162df76baf851..d3b3a394f3844 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -2,8 +2,8 @@ use clippy_config::Conf; use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; -use clippy_utils::source::{SpanExt, snippet, snippet_with_applicability}; +use clippy_utils::res::MaybeResPath as _; +use clippy_utils::source::{SpanExt as _, snippet, snippet_with_applicability}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::implements_trait; use clippy_utils::{ diff --git a/clippy_lints/src/raw_strings.rs b/clippy_lints/src/raw_strings.rs index 31c90c591b7c2..889dcc1fbc777 100644 --- a/clippy_lints/src/raw_strings.rs +++ b/clippy_lints/src/raw_strings.rs @@ -1,12 +1,12 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{SpanExt, snippet_opt}; +use clippy_utils::source::{SpanExt as _, snippet_opt}; use rustc_ast::ast::{Expr, ExprKind}; use rustc_ast::token::LitKind; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; -use rustc_span::{BytePos, Pos, Span}; +use rustc_span::{BytePos, Pos as _, Span}; use std::iter::once; use std::ops::ControlFlow; diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index db3be9e64f147..f877f12c72462 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then}; use clippy_utils::mir::{LocalUsage, PossibleBorrowerMap, visit_local_usage}; -use clippy_utils::res::MaybeDef; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeDef as _; +use clippy_utils::source::SpanExt as _; use clippy_utils::ty::{has_drop, is_copy, peel_and_count_ty_refs}; use clippy_utils::{fn_has_unsatisfiable_preds, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index b8ede29802fd1..49d09c0e7c666 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -4,11 +4,11 @@ use clippy_utils::sugg::Sugg; use hir::Param; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor}; +use rustc_hir::intravisit::Visitor; use rustc_hir::{ CaptureBy, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, ExprKind, intravisit as hir_visit, }; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::hir::nested_filter; use rustc_middle::ty; use rustc_session::declare_lint_pass; diff --git a/clippy_lints/src/redundant_else.rs b/clippy_lints/src/redundant_else.rs index 148290b4faec4..cb7d7cfafa2d5 100644 --- a/clippy_lints/src/redundant_else.rs +++ b/clippy_lints/src/redundant_else.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::is_from_proc_macro; -use clippy_utils::source::{SpanExt, indent_of, reindent_multiline}; +use clippy_utils::source::{SpanExt as _, indent_of, reindent_multiline}; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, ExprKind, MatchSource, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index 10793ccca97fd..b6edef91f8ded 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, MsrvStack}; use rustc_ast::ast::{Expr, ExprKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index 13bd05511ec33..93f583f36e2ef 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -5,7 +5,7 @@ use rustc_ast::Mutability; use rustc_hir::def::Res; use rustc_hir::{BindingMode, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath}; use rustc_hir_typeck::expr_use_visitor::PlaceBase; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::UpvarCapture; use rustc_session::declare_lint_pass; use rustc_span::DesugaringKind; diff --git a/clippy_lints/src/redundant_slicing.rs b/clippy_lints/src/redundant_slicing.rs index dbad96fa9be49..f0a0e4220444f 100644 --- a/clippy_lints/src/redundant_slicing.rs +++ b/clippy_lints/src/redundant_slicing.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::get_parent_expr; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use clippy_utils::ty::peel_and_count_ty_refs; use rustc_ast::util::parser::ExprPrecedence; diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 837c29c08851b..9f929bb6d2b56 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -4,8 +4,8 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use clippy_utils::paths; use clippy_utils::paths::PathLookup; -use clippy_utils::res::MaybeQPath; -use clippy_utils::source::SpanExt; +use clippy_utils::res::MaybeQPath as _; +use clippy_utils::source::SpanExt as _; use rustc_ast::ast::{LitKind, StrStyle}; use rustc_hir::def_id::DefIdMap; use rustc_hir::{BorrowKind, Expr, ExprKind, OwnerId}; diff --git a/clippy_lints/src/replace_box.rs b/clippy_lints/src/replace_box.rs index 7b743746df2c1..95f2f8da2c647 100644 --- a/clippy_lints/src/replace_box.rs +++ b/clippy_lints/src/replace_box.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::implements_trait; use clippy_utils::{is_default_equivalent_call, local_is_initialized}; diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index b5503f6cdfb03..475b350047e78 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -1,12 +1,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::higher::{VecInitKind, get_vec_init_kind}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet; use clippy_utils::{is_from_proc_macro, sym}; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/return_self_not_must_use.rs b/clippy_lints/src/return_self_not_must_use.rs index 8c892b7085b7c..beba2e2a6b4c5 100644 --- a/clippy_lints/src/return_self_not_must_use.rs +++ b/clippy_lints/src/return_self_not_must_use.rs @@ -4,7 +4,7 @@ use clippy_utils::{nth_arg, return_ty}; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, OwnerId, TraitItem, TraitItemKind, find_attr}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/returns/let_and_return.rs b/clippy_lints/src/returns/let_and_return.rs index c1a909fdde4e1..1041dadaf4d10 100644 --- a/clippy_lints/src/returns/let_and_return.rs +++ b/clippy_lints/src/returns/let_and_return.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet_with_context; use clippy_utils::sugg::has_enclosing_paren; use clippy_utils::visitors::for_each_expr; @@ -7,7 +7,7 @@ use clippy_utils::{binary_expr_needs_parentheses, fn_def_id, span_contains_non_w use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, PatKind, StmtKind}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::GenericArgKind; use rustc_span::edition::Edition; diff --git a/clippy_lints/src/returns/needless_return.rs b/clippy_lints/src/returns/needless_return.rs index f3d6324e1885e..ad81b5efcfe13 100644 --- a/clippy_lints/src/returns/needless_return.rs +++ b/clippy_lints/src/returns/needless_return.rs @@ -8,9 +8,9 @@ use rustc_ast::MetaItemInner; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Expr, ExprKind, HirId, LangItem, MatchSource, StmtKind}; -use rustc_lint::{LateContext, Level, LintContext}; +use rustc_lint::{LateContext, Level, LintContext as _}; use rustc_middle::ty::{self, Ty}; -use rustc_span::{BytePos, Pos, Span}; +use rustc_span::{BytePos, Pos as _, Span}; use std::borrow::Cow; use std::fmt::Display; diff --git a/clippy_lints/src/returns/needless_return_with_question_mark.rs b/clippy_lints/src/returns/needless_return_with_question_mark.rs index e37ea9800ed0e..b74ee266c1a82 100644 --- a/clippy_lints/src/returns/needless_return_with_question_mark.rs +++ b/clippy_lints/src/returns/needless_return_with_question_mark.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::{is_from_proc_macro, is_inside_let_else}; use rustc_errors::Applicability; use rustc_hir::LangItem::ResultErr; use rustc_hir::{Expr, ExprKind, HirId, MatchSource, Node, Stmt, StmtKind}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::adjustment::Adjust; use super::NEEDLESS_RETURN_WITH_QUESTION_MARK; diff --git a/clippy_lints/src/same_length_and_capacity.rs b/clippy_lints/src/same_length_and_capacity.rs index 1d5d960665ef6..fcd23619f9ed2 100644 --- a/clippy_lints/src/same_length_and_capacity.rs +++ b/clippy_lints/src/same_length_and_capacity.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::{eq_expr_value, sym}; use rustc_hir::{Expr, ExprKind, LangItem, QPath}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/semicolon_block.rs b/clippy_lints/src/semicolon_block.rs index 7fdc03891a889..583585282ac9e 100644 --- a/clippy_lints/src/semicolon_block.rs +++ b/clippy_lints/src/semicolon_block.rs @@ -1,9 +1,9 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, ExprKind, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/semicolon_if_nothing_returned.rs b/clippy_lints/src/semicolon_if_nothing_returned.rs index 63237c655ef17..5a3a1191c63d8 100644 --- a/clippy_lints/src/semicolon_if_nothing_returned.rs +++ b/clippy_lints/src/semicolon_if_nothing_returned.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_context; use rustc_errors::Applicability; use rustc_hir::{Block, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::{ExpnKind, MacroKind, Span}; diff --git a/clippy_lints/src/set_contains_or_insert.rs b/clippy_lints/src/set_contains_or_insert.rs index 03acfb22c6c82..e3057e72f9ea7 100644 --- a/clippy_lints/src/set_contains_or_insert.rs +++ b/clippy_lints/src/set_contains_or_insert.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::visitors::for_each_expr; use clippy_utils::{SpanlessEq, higher, peel_hir_expr_while, sym}; use rustc_hir::{Expr, ExprKind, UnOp}; diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 5072e39afb8c1..f7ae2ce673f88 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet; use clippy_utils::visitors::{Descend, Visitable, for_each_expr}; use rustc_data_structures::fx::FxHashMap; diff --git a/clippy_lints/src/significant_drop_tightening.rs b/clippy_lints/src/significant_drop_tightening.rs index 86b3387ae643f..0e762a795c7b0 100644 --- a/clippy_lints/src/significant_drop_tightening.rs +++ b/clippy_lints/src/significant_drop_tightening.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::{indent_of, snippet}; use clippy_utils::{expr_or_init, get_builtin_attr, peel_hir_expr_unary, sym}; use rustc_ast::BindingMode; diff --git a/clippy_lints/src/single_call_fn.rs b/clippy_lints/src/single_call_fn.rs index 4adcc1cac1237..8f0fed4d7d27c 100644 --- a/clippy_lints/src/single_call_fn.rs +++ b/clippy_lints/src/single_call_fn.rs @@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxIndexMap, IndexEntry}; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::{Expr, ExprKind, HirId, Node}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/single_char_lifetime_names.rs b/clippy_lints/src/single_char_lifetime_names.rs index 595c75acf031f..d38da79ed2e36 100644 --- a/clippy_lints/src/single_char_lifetime_names.rs +++ b/clippy_lints/src/single_char_lifetime_names.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast::ast::{GenericParam, GenericParamKind}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index 67c8710b80ec8..c1365d299ed2a 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -3,7 +3,7 @@ use rustc_ast::node_id::{NodeId, NodeMap}; use rustc_ast::visit::{Visitor, walk_expr}; use rustc_ast::{Crate, Expr, ExprKind, Item, ItemKind, MacroDef, ModKind, Ty, TyKind, UseTreeKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::edition::Edition; use rustc_span::symbol::kw; diff --git a/clippy_lints/src/single_option_map.rs b/clippy_lints/src/single_option_map.rs index 4556d287711fe..ba9a8368621f6 100644 --- a/clippy_lints/src/single_option_map.rs +++ b/clippy_lints/src/single_option_map.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::peel_blocks; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use rustc_hir::def::Res; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::FnKind; diff --git a/clippy_lints/src/single_range_in_vec_init.rs b/clippy_lints/src/single_range_in_vec_init.rs index e922f72330b3e..1de96df06baf8 100644 --- a/clippy_lints/src/single_range_in_vec_init.rs +++ b/clippy_lints/src/single_range_in_vec_init.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::higher::{Range, VecArgs}; use clippy_utils::macros::root_macro_call_first_node; -use clippy_utils::source::{SpanExt, snippet_with_context}; +use clippy_utils::source::{SpanExt as _, snippet_with_context}; use clippy_utils::ty::implements_trait; use clippy_utils::{is_no_std_crate, sym}; use rustc_ast::{LitIntType, LitKind, RangeLimits, UintTy}; diff --git a/clippy_lints/src/size_of_ref.rs b/clippy_lints/src/size_of_ref.rs index 0e78cf277c643..20ac318470568 100644 --- a/clippy_lints/src/size_of_ref.rs +++ b/clippy_lints/src/size_of_ref.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::sym; use clippy_utils::ty::peel_and_count_ty_refs; use rustc_hir::{Expr, ExprKind}; diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index ce74a9bea57f7..445c39fa57275 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::macros::matching_root_macro_call; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _}; use clippy_utils::sugg::Sugg; use clippy_utils::{SpanlessEq, get_enclosing_block, is_integer_literal, span_contains_comment, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/std_instead_of_core.rs b/clippy_lints/src/std_instead_of_core.rs index 0f7cbd503bcd8..5b9545e0fe4bc 100644 --- a/clippy_lints/src/std_instead_of_core.rs +++ b/clippy_lints/src/std_instead_of_core.rs @@ -6,7 +6,7 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{Block, Body, HirId, Path, PathSegment, StabilityLevel, StableSince}; -use rustc_lint::{LateContext, LateLintPass, Lint, LintContext}; +use rustc_lint::{LateContext, LateLintPass, Lint, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::symbol::kw; use rustc_span::{Span, sym}; diff --git a/clippy_lints/src/string_patterns.rs b/clippy_lints/src/string_patterns.rs index 986429ec0829e..efa61b3ad9630 100644 --- a/clippy_lints/src/string_patterns.rs +++ b/clippy_lints/src/string_patterns.rs @@ -5,11 +5,11 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::eager_or_lazy::switch_to_eager_eval; use clippy_utils::macros::matching_root_macro_call; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::{snippet, str_literal_to_char_literal}; use clippy_utils::sym; use clippy_utils::visitors::{Descend, for_each_expr}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_ast::{BinOpKind, LitKind}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, PatExprKind, PatKind}; diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 2128ffb6d7d60..6cbbcc681f944 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -1,12 +1,12 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_context}; use clippy_utils::{SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, method_calls, sym}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, LangItem, Node}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty; use rustc_session::declare_lint_pass; diff --git a/clippy_lints/src/strlen_on_c_strings.rs b/clippy_lints/src/strlen_on_c_strings.rs index 0320f76f8772a..4c1e14a3b104a 100644 --- a/clippy_lints/src/strlen_on_c_strings.rs +++ b/clippy_lints/src/strlen_on_c_strings.rs @@ -1,7 +1,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use clippy_utils::visitors::is_expr_unsafe; use clippy_utils::{match_libc_symbol, sym}; diff --git a/clippy_lints/src/suspicious_xor_used_as_pow.rs b/clippy_lints/src/suspicious_xor_used_as_pow.rs index e3d96245289ad..7ef7b1bc1d234 100644 --- a/clippy_lints/src/suspicious_xor_used_as_pow.rs +++ b/clippy_lints/src/suspicious_xor_used_as_pow.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 871c59d52659e..7abf789089852 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -1,17 +1,17 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::{snippet_indent, snippet_with_context}; use clippy_utils::sugg::Sugg; use clippy_utils::{can_mut_borrow_both, eq_expr_value, is_in_const_context, std_or_core, sym}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_data_structures::fx::FxIndexSet; use rustc_hir::intravisit::{Visitor, walk_expr}; use rustc_errors::Applicability; use rustc_hir::{AssignOpKind, Block, Expr, ExprKind, LetStmt, PatKind, QPath, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty; use rustc_session::declare_lint_pass; use rustc_span::symbol::Ident; diff --git a/clippy_lints/src/swap_ptr_to_ref.rs b/clippy_lints/src/swap_ptr_to_ref.rs index 4d7bb2cc1f988..e1b5e57432a76 100644 --- a/clippy_lints/src/swap_ptr_to_ref.rs +++ b/clippy_lints/src/swap_ptr_to_ref.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet_with_context; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, UnOp}; diff --git a/clippy_lints/src/time_subtraction.rs b/clippy_lints/src/time_subtraction.rs index e906ee081346f..61b488e7b2d13 100644 --- a/clippy_lints/src/time_subtraction.rs +++ b/clippy_lints/src/time_subtraction.rs @@ -4,7 +4,7 @@ use clippy_config::Conf; use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::sugg::Sugg; use clippy_utils::sym; use rustc_errors::Applicability; diff --git a/clippy_lints/src/to_digit_is_some.rs b/clippy_lints/src/to_digit_is_some.rs index 71c4172c98528..7a627edbe8049 100644 --- a/clippy_lints/src/to_digit_is_some.rs +++ b/clippy_lints/src/to_digit_is_some.rs @@ -1,7 +1,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_in_const_context, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 16cf0ecbc0bc7..db9525bc6a439 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -1,10 +1,10 @@ use clippy_config::Conf; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::source::{SpanExt, snippet, snippet_with_applicability}; +use clippy_utils::source::{SpanExt as _, snippet, snippet_with_applicability}; use clippy_utils::{SpanlessEq, SpanlessHash, is_from_proc_macro}; use core::hash::{Hash, Hasher}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, IndexEntry}; use rustc_data_structures::unhash::UnhashMap; use rustc_errors::Applicability; diff --git a/clippy_lints/src/transmute/transmute_null_to_fn.rs b/clippy_lints/src/transmute/transmute_null_to_fn.rs index e109b1c50e227..427e832913310 100644 --- a/clippy_lints/src/transmute/transmute_null_to_fn.rs +++ b/clippy_lints/src/transmute/transmute_null_to_fn.rs @@ -1,7 +1,7 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_integer_literal; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::Ty; diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs index 036b16e3dc3d6..ff0f0218083ec 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs @@ -5,7 +5,7 @@ use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt as _}; /// Checks for `transmute_ptr_to_ptr` lint. /// Returns `true` if it's triggered, otherwise returns `false`. diff --git a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs index ba107eed6b140..1edd7f8baea96 100644 --- a/clippy_lints/src/transmute/transmute_ptr_to_ref.rs +++ b/clippy_lints/src/transmute/transmute_ptr_to_ref.rs @@ -6,7 +6,7 @@ use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::{self as hir, Expr, GenericArg, Mutability, Path, TyKind}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt as _}; /// Checks for `transmute_ptr_to_ref` lint. /// Returns `true` if it's triggered, otherwise returns `false`. diff --git a/clippy_lints/src/transmute/transmuting_null.rs b/clippy_lints/src/transmute/transmuting_null.rs index c85a3155da8f7..55089fbf1bcac 100644 --- a/clippy_lints/src/transmute/transmuting_null.rs +++ b/clippy_lints/src/transmute/transmuting_null.rs @@ -1,6 +1,6 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant, FullInt, eval_int}; use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::sym; use rustc_hir::{ConstBlock, Expr, ExprKind}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/transmute/useless_transmute.rs b/clippy_lints/src/transmute/useless_transmute.rs index b898920baefc2..98be39522f3f3 100644 --- a/clippy_lints/src/transmute/useless_transmute.rs +++ b/clippy_lints/src/transmute/useless_transmute.rs @@ -4,7 +4,7 @@ use clippy_utils::sugg; use rustc_errors::Applicability; use rustc_hir::Expr; use rustc_lint::LateContext; -use rustc_middle::ty::{self, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt as _}; /// Checks for `useless_transmute` lint. /// Returns `true` if it's triggered, otherwise returns `false`. diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index c12cb3846a540..13d408a1c1c2a 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -2,7 +2,7 @@ use arrayvec::ArrayVec; use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::visitors::{Visitable, for_each_expr}; use clippy_utils::{SpanlessEq, is_from_proc_macro}; use core::ops::ControlFlow::{Break, Continue}; diff --git a/clippy_lints/src/types/box_collection.rs b/clippy_lints/src/types/box_collection.rs index b3fea7b5a32ac..246a54dd487dd 100644 --- a/clippy_lints/src/types/box_collection.rs +++ b/clippy_lints/src/types/box_collection.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::{qpath_generic_tys, sym}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, QPath}; diff --git a/clippy_lints/src/types/option_option.rs b/clippy_lints/src/types/option_option.rs index 6d57bb6ef3a0d..dbf7b475d110d 100644 --- a/clippy_lints/src/types/option_option.rs +++ b/clippy_lints/src/types/option_option.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::qpath_generic_tys; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, QPath}; diff --git a/clippy_lints/src/types/owned_cow.rs b/clippy_lints/src/types/owned_cow.rs index 0b8389b72c356..85a49253320eb 100644 --- a/clippy_lints/src/types/owned_cow.rs +++ b/clippy_lints/src/types/owned_cow.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet_opt; use clippy_utils::sym; use rustc_errors::Applicability; diff --git a/clippy_lints/src/types/rc_buffer.rs b/clippy_lints/src/types/rc_buffer.rs index 81061ce1178b9..f056c56be5b3e 100644 --- a/clippy_lints/src/types/rc_buffer.rs +++ b/clippy_lints/src/types/rc_buffer.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{qpath_generic_tys, sym}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/types/rc_mutex.rs b/clippy_lints/src/types/rc_mutex.rs index e3d536822d5f8..43194aa448560 100644 --- a/clippy_lints/src/types/rc_mutex.rs +++ b/clippy_lints/src/types/rc_mutex.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::qpath_generic_tys; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, QPath}; use rustc_lint::LateContext; diff --git a/clippy_lints/src/types/redundant_allocation.rs b/clippy_lints/src/types/redundant_allocation.rs index dbae2cc335165..7de6cf69d02d3 100644 --- a/clippy_lints/src/types/redundant_allocation.rs +++ b/clippy_lints/src/types/redundant_allocation.rs @@ -1,13 +1,13 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::qpath_generic_tys; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::{snippet, snippet_with_applicability}; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, QPath, TyKind}; use rustc_hir_analysis::lower_ty; use rustc_lint::LateContext; -use rustc_middle::ty::TypeVisitableExt; +use rustc_middle::ty::TypeVisitableExt as _; use rustc_span::symbol::sym; use super::{REDUNDANT_ALLOCATION, utils}; diff --git a/clippy_lints/src/types/type_complexity.rs b/clippy_lints/src/types/type_complexity.rs index 52c6fda80973c..ca2977736e4c4 100644 --- a/clippy_lints/src/types/type_complexity.rs +++ b/clippy_lints/src/types/type_complexity.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint; use rustc_abi::ExternAbi; -use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty}; +use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt as _, walk_ty}; use rustc_hir::{self as hir, AmbigArg, GenericParamKind, TyKind}; use rustc_lint::LateContext; use rustc_span::Span; diff --git a/clippy_lints/src/types/vec_box.rs b/clippy_lints/src/types/vec_box.rs index f13042a6fa6bf..539fa8505a109 100644 --- a/clippy_lints/src/types/vec_box.rs +++ b/clippy_lints/src/types/vec_box.rs @@ -6,8 +6,8 @@ use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, GenericArg, LangItem, QPath, TyKind}; use rustc_hir_analysis::lower_ty; use rustc_lint::LateContext; -use rustc_middle::ty::TypeVisitableExt; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::TypeVisitableExt as _; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_span::symbol::sym; use super::VEC_BOX; diff --git a/clippy_lints/src/unconditional_recursion.rs b/clippy_lints/src/unconditional_recursion.rs index e63a524ff5dc0..d375758e45e81 100644 --- a/clippy_lints/src/unconditional_recursion.rs +++ b/clippy_lints/src/unconditional_recursion.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeQPath; +use clippy_utils::res::MaybeQPath as _; use clippy_utils::{expr_or_init, fn_def_id_with_node_args, sym}; use rustc_ast::BinOpKind; use rustc_data_structures::fx::FxHashMap; diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index d35139f2f6b9b..ef8cd6c3b3e9d 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -11,9 +11,9 @@ use hir::HirId; use rustc_errors::Applicability; use rustc_hir::{self as hir, Block, BlockCheckMode, FnSig, Impl, ItemKind, Node, UnsafeSource}; use rustc_lexer::{FrontmatterAllowed, TokenKind, tokenize}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; -use rustc_span::{BytePos, Pos, RelativeBytePos, Span, SyntaxContext}; +use rustc_span::{BytePos, Pos as _, RelativeBytePos, Span, SyntaxContext}; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index 0c95c7f4859c8..3128bf1cc9755 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -8,7 +8,7 @@ use rustc_hir::{Expr, ExprKind, HirId}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::Span; -use unicode_normalization::UnicodeNormalization; +use unicode_normalization::UnicodeNormalization as _; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/uninit_vec.rs b/clippy_lints/src/uninit_vec.rs index 9449d44c009e5..4408e40c24788 100644 --- a/clippy_lints/src/uninit_vec.rs +++ b/clippy_lints/src/uninit_vec.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use clippy_utils::higher::{VecInitKind, get_vec_init_kind}; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::ty::is_uninit_value_valid_for_ty; use clippy_utils::{SpanlessEq, is_integer_literal, is_lint_allowed, peel_hir_expr_while, sym}; use rustc_hir::{Block, Expr, ExprKind, HirId, PatKind, PathSegment, Stmt, StmtKind}; diff --git a/clippy_lints/src/unit_types/let_unit_value.rs b/clippy_lints/src/unit_types/let_unit_value.rs index 8bb6ceb863a37..192cbecb3c46f 100644 --- a/clippy_lints/src/unit_types/let_unit_value.rs +++ b/clippy_lints/src/unit_types/let_unit_value.rs @@ -8,7 +8,7 @@ use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{Visitor, walk_body, walk_expr}; use rustc_hir::{Expr, ExprKind, HirId, HirIdSet, LetStmt, MatchSource, Node, PatKind, QPath, TyKind}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty; use rustc_span::Span; diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index b9d6c81a152b3..898af91e0cde2 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -1,7 +1,7 @@ use std::iter; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::{SpanExt, indent_of, reindent_multiline}; +use clippy_utils::source::{SpanExt as _, indent_of, reindent_multiline}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::expr_type_is_certain; use clippy_utils::{is_empty_block, is_expr_default, is_from_proc_macro}; diff --git a/clippy_lints/src/unnecessary_box_returns.rs b/clippy_lints/src/unnecessary_box_returns.rs index 4112e1b6ca63f..fd40c607c50ad 100644 --- a/clippy_lints/src/unnecessary_box_returns.rs +++ b/clippy_lints/src/unnecessary_box_returns.rs @@ -4,7 +4,7 @@ use rustc_errors::Applicability; use rustc_hir::def_id::LocalDefId; use rustc_hir::{FnDecl, FnRetTy, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_session::impl_lint_pass; use rustc_span::Symbol; diff --git a/clippy_lints/src/unnecessary_literal_bound.rs b/clippy_lints/src/unnecessary_literal_bound.rs index 2603884440d16..f28c9a18fe59a 100644 --- a/clippy_lints/src/unnecessary_literal_bound.rs +++ b/clippy_lints/src/unnecessary_literal_bound.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def::Res; diff --git a/clippy_lints/src/unnecessary_map_on_constructor.rs b/clippy_lints/src/unnecessary_map_on_constructor.rs index 6754c224e7e42..9f6212ebc16cc 100644 --- a/clippy_lints/src/unnecessary_map_on_constructor.rs +++ b/clippy_lints/src/unnecessary_map_on_constructor.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_applicability; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/clippy_lints/src/unnecessary_mut_passed.rs b/clippy_lints/src/unnecessary_mut_passed.rs index 60a6688927ab5..f77c58c6e5c35 100644 --- a/clippy_lints/src/unnecessary_mut_passed.rs +++ b/clippy_lints/src/unnecessary_mut_passed.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints/src/unnecessary_owned_empty_strings.rs b/clippy_lints/src/unnecessary_owned_empty_strings.rs index 6960c006ab949..de24e7827593c 100644 --- a/clippy_lints/src/unnecessary_owned_empty_strings.rs +++ b/clippy_lints/src/unnecessary_owned_empty_strings.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; diff --git a/clippy_lints/src/unnecessary_struct_initialization.rs b/clippy_lints/src/unnecessary_struct_initialization.rs index 65a3c2f304af8..2d1df64a22c19 100644 --- a/clippy_lints/src/unnecessary_struct_initialization.rs +++ b/clippy_lints/src/unnecessary_struct_initialization.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet; use clippy_utils::ty::is_copy; use clippy_utils::{get_parent_expr, is_mutable}; diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index cecffaae69704..39b17e58b8e2a 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeQPath}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _}; use clippy_utils::source::snippet; use clippy_utils::visitors::find_all_ret_expressions; use clippy_utils::{contains_return, return_ty}; diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index ffce03cb5dbea..3a9aa8e5788e2 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::macros::{is_panic, root_macro_call_first_node}; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::{paths, peel_blocks, sym}; use hir::{ExprKind, HirId, PatKind}; use rustc_hir as hir; diff --git a/clippy_lints/src/unused_peekable.rs b/clippy_lints/src/unused_peekable.rs index 668663e4cf794..f8827b916635a 100644 --- a/clippy_lints/src/unused_peekable.rs +++ b/clippy_lints/src/unused_peekable.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::ty::peel_and_count_ty_refs; use clippy_utils::{fn_def_id, peel_ref_operators, sym}; use rustc_ast::Mutability; diff --git a/clippy_lints/src/unused_result_ok.rs b/clippy_lints/src/unused_result_ok.rs index c1dc64e0bbe8d..f33cd7f82ce4e 100644 --- a/clippy_lints/src/unused_result_ok.rs +++ b/clippy_lints/src/unused_result_ok.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::source::snippet_with_context; use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir::{ExprKind, Stmt, StmtKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index bb2ad9f92157c..c84a24a28e939 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::{SpanExt, position_before_rarrow}; +use clippy_utils::source::{SpanExt as _, position_before_rarrow}; use clippy_utils::{is_never_expr, is_unit_expr}; use rustc_ast::{Block, StmtKind}; use rustc_errors::Applicability; diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index d87289e1362dd..c856d08ac9db6 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -4,7 +4,7 @@ use std::iter; use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::msrvs::Msrv; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::source::snippet; use clippy_utils::usage::is_potentially_local_place; use clippy_utils::{can_use_if_let_chains, higher, sym}; @@ -13,7 +13,7 @@ use rustc_errors::Applicability; use rustc_hir::intravisit::{FnKind, Visitor, walk_expr, walk_fn}; use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Node, UnOp}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, Place, PlaceWithHirId}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::hir::nested_filter; use rustc_middle::hir::place::ProjectionKind; use rustc_middle::mir::FakeReadCause; diff --git a/clippy_lints/src/upper_case_acronyms.rs b/clippy_lints/src/upper_case_acronyms.rs index 15dc40af947ef..d1df36911b896 100644 --- a/clippy_lints/src/upper_case_acronyms.rs +++ b/clippy_lints/src/upper_case_acronyms.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use core::mem::replace; use rustc_errors::Applicability; use rustc_hir::{HirId, Item, ItemKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::symbol::Ident; diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 93d0870a30a21..ff96e439deb9a 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::LocalDefId; -use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty}; +use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt as _, walk_ty}; use rustc_hir::{ self as hir, AmbigArg, Expr, ExprKind, FnRetTy, FnSig, GenericArgsParentheses, GenericParamKind, HirId, Impl, ImplItemImplKind, ImplItemKind, Item, ItemKind, Node, Pat, PatExpr, PatExprKind, PatKind, Path, QPath, Ty, TyKind, diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index dcff26f7d6443..5ad5e0431ac53 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; -use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::source::{snippet, snippet_with_context}; use clippy_utils::sugg::{DiagExt as _, Sugg}; use clippy_utils::ty::{is_copy, same_type_modulo_regions}; @@ -7,15 +7,15 @@ use clippy_utils::{get_parent_expr, is_ty_alias, sym}; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{BindingMode, Expr, ExprKind, HirId, LangItem, MatchSource, Mutability, Node, PatKind}; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::TyCtxtInferExt as _; use rustc_infer::traits::Obligation; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::adjustment::{Adjust, AutoBorrow, AutoBorrowMutability}; -use rustc_middle::ty::{self, EarlyBinder, GenericArg, GenericArgsRef, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, EarlyBinder, GenericArg, GenericArgsRef, Ty, TypeVisitableExt as _}; use rustc_session::impl_lint_pass; use rustc_span::Span; -use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; +use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; declare_clippy_lint! { /// ### What it does diff --git a/clippy_lints/src/useless_vec.rs b/clippy_lints/src/useless_vec.rs index cdb757ed89e23..4f089613b9af9 100644 --- a/clippy_lints/src/useless_vec.rs +++ b/clippy_lints/src/useless_vec.rs @@ -7,7 +7,7 @@ use clippy_config::Conf; use clippy_utils::consts::{ConstEvalCtxt, Constant}; use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::msrvs::{self, Msrv}; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::ty::is_copy; use clippy_utils::visitors::for_each_local_use_after_expr; use clippy_utils::{VEC_METHODS_SHADOWING_SLICE_METHODS, get_parent_expr, higher, is_in_test, span_contains_comment}; @@ -15,7 +15,7 @@ use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, LetStmt, Mutability, Node, Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::layout::LayoutOf; +use rustc_middle::ty::layout::LayoutOf as _; use rustc_session::impl_lint_pass; use rustc_span::{DesugaringKind, Span}; diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 2bcf369fb3334..f82edb813d88c 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -1,6 +1,6 @@ use clippy_utils::res::MaybeQPath; use clippy_utils::{get_builtin_attr, higher, sym}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_ast::LitIntType; use rustc_ast::ast::{LitFloatType, LitKind}; use rustc_data_structures::fx::FxHashMap; diff --git a/clippy_lints/src/utils/format_args_collector.rs b/clippy_lints/src/utils/format_args_collector.rs index 6401b48f70b05..3cc06f40c2363 100644 --- a/clippy_lints/src/utils/format_args_collector.rs +++ b/clippy_lints/src/utils/format_args_collector.rs @@ -1,9 +1,9 @@ use clippy_utils::macros::FormatArgsStorage; -use clippy_utils::source::{SpanExt, walk_span_to_context}; +use clippy_utils::source::{SpanExt as _, walk_span_to_context}; use rustc_ast::{Crate, Expr, ExprKind, FormatArgs}; use rustc_data_structures::fx::FxHashMap; use rustc_lexer::{FrontmatterAllowed, TokenKind, tokenize}; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::source_map::SourceMap; use rustc_span::{Span, SpanData}; diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 414dc55b61ba8..18c9499b26f3b 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::higher::{VecInitKind, get_vec_init_kind}; -use clippy_utils::res::MaybeResPath; +use clippy_utils::res::MaybeResPath as _; use clippy_utils::source::snippet; use clippy_utils::visitors::for_each_local_use_after_expr; use clippy_utils::{get_parent_expr, sym}; @@ -8,7 +8,7 @@ use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{BindingMode, Block, Expr, ExprKind, HirId, LetStmt, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; use rustc_span::{Span, Symbol}; diff --git a/clippy_lints/src/visibility.rs b/clippy_lints/src/visibility.rs index 9cefc54598b78..d07c3d76b7ec8 100644 --- a/clippy_lints/src/visibility.rs +++ b/clippy_lints/src/visibility.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use rustc_ast::ast::{Item, VisibilityKind}; use rustc_errors::Applicability; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::declare_lint_pass; use rustc_span::Span; use rustc_span::symbol::kw; diff --git a/clippy_lints/src/volatile_composites.rs b/clippy_lints/src/volatile_composites.rs index 45177c7a86be6..e7eeade451724 100644 --- a/clippy_lints/src/volatile_composites.rs +++ b/clippy_lints/src/volatile_composites.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{self, Ty, TypeVisitableExt}; +use rustc_middle::ty::layout::LayoutOf as _; +use rustc_middle::ty::{self, Ty, TypeVisitableExt as _}; use rustc_session::declare_lint_pass; declare_clippy_lint! { diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 22c46527b5c6c..0c472909a10c5 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Item, ItemKind, PathSegment, UseKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty; use rustc_session::impl_lint_pass; use rustc_span::BytePos; diff --git a/clippy_lints/src/with_capacity_zero.rs b/clippy_lints/src/with_capacity_zero.rs index 26c09c9dc3a6b..62ab50bcde394 100644 --- a/clippy_lints/src/with_capacity_zero.rs +++ b/clippy_lints/src/with_capacity_zero.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::{fn_def_id, is_integer_literal, last_path_segment, span_contains_comment, sym}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem}; diff --git a/clippy_lints/src/write/empty_string.rs b/clippy_lints/src/write/empty_string.rs index 31869e0d2cda9..21dae7f256076 100644 --- a/clippy_lints/src/write/empty_string.rs +++ b/clippy_lints/src/write/empty_string.rs @@ -4,7 +4,7 @@ use clippy_utils::source::{expand_past_previous_comma, snippet_opt}; use clippy_utils::{span_extract_comments, sym}; use rustc_ast::{FormatArgs, FormatArgsPiece}; use rustc_errors::Applicability; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use super::{PRINTLN_EMPTY_STRING, WRITELN_EMPTY_STRING}; diff --git a/clippy_lints/src/write/literal.rs b/clippy_lints/src/write/literal.rs index df31fad8615ed..48e275640804c 100644 --- a/clippy_lints/src/write/literal.rs +++ b/clippy_lints/src/write/literal.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::format_arg_removal_span; -use clippy_utils::source::SpanExt; +use clippy_utils::source::SpanExt as _; use clippy_utils::sym; use rustc_ast::token::LitKind; use rustc_ast::{ diff --git a/clippy_lints/src/write/mod.rs b/clippy_lints/src/write/mod.rs index 8d896046200b4..9937d1e0cad20 100644 --- a/clippy_lints/src/write/mod.rs +++ b/clippy_lints/src/write/mod.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::macros::{FormatArgsStorage, root_macro_call_first_node}; use clippy_utils::{is_in_test, sym}; use rustc_hir::{Expr, Impl, Item, ItemKind, OwnerId}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_session::impl_lint_pass; mod empty_string; diff --git a/clippy_lints/src/write/with_newline.rs b/clippy_lints/src/write/with_newline.rs index 15cc29818aec4..14e6e496f2cf4 100644 --- a/clippy_lints/src/write/with_newline.rs +++ b/clippy_lints/src/write/with_newline.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::MacroCall; -use clippy_utils::source::{SpanExt, expand_past_previous_comma}; +use clippy_utils::source::{SpanExt as _, expand_past_previous_comma}; use clippy_utils::sym; use rustc_ast::{FormatArgs, FormatArgsPiece}; use rustc_errors::Applicability; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_span::BytePos; use super::{PRINT_WITH_NEWLINE, WRITE_WITH_NEWLINE}; diff --git a/clippy_lints/src/zero_repeat_side_effects.rs b/clippy_lints/src/zero_repeat_side_effects.rs index cb254cc156296..c1a7013827208 100644 --- a/clippy_lints/src/zero_repeat_side_effects.rs +++ b/clippy_lints/src/zero_repeat_side_effects.rs @@ -6,7 +6,7 @@ use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{ConstArgKind, Expr, ExprKind, LetStmt, LocalSource, Node}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{IsSuggestable, Ty}; +use rustc_middle::ty::{IsSuggestable as _, Ty}; use rustc_session::declare_lint_pass; use rustc_span::Span; diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 94c2fb20d5f5c..bfbb6cc851296 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -1,10 +1,10 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::res::MaybeDef; +use clippy_utils::res::MaybeDef as _; use clippy_utils::ty::ty_from_hir_ty; use rustc_hir::{self as hir, AmbigArg, HirId, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; -use rustc_middle::ty::{self, TypeVisitableExt}; +use rustc_middle::ty::{self, TypeVisitableExt as _}; use rustc_session::declare_lint_pass; use rustc_span::sym; diff --git a/clippy_lints/src/zombie_processes.rs b/clippy_lints/src/zombie_processes.rs index df2dcdbb9d067..68023209b34b0 100644 --- a/clippy_lints/src/zombie_processes.rs +++ b/clippy_lints/src/zombie_processes.rs @@ -1,6 +1,6 @@ use ControlFlow::{Break, Continue}; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeResPath}; +use clippy_utils::res::{MaybeDef as _, MaybeResPath as _}; use clippy_utils::{fn_def_id, get_enclosing_block, sym}; use rustc_ast::Mutability; use rustc_ast::visit::visit_opt; diff --git a/clippy_lints_internal/src/collapsible_span_lint_calls.rs b/clippy_lints_internal/src/collapsible_span_lint_calls.rs index bac05acebf344..77a17110bf81a 100644 --- a/clippy_lints_internal/src/collapsible_span_lint_calls.rs +++ b/clippy_lints_internal/src/collapsible_span_lint_calls.rs @@ -7,7 +7,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{Span, SyntaxContext}; -use std::borrow::{Borrow, Cow}; +use std::borrow::{Borrow as _, Cow}; use crate::internal_paths; diff --git a/clippy_lints_internal/src/msrv_attr_impl.rs b/clippy_lints_internal/src/msrv_attr_impl.rs index 1225f42d56022..52f911b494fbb 100644 --- a/clippy_lints_internal/src/msrv_attr_impl.rs +++ b/clippy_lints_internal/src/msrv_attr_impl.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use clippy_utils::sym; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass, LintContext as _}; use rustc_middle::ty::{self, GenericArgKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints_internal/src/produce_ice.rs b/clippy_lints_internal/src/produce_ice.rs index 630843049da25..9beab9568abb5 100644 --- a/clippy_lints_internal/src/produce_ice.rs +++ b/clippy_lints_internal/src/produce_ice.rs @@ -1,6 +1,6 @@ use rustc_ast::ast::NodeId; use rustc_ast::visit::FnKind; -use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext as _}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; diff --git a/clippy_lints_internal/src/repeated_is_diagnostic_item.rs b/clippy_lints_internal/src/repeated_is_diagnostic_item.rs index e0148c79477c0..a7599ae21350c 100644 --- a/clippy_lints_internal/src/repeated_is_diagnostic_item.rs +++ b/clippy_lints_internal/src/repeated_is_diagnostic_item.rs @@ -3,7 +3,7 @@ use std::ops::ControlFlow; use crate::internal_paths::MAYBE_DEF; use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; +use clippy_utils::res::{MaybeDef as _, MaybeTypeckRes as _}; use clippy_utils::source::{snippet_indent, snippet_with_applicability}; use clippy_utils::visitors::for_each_expr; use clippy_utils::{eq_expr_value, if_sequence, sym}; diff --git a/clippy_lints_internal/src/unnecessary_def_path.rs b/clippy_lints_internal/src/unnecessary_def_path.rs index f2e8d3579d851..07bbe6aad645d 100644 --- a/clippy_lints_internal/src/unnecessary_def_path.rs +++ b/clippy_lints_internal/src/unnecessary_def_path.rs @@ -2,7 +2,7 @@ use crate::internal_paths; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::paths::{PathNS, lookup_path}; use clippy_utils::peel_ref_operators; -use clippy_utils::res::MaybeQPath; +use clippy_utils::res::MaybeQPath as _; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/clippy_lints_internal/src/unusual_names.rs b/clippy_lints_internal/src/unusual_names.rs index b68ebed713fcb..4f2dd8cfc8093 100644 --- a/clippy_lints_internal/src/unusual_names.rs +++ b/clippy_lints_internal/src/unusual_names.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::paths::PathLookup; use clippy_utils::sym; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, Pat, PatKind, Stmt, StmtKind}; diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 7718afc5f0222..9feb723e7a443 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -1,6 +1,6 @@ //! Utility functions for attributes, including Clippy's built-in ones -use crate::source::SpanExt; +use crate::source::SpanExt as _; use crate::{sym, tokenize_with_text}; use rustc_ast::attr::AttributeExt; use rustc_errors::Applicability; @@ -10,7 +10,7 @@ use rustc_lint::LateContext; use rustc_middle::ty::{AdtDef, TyCtxt}; use rustc_session::Session; use rustc_span::{Span, Symbol}; -use std::str::FromStr; +use std::str::FromStr as _; /// Validates a single clippy attribute and emits errors for unknown or deprecated ones. pub fn check_clippy_attr(sess: &Session, attr: &A) { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index b6dc5dc38cd17..c6c9ec05809d8 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -4,12 +4,12 @@ //! executable MIR bodies, so we have to do this instead. #![expect(clippy::float_cmp)] -use crate::res::MaybeDef; -use crate::source::{SpanExt, walk_span_to_context}; +use crate::res::MaybeDef as _; +use crate::source::{SpanExt as _, walk_span_to_context}; use crate::{clip, is_direct_expn_of, sext, sym, unsext}; use rustc_abi::Size; -use rustc_apfloat::Float; +use rustc_apfloat::Float as _; use rustc_apfloat::ieee::{Half, Quad}; use rustc_ast::ast::{LitFloatType, LitKind}; use rustc_hir::def::{DefKind, Res}; diff --git a/clippy_utils/src/higher.rs b/clippy_utils/src/higher.rs index fe0f14d3f95ae..57e41a9306d9c 100644 --- a/clippy_utils/src/higher.rs +++ b/clippy_utils/src/higher.rs @@ -3,7 +3,7 @@ #![deny(clippy::missing_docs_in_private_items)] use crate::consts::{ConstEvalCtxt, Constant}; -use crate::res::MaybeDef; +use crate::res::MaybeDef as _; use crate::{is_expn_of, sym}; use rustc_ast::ast; diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 050e43344d0c4..da4952645cf60 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -1,6 +1,6 @@ use crate::consts::ConstEvalCtxt; use crate::macros::macro_backtrace; -use crate::source::{SpanExt, SpanRange, walk_span_to_context}; +use crate::source::{SpanExt as _, SpanRange, walk_span_to_context}; use crate::{sym, tokenize_with_text}; use core::mem; use rustc_ast::ast; @@ -21,7 +21,7 @@ use rustc_lexer::{FrontmatterAllowed, TokenKind, tokenize}; use rustc_lint::LateContext; use rustc_middle::ty::TypeckResults; use rustc_span::{BytePos, ExpnKind, MacroKind, Symbol, SyntaxContext}; -use std::hash::{Hash, Hasher}; +use std::hash::{Hash as _, Hasher as _}; use std::ops::Range; use std::slice; diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 56a5e80df2df8..3eef8e6bca366 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -77,7 +77,7 @@ use std::collections::hash_map::Entry; use std::iter::{once, repeat_n, zip}; use std::sync::{Mutex, OnceLock}; -use itertools::Itertools; +use itertools::Itertools as _; use rustc_abi::Integer; use rustc_ast::ast::{self, LitKind, RangeLimits}; use rustc_ast::{LitIntType, join_path_syms}; @@ -101,27 +101,27 @@ use rustc_hir::{ find_attr, }; use rustc_lexer::{FrontmatterAllowed, TokenKind, tokenize}; -use rustc_lint::{LateContext, Level, Lint, LintContext}; +use rustc_lint::{LateContext, Level, Lint, LintContext as _}; use rustc_middle::hir::nested_filter; use rustc_middle::hir::place::PlaceBase; use rustc_middle::mir::{AggregateKind, Operand, RETURN_PLACE, Rvalue, StatementKind, TerminatorKind}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, DerefAdjustKind, PointerCoercion}; -use rustc_middle::ty::layout::IntegerExt; +use rustc_middle::ty::layout::IntegerExt as _; use rustc_middle::ty::{ self as rustc_ty, Binder, BorrowKind, ClosureKind, EarlyBinder, GenericArgKind, GenericArgsRef, IntTy, Ty, TyCtxt, - TypeFlags, TypeVisitableExt, TypeckResults, UintTy, UpvarCapture, + TypeFlags, TypeVisitableExt as _, TypeckResults, UintTy, UpvarCapture, }; use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::{Ident, Symbol, kw}; use rustc_span::{InnerSpan, Span, SyntaxContext}; -use source::{SpanExt, walk_span_to_context}; +use source::{SpanExt as _, walk_span_to_context}; use visitors::{Visitable, for_each_unconsumed_temporary}; use crate::ast_utils::unordered_over; use crate::higher::Range; use crate::msrvs::Msrv; -use crate::res::{MaybeDef, MaybeQPath, MaybeResPath}; +use crate::res::{MaybeDef as _, MaybeQPath as _, MaybeResPath as _}; use crate::source::HasSourceMap; use crate::ty::{adt_and_variant_of_res, can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type}; use crate::visitors::for_each_expr_without_closures; diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs index 76f9b50ca9f4f..3c000b420b9d4 100644 --- a/clippy_utils/src/macros.rs +++ b/clippy_utils/src/macros.rs @@ -10,7 +10,7 @@ use arrayvec::ArrayVec; use rustc_ast::{FormatArgs, FormatArgument, FormatPlaceholder}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::{self as hir, Expr, ExprKind, HirId, Node, QPath}; -use rustc_lint::{LateContext, LintContext}; +use rustc_lint::{LateContext, LintContext as _}; use rustc_span::def_id::DefId; use rustc_span::hygiene::{self, MacroKind, SyntaxContext}; use rustc_span::{BytePos, ExpnData, ExpnId, ExpnKind, Span, SpanData, Symbol}; diff --git a/clippy_utils/src/mir/possible_borrower.rs b/clippy_utils/src/mir/possible_borrower.rs index cbd55ce9b4351..dae6661c5ee1a 100644 --- a/clippy_utils/src/mir/possible_borrower.rs +++ b/clippy_utils/src/mir/possible_borrower.rs @@ -8,7 +8,7 @@ use rustc_middle::mir::visit::Visitor as _; use rustc_middle::mir::{self, Mutability}; use rustc_middle::ty::{self, TyCtxt, TypeVisitor}; use rustc_mir_dataflow::impls::MaybeStorageLive; -use rustc_mir_dataflow::{Analysis, ResultsCursor}; +use rustc_mir_dataflow::{Analysis as _, ResultsCursor}; use std::borrow::Cow; use std::ops::ControlFlow; diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 0e94868144f05..abe53528a6101 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -8,7 +8,7 @@ use hir::LangItem; use rustc_const_eval::check_consts::ConstCx; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, HirId, RustcVersion, StableSince}; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::TyCtxtInferExt as _; use rustc_infer::traits::Obligation; use rustc_lint::LateContext; use rustc_middle::mir::{ diff --git a/clippy_utils/src/source.rs b/clippy_utils/src/source.rs index 171276f997d39..77e0d1000f957 100644 --- a/clippy_utils/src/source.rs +++ b/clippy_utils/src/source.rs @@ -13,7 +13,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::source_map::{SourceMap, original_sp}; use rustc_span::{ - BytePos, DUMMY_SP, DesugaringKind, Pos, RelativeBytePos, SourceFile, SourceFileAndLine, Span, SpanData, + BytePos, DUMMY_SP, DesugaringKind, Pos as _, RelativeBytePos, SourceFile, SourceFileAndLine, Span, SpanData, SyntaxContext, hygiene, }; use std::borrow::Cow; diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index 5c1ae2ed8413d..3bb3b0f791c9d 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -14,7 +14,7 @@ use rustc_lint::{EarlyContext, LateContext, LintContext}; use rustc_middle::hir::place::ProjectionKind; use rustc_middle::mir::{FakeReadCause, Mutability}; use rustc_middle::ty; -use rustc_span::{BytePos, CharPos, Pos, Span, SyntaxContext}; +use rustc_span::{BytePos, CharPos, Pos as _, Span, SyntaxContext}; use std::borrow::Cow; use std::fmt::{self, Display, Write as _}; use std::ops::{Add, Neg, Not, Sub}; diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index 2f9a3585c05b8..c4de2aebad586 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -11,29 +11,29 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, FnDecl, LangItem, find_attr}; use rustc_hir_analysis::lower_ty; -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::TyCtxtInferExt as _; use rustc_lint::LateContext; use rustc_middle::mir::ConstValue; use rustc_middle::mir::interpret::Scalar; use rustc_middle::traits::EvaluationResult; use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind}; -use rustc_middle::ty::layout::{LayoutError, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{LayoutError, LayoutOf as _, TyAndLayout}; use rustc_middle::ty::{ self, AdtDef, AliasTy, AssocItem, AssocTag, Binder, BoundRegion, BoundVarIndexKind, FnSig, GenericArg, GenericArgKind, GenericArgsRef, IntTy, ProjectionAliasTy, Region, RegionKind, TraitRef, Ty, TyCtxt, - TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, Unnormalized, Upcast, VariantDef, - VariantDiscr, + TypeSuperVisitable as _, TypeVisitable, TypeVisitableExt as _, TypeVisitor, UintTy, Unnormalized, Upcast as _, + VariantDef, VariantDiscr, }; use rustc_span::symbol::Ident; use rustc_span::{DUMMY_SP, Span, Symbol}; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; -use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; +use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt as _; use rustc_trait_selection::traits::{Obligation, ObligationCause}; use std::collections::hash_map::Entry; use std::{debug_assert_matches, iter, mem}; use crate::paths::{PathNS, lookup_path_str}; -use crate::res::{MaybeDef, MaybeQPath}; +use crate::res::{MaybeDef as _, MaybeQPath as _}; use crate::{over, sym}; mod type_certainty; @@ -1007,7 +1007,7 @@ pub fn adt_and_variant_of_res<'tcx>(cx: &LateContext<'tcx>, res: Res) -> Option< /// Comes up with an "at least" guesstimate for the type's size, not taking into /// account the layout of type parameters. pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 { - use rustc_middle::ty::layout::LayoutOf; + use rustc_middle::ty::layout::LayoutOf as _; match (cx.layout_of(ty).map(|layout| layout.size.bytes()), ty.kind()) { (Ok(size), _) => size, (Err(_), ty::Tuple(list)) => list.iter().map(|t| approx_ty_size(cx, t)).sum(), @@ -1052,7 +1052,7 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 { #[cfg(debug_assertions)] /// Asserts that the given arguments match the generic parameters of the given item. fn assert_generic_args_match<'tcx>(tcx: TyCtxt<'tcx>, did: DefId, args: &[GenericArg<'tcx>]) { - use itertools::Itertools; + use itertools::Itertools as _; let g = tcx.generics_of(did); let parent = g.parent.map(|did| tcx.generics_of(did)); let count = g.parent_count + g.own_params.len(); diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index 5d8d30b910955..07ea49f3bb7a9 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -15,14 +15,14 @@ use crate::paths::{PathNS, lookup_path}; use rustc_ast::{LitFloatType, LitIntType, LitKind}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; -use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_qpath, walk_ty}; +use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt as _, walk_qpath, walk_ty}; use rustc_hir::{self as hir, AmbigArg, Expr, ExprKind, GenericArgs, HirId, Node, Param, PathSegment, QPath, TyKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self, AdtDef, GenericArgKind, Ty}; use rustc_span::Span; mod certainty; -use certainty::{Certainty, Meet, join, meet}; +use certainty::{Certainty, Meet as _, join, meet}; pub fn expr_type_is_certain(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { expr_type_certainty(cx, expr, false).is_certain() diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs index d644cd5a4aace..bc575701f6ee3 100644 --- a/clippy_utils/src/usage.rs +++ b/clippy_utils/src/usage.rs @@ -1,5 +1,5 @@ use crate::macros::root_macro_call_first_node; -use crate::res::MaybeResPath; +use crate::res::MaybeResPath as _; use crate::visitors::{Descend, Visitable, for_each_expr, for_each_expr_without_closures}; use crate::{self as utils, get_enclosing_loop_or_multi_call_closure, sym}; use core::ops::ControlFlow; diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index 85f983f836d23..1192d7353d123 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -1,10 +1,10 @@ use crate::get_enclosing_block; use crate::msrvs::Msrv; use crate::qualify_min_const_fn::is_stable_const_fn_at; -use crate::res::MaybeResPath; +use crate::res::MaybeResPath as _; use crate::ty::needs_ordered_drop; use core::ops::ControlFlow; -use rustc_ast::visit::{VisitorResult, try_visit}; +use rustc_ast::visit::{VisitorResult as _, try_visit}; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::intravisit::{self, Visitor, walk_block, walk_expr, walk_qpath}; use rustc_hir::{ diff --git a/lintcheck/src/driver.rs b/lintcheck/src/driver.rs index 87ab14ba0cf83..7cbccdab58a48 100644 --- a/lintcheck/src/driver.rs +++ b/lintcheck/src/driver.rs @@ -1,6 +1,6 @@ use crate::recursive::{DriverInfo, deserialize_line, serialize_line}; -use std::io::{self, BufReader, Write}; +use std::io::{self, BufReader, Write as _}; use std::net::TcpStream; use std::process::{self, Command, Stdio}; use std::{env, mem}; diff --git a/lintcheck/src/json.rs b/lintcheck/src/json.rs index 79c1255c5ffe5..f39a7fef16183 100644 --- a/lintcheck/src/json.rs +++ b/lintcheck/src/json.rs @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf}; use std::{fmt, fs}; -use itertools::{EitherOrBoth, Itertools}; +use itertools::{EitherOrBoth, Itertools as _}; use serde::{Deserialize, Serialize}; use crate::ClippyWarning; diff --git a/lintcheck/src/popular_crates.rs b/lintcheck/src/popular_crates.rs index ad8fc440c4240..c3170e46eaf9c 100644 --- a/lintcheck/src/popular_crates.rs +++ b/lintcheck/src/popular_crates.rs @@ -1,6 +1,6 @@ use serde::Deserialize; use std::error::Error; -use std::fmt::Write; +use std::fmt::Write as _; use std::fs; use std::path::PathBuf; diff --git a/lintcheck/src/recursive.rs b/lintcheck/src/recursive.rs index 6406b2dcb643b..a236ec904ee51 100644 --- a/lintcheck/src/recursive.rs +++ b/lintcheck/src/recursive.rs @@ -7,7 +7,7 @@ use crate::ClippyWarning; use crate::input::RecursiveOptions; use std::collections::HashSet; -use std::io::{BufRead, BufReader, Read, Write}; +use std::io::{BufRead, BufReader, Read as _, Write}; use std::net::{SocketAddr, TcpListener, TcpStream}; use std::sync::{Arc, Mutex}; use std::thread; diff --git a/src/driver.rs b/src/driver.rs index b73ddc3ae12c8..890b15fe9e120 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -60,7 +60,7 @@ fn is_arg(argument: &str, key: &str) -> bool { #[test] fn test_arg_value() { - use std::ops::Not; + use std::ops::Not as _; let args = &["--bar=bar", "--foobar", "123", "--foo"].map(String::from); diff --git a/tests/compile-test.rs b/tests/compile-test.rs index e5933d7c7a3f1..f51a7aeca1103 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -24,7 +24,7 @@ use ui_test::{Args, CommandBuilder, Config, Match, error_on_output_conflict}; use std::collections::{BTreeMap, HashMap}; use std::env::{self, set_var, var_os}; use std::ffi::{OsStr, OsString}; -use std::fmt::Write; +use std::fmt::Write as _; use std::path::{Path, PathBuf}; use std::sync::mpsc::{Sender, channel}; use std::{fs, iter, thread}; diff --git a/tests/config-metadata.rs b/tests/config-metadata.rs index af9fe064dc708..0dfaacfb65f42 100644 --- a/tests/config-metadata.rs +++ b/tests/config-metadata.rs @@ -1,7 +1,7 @@ #![feature(rustc_private)] use clippy_config::{ClippyConfiguration, get_configuration_metadata}; -use itertools::Itertools; +use itertools::Itertools as _; use regex::Regex; use std::borrow::Cow; use std::{env, fs}; diff --git a/tests/dogfood.rs b/tests/dogfood.rs index 389616801fcaa..de91b48e847e0 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -5,8 +5,8 @@ #![warn(rust_2018_idioms, unused_lifetimes)] -use itertools::Itertools; -use std::io::{self, IsTerminal}; +use itertools::Itertools as _; +use std::io::{self, IsTerminal as _}; use std::path::PathBuf; use std::process::Command; use test_utils::IS_RUSTC_TEST_SUITE; From 15edcddcbb31ff5077e2ed41d65c433599e35cdf Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 6 Jul 2026 17:03:22 +0200 Subject: [PATCH 33/63] Enable `clippy::unused_trait_names` in dogfood --- tests/dogfood.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/dogfood.rs b/tests/dogfood.rs index de91b48e847e0..2213dd70415f8 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -82,7 +82,16 @@ fn run_clippy_for_package(project: &str) -> bool { command.arg("--"); command.arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir - command.args(["-D", "clippy::all", "-D", "clippy::pedantic", "-D", "clippy::dbg_macro"]); + command.args([ + "-D", + "clippy::all", + "-D", + "clippy::pedantic", + "-D", + "clippy::dbg_macro", + "-D", + "clippy::unused_trait_names", + ]); if !cfg!(feature = "internal") { // running a clippy built without internal lints on the clippy source // that contains e.g. `allow(clippy::symbol_as_str)` From 3bba7c4adcf95cb9003b5050f0e2735e5b482286 Mon Sep 17 00:00:00 2001 From: shulaoda <165626830+shulaoda@users.noreply.github.com> Date: Sat, 11 Jul 2026 21:20:16 +0800 Subject: [PATCH 34/63] Respect the configured MSRV in `implicit_saturating_sub`'s `if x != 0 { x -= 1 }` rewrite --- book/src/lint_configuration.md | 1 + clippy_config/src/conf.rs | 1 + clippy_lints/src/implicit_saturating_sub.rs | 7 +++++- tests/ui/implicit_saturating_sub.fixed | 20 ++++++++++++++++ tests/ui/implicit_saturating_sub.rs | 26 +++++++++++++++++++++ tests/ui/implicit_saturating_sub.stderr | 20 +++++++++++++++- 6 files changed, 73 insertions(+), 2 deletions(-) diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index fb4df6234dacd..c713dffcba8ba 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -941,6 +941,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio * [`filter_map_next`](https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next) * [`from_over_into`](https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into) * [`if_then_some_else_none`](https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none) +* [`implicit_saturating_sub`](https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub) * [`index_refutable_slice`](https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice) * [`inefficient_to_string`](https://rust-lang.github.io/rust-clippy/master/index.html#inefficient_to_string) * [`io_other_error`](https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 8a2795defc08f..c00bb6890df92 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -796,6 +796,7 @@ define_Conf! { filter_map_next, from_over_into, if_then_some_else_none, + implicit_saturating_sub, index_refutable_slice, inefficient_to_string, io_other_error, diff --git a/clippy_lints/src/implicit_saturating_sub.rs b/clippy_lints/src/implicit_saturating_sub.rs index 4093ff9f4b2d8..960b187de0b59 100644 --- a/clippy_lints/src/implicit_saturating_sub.rs +++ b/clippy_lints/src/implicit_saturating_sub.rs @@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { // Check if the conditional expression is a binary operation && let ExprKind::Binary(ref cond_op, cond_left, cond_right) = cond.kind { - check_with_condition(cx, expr, cond_op.node, cond_left, cond_right, then); + check_with_condition(cx, expr, cond_op.node, cond_left, cond_right, then, self.msrv); } else if let Some(higher::If { cond, then: if_block, @@ -309,6 +309,7 @@ fn check_with_condition<'tcx>( cond_left: &Expr<'tcx>, cond_right: &Expr<'tcx>, then: &Expr<'tcx>, + msrv: Msrv, ) { // Ensure that the binary operator is >, !=, or < if (BinOpKind::Ne == cond_op || BinOpKind::Gt == cond_op || BinOpKind::Lt == cond_op) @@ -342,6 +343,10 @@ fn check_with_condition<'tcx>( return; } + if is_in_const_context(cx) && !msrv.meets(cx, msrvs::SATURATING_SUB_CONST) { + return; + } + // Get the variable name let var_name = ares_path.segments[0].ident.name; match cond_num_val.kind { diff --git a/tests/ui/implicit_saturating_sub.fixed b/tests/ui/implicit_saturating_sub.fixed index c7ab65cbb0151..7756541224a39 100644 --- a/tests/ui/implicit_saturating_sub.fixed +++ b/tests/ui/implicit_saturating_sub.fixed @@ -278,3 +278,23 @@ fn wrongly_unmangled_macros() { let b = 20u64; let _ = test_big!(a).saturating_sub(test_little!(b)); } + +#[clippy::msrv = "1.46.0"] +pub const fn const_msrv_too_low(mut x: u32) -> u32 { + if x != 0 { + x -= 1; + } + x +} + +#[clippy::msrv = "1.47.0"] +pub const fn const_msrv_ok(mut x: u32) -> u32 { + x = x.saturating_sub(1); + x +} + +#[clippy::msrv = "1.46.0"] +pub fn nonconst_msrv_low(mut x: u32) -> u32 { + x = x.saturating_sub(1); + x +} diff --git a/tests/ui/implicit_saturating_sub.rs b/tests/ui/implicit_saturating_sub.rs index 1371928e15b5d..72f6e719ae1c2 100644 --- a/tests/ui/implicit_saturating_sub.rs +++ b/tests/ui/implicit_saturating_sub.rs @@ -357,3 +357,29 @@ fn wrongly_unmangled_macros() { 0 }; } + +#[clippy::msrv = "1.46.0"] +pub const fn const_msrv_too_low(mut x: u32) -> u32 { + if x != 0 { + x -= 1; + } + x +} + +#[clippy::msrv = "1.47.0"] +pub const fn const_msrv_ok(mut x: u32) -> u32 { + if x != 0 { + //~^ implicit_saturating_sub + x -= 1; + } + x +} + +#[clippy::msrv = "1.46.0"] +pub fn nonconst_msrv_low(mut x: u32) -> u32 { + if x != 0 { + //~^ implicit_saturating_sub + x -= 1; + } + x +} diff --git a/tests/ui/implicit_saturating_sub.stderr b/tests/ui/implicit_saturating_sub.stderr index c7a4330603a29..bb099e6288a6b 100644 --- a/tests/ui/implicit_saturating_sub.stderr +++ b/tests/ui/implicit_saturating_sub.stderr @@ -256,5 +256,23 @@ LL | | 0 LL | | }; | |_____^ help: replace it with: `test_big!(a).saturating_sub(test_little!(b))` -error: aborting due to 29 previous errors +error: implicitly performing saturating subtraction + --> tests/ui/implicit_saturating_sub.rs:371:5 + | +LL | / if x != 0 { +LL | | +LL | | x -= 1; +LL | | } + | |_____^ help: try: `x = x.saturating_sub(1);` + +error: implicitly performing saturating subtraction + --> tests/ui/implicit_saturating_sub.rs:380:5 + | +LL | / if x != 0 { +LL | | +LL | | x -= 1; +LL | | } + | |_____^ help: try: `x = x.saturating_sub(1);` + +error: aborting due to 31 previous errors From 75abcda35dd38ef7f5c73b3a78ab5cf3bae044a7 Mon Sep 17 00:00:00 2001 From: Gri-ffin Date: Sat, 11 Jul 2026 14:44:54 +0100 Subject: [PATCH 35/63] fix if_not_else firing on macro expanded conditions --- clippy_lints/src/if_not_else.rs | 3 +- tests/ui/if_not_else.fixed | 68 +++++++++++++++++++++++++++++++++ tests/ui/if_not_else.rs | 68 +++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index ea1992d471312..9b904699b9afc 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -52,6 +52,7 @@ impl LateLintPass<'_> for IfNotElse { fn check_expr(&mut self, cx: &LateContext<'_>, e: &Expr<'_>) { if let ExprKind::If(cond, cond_inner, Some(els)) = e.kind && let ExprKind::Block(..) = els.kind + && !cond.span.from_expansion() { let (msg, help) = match cond.kind { ExprKind::Unary(UnOp::Not, _) => ( @@ -61,7 +62,7 @@ impl LateLintPass<'_> for IfNotElse { // Don't lint on `… != 0`, as these are likely to be bit tests. // For example, `if foo & 0x0F00 != 0 { … } else { … }` is already in the "proper" order. ExprKind::Binary(op, _, rhs) - if op.node == BinOpKind::Ne && !is_zero_integer_const(cx, rhs, e.span.ctxt()) => + if op.node == BinOpKind::Ne && !is_zero_integer_const(cx, rhs, cond.span.ctxt()) => { ( "unnecessary `!=` operation", diff --git a/tests/ui/if_not_else.fixed b/tests/ui/if_not_else.fixed index a29847f0cf978..9c01cb62ac77b 100644 --- a/tests/ui/if_not_else.fixed +++ b/tests/ui/if_not_else.fixed @@ -93,3 +93,71 @@ fn issue15924() { println!(":)"); } } + +mod issue17373 { + macro_rules! ht_is_packed { + ($ht:expr) => { + ($ht).u & 4 != 0 + }; + } + struct HashTable { + u: u32, + } + impl HashTable { + fn check(&mut self) { + if ht_is_packed!(self) { + println!("Packed"); + } else { + println!("Not packed"); + } + } + } + + macro_rules! is_active { + ($x:expr) => { + ($x).state != 3 + }; + } + struct Widget { + state: u32, + } + impl Widget { + fn check(&self) { + if is_active!(self) { + println!("active"); + } else { + println!("inactive"); + } + } + } + + macro_rules! not_ready { + ($x:expr) => { + !($x).ready + }; + } + struct Task { + ready: bool, + } + impl Task { + fn check(&self) { + if not_ready!(self) { + println!("waiting"); + } else { + println!("go"); + } + } + } + + macro_rules! wrap_if { + ($cond:expr, $t:block, $e:block) => { + if $cond $t else $e + }; + } + fn wrap_if_macro() { + let x = 0; + fn a() {} + fn b() {} + wrap_if!(x != 0, { a() }, { b() }); + } +} diff --git a/tests/ui/if_not_else.rs b/tests/ui/if_not_else.rs index 4ae11d6ad90ea..9d7da2dac37a4 100644 --- a/tests/ui/if_not_else.rs +++ b/tests/ui/if_not_else.rs @@ -93,3 +93,71 @@ fn issue15924() { println!(":("); } } + +mod issue17373 { + macro_rules! ht_is_packed { + ($ht:expr) => { + ($ht).u & 4 != 0 + }; + } + struct HashTable { + u: u32, + } + impl HashTable { + fn check(&mut self) { + if ht_is_packed!(self) { + println!("Packed"); + } else { + println!("Not packed"); + } + } + } + + macro_rules! is_active { + ($x:expr) => { + ($x).state != 3 + }; + } + struct Widget { + state: u32, + } + impl Widget { + fn check(&self) { + if is_active!(self) { + println!("active"); + } else { + println!("inactive"); + } + } + } + + macro_rules! not_ready { + ($x:expr) => { + !($x).ready + }; + } + struct Task { + ready: bool, + } + impl Task { + fn check(&self) { + if not_ready!(self) { + println!("waiting"); + } else { + println!("go"); + } + } + } + + macro_rules! wrap_if { + ($cond:expr, $t:block, $e:block) => { + if $cond $t else $e + }; + } + fn wrap_if_macro() { + let x = 0; + fn a() {} + fn b() {} + wrap_if!(x != 0, { a() }, { b() }); + } +} From 061b37acc1aa421737554a22951449c1bf2fdbe2 Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Sat, 11 Jul 2026 20:57:36 +0200 Subject: [PATCH 36/63] Fix race in two Clippy UI tests. Both tests only declare: //@aux-build:proc_macro_derive.rs but they also contain: extern crate proc_macros; use proc_macros::inline_macros; Because `proc_macros.rs` is not declared, ui_test does not pass an explicit `--extern proc_macros=.../libproc_macros.so` for these tests. The tests can still appear to work when another test has already built `proc_macros.rs`, because rustc then finds it through the shared `-L .../tests/ui/auxiliary` directory. That fallback is racy. During a parallel Clippy UI run, the auxiliary build can leave `libproc_macros.rmeta` visible before `libproc_macros.so` is written. If one of these tests starts in that window, rustc loads metadata for a proc-macro crate but has no dylib in the crate source, then ICEs in `rustc_metadata::creader` with: no dylib for a proc-macro crate Adding `//@aux-build:proc_macros.rs` makes the dependency explicit, forcing ui_test to build `proc_macros.rs` before running the test and to pass the proc-macro dylib through `--extern`. --- tests/ui/non_canonical_clone_impl.fixed | 1 + tests/ui/non_canonical_clone_impl.rs | 1 + tests/ui/non_canonical_clone_impl.stderr | 14 +++++++------- tests/ui/non_canonical_partial_ord_impl.fixed | 1 + tests/ui/non_canonical_partial_ord_impl.rs | 1 + tests/ui/non_canonical_partial_ord_impl.stderr | 10 +++++----- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/ui/non_canonical_clone_impl.fixed b/tests/ui/non_canonical_clone_impl.fixed index 466a1304e72c5..7cbc8f8aa06f5 100644 --- a/tests/ui/non_canonical_clone_impl.fixed +++ b/tests/ui/non_canonical_clone_impl.fixed @@ -1,4 +1,5 @@ //@aux-build:proc_macro_derive.rs +//@aux-build:proc_macros.rs #![expect(clippy::clone_on_copy)] #![allow(clippy::assigning_clones)] #![no_main] diff --git a/tests/ui/non_canonical_clone_impl.rs b/tests/ui/non_canonical_clone_impl.rs index 5f815b567dfc7..58b2a3207efd4 100644 --- a/tests/ui/non_canonical_clone_impl.rs +++ b/tests/ui/non_canonical_clone_impl.rs @@ -1,4 +1,5 @@ //@aux-build:proc_macro_derive.rs +//@aux-build:proc_macros.rs #![expect(clippy::clone_on_copy)] #![allow(clippy::assigning_clones)] #![no_main] diff --git a/tests/ui/non_canonical_clone_impl.stderr b/tests/ui/non_canonical_clone_impl.stderr index 3741a7dcce860..98862b426ec5c 100644 --- a/tests/ui/non_canonical_clone_impl.stderr +++ b/tests/ui/non_canonical_clone_impl.stderr @@ -1,5 +1,5 @@ error: non-canonical implementation of `clone` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:12:29 + --> tests/ui/non_canonical_clone_impl.rs:13:29 | LL | fn clone(&self) -> Self { | _____________________________^ @@ -12,7 +12,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::non_canonical_clone_impl)]` error: unnecessary implementation of `clone_from` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:17:5 + --> tests/ui/non_canonical_clone_impl.rs:18:5 | LL | / fn clone_from(&mut self, source: &Self) { LL | | @@ -22,7 +22,7 @@ LL | | } | |_____^ help: remove it error: non-canonical implementation of `clone` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:82:29 + --> tests/ui/non_canonical_clone_impl.rs:83:29 | LL | fn clone(&self) -> Self { | _____________________________^ @@ -32,7 +32,7 @@ LL | | } | |_____^ help: change this to: `{ *self }` error: unnecessary implementation of `clone_from` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:87:5 + --> tests/ui/non_canonical_clone_impl.rs:88:5 | LL | / fn clone_from(&mut self, source: &Self) { LL | | @@ -42,7 +42,7 @@ LL | | } | |_____^ help: remove it error: non-canonical implementation of `clone` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:121:37 + --> tests/ui/non_canonical_clone_impl.rs:122:37 | LL | fn clone(&self) -> Self { | _____________________________________^ @@ -54,7 +54,7 @@ LL | | } = note: this error originates in the macro `__inline_mac_mod_issue12788` (in Nightly builds, run with -Z macro-backtrace for more info) error: non-canonical implementation of `clone` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:160:29 + --> tests/ui/non_canonical_clone_impl.rs:161:29 | LL | fn clone(&self) -> Self { | _____________________________^ @@ -64,7 +64,7 @@ LL | | } | |_____^ help: change this to: `{ *self }` error: non-canonical implementation of `clone` on a `Copy` type - --> tests/ui/non_canonical_clone_impl.rs:187:33 + --> tests/ui/non_canonical_clone_impl.rs:188:33 | LL | fn clone(&self) -> Self { | _________________________________^ diff --git a/tests/ui/non_canonical_partial_ord_impl.fixed b/tests/ui/non_canonical_partial_ord_impl.fixed index aa23fd99ad77b..526497c781501 100644 --- a/tests/ui/non_canonical_partial_ord_impl.fixed +++ b/tests/ui/non_canonical_partial_ord_impl.fixed @@ -1,4 +1,5 @@ //@aux-build:proc_macro_derive.rs +//@aux-build:proc_macros.rs #![no_main] extern crate proc_macros; diff --git a/tests/ui/non_canonical_partial_ord_impl.rs b/tests/ui/non_canonical_partial_ord_impl.rs index da7f73f7c4bef..cff98810adebc 100644 --- a/tests/ui/non_canonical_partial_ord_impl.rs +++ b/tests/ui/non_canonical_partial_ord_impl.rs @@ -1,4 +1,5 @@ //@aux-build:proc_macro_derive.rs +//@aux-build:proc_macros.rs #![no_main] extern crate proc_macros; diff --git a/tests/ui/non_canonical_partial_ord_impl.stderr b/tests/ui/non_canonical_partial_ord_impl.stderr index 36f68ae897d3d..ffd0611497fa7 100644 --- a/tests/ui/non_canonical_partial_ord_impl.stderr +++ b/tests/ui/non_canonical_partial_ord_impl.stderr @@ -1,5 +1,5 @@ error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> tests/ui/non_canonical_partial_ord_impl.rs:20:1 + --> tests/ui/non_canonical_partial_ord_impl.rs:21:1 | LL | / impl PartialOrd for A { LL | | @@ -20,7 +20,7 @@ LL + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp | error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> tests/ui/non_canonical_partial_ord_impl.rs:55:1 + --> tests/ui/non_canonical_partial_ord_impl.rs:56:1 | LL | / impl PartialOrd for C { LL | | @@ -39,7 +39,7 @@ LL + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp | error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> tests/ui/non_canonical_partial_ord_impl.rs:191:9 + --> tests/ui/non_canonical_partial_ord_impl.rs:192:9 | LL | / impl PartialOrd for A { LL | | @@ -59,7 +59,7 @@ LL + fn partial_cmp(&self, other: &Self) -> Option { Some( | error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> tests/ui/non_canonical_partial_ord_impl.rs:271:1 + --> tests/ui/non_canonical_partial_ord_impl.rs:272:1 | LL | / impl PartialOrd for K { LL | | @@ -78,7 +78,7 @@ LL + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp | error: non-canonical implementation of `partial_cmp` on an `Ord` type - --> tests/ui/non_canonical_partial_ord_impl.rs:289:1 + --> tests/ui/non_canonical_partial_ord_impl.rs:290:1 | LL | / impl PartialOrd for L { LL | | From 33096b4cfde3fe97cf7492064cec392f7f2c8caf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 3 Jul 2026 14:58:41 +1000 Subject: [PATCH 37/63] Shrink `ast::Expr` From 72 bytes to 64 bytes, by boxing `ForLoop`, which is the biggest variant. There are now 11 `ExprKind` variants that are 31 bytes, so future improvements here will be very difficult. --- clippy_utils/src/ast_utils/mod.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/clippy_utils/src/ast_utils/mod.rs b/clippy_utils/src/ast_utils/mod.rs index c89130fb647a4..fe51f841bc8b6 100644 --- a/clippy_utils/src/ast_utils/mod.rs +++ b/clippy_utils/src/ast_utils/mod.rs @@ -183,22 +183,13 @@ fn eq_expr(l: &Expr, r: &Expr) -> bool { (While(lc, lt, ll), While(rc, rt, rl)) => { eq_label(ll.as_ref(), rl.as_ref()) && eq_expr(lc, rc) && eq_block(lt, rt) }, - ( - ForLoop { - pat: lp, - iter: li, - body: lt, - label: ll, - kind: lk, - }, - ForLoop { - pat: rp, - iter: ri, - body: rt, - label: rl, - kind: rk, - }, - ) => eq_label(ll.as_ref(), rl.as_ref()) && eq_pat(lp, rp) && eq_expr(li, ri) && eq_block(lt, rt) && lk == rk, + (ForLoop(lf), ForLoop(rf)) => { + eq_label(lf.label.as_ref(), rf.label.as_ref()) + && eq_pat(&lf.pat, &rf.pat) + && eq_expr(&lf.iter, &rf.iter) + && eq_block(&lf.body, &rf.body) + && lf.kind == rf.kind + } (Loop(lt, ll, _), Loop(rt, rl, _)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_block(lt, rt), (Block(lb, ll), Block(rb, rl)) => eq_label(ll.as_ref(), rl.as_ref()) && eq_block(lb, rb), (TryBlock(lb, lt), TryBlock(rb, rt)) => eq_block(lb, rb) && both(lt.as_deref(), rt.as_deref(), eq_ty), From dd38e1881864852f81bd6bee212c6b21b2207a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=99=A8=20=28Leo=20Cheng=29?= Date: Thu, 9 Jul 2026 22:32:42 +0800 Subject: [PATCH 38/63] fix(non_zero_suggestions): don't lint signed div/rem as NonZero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Div> and Rem> are only implemented for unsigned integer types in std. Suggesting NonZeroI* as the RHS of / or % produces code that fails to compile because those trait impls do not exist for signed types. Guard the div/rem path to only fire when the RHS type is ty::Uint. Signed-off-by: 林晨 (Leo Cheng) --- clippy_lints/src/non_zero_suggestions.rs | 8 +++++++- tests/ui/non_zero_suggestions.fixed | 8 +++++++- tests/ui/non_zero_suggestions.rs | 8 +++++++- tests/ui/non_zero_suggestions.stderr | 4 ++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/non_zero_suggestions.rs b/clippy_lints/src/non_zero_suggestions.rs index 1b8ab1bdedf8a..b8d1147baeb71 100644 --- a/clippy_lints/src/non_zero_suggestions.rs +++ b/clippy_lints/src/non_zero_suggestions.rs @@ -52,7 +52,13 @@ impl<'tcx> LateLintPass<'tcx> for NonZeroSuggestions { if let ExprKind::Binary(op, _, rhs) = expr.kind && matches!(op.node, BinOpKind::Div | BinOpKind::Rem) { - check_non_zero_conversion(cx, rhs, Applicability::MachineApplicable); + // `Div>` and `Rem>` are only implemented for unsigned + // integer types; signed integer types do not have these impls, so suggesting + // `NonZeroI*::from(x)` as the divisor produces code that won't compile. + let rhs_ty = cx.typeck_results().expr_ty(rhs); + if matches!(rhs_ty.kind(), ty::Uint(_)) { + check_non_zero_conversion(cx, rhs, Applicability::MachineApplicable); + } } else { // Check if the parent expression is a binary operation let parent_is_binary = cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, node)| { diff --git a/tests/ui/non_zero_suggestions.fixed b/tests/ui/non_zero_suggestions.fixed index 4573896ecd673..b714a6cf6ede7 100644 --- a/tests/ui/non_zero_suggestions.fixed +++ b/tests/ui/non_zero_suggestions.fixed @@ -1,5 +1,5 @@ #![warn(clippy::non_zero_suggestions)] -use std::num::{NonZeroI8, NonZeroI16, NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroUsize}; +use std::num::{NonZeroI8, NonZeroI16, NonZeroI32, NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroUsize}; fn main() { /// Positive test cases (lint should trigger) @@ -45,6 +45,12 @@ fn main() { let k: u64 = 300; let l = NonZeroU32::new(15).unwrap(); let r9 = k / NonZeroU64::from(l); + + // Signed integers in div/rem: must NOT trigger because i64 / NonZeroI64 is not in std + let s: i64 = 10; + let t = NonZeroI32::new(3).unwrap(); + let r10 = s / i64::from(t.get()); + let r11 = s % i64::from(t.get()); } // Additional function to test the lint in a different context diff --git a/tests/ui/non_zero_suggestions.rs b/tests/ui/non_zero_suggestions.rs index 3e7081e0c1c0c..0e4cd3cc36528 100644 --- a/tests/ui/non_zero_suggestions.rs +++ b/tests/ui/non_zero_suggestions.rs @@ -1,5 +1,5 @@ #![warn(clippy::non_zero_suggestions)] -use std::num::{NonZeroI8, NonZeroI16, NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroUsize}; +use std::num::{NonZeroI8, NonZeroI16, NonZeroI32, NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroUsize}; fn main() { /// Positive test cases (lint should trigger) @@ -45,6 +45,12 @@ fn main() { let k: u64 = 300; let l = NonZeroU32::new(15).unwrap(); let r9 = k / NonZeroU64::from(l); + + // Signed integers in div/rem: must NOT trigger because i64 / NonZeroI64 is not in std + let s: i64 = 10; + let t = NonZeroI32::new(3).unwrap(); + let r10 = s / i64::from(t.get()); + let r11 = s % i64::from(t.get()); } // Additional function to test the lint in a different context diff --git a/tests/ui/non_zero_suggestions.stderr b/tests/ui/non_zero_suggestions.stderr index 7a57f7983be74..4b5a8a3fc6ff7 100644 --- a/tests/ui/non_zero_suggestions.stderr +++ b/tests/ui/non_zero_suggestions.stderr @@ -26,13 +26,13 @@ LL | let x = u64::from(NonZeroU32::new(5).unwrap().get()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(NonZeroU32::new(5).unwrap())` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:52:9 + --> tests/ui/non_zero_suggestions.rs:58:9 | LL | x / u64::from(y.get()) | ^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(y)` error: consider using `NonZeroU64::from()` for more efficient and type-safe conversion - --> tests/ui/non_zero_suggestions.rs:62:22 + --> tests/ui/non_zero_suggestions.rs:68:22 | LL | self.value / u64::from(divisor.get()) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `NonZeroU64::from(divisor)` From 8245e85a6e520241ceb7ab74735f47057c69dc22 Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 13 Jul 2026 14:04:01 +1000 Subject: [PATCH 39/63] Update tools to rustc-demangle 1.2.8 --- lintcheck/ci_crates.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lintcheck/ci_crates.toml b/lintcheck/ci_crates.toml index 6299823451d01..73ccb734ca27d 100644 --- a/lintcheck/ci_crates.toml +++ b/lintcheck/ci_crates.toml @@ -163,7 +163,7 @@ zerocopy = { name = 'zerocopy', version = '0.7.35' } rustversion = { name = 'rustversion', version = '1.0.17' } env_logger = { name = 'env_logger', version = '0.11.3' } webpki-roots = { name = 'webpki-roots', version = '0.26.3' } -rustc-demangle = { name = 'rustc-demangle', version = '0.1.24' } +rustc-demangle = { name = 'rustc-demangle', version = '0.1.28' } mime = { name = 'mime', version = '0.3.17' } termcolor = { name = 'termcolor', version = '1.4.1' } subtle = { name = 'subtle', version = '2.6.1' } From d728c37941f4b1f059386185bf9cddc182b30ef7 Mon Sep 17 00:00:00 2001 From: rabindra789 Date: Mon, 13 Jul 2026 12:17:13 +0530 Subject: [PATCH 40/63] ref_as_ptr: avoid invalid suggestions in const/static initializers Extend the existing const/static guard to also handle nested cast expressions. This prevents \ ef_as_ptr\ from suggesting \ptr::from_ref\/\ptr::from_mut\ replacements that fail during const evaluation. --- clippy_lints/src/casts/ref_as_ptr.rs | 8 +++++--- tests/ui/ref_as_ptr.fixed | 5 +++++ tests/ui/ref_as_ptr.rs | 5 +++++ tests/ui/ref_as_ptr.stderr | 22 +++++++++++----------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/casts/ref_as_ptr.rs b/clippy_lints/src/casts/ref_as_ptr.rs index aef04dc9f7f9a..b850f7f41ed33 100644 --- a/clippy_lints/src/casts/ref_as_ptr.rs +++ b/clippy_lints/src/casts/ref_as_ptr.rs @@ -1,7 +1,9 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; use clippy_utils::sugg::Sugg; -use clippy_utils::{ExprUseNode, get_expr_use_site, is_expr_temporary_value, std_or_core}; +use clippy_utils::{ + ExprUseNode, get_expr_use_site, is_expr_temporary_value, is_inside_always_const_context, std_or_core, +}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, Mutability, Ty, TyKind}; use rustc_lint::LateContext; @@ -26,10 +28,10 @@ pub(super) fn check<'tcx>( { if let ExprKind::AddrOf(_, _, addr_inner) = cast_expr.kind && is_expr_temporary_value(cx, addr_inner) - && matches!( + && (matches!( get_expr_use_site(cx.tcx, cx.typeck_results(), expr.span.ctxt(), expr).use_node(cx), ExprUseNode::LetStmt(_) | ExprUseNode::ConstStatic(_) - ) + ) || is_inside_always_const_context(cx.tcx, expr.hir_id)) { return; } diff --git a/tests/ui/ref_as_ptr.fixed b/tests/ui/ref_as_ptr.fixed index d00a2fd693f64..75a97330c61d3 100644 --- a/tests/ui/ref_as_ptr.fixed +++ b/tests/ui/ref_as_ptr.fixed @@ -99,6 +99,11 @@ fn main() { let _ = &String::new() as *const _; let _ = &mut String::new() as *mut _; const FOO: *const String = &String::new() as *const _; + + // Regression test for #13910. + // This should not lint because the suggested replacement fails during + // const evaluation. + static mut REGRESSION: *mut i32 = &mut [42] as *mut [i32] as *mut i32; } #[clippy::msrv = "1.75"] diff --git a/tests/ui/ref_as_ptr.rs b/tests/ui/ref_as_ptr.rs index c9b87256290fa..e3b816d4a0457 100644 --- a/tests/ui/ref_as_ptr.rs +++ b/tests/ui/ref_as_ptr.rs @@ -99,6 +99,11 @@ fn main() { let _ = &String::new() as *const _; let _ = &mut String::new() as *mut _; const FOO: *const String = &String::new() as *const _; + + // Regression test for #13910. + // This should not lint because the suggested replacement fails during + // const evaluation. + static mut REGRESSION: *mut i32 = &mut [42] as *mut [i32] as *mut i32; } #[clippy::msrv = "1.75"] diff --git a/tests/ui/ref_as_ptr.stderr b/tests/ui/ref_as_ptr.stderr index 587e4fb809cdb..c7b2bdea3cd1b 100644 --- a/tests/ui/ref_as_ptr.stderr +++ b/tests/ui/ref_as_ptr.stderr @@ -218,67 +218,67 @@ LL | let _ = &*x as *const _; | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(&*x)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:119:7 + --> tests/ui/ref_as_ptr.rs:124:7 | LL | f(val as *const i32); | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:121:7 + --> tests/ui/ref_as_ptr.rs:126:7 | LL | f(mut_val as *mut i32); | ^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(mut_val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:126:7 + --> tests/ui/ref_as_ptr.rs:131:7 | LL | f(val as *const _); | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:128:7 + --> tests/ui/ref_as_ptr.rs:133:7 | LL | f(val as *const [u8]); | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref::<[u8]>(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:133:7 + --> tests/ui/ref_as_ptr.rs:138:7 | LL | f(val as *mut _); | ^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:135:7 + --> tests/ui/ref_as_ptr.rs:140:7 | LL | f(val as *mut str); | ^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut::(val)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:143:9 + --> tests/ui/ref_as_ptr.rs:148:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:148:9 + --> tests/ui/ref_as_ptr.rs:153:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:157:9 + --> tests/ui/ref_as_ptr.rs:162:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:162:9 + --> tests/ui/ref_as_ptr.rs:167:9 | LL | self.0 as *const _ as *const _ | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_ref(self.0)` error: reference as raw pointer - --> tests/ui/ref_as_ptr.rs:167:9 + --> tests/ui/ref_as_ptr.rs:172:9 | LL | self.0 as *mut _ as *mut _ | ^^^^^^^^^^^^^^^^ help: try: `std::ptr::from_mut(self.0)` From 93c02236bd43449a6874ca580400af8b66dfb13d Mon Sep 17 00:00:00 2001 From: Valdemar Erk Date: Mon, 13 Jul 2026 12:12:49 +0200 Subject: [PATCH 41/63] partly disable unneeded_wildcard_pattern when rest_pattern_accessible_field is enabled --- clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs | 4 +++- tests/ui/rest_pattern_accessible_field.fixed | 2 +- tests/ui/rest_pattern_accessible_field.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs b/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs index 897d720036ee9..c5eae228333d4 100644 --- a/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs +++ b/clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use rustc_ast::ast::{Pat, PatFieldsRest, PatKind}; use rustc_errors::Applicability; -use rustc_lint::EarlyContext; +use rustc_lint::{EarlyContext, LintContext as _}; use rustc_span::Span; use super::UNNEEDED_WILDCARD_PATTERN; @@ -40,6 +40,8 @@ pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) { .take_while(|patfield| matches!(patfield.pat.kind, PatKind::Wild)) .enumerate() .last() + // Only run if `rest_pattern_accessible_field` is Allow, as they otherwise will contradict each other. + && cx.get_lint_level_spec(crate::rest_when_destructuring_struct::REST_PATTERN_ACCESSIBLE_FIELD).is_allow() { // Unlike the tuples above, structs have patfields rather than patterns, and separate out the // `..` into a separate parameter. Also, the `..` can only be at the end of the pattern. diff --git a/tests/ui/rest_pattern_accessible_field.fixed b/tests/ui/rest_pattern_accessible_field.fixed index d2bc2c1de8ec5..0ccfb551aa28c 100644 --- a/tests/ui/rest_pattern_accessible_field.fixed +++ b/tests/ui/rest_pattern_accessible_field.fixed @@ -1,7 +1,7 @@ //@aux-build:proc_macros.rs //@aux-build:non-exhaustive-struct.rs #![warn(clippy::rest_pattern_accessible_field)] -#![allow(clippy::unneeded_wildcard_pattern)] +#![warn(clippy::unneeded_wildcard_pattern)] use non_exhaustive_struct::{NonExhaustiveStruct, NonExhaustiveStructNoPrivateFields}; diff --git a/tests/ui/rest_pattern_accessible_field.rs b/tests/ui/rest_pattern_accessible_field.rs index 0df08c9d0521c..9a692b7417851 100644 --- a/tests/ui/rest_pattern_accessible_field.rs +++ b/tests/ui/rest_pattern_accessible_field.rs @@ -1,7 +1,7 @@ //@aux-build:proc_macros.rs //@aux-build:non-exhaustive-struct.rs #![warn(clippy::rest_pattern_accessible_field)] -#![allow(clippy::unneeded_wildcard_pattern)] +#![warn(clippy::unneeded_wildcard_pattern)] use non_exhaustive_struct::{NonExhaustiveStruct, NonExhaustiveStructNoPrivateFields}; From 370a5860629b491540ee4683c42c084aba8161e2 Mon Sep 17 00:00:00 2001 From: "Alexis (Poliorcetics) Bourget" Date: Mon, 13 Jul 2026 15:11:24 +0200 Subject: [PATCH 42/63] lints: `rest_pattern_accessible_fields`: fix typo `accesible` -> accessible --- clippy_lints/src/rest_when_destructuring_struct.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/rest_when_destructuring_struct.rs b/clippy_lints/src/rest_when_destructuring_struct.rs index 536d6803bc28d..73772e5b52f08 100644 --- a/clippy_lints/src/rest_when_destructuring_struct.rs +++ b/clippy_lints/src/rest_when_destructuring_struct.rs @@ -9,7 +9,7 @@ use std::fmt::Write as _; declare_clippy_lint! { /// ### What it does - /// Disallow the use of rest patterns for accesible fields + /// Disallow the use of rest patterns for accessible fields /// /// ### Why restrict this? /// It might lead to unhandled fields when the struct changes. From a3ba59a5056a04d1dc1f733dab088627d1268d61 Mon Sep 17 00:00:00 2001 From: lapla Date: Thu, 5 Feb 2026 18:45:52 +0900 Subject: [PATCH 43/63] Trigger `single_element_loop` if the block contains only a final expression --- clippy_lints/src/loops/single_element_loop.rs | 42 ++++++++++++------- tests/ui/single_element_loop.fixed | 7 ++++ tests/ui/single_element_loop.rs | 7 ++++ tests/ui/single_element_loop.stderr | 8 +++- tests/ui/single_element_loop_nofix.rs | 12 ++++++ tests/ui/single_element_loop_nofix.stderr | 16 +++++++ 6 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 tests/ui/single_element_loop_nofix.rs create mode 100644 tests/ui/single_element_loop_nofix.stderr diff --git a/clippy_lints/src/loops/single_element_loop.rs b/clippy_lints/src/loops/single_element_loop.rs index edbf6e63e659f..5b16d69dc5c41 100644 --- a/clippy_lints/src/loops/single_element_loop.rs +++ b/clippy_lints/src/loops/single_element_loop.rs @@ -1,5 +1,5 @@ use super::SINGLE_ELEMENT_LOOP; -use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; use clippy_utils::source::{indent_of, snippet, snippet_with_applicability}; use clippy_utils::visitors::contains_break_or_continue; use rustc_ast::Mutability; @@ -66,7 +66,7 @@ pub(super) fn check<'tcx>( _ => return, }; if let ExprKind::Block(block, _) = body.kind - && !block.stmts.is_empty() + && (!block.stmts.is_empty() || block.expr.is_some()) && !contains_break_or_continue(body) { let mut applicability = Applicability::MachineApplicable; @@ -78,7 +78,13 @@ pub(super) fn check<'tcx>( let mut block_str = snippet_with_applicability(cx, block.span, "..", &mut applicability).into_owned(); block_str.remove(0); block_str.pop(); - let indent = " ".repeat(indent_of(cx, block.stmts[0].span).unwrap_or(0)); + let indent = if let Some(first_stmt) = block.stmts.first() { + " ".repeat(indent_of(cx, first_stmt.span).unwrap_or(0)) + } else if let Some(block_expr) = block.expr { + " ".repeat(indent_of(cx, block_expr.span).unwrap_or(0)) + } else { + String::new() + }; // Reference iterator from `&(mut) []` or `[].iter(_mut)()`. if !prefix.is_empty() @@ -90,19 +96,23 @@ pub(super) fn check<'tcx>( arg_snip = format!("({arg_snip})").into(); } - if clippy_utils::higher::Range::hir(cx, arg_expression).is_some() { - let range_expr = snippet(cx, arg_expression.span, "?").to_string(); - - let sugg = snippet(cx, arg_expression.span, ".."); - span_lint_and_sugg( - cx, - SINGLE_ELEMENT_LOOP, - arg.span, - format!("this loops only once with `{pat_snip}` being `{range_expr}`"), - "did you mean to iterate over the range instead?", - sugg.to_string(), - Applicability::Unspecified, - ); + if let Some(range) = clippy_utils::higher::Range::hir(cx, arg_expression) { + if range.start.is_some() { + // Only suggest iterating over ranges that have a start value. + let range_expr = snippet(cx, arg_expression.span, "?").to_string(); + let sugg = snippet(cx, arg_expression.span, ".."); + span_lint_and_sugg( + cx, + SINGLE_ELEMENT_LOOP, + arg.span, + format!("this loops only once with `{pat_snip}` being `{range_expr}`"), + "did you mean to iterate over the range instead?", + sugg.to_string(), + Applicability::Unspecified, + ); + } else { + span_lint(cx, SINGLE_ELEMENT_LOOP, expr.span, "for loop over a single element"); + } } else { span_lint_and_sugg( cx, diff --git a/tests/ui/single_element_loop.fixed b/tests/ui/single_element_loop.fixed index 76c3cf56c11ec..26fe8e1a3e373 100644 --- a/tests/ui/single_element_loop.fixed +++ b/tests/ui/single_element_loop.fixed @@ -73,4 +73,11 @@ fn main() { //~^ single_element_loop let ptr: *const bool = std::ptr::null(); } + + for _ in 3..5 { + //~^ single_element_loop + if true { + println!("aaa"); + } + } } diff --git a/tests/ui/single_element_loop.rs b/tests/ui/single_element_loop.rs index 2eb928397b0a6..e05e9fb189933 100644 --- a/tests/ui/single_element_loop.rs +++ b/tests/ui/single_element_loop.rs @@ -69,4 +69,11 @@ fn main() { //~^ single_element_loop let ptr: *const bool = std::ptr::null(); } + + for _ in [3..5] { + //~^ single_element_loop + if true { + println!("aaa"); + } + } } diff --git a/tests/ui/single_element_loop.stderr b/tests/ui/single_element_loop.stderr index 639f8d2d1b98f..1fdc388eb34e5 100644 --- a/tests/ui/single_element_loop.stderr +++ b/tests/ui/single_element_loop.stderr @@ -106,5 +106,11 @@ LL + let ptr: *const bool = std::ptr::null(); LL + } | -error: aborting due to 8 previous errors +error: this loops only once with `_` being `3..5` + --> tests/ui/single_element_loop.rs:73:14 + | +LL | for _ in [3..5] { + | ^^^^^^ help: did you mean to iterate over the range instead?: `3..5` + +error: aborting due to 9 previous errors diff --git a/tests/ui/single_element_loop_nofix.rs b/tests/ui/single_element_loop_nofix.rs new file mode 100644 index 0000000000000..76f19f372bc40 --- /dev/null +++ b/tests/ui/single_element_loop_nofix.rs @@ -0,0 +1,12 @@ +//@no-rustfix +#![warn(clippy::single_element_loop)] +#![allow(clippy::single_range_in_vec_init)] + +fn f(print: bool) { + for _ in [..5] { + //~^ single_element_loop + if print { + println!("Hello from f"); + } + } +} diff --git a/tests/ui/single_element_loop_nofix.stderr b/tests/ui/single_element_loop_nofix.stderr new file mode 100644 index 0000000000000..b3d3988f4ce33 --- /dev/null +++ b/tests/ui/single_element_loop_nofix.stderr @@ -0,0 +1,16 @@ +error: for loop over a single element + --> tests/ui/single_element_loop_nofix.rs:6:5 + | +LL | / for _ in [..5] { +LL | | +LL | | if print { +LL | | println!("Hello from f"); +LL | | } +LL | | } + | |_____^ + | + = note: `-D clippy::single-element-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_element_loop)]` + +error: aborting due to 1 previous error + From 764f02f4f5bbf1dd712b8e6060b771b2d1acd1c1 Mon Sep 17 00:00:00 2001 From: lapla Date: Mon, 13 Jul 2026 22:34:42 +0900 Subject: [PATCH 44/63] Refactor `single_element_loop` to avoid `clippy::too_many_lines` --- clippy_lints/src/loops/single_element_loop.rs | 152 ++++++++++-------- 1 file changed, 87 insertions(+), 65 deletions(-) diff --git a/clippy_lints/src/loops/single_element_loop.rs b/clippy_lints/src/loops/single_element_loop.rs index 5b16d69dc5c41..917fe32610b5e 100644 --- a/clippy_lints/src/loops/single_element_loop.rs +++ b/clippy_lints/src/loops/single_element_loop.rs @@ -17,112 +17,134 @@ pub(super) fn check<'tcx>( body: &'tcx Expr<'_>, expr: &'tcx Expr<'_>, ) { - let (arg_expression, prefix) = match arg.kind { + let Some((arg_expression, prefix)) = extract_single_element(cx, arg) else { + return; + }; + + if let ExprKind::Block(block, _) = body.kind + && (!block.stmts.is_empty() || block.expr.is_some()) + && !contains_break_or_continue(body) + { + emit_lint(cx, pat, arg, expr, arg_expression, prefix, block); + } +} + +fn extract_single_element<'tcx>( + cx: &LateContext<'tcx>, + arg: &'tcx Expr<'_>, +) -> Option<(&'tcx Expr<'tcx>, &'static str)> { + match arg.kind { ExprKind::AddrOf( BorrowKind::Ref, Mutability::Not, Expr { - kind: ExprKind::Array([arg]), + kind: ExprKind::Array([inner]), .. }, - ) => (arg, "&"), + ) => Some((inner, "&")), ExprKind::AddrOf( BorrowKind::Ref, Mutability::Mut, Expr { - kind: ExprKind::Array([arg]), + kind: ExprKind::Array([inner]), .. }, - ) => (arg, "&mut "), + ) => Some((inner, "&mut ")), ExprKind::MethodCall( method, Expr { - kind: ExprKind::Array([arg]), + kind: ExprKind::Array([inner]), .. }, [], _, - ) if method.ident.name == sym::iter => (arg, "&"), + ) if method.ident.name == sym::iter => Some((inner, "&")), ExprKind::MethodCall( method, Expr { - kind: ExprKind::Array([arg]), + kind: ExprKind::Array([inner]), .. }, [], _, - ) if method.ident.name == sym::iter_mut => (arg, "&mut "), + ) if method.ident.name == sym::iter_mut => Some((inner, "&mut ")), ExprKind::MethodCall( method, Expr { - kind: ExprKind::Array([arg]), + kind: ExprKind::Array([inner]), .. }, [], _, - ) if method.ident.name == sym::into_iter => (arg, ""), + ) if method.ident.name == sym::into_iter => Some((inner, "")), // Only check for arrays edition 2021 or later, as this case will trigger a compiler error otherwise. - ExprKind::Array([arg]) if cx.tcx.sess.edition() >= Edition::Edition2021 => (arg, ""), - _ => return, + ExprKind::Array([inner]) if cx.tcx.sess.edition() >= Edition::Edition2021 => Some((inner, "")), + _ => None, + } +} + +fn emit_lint<'tcx>( + cx: &LateContext<'tcx>, + pat: &'tcx Pat<'_>, + arg: &'tcx Expr<'_>, + expr: &'tcx Expr<'_>, + arg_expression: &'tcx Expr<'_>, + prefix: &str, + block: &rustc_hir::Block<'_>, +) { + let mut applicability = Applicability::MachineApplicable; + let mut pat_snip = snippet_with_applicability(cx, pat.span, "..", &mut applicability); + if matches!(pat.kind, PatKind::Or(..)) { + pat_snip = format!("({pat_snip})").into(); + } + let mut arg_snip = snippet_with_applicability(cx, arg_expression.span, "..", &mut applicability); + let mut block_str = snippet_with_applicability(cx, block.span, "..", &mut applicability).into_owned(); + block_str.remove(0); + block_str.pop(); + let indent = if let Some(first_stmt) = block.stmts.first() { + " ".repeat(indent_of(cx, first_stmt.span).unwrap_or(0)) + } else if let Some(block_expr) = block.expr { + " ".repeat(indent_of(cx, block_expr.span).unwrap_or(0)) + } else { + String::new() }; - if let ExprKind::Block(block, _) = body.kind - && (!block.stmts.is_empty() || block.expr.is_some()) - && !contains_break_or_continue(body) - { - let mut applicability = Applicability::MachineApplicable; - let mut pat_snip = snippet_with_applicability(cx, pat.span, "..", &mut applicability); - if matches!(pat.kind, PatKind::Or(..)) { - pat_snip = format!("({pat_snip})").into(); - } - let mut arg_snip = snippet_with_applicability(cx, arg_expression.span, "..", &mut applicability); - let mut block_str = snippet_with_applicability(cx, block.span, "..", &mut applicability).into_owned(); - block_str.remove(0); - block_str.pop(); - let indent = if let Some(first_stmt) = block.stmts.first() { - " ".repeat(indent_of(cx, first_stmt.span).unwrap_or(0)) - } else if let Some(block_expr) = block.expr { - " ".repeat(indent_of(cx, block_expr.span).unwrap_or(0)) - } else { - String::new() - }; - // Reference iterator from `&(mut) []` or `[].iter(_mut)()`. - if !prefix.is_empty() - && ( - // Precedence of internal expression is less than or equal to precedence of `&expr`. - cx.precedence(arg_expression) <= ExprPrecedence::Prefix || is_range_literal(arg_expression) - ) - { - arg_snip = format!("({arg_snip})").into(); - } + // Reference iterator from `&(mut) []` or `[].iter(_mut)()`. + if !prefix.is_empty() + && ( + // Precedence of internal expression is less than or equal to precedence of `&expr`. + cx.precedence(arg_expression) <= ExprPrecedence::Prefix || is_range_literal(arg_expression) + ) + { + arg_snip = format!("({arg_snip})").into(); + } - if let Some(range) = clippy_utils::higher::Range::hir(cx, arg_expression) { - if range.start.is_some() { - // Only suggest iterating over ranges that have a start value. - let range_expr = snippet(cx, arg_expression.span, "?").to_string(); - let sugg = snippet(cx, arg_expression.span, ".."); - span_lint_and_sugg( - cx, - SINGLE_ELEMENT_LOOP, - arg.span, - format!("this loops only once with `{pat_snip}` being `{range_expr}`"), - "did you mean to iterate over the range instead?", - sugg.to_string(), - Applicability::Unspecified, - ); - } else { - span_lint(cx, SINGLE_ELEMENT_LOOP, expr.span, "for loop over a single element"); - } - } else { + if let Some(range) = clippy_utils::higher::Range::hir(cx, arg_expression) { + if range.start.is_some() { + // Only suggest iterating over ranges that have a start value. + let range_expr = snippet(cx, arg_expression.span, "?").to_string(); + let sugg = snippet(cx, arg_expression.span, ".."); span_lint_and_sugg( cx, SINGLE_ELEMENT_LOOP, - expr.span, - "for loop over a single element", - "try", - format!("{{\n{indent}let {pat_snip} = {prefix}{arg_snip};{block_str}}}"), - applicability, + arg.span, + format!("this loops only once with `{pat_snip}` being `{range_expr}`"), + "did you mean to iterate over the range instead?", + sugg.to_string(), + Applicability::Unspecified, ); + } else { + span_lint(cx, SINGLE_ELEMENT_LOOP, expr.span, "for loop over a single element"); } + } else { + span_lint_and_sugg( + cx, + SINGLE_ELEMENT_LOOP, + expr.span, + "for loop over a single element", + "try", + format!("{{\n{indent}let {pat_snip} = {prefix}{arg_snip};{block_str}}}"), + applicability, + ); } } From 107bf3f8e4be9330964b0137642204b953129750 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 13 Jul 2026 21:23:39 -0500 Subject: [PATCH 45/63] Fix rustdoc with ModId refactors --- clippy_lints/src/inherent_impl.rs | 4 ++-- clippy_utils/src/lib.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 257a165ba8315..7475897852177 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -3,7 +3,7 @@ use clippy_config::types::InherentImplLintScope; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{fulfill_or_allowed, is_cfg_test, is_in_cfg_test}; use rustc_data_structures::fx::FxHashMap; -use rustc_hir::def_id::{LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{LocalDefId, LocalModId}; use rustc_hir::{Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; @@ -63,7 +63,7 @@ impl MultipleInherentImpl { #[derive(Hash, Eq, PartialEq, Clone)] enum Criterion { - Module(LocalModDefId), + Module(LocalModId), File(FileName), Crate, } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 56a5e80df2df8..2be96a6f08973 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -88,7 +88,7 @@ use rustc_data_structures::unhash::UnindexMap; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::attrs::CfgEntry; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{DefId, LocalDefId, LocalModId}; use rustc_hir::definitions::{DefPath, DefPathData}; use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{Visitor, walk_expr}; @@ -2348,11 +2348,11 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { false } -static TEST_ITEM_NAMES_CACHE: OnceLock>>> = OnceLock::new(); +static TEST_ITEM_NAMES_CACHE: OnceLock>>> = OnceLock::new(); /// Returns the names of the test items in the given module. /// The names are sorted using the default `Symbol` ordering. -fn test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId) -> Vec { +fn test_item_names(tcx: TyCtxt<'_>, module: LocalModId) -> Vec { let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default())); let mut map = cache.lock().unwrap(); match map.entry(module) { From 76efc6cbef06866afc69420edb6ff04c51d7acee Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 13 Jul 2026 21:23:39 -0500 Subject: [PATCH 46/63] Fix clippy with ModId refactors --- clippy_lints/src/error_impl_error.rs | 4 ++-- clippy_lints/src/infallible_try_from.rs | 2 +- clippy_lints/src/redundant_pub_crate.rs | 4 ++-- clippy_lints/src/unused_trait_names.rs | 2 +- clippy_lints/src/wildcard_imports.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/error_impl_error.rs b/clippy_lints/src/error_impl_error.rs index 4b9e3cee011c6..4b7aaa34d1ad8 100644 --- a/clippy_lints/src/error_impl_error.rs +++ b/clippy_lints/src/error_impl_error.rs @@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ErrorImplError { /// which aren't reexported fn is_visible_outside_module(cx: &LateContext<'_>, def_id: LocalDefId) -> bool { !matches!( - cx.tcx.visibility(def_id), - Visibility::Restricted(mod_def_id) if cx.tcx.parent_module_from_def_id(def_id).to_def_id() == mod_def_id + cx.tcx.local_visibility(def_id), + Visibility::Restricted(mod_def_id) if cx.tcx.parent_module_from_def_id(def_id) == mod_def_id ) } diff --git a/clippy_lints/src/infallible_try_from.rs b/clippy_lints/src/infallible_try_from.rs index b7cbe667b3346..7472ec0a2106b 100644 --- a/clippy_lints/src/infallible_try_from.rs +++ b/clippy_lints/src/infallible_try_from.rs @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleTryFrom { .filter_by_name_unhygienic_and_kind(sym::Error, AssocTag::Type) { let ii_ty = cx.tcx.type_of(ii.def_id).instantiate_identity().skip_norm_wip(); - if !ii_ty.is_inhabited_from(cx.tcx, ii.def_id, cx.typing_env()) { + if !ii_ty.is_inhabited_from(cx.tcx, cx.tcx.parent_module_from_def_id(ii.def_id.expect_local()), cx.typing_env()) { let mut span = MultiSpan::from_span(cx.tcx.def_span(item.owner_id.to_def_id())); let ii_ty_span = cx .tcx diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs index c7f7b47403376..8abb5159f90e6 100644 --- a/clippy_lints/src/redundant_pub_crate.rs +++ b/clippy_lints/src/redundant_pub_crate.rs @@ -5,7 +5,7 @@ use rustc_hir::{Item, ItemKind, UseKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::impl_lint_pass; -use rustc_span::def_id::CRATE_DEF_ID; +use rustc_span::def_id::CRATE_MOD_ID; declare_clippy_lint! { /// ### What it does @@ -44,7 +44,7 @@ pub struct RedundantPubCrate { impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if cx.tcx.visibility(item.owner_id.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()) + if cx.tcx.local_visibility(item.owner_id.def_id) == ty::Visibility::Restricted(CRATE_MOD_ID) && !cx.effective_visibilities.is_exported(item.owner_id.def_id) && self.is_exported.last() == Some(&false) && !is_ignorable_export(item) diff --git a/clippy_lints/src/unused_trait_names.rs b/clippy_lints/src/unused_trait_names.rs index be41bdd380204..e09018284434f 100644 --- a/clippy_lints/src/unused_trait_names.rs +++ b/clippy_lints/src/unused_trait_names.rs @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames { && cx.tcx.resolutions(()).maybe_unused_trait_imports.contains(&item.owner_id.def_id) // Only check this import if it is visible to its module only (no pub, pub(crate), ...) && let module = cx.tcx.parent_module_from_def_id(item.owner_id.def_id) - && cx.tcx.visibility(item.owner_id.def_id) == Visibility::Restricted(module.to_def_id()) + && cx.tcx.local_visibility(item.owner_id.def_id) == Visibility::Restricted(module) && let Some(last_segment) = path.segments.last() && let Some(snip) = snippet_opt(cx, last_segment.ident.span) && self.msrv.meets(cx, msrvs::UNDERSCORE_IMPORTS) diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 22c46527b5c6c..19ab3789232cd 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -123,7 +123,7 @@ impl LateLintPass<'_> for WildcardImports { } let module = cx.tcx.parent_module_from_def_id(item.owner_id.def_id); - if cx.tcx.visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module.to_def_id()) + if cx.tcx.local_visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module) && !self.warn_on_all { return; From 5f14555b6902385287db1f551ad69b9f9eeb5929 Mon Sep 17 00:00:00 2001 From: Aluminium Date: Wed, 15 Jul 2026 15:13:42 +0300 Subject: [PATCH 47/63] Code simplification (collect has only one generic parameter) --- clippy_lints/src/methods/needless_collect.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/methods/needless_collect.rs b/clippy_lints/src/methods/needless_collect.rs index b132d60007cf0..77f0abc780267 100644 --- a/clippy_lints/src/methods/needless_collect.rs +++ b/clippy_lints/src/methods/needless_collect.rs @@ -239,9 +239,9 @@ fn check_collect_into_intoiterator<'tcx>( fn collect_turbofish_is_fully_concrete(collect_expr: &Expr<'_>) -> bool { if let ExprKind::MethodCall(segment, ..) = collect_expr.kind && let Some(args) = segment.args - && !args.args.is_empty() + && let [a] = args.args { - args.args.iter().all(generic_arg_is_fully_concrete) + generic_arg_is_fully_concrete(a) } else { false } From 3ff23804c80ef060da85d37dcf1d0db862586ebc Mon Sep 17 00:00:00 2001 From: Shivendra Sharma Date: Wed, 15 Apr 2026 15:23:44 +0530 Subject: [PATCH 48/63] Add `block_scrutinee` lint --- CHANGELOG.md | 1 + clippy_lints/src/block_scrutinee.rs | 111 ++++++++++++++++++++++++++++ clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/lib.rs | 2 + tests/ui/block_scrutinee.1.fixed | 60 +++++++++++++++ tests/ui/block_scrutinee.2.fixed | 64 ++++++++++++++++ tests/ui/block_scrutinee.rs | 63 ++++++++++++++++ tests/ui/block_scrutinee.stderr | 87 ++++++++++++++++++++++ tests/ui/block_scrutinee_2024.rs | 28 +++++++ 9 files changed, 417 insertions(+) create mode 100644 clippy_lints/src/block_scrutinee.rs create mode 100644 tests/ui/block_scrutinee.1.fixed create mode 100644 tests/ui/block_scrutinee.2.fixed create mode 100644 tests/ui/block_scrutinee.rs create mode 100644 tests/ui/block_scrutinee.stderr create mode 100644 tests/ui/block_scrutinee_2024.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 856c229f4679a..dc308285319fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6763,6 +6763,7 @@ Released 2018-09-13 [`blanket_clippy_restriction_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#blanket_clippy_restriction_lints [`block_in_if_condition_expr`]: https://rust-lang.github.io/rust-clippy/master/index.html#block_in_if_condition_expr [`block_in_if_condition_stmt`]: https://rust-lang.github.io/rust-clippy/master/index.html#block_in_if_condition_stmt +[`block_scrutinee`]: https://rust-lang.github.io/rust-clippy/master/index.html#block_scrutinee [`blocks_in_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions [`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions [`bool_assert_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison diff --git a/clippy_lints/src/block_scrutinee.rs b/clippy_lints/src/block_scrutinee.rs new file mode 100644 index 0000000000000..0d0a8ba3b60a3 --- /dev/null +++ b/clippy_lints/src/block_scrutinee.rs @@ -0,0 +1,111 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::source::{indent_of, snippet}; +use rustc_errors::Applicability; +use rustc_hir::{BlockCheckMode, Expr, ExprKind, LoopSource}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_session::declare_lint_pass; +use rustc_span::edition::Edition; + +declare_clippy_lint! { + /// ### What it does + /// Warns when a match, if let, or while let scrutinee is wrapped in a block. + /// This lint only triggers on the 2021 edition and older. + /// + /// ### Why is this bad? + /// It is unusual to write `{ expr }` when you could just have written + /// `expr`, and it is unlikely that anyone would write that for any reason + /// other than wanting temporaries in `expr` to be dropped before executing + /// the body of the `match`/`if let`/`while` statement. However, prior to + /// the 2024 edition, wrapping the scrutinee in a block did not drop + /// temporaries before the body executes. + /// + /// ### Example + /// ```rust,ignore + /// if let Some(x) = { my_function() } { .. } + /// ``` + #[clippy::version = "1.98.0"] + pub BLOCK_SCRUTINEE, + suspicious, + "warns when the scrutinee is wrapped in a block in older editions" +} + +declare_lint_pass!(BlockScrutinee => [BLOCK_SCRUTINEE]); + +impl<'tcx> LateLintPass<'tcx> for BlockScrutinee { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { + if cx.tcx.sess.edition() >= Edition::Edition2024 { + return; + } + + let (scrutinee, keyword_fallback) = match expr.kind { + ExprKind::Match(scrutinee, _, _) => (scrutinee, "`match`"), + ExprKind::Let(let_expr) => (let_expr.init, "`if let` / `while let`"), + _ => return, + }; + + if scrutinee.span.from_expansion() || expr.span.from_expansion() { + return; + } + + if let ExprKind::Block(block, _) = scrutinee.kind + && matches!(block.rules, BlockCheckMode::DefaultBlock) + && block.stmts.is_empty() + && let Some(inner_expr) = block.expr + { + let inner_snippet = snippet(cx, inner_expr.span, ".."); + + let main_msg = "this scrutinee is wrapped in a block"; + + span_lint_and_then(cx, BLOCK_SCRUTINEE, scrutinee.span, main_msg, |diag| { + let mut keyword = keyword_fallback; + let mut outer_span = expr.span; + + if let ExprKind::Let(_) = expr.kind { + keyword = "`if let`"; + for (_, node) in cx.tcx.hir_parent_iter(expr.hir_id) { + if let rustc_hir::Node::Expr(e) = node { + if let ExprKind::If(..) = e.kind { + if keyword == "`if let`" { + outer_span = e.span; + } + } else if let ExprKind::Loop(_, _, LoopSource::While, _) = e.kind { + keyword = "`while let`"; + outer_span = e.span; + break; + } + } else if matches!(node, rustc_hir::Node::Item(..) | rustc_hir::Node::ImplItem(..)) { + break; + } + } + } + + diag.note(format!( + "temporary values in this block-wrapped scrutinee will be dropped after the body of the {keyword} statement" + )); + + diag.note("starting with the 2024 edition, temporaries within a block's final expression are dropped immediately at the end of the block"); + + let suggestion_msg = format!("to drop temporaries after the surrounding {keyword}, remove the block"); + + diag.span_suggestion( + scrutinee.span, + suggestion_msg, + inner_snippet.to_string(), + Applicability::MaybeIncorrect, + ); + + let indent = indent_of(cx, outer_span).unwrap_or(0); + let pad = " ".repeat(indent); + + diag.multipart_suggestion( + "to drop temporaries early, move them to a separate local binding (or update your `Cargo.toml` to the 2024 edition)", + vec![ + (outer_span.shrink_to_lo(), format!("let res = {inner_snippet};\n{pad}")), + (scrutinee.span, "res".to_string()), + ], + Applicability::MaybeIncorrect, + ); + }); + } + } +} diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index e77a0ff4a8abb..b14ee7f3de902 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -35,6 +35,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[ crate::await_holding_invalid::AWAIT_HOLDING_REFCELL_REF_INFO, crate::bit_width::MANUAL_BIT_WIDTH_INFO, crate::bit_width::MISMATCHED_BIT_WIDTH_TYPE_INFO, + crate::block_scrutinee::BLOCK_SCRUTINEE_INFO, crate::blocks_in_conditions::BLOCKS_IN_CONDITIONS_INFO, crate::bool_assert_comparison::BOOL_ASSERT_COMPARISON_INFO, crate::bool_comparison::BOOL_COMPARISON_INFO, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 74e03c9b38592..7a233e09e8009 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -76,6 +76,7 @@ mod async_yields_async; mod attrs; mod await_holding_invalid; mod bit_width; +mod block_scrutinee; mod blocks_in_conditions; mod bool_assert_comparison; mod bool_comparison; @@ -866,6 +867,7 @@ rustc_lint::late_lint_methods!( RefPatterns: ref_patterns::RefPatterns = ref_patterns::RefPatterns, RedundantElse: redundant_else::RedundantElse = redundant_else::RedundantElse, RestWhenDestructuringStruct: rest_when_destructuring_struct::RestWhenDestructuringStruct = rest_when_destructuring_struct::RestWhenDestructuringStruct, + BlockScrutinee: block_scrutinee::BlockScrutinee = block_scrutinee::BlockScrutinee, // add late passes here, used by `cargo dev new_lint` ]] ); diff --git a/tests/ui/block_scrutinee.1.fixed b/tests/ui/block_scrutinee.1.fixed new file mode 100644 index 0000000000000..a5da489f24d91 --- /dev/null +++ b/tests/ui/block_scrutinee.1.fixed @@ -0,0 +1,60 @@ +//@ edition: 2021 +#![warn(clippy::block_scrutinee)] +#![allow(clippy::blocks_in_conditions)] +#![allow(clippy::let_and_return)] + +fn my_function() -> Option { + Some(1) +} + +fn main() { + if let Some(x) = my_function() { + //~^ ERROR: this scrutinee is wrapped in a block + let _ = x; + } + + match my_function() { + //~^ ERROR: this scrutinee is wrapped in a block + Some(1) => println!("one"), + Some(_) => println!("other"), + None => println!("none"), + } + + let mut v = vec![1, 2, 3]; + while let Some(x) = v.pop() { + //~^ ERROR: this scrutinee is wrapped in a block + let _ = x; + } + + if let Some(x) = my_function() { + let _ = x; + } + + if let Some(x) = { + let _y = 2; + my_function() + } { + let _ = x; + } + + //~v ERROR: this scrutinee is wrapped in a block + if let Some(x) = v.pop() { + let _ = x; + } + + macro_rules! get_val { + () => {{ my_function() }}; + } + if let Some(x) = get_val!() { + let _ = x; + } + + // Test that `unsafe` blocks are ignored + unsafe fn my_unsafe_fn() -> Option { + Some(1) + } + + if let Some(x) = unsafe { my_unsafe_fn() } { + let _ = x; + } +} diff --git a/tests/ui/block_scrutinee.2.fixed b/tests/ui/block_scrutinee.2.fixed new file mode 100644 index 0000000000000..c771895cbc7a5 --- /dev/null +++ b/tests/ui/block_scrutinee.2.fixed @@ -0,0 +1,64 @@ +//@ edition: 2021 +#![warn(clippy::block_scrutinee)] +#![allow(clippy::blocks_in_conditions)] +#![allow(clippy::let_and_return)] + +fn my_function() -> Option { + Some(1) +} + +fn main() { + let res = my_function(); + if let Some(x) = res { + //~^ ERROR: this scrutinee is wrapped in a block + let _ = x; + } + + let res = my_function(); + match res { + //~^ ERROR: this scrutinee is wrapped in a block + Some(1) => println!("one"), + Some(_) => println!("other"), + None => println!("none"), + } + + let mut v = vec![1, 2, 3]; + let res = v.pop(); + while let Some(x) = res { + //~^ ERROR: this scrutinee is wrapped in a block + let _ = x; + } + + if let Some(x) = my_function() { + let _ = x; + } + + if let Some(x) = { + let _y = 2; + my_function() + } { + let _ = x; + } + + //~v ERROR: this scrutinee is wrapped in a block + let res = v.pop(); + if let Some(x) = res { + let _ = x; + } + + macro_rules! get_val { + () => {{ my_function() }}; + } + if let Some(x) = get_val!() { + let _ = x; + } + + // Test that `unsafe` blocks are ignored + unsafe fn my_unsafe_fn() -> Option { + Some(1) + } + + if let Some(x) = unsafe { my_unsafe_fn() } { + let _ = x; + } +} diff --git a/tests/ui/block_scrutinee.rs b/tests/ui/block_scrutinee.rs new file mode 100644 index 0000000000000..07b763baaee17 --- /dev/null +++ b/tests/ui/block_scrutinee.rs @@ -0,0 +1,63 @@ +//@ edition: 2021 +#![warn(clippy::block_scrutinee)] +#![allow(clippy::blocks_in_conditions)] +#![allow(clippy::let_and_return)] + +fn my_function() -> Option { + Some(1) +} + +fn main() { + if let Some(x) = { my_function() } { + //~^ ERROR: this scrutinee is wrapped in a block + let _ = x; + } + + match { my_function() } { + //~^ ERROR: this scrutinee is wrapped in a block + Some(1) => println!("one"), + Some(_) => println!("other"), + None => println!("none"), + } + + let mut v = vec![1, 2, 3]; + while let Some(x) = { v.pop() } { + //~^ ERROR: this scrutinee is wrapped in a block + let _ = x; + } + + if let Some(x) = my_function() { + let _ = x; + } + + if let Some(x) = { + let _y = 2; + my_function() + } { + let _ = x; + } + + //~v ERROR: this scrutinee is wrapped in a block + if let Some(x) = { + // We are popping a value + v.pop() + } { + let _ = x; + } + + macro_rules! get_val { + () => {{ my_function() }}; + } + if let Some(x) = get_val!() { + let _ = x; + } + + // Test that `unsafe` blocks are ignored + unsafe fn my_unsafe_fn() -> Option { + Some(1) + } + + if let Some(x) = unsafe { my_unsafe_fn() } { + let _ = x; + } +} diff --git a/tests/ui/block_scrutinee.stderr b/tests/ui/block_scrutinee.stderr new file mode 100644 index 0000000000000..b44f742af22fa --- /dev/null +++ b/tests/ui/block_scrutinee.stderr @@ -0,0 +1,87 @@ +error: this scrutinee is wrapped in a block + --> tests/ui/block_scrutinee.rs:11:22 + | +LL | if let Some(x) = { my_function() } { + | ^^^^^^^^^^^^^^^^^ + | + = note: temporary values in this block-wrapped scrutinee will be dropped after the body of the `if let` statement + = note: starting with the 2024 edition, temporaries within a block's final expression are dropped immediately at the end of the block + = note: `-D clippy::block-scrutinee` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::block_scrutinee)]` +help: to drop temporaries after the surrounding `if let`, remove the block + | +LL - if let Some(x) = { my_function() } { +LL + if let Some(x) = my_function() { + | +help: to drop temporaries early, move them to a separate local binding (or update your `Cargo.toml` to the 2024 edition) + | +LL ~ let res = my_function(); +LL ~ if let Some(x) = res { + | + +error: this scrutinee is wrapped in a block + --> tests/ui/block_scrutinee.rs:16:11 + | +LL | match { my_function() } { + | ^^^^^^^^^^^^^^^^^ + | + = note: temporary values in this block-wrapped scrutinee will be dropped after the body of the `match` statement + = note: starting with the 2024 edition, temporaries within a block's final expression are dropped immediately at the end of the block +help: to drop temporaries after the surrounding `match`, remove the block + | +LL - match { my_function() } { +LL + match my_function() { + | +help: to drop temporaries early, move them to a separate local binding (or update your `Cargo.toml` to the 2024 edition) + | +LL ~ let res = my_function(); +LL ~ match res { + | + +error: this scrutinee is wrapped in a block + --> tests/ui/block_scrutinee.rs:24:25 + | +LL | while let Some(x) = { v.pop() } { + | ^^^^^^^^^^^ + | + = note: temporary values in this block-wrapped scrutinee will be dropped after the body of the `while let` statement + = note: starting with the 2024 edition, temporaries within a block's final expression are dropped immediately at the end of the block +help: to drop temporaries after the surrounding `while let`, remove the block + | +LL - while let Some(x) = { v.pop() } { +LL + while let Some(x) = v.pop() { + | +help: to drop temporaries early, move them to a separate local binding (or update your `Cargo.toml` to the 2024 edition) + | +LL ~ let res = v.pop(); +LL ~ while let Some(x) = res { + | + +error: this scrutinee is wrapped in a block + --> tests/ui/block_scrutinee.rs:41:22 + | +LL | if let Some(x) = { + | ______________________^ +LL | | // We are popping a value +LL | | v.pop() +LL | | } { + | |_____^ + | + = note: temporary values in this block-wrapped scrutinee will be dropped after the body of the `if let` statement + = note: starting with the 2024 edition, temporaries within a block's final expression are dropped immediately at the end of the block +help: to drop temporaries after the surrounding `if let`, remove the block + | +LL - if let Some(x) = { +LL - // We are popping a value +LL - v.pop() +LL - } { +LL + if let Some(x) = v.pop() { + | +help: to drop temporaries early, move them to a separate local binding (or update your `Cargo.toml` to the 2024 edition) + | +LL ~ let res = v.pop(); +LL ~ if let Some(x) = res { + | + +error: aborting due to 4 previous errors + diff --git a/tests/ui/block_scrutinee_2024.rs b/tests/ui/block_scrutinee_2024.rs new file mode 100644 index 0000000000000..e3b3a7b42d59c --- /dev/null +++ b/tests/ui/block_scrutinee_2024.rs @@ -0,0 +1,28 @@ +//@ edition: 2024 +//@ check-pass +#![warn(clippy::block_scrutinee)] +#![allow(clippy::blocks_in_conditions)] + +fn my_function() -> Option { + Some(1) +} + +fn main() { + // This should NOT trigger the lint on the 2024 edition + if let Some(x) = { my_function() } { + let _ = x; + } + + // This should NOT trigger the lint on the 2024 edition + match { my_function() } { + Some(1) => println!("one"), + Some(_) => println!("other"), + None => println!("none"), + } + + // This should NOT trigger the lint on the 2024 edition + let mut v = vec![1, 2, 3]; + while let Some(x) = { v.pop() } { + let _ = x; + } +} From 1244629419261375a2ace6eadfe39a5892693c6e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 13 Jul 2026 17:58:36 +1000 Subject: [PATCH 49/63] Improve an attribute check Once `sym::ignore` has been matched, the attribute can't be a `DocComment` and trying to match one is pointless. --- clippy_lints/src/attrs/mod.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs index 78701b3368226..9b481952c98ee 100644 --- a/clippy_lints/src/attrs/mod.rs +++ b/clippy_lints/src/attrs/mod.rs @@ -614,12 +614,8 @@ impl EarlyLintPass for PostExpansionEarlyAttributes { } if attr.has_name(sym::ignore) - && match &attr.kind { - AttrKind::Normal(normal_attr) => { - !matches!(normal_attr.item.args, AttrItemKind::Unparsed(AttrArgs::Eq { .. })) - }, - AttrKind::DocComment(..) => true, - } + && let AttrKind::Normal(normal_attr) = &attr.kind + && !matches!(normal_attr.item.args, AttrItemKind::Unparsed(AttrArgs::Eq { .. })) { span_lint_and_help( cx, From 13bdce3b36dc760a756b0e4c3507949a1a34662d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 13 Jul 2026 10:46:23 +1000 Subject: [PATCH 50/63] Remove `AttrItemKind` `AttrItem` currently contains an `AttrItemKind` which is either `Parsed` or `Unparsed`. In the `Parsed` case the surrounding `AttrItem` is basically fake, with a meaningless `unsafety` field, a synthetic (non-ident) symbol, and an empty `tokens`. This commit moves `Parsed` up one level to become a new variant of `AttrKind`. It no longer needs to pretend to be an `AttrKind::Normal`, and makes a number of things simpler: - No `unparsed_ref` calls needed. - Replaces the `attr_into_trace` and `Attribute::replace_args` mess with the much simpler `convert_normal_to_parsed`. The commit converts a numberof non-exhaustive `AttrKind` matches (those that don't involve matching a single attribute) to exhaustive, for future-proofing. It uses `unreachable!` on all the `AttrKind::Parsed` cases that aren't hit by the full test suite. --- .../src/attrs/mixed_attributes_style.rs | 10 +++++- clippy_lints/src/attrs/mod.rs | 4 +-- .../src/attrs/should_panic_without_expect.rs | 6 ++-- clippy_lints/src/cfg_not_test.rs | 33 +++++++++---------- .../src/doc/include_in_doc_without_cfg.rs | 6 ++-- clippy_lints/src/empty_line_after.rs | 2 +- clippy_lints/src/large_include_file.rs | 6 ++-- clippy_utils/src/ast_utils/mod.rs | 15 +++------ clippy_utils/src/check_proc_macro.rs | 1 + 9 files changed, 41 insertions(+), 42 deletions(-) diff --git a/clippy_lints/src/attrs/mixed_attributes_style.rs b/clippy_lints/src/attrs/mixed_attributes_style.rs index d71c8e9894bf7..6dc3ec13cf2c3 100644 --- a/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -1,6 +1,6 @@ use super::MIXED_ATTRIBUTES_STYLE; use clippy_utils::diagnostics::span_lint; -use rustc_ast::{AttrKind, AttrStyle, Attribute}; +use rustc_ast::{AttrKind, AttrStyle, Attribute, EarlyParsedAttribute}; use rustc_data_structures::fx::FxHashSet; use rustc_lint::{EarlyContext, LintContext}; use rustc_span::source_map::SourceMap; @@ -12,6 +12,8 @@ enum SimpleAttrKind { Doc, /// A normal attribute, with its name symbols. Normal(Vec), + CfgTrace, + CfgAttrTrace, } impl From<&AttrKind> for SimpleAttrKind { @@ -27,6 +29,12 @@ impl From<&AttrKind> for SimpleAttrKind { .collect::>(); Self::Normal(path_symbols) }, + AttrKind::Parsed(parsed) => { + match &**parsed { + EarlyParsedAttribute::CfgTrace(_) => Self::CfgTrace, + EarlyParsedAttribute::CfgAttrTrace => Self::CfgAttrTrace, + } + } AttrKind::DocComment(..) => Self::Doc, } } diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs index 9b481952c98ee..2833619814cc3 100644 --- a/clippy_lints/src/attrs/mod.rs +++ b/clippy_lints/src/attrs/mod.rs @@ -17,7 +17,7 @@ use clippy_config::Conf; use clippy_utils::check_clippy_attr; use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::msrvs::{self, Msrv, MsrvStack}; -use rustc_ast::{self as ast, AttrArgs, AttrItemKind, AttrKind, Attribute, MetaItemInner, MetaItemKind}; +use rustc_ast::{self as ast, AttrArgs, AttrKind, Attribute, MetaItemInner, MetaItemKind}; use rustc_hir::{ImplItem, ImplItemKind, Item, ItemKind, TraitFn, TraitItem, TraitItemKind}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; use rustc_session::impl_lint_pass; @@ -615,7 +615,7 @@ impl EarlyLintPass for PostExpansionEarlyAttributes { if attr.has_name(sym::ignore) && let AttrKind::Normal(normal_attr) = &attr.kind - && !matches!(normal_attr.item.args, AttrItemKind::Unparsed(AttrArgs::Eq { .. })) + && !matches!(normal_attr.item.args, AttrArgs::Eq { .. }) { span_lint_and_help( cx, diff --git a/clippy_lints/src/attrs/should_panic_without_expect.rs b/clippy_lints/src/attrs/should_panic_without_expect.rs index 1a9abd88a46ae..fd27e30a67f3b 100644 --- a/clippy_lints/src/attrs/should_panic_without_expect.rs +++ b/clippy_lints/src/attrs/should_panic_without_expect.rs @@ -2,19 +2,19 @@ use super::{Attribute, SHOULD_PANIC_WITHOUT_EXPECT}; use clippy_utils::diagnostics::span_lint_and_sugg; use rustc_ast::token::{Token, TokenKind}; use rustc_ast::tokenstream::TokenTree; -use rustc_ast::{AttrArgs, AttrItemKind, AttrKind}; +use rustc_ast::{AttrArgs, AttrKind}; use rustc_errors::Applicability; use rustc_lint::EarlyContext; use rustc_span::sym; pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) { if let AttrKind::Normal(normal_attr) = &attr.kind { - if let AttrItemKind::Unparsed(AttrArgs::Eq { .. }) = &normal_attr.item.args { + if let AttrArgs::Eq { .. } = &normal_attr.item.args { // `#[should_panic = ".."]` found, good return; } - if let AttrItemKind::Unparsed(AttrArgs::Delimited(args)) = &normal_attr.item.args + if let AttrArgs::Delimited(args) = &normal_attr.item.args && let mut tt_iter = args.tokens.iter() && let Some(TokenTree::Token( Token { diff --git a/clippy_lints/src/cfg_not_test.rs b/clippy_lints/src/cfg_not_test.rs index 88d07be0d4d46..a769954696c8a 100644 --- a/clippy_lints/src/cfg_not_test.rs +++ b/clippy_lints/src/cfg_not_test.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast::attr::data_structures::CfgEntry; -use rustc_ast::{AttrItemKind, EarlyParsedAttribute}; +use rustc_ast::{AttrKind, EarlyParsedAttribute}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -34,23 +34,20 @@ declare_lint_pass!(CfgNotTest => [CFG_NOT_TEST]); impl EarlyLintPass for CfgNotTest { fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &rustc_ast::Attribute) { - if attr.has_name(sym::cfg_trace) { - let AttrItemKind::Parsed(EarlyParsedAttribute::CfgTrace(cfg)) = &attr.get_normal_item().args else { - unreachable!() - }; - - if contains_not_test(cfg, false) { - span_lint_and_then( - cx, - CFG_NOT_TEST, - attr.span, - "code is excluded from test builds", - |diag| { - diag.help("consider not excluding any code from test builds"); - diag.note_once("this could increase code coverage despite not actually being tested"); - }, - ); - } + if let AttrKind::Parsed(parsed) = &attr.kind + && let EarlyParsedAttribute::CfgTrace(cfg) = &**parsed + && contains_not_test(cfg, false) + { + span_lint_and_then( + cx, + CFG_NOT_TEST, + attr.span, + "code is excluded from test builds", + |diag| { + diag.help("consider not excluding any code from test builds"); + diag.note_once("this could increase code coverage despite not actually being tested"); + }, + ); } } } diff --git a/clippy_lints/src/doc/include_in_doc_without_cfg.rs b/clippy_lints/src/doc/include_in_doc_without_cfg.rs index 6c800f47b68a9..0a4ef50f14bb3 100644 --- a/clippy_lints/src/doc/include_in_doc_without_cfg.rs +++ b/clippy_lints/src/doc/include_in_doc_without_cfg.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_opt; -use rustc_ast::{AttrArgs, AttrItemKind, AttrKind, AttrStyle, Attribute}; +use rustc_ast::{AttrArgs, AttrKind, AttrStyle, Attribute}; use rustc_errors::Applicability; use rustc_lint::EarlyContext; @@ -9,9 +9,9 @@ use super::DOC_INCLUDE_WITHOUT_CFG; pub fn check(cx: &EarlyContext<'_>, attrs: &[Attribute]) { for attr in attrs { if !attr.span.from_expansion() - && let AttrKind::Normal(ref item) = attr.kind + && let AttrKind::Normal(ref normal) = attr.kind && attr.doc_str().is_some() - && let AttrItemKind::Unparsed(AttrArgs::Eq { expr: meta, .. }) = &item.item.args + && let AttrArgs::Eq { expr: meta, .. } = &normal.item.args && !attr.span.contains(meta.span) // Since the `include_str` is already expanded at this point, we can only take the // whole attribute snippet and then modify for our suggestion. diff --git a/clippy_lints/src/empty_line_after.rs b/clippy_lints/src/empty_line_after.rs index f076c6d29138d..6eb5db1f7304a 100644 --- a/clippy_lints/src/empty_line_after.rs +++ b/clippy_lints/src/empty_line_after.rs @@ -251,7 +251,7 @@ impl Stop { Some(Self { span: attr.span, kind: match attr.kind { - AttrKind::Normal(_) => StopKind::Attr, + AttrKind::Normal(_) | AttrKind::Parsed(_) => StopKind::Attr, AttrKind::DocComment(comment_kind, _) => StopKind::Doc(comment_kind), }, first: file.lookup_line(file.relative_position(lo))?, diff --git a/clippy_lints/src/large_include_file.rs b/clippy_lints/src/large_include_file.rs index 39d252f4f3b6b..3c35c2fc9c82d 100644 --- a/clippy_lints/src/large_include_file.rs +++ b/clippy_lints/src/large_include_file.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::root_macro_call_first_node; use clippy_utils::source::snippet_opt; use clippy_utils::sym; -use rustc_ast::{AttrArgs, AttrItemKind, AttrKind, Attribute, LitKind}; +use rustc_ast::{AttrArgs, AttrKind, Attribute, LitKind}; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; use rustc_session::impl_lint_pass; @@ -89,10 +89,10 @@ impl EarlyLintPass for LargeIncludeFile { if !attr.span.from_expansion() // Currently, rustc limits the usage of macro at the top-level of attributes, // so we don't need to recurse into each level. - && let AttrKind::Normal(ref item) = attr.kind + && let AttrKind::Normal(ref normal) = attr.kind && let Some(doc) = attr.doc_str() && doc.as_str().len() as u64 > self.max_file_size - && let AttrItemKind::Unparsed(AttrArgs::Eq { expr: meta, .. }) = &item.item.args + && let AttrArgs::Eq { expr: meta, .. } = &normal.item.args && !attr.span.contains(meta.span) // Since the `include_str` is already expanded at this point, we can only take the // whole attribute snippet and then modify for our suggestion. diff --git a/clippy_utils/src/ast_utils/mod.rs b/clippy_utils/src/ast_utils/mod.rs index fe51f841bc8b6..ea9dfe32ab533 100644 --- a/clippy_utils/src/ast_utils/mod.rs +++ b/clippy_utils/src/ast_utils/mod.rs @@ -1004,20 +1004,13 @@ fn eq_attr(l: &Attribute, r: &Attribute) -> bool { && match (&l.kind, &r.kind) { (DocComment(l1, l2), DocComment(r1, r2)) => l1 == r1 && l2 == r2, (Normal(l), Normal(r)) => { - eq_path(&l.item.path, &r.item.path) && eq_attr_item_kind(&l.item.args, &r.item.args) + eq_path(&l.item.path, &r.item.path) && eq_attr_args(&l.item.args, &r.item.args) }, + (Parsed(..), _) | (_, Parsed(..)) => unreachable!(), _ => false, } } -fn eq_attr_item_kind(l: &AttrItemKind, r: &AttrItemKind) -> bool { - match (l, r) { - (AttrItemKind::Unparsed(l), AttrItemKind::Unparsed(r)) => eq_attr_args(l, r), - (AttrItemKind::Parsed(_l), AttrItemKind::Parsed(_r)) => todo!(), - _ => false, - } -} - fn eq_attr_args(l: &AttrArgs, r: &AttrArgs) -> bool { use AttrArgs::*; match (l, r) { @@ -1042,8 +1035,8 @@ pub fn is_cfg_test(item: &impl HasAttrs) -> bool { && item_list.iter().any(|item| item.has_name(sym::test)) { true - } else if attr.has_name(sym::cfg_trace) - && let AttrItemKind::Parsed(EarlyParsedAttribute::CfgTrace(cfg)) = &attr.get_normal_item().args + } else if let AttrKind::Parsed(parsed) = &attr.kind + && let EarlyParsedAttribute::CfgTrace(cfg) = &**parsed { requires_test_cfg(cfg) } else { diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 7b47141c9fb8a..b82240bf36d1e 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -369,6 +369,7 @@ fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) { (Pat::Str("#"), Pat::Str("]")) } }, + AttrKind::Parsed(..) => unreachable!(), AttrKind::DocComment(_kind @ CommentKind::Line, ..) => { if attr.style == AttrStyle::Outer { (Pat::Str("///"), Pat::Str("")) From 5d58075264b943bd3cd142dd93d0f4ed70ccb96b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 13 Jul 2026 21:01:59 +1000 Subject: [PATCH 51/63] Remove `sym::cfg_trace` and `sym::cfg_attr_trace` This commit pushes further than the previous one, relying more heavily on looking directly at `AttrKind::Parsed` to handle various cases. Note that the removed clippy code was actually dead. --- clippy_lints/src/attrs/duplicated_attributes.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/clippy_lints/src/attrs/duplicated_attributes.rs b/clippy_lints/src/attrs/duplicated_attributes.rs index c956738edf0eb..da9ace312f7d3 100644 --- a/clippy_lints/src/attrs/duplicated_attributes.rs +++ b/clippy_lints/src/attrs/duplicated_attributes.rs @@ -43,21 +43,12 @@ fn check_duplicated_attr( }; 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 - { + if name == sym::doc || 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( From 11671dcbbb1b0009f099f3cf6b7865ece8c19fa5 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 14 Jul 2026 12:45:32 +1000 Subject: [PATCH 52/63] Replace "early parsed" terminology AST attributes use "early parsed"/"parsed" terminology to refer to the `CfgTrace` and `CfgAttrTrace` attributes. I think this terminology is meant to echo the terminology used for HIR attributes, i.e. `hir::Attribute::{Parsed,Unparsed}`, probably because `hir::Attribute::Parsed` is used for attributes that aren't stored in a token-based form. But this naming is misleading. "Early parsed" attributes aren't parsed at all because they are inserted by the compiler and cannot be written in source code. There are also two comments that claim that these attributes are kept in parsed form "so they don't have to be reparsed every time they're used, for performance", which is simply incorrect. This commit renames these as "synthetic" attributes, which better reflects their nature. The commit also fixes the incorrect comments. Note that `is_parsed_attribute` is unchanged, because it refers to the HIR attribute meaning. (And the removal of the synthetic attributes from it in the previous commit is now more obviously correct.) --- clippy_lints/src/attrs/mixed_attributes_style.rs | 10 +++++----- clippy_lints/src/cfg_not_test.rs | 6 +++--- clippy_lints/src/empty_line_after.rs | 2 +- clippy_utils/src/ast_utils/mod.rs | 6 +++--- clippy_utils/src/check_proc_macro.rs | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/attrs/mixed_attributes_style.rs b/clippy_lints/src/attrs/mixed_attributes_style.rs index 6dc3ec13cf2c3..3e82ff4a69545 100644 --- a/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -1,6 +1,6 @@ use super::MIXED_ATTRIBUTES_STYLE; use clippy_utils::diagnostics::span_lint; -use rustc_ast::{AttrKind, AttrStyle, Attribute, EarlyParsedAttribute}; +use rustc_ast::{AttrKind, AttrStyle, Attribute, SyntheticAttr}; use rustc_data_structures::fx::FxHashSet; use rustc_lint::{EarlyContext, LintContext}; use rustc_span::source_map::SourceMap; @@ -29,10 +29,10 @@ impl From<&AttrKind> for SimpleAttrKind { .collect::>(); Self::Normal(path_symbols) }, - AttrKind::Parsed(parsed) => { - match &**parsed { - EarlyParsedAttribute::CfgTrace(_) => Self::CfgTrace, - EarlyParsedAttribute::CfgAttrTrace => Self::CfgAttrTrace, + AttrKind::Synthetic(synthetic) => { + match &**synthetic { + SyntheticAttr::CfgTrace(_) => Self::CfgTrace, + SyntheticAttr::CfgAttrTrace => Self::CfgAttrTrace, } } AttrKind::DocComment(..) => Self::Doc, diff --git a/clippy_lints/src/cfg_not_test.rs b/clippy_lints/src/cfg_not_test.rs index a769954696c8a..0a1ad883c2977 100644 --- a/clippy_lints/src/cfg_not_test.rs +++ b/clippy_lints/src/cfg_not_test.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_ast::attr::data_structures::CfgEntry; -use rustc_ast::{AttrKind, EarlyParsedAttribute}; +use rustc_ast::{AttrKind, SyntheticAttr}; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -34,8 +34,8 @@ declare_lint_pass!(CfgNotTest => [CFG_NOT_TEST]); impl EarlyLintPass for CfgNotTest { fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &rustc_ast::Attribute) { - if let AttrKind::Parsed(parsed) = &attr.kind - && let EarlyParsedAttribute::CfgTrace(cfg) = &**parsed + if let AttrKind::Synthetic(synthetic) = &attr.kind + && let SyntheticAttr::CfgTrace(cfg) = &**synthetic && contains_not_test(cfg, false) { span_lint_and_then( diff --git a/clippy_lints/src/empty_line_after.rs b/clippy_lints/src/empty_line_after.rs index 6eb5db1f7304a..834981a582832 100644 --- a/clippy_lints/src/empty_line_after.rs +++ b/clippy_lints/src/empty_line_after.rs @@ -251,7 +251,7 @@ impl Stop { Some(Self { span: attr.span, kind: match attr.kind { - AttrKind::Normal(_) | AttrKind::Parsed(_) => StopKind::Attr, + AttrKind::Normal(_) | AttrKind::Synthetic(_) => StopKind::Attr, AttrKind::DocComment(comment_kind, _) => StopKind::Doc(comment_kind), }, first: file.lookup_line(file.relative_position(lo))?, diff --git a/clippy_utils/src/ast_utils/mod.rs b/clippy_utils/src/ast_utils/mod.rs index ea9dfe32ab533..07c3d2e2f0ffe 100644 --- a/clippy_utils/src/ast_utils/mod.rs +++ b/clippy_utils/src/ast_utils/mod.rs @@ -1006,7 +1006,7 @@ fn eq_attr(l: &Attribute, r: &Attribute) -> bool { (Normal(l), Normal(r)) => { eq_path(&l.item.path, &r.item.path) && eq_attr_args(&l.item.args, &r.item.args) }, - (Parsed(..), _) | (_, Parsed(..)) => unreachable!(), + (Synthetic(..), _) | (_, Synthetic(..)) => unreachable!(), _ => false, } } @@ -1035,8 +1035,8 @@ pub fn is_cfg_test(item: &impl HasAttrs) -> bool { && item_list.iter().any(|item| item.has_name(sym::test)) { true - } else if let AttrKind::Parsed(parsed) = &attr.kind - && let EarlyParsedAttribute::CfgTrace(cfg) = &**parsed + } else if let AttrKind::Synthetic(synthetic) = &attr.kind + && let SyntheticAttr::CfgTrace(cfg) = &**synthetic { requires_test_cfg(cfg) } else { diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index b82240bf36d1e..412cdd41d0f2c 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -369,7 +369,7 @@ fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) { (Pat::Str("#"), Pat::Str("]")) } }, - AttrKind::Parsed(..) => unreachable!(), + AttrKind::Synthetic(..) => unreachable!(), AttrKind::DocComment(_kind @ CommentKind::Line, ..) => { if attr.style == AttrStyle::Outer { (Pat::Str("///"), Pat::Str("")) From 21a39ad6cc2d8054269393103d85856fdfe324ac Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Fri, 3 Apr 2026 10:56:53 +0200 Subject: [PATCH 53/63] feat: detect `== 0` on unsigned types as a `manual_clamp` lower bound --- clippy_lints/src/manual_clamp.rs | 46 +++++++++++++++++++++++- tests/ui/manual_clamp.fixed | 38 ++++++++++++++++++++ tests/ui/manual_clamp.rs | 61 ++++++++++++++++++++++++++++++++ tests/ui/manual_clamp.stderr | 56 ++++++++++++++++++++++++++++- 4 files changed, 199 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/manual_clamp.rs b/clippy_lints/src/manual_clamp.rs index a1a9266deaf96..407ddb3aaf20b 100644 --- a/clippy_lints/src/manual_clamp.rs +++ b/clippy_lints/src/manual_clamp.rs @@ -7,7 +7,7 @@ use clippy_utils::res::{MaybeDef as _, MaybeResPath as _, MaybeTypeckRes as _}; use clippy_utils::sugg::Sugg; use clippy_utils::ty::implements_trait; use clippy_utils::visitors::is_const_evaluatable; -use clippy_utils::{eq_expr_value, is_in_const_context, peel_blocks, peel_blocks_with_stmt, sym}; +use clippy_utils::{eq_expr_value, is_in_const_context, is_integer_literal, peel_blocks, peel_blocks_with_stmt, sym}; use itertools::Itertools as _; use rustc_errors::{Applicability, Diag}; use rustc_hir::def::Res; @@ -718,6 +718,9 @@ fn is_clamp_meta_pattern<'tcx>( if exprs.iter().any(|e| peel_blocks(e).can_have_side_effects()) { return None; } + let first_bin = try_normalize_unsigned_eq_to_ord(cx, first_bin, first_expr).unwrap_or(*first_bin); + let second_bin = try_normalize_unsigned_eq_to_ord(cx, second_bin, second_expr).unwrap_or(*second_bin); + let (first_bin, second_bin) = (&first_bin, &second_bin); if !(is_ord_op(first_bin.op) && is_ord_op(second_bin.op)) { return None; } @@ -771,6 +774,47 @@ fn is_ord_op(op: BinOpKind) -> bool { matches!(op, BinOpKind::Ge | BinOpKind::Gt | BinOpKind::Le | BinOpKind::Lt) } +/// For unsigned integer types, `x == 0` is equivalent to `x < 1`. This normalizes such `==` +/// comparisons to `<` when the result expression evaluates to 1, enabling clamp detection for +/// patterns like: +/// +/// ```ignore +/// if x == 0 { x = 1; } else if x > y { x = y; } +/// ``` +fn try_normalize_unsigned_eq_to_ord<'tcx>( + cx: &LateContext<'tcx>, + bin: &BinaryOp<'tcx>, + result_expr: &'tcx Expr<'tcx>, +) -> Option> { + if bin.op != BinOpKind::Eq { + return None; + } + + // both sides of the expression have the same type, so checking either of them is sufficient + if !matches!(cx.typeck_results().expr_ty(bin.left).kind(), rustc_middle::ty::Uint(_)) { + return None; + } + + // Handles both `x == 0` and the Yoda notation `0 == x`. + let input = if is_integer_literal(bin.right, 0) { + bin.left + } else if is_integer_literal(bin.left, 0) { + bin.right + } else { + return None; + }; + + if is_integer_literal(result_expr, 1) { + Some(BinaryOp { + op: BinOpKind::Lt, + left: input, + right: result_expr, + }) + } else { + None + } +} + /// Really similar to Cow, but doesn't have a `Clone` requirement. #[derive(Debug)] enum MaybeBorrowedStmtKind<'a> { diff --git a/tests/ui/manual_clamp.fixed b/tests/ui/manual_clamp.fixed index 4cd6fe60f381b..5b3670d46bfba 100644 --- a/tests/ui/manual_clamp.fixed +++ b/tests/ui/manual_clamp.fixed @@ -410,6 +410,44 @@ fn msrv_1_50() { let _ = input.clamp(CONST_MIN, CONST_MAX); } +const CONST_U32_MAX: u32 = 100; + +fn eq_unsigned_zero_lint() { + // == 0 on unsigned with result 1: equivalent to < 1 + let mut x0: u32 = 5; + x0 = x0.clamp(1, CONST_U32_MAX); + + // Flipped: `0 == x` + let mut x1: u32 = 5; + x1 = x1.clamp(1, CONST_U32_MAX); + + // Two separate if statements + let mut x2: u32 = 5; + x2 = x2.clamp(1, CONST_U32_MAX); + + // if-elseif-else (value) pattern + let input: u32 = 5; + let x3 = input.clamp(1, CONST_U32_MAX); +} + +fn eq_unsigned_zero_no_lint() { + // Result is not 1, so == 0 doesn't cover all values < 5. + let mut x0: u32 = 5; + if x0 == 0 { + x0 = 5; + } else if x0 > CONST_U32_MAX { + x0 = CONST_U32_MAX; + } + + // Signed type: not applicable + let mut x1: i32 = 5; + if x1 == 0 { + x1 = 1; + } else if x1 > CONST_MAX { + x1 = CONST_MAX; + } +} + const fn _const() { let (input, min, max) = (0, -1, 2); let _ = if input < min { diff --git a/tests/ui/manual_clamp.rs b/tests/ui/manual_clamp.rs index f0613501a8e85..04de0677893fd 100644 --- a/tests/ui/manual_clamp.rs +++ b/tests/ui/manual_clamp.rs @@ -527,6 +527,67 @@ fn msrv_1_50() { }; } +const CONST_U32_MAX: u32 = 100; + +fn eq_unsigned_zero_lint() { + // == 0 on unsigned with result 1: equivalent to < 1 + let mut x0: u32 = 5; + if x0 == 0 { + //~^ manual_clamp + x0 = 1; + } else if x0 > CONST_U32_MAX { + x0 = CONST_U32_MAX; + } + + // Flipped: `0 == x` + let mut x1: u32 = 5; + if 0 == x1 { + //~^ manual_clamp + x1 = 1; + } else if x1 > CONST_U32_MAX { + x1 = CONST_U32_MAX; + } + + // Two separate if statements + let mut x2: u32 = 5; + if x2 == 0 { + //~^ manual_clamp + x2 = 1; + } + if x2 > CONST_U32_MAX { + x2 = CONST_U32_MAX; + } + + // if-elseif-else (value) pattern + let input: u32 = 5; + let x3 = if input == 0 { + //~^ manual_clamp + 1 + } else if input > CONST_U32_MAX { + CONST_U32_MAX + } else { + input + }; +} + +fn eq_unsigned_zero_no_lint() { + // Result is not 1, so == 0 doesn't cover all values < 5. + let mut x0: u32 = 5; + if x0 == 0 { + x0 = 5; + } else if x0 > CONST_U32_MAX { + x0 = CONST_U32_MAX; + } + + // Signed type: not applicable + let mut x1: i32 = 5; + if x1 == 0 { + x1 = 1; + } else if x1 > CONST_MAX { + x1 = CONST_MAX; + } +} + const fn _const() { let (input, min, max) = (0, -1, 2); let _ = if input < min { diff --git a/tests/ui/manual_clamp.stderr b/tests/ui/manual_clamp.stderr index 4876e2eb1cd1f..11568be6b22da 100644 --- a/tests/ui/manual_clamp.stderr +++ b/tests/ui/manual_clamp.stderr @@ -398,5 +398,59 @@ LL | | }; | = note: clamp will panic if max < min -error: aborting due to 35 previous errors +error: clamp-like pattern without using clamp function + --> tests/ui/manual_clamp.rs:553:5 + | +LL | / if x2 == 0 { +LL | | +LL | | x2 = 1; +... | +LL | | x2 = CONST_U32_MAX; +LL | | } + | |_____^ help: replace with clamp: `x2 = x2.clamp(1, CONST_U32_MAX);` + | + = note: clamp will panic if max < min + +error: clamp-like pattern without using clamp function + --> tests/ui/manual_clamp.rs:535:5 + | +LL | / if x0 == 0 { +LL | | +LL | | x0 = 1; +LL | | } else if x0 > CONST_U32_MAX { +LL | | x0 = CONST_U32_MAX; +LL | | } + | |_____^ help: replace with clamp: `x0 = x0.clamp(1, CONST_U32_MAX);` + | + = note: clamp will panic if max < min + +error: clamp-like pattern without using clamp function + --> tests/ui/manual_clamp.rs:544:5 + | +LL | / if 0 == x1 { +LL | | +LL | | x1 = 1; +LL | | } else if x1 > CONST_U32_MAX { +LL | | x1 = CONST_U32_MAX; +LL | | } + | |_____^ help: replace with clamp: `x1 = x1.clamp(1, CONST_U32_MAX);` + | + = note: clamp will panic if max < min + +error: clamp-like pattern without using clamp function + --> tests/ui/manual_clamp.rs:563:14 + | +LL | let x3 = if input == 0 { + | ______________^ +LL | | +LL | | 1 +LL | | } else if input > CONST_U32_MAX { +... | +LL | | input +LL | | }; + | |_____^ help: replace with clamp: `input.clamp(1, CONST_U32_MAX)` + | + = note: clamp will panic if max < min + +error: aborting due to 39 previous errors From b5369f9717b02f7c1dba19dd425593cfe13b963b Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 24 Feb 2026 23:48:25 +0100 Subject: [PATCH 54/63] Use `#[must_use]` determination from the compiler --- clippy_lints/src/functions/mod.rs | 8 ++- clippy_lints/src/functions/must_use.rs | 10 +-- clippy_lints/src/return_self_not_must_use.rs | 2 +- clippy_utils/src/ty/mod.rs | 66 +++++--------------- tests/ui/double_must_use.stderr | 12 ++-- tests/ui/double_must_use_unfixable.stderr | 4 +- tests/ui/must_use_candidates.fixed | 14 ++++- tests/ui/must_use_candidates.rs | 15 ++++- tests/ui/must_use_candidates.stderr | 22 ++----- 9 files changed, 61 insertions(+), 92 deletions(-) diff --git a/clippy_lints/src/functions/mod.rs b/clippy_lints/src/functions/mod.rs index 7c5fd760a7da8..7cd7cec1248a3 100644 --- a/clippy_lints/src/functions/mod.rs +++ b/clippy_lints/src/functions/mod.rs @@ -25,7 +25,7 @@ declare_clippy_lint! { /// ### What it does /// Checks for a `#[must_use]` attribute without /// further information on functions and methods that return a type already - /// marked as `#[must_use]`. + /// considered as `#[must_use]`. /// /// ### Why is this bad? /// The attribute isn't needed. Not using the result @@ -39,6 +39,12 @@ declare_clippy_lint! { /// unimplemented!(); /// } /// ``` + /// + /// ### Note + /// The compiler may consider a type as being indirectly `#[must_use]`. For + /// example, although `Box<_>` itself is not `#[must_use]`, `Box` will be + /// considered `#[must_use]` if `T` is. + /// ``` #[clippy::version = "1.40.0"] pub DOUBLE_MUST_USE, style, diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index e7b7b18967a07..3328597a165fe 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -1,4 +1,3 @@ -use clippy_utils::res::MaybeDef as _; use hir::FnSig; use rustc_errors::Applicability; use rustc_hir::def::Res; @@ -174,7 +173,7 @@ fn check_needless_must_use( cx, DOUBLE_MUST_USE, fn_header_span, - "this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]`", + "this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]`", |diag| { // When there are multiple attributes, it is not sufficient to simply make `must_use` empty, see // issue #12320. @@ -220,13 +219,6 @@ fn check_must_use_candidate<'tcx>( format!("#[must_use]\n{indent}"), Applicability::MachineApplicable, ); - if let Some(msg) = match return_ty(cx, item_id).opt_diag_name(cx) { - Some(sym::ControlFlow) => Some("`ControlFlow` as `C` when `B` is uninhabited"), - Some(sym::Result) => Some("`Result` as `T` when `E` is uninhabited"), - _ => None, - } { - diag.note(format!("a future version of Rust will treat {msg} wrt `#[must_use]`")); - } }); } diff --git a/clippy_lints/src/return_self_not_must_use.rs b/clippy_lints/src/return_self_not_must_use.rs index beba2e2a6b4c5..a2bf2c8ccf1a3 100644 --- a/clippy_lints/src/return_self_not_must_use.rs +++ b/clippy_lints/src/return_self_not_must_use.rs @@ -86,7 +86,7 @@ fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, spa // For this check, we don't want to remove the reference on the returned type because if // there is one, we shouldn't emit a warning! && self_arg.peel_refs() == ret_ty - // If `Self` is already marked as `#[must_use]`, no need for the attribute here. + // If `Self` is already considered as `#[must_use]`, no need for the attribute here. && !is_must_use_ty(cx, ret_ty) { span_lint_and_help( diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index c4de2aebad586..8569cf08ce037 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -9,10 +9,11 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; -use rustc_hir::{Expr, FnDecl, LangItem, find_attr}; +use rustc_hir::{Expr, ExprKind, FnDecl, LangItem}; use rustc_hir_analysis::lower_ty; use rustc_infer::infer::TyCtxtInferExt as _; use rustc_lint::LateContext; +use rustc_lint::unused::must_use::{IsTyMustUse, is_ty_must_use}; use rustc_middle::mir::ConstValue; use rustc_middle::mir::interpret::Scalar; use rustc_middle::traits::EvaluationResult; @@ -319,55 +320,22 @@ pub fn has_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } } -// Returns whether the `ty` has `#[must_use]` attribute. If `ty` is a `Result`/`ControlFlow` -// whose `Err`/`Break` payload is an uninhabited type, the `Ok`/`Continue` payload type -// will be used instead. See . +/// Returns whether the `ty` has `#[must_use]` attribute, or acts like it does according to the +/// compiler determination. For example, if `ty` is a `Result`/`ControlFlow` whose `Err`/`Break` +/// payload is an uninhabited type, the `Ok`/`Continue` payload type will be used instead. pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - match ty.kind() { - ty::Adt(adt, args) => match cx.tcx.get_diagnostic_name(adt.did()) { - Some(sym::Result) if args.type_at(1).is_privately_uninhabited(cx.tcx, cx.typing_env()) => { - is_must_use_ty(cx, args.type_at(0)) - }, - Some(sym::ControlFlow) if args.type_at(0).is_privately_uninhabited(cx.tcx, cx.typing_env()) => { - is_must_use_ty(cx, args.type_at(1)) - }, - _ => find_attr!(cx.tcx, adt.did(), MustUse { .. }), - }, - ty::Foreign(did) => find_attr!(cx.tcx, *did, MustUse { .. }), - ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty, _) | ty::Ref(_, ty, _) => { - // for the Array case we don't need to care for the len == 0 case - // because we don't want to lint functions returning empty arrays - is_must_use_ty(cx, *ty) - }, - ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Alias( - _, - AliasTy { - kind: ty::Opaque { def_id }, - .. - }, - ) => { - for (predicate, _) in cx.tcx.explicit_item_self_bounds(*def_id).skip_binder() { - if let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() - && find_attr!(cx.tcx, trait_predicate.trait_ref.def_id, MustUse { .. }) - { - return true; - } - } - false - }, - ty::Dynamic(binder, _) => { - for predicate in *binder { - if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() - && find_attr!(cx.tcx, trait_ref.def_id, MustUse { .. }) - { - return true; - } - } - false - }, - _ => false, - } + // `is_ty_must_use` requires an expression, whose `hir_id` will be used to determine whether + // certain types are visibly uninhabited from the module containing the expression. + // `cx.last_node_with_lint_attrs` is initialized to the crate/module `hir_id` when linting + // a new crate/module. If it is overriden, it is with an `hir_id` pertaining to the same + // create/module. We can use this in a dummy expression instead of asking all callers + // to provide a local `hir_id` which would not add more information. + let dummy_expr = Expr { + hir_id: cx.last_node_with_lint_attrs, + span: DUMMY_SP, + kind: ExprKind::Ret(None), + }; + matches!(is_ty_must_use(cx, ty, &dummy_expr), IsTyMustUse::Yes(_)) } /// Returns `true` if the given type is a non aggregate primitive (a `bool` or `char`, any diff --git a/tests/ui/double_must_use.stderr b/tests/ui/double_must_use.stderr index 89189bcc49fef..29c004959c103 100644 --- a/tests/ui/double_must_use.stderr +++ b/tests/ui/double_must_use.stderr @@ -1,4 +1,4 @@ -error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` +error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` --> tests/ui/double_must_use.rs:8:1 | LL | #[must_use] @@ -10,7 +10,7 @@ LL | pub fn must_use_result() -> Result<(), ()> { = note: `-D clippy::double-must-use` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::double_must_use)]` -error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` +error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` --> tests/ui/double_must_use.rs:15:1 | LL | #[must_use] @@ -20,7 +20,7 @@ LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { | = note: alternatively, you may add an explicit reason to the `must_use` attribute -error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` +error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` --> tests/ui/double_must_use.rs:22:1 | LL | #[must_use] @@ -30,7 +30,7 @@ LL | pub fn must_use_array() -> [Result<(), ()>; 1] { | = note: alternatively, you may add an explicit reason to the `must_use` attribute -error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` +error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` --> tests/ui/double_must_use.rs:40:1 | LL | #[must_use] @@ -40,7 +40,7 @@ LL | async fn async_must_use_result() -> Result<(), ()> { | = note: alternatively, you may add an explicit reason to the `must_use` attribute -error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` +error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` --> tests/ui/double_must_use.rs:55:1 | LL | #[must_use] @@ -50,7 +50,7 @@ LL | pub fn must_use_result_with_uninhabited_2() -> Result { | = note: alternatively, you may add an explicit reason to the `must_use` attribute -error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` +error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` --> tests/ui/double_must_use.rs:66:1 | LL | #[must_use] diff --git a/tests/ui/double_must_use_unfixable.stderr b/tests/ui/double_must_use_unfixable.stderr index ce3de9e36de88..5d9c02e5d6cea 100644 --- a/tests/ui/double_must_use_unfixable.stderr +++ b/tests/ui/double_must_use_unfixable.stderr @@ -1,4 +1,4 @@ -error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` +error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` --> tests/ui/double_must_use_unfixable.rs:6:1 | LL | pub fn issue_12320() -> Result<(), ()> { @@ -13,7 +13,7 @@ LL | #[cfg_attr(all(), must_use, deprecated)] = note: `-D clippy::double-must-use` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::double_must_use)]` -error: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` +error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` --> tests/ui/double_must_use_unfixable.rs:12:1 | LL | pub fn issue_12320_2() -> Result<(), ()> { diff --git a/tests/ui/must_use_candidates.fixed b/tests/ui/must_use_candidates.fixed index 226fafccddced..8aac045cad089 100644 --- a/tests/ui/must_use_candidates.fixed +++ b/tests/ui/must_use_candidates.fixed @@ -105,12 +105,20 @@ pub fn main() -> std::process::ExitCode { //~v must_use_candidate #[must_use] -pub fn result_uninhabited() -> Result { +pub fn result_uninhabited_1() -> Result { todo!() } -//~v must_use_candidate #[must_use] -pub fn controlflow_uninhabited() -> std::ops::ControlFlow { +pub struct T; + +// Do not lint, `T` is `#[must_use]`, so the `Result` also is. +pub fn result_uninhabited_2() -> Result { + todo!() +} + +// Do not lint: even though `Box` itself is not `#[must_use]`, if the content is (which is +// the case of `T`), the compiler will treat the box as a `#[must_use]` type already. +pub fn with_box() -> Box { todo!() } diff --git a/tests/ui/must_use_candidates.rs b/tests/ui/must_use_candidates.rs index f9b6c2986504c..d0e2dbd3d62de 100644 --- a/tests/ui/must_use_candidates.rs +++ b/tests/ui/must_use_candidates.rs @@ -99,11 +99,20 @@ pub fn main() -> std::process::ExitCode { } //~v must_use_candidate -pub fn result_uninhabited() -> Result { +pub fn result_uninhabited_1() -> Result { todo!() } -//~v must_use_candidate -pub fn controlflow_uninhabited() -> std::ops::ControlFlow { +#[must_use] +pub struct T; + +// Do not lint, `T` is `#[must_use]`, so the `Result` also is. +pub fn result_uninhabited_2() -> Result { + todo!() +} + +// Do not lint: even though `Box` itself is not `#[must_use]`, if the content is (which is +// the case of `T`), the compiler will treat the box as a `#[must_use]` type already. +pub fn with_box() -> Box { todo!() } diff --git a/tests/ui/must_use_candidates.stderr b/tests/ui/must_use_candidates.stderr index 24fda87cd16aa..9f6beaf19595d 100644 --- a/tests/ui/must_use_candidates.stderr +++ b/tests/ui/must_use_candidates.stderr @@ -63,28 +63,14 @@ LL | pub fn arcd(_x: Arc) -> bool { error: this function could have a `#[must_use]` attribute --> tests/ui/must_use_candidates.rs:102:8 | -LL | pub fn result_uninhabited() -> Result { - | ^^^^^^^^^^^^^^^^^^ +LL | pub fn result_uninhabited_1() -> Result { + | ^^^^^^^^^^^^^^^^^^^^ | - = note: a future version of Rust will treat `Result` as `T` when `E` is uninhabited wrt `#[must_use]` help: add the attribute | LL + #[must_use] -LL | pub fn result_uninhabited() -> Result { +LL | pub fn result_uninhabited_1() -> Result { | -error: this function could have a `#[must_use]` attribute - --> tests/ui/must_use_candidates.rs:107:8 - | -LL | pub fn controlflow_uninhabited() -> std::ops::ControlFlow { - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: a future version of Rust will treat `ControlFlow` as `C` when `B` is uninhabited wrt `#[must_use]` -help: add the attribute - | -LL + #[must_use] -LL | pub fn controlflow_uninhabited() -> std::ops::ControlFlow { - | - -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors From 81977198127ad4730a3d1313c9a3b0581abbbd40 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 3 Jun 2026 12:10:00 +0200 Subject: [PATCH 55/63] Use better error message for `#[must_use]` types This is inspired by the compiler. Ideally, this function should be provided by the compiler itself. --- clippy_lints/src/drop_forget_ref.rs | 4 +- clippy_lints/src/functions/must_use.rs | 21 ++++- clippy_lints/src/let_underscore.rs | 10 +- clippy_lints/src/return_self_not_must_use.rs | 4 +- clippy_utils/src/ty/mod.rs | 99 +++++++++++++++++++- tests/ui/double_must_use.stderr | 25 +++++ tests/ui/let_underscore_must_use.rs | 3 + tests/ui/let_underscore_must_use.stderr | 58 +++++++++++- 8 files changed, 205 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 560c365a988b7..080569c813911 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_must_use_func_call; use clippy_utils::res::MaybeDef as _; -use clippy_utils::ty::{is_copy, is_must_use_ty}; +use clippy_utils::ty::{is_copy, opt_must_use_path}; use rustc_hir::{Arm, Expr, ExprKind, LangItem, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { sym::mem_drop if !(arg_ty.needs_drop(cx.tcx, cx.typing_env()) || is_must_use_func_call(cx, arg) - || is_must_use_ty(cx, arg_ty) + || opt_must_use_path(cx, arg_ty).is_some() || drop_is_single_call_in_arm) => { (DROP_NON_DROP, DROP_NON_DROP_SUMMARY.into(), Some(arg.span)) diff --git a/clippy_lints/src/functions/must_use.rs b/clippy_lints/src/functions/must_use.rs index 3328597a165fe..1b7db66366b87 100644 --- a/clippy_lints/src/functions/must_use.rs +++ b/clippy_lints/src/functions/must_use.rs @@ -3,6 +3,7 @@ use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::def_id::DefIdSet; use rustc_hir::{self as hir, Attribute, QPath, find_attr}; +use rustc_lint::unused::must_use::MustUsePath; use rustc_lint::{LateContext, LintContext as _}; use rustc_middle::ty::{self, Ty}; use rustc_span::{Span, sym}; @@ -10,7 +11,7 @@ use rustc_span::{Span, sym}; use clippy_utils::attrs::is_proc_macro; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_indent; -use clippy_utils::ty::is_must_use_ty; +use clippy_utils::ty::{describe_must_use_type, opt_must_use_path}; use clippy_utils::visitors::for_each_expr_without_closures; use clippy_utils::{is_entrypoint_fn, return_ty, trait_ref_of_method}; use rustc_span::Symbol; @@ -160,11 +161,13 @@ fn check_needless_must_use( } }, ); - } else if reason.is_none() && is_must_use_ty(cx, return_ty(cx, item_id)) { + } else if reason.is_none() + && let Some(return_must_use_path) = opt_must_use_path(cx, return_ty(cx, item_id)) + { // Ignore async functions unless Future::Output type is a must_use type if sig.header.is_async() && let Some(future_ty) = cx.tcx.get_impl_future_output_ty(return_ty(cx, item_id)) - && !is_must_use_ty(cx, future_ty) + && opt_must_use_path(cx, future_ty).is_none() { return; } @@ -175,6 +178,16 @@ fn check_needless_must_use( fn_header_span, "this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]`", |diag| { + // Add info about the reason why the return type is `#[must_use]` if it is a compound type. + if !matches!(return_must_use_path, MustUsePath::Def(..)) { + diag.span_note( + sig.decl.output.span(), + format!( + "the return type is {}", + describe_must_use_type(cx, &return_must_use_path) + ), + ); + } // When there are multiple attributes, it is not sufficient to simply make `must_use` empty, see // issue #12320. // FIXME(jdonszelmann): this used to give a machine-applicable fix. However, it was super fragile, @@ -205,7 +218,7 @@ fn check_must_use_candidate<'tcx>( || item_span.in_external_macro(cx.sess().source_map()) || returns_unit(decl) || !cx.effective_visibilities.is_exported(item_id.def_id) - || is_must_use_ty(cx, return_ty(cx, item_id)) + || opt_must_use_path(cx, return_ty(cx, item_id)).is_some() || item_span.from_expansion() || is_entrypoint_fn(cx, item_id.def_id.to_def_id()) { diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index ca69f92aeda8b..97a79cfccb9e4 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::ty::{implements_trait, is_must_use_ty}; +use clippy_utils::ty::{describe_must_use_type, implements_trait, opt_must_use_path}; use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths}; use rustc_hir::{LetStmt, LocalSource, PatKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -176,8 +176,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { diag.help("consider awaiting the future or dropping explicitly with `std::mem::drop`"); }, ); - } else if is_must_use_ty(cx, cx.typeck_results().expr_ty(init)) { - #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] + } else if let Some(must_use_path) = opt_must_use_path(cx, cx.typeck_results().expr_ty(init)) { span_lint_and_then( cx, LET_UNDERSCORE_MUST_USE, @@ -185,6 +184,11 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { "non-binding `let` on an expression with `#[must_use]` type", |diag| { diag.help("consider explicitly using expression value"); + let ty_span = local.ty.map_or(init.span, |ty| ty.span); + diag.span_note( + ty_span, + format!("type is {}", describe_must_use_type(cx, &must_use_path)), + ); }, ); } else if is_must_use_func_call(cx, init) { diff --git a/clippy_lints/src/return_self_not_must_use.rs b/clippy_lints/src/return_self_not_must_use.rs index a2bf2c8ccf1a3..84fc88936f178 100644 --- a/clippy_lints/src/return_self_not_must_use.rs +++ b/clippy_lints/src/return_self_not_must_use.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::is_must_use_ty; +use clippy_utils::ty::opt_must_use_path; use clippy_utils::{nth_arg, return_ty}; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::FnKind; @@ -87,7 +87,7 @@ fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, spa // there is one, we shouldn't emit a warning! && self_arg.peel_refs() == ret_ty // If `Self` is already considered as `#[must_use]`, no need for the attribute here. - && !is_must_use_ty(cx, ret_ty) + && opt_must_use_path(cx, ret_ty).is_none() { span_lint_and_help( cx, diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index 8569cf08ce037..ee107d67b45f6 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -3,9 +3,11 @@ #![allow(clippy::module_name_repetitions)] use core::ops::ControlFlow; +use itertools::Itertools as _; use rustc_abi::{BackendRepr, FieldsShape, VariantIdx, Variants}; use rustc_ast::ast::Mutability; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::pluralize; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; @@ -13,7 +15,7 @@ use rustc_hir::{Expr, ExprKind, FnDecl, LangItem}; use rustc_hir_analysis::lower_ty; use rustc_infer::infer::TyCtxtInferExt as _; use rustc_lint::LateContext; -use rustc_lint::unused::must_use::{IsTyMustUse, is_ty_must_use}; +use rustc_lint::unused::must_use::{IsTyMustUse, MustUsePath, is_ty_must_use}; use rustc_middle::mir::ConstValue; use rustc_middle::mir::interpret::Scalar; use rustc_middle::traits::EvaluationResult; @@ -323,7 +325,9 @@ pub fn has_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { /// Returns whether the `ty` has `#[must_use]` attribute, or acts like it does according to the /// compiler determination. For example, if `ty` is a `Result`/`ControlFlow` whose `Err`/`Break` /// payload is an uninhabited type, the `Ok`/`Continue` payload type will be used instead. -pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { +/// +/// The [`MustUsePath`] can be used to describe the type through [`describe_must_use_type`]. +pub fn opt_must_use_path<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { // `is_ty_must_use` requires an expression, whose `hir_id` will be used to determine whether // certain types are visibly uninhabited from the module containing the expression. // `cx.last_node_with_lint_attrs` is initialized to the crate/module `hir_id` when linting @@ -335,7 +339,96 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { span: DUMMY_SP, kind: ExprKind::Ret(None), }; - matches!(is_ty_must_use(cx, ty, &dummy_expr), IsTyMustUse::Yes(_)) + match is_ty_must_use(cx, ty, &dummy_expr) { + IsTyMustUse::Yes(path) => Some(path), + _ => None, + } +} + +/// Describe a [`MustUsePath`] returned by [`is_must_use_ty`]. +pub fn describe_must_use_type(cx: &LateContext<'_>, path: &MustUsePath) -> String { + describe_must_use_type_inner(cx, path, "", "", 1) +} + +// This is a rip-off from the compiler's `rustc_lint/src/unused/must_use.rs` +fn describe_must_use_type_inner( + cx: &LateContext<'_>, + path: &MustUsePath, + descr_pre: &str, + descr_post: &str, + plural_len: usize, +) -> String { + let plural_suffix = pluralize!(plural_len); + + match path { + MustUsePath::Boxed(path) => { + let descr_pre = &format!("{descr_pre}boxed "); + describe_must_use_type_inner(cx, path, descr_pre, descr_post, plural_len) + }, + MustUsePath::Pinned(path) => { + let descr_pre = &format!("{descr_pre}pinned "); + describe_must_use_type_inner(cx, path, descr_pre, descr_post, plural_len) + }, + MustUsePath::Opaque(path) => { + let descr_pre = &format!("{descr_pre}implementer{plural_suffix} of "); + describe_must_use_type_inner(cx, path, descr_pre, descr_post, plural_len) + }, + MustUsePath::TraitObject(path) => { + let descr_post = &format!(" trait object{plural_suffix}{descr_post}"); + describe_must_use_type_inner(cx, path, descr_pre, descr_post, plural_len) + }, + MustUsePath::TupleElement(elems) => elems + .iter() + .map(|(index, path)| { + let descr_post = &format!(" in tuple element {index}"); + describe_must_use_type_inner(cx, path, descr_pre, descr_post, plural_len) + }) + .join(", "), + MustUsePath::Result(path) => { + let descr_post = &format!(" in a `Result` with an uninhabited error{descr_post}"); + describe_must_use_type_inner(cx, path, descr_pre, descr_post, plural_len) + }, + MustUsePath::ControlFlow(path) => { + let descr_post = &format!(" in a `ControlFlow` with an uninhabited break{descr_post}"); + describe_must_use_type_inner(cx, path, descr_pre, descr_post, plural_len) + }, + MustUsePath::Array(path, len) => { + let descr_pre = &format!("{descr_pre}array{plural_suffix} of "); + describe_must_use_type_inner( + cx, + path, + descr_pre, + descr_post, + plural_len.saturating_add(usize::try_from(*len).unwrap_or(usize::MAX)), + ) + }, + MustUsePath::Closure(_) => { + format!( + "{descr_pre}{} closure{plural_suffix}{descr_post}", + if plural_len == 1 { + "one".to_string() + } else { + plural_len.to_string() + } + ) + }, + MustUsePath::Coroutine(_) => { + format!( + "{descr_pre}{} coroutine{plural_suffix}{descr_post}", + if plural_len == 1 { + "one".to_string() + } else { + plural_len.to_string() + } + ) + }, + MustUsePath::Def(_, def_id, _) => { + format!( + "{descr_pre}`{}`{plural_suffix}{descr_post}", + cx.tcx.def_path_str(*def_id) + ) + }, + } } /// Returns `true` if the given type is a non aggregate primitive (a `bool` or `char`, any diff --git a/tests/ui/double_must_use.stderr b/tests/ui/double_must_use.stderr index 29c004959c103..edb56104e6f24 100644 --- a/tests/ui/double_must_use.stderr +++ b/tests/ui/double_must_use.stderr @@ -18,6 +18,11 @@ LL | #[must_use] LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +note: the return type is `std::result::Result` in tuple element 0 + --> tests/ui/double_must_use.rs:15:28 + | +LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { + | ^^^^^^^^^^^^^^^^^^^^ = note: alternatively, you may add an explicit reason to the `must_use` attribute error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` @@ -28,6 +33,11 @@ LL | #[must_use] LL | pub fn must_use_array() -> [Result<(), ()>; 1] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +note: the return type is array of `std::result::Result`s + --> tests/ui/double_must_use.rs:22:28 + | +LL | pub fn must_use_array() -> [Result<(), ()>; 1] { + | ^^^^^^^^^^^^^^^^^^^ = note: alternatively, you may add an explicit reason to the `must_use` attribute error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` @@ -38,6 +48,11 @@ LL | #[must_use] LL | async fn async_must_use_result() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +note: the return type is implementer of `std::future::Future` + --> tests/ui/double_must_use.rs:40:37 + | +LL | async fn async_must_use_result() -> Result<(), ()> { + | ^^^^^^^^^^^^^^ = note: alternatively, you may add an explicit reason to the `must_use` attribute error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` @@ -48,6 +63,11 @@ LL | #[must_use] LL | pub fn must_use_result_with_uninhabited_2() -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +note: the return type is `T` in a `Result` with an uninhabited error + --> tests/ui/double_must_use.rs:55:48 + | +LL | pub fn must_use_result_with_uninhabited_2() -> Result { + | ^^^^^^^^^^^^ = note: alternatively, you may add an explicit reason to the `must_use` attribute error: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]` @@ -58,6 +78,11 @@ LL | #[must_use] LL | pub fn must_use_controlflow_with_uninhabited_2() -> ControlFlow { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +note: the return type is `T` in a `ControlFlow` with an uninhabited break + --> tests/ui/double_must_use.rs:66:53 + | +LL | pub fn must_use_controlflow_with_uninhabited_2() -> ControlFlow { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: alternatively, you may add an explicit reason to the `must_use` attribute error: aborting due to 6 previous errors diff --git a/tests/ui/let_underscore_must_use.rs b/tests/ui/let_underscore_must_use.rs index 37dac4f9a2b05..78f0104496cf4 100644 --- a/tests/ui/let_underscore_must_use.rs +++ b/tests/ui/let_underscore_must_use.rs @@ -96,6 +96,9 @@ fn main() { let _ = if true { Ok(()) } else { Err(()) }; //~^ let_underscore_must_use + let _: Result<(), ()> = if true { Ok(()) } else { Err(()) }; + //~^ let_underscore_must_use + let a = Result::<(), ()>::Ok(()); let _ = a.is_ok(); diff --git a/tests/ui/let_underscore_must_use.stderr b/tests/ui/let_underscore_must_use.stderr index 23e929b5bf895..5a0790d6e1c69 100644 --- a/tests/ui/let_underscore_must_use.stderr +++ b/tests/ui/let_underscore_must_use.stderr @@ -15,6 +15,11 @@ LL | let _ = g(); | ^^^^^^^^^^^^ | = help: consider explicitly using expression value +note: type is `std::result::Result` + --> tests/ui/let_underscore_must_use.rs:70:13 + | +LL | let _ = g(); + | ^^^ error: non-binding `let` on a result of a `#[must_use]` function --> tests/ui/let_underscore_must_use.rs:74:5 @@ -39,6 +44,11 @@ LL | let _ = s.g(); | ^^^^^^^^^^^^^^ | = help: consider explicitly using expression value +note: type is `std::result::Result` + --> tests/ui/let_underscore_must_use.rs:82:13 + | +LL | let _ = s.g(); + | ^^^^^ error: non-binding `let` on a result of a `#[must_use]` function --> tests/ui/let_underscore_must_use.rs:87:5 @@ -55,6 +65,11 @@ LL | let _ = S::p(); | ^^^^^^^^^^^^^^^ | = help: consider explicitly using expression value +note: type is `std::result::Result` + --> tests/ui/let_underscore_must_use.rs:90:13 + | +LL | let _ = S::p(); + | ^^^^^^ error: non-binding `let` on a result of a `#[must_use]` function --> tests/ui/let_underscore_must_use.rs:93:5 @@ -71,9 +86,27 @@ LL | let _ = if true { Ok(()) } else { Err(()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider explicitly using expression value +note: type is `std::result::Result` + --> tests/ui/let_underscore_must_use.rs:96:13 + | +LL | let _ = if true { Ok(()) } else { Err(()) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: non-binding `let` on an expression with `#[must_use]` type + --> tests/ui/let_underscore_must_use.rs:99:5 + | +LL | let _: Result<(), ()> = if true { Ok(()) } else { Err(()) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider explicitly using expression value +note: type is `std::result::Result` + --> tests/ui/let_underscore_must_use.rs:99:12 + | +LL | let _: Result<(), ()> = if true { Ok(()) } else { Err(()) }; + | ^^^^^^^^^^^^^^ error: non-binding `let` on a result of a `#[must_use]` function - --> tests/ui/let_underscore_must_use.rs:101:5 + --> tests/ui/let_underscore_must_use.rs:104:5 | LL | let _ = a.is_ok(); | ^^^^^^^^^^^^^^^^^^ @@ -81,28 +114,43 @@ LL | let _ = a.is_ok(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:104:5 + --> tests/ui/let_underscore_must_use.rs:107:5 | LL | let _ = a.map(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ | = help: consider explicitly using expression value +note: type is `std::result::Result` + --> tests/ui/let_underscore_must_use.rs:107:13 + | +LL | let _ = a.map(|_| ()); + | ^^^^^^^^^^^^^ error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:107:5 + --> tests/ui/let_underscore_must_use.rs:110:5 | LL | let _ = a; | ^^^^^^^^^^ | = help: consider explicitly using expression value +note: type is `std::result::Result` + --> tests/ui/let_underscore_must_use.rs:110:13 + | +LL | let _ = a; + | ^ error: non-binding `let` on an expression with `#[must_use]` type - --> tests/ui/let_underscore_must_use.rs:120:5 + --> tests/ui/let_underscore_must_use.rs:123:5 | LL | let _ = Result::<_, std::convert::Infallible>::Ok(T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider explicitly using expression value +note: type is `main::T` in a `Result` with an uninhabited error + --> tests/ui/let_underscore_must_use.rs:123:13 + | +LL | let _ = Result::<_, std::convert::Infallible>::Ok(T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 13 previous errors +error: aborting due to 14 previous errors From a1488fc2779a0362f100ed0dc4099ee617b67f06 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 21 May 2026 19:06:48 +0200 Subject: [PATCH 56/63] Attributes cleanup in tests [19/20] --- tests/ui/unnecessary_first_then_check.fixed | 3 +- tests/ui/unnecessary_first_then_check.rs | 3 +- tests/ui/unnecessary_first_then_check.stderr | 14 +- tests/ui/unnecessary_fold.fixed | 2 +- tests/ui/unnecessary_fold.rs | 2 +- tests/ui/unnecessary_iter_cloned.fixed | 5 +- tests/ui/unnecessary_iter_cloned.rs | 5 +- tests/ui/unnecessary_iter_cloned.stderr | 10 +- tests/ui/unnecessary_join.fixed | 2 +- tests/ui/unnecessary_join.rs | 2 +- tests/ui/unnecessary_lazy_eval.fixed | 13 +- tests/ui/unnecessary_lazy_eval.rs | 13 +- tests/ui/unnecessary_lazy_eval.stderr | 130 +++++------ tests/ui/unnecessary_lazy_eval_unfixable.rs | 2 +- tests/ui/unnecessary_literal_unwrap.fixed | 5 +- tests/ui/unnecessary_literal_unwrap.rs | 5 +- tests/ui/unnecessary_literal_unwrap.stderr | 106 ++++----- .../unnecessary_literal_unwrap_unfixable.rs | 3 +- ...nnecessary_literal_unwrap_unfixable.stderr | 204 +++++++++--------- tests/ui/unnecessary_map_on_constructor.fixed | 1 - tests/ui/unnecessary_map_on_constructor.rs | 1 - .../ui/unnecessary_map_on_constructor.stderr | 16 +- tests/ui/unnecessary_map_or.fixed | 9 +- tests/ui/unnecessary_map_or.rs | 9 +- tests/ui/unnecessary_map_or.stderr | 60 +++--- tests/ui/unnecessary_min_or_max.fixed | 3 +- tests/ui/unnecessary_min_or_max.rs | 3 +- tests/ui/unnecessary_min_or_max.stderr | 50 ++--- tests/ui/unnecessary_mut_passed.fixed | 3 +- tests/ui/unnecessary_mut_passed.rs | 3 +- tests/ui/unnecessary_mut_passed.stderr | 36 ++-- tests/ui/unnecessary_operation.fixed | 9 +- tests/ui/unnecessary_operation.rs | 9 +- tests/ui/unnecessary_operation.stderr | 42 ++-- tests/ui/unnecessary_option_map_or_else.fixed | 6 +- tests/ui/unnecessary_option_map_or_else.rs | 6 +- .../ui/unnecessary_os_str_debug_formatting.rs | 2 +- tests/ui/unnecessary_path_debug_formatting.rs | 2 +- tests/ui/unnecessary_result_map_or_else.fixed | 8 +- tests/ui/unnecessary_result_map_or_else.rs | 8 +- .../ui/unnecessary_result_map_or_else.stderr | 14 +- tests/ui/unnecessary_safety_comment.rs | 2 +- tests/ui/unnecessary_self_imports.fixed | 1 - tests/ui/unnecessary_self_imports.rs | 1 - tests/ui/unnecessary_self_imports.stderr | 4 +- .../unnecessary_semicolon.edition2021.fixed | 2 +- .../unnecessary_semicolon.edition2024.fixed | 2 +- tests/ui/unnecessary_semicolon.rs | 2 +- tests/ui/unnecessary_sort_by.fixed | 3 +- tests/ui/unnecessary_sort_by.rs | 3 +- tests/ui/unnecessary_sort_by.stderr | 44 ++-- .../unnecessary_struct_initialization.fixed | 2 +- tests/ui/unnecessary_struct_initialization.rs | 2 +- tests/ui/unnecessary_to_owned.fixed | 19 +- tests/ui/unnecessary_to_owned.rs | 19 +- tests/ui/unnecessary_to_owned.stderr | 176 +++++++-------- tests/ui/unnecessary_to_owned_on_split.fixed | 3 +- tests/ui/unnecessary_to_owned_on_split.rs | 3 +- tests/ui/unnecessary_to_owned_on_split.stderr | 18 +- tests/ui/unnecessary_unsafety_doc.rs | 1 - tests/ui/unnecessary_unsafety_doc.stderr | 14 +- tests/ui/unnecessary_wraps.rs | 4 +- tests/ui/unnecessary_wraps.stderr | 14 +- tests/ui/unneeded_field_pattern.rs | 2 +- tests/ui/unneeded_struct_pattern.fixed | 7 +- tests/ui/unneeded_struct_pattern.rs | 7 +- tests/ui/unneeded_struct_pattern.stderr | 66 +++--- tests/ui/unneeded_wildcard_pattern.fixed | 3 +- tests/ui/unneeded_wildcard_pattern.rs | 3 +- tests/ui/unneeded_wildcard_pattern.stderr | 43 ++-- tests/ui/unnested_or_patterns.fixed | 10 +- tests/ui/unnested_or_patterns.rs | 10 +- tests/ui/unnested_or_patterns.stderr | 42 ++-- tests/ui/unnested_or_patterns2.fixed | 8 +- tests/ui/unnested_or_patterns2.rs | 8 +- tests/ui/unnested_or_patterns2.stderr | 16 +- tests/ui/unsafe_derive_deserialize.rs | 2 +- tests/ui/unsafe_removed_from_name.rs | 2 - tests/ui/unsafe_removed_from_name.stderr | 12 +- tests/ui/unseparated_prefix_literals.fixed | 1 - tests/ui/unseparated_prefix_literals.rs | 1 - tests/ui/unseparated_prefix_literals.stderr | 18 +- tests/ui/unused_async.rs | 3 +- tests/ui/unused_async.stderr | 10 +- tests/ui/unused_enumerate_index.fixed | 2 +- tests/ui/unused_enumerate_index.rs | 2 +- tests/ui/unused_format_specs_width.rs | 2 +- tests/ui/unused_io_amount.rs | 3 +- tests/ui/unused_io_amount.stderr | 70 +++--- tests/ui/unused_peekable.rs | 2 +- tests/ui/unused_result_ok.fixed | 1 - tests/ui/unused_result_ok.rs | 1 - tests/ui/unused_result_ok.stderr | 8 +- 93 files changed, 704 insertions(+), 829 deletions(-) diff --git a/tests/ui/unnecessary_first_then_check.fixed b/tests/ui/unnecessary_first_then_check.fixed index aa049eb33751b..38d3db0672449 100644 --- a/tests/ui/unnecessary_first_then_check.fixed +++ b/tests/ui/unnecessary_first_then_check.fixed @@ -1,5 +1,6 @@ #![warn(clippy::unnecessary_first_then_check)] -#![allow(clippy::useless_vec, clippy::const_is_empty)] +#![allow(clippy::const_is_empty)] +#![expect(clippy::useless_vec)] fn main() { let s = [1, 2, 3]; diff --git a/tests/ui/unnecessary_first_then_check.rs b/tests/ui/unnecessary_first_then_check.rs index 4c2ac3ba40a21..d2a5d68d76096 100644 --- a/tests/ui/unnecessary_first_then_check.rs +++ b/tests/ui/unnecessary_first_then_check.rs @@ -1,5 +1,6 @@ #![warn(clippy::unnecessary_first_then_check)] -#![allow(clippy::useless_vec, clippy::const_is_empty)] +#![allow(clippy::const_is_empty)] +#![expect(clippy::useless_vec)] fn main() { let s = [1, 2, 3]; diff --git a/tests/ui/unnecessary_first_then_check.stderr b/tests/ui/unnecessary_first_then_check.stderr index 408b388ecf71a..a15c09204d48b 100644 --- a/tests/ui/unnecessary_first_then_check.stderr +++ b/tests/ui/unnecessary_first_then_check.stderr @@ -1,5 +1,5 @@ error: unnecessary use of `first().is_some()` to check if slice is not empty - --> tests/ui/unnecessary_first_then_check.rs:6:19 + --> tests/ui/unnecessary_first_then_check.rs:7:19 | LL | let _: bool = s.first().is_some(); | ^^^^^^^^^^^^^^^^^^^ help: replace this with: `!s.is_empty()` @@ -8,37 +8,37 @@ LL | let _: bool = s.first().is_some(); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_first_then_check)]` error: unnecessary use of `first().is_none()` to check if slice is empty - --> tests/ui/unnecessary_first_then_check.rs:8:21 + --> tests/ui/unnecessary_first_then_check.rs:9:21 | LL | let _: bool = s.first().is_none(); | ^^^^^^^^^^^^^^^^^ help: replace this with: `is_empty()` error: unnecessary use of `first().is_some()` to check if slice is not empty - --> tests/ui/unnecessary_first_then_check.rs:12:19 + --> tests/ui/unnecessary_first_then_check.rs:13:19 | LL | let _: bool = v.first().is_some(); | ^^^^^^^^^^^^^^^^^^^ help: replace this with: `!v.is_empty()` error: unnecessary use of `first().is_some()` to check if slice is not empty - --> tests/ui/unnecessary_first_then_check.rs:16:19 + --> tests/ui/unnecessary_first_then_check.rs:17:19 | LL | let _: bool = n[0].first().is_some(); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace this with: `!n[0].is_empty()` error: unnecessary use of `first().is_none()` to check if slice is empty - --> tests/ui/unnecessary_first_then_check.rs:18:24 + --> tests/ui/unnecessary_first_then_check.rs:19:24 | LL | let _: bool = n[0].first().is_none(); | ^^^^^^^^^^^^^^^^^ help: replace this with: `is_empty()` error: unnecessary use of `first().is_some()` to check if slice is not empty - --> tests/ui/unnecessary_first_then_check.rs:25:19 + --> tests/ui/unnecessary_first_then_check.rs:26:19 | LL | let _: bool = f[0].bar.first().is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this with: `!f[0].bar.is_empty()` error: unnecessary use of `first().is_none()` to check if slice is empty - --> tests/ui/unnecessary_first_then_check.rs:27:28 + --> tests/ui/unnecessary_first_then_check.rs:28:28 | LL | let _: bool = f[0].bar.first().is_none(); | ^^^^^^^^^^^^^^^^^ help: replace this with: `is_empty()` diff --git a/tests/ui/unnecessary_fold.fixed b/tests/ui/unnecessary_fold.fixed index a8370ed03b746..e0883b6ed58f1 100644 --- a/tests/ui/unnecessary_fold.fixed +++ b/tests/ui/unnecessary_fold.fixed @@ -1,4 +1,4 @@ -#![allow(dead_code)] +#![warn(clippy::unnecessary_fold)] fn is_any(acc: bool, x: usize) -> bool { acc || x > 2 diff --git a/tests/ui/unnecessary_fold.rs b/tests/ui/unnecessary_fold.rs index f495da6e720ba..76b149bf5e2de 100644 --- a/tests/ui/unnecessary_fold.rs +++ b/tests/ui/unnecessary_fold.rs @@ -1,4 +1,4 @@ -#![allow(dead_code)] +#![warn(clippy::unnecessary_fold)] fn is_any(acc: bool, x: usize) -> bool { acc || x > 2 diff --git a/tests/ui/unnecessary_iter_cloned.fixed b/tests/ui/unnecessary_iter_cloned.fixed index 61f2e3745ad05..a2782bcd21635 100644 --- a/tests/ui/unnecessary_iter_cloned.fixed +++ b/tests/ui/unnecessary_iter_cloned.fixed @@ -1,7 +1,6 @@ -#![allow(unused_assignments, clippy::uninlined_format_args)] #![warn(clippy::unnecessary_to_owned)] +#![expect(clippy::uninlined_format_args)] -#[allow(dead_code)] #[derive(Clone, Copy)] enum FileType { Account, @@ -74,7 +73,6 @@ fn check_files_ref(files: &[(FileType, &std::path::Path)]) -> bool { true } -#[allow(unused_assignments)] fn check_files_mut(files: &[(FileType, &std::path::Path)]) -> bool { for (mut t, path) in files.iter().copied() { t = FileType::PrivateKey; @@ -122,7 +120,6 @@ fn check_files_self_and_arg(files: &[(FileType, &std::path::Path)]) -> bool { true } -#[allow(unused_assignments)] fn check_files_mut_path_buf(files: &[(FileType, std::path::PathBuf)]) -> bool { for (mut t, path) in files.iter().cloned() { t = FileType::PrivateKey; diff --git a/tests/ui/unnecessary_iter_cloned.rs b/tests/ui/unnecessary_iter_cloned.rs index b90ca00a5fece..1225e6f94ec5a 100644 --- a/tests/ui/unnecessary_iter_cloned.rs +++ b/tests/ui/unnecessary_iter_cloned.rs @@ -1,7 +1,6 @@ -#![allow(unused_assignments, clippy::uninlined_format_args)] #![warn(clippy::unnecessary_to_owned)] +#![expect(clippy::uninlined_format_args)] -#[allow(dead_code)] #[derive(Clone, Copy)] enum FileType { Account, @@ -74,7 +73,6 @@ fn check_files_ref(files: &[(FileType, &std::path::Path)]) -> bool { true } -#[allow(unused_assignments)] fn check_files_mut(files: &[(FileType, &std::path::Path)]) -> bool { for (mut t, path) in files.iter().copied() { t = FileType::PrivateKey; @@ -122,7 +120,6 @@ fn check_files_self_and_arg(files: &[(FileType, &std::path::Path)]) -> bool { true } -#[allow(unused_assignments)] fn check_files_mut_path_buf(files: &[(FileType, std::path::PathBuf)]) -> bool { for (mut t, path) in files.iter().cloned() { t = FileType::PrivateKey; diff --git a/tests/ui/unnecessary_iter_cloned.stderr b/tests/ui/unnecessary_iter_cloned.stderr index d700446fce774..46099e4e2cfbc 100644 --- a/tests/ui/unnecessary_iter_cloned.stderr +++ b/tests/ui/unnecessary_iter_cloned.stderr @@ -1,5 +1,5 @@ error: unnecessary use of `copied` - --> tests/ui/unnecessary_iter_cloned.rs:31:22 + --> tests/ui/unnecessary_iter_cloned.rs:30:22 | LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ @@ -14,7 +14,7 @@ LL ~ let other = match get_file_path(t) { | error: unnecessary use of `copied` - --> tests/ui/unnecessary_iter_cloned.rs:47:22 + --> tests/ui/unnecessary_iter_cloned.rs:46:22 | LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL ~ let other = match get_file_path(t) { | error: unnecessary use of `cloned` - --> tests/ui/unnecessary_iter_cloned.rs:179:18 + --> tests/ui/unnecessary_iter_cloned.rs:176:18 | LL | for c in v.iter().cloned() { | ^^^^^^^^^^^^^^^^^ @@ -39,7 +39,7 @@ LL + for c in v.iter() { | error: unnecessary use of `cloned` - --> tests/ui/unnecessary_iter_cloned.rs:188:18 + --> tests/ui/unnecessary_iter_cloned.rs:185:18 | LL | for c in v.iter().cloned() { | ^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL ~ let ref_c = c; | error: unnecessary use of `cloned` - --> tests/ui/unnecessary_iter_cloned.rs:198:23 + --> tests/ui/unnecessary_iter_cloned.rs:195:23 | LL | for (i, c) in v.iter().cloned() { | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_join.fixed b/tests/ui/unnecessary_join.fixed index dab09be7ebd09..2f846b7beff4c 100644 --- a/tests/ui/unnecessary_join.fixed +++ b/tests/ui/unnecessary_join.fixed @@ -1,5 +1,5 @@ #![warn(clippy::unnecessary_join)] -#![allow(clippy::uninlined_format_args, clippy::useless_vec)] +#![expect(clippy::uninlined_format_args, clippy::useless_vec)] fn main() { // should be linted diff --git a/tests/ui/unnecessary_join.rs b/tests/ui/unnecessary_join.rs index e58b2696645a9..5dcc394f01570 100644 --- a/tests/ui/unnecessary_join.rs +++ b/tests/ui/unnecessary_join.rs @@ -1,5 +1,5 @@ #![warn(clippy::unnecessary_join)] -#![allow(clippy::uninlined_format_args, clippy::useless_vec)] +#![expect(clippy::uninlined_format_args, clippy::useless_vec)] fn main() { // should be linted diff --git a/tests/ui/unnecessary_lazy_eval.fixed b/tests/ui/unnecessary_lazy_eval.fixed index c8d6b1832a710..c178d41b8861d 100644 --- a/tests/ui/unnecessary_lazy_eval.fixed +++ b/tests/ui/unnecessary_lazy_eval.fixed @@ -1,13 +1,7 @@ //@aux-build: proc_macros.rs #![warn(clippy::unnecessary_lazy_evaluations)] -#![allow(clippy::redundant_closure)] -#![allow(clippy::bind_instead_of_map)] -#![allow(clippy::map_identity)] -#![allow(clippy::needless_borrow)] -#![allow(clippy::unnecessary_literal_unwrap)] -#![allow(clippy::unit_arg)] -#![allow(arithmetic_overflow)] -#![allow(unconditional_panic)] +#![expect(clippy::bind_instead_of_map, clippy::needless_borrow, clippy::redundant_closure)] +#![allow(clippy::unit_arg, clippy::unnecessary_literal_unwrap)] use std::ops::Deref; @@ -252,7 +246,6 @@ fn issue11672_as() { //~^ unnecessary_lazy_evaluations } -#[allow(unused)] fn issue9485() { // should not lint, is in proc macro with_span!(span Some(42).unwrap_or_else(|| 2);); @@ -264,7 +257,7 @@ fn issue9422(x: usize) -> Option { } fn panicky_arithmetic_ops(x: usize, y: isize) { - #![allow(clippy::identity_op, clippy::eq_op)] + #![expect(clippy::eq_op, clippy::identity_op)] // See comments in `eager_or_lazy.rs` for the rules that this is meant to follow diff --git a/tests/ui/unnecessary_lazy_eval.rs b/tests/ui/unnecessary_lazy_eval.rs index 87e903c5bbb8c..33156b4cb986c 100644 --- a/tests/ui/unnecessary_lazy_eval.rs +++ b/tests/ui/unnecessary_lazy_eval.rs @@ -1,13 +1,7 @@ //@aux-build: proc_macros.rs #![warn(clippy::unnecessary_lazy_evaluations)] -#![allow(clippy::redundant_closure)] -#![allow(clippy::bind_instead_of_map)] -#![allow(clippy::map_identity)] -#![allow(clippy::needless_borrow)] -#![allow(clippy::unnecessary_literal_unwrap)] -#![allow(clippy::unit_arg)] -#![allow(arithmetic_overflow)] -#![allow(unconditional_panic)] +#![expect(clippy::bind_instead_of_map, clippy::needless_borrow, clippy::redundant_closure)] +#![allow(clippy::unit_arg, clippy::unnecessary_literal_unwrap)] use std::ops::Deref; @@ -252,7 +246,6 @@ fn issue11672_as() { //~^ unnecessary_lazy_evaluations } -#[allow(unused)] fn issue9485() { // should not lint, is in proc macro with_span!(span Some(42).unwrap_or_else(|| 2);); @@ -264,7 +257,7 @@ fn issue9422(x: usize) -> Option { } fn panicky_arithmetic_ops(x: usize, y: isize) { - #![allow(clippy::identity_op, clippy::eq_op)] + #![expect(clippy::eq_op, clippy::identity_op)] // See comments in `eager_or_lazy.rs` for the rules that this is meant to follow diff --git a/tests/ui/unnecessary_lazy_eval.stderr b/tests/ui/unnecessary_lazy_eval.stderr index 9b91b22f80d3a..93a751a1b15fa 100644 --- a/tests/ui/unnecessary_lazy_eval.stderr +++ b/tests/ui/unnecessary_lazy_eval.stderr @@ -1,5 +1,5 @@ error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:83:13 + --> tests/ui/unnecessary_lazy_eval.rs:77:13 | LL | let _ = opt.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + let _ = opt.unwrap_or(2); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:85:13 + --> tests/ui/unnecessary_lazy_eval.rs:79:13 | LL | let _ = opt.unwrap_or_else(|| astronomers_pi); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _ = opt.unwrap_or(astronomers_pi); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:87:13 + --> tests/ui/unnecessary_lazy_eval.rs:81:13 | LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + let _ = opt.unwrap_or(ext_str.some_field); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:90:13 + --> tests/ui/unnecessary_lazy_eval.rs:84:13 | LL | let _ = opt.and_then(|_| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + let _ = opt.and(ext_opt); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:92:13 + --> tests/ui/unnecessary_lazy_eval.rs:86:13 | LL | let _ = opt.or_else(|| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let _ = opt.or(ext_opt); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:94:13 + --> tests/ui/unnecessary_lazy_eval.rs:88:13 | LL | let _ = opt.or_else(|| None); | ^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + let _ = opt.or(None); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:96:13 + --> tests/ui/unnecessary_lazy_eval.rs:90:13 | LL | let _ = opt.get_or_insert_with(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + let _ = opt.get_or_insert(2); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:98:13 + --> tests/ui/unnecessary_lazy_eval.rs:92:13 | LL | let _ = opt.ok_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + let _ = opt.ok_or(2); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:100:13 + --> tests/ui/unnecessary_lazy_eval.rs:94:13 | LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + let _ = nested_tuple_opt.unwrap_or(Some((1, 2))); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:102:13 + --> tests/ui/unnecessary_lazy_eval.rs:96:13 | LL | let _ = cond.then(|| astronomers_pi); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + let _ = cond.then_some(astronomers_pi); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:104:13 + --> tests/ui/unnecessary_lazy_eval.rs:98:13 | LL | let _ = true.then(|| -> _ {}); | ^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + let _ = true.then_some({}); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:106:13 + --> tests/ui/unnecessary_lazy_eval.rs:100:13 | LL | let _ = true.then(|| {}); | ^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + let _ = true.then_some({}); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:111:13 + --> tests/ui/unnecessary_lazy_eval.rs:105:13 | LL | let _ = Some(1).unwrap_or_else(|| *r); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + let _ = Some(1).unwrap_or(*r); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:114:13 + --> tests/ui/unnecessary_lazy_eval.rs:108:13 | LL | let _ = Some(1).unwrap_or_else(|| *b); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + let _ = Some(1).unwrap_or(*b); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:117:13 + --> tests/ui/unnecessary_lazy_eval.rs:111:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + let _ = Some(1).as_ref().unwrap_or(&r); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:119:13 + --> tests/ui/unnecessary_lazy_eval.rs:113:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + let _ = Some(1).as_ref().unwrap_or(&b); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:123:13 + --> tests/ui/unnecessary_lazy_eval.rs:117:13 | LL | let _ = Some(10).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL + let _ = Some(10).unwrap_or(2); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:125:13 + --> tests/ui/unnecessary_lazy_eval.rs:119:13 | LL | let _ = Some(10).and_then(|_| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL + let _ = Some(10).and(ext_opt); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:127:28 + --> tests/ui/unnecessary_lazy_eval.rs:121:28 | LL | let _: Option = None.or_else(|| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL + let _: Option = None.or(ext_opt); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:129:13 + --> tests/ui/unnecessary_lazy_eval.rs:123:13 | LL | let _ = None.get_or_insert_with(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL + let _ = None.get_or_insert(2); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:131:35 + --> tests/ui/unnecessary_lazy_eval.rs:125:35 | LL | let _: Result = None.ok_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL + let _: Result = None.ok_or(2); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:133:28 + --> tests/ui/unnecessary_lazy_eval.rs:127:28 | LL | let _: Option = None.or_else(|| None); | ^^^^^^^^^^^^^^^^^^^^^ @@ -265,7 +265,7 @@ LL + let _: Option = None.or(None); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:137:13 + --> tests/ui/unnecessary_lazy_eval.rs:131:13 | LL | let _ = deep.0.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL + let _ = deep.0.unwrap_or(2); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:139:13 + --> tests/ui/unnecessary_lazy_eval.rs:133:13 | LL | let _ = deep.0.and_then(|_| ext_opt); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL + let _ = deep.0.and(ext_opt); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:141:13 + --> tests/ui/unnecessary_lazy_eval.rs:135:13 | LL | let _ = deep.0.or_else(|| None); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL + let _ = deep.0.or(None); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:143:13 + --> tests/ui/unnecessary_lazy_eval.rs:137:13 | LL | let _ = deep.0.get_or_insert_with(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL + let _ = deep.0.get_or_insert(2); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:145:13 + --> tests/ui/unnecessary_lazy_eval.rs:139:13 | LL | let _ = deep.0.ok_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL + let _ = deep.0.ok_or(2); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:177:28 + --> tests/ui/unnecessary_lazy_eval.rs:171:28 | LL | let _: Option = None.or_else(|| Some(3)); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL + let _: Option = None.or(Some(3)); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:179:13 + --> tests/ui/unnecessary_lazy_eval.rs:173:13 | LL | let _ = deep.0.or_else(|| Some(3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -349,7 +349,7 @@ LL + let _ = deep.0.or(Some(3)); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:181:13 + --> tests/ui/unnecessary_lazy_eval.rs:175:13 | LL | let _ = opt.or_else(|| Some(3)); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -361,7 +361,7 @@ LL + let _ = opt.or(Some(3)); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:188:13 + --> tests/ui/unnecessary_lazy_eval.rs:182:13 | LL | let _ = res2.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -373,7 +373,7 @@ LL + let _ = res2.unwrap_or(2); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:190:13 + --> tests/ui/unnecessary_lazy_eval.rs:184:13 | LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -385,7 +385,7 @@ LL + let _ = res2.unwrap_or(astronomers_pi); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:192:13 + --> tests/ui/unnecessary_lazy_eval.rs:186:13 | LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -397,7 +397,7 @@ LL + let _ = res2.unwrap_or(ext_str.some_field); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:215:35 + --> tests/ui/unnecessary_lazy_eval.rs:209:35 | LL | let _: Result = res.and_then(|_| Err(2)); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -409,7 +409,7 @@ LL + let _: Result = res.and(Err(2)); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:217:35 + --> tests/ui/unnecessary_lazy_eval.rs:211:35 | LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -421,7 +421,7 @@ LL + let _: Result = res.and(Err(astronomers_pi)); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:219:35 + --> tests/ui/unnecessary_lazy_eval.rs:213:35 | LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -433,7 +433,7 @@ LL + let _: Result = res.and(Err(ext_str.some_field)); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:222:35 + --> tests/ui/unnecessary_lazy_eval.rs:216:35 | LL | let _: Result = res.or_else(|_| Ok(2)); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -445,7 +445,7 @@ LL + let _: Result = res.or(Ok(2)); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:224:35 + --> tests/ui/unnecessary_lazy_eval.rs:218:35 | LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -457,7 +457,7 @@ LL + let _: Result = res.or(Ok(astronomers_pi)); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:226:35 + --> tests/ui/unnecessary_lazy_eval.rs:220:35 | LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -469,7 +469,7 @@ LL + let _: Result = res.or(Ok(ext_str.some_field)); | error: unnecessary closure used to substitute value for `Result::Err` - --> tests/ui/unnecessary_lazy_eval.rs:228:35 + --> tests/ui/unnecessary_lazy_eval.rs:222:35 | LL | let _: Result = res. | ___________________________________^ @@ -484,7 +484,7 @@ LL + or(Ok(ext_str.some_field)); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:245:13 + --> tests/ui/unnecessary_lazy_eval.rs:239:13 | LL | let _ = true.then(|| -> &[u8] { &[] }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -496,7 +496,7 @@ LL + let _ = true.then_some::<&[u8]>({ &[] }); | error: unnecessary closure used to substitute value for `Option::None` - --> tests/ui/unnecessary_lazy_eval.rs:251:13 + --> tests/ui/unnecessary_lazy_eval.rs:245:13 | LL | let _ = None.get_or_insert_with(|| -> &[u8] { &[] }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -508,7 +508,7 @@ LL + let _ = None.get_or_insert({ &[] } as &[u8]); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:271:14 + --> tests/ui/unnecessary_lazy_eval.rs:264:14 | LL | let _x = false.then(|| i32::MAX + 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -520,7 +520,7 @@ LL + let _x = false.then_some(i32::MAX + 1); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:273:14 + --> tests/ui/unnecessary_lazy_eval.rs:266:14 | LL | let _x = false.then(|| i32::MAX * 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -532,7 +532,7 @@ LL + let _x = false.then_some(i32::MAX * 2); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:275:14 + --> tests/ui/unnecessary_lazy_eval.rs:268:14 | LL | let _x = false.then(|| i32::MAX - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -544,7 +544,7 @@ LL + let _x = false.then_some(i32::MAX - 1); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:277:14 + --> tests/ui/unnecessary_lazy_eval.rs:270:14 | LL | let _x = false.then(|| i32::MIN - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -556,7 +556,7 @@ LL + let _x = false.then_some(i32::MIN - 1); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:279:14 + --> tests/ui/unnecessary_lazy_eval.rs:272:14 | LL | let _x = false.then(|| (1 + 2 * 3 - 2 / 3 + 9) << 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -568,7 +568,7 @@ LL + let _x = false.then_some((1 + 2 * 3 - 2 / 3 + 9) << 2); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:281:14 + --> tests/ui/unnecessary_lazy_eval.rs:274:14 | LL | let _x = false.then(|| 255u8 << 7); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -580,7 +580,7 @@ LL + let _x = false.then_some(255u8 << 7); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:283:14 + --> tests/ui/unnecessary_lazy_eval.rs:276:14 | LL | let _x = false.then(|| 255u8 << 8); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -592,7 +592,7 @@ LL + let _x = false.then_some(255u8 << 8); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:285:14 + --> tests/ui/unnecessary_lazy_eval.rs:278:14 | LL | let _x = false.then(|| 255u8 >> 8); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -604,7 +604,7 @@ LL + let _x = false.then_some(255u8 >> 8); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:288:14 + --> tests/ui/unnecessary_lazy_eval.rs:281:14 | LL | let _x = false.then(|| i32::MAX + -1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -616,7 +616,7 @@ LL + let _x = false.then_some(i32::MAX + -1); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:290:14 + --> tests/ui/unnecessary_lazy_eval.rs:283:14 | LL | let _x = false.then(|| -i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -628,7 +628,7 @@ LL + let _x = false.then_some(-i32::MAX); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:292:14 + --> tests/ui/unnecessary_lazy_eval.rs:285:14 | LL | let _x = false.then(|| -i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -640,7 +640,7 @@ LL + let _x = false.then_some(-i32::MIN); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:295:14 + --> tests/ui/unnecessary_lazy_eval.rs:288:14 | LL | let _x = false.then(|| 255 >> -7); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -652,7 +652,7 @@ LL + let _x = false.then_some(255 >> -7); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:297:14 + --> tests/ui/unnecessary_lazy_eval.rs:290:14 | LL | let _x = false.then(|| 255 << -1); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -664,7 +664,7 @@ LL + let _x = false.then_some(255 << -1); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:299:14 + --> tests/ui/unnecessary_lazy_eval.rs:292:14 | LL | let _x = false.then(|| 1 / 0); | ^^^^^^^^^^^^^^^^^^^^ @@ -676,7 +676,7 @@ LL + let _x = false.then_some(1 / 0); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:301:14 + --> tests/ui/unnecessary_lazy_eval.rs:294:14 | LL | let _x = false.then(|| x << -1); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -688,7 +688,7 @@ LL + let _x = false.then_some(x << -1); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:303:14 + --> tests/ui/unnecessary_lazy_eval.rs:296:14 | LL | let _x = false.then(|| x << 2); | ^^^^^^^^^^^^^^^^^^^^^ @@ -700,7 +700,7 @@ LL + let _x = false.then_some(x << 2); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:313:14 + --> tests/ui/unnecessary_lazy_eval.rs:306:14 | LL | let _x = false.then(|| x / 0); | ^^^^^^^^^^^^^^^^^^^^ @@ -712,7 +712,7 @@ LL + let _x = false.then_some(x / 0); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:315:14 + --> tests/ui/unnecessary_lazy_eval.rs:308:14 | LL | let _x = false.then(|| x % 0); | ^^^^^^^^^^^^^^^^^^^^ @@ -724,7 +724,7 @@ LL + let _x = false.then_some(x % 0); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:318:14 + --> tests/ui/unnecessary_lazy_eval.rs:311:14 | LL | let _x = false.then(|| 1 / -1); | ^^^^^^^^^^^^^^^^^^^^^ @@ -736,7 +736,7 @@ LL + let _x = false.then_some(1 / -1); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:320:14 + --> tests/ui/unnecessary_lazy_eval.rs:313:14 | LL | let _x = false.then(|| i32::MIN / -1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -748,7 +748,7 @@ LL + let _x = false.then_some(i32::MIN / -1); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:323:14 + --> tests/ui/unnecessary_lazy_eval.rs:316:14 | LL | let _x = false.then(|| i32::MIN / 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -760,7 +760,7 @@ LL + let _x = false.then_some(i32::MIN / 0); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:325:14 + --> tests/ui/unnecessary_lazy_eval.rs:318:14 | LL | let _x = false.then(|| 4 / 2); | ^^^^^^^^^^^^^^^^^^^^ @@ -772,7 +772,7 @@ LL + let _x = false.then_some(4 / 2); | error: unnecessary closure used with `bool::then` - --> tests/ui/unnecessary_lazy_eval.rs:333:14 + --> tests/ui/unnecessary_lazy_eval.rs:326:14 | LL | let _x = false.then(|| f1 + f2); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.rs b/tests/ui/unnecessary_lazy_eval_unfixable.rs index 7ceda40597942..c9b8890861a5d 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.rs +++ b/tests/ui/unnecessary_lazy_eval_unfixable.rs @@ -1,5 +1,5 @@ #![warn(clippy::unnecessary_lazy_evaluations)] -#![allow(clippy::unnecessary_literal_unwrap)] +#![expect(clippy::unnecessary_literal_unwrap)] //@no-rustfix struct Deep(Option); diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed index 05ffdeb1dcc59..96242b9a5ec2d 100644 --- a/tests/ui/unnecessary_literal_unwrap.fixed +++ b/tests/ui/unnecessary_literal_unwrap.fixed @@ -1,10 +1,9 @@ #![warn(clippy::unnecessary_literal_unwrap)] -#![allow(unreachable_code)] #![allow( - clippy::unnecessary_lazy_evaluations, clippy::diverging_sub_expression, clippy::let_unit_value, - clippy::no_effect + clippy::no_effect, + clippy::unnecessary_lazy_evaluations )] fn unwrap_option_some() { diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs index 5efefb24530b9..a901f82c03d64 100644 --- a/tests/ui/unnecessary_literal_unwrap.rs +++ b/tests/ui/unnecessary_literal_unwrap.rs @@ -1,10 +1,9 @@ #![warn(clippy::unnecessary_literal_unwrap)] -#![allow(unreachable_code)] #![allow( - clippy::unnecessary_lazy_evaluations, clippy::diverging_sub_expression, clippy::let_unit_value, - clippy::no_effect + clippy::no_effect, + clippy::unnecessary_lazy_evaluations )] fn unwrap_option_some() { diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index 9c93f5a09bb04..fdad1ee060b91 100644 --- a/tests/ui/unnecessary_literal_unwrap.stderr +++ b/tests/ui/unnecessary_literal_unwrap.stderr @@ -1,5 +1,5 @@ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:11:16 + --> tests/ui/unnecessary_literal_unwrap.rs:10:16 | LL | let _val = Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + let _val = 1; | error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:13:16 + --> tests/ui/unnecessary_literal_unwrap.rs:12:16 | LL | let _val = Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:16:5 + --> tests/ui/unnecessary_literal_unwrap.rs:15:5 | LL | Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + 1; | error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:18:5 + --> tests/ui/unnecessary_literal_unwrap.rs:17:5 | LL | Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + 1; | error: used `unwrap()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:24:16 + --> tests/ui/unnecessary_literal_unwrap.rs:23:16 | LL | let _val = None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let _val = panic!(); | error: used `expect()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:26:16 + --> tests/ui/unnecessary_literal_unwrap.rs:25:16 | LL | let _val = None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + let _val = panic!("this always happens"); | error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:28:24 + --> tests/ui/unnecessary_literal_unwrap.rs:27:24 | LL | let _val: String = None.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + let _val: String = String::default(); | error: used `unwrap_or()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:30:21 + --> tests/ui/unnecessary_literal_unwrap.rs:29:21 | LL | let _val: u16 = None.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:32:21 + --> tests/ui/unnecessary_literal_unwrap.rs:31:21 | LL | let _val: u16 = None.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:34:21 + --> tests/ui/unnecessary_literal_unwrap.rs:33:21 | LL | let _val: u16 = None.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:36:21 + --> tests/ui/unnecessary_literal_unwrap.rs:35:21 | LL | let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:39:5 + --> tests/ui/unnecessary_literal_unwrap.rs:38:5 | LL | None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + panic!(); | error: used `expect()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:41:5 + --> tests/ui/unnecessary_literal_unwrap.rs:40:5 | LL | None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + panic!("this always happens"); | error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:43:5 + --> tests/ui/unnecessary_literal_unwrap.rs:42:5 | LL | None::.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + String::default(); | error: used `unwrap_or()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:45:5 + --> tests/ui/unnecessary_literal_unwrap.rs:44:5 | LL | None::.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:47:5 + --> tests/ui/unnecessary_literal_unwrap.rs:46:5 | LL | None::.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:49:5 + --> tests/ui/unnecessary_literal_unwrap.rs:48:5 | LL | None::.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL + { 234 }; | error: used `unwrap_or_else()` on `None` value - --> tests/ui/unnecessary_literal_unwrap.rs:51:5 + --> tests/ui/unnecessary_literal_unwrap.rs:50:5 | LL | None::.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL + { 234 }; | error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:56:16 + --> tests/ui/unnecessary_literal_unwrap.rs:55:16 | LL | let _val = Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL + let _val = 1; | error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:58:16 + --> tests/ui/unnecessary_literal_unwrap.rs:57:16 | LL | let _val = Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL + let _val = 1; | error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:60:16 + --> tests/ui/unnecessary_literal_unwrap.rs:59:16 | LL | let _val = Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL + let _val = panic!("{:?}", 1); | error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:62:16 + --> tests/ui/unnecessary_literal_unwrap.rs:61:16 | LL | let _val = Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,7 +265,7 @@ LL + let _val = panic!("{1}: {:?}", 1, "this always happens"); | error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:65:5 + --> tests/ui/unnecessary_literal_unwrap.rs:64:5 | LL | Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL + 1; | error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:67:5 + --> tests/ui/unnecessary_literal_unwrap.rs:66:5 | LL | Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -289,7 +289,7 @@ LL + 1; | error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:69:5 + --> tests/ui/unnecessary_literal_unwrap.rs:68:5 | LL | Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL + panic!("{:?}", 1); | error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:71:5 + --> tests/ui/unnecessary_literal_unwrap.rs:70:5 | LL | Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -313,7 +313,7 @@ LL + panic!("{1}: {:?}", 1, "this always happens"); | error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:76:16 + --> tests/ui/unnecessary_literal_unwrap.rs:75:16 | LL | let _val = Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL + let _val = 1; | error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:78:16 + --> tests/ui/unnecessary_literal_unwrap.rs:77:16 | LL | let _val = Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +337,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:80:16 + --> tests/ui/unnecessary_literal_unwrap.rs:79:16 | LL | let _val = Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -349,7 +349,7 @@ LL + let _val = panic!("{:?}", 1); | error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:82:16 + --> tests/ui/unnecessary_literal_unwrap.rs:81:16 | LL | let _val = Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -361,7 +361,7 @@ LL + let _val = panic!("{1}: {:?}", 1, "this always happens"); | error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:85:5 + --> tests/ui/unnecessary_literal_unwrap.rs:84:5 | LL | Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -373,7 +373,7 @@ LL + 1; | error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:87:5 + --> tests/ui/unnecessary_literal_unwrap.rs:86:5 | LL | Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -385,7 +385,7 @@ LL + 1; | error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:89:5 + --> tests/ui/unnecessary_literal_unwrap.rs:88:5 | LL | Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -397,7 +397,7 @@ LL + panic!("{:?}", 1); | error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:91:5 + --> tests/ui/unnecessary_literal_unwrap.rs:90:5 | LL | Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -409,7 +409,7 @@ LL + panic!("{1}: {:?}", 1, "this always happens"); | error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:96:16 + --> tests/ui/unnecessary_literal_unwrap.rs:95:16 | LL | let _val = Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -421,7 +421,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:98:16 + --> tests/ui/unnecessary_literal_unwrap.rs:97:16 | LL | let _val = Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -433,7 +433,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:100:16 + --> tests/ui/unnecessary_literal_unwrap.rs:99:16 | LL | let _val = Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -445,7 +445,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:103:5 + --> tests/ui/unnecessary_literal_unwrap.rs:102:5 | LL | Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -457,7 +457,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:105:5 + --> tests/ui/unnecessary_literal_unwrap.rs:104:5 | LL | Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -469,7 +469,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:107:5 + --> tests/ui/unnecessary_literal_unwrap.rs:106:5 | LL | Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -481,7 +481,7 @@ LL + 1; | error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:112:16 + --> tests/ui/unnecessary_literal_unwrap.rs:111:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -493,7 +493,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:114:16 + --> tests/ui/unnecessary_literal_unwrap.rs:113:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -505,7 +505,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:116:16 + --> tests/ui/unnecessary_literal_unwrap.rs:115:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -517,7 +517,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:119:5 + --> tests/ui/unnecessary_literal_unwrap.rs:118:5 | LL | Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -529,7 +529,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:121:5 + --> tests/ui/unnecessary_literal_unwrap.rs:120:5 | LL | Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -541,7 +541,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:123:5 + --> tests/ui/unnecessary_literal_unwrap.rs:122:5 | LL | Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -553,7 +553,7 @@ LL + 1; | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:138:22 + --> tests/ui/unnecessary_literal_unwrap.rs:137:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -565,7 +565,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:140:22 + --> tests/ui/unnecessary_literal_unwrap.rs:139:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -577,7 +577,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe | error: used `unwrap_unchecked()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap.rs:143:22 + --> tests/ui/unnecessary_literal_unwrap.rs:142:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -589,7 +589,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:145:22 + --> tests/ui/unnecessary_literal_unwrap.rs:144:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -601,7 +601,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:147:22 + --> tests/ui/unnecessary_literal_unwrap.rs:146:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -613,7 +613,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; | error: used `unwrap_unchecked()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap.rs:149:22 + --> tests/ui/unnecessary_literal_unwrap.rs:148:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -625,7 +625,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_err_unchecked()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap.rs:151:22 + --> tests/ui/unnecessary_literal_unwrap.rs:150:22 | LL | let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/tests/ui/unnecessary_literal_unwrap_unfixable.rs index 2680d0a6697be..cd47d96f1c1e8 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.rs +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs @@ -1,6 +1,5 @@ #![warn(clippy::unnecessary_literal_unwrap)] -#![allow(unreachable_code)] -#![allow(clippy::unnecessary_lazy_evaluations, clippy::let_unit_value)] +#![expect(clippy::let_unit_value, clippy::unnecessary_lazy_evaluations)] //@no-rustfix fn unwrap_option_some() { let val = Some(1); diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr index 39418d0e3a969..278bbefd678dd 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr @@ -1,11 +1,11 @@ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:7:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:6:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:6:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:5:15 | LL | let val = Some(1); | ^^^^^^^ @@ -13,91 +13,91 @@ LL | let val = Some(1); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_unwrap)]` error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:10:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:9:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:6:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:5:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:15:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:14:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:15:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:14:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:18:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:17:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:18:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:17:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:22:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:21:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:20:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:25:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:24:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:20:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:31:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:30:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `None` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:30:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:29:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `expect()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:34:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:33:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `None` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:30:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:29:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:37:21 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:36:21 | LL | let _val3: u8 = None.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + let _val3: u8 = Default::default(); | error: used `unwrap_or_default()` on `None` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:40:5 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:39:5 | LL | None::<()>.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,505 +121,505 @@ LL + Default::default(); | error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:46:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:45:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:45:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:44:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:49:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:48:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:45:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:44:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:52:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:51:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:45:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:44:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:55:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:54:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:45:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:44:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:60:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:59:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:60:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:59:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:63:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:62:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:63:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:62:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:66:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:65:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:66:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:65:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:69:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:68:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:69:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:68:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:73:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:71:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:76:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:75:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:71:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:79:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:78:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:71:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:82:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:81:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:72:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:71:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:88:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:86:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:91:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:90:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:86:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:94:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:93:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:86:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:97:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:96:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:87:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:86:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:102:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:101:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:102:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:101:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:105:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:104:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:105:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:104:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:108:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:107:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:108:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:107:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:111:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:110:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:111:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:110:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:115:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:113:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:118:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:117:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:113:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:121:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:120:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:113:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:124:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:123:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:114:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:113:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:130:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:128:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:133:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:132:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:128:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:136:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:135:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:129:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:128:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:141:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:140:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:141:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:140:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:144:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:143:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:144:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:143:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:147:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:146:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:147:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:146:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:151:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:154:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:153:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:157:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:156:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:150:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:163:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:161:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:166:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:165:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:161:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:169:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:168:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:162:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:161:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:174:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:173:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:174:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:173:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:177:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:176:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:177:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:176:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:180:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:179:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:180:16 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:179:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:184:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:182:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:187:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:186:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:182:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:190:17 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:189:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:183:15 + --> tests/ui/unnecessary_literal_unwrap_unfixable.rs:182:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_map_on_constructor.fixed b/tests/ui/unnecessary_map_on_constructor.fixed index 4452fda38c406..9e6059808d3c8 100644 --- a/tests/ui/unnecessary_map_on_constructor.fixed +++ b/tests/ui/unnecessary_map_on_constructor.fixed @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::unnecessary_map_on_constructor)] use std::ffi::OsStr; diff --git a/tests/ui/unnecessary_map_on_constructor.rs b/tests/ui/unnecessary_map_on_constructor.rs index 0cd41f2b363ac..d731fc13e291c 100644 --- a/tests/ui/unnecessary_map_on_constructor.rs +++ b/tests/ui/unnecessary_map_on_constructor.rs @@ -1,4 +1,3 @@ -#![allow(unused)] #![warn(clippy::unnecessary_map_on_constructor)] use std::ffi::OsStr; diff --git a/tests/ui/unnecessary_map_on_constructor.stderr b/tests/ui/unnecessary_map_on_constructor.stderr index a191168208088..4e31d4f6bc8da 100644 --- a/tests/ui/unnecessary_map_on_constructor.stderr +++ b/tests/ui/unnecessary_map_on_constructor.stderr @@ -1,5 +1,5 @@ error: unnecessary `map` on constructor `Some(_)` - --> tests/ui/unnecessary_map_on_constructor.rs:32:13 + --> tests/ui/unnecessary_map_on_constructor.rs:31:13 | LL | let a = Some(x).map(fun); | ^^^^^^^^^^^^^^^^ help: try: `Some(fun(x))` @@ -8,43 +8,43 @@ LL | let a = Some(x).map(fun); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_map_on_constructor)]` error: unnecessary `map` on constructor `Ok(_)` - --> tests/ui/unnecessary_map_on_constructor.rs:34:27 + --> tests/ui/unnecessary_map_on_constructor.rs:33:27 | LL | let b: SimpleResult = Ok(x).map(fun); | ^^^^^^^^^^^^^^ help: try: `Ok(fun(x))` error: unnecessary `map_err` on constructor `Err(_)` - --> tests/ui/unnecessary_map_on_constructor.rs:36:27 + --> tests/ui/unnecessary_map_on_constructor.rs:35:27 | LL | let c: SimpleResult = Err(err).map_err(notfun); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Err(notfun(err))` error: unnecessary `map` on constructor `Option::Some(_)` - --> tests/ui/unnecessary_map_on_constructor.rs:39:13 + --> tests/ui/unnecessary_map_on_constructor.rs:38:13 | LL | let a = Option::Some(x).map(fun); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option::Some(fun(x))` error: unnecessary `map` on constructor `SimpleResult::Ok(_)` - --> tests/ui/unnecessary_map_on_constructor.rs:41:27 + --> tests/ui/unnecessary_map_on_constructor.rs:40:27 | LL | let b: SimpleResult = SimpleResult::Ok(x).map(fun); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `SimpleResult::Ok(fun(x))` error: unnecessary `map_err` on constructor `SimpleResult::Err(_)` - --> tests/ui/unnecessary_map_on_constructor.rs:43:27 + --> tests/ui/unnecessary_map_on_constructor.rs:42:27 | LL | let c: SimpleResult = SimpleResult::Err(err).map_err(notfun); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `SimpleResult::Err(notfun(err))` error: unnecessary `map` on constructor `Ok(_)` - --> tests/ui/unnecessary_map_on_constructor.rs:45:52 + --> tests/ui/unnecessary_map_on_constructor.rs:44:52 | LL | let b: std::result::Result = Ok(x).map(fun); | ^^^^^^^^^^^^^^ help: try: `Ok(fun(x))` error: unnecessary `map_err` on constructor `Err(_)` - --> tests/ui/unnecessary_map_on_constructor.rs:47:52 + --> tests/ui/unnecessary_map_on_constructor.rs:46:52 | LL | let c: std::result::Result = Err(err).map_err(notfun); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Err(notfun(err))` diff --git a/tests/ui/unnecessary_map_or.fixed b/tests/ui/unnecessary_map_or.fixed index b1f991b9b26c0..aa88ea8589aca 100644 --- a/tests/ui/unnecessary_map_or.fixed +++ b/tests/ui/unnecessary_map_or.fixed @@ -1,12 +1,7 @@ //@aux-build:proc_macros.rs #![warn(clippy::unnecessary_map_or)] -#![allow( - clippy::no_effect, - clippy::eq_op, - clippy::unnecessary_lazy_evaluations, - clippy::nonminimal_bool, - clippy::manual_assert_eq -)] +#![expect(clippy::eq_op, clippy::unnecessary_lazy_evaluations)] + #[clippy::msrv = "1.70.0"] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/unnecessary_map_or.rs b/tests/ui/unnecessary_map_or.rs index edd5ea9d878fe..cab89bf805616 100644 --- a/tests/ui/unnecessary_map_or.rs +++ b/tests/ui/unnecessary_map_or.rs @@ -1,12 +1,7 @@ //@aux-build:proc_macros.rs #![warn(clippy::unnecessary_map_or)] -#![allow( - clippy::no_effect, - clippy::eq_op, - clippy::unnecessary_lazy_evaluations, - clippy::nonminimal_bool, - clippy::manual_assert_eq -)] +#![expect(clippy::eq_op, clippy::unnecessary_lazy_evaluations)] + #[clippy::msrv = "1.70.0"] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/unnecessary_map_or.stderr b/tests/ui/unnecessary_map_or.stderr index 12a973c84213d..6deaa88824752 100644 --- a/tests/ui/unnecessary_map_or.stderr +++ b/tests/ui/unnecessary_map_or.stderr @@ -1,5 +1,5 @@ error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:16:13 + --> tests/ui/unnecessary_map_or.rs:11:13 | LL | let _ = Some(5).map_or(false, |n| n == 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + let _ = Some(5) == Some(5); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:18:13 + --> tests/ui/unnecessary_map_or.rs:13:13 | LL | let _ = Some(5).map_or(true, |n| n != 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _ = Some(5) != Some(5); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:20:13 + --> tests/ui/unnecessary_map_or.rs:15:13 | LL | let _ = Some(5).map_or(false, |n| { | _____________^ @@ -46,7 +46,7 @@ LL + let _ = Some(5) == Some(5); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:25:13 + --> tests/ui/unnecessary_map_or.rs:20:13 | LL | let _ = Some(5).map_or(false, |n| { | _____________^ @@ -63,7 +63,7 @@ LL + let _ = Some(5).is_some_and(|n| { | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:30:13 + --> tests/ui/unnecessary_map_or.rs:25:13 | LL | let _ = Some(vec![5]).map_or(false, |n| n == [5]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL + let _ = Some(vec![5]).is_some_and(|n| n == [5]); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:32:13 + --> tests/ui/unnecessary_map_or.rs:27:13 | LL | let _ = Some(vec![1]).map_or(false, |n| vec![2] == n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -87,7 +87,7 @@ LL + let _ = Some(vec![1]).is_some_and(|n| vec![2] == n); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:34:13 + --> tests/ui/unnecessary_map_or.rs:29:13 | LL | let _ = Some(5).map_or(false, |n| n == n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL + let _ = Some(5).is_some_and(|n| n == n); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:36:13 + --> tests/ui/unnecessary_map_or.rs:31:13 | LL | let _ = Some(5).map_or(false, |n| n == if 2 > 1 { n } else { 0 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL + let _ = Some(5).is_some_and(|n| n == if 2 > 1 { n } else { 0 }); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:38:13 + --> tests/ui/unnecessary_map_or.rs:33:13 | LL | let _ = Ok::, i32>(vec![5]).map_or(false, |n| n == [5]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -123,7 +123,7 @@ LL + let _ = Ok::, i32>(vec![5]).is_ok_and(|n| n == [5]); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:40:13 + --> tests/ui/unnecessary_map_or.rs:35:13 | LL | let _ = Ok::(5).map_or(false, |n| n == 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -135,7 +135,7 @@ LL + let _ = Ok::(5) == Ok(5); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:42:13 + --> tests/ui/unnecessary_map_or.rs:37:13 | LL | let _ = Some(5).map_or(false, |n| n == 5).then(|| 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -147,7 +147,7 @@ LL + let _ = (Some(5) == Some(5)).then(|| 1); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:44:13 + --> tests/ui/unnecessary_map_or.rs:39:13 | LL | let _ = Some(5).map_or(true, |n| n == 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -159,7 +159,7 @@ LL + let _ = Some(5).is_none_or(|n| n == 5); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:46:13 + --> tests/ui/unnecessary_map_or.rs:41:13 | LL | let _ = Some(5).map_or(true, |n| 5 == n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -171,7 +171,7 @@ LL + let _ = Some(5).is_none_or(|n| 5 == n); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:48:14 + --> tests/ui/unnecessary_map_or.rs:43:14 | LL | let _ = !Some(5).map_or(false, |n| n == 5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -183,7 +183,7 @@ LL + let _ = !(Some(5) == Some(5)); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:50:13 + --> tests/ui/unnecessary_map_or.rs:45:13 | LL | let _ = Some(5).map_or(false, |n| n == 5) || false; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -195,7 +195,7 @@ LL + let _ = (Some(5) == Some(5)) || false; | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:52:13 + --> tests/ui/unnecessary_map_or.rs:47:13 | LL | let _ = Some(5).map_or(false, |n| n == 5) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -207,7 +207,7 @@ LL + let _ = (Some(5) == Some(5)) as usize; | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:77:13 + --> tests/ui/unnecessary_map_or.rs:72:13 | LL | let _ = r.map_or(false, |x| x == 7); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -219,7 +219,7 @@ LL + let _ = r.is_ok_and(|x| x == 7); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:83:13 + --> tests/ui/unnecessary_map_or.rs:78:13 | LL | let _ = r.map_or(false, func); | ^^^^^^^^^^^^^^^^^^^^^ @@ -231,7 +231,7 @@ LL + let _ = r.is_ok_and(func); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:85:13 + --> tests/ui/unnecessary_map_or.rs:80:13 | LL | let _ = Some(5).map_or(false, func); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -243,7 +243,7 @@ LL + let _ = Some(5).is_some_and(func); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:87:13 + --> tests/ui/unnecessary_map_or.rs:82:13 | LL | let _ = Some(5).map_or(true, func); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -255,7 +255,7 @@ LL + let _ = Some(5).is_none_or(func); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:93:13 + --> tests/ui/unnecessary_map_or.rs:88:13 | LL | let _ = r.map_or(false, |x| x == 8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -267,7 +267,7 @@ LL + let _ = r == Ok(8); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:114:5 + --> tests/ui/unnecessary_map_or.rs:109:5 | LL | o.map_or(true, |n| n > 5) || (o as &Option).map_or(true, |n| n < 5) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -279,7 +279,7 @@ LL + o.is_none_or(|n| n > 5) || (o as &Option).map_or(true, |n| n < 5) | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:114:34 + --> tests/ui/unnecessary_map_or.rs:109:34 | LL | o.map_or(true, |n| n > 5) || (o as &Option).map_or(true, |n| n < 5) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -291,7 +291,7 @@ LL + o.map_or(true, |n| n > 5) || (o as &Option).is_none_or(|n| n < 5) | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:129:5 + --> tests/ui/unnecessary_map_or.rs:124:5 | LL | o.map_or(true, |n| n > 5) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -303,7 +303,7 @@ LL + o.is_none_or(|n| n > 5) | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:134:13 + --> tests/ui/unnecessary_map_or.rs:129:13 | LL | let x = a.map_or(false, |a| a == *s); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -315,7 +315,7 @@ LL + let x = a.is_some_and(|a| a == *s); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:136:13 + --> tests/ui/unnecessary_map_or.rs:131:13 | LL | let y = b.map_or(true, |b| b == *s); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -327,7 +327,7 @@ LL + let y = b.is_none_or(|b| b == *s); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:142:13 + --> tests/ui/unnecessary_map_or.rs:137:13 | LL | assert!(Some("test").map_or(false, |x| x == "test")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -339,7 +339,7 @@ LL + assert!(Some("test") == Some("test")); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:146:13 + --> tests/ui/unnecessary_map_or.rs:141:13 | LL | assert!(Some("test").map_or(false, |x| x == "test").then(|| 1).is_some()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -351,7 +351,7 @@ LL + assert!((Some("test") == Some("test")).then(|| 1).is_some()); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:163:9 + --> tests/ui/unnecessary_map_or.rs:158:9 | LL | _ = s.lock().unwrap().map_or(false, |s| s == "foo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -363,7 +363,7 @@ LL + _ = s.lock().unwrap().is_some_and(|s| s == "foo"); | error: this `map_or` can be simplified - --> tests/ui/unnecessary_map_or.rs:167:9 + --> tests/ui/unnecessary_map_or.rs:162:9 | LL | _ = s.map_or(false, |s| s == "foo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_min_or_max.fixed b/tests/ui/unnecessary_min_or_max.fixed index e2e1700e28b99..fd6f136e99e51 100644 --- a/tests/ui/unnecessary_min_or_max.fixed +++ b/tests/ui/unnecessary_min_or_max.fixed @@ -1,8 +1,7 @@ //@aux-build:external_consts.rs -#![allow(unused)] #![warn(clippy::unnecessary_min_or_max)] -#![allow(clippy::identity_op)] +#![expect(clippy::identity_op)] extern crate external_consts; diff --git a/tests/ui/unnecessary_min_or_max.rs b/tests/ui/unnecessary_min_or_max.rs index dd71ee2080305..a1aede84cd93b 100644 --- a/tests/ui/unnecessary_min_or_max.rs +++ b/tests/ui/unnecessary_min_or_max.rs @@ -1,8 +1,7 @@ //@aux-build:external_consts.rs -#![allow(unused)] #![warn(clippy::unnecessary_min_or_max)] -#![allow(clippy::identity_op)] +#![expect(clippy::identity_op)] extern crate external_consts; diff --git a/tests/ui/unnecessary_min_or_max.stderr b/tests/ui/unnecessary_min_or_max.stderr index b391d21d3bf43..e23450ec2a68f 100644 --- a/tests/ui/unnecessary_min_or_max.stderr +++ b/tests/ui/unnecessary_min_or_max.stderr @@ -1,5 +1,5 @@ error: `(-6_i32)` is never greater than `9` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:13:13 + --> tests/ui/unnecessary_min_or_max.rs:12:13 | LL | let _ = (-6_i32).min(9); | ^^^^^^^^^^^^^^^ help: try: `(-6_i32)` @@ -8,145 +8,145 @@ LL | let _ = (-6_i32).min(9); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_min_or_max)]` error: `(-6_i32)` is never greater than `9` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:15:13 + --> tests/ui/unnecessary_min_or_max.rs:14:13 | LL | let _ = (-6_i32).max(9); | ^^^^^^^^^^^^^^^ help: try: `9` error: `9_u32` is never smaller than `6` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:17:13 + --> tests/ui/unnecessary_min_or_max.rs:16:13 | LL | let _ = 9_u32.min(6); | ^^^^^^^^^^^^ help: try: `6` error: `9_u32` is never smaller than `6` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:19:13 + --> tests/ui/unnecessary_min_or_max.rs:18:13 | LL | let _ = 9_u32.max(6); | ^^^^^^^^^^^^ help: try: `9_u32` error: `6` is never greater than `7_u8` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:21:13 + --> tests/ui/unnecessary_min_or_max.rs:20:13 | LL | let _ = 6.min(7_u8); | ^^^^^^^^^^^ help: try: `6` error: `6` is never greater than `7_u8` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:23:13 + --> tests/ui/unnecessary_min_or_max.rs:22:13 | LL | let _ = 6.max(7_u8); | ^^^^^^^^^^^ help: try: `7_u8` error: `0` is never greater than `x` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:28:13 + --> tests/ui/unnecessary_min_or_max.rs:27:13 | LL | let _ = 0.min(x); | ^^^^^^^^ help: try: `0` error: `0` is never greater than `x` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:30:13 + --> tests/ui/unnecessary_min_or_max.rs:29:13 | LL | let _ = 0.max(x); | ^^^^^^^^ help: try: `x` error: `x` is never smaller than `0_u32` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:32:13 + --> tests/ui/unnecessary_min_or_max.rs:31:13 | LL | let _ = x.min(0_u32); | ^^^^^^^^^^^^ help: try: `0_u32` error: `x` is never smaller than `0_u32` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:34:13 + --> tests/ui/unnecessary_min_or_max.rs:33:13 | LL | let _ = x.max(0_u32); | ^^^^^^^^^^^^ help: try: `x` error: `i32::MIN` is never greater than `x` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:39:13 + --> tests/ui/unnecessary_min_or_max.rs:38:13 | LL | let _ = i32::MIN.min(x); | ^^^^^^^^^^^^^^^ help: try: `i32::MIN` error: `i32::MIN` is never greater than `x` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:41:13 + --> tests/ui/unnecessary_min_or_max.rs:40:13 | LL | let _ = i32::MIN.max(x); | ^^^^^^^^^^^^^^^ help: try: `x` error: `x` is never smaller than `i32::MIN` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:43:13 + --> tests/ui/unnecessary_min_or_max.rs:42:13 | LL | let _ = x.min(i32::MIN); | ^^^^^^^^^^^^^^^ help: try: `i32::MIN` error: `x` is never smaller than `i32::MIN` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:45:13 + --> tests/ui/unnecessary_min_or_max.rs:44:13 | LL | let _ = x.max(i32::MIN); | ^^^^^^^^^^^^^^^ help: try: `x` error: `x` is never smaller than `i32::MIN - 0` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:48:13 + --> tests/ui/unnecessary_min_or_max.rs:47:13 | LL | let _ = x.min(i32::MIN - 0); | ^^^^^^^^^^^^^^^^^^^ help: try: `i32::MIN - 0` error: `x` is never smaller than `i32::MIN` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:50:13 + --> tests/ui/unnecessary_min_or_max.rs:49:13 | LL | let _ = x.max(i32::MIN); | ^^^^^^^^^^^^^^^ help: try: `x` error: `x` is never smaller than `i32::MIN - 0` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:53:13 + --> tests/ui/unnecessary_min_or_max.rs:52:13 | LL | let _ = x.min(i32::MIN - 0); | ^^^^^^^^^^^^^^^^^^^ help: try: `i32::MIN - 0` error: `n` is never smaller than `0` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:83:13 + --> tests/ui/unnecessary_min_or_max.rs:82:13 | LL | let _ = n.min(0); | ^^^^^^^^ help: try: `0` error: `n` is never smaller than `0usize` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:86:13 + --> tests/ui/unnecessary_min_or_max.rs:85:13 | LL | let _ = n.min(0usize); | ^^^^^^^^^^^^^ help: try: `0usize` error: `(0usize)` is never greater than `n` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:89:13 + --> tests/ui/unnecessary_min_or_max.rs:88:13 | LL | let _ = (0usize).min(n); | ^^^^^^^^^^^^^^^ help: try: `(0usize)` error: `n` is never smaller than `usize::MIN` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:92:13 + --> tests/ui/unnecessary_min_or_max.rs:91:13 | LL | let _ = n.min(usize::MIN); | ^^^^^^^^^^^^^^^^^ help: try: `usize::MIN` error: `n` is never greater than `usize::MAX` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:95:13 + --> tests/ui/unnecessary_min_or_max.rs:94:13 | LL | let _ = n.max(usize::MAX); | ^^^^^^^^^^^^^^^^^ help: try: `usize::MAX` error: `(usize::MAX)` is never smaller than `n` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:98:13 + --> tests/ui/unnecessary_min_or_max.rs:97:13 | LL | let _ = (usize::MAX).max(n); | ^^^^^^^^^^^^^^^^^^^ help: try: `(usize::MAX)` error: `n` is never greater than `!0usize` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:101:13 + --> tests/ui/unnecessary_min_or_max.rs:100:13 | LL | let _ = n.max(!0usize); | ^^^^^^^^^^^^^^ help: try: `!0usize` error: `n` is never smaller than `0` and has therefore no effect - --> tests/ui/unnecessary_min_or_max.rs:104:13 + --> tests/ui/unnecessary_min_or_max.rs:103:13 | LL | let _ = n.max(0); | ^^^^^^^^ help: try: `n` diff --git a/tests/ui/unnecessary_mut_passed.fixed b/tests/ui/unnecessary_mut_passed.fixed index 876b61d29519b..7fff62b9e9384 100644 --- a/tests/ui/unnecessary_mut_passed.fixed +++ b/tests/ui/unnecessary_mut_passed.fixed @@ -1,4 +1,5 @@ -#![allow(clippy::mut_mut)] +#![warn(clippy::unnecessary_mut_passed)] +#![expect(clippy::mut_mut)] fn takes_ref(a: &i32) {} fn takes_refmut(a: &mut i32) {} diff --git a/tests/ui/unnecessary_mut_passed.rs b/tests/ui/unnecessary_mut_passed.rs index e92368bfffeb6..9beb4851db619 100644 --- a/tests/ui/unnecessary_mut_passed.rs +++ b/tests/ui/unnecessary_mut_passed.rs @@ -1,4 +1,5 @@ -#![allow(clippy::mut_mut)] +#![warn(clippy::unnecessary_mut_passed)] +#![expect(clippy::mut_mut)] fn takes_ref(a: &i32) {} fn takes_refmut(a: &mut i32) {} diff --git a/tests/ui/unnecessary_mut_passed.stderr b/tests/ui/unnecessary_mut_passed.stderr index ace11027e3e25..ff379d2132cf3 100644 --- a/tests/ui/unnecessary_mut_passed.stderr +++ b/tests/ui/unnecessary_mut_passed.stderr @@ -1,5 +1,5 @@ error: the function `takes_ref` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:57:15 + --> tests/ui/unnecessary_mut_passed.rs:58:15 | LL | takes_ref(&mut 42); | ^^^^^^^ @@ -13,7 +13,7 @@ LL + takes_ref(&42); | error: the function `takes_ref_ref` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:59:19 + --> tests/ui/unnecessary_mut_passed.rs:60:19 | LL | takes_ref_ref(&mut &42); | ^^^^^^^^ @@ -25,7 +25,7 @@ LL + takes_ref_ref(&&42); | error: the function `takes_ref_refmut` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:61:22 + --> tests/ui/unnecessary_mut_passed.rs:62:22 | LL | takes_ref_refmut(&mut &mut 42); | ^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + takes_ref_refmut(&&mut 42); | error: the function `takes_raw_const` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:63:21 + --> tests/ui/unnecessary_mut_passed.rs:64:21 | LL | takes_raw_const(&mut 42); | ^^^^^^^ @@ -49,7 +49,7 @@ LL + takes_raw_const(&42); | error: the function `as_ptr` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:67:12 + --> tests/ui/unnecessary_mut_passed.rs:68:12 | LL | as_ptr(&mut 42); | ^^^^^^^ @@ -61,7 +61,7 @@ LL + as_ptr(&42); | error: the function `as_ptr` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:70:12 + --> tests/ui/unnecessary_mut_passed.rs:71:12 | LL | as_ptr(&mut &42); | ^^^^^^^^ @@ -73,7 +73,7 @@ LL + as_ptr(&&42); | error: the function `as_ptr` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:73:12 + --> tests/ui/unnecessary_mut_passed.rs:74:12 | LL | as_ptr(&mut &mut 42); | ^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + as_ptr(&&mut 42); | error: the function `as_ptr` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:76:12 + --> tests/ui/unnecessary_mut_passed.rs:77:12 | LL | as_ptr(&mut 42); | ^^^^^^^ @@ -97,7 +97,7 @@ LL + as_ptr(&42); | error: the method `takes_ref` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:81:25 + --> tests/ui/unnecessary_mut_passed.rs:82:25 | LL | my_struct.takes_ref(&mut 42); | ^^^^^^^ @@ -109,7 +109,7 @@ LL + my_struct.takes_ref(&42); | error: the method `takes_ref_ref` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:83:29 + --> tests/ui/unnecessary_mut_passed.rs:84:29 | LL | my_struct.takes_ref_ref(&mut &42); | ^^^^^^^^ @@ -121,7 +121,7 @@ LL + my_struct.takes_ref_ref(&&42); | error: the method `takes_ref_refmut` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:85:32 + --> tests/ui/unnecessary_mut_passed.rs:86:32 | LL | my_struct.takes_ref_refmut(&mut &mut 42); | ^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + my_struct.takes_ref_refmut(&&mut 42); | error: the method `takes_raw_const` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:87:31 + --> tests/ui/unnecessary_mut_passed.rs:88:31 | LL | my_struct.takes_raw_const(&mut 42); | ^^^^^^^ @@ -145,7 +145,7 @@ LL + my_struct.takes_raw_const(&42); | error: the method `takes_nothing` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:175:5 + --> tests/ui/unnecessary_mut_passed.rs:176:5 | LL | (&mut my_struct).takes_nothing(); | ^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + (&my_struct).takes_nothing(); | error: the method `takes_ref` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:180:5 + --> tests/ui/unnecessary_mut_passed.rs:181:5 | LL | (&mut my_struct).takes_ref(&mut 42); | ^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + (&my_struct).takes_ref(&mut 42); | error: the method `takes_ref` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:180:32 + --> tests/ui/unnecessary_mut_passed.rs:181:32 | LL | (&mut my_struct).takes_ref(&mut 42); | ^^^^^^^ @@ -181,7 +181,7 @@ LL + (&mut my_struct).takes_ref(&42); | error: the method `takes_ref` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:184:5 + --> tests/ui/unnecessary_mut_passed.rs:185:5 | LL | (&mut my_struct).takes_ref((&mut 42)); | ^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + (&my_struct).takes_ref((&mut 42)); | error: the method `takes_ref` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:184:32 + --> tests/ui/unnecessary_mut_passed.rs:185:32 | LL | (&mut my_struct).takes_ref((&mut 42)); | ^^^^^^^^^ @@ -205,7 +205,7 @@ LL + (&mut my_struct).takes_ref((&42)); | error: the method `takes_ref` doesn't need a mutable reference - --> tests/ui/unnecessary_mut_passed.rs:188:25 + --> tests/ui/unnecessary_mut_passed.rs:189:25 | LL | my_struct.takes_ref((&mut 42)); | ^^^^^^^^^ diff --git a/tests/ui/unnecessary_operation.fixed b/tests/ui/unnecessary_operation.fixed index 2b447e5c4a36d..092cc7c348909 100644 --- a/tests/ui/unnecessary_operation.fixed +++ b/tests/ui/unnecessary_operation.fixed @@ -1,12 +1,5 @@ -#![allow( - clippy::deref_addrof, - clippy::no_effect, - clippy::uninlined_format_args, - clippy::unnecessary_struct_initialization, - dead_code, - unused -)] #![warn(clippy::unnecessary_operation)] +#![allow(clippy::deref_addrof, clippy::no_effect)] use std::fmt::Display; use std::ops::Shl; diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs index def14469c9bdc..c298bd8c15fcb 100644 --- a/tests/ui/unnecessary_operation.rs +++ b/tests/ui/unnecessary_operation.rs @@ -1,12 +1,5 @@ -#![allow( - clippy::deref_addrof, - clippy::no_effect, - clippy::uninlined_format_args, - clippy::unnecessary_struct_initialization, - dead_code, - unused -)] #![warn(clippy::unnecessary_operation)] +#![allow(clippy::deref_addrof, clippy::no_effect)] use std::fmt::Display; use std::ops::Shl; diff --git a/tests/ui/unnecessary_operation.stderr b/tests/ui/unnecessary_operation.stderr index 55751cb08b136..92434be9d798e 100644 --- a/tests/ui/unnecessary_operation.stderr +++ b/tests/ui/unnecessary_operation.stderr @@ -1,5 +1,5 @@ error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:71:5 + --> tests/ui/unnecessary_operation.rs:64:5 | LL | Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` @@ -8,103 +8,103 @@ LL | Tuple(get_number()); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_operation)]` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:73:5 + --> tests/ui/unnecessary_operation.rs:66:5 | LL | Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:75:5 + --> tests/ui/unnecessary_operation.rs:68:5 | LL | Struct { ..get_struct() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_struct();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:77:5 + --> tests/ui/unnecessary_operation.rs:70:5 | LL | Enum::Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:79:5 + --> tests/ui/unnecessary_operation.rs:72:5 | LL | Enum::Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:81:5 + --> tests/ui/unnecessary_operation.rs:74:5 | LL | 5 + get_number(); | ^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5; get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:83:5 + --> tests/ui/unnecessary_operation.rs:76:5 | LL | *&get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:85:5 + --> tests/ui/unnecessary_operation.rs:78:5 | LL | &get_number(); | ^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:87:5 + --> tests/ui/unnecessary_operation.rs:80:5 | LL | (5, 6, get_number()); | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5; 6; get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:89:5 + --> tests/ui/unnecessary_operation.rs:82:5 | LL | get_number()..; | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:91:5 + --> tests/ui/unnecessary_operation.rs:84:5 | LL | ..get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:93:5 + --> tests/ui/unnecessary_operation.rs:86:5 | LL | 5..get_number(); | ^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5; get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:95:5 + --> tests/ui/unnecessary_operation.rs:88:5 | LL | [42, get_number()]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42; get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:97:5 + --> tests/ui/unnecessary_operation.rs:90:5 | LL | [42, 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:99:5 + --> tests/ui/unnecessary_operation.rs:92:5 | LL | (42, get_number()).1; | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42; get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:101:5 + --> tests/ui/unnecessary_operation.rs:94:5 | LL | [get_number(); 55]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:103:5 + --> tests/ui/unnecessary_operation.rs:96:5 | LL | [42; 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42; 55].len() > get_usize());` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:105:5 + --> tests/ui/unnecessary_operation.rs:98:5 | LL | / { LL | | @@ -113,7 +113,7 @@ LL | | }; | |______^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:109:5 + --> tests/ui/unnecessary_operation.rs:102:5 | LL | / FooString { LL | | @@ -122,13 +122,13 @@ LL | | }; | |______^ help: statement can be reduced to: `String::from("blah");` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:150:5 + --> tests/ui/unnecessary_operation.rs:143:5 | LL | [42, 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());` error: unnecessary operation - --> tests/ui/unnecessary_operation.rs:181:9 + --> tests/ui/unnecessary_operation.rs:174:9 | LL | / { LL | | never() diff --git a/tests/ui/unnecessary_option_map_or_else.fixed b/tests/ui/unnecessary_option_map_or_else.fixed index 8d25efbeea001..867528dd7e44f 100644 --- a/tests/ui/unnecessary_option_map_or_else.fixed +++ b/tests/ui/unnecessary_option_map_or_else.fixed @@ -1,11 +1,11 @@ #![warn(clippy::unnecessary_option_map_or_else)] #![allow( - clippy::let_and_return, clippy::let_unit_value, + clippy::needless_return, clippy::unnecessary_lazy_evaluations, - clippy::unnecessary_literal_unwrap, - clippy::needless_return + clippy::unnecessary_literal_unwrap )] +#![expect(clippy::let_and_return)] const fn double_it(x: i32) -> i32 { x * 2 diff --git a/tests/ui/unnecessary_option_map_or_else.rs b/tests/ui/unnecessary_option_map_or_else.rs index 42d4ad6ac1f82..325e63879ba24 100644 --- a/tests/ui/unnecessary_option_map_or_else.rs +++ b/tests/ui/unnecessary_option_map_or_else.rs @@ -1,11 +1,11 @@ #![warn(clippy::unnecessary_option_map_or_else)] #![allow( - clippy::let_and_return, clippy::let_unit_value, + clippy::needless_return, clippy::unnecessary_lazy_evaluations, - clippy::unnecessary_literal_unwrap, - clippy::needless_return + clippy::unnecessary_literal_unwrap )] +#![expect(clippy::let_and_return)] const fn double_it(x: i32) -> i32 { x * 2 diff --git a/tests/ui/unnecessary_os_str_debug_formatting.rs b/tests/ui/unnecessary_os_str_debug_formatting.rs index 66590be3d0543..c5b279ea2ae12 100644 --- a/tests/ui/unnecessary_os_str_debug_formatting.rs +++ b/tests/ui/unnecessary_os_str_debug_formatting.rs @@ -1,5 +1,5 @@ #![warn(clippy::unnecessary_debug_formatting)] -#![allow(clippy::uninlined_format_args)] +#![expect(clippy::uninlined_format_args)] use std::ffi::{OsStr, OsString}; diff --git a/tests/ui/unnecessary_path_debug_formatting.rs b/tests/ui/unnecessary_path_debug_formatting.rs index 215e0d5d7802e..303cded913071 100644 --- a/tests/ui/unnecessary_path_debug_formatting.rs +++ b/tests/ui/unnecessary_path_debug_formatting.rs @@ -1,5 +1,5 @@ #![warn(clippy::unnecessary_debug_formatting)] -#![allow(clippy::uninlined_format_args)] +#![expect(clippy::uninlined_format_args)] use std::ffi::{OsStr, OsString}; use std::ops::Deref; diff --git a/tests/ui/unnecessary_result_map_or_else.fixed b/tests/ui/unnecessary_result_map_or_else.fixed index 55542519bdb7e..2bb8e22a0bb90 100644 --- a/tests/ui/unnecessary_result_map_or_else.fixed +++ b/tests/ui/unnecessary_result_map_or_else.fixed @@ -1,10 +1,6 @@ #![warn(clippy::unnecessary_result_map_or_else)] -#![allow( - clippy::unnecessary_literal_unwrap, - clippy::let_and_return, - clippy::let_unit_value, - clippy::needless_return -)] +#![allow(clippy::needless_return, clippy::unnecessary_literal_unwrap)] +#![expect(clippy::let_and_return, clippy::let_unit_value)] fn main() { let x: Result<(), ()> = Ok(()); diff --git a/tests/ui/unnecessary_result_map_or_else.rs b/tests/ui/unnecessary_result_map_or_else.rs index 21a4826911e58..829dd035adc32 100644 --- a/tests/ui/unnecessary_result_map_or_else.rs +++ b/tests/ui/unnecessary_result_map_or_else.rs @@ -1,10 +1,6 @@ #![warn(clippy::unnecessary_result_map_or_else)] -#![allow( - clippy::unnecessary_literal_unwrap, - clippy::let_and_return, - clippy::let_unit_value, - clippy::needless_return -)] +#![allow(clippy::needless_return, clippy::unnecessary_literal_unwrap)] +#![expect(clippy::let_and_return, clippy::let_unit_value)] fn main() { let x: Result<(), ()> = Ok(()); diff --git a/tests/ui/unnecessary_result_map_or_else.stderr b/tests/ui/unnecessary_result_map_or_else.stderr index f76999127c647..2443083d4390c 100644 --- a/tests/ui/unnecessary_result_map_or_else.stderr +++ b/tests/ui/unnecessary_result_map_or_else.stderr @@ -1,5 +1,5 @@ error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:11:5 + --> tests/ui/unnecessary_result_map_or_else.rs:7:5 | LL | x.map_or_else(|err| err, |n| n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + x.unwrap_or_else(|err| err); | error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:16:5 + --> tests/ui/unnecessary_result_map_or_else.rs:12:5 | LL | x.map_or_else(|err: ()| err, |n: ()| n); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + x.unwrap_or_else(|err: ()| err); | error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:27:5 + --> tests/ui/unnecessary_result_map_or_else.rs:23:5 | LL | / x.map_or_else( LL | | @@ -51,7 +51,7 @@ LL + x.unwrap_or_else(|err| err); | error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:39:5 + --> tests/ui/unnecessary_result_map_or_else.rs:35:5 | LL | / x.map_or_else( LL | | @@ -77,7 +77,7 @@ LL + x.unwrap_or_else(|err| err); | error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:91:5 + --> tests/ui/unnecessary_result_map_or_else.rs:87:5 | LL | x.map_or_else(|err| err, |(a, b)| (a, b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL + x.unwrap_or_else(|err| err); | error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:96:5 + --> tests/ui/unnecessary_result_map_or_else.rs:92:5 | LL | / x.map_or_else( LL | | @@ -115,7 +115,7 @@ LL + x.unwrap_or_else(|err| err); | error: unused "map closure" when calling `Result::map_or_else` value - --> tests/ui/unnecessary_result_map_or_else.rs:108:5 + --> tests/ui/unnecessary_result_map_or_else.rs:104:5 | LL | / x.map_or_else( LL | | diff --git a/tests/ui/unnecessary_safety_comment.rs b/tests/ui/unnecessary_safety_comment.rs index 75e8315343d3d..80e065c64fe52 100644 --- a/tests/ui/unnecessary_safety_comment.rs +++ b/tests/ui/unnecessary_safety_comment.rs @@ -1,5 +1,5 @@ #![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)] -#![allow(clippy::let_unit_value, clippy::missing_safety_doc, clippy::needless_ifs)] +#![expect(clippy::needless_ifs)] mod unsafe_items_invalid_comment { // SAFETY: diff --git a/tests/ui/unnecessary_self_imports.fixed b/tests/ui/unnecessary_self_imports.fixed index 0fd74705bde02..f3405f486b2d4 100644 --- a/tests/ui/unnecessary_self_imports.fixed +++ b/tests/ui/unnecessary_self_imports.fixed @@ -1,5 +1,4 @@ #![warn(clippy::unnecessary_self_imports)] -#![allow(unused_imports, dead_code)] use std::collections::hash_map::{self, *}; use std::fs as alias; diff --git a/tests/ui/unnecessary_self_imports.rs b/tests/ui/unnecessary_self_imports.rs index d09c5fcb8caa6..c15efb274f46a 100644 --- a/tests/ui/unnecessary_self_imports.rs +++ b/tests/ui/unnecessary_self_imports.rs @@ -1,5 +1,4 @@ #![warn(clippy::unnecessary_self_imports)] -#![allow(unused_imports, dead_code)] use std::collections::hash_map::{self, *}; use std::fs::{self as alias}; diff --git a/tests/ui/unnecessary_self_imports.stderr b/tests/ui/unnecessary_self_imports.stderr index 1bb22c46a6c11..8e7add731cd60 100644 --- a/tests/ui/unnecessary_self_imports.stderr +++ b/tests/ui/unnecessary_self_imports.stderr @@ -1,5 +1,5 @@ error: import ending with `::{self}` - --> tests/ui/unnecessary_self_imports.rs:5:1 + --> tests/ui/unnecessary_self_imports.rs:4:1 | LL | use std::fs::{self as alias}; | ^^^^^^^^^-------------------- @@ -11,7 +11,7 @@ LL | use std::fs::{self as alias}; = help: to override `-D warnings` add `#[allow(clippy::unnecessary_self_imports)]` error: import ending with `::{self}` - --> tests/ui/unnecessary_self_imports.rs:8:1 + --> tests/ui/unnecessary_self_imports.rs:7:1 | LL | use std::rc::{self}; | ^^^^^^^^^----------- diff --git a/tests/ui/unnecessary_semicolon.edition2021.fixed b/tests/ui/unnecessary_semicolon.edition2021.fixed index 797f1505f4992..624aefe087195 100644 --- a/tests/ui/unnecessary_semicolon.edition2021.fixed +++ b/tests/ui/unnecessary_semicolon.edition2021.fixed @@ -4,7 +4,7 @@ #![warn(clippy::unnecessary_semicolon)] #![feature(postfix_match)] -#![allow(clippy::single_match)] +#![expect(clippy::single_match)] fn no_lint(mut x: u32) -> Option { Some(())?; diff --git a/tests/ui/unnecessary_semicolon.edition2024.fixed b/tests/ui/unnecessary_semicolon.edition2024.fixed index d2609cea00027..87cda0f34ed91 100644 --- a/tests/ui/unnecessary_semicolon.edition2024.fixed +++ b/tests/ui/unnecessary_semicolon.edition2024.fixed @@ -4,7 +4,7 @@ #![warn(clippy::unnecessary_semicolon)] #![feature(postfix_match)] -#![allow(clippy::single_match)] +#![expect(clippy::single_match)] fn no_lint(mut x: u32) -> Option { Some(())?; diff --git a/tests/ui/unnecessary_semicolon.rs b/tests/ui/unnecessary_semicolon.rs index 55f1ec84cb0ea..d2badb556255a 100644 --- a/tests/ui/unnecessary_semicolon.rs +++ b/tests/ui/unnecessary_semicolon.rs @@ -4,7 +4,7 @@ #![warn(clippy::unnecessary_semicolon)] #![feature(postfix_match)] -#![allow(clippy::single_match)] +#![expect(clippy::single_match)] fn no_lint(mut x: u32) -> Option { Some(())?; diff --git a/tests/ui/unnecessary_sort_by.fixed b/tests/ui/unnecessary_sort_by.fixed index db31b339a08b0..f2753252bd5f0 100644 --- a/tests/ui/unnecessary_sort_by.fixed +++ b/tests/ui/unnecessary_sort_by.fixed @@ -1,4 +1,5 @@ -#![allow(clippy::stable_sort_primitive, clippy::useless_vec)] +#![warn(clippy::unnecessary_sort_by)] +#![expect(clippy::useless_vec)] use std::cell::Ref; diff --git a/tests/ui/unnecessary_sort_by.rs b/tests/ui/unnecessary_sort_by.rs index a31cf29679993..bcf2e1ca694bc 100644 --- a/tests/ui/unnecessary_sort_by.rs +++ b/tests/ui/unnecessary_sort_by.rs @@ -1,4 +1,5 @@ -#![allow(clippy::stable_sort_primitive, clippy::useless_vec)] +#![warn(clippy::unnecessary_sort_by)] +#![expect(clippy::useless_vec)] use std::cell::Ref; diff --git a/tests/ui/unnecessary_sort_by.stderr b/tests/ui/unnecessary_sort_by.stderr index 868f7895fc069..afd2cd72e5db3 100644 --- a/tests/ui/unnecessary_sort_by.stderr +++ b/tests/ui/unnecessary_sort_by.stderr @@ -1,5 +1,5 @@ error: consider using `sort` - --> tests/ui/unnecessary_sort_by.rs:12:5 + --> tests/ui/unnecessary_sort_by.rs:13:5 | LL | vec.sort_by(|a, b| a.cmp(b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + vec.sort(); | error: consider using `sort_unstable` - --> tests/ui/unnecessary_sort_by.rs:14:5 + --> tests/ui/unnecessary_sort_by.rs:15:5 | LL | vec.sort_unstable_by(|a, b| a.cmp(b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + vec.sort_unstable(); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:16:5 + --> tests/ui/unnecessary_sort_by.rs:17:5 | LL | vec.sort_by(|a, b| (a + 5).abs().cmp(&(b + 5).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + vec.sort_by_key(|a| (a + 5).abs()); | error: consider using `sort_unstable_by_key` - --> tests/ui/unnecessary_sort_by.rs:18:5 + --> tests/ui/unnecessary_sort_by.rs:19:5 | LL | vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + vec.sort_unstable_by_key(|a| id(-a)); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:22:5 + --> tests/ui/unnecessary_sort_by.rs:23:5 | LL | vec.sort_by(|a, b| (b + 5).abs().cmp(&(a + 5).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + vec.sort_by_key(|a| std::cmp::Reverse((a + 5).abs())); | error: consider using `sort_unstable_by_key` - --> tests/ui/unnecessary_sort_by.rs:24:5 + --> tests/ui/unnecessary_sort_by.rs:25:5 | LL | vec.sort_unstable_by(|a, b| id(-b).cmp(&id(-a))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + vec.sort_unstable_by_key(|a| std::cmp::Reverse(id(-a))); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:35:5 + --> tests/ui/unnecessary_sort_by.rs:36:5 | LL | vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + vec.sort_by_key(|a| (***a).abs()); | error: consider using `sort_unstable_by_key` - --> tests/ui/unnecessary_sort_by.rs:37:5 + --> tests/ui/unnecessary_sort_by.rs:38:5 | LL | vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + vec.sort_unstable_by_key(|a| (***a).abs()); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:97:9 + --> tests/ui/unnecessary_sort_by.rs:98:9 | LL | args.sort_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + args.sort_by_key(|a| a.name()); | error: consider using `sort_unstable_by_key` - --> tests/ui/unnecessary_sort_by.rs:99:9 + --> tests/ui/unnecessary_sort_by.rs:100:9 | LL | args.sort_unstable_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + args.sort_unstable_by_key(|a| a.name()); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:102:9 + --> tests/ui/unnecessary_sort_by.rs:103:9 | LL | args.sort_by(|a, b| b.name().cmp(&a.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + args.sort_by_key(|a| std::cmp::Reverse(a.name())); | error: consider using `sort_unstable_by_key` - --> tests/ui/unnecessary_sort_by.rs:104:9 + --> tests/ui/unnecessary_sort_by.rs:105:9 | LL | args.sort_unstable_by(|a, b| b.name().cmp(&a.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + args.sort_unstable_by_key(|a| std::cmp::Reverse(a.name())); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:114:5 + --> tests/ui/unnecessary_sort_by.rs:115:5 | LL | v.sort_by(|a, b| a.0.cmp(&b.0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + v.sort_by_key(|a| a.0); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:132:5 + --> tests/ui/unnecessary_sort_by.rs:133:5 | LL | items.sort_by(|item1, item2| item1.key.cmp(&item2.key)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + items.sort_by_key(|item1| item1.key); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:137:5 + --> tests/ui/unnecessary_sort_by.rs:138:5 | LL | items.sort_by(|item1, item2| item1.value.clone().cmp(&item2.value.clone())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + items.sort_by_key(|item1| item1.value.clone()); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:143:5 + --> tests/ui/unnecessary_sort_by.rs:144:5 | LL | v.sort_by(|(_, s1), (_, s2)| s1.cmp(s2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + v.sort_by_key(|(_, s1)| *s1); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:150:5 + --> tests/ui/unnecessary_sort_by.rs:151:5 | LL | v.sort_by(|Foo { bar: b1 }, Foo { bar: b2 }| b1.cmp(b2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL + v.sort_by_key(|Foo { bar: b1 }| *b1); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:155:5 + --> tests/ui/unnecessary_sort_by.rs:156:5 | LL | v.sort_by(|Baz(b1), Baz(b2)| b1.cmp(b2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL + v.sort_by_key(|Baz(b1)| *b1); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:158:5 + --> tests/ui/unnecessary_sort_by.rs:159:5 | LL | v.sort_by(|&Baz(b1), &Baz(b2)| b1.cmp(&b2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL + v.sort_by_key(|&Baz(b1)| b1); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:162:5 + --> tests/ui/unnecessary_sort_by.rs:163:5 | LL | v.sort_by(|&&b1, &&b2| b1.cmp(&b2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL + v.sort_by_key(|&&b1| b1); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:166:5 + --> tests/ui/unnecessary_sort_by.rs:167:5 | LL | v.sort_by(|[a1, b1], [a2, b2]| a1.cmp(a2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL + v.sort_by_key(|[a1, b1]| *a1); | error: consider using `sort_by_key` - --> tests/ui/unnecessary_sort_by.rs:169:5 + --> tests/ui/unnecessary_sort_by.rs:170:5 | LL | v.sort_by(|[a1, b1], [a2, b2]| (a1 - b1).cmp(&(a2 - b2))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_struct_initialization.fixed b/tests/ui/unnecessary_struct_initialization.fixed index 07dc90acfa308..c39a336674fd1 100644 --- a/tests/ui/unnecessary_struct_initialization.fixed +++ b/tests/ui/unnecessary_struct_initialization.fixed @@ -1,5 +1,5 @@ -#![allow(clippy::non_canonical_clone_impl, unused)] #![warn(clippy::unnecessary_struct_initialization)] +#![allow(clippy::non_canonical_clone_impl)] struct S { f: String, diff --git a/tests/ui/unnecessary_struct_initialization.rs b/tests/ui/unnecessary_struct_initialization.rs index 12a444fc878b9..28bb450d219cb 100644 --- a/tests/ui/unnecessary_struct_initialization.rs +++ b/tests/ui/unnecessary_struct_initialization.rs @@ -1,5 +1,5 @@ -#![allow(clippy::non_canonical_clone_impl, unused)] #![warn(clippy::unnecessary_struct_initialization)] +#![allow(clippy::non_canonical_clone_impl)] struct S { f: String, diff --git a/tests/ui/unnecessary_to_owned.fixed b/tests/ui/unnecessary_to_owned.fixed index 590359bc1ad2b..dbcb32bd4823e 100644 --- a/tests/ui/unnecessary_to_owned.fixed +++ b/tests/ui/unnecessary_to_owned.fixed @@ -1,13 +1,11 @@ -#![allow( +#![warn(clippy::redundant_clone, clippy::unnecessary_to_owned)] +#![expect( clippy::manual_async_fn, clippy::needless_borrow, clippy::needless_borrows_for_generic_args, - clippy::needless_lifetimes, clippy::owned_cow, - clippy::ptr_arg, - clippy::uninlined_format_args + clippy::ptr_arg )] -#![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)] use std::borrow::Cow; use std::ffi::{CStr, CString, OsStr, OsString}; @@ -44,7 +42,6 @@ impl X { } } -#[allow(dead_code)] #[derive(Clone)] enum FileType { Account, @@ -312,7 +309,6 @@ fn require_string(_: &String) {} // https://github.com/rust-lang/rust-clippy/issues/8507 mod issue_8507 { - #![allow(dead_code)] struct Opaque

(P); @@ -362,7 +358,6 @@ mod issue_8507 { // https://github.com/rust-lang/rust-clippy/issues/8759 mod issue_8759 { - #![allow(dead_code)] #[derive(Default)] struct View {} @@ -393,7 +388,6 @@ mod issue_8759 { } mod issue_8759_variant { - #![allow(dead_code)] #[derive(Clone, Default)] struct View {} @@ -417,7 +411,6 @@ mod issue_8759_variant { } mod issue_9317 { - #![allow(dead_code)] struct Bytes {} @@ -446,7 +439,6 @@ mod issue_9317 { } mod issue_9351 { - #![allow(dead_code)] use std::ops::Deref; use std::path::{Path, PathBuf}; @@ -507,7 +499,6 @@ mod issue_9351 { } mod issue_9504 { - #![allow(dead_code)] async fn foo>(_: S) {} async fn bar() { @@ -516,7 +507,6 @@ mod issue_9504 { } mod issue_9771a { - #![allow(dead_code)] use std::marker::PhantomData; @@ -534,7 +524,6 @@ mod issue_9771a { } mod issue_9771b { - #![allow(dead_code)] pub struct Key>(K); @@ -548,7 +537,6 @@ mod issue_9771b { // The ICE is triggered by the call to `to_owned` on this line: // https://github.com/oxigraph/rio/blob/66635b9ff8e5423e58932353fa40d6e64e4820f7/testsuite/src/parser_evaluator.rs#L116 mod issue_10021 { - #![allow(unused)] pub struct Iri(T); @@ -565,7 +553,6 @@ mod issue_10021 { } mod issue_10033 { - #![allow(dead_code)] use std::fmt::Display; use std::ops::Deref; diff --git a/tests/ui/unnecessary_to_owned.rs b/tests/ui/unnecessary_to_owned.rs index d1e3e6497c0af..1f8cb7681a887 100644 --- a/tests/ui/unnecessary_to_owned.rs +++ b/tests/ui/unnecessary_to_owned.rs @@ -1,13 +1,11 @@ -#![allow( +#![warn(clippy::redundant_clone, clippy::unnecessary_to_owned)] +#![expect( clippy::manual_async_fn, clippy::needless_borrow, clippy::needless_borrows_for_generic_args, - clippy::needless_lifetimes, clippy::owned_cow, - clippy::ptr_arg, - clippy::uninlined_format_args + clippy::ptr_arg )] -#![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)] use std::borrow::Cow; use std::ffi::{CStr, CString, OsStr, OsString}; @@ -44,7 +42,6 @@ impl X { } } -#[allow(dead_code)] #[derive(Clone)] enum FileType { Account, @@ -312,7 +309,6 @@ fn require_string(_: &String) {} // https://github.com/rust-lang/rust-clippy/issues/8507 mod issue_8507 { - #![allow(dead_code)] struct Opaque

(P); @@ -362,7 +358,6 @@ mod issue_8507 { // https://github.com/rust-lang/rust-clippy/issues/8759 mod issue_8759 { - #![allow(dead_code)] #[derive(Default)] struct View {} @@ -393,7 +388,6 @@ mod issue_8759 { } mod issue_8759_variant { - #![allow(dead_code)] #[derive(Clone, Default)] struct View {} @@ -417,7 +411,6 @@ mod issue_8759_variant { } mod issue_9317 { - #![allow(dead_code)] struct Bytes {} @@ -446,7 +439,6 @@ mod issue_9317 { } mod issue_9351 { - #![allow(dead_code)] use std::ops::Deref; use std::path::{Path, PathBuf}; @@ -507,7 +499,6 @@ mod issue_9351 { } mod issue_9504 { - #![allow(dead_code)] async fn foo>(_: S) {} async fn bar() { @@ -516,7 +507,6 @@ mod issue_9504 { } mod issue_9771a { - #![allow(dead_code)] use std::marker::PhantomData; @@ -534,7 +524,6 @@ mod issue_9771a { } mod issue_9771b { - #![allow(dead_code)] pub struct Key>(K); @@ -548,7 +537,6 @@ mod issue_9771b { // The ICE is triggered by the call to `to_owned` on this line: // https://github.com/oxigraph/rio/blob/66635b9ff8e5423e58932353fa40d6e64e4820f7/testsuite/src/parser_evaluator.rs#L116 mod issue_10021 { - #![allow(unused)] pub struct Iri(T); @@ -565,7 +553,6 @@ mod issue_10021 { } mod issue_10033 { - #![allow(dead_code)] use std::fmt::Display; use std::ops::Deref; diff --git a/tests/ui/unnecessary_to_owned.stderr b/tests/ui/unnecessary_to_owned.stderr index 50e3d5eb21950..158adffe0f7f8 100644 --- a/tests/ui/unnecessary_to_owned.stderr +++ b/tests/ui/unnecessary_to_owned.stderr @@ -1,11 +1,11 @@ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:218:64 + --> tests/ui/unnecessary_to_owned.rs:215:64 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:218:20 + --> tests/ui/unnecessary_to_owned.rs:215:20 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,55 +13,55 @@ LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()) = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:220:40 + --> tests/ui/unnecessary_to_owned.rs:217:40 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:220:21 + --> tests/ui/unnecessary_to_owned.rs:217:21 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:222:48 + --> tests/ui/unnecessary_to_owned.rs:219:48 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:222:19 + --> tests/ui/unnecessary_to_owned.rs:219:19 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:224:35 + --> tests/ui/unnecessary_to_owned.rs:221:35 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:224:18 + --> tests/ui/unnecessary_to_owned.rs:221:18 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^^^^^^ error: redundant clone - --> tests/ui/unnecessary_to_owned.rs:226:39 + --> tests/ui/unnecessary_to_owned.rs:223:39 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> tests/ui/unnecessary_to_owned.rs:226:20 + --> tests/ui/unnecessary_to_owned.rs:223:20 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^^^^^^^^^ error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:66:36 + --> tests/ui/unnecessary_to_owned.rs:63:36 | LL | require_c_str(&Cow::from(c_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this @@ -70,391 +70,391 @@ LL | require_c_str(&Cow::from(c_str).into_owned()); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:68:19 + --> tests/ui/unnecessary_to_owned.rs:65:19 | LL | require_c_str(&c_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_os_string` - --> tests/ui/unnecessary_to_owned.rs:71:20 + --> tests/ui/unnecessary_to_owned.rs:68:20 | LL | require_os_str(&os_str.to_os_string()); | ^^^^^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:73:38 + --> tests/ui/unnecessary_to_owned.rs:70:38 | LL | require_os_str(&Cow::from(os_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:75:20 + --> tests/ui/unnecessary_to_owned.rs:72:20 | LL | require_os_str(&os_str.to_owned()); | ^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_path_buf` - --> tests/ui/unnecessary_to_owned.rs:78:18 + --> tests/ui/unnecessary_to_owned.rs:75:18 | LL | require_path(&path.to_path_buf()); | ^^^^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:80:34 + --> tests/ui/unnecessary_to_owned.rs:77:34 | LL | require_path(&Cow::from(path).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:82:18 + --> tests/ui/unnecessary_to_owned.rs:79:18 | LL | require_path(&path.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:85:17 + --> tests/ui/unnecessary_to_owned.rs:82:17 | LL | require_str(&s.to_string()); | ^^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:87:30 + --> tests/ui/unnecessary_to_owned.rs:84:30 | LL | require_str(&Cow::from(s).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:89:17 + --> tests/ui/unnecessary_to_owned.rs:86:17 | LL | require_str(&s.to_owned()); | ^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:91:17 + --> tests/ui/unnecessary_to_owned.rs:88:17 | LL | require_str(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref.as_ref()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:94:19 + --> tests/ui/unnecessary_to_owned.rs:91:19 | LL | require_slice(&slice.to_vec()); | ^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:96:36 + --> tests/ui/unnecessary_to_owned.rs:93:36 | LL | require_slice(&Cow::from(slice).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:98:19 + --> tests/ui/unnecessary_to_owned.rs:95:19 | LL | require_slice(&array.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `array.as_ref()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:100:19 + --> tests/ui/unnecessary_to_owned.rs:97:19 | LL | require_slice(&array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref.as_ref()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:102:19 + --> tests/ui/unnecessary_to_owned.rs:99:19 | LL | require_slice(&slice.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> tests/ui/unnecessary_to_owned.rs:106:42 + --> tests/ui/unnecessary_to_owned.rs:103:42 | LL | require_x(&Cow::::Owned(x.clone()).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:110:25 + --> tests/ui/unnecessary_to_owned.rs:107:25 | LL | require_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:112:26 + --> tests/ui/unnecessary_to_owned.rs:109:26 | LL | require_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:114:24 + --> tests/ui/unnecessary_to_owned.rs:111:24 | LL | require_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:116:23 + --> tests/ui/unnecessary_to_owned.rs:113:23 | LL | require_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:118:25 + --> tests/ui/unnecessary_to_owned.rs:115:25 | LL | require_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:121:30 + --> tests/ui/unnecessary_to_owned.rs:118:30 | LL | require_impl_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:123:31 + --> tests/ui/unnecessary_to_owned.rs:120:31 | LL | require_impl_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:125:29 + --> tests/ui/unnecessary_to_owned.rs:122:29 | LL | require_impl_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:127:28 + --> tests/ui/unnecessary_to_owned.rs:124:28 | LL | require_impl_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:129:30 + --> tests/ui/unnecessary_to_owned.rs:126:30 | LL | require_impl_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:132:29 + --> tests/ui/unnecessary_to_owned.rs:129:29 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:132:43 + --> tests/ui/unnecessary_to_owned.rs:129:43 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:135:29 + --> tests/ui/unnecessary_to_owned.rs:132:29 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:135:47 + --> tests/ui/unnecessary_to_owned.rs:132:47 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:139:26 + --> tests/ui/unnecessary_to_owned.rs:136:26 | LL | require_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:141:27 + --> tests/ui/unnecessary_to_owned.rs:138:27 | LL | require_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:143:25 + --> tests/ui/unnecessary_to_owned.rs:140:25 | LL | require_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:145:24 + --> tests/ui/unnecessary_to_owned.rs:142:24 | LL | require_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:147:24 + --> tests/ui/unnecessary_to_owned.rs:144:24 | LL | require_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:149:26 + --> tests/ui/unnecessary_to_owned.rs:146:26 | LL | require_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:151:26 + --> tests/ui/unnecessary_to_owned.rs:148:26 | LL | require_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:153:26 + --> tests/ui/unnecessary_to_owned.rs:150:26 | LL | require_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:156:31 + --> tests/ui/unnecessary_to_owned.rs:153:31 | LL | require_impl_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:158:32 + --> tests/ui/unnecessary_to_owned.rs:155:32 | LL | require_impl_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:160:30 + --> tests/ui/unnecessary_to_owned.rs:157:30 | LL | require_impl_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:162:29 + --> tests/ui/unnecessary_to_owned.rs:159:29 | LL | require_impl_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:164:29 + --> tests/ui/unnecessary_to_owned.rs:161:29 | LL | require_impl_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:166:31 + --> tests/ui/unnecessary_to_owned.rs:163:31 | LL | require_impl_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:168:31 + --> tests/ui/unnecessary_to_owned.rs:165:31 | LL | require_impl_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:170:31 + --> tests/ui/unnecessary_to_owned.rs:167:31 | LL | require_impl_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:173:30 + --> tests/ui/unnecessary_to_owned.rs:170:30 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:173:44 + --> tests/ui/unnecessary_to_owned.rs:170:44 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:176:30 + --> tests/ui/unnecessary_to_owned.rs:173:30 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:176:44 + --> tests/ui/unnecessary_to_owned.rs:173:44 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:179:30 + --> tests/ui/unnecessary_to_owned.rs:176:30 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:179:44 + --> tests/ui/unnecessary_to_owned.rs:176:44 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:182:30 + --> tests/ui/unnecessary_to_owned.rs:179:30 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:182:48 + --> tests/ui/unnecessary_to_owned.rs:179:48 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:185:30 + --> tests/ui/unnecessary_to_owned.rs:182:30 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:185:52 + --> tests/ui/unnecessary_to_owned.rs:182:52 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:188:30 + --> tests/ui/unnecessary_to_owned.rs:185:30 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:188:48 + --> tests/ui/unnecessary_to_owned.rs:185:48 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:192:20 + --> tests/ui/unnecessary_to_owned.rs:189:20 | LL | let _ = x.join(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:195:13 + --> tests/ui/unnecessary_to_owned.rs:192:13 | LL | let _ = slice.to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:197:13 + --> tests/ui/unnecessary_to_owned.rs:194:13 | LL | let _ = slice.to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:200:13 + --> tests/ui/unnecessary_to_owned.rs:197:13 | LL | let _ = IntoIterator::into_iter(slice.to_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:202:13 + --> tests/ui/unnecessary_to_owned.rs:199:13 | LL | let _ = IntoIterator::into_iter(slice.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: allocating a new `String` only to create a temporary `&str` from it - --> tests/ui/unnecessary_to_owned.rs:230:26 + --> tests/ui/unnecessary_to_owned.rs:227:26 | LL | let _ref_str: &str = &String::from_utf8(slice.to_vec()).expect("not UTF-8"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -466,7 +466,7 @@ LL + let _ref_str: &str = core::str::from_utf8(&slice).expect("not UTF-8"); | error: allocating a new `String` only to create a temporary `&str` from it - --> tests/ui/unnecessary_to_owned.rs:232:26 + --> tests/ui/unnecessary_to_owned.rs:229:26 | LL | let _ref_str: &str = &String::from_utf8(b"foo".to_vec()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -478,7 +478,7 @@ LL + let _ref_str: &str = core::str::from_utf8(b"foo").unwrap(); | error: allocating a new `String` only to create a temporary `&str` from it - --> tests/ui/unnecessary_to_owned.rs:234:26 + --> tests/ui/unnecessary_to_owned.rs:231:26 | LL | let _ref_str: &str = &String::from_utf8(b"foo".as_slice().to_owned()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -490,7 +490,7 @@ LL + let _ref_str: &str = core::str::from_utf8(b"foo".as_slice()).unwrap(); | error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:292:14 + --> tests/ui/unnecessary_to_owned.rs:289:14 | LL | for t in file_types.to_vec() { | ^^^^^^^^^^^^^^^^^^^ @@ -503,55 +503,55 @@ LL ~ let path = match get_file_path(t) { | error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:358:24 + --> tests/ui/unnecessary_to_owned.rs:354:24 | LL | Box::new(build(y.to_string())) | ^^^^^^^^^^^^^ help: use: `y` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:468:12 + --> tests/ui/unnecessary_to_owned.rs:460:12 | LL | id("abc".to_string()) | ^^^^^^^^^^^^^^^^^ help: use: `"abc"` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:612:37 + --> tests/ui/unnecessary_to_owned.rs:599:37 | LL | IntoFuture::into_future(foo([].to_vec(), &0)); | ^^^^^^^^^^^ help: use: `[]` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:623:18 + --> tests/ui/unnecessary_to_owned.rs:610:18 | LL | s.remove(&a.to_vec()); | ^^^^^^^^^^^ help: replace it with: `a` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned.rs:628:14 + --> tests/ui/unnecessary_to_owned.rs:615:14 | LL | s.remove(&"b".to_owned()); | ^^^^^^^^^^^^^^^ help: replace it with: `"b"` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:630:14 + --> tests/ui/unnecessary_to_owned.rs:617:14 | LL | s.remove(&"b".to_string()); | ^^^^^^^^^^^^^^^^ help: replace it with: `"b"` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:636:14 + --> tests/ui/unnecessary_to_owned.rs:623:14 | LL | s.remove(&["b"].to_vec()); | ^^^^^^^^^^^^^^^ help: replace it with: `["b"].as_slice()` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned.rs:638:14 + --> tests/ui/unnecessary_to_owned.rs:625:14 | LL | s.remove(&(&["b"]).to_vec()); | ^^^^^^^^^^^^^^^^^^ help: replace it with: `(&["b"]).as_slice()` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned.rs:690:10 + --> tests/ui/unnecessary_to_owned.rs:677:10 | LL | take(format!("ouch{dot}").to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `&format!("ouch{dot}")` diff --git a/tests/ui/unnecessary_to_owned_on_split.fixed b/tests/ui/unnecessary_to_owned_on_split.fixed index f43d92a2d9bab..7ee1f539c2048 100644 --- a/tests/ui/unnecessary_to_owned_on_split.fixed +++ b/tests/ui/unnecessary_to_owned_on_split.fixed @@ -1,4 +1,5 @@ -#![allow(clippy::single_char_pattern)] +#![warn(clippy::unnecessary_to_owned)] +#![expect(clippy::single_char_pattern)] struct Issue12068; diff --git a/tests/ui/unnecessary_to_owned_on_split.rs b/tests/ui/unnecessary_to_owned_on_split.rs index bdf5f98bf61e3..a716ac965175c 100644 --- a/tests/ui/unnecessary_to_owned_on_split.rs +++ b/tests/ui/unnecessary_to_owned_on_split.rs @@ -1,4 +1,5 @@ -#![allow(clippy::single_char_pattern)] +#![warn(clippy::unnecessary_to_owned)] +#![expect(clippy::single_char_pattern)] struct Issue12068; diff --git a/tests/ui/unnecessary_to_owned_on_split.stderr b/tests/ui/unnecessary_to_owned_on_split.stderr index 5e4fbb1035d69..a9e913de89b1e 100644 --- a/tests/ui/unnecessary_to_owned_on_split.stderr +++ b/tests/ui/unnecessary_to_owned_on_split.stderr @@ -1,5 +1,5 @@ error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned_on_split.rs:19:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:20:13 | LL | let _ = "a".to_string().split('a').next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split('a')` @@ -8,49 +8,49 @@ LL | let _ = "a".to_string().split('a').next().unwrap(); = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned_on_split.rs:22:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:23:13 | LL | let _ = "a".to_string().split("a").next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split("a")` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:25:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:26:13 | LL | let _ = "a".to_owned().split('a').next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split('a')` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:28:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:29:13 | LL | let _ = "a".to_owned().split("a").next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `"a".split("a")` error: unnecessary use of `to_string` - --> tests/ui/unnecessary_to_owned_on_split.rs:31:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:32:13 | LL | let _ = Issue12068.to_string().split('a').next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `Issue12068.as_ref().split('a')` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned_on_split.rs:34:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:35:13 | LL | let _ = [1].to_vec().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` error: unnecessary use of `to_vec` - --> tests/ui/unnecessary_to_owned_on_split.rs:37:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:38:13 | LL | let _ = [1].to_vec().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:40:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:41:13 | LL | let _ = [1].to_owned().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` error: unnecessary use of `to_owned` - --> tests/ui/unnecessary_to_owned_on_split.rs:43:13 + --> tests/ui/unnecessary_to_owned_on_split.rs:44:13 | LL | let _ = [1].to_owned().split(|x| *x == 2).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[1].split(|x| *x == 2)` diff --git a/tests/ui/unnecessary_unsafety_doc.rs b/tests/ui/unnecessary_unsafety_doc.rs index 7a847d2e3b501..1fcad44e83804 100644 --- a/tests/ui/unnecessary_unsafety_doc.rs +++ b/tests/ui/unnecessary_unsafety_doc.rs @@ -1,6 +1,5 @@ //@aux-build:proc_macros.rs -#![allow(clippy::let_unit_value, clippy::needless_pass_by_ref_mut)] #![warn(clippy::unnecessary_safety_doc)] extern crate proc_macros; diff --git a/tests/ui/unnecessary_unsafety_doc.stderr b/tests/ui/unnecessary_unsafety_doc.stderr index dd9d8b65f75e8..cb2fb3119e86e 100644 --- a/tests/ui/unnecessary_unsafety_doc.stderr +++ b/tests/ui/unnecessary_unsafety_doc.stderr @@ -1,5 +1,5 @@ error: safe function's docs have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:19:1 + --> tests/ui/unnecessary_unsafety_doc.rs:18:1 | LL | pub fn apocalypse(universe: &mut ()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,31 +8,31 @@ LL | pub fn apocalypse(universe: &mut ()) { = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_doc)]` error: safe function's docs have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:46:5 + --> tests/ui/unnecessary_unsafety_doc.rs:45:5 | LL | pub fn republished() { | ^^^^^^^^^^^^^^^^^^^^ error: safe function's docs have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:60:5 + --> tests/ui/unnecessary_unsafety_doc.rs:59:5 | LL | fn documented(self); | ^^^^^^^^^^^^^^^^^^^^ error: docs for safe trait have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:71:1 + --> tests/ui/unnecessary_unsafety_doc.rs:70:1 | LL | pub trait DocumentedSafeTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: safe function's docs have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:100:5 + --> tests/ui/unnecessary_unsafety_doc.rs:99:5 | LL | pub fn documented() -> Self { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: safe function's docs have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:128:9 + --> tests/ui/unnecessary_unsafety_doc.rs:127:9 | LL | pub fn drive() { | ^^^^^^^^^^^^^^ @@ -43,7 +43,7 @@ LL | very_safe!(); = note: this error originates in the macro `very_safe` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for safe trait have unnecessary `# Safety` section - --> tests/ui/unnecessary_unsafety_doc.rs:157:1 + --> tests/ui/unnecessary_unsafety_doc.rs:156:1 | LL | pub trait DocumentedSafeTraitWithImplementationHeader { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs index 4770ef3b48300..5803eff6a4ff9 100644 --- a/tests/ui/unnecessary_wraps.rs +++ b/tests/ui/unnecessary_wraps.rs @@ -1,9 +1,7 @@ //@no-rustfix: overlapping suggestions #![warn(clippy::unnecessary_wraps)] -#![allow(clippy::no_effect)] +#![expect(clippy::if_same_then_else, clippy::no_effect)] #![allow(clippy::needless_return)] -#![allow(clippy::if_same_then_else)] -#![allow(dead_code)] // should be linted fn func1(a: bool, b: bool) -> Option { diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index 13d71271e211c..1fd421c201c96 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -1,5 +1,5 @@ error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:9:1 + --> tests/ui/unnecessary_wraps.rs:7:1 | LL | fn func1(a: bool, b: bool) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL ~ return 1337; | error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:24:1 + --> tests/ui/unnecessary_wraps.rs:22:1 | LL | fn func2(a: bool, b: bool) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL ~ if a { 20 } else { 30 } | error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:44:1 + --> tests/ui/unnecessary_wraps.rs:42:1 | LL | fn func5() -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -58,7 +58,7 @@ LL + 1 | error: this function's return value is unnecessarily wrapped by `Result` - --> tests/ui/unnecessary_wraps.rs:56:1 + --> tests/ui/unnecessary_wraps.rs:54:1 | LL | fn func7() -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL + 1 | error: this function's return value is unnecessarily wrapped by `Option` - --> tests/ui/unnecessary_wraps.rs:86:5 + --> tests/ui/unnecessary_wraps.rs:84:5 | LL | fn func12() -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL + 1 | error: this function's return value is unnecessary - --> tests/ui/unnecessary_wraps.rs:115:1 + --> tests/ui/unnecessary_wraps.rs:113:1 | LL | fn issue_6640_1(a: bool, b: bool) -> Option<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -114,7 +114,7 @@ LL ~ return ; | error: this function's return value is unnecessary - --> tests/ui/unnecessary_wraps.rs:130:1 + --> tests/ui/unnecessary_wraps.rs:128:1 | LL | fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unneeded_field_pattern.rs b/tests/ui/unneeded_field_pattern.rs index 327b64e7c4aab..b048789cf1aaf 100644 --- a/tests/ui/unneeded_field_pattern.rs +++ b/tests/ui/unneeded_field_pattern.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs #![warn(clippy::unneeded_field_pattern)] -#![allow(dead_code, unused, clippy::single_match)] +#![expect(clippy::single_match)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/unneeded_struct_pattern.fixed b/tests/ui/unneeded_struct_pattern.fixed index 665ab98913be3..a51f6ad34fec0 100644 --- a/tests/ui/unneeded_struct_pattern.fixed +++ b/tests/ui/unneeded_struct_pattern.fixed @@ -1,10 +1,7 @@ //@aux-build:non-exhaustive-enum.rs -#![allow( - clippy::manual_unwrap_or_default, - clippy::manual_unwrap_or, - clippy::redundant_pattern_matching -)] #![warn(clippy::unneeded_struct_pattern)] +#![allow(clippy::redundant_pattern_matching)] +#![expect(clippy::manual_unwrap_or_default)] extern crate non_exhaustive_enum; use non_exhaustive_enum::*; diff --git a/tests/ui/unneeded_struct_pattern.rs b/tests/ui/unneeded_struct_pattern.rs index 7cadb6c7fbb54..4039f72c5316a 100644 --- a/tests/ui/unneeded_struct_pattern.rs +++ b/tests/ui/unneeded_struct_pattern.rs @@ -1,10 +1,7 @@ //@aux-build:non-exhaustive-enum.rs -#![allow( - clippy::manual_unwrap_or_default, - clippy::manual_unwrap_or, - clippy::redundant_pattern_matching -)] #![warn(clippy::unneeded_struct_pattern)] +#![allow(clippy::redundant_pattern_matching)] +#![expect(clippy::manual_unwrap_or_default)] extern crate non_exhaustive_enum; use non_exhaustive_enum::*; diff --git a/tests/ui/unneeded_struct_pattern.stderr b/tests/ui/unneeded_struct_pattern.stderr index 7c0c3c9e4462e..2e66fb40881ca 100644 --- a/tests/ui/unneeded_struct_pattern.stderr +++ b/tests/ui/unneeded_struct_pattern.stderr @@ -1,5 +1,5 @@ error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:17:13 + --> tests/ui/unneeded_struct_pattern.rs:14:13 | LL | None {} => 0, | ^^^ help: remove the struct pattern @@ -8,193 +8,193 @@ LL | None {} => 0, = help: to override `-D warnings` add `#[allow(clippy::unneeded_struct_pattern)]` error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:23:13 + --> tests/ui/unneeded_struct_pattern.rs:20:13 | LL | None { .. } => 0, | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:34:18 + --> tests/ui/unneeded_struct_pattern.rs:31:18 | LL | Some(None {}) => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:36:13 + --> tests/ui/unneeded_struct_pattern.rs:33:13 | LL | None {} => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:40:16 + --> tests/ui/unneeded_struct_pattern.rs:37:16 | LL | if let None {} = Some(0) {} | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:42:16 + --> tests/ui/unneeded_struct_pattern.rs:39:16 | LL | if let None { .. } = Some(0) {} | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:44:21 + --> tests/ui/unneeded_struct_pattern.rs:41:21 | LL | if let Some(None {}) = Some(Some(0)) {} | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:46:13 + --> tests/ui/unneeded_struct_pattern.rs:43:13 | LL | let None {} = Some(0) else { panic!() }; | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:48:13 + --> tests/ui/unneeded_struct_pattern.rs:45:13 | LL | let None { .. } = Some(0) else { panic!() }; | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:50:18 + --> tests/ui/unneeded_struct_pattern.rs:47:18 | LL | let Some(None {}) = Some(Some(0)) else { panic!() }; | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:67:27 + --> tests/ui/unneeded_struct_pattern.rs:64:27 | LL | Custom::NoBrackets {} => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:68:40 + --> tests/ui/unneeded_struct_pattern.rs:65:40 | LL | Custom::NoBracketsNonExhaustive {} => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:75:27 + --> tests/ui/unneeded_struct_pattern.rs:72:27 | LL | Custom::NoBrackets { .. } => 0, | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:76:40 + --> tests/ui/unneeded_struct_pattern.rs:73:40 | LL | Custom::NoBracketsNonExhaustive { .. } => 0, | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:81:27 + --> tests/ui/unneeded_struct_pattern.rs:78:27 | LL | Custom::NoBrackets {} if true => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:86:27 + --> tests/ui/unneeded_struct_pattern.rs:83:27 | LL | Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:86:64 + --> tests/ui/unneeded_struct_pattern.rs:83:64 | LL | Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} => 0, | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:101:30 + --> tests/ui/unneeded_struct_pattern.rs:98:30 | LL | if let Custom::NoBrackets {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:105:30 + --> tests/ui/unneeded_struct_pattern.rs:102:30 | LL | if let Custom::NoBrackets { .. } = Custom::Init { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:109:30 + --> tests/ui/unneeded_struct_pattern.rs:106:30 | LL | if let Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:109:67 + --> tests/ui/unneeded_struct_pattern.rs:106:67 | LL | if let Custom::NoBrackets {} | Custom::NoBracketsNonExhaustive {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:114:43 + --> tests/ui/unneeded_struct_pattern.rs:111:43 | LL | if let Custom::NoBracketsNonExhaustive {} = Custom::Init { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:118:43 + --> tests/ui/unneeded_struct_pattern.rs:115:43 | LL | if let Custom::NoBracketsNonExhaustive { .. } = Custom::Init { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:134:27 + --> tests/ui/unneeded_struct_pattern.rs:131:27 | LL | let Custom::NoBrackets {} = Custom::Init else { panic!() }; | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:136:27 + --> tests/ui/unneeded_struct_pattern.rs:133:27 | LL | let Custom::NoBrackets { .. } = Custom::Init else { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:140:40 + --> tests/ui/unneeded_struct_pattern.rs:137:40 | LL | let Custom::NoBracketsNonExhaustive {} = Custom::Init else { | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:144:40 + --> tests/ui/unneeded_struct_pattern.rs:141:40 | LL | let Custom::NoBracketsNonExhaustive { .. } = Custom::Init else { | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:153:44 + --> tests/ui/unneeded_struct_pattern.rs:150:44 | LL | fn pat_in_fn_param_1(Refutable::Variant {}: Refutable) {} | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:154:44 + --> tests/ui/unneeded_struct_pattern.rs:151:44 | LL | fn pat_in_fn_param_2(Refutable::Variant { .. }: Refutable) {} | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:156:27 + --> tests/ui/unneeded_struct_pattern.rs:153:27 | LL | for Refutable::Variant {} in [] {} | ^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:157:27 + --> tests/ui/unneeded_struct_pattern.rs:154:27 | LL | for Refutable::Variant { .. } in [] {} | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:171:23 + --> tests/ui/unneeded_struct_pattern.rs:168:23 | LL | ExhaustiveUnit { .. } => 0, | ^^^^^^^ help: remove the struct pattern error: struct pattern is not needed for a unit variant - --> tests/ui/unneeded_struct_pattern.rs:177:23 + --> tests/ui/unneeded_struct_pattern.rs:174:23 | LL | ExhaustiveUnit {} => 0, | ^^^ help: remove the struct pattern diff --git a/tests/ui/unneeded_wildcard_pattern.fixed b/tests/ui/unneeded_wildcard_pattern.fixed index ff99e436c661f..1c987d0a9aec4 100644 --- a/tests/ui/unneeded_wildcard_pattern.fixed +++ b/tests/ui/unneeded_wildcard_pattern.fixed @@ -1,7 +1,6 @@ //@aux-build:proc_macros.rs #![feature(stmt_expr_attributes)] -#![deny(clippy::unneeded_wildcard_pattern)] -#![allow(clippy::needless_ifs)] +#![warn(clippy::unneeded_wildcard_pattern)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/unneeded_wildcard_pattern.rs b/tests/ui/unneeded_wildcard_pattern.rs index 5913735d3b4ba..30c11c2f5e7e5 100644 --- a/tests/ui/unneeded_wildcard_pattern.rs +++ b/tests/ui/unneeded_wildcard_pattern.rs @@ -1,7 +1,6 @@ //@aux-build:proc_macros.rs #![feature(stmt_expr_attributes)] -#![deny(clippy::unneeded_wildcard_pattern)] -#![allow(clippy::needless_ifs)] +#![warn(clippy::unneeded_wildcard_pattern)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/unneeded_wildcard_pattern.stderr b/tests/ui/unneeded_wildcard_pattern.stderr index bfdceb53f7d4a..6559aa42b36fc 100644 --- a/tests/ui/unneeded_wildcard_pattern.stderr +++ b/tests/ui/unneeded_wildcard_pattern.stderr @@ -1,113 +1,110 @@ error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:12:18 + --> tests/ui/unneeded_wildcard_pattern.rs:11:18 | LL | if let (0, .., _) = t {}; | ^^^ help: remove it | -note: the lint level is defined here - --> tests/ui/unneeded_wildcard_pattern.rs:3:9 - | -LL | #![deny(clippy::unneeded_wildcard_pattern)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::unneeded-wildcard-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unneeded_wildcard_pattern)]` error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:14:16 + --> tests/ui/unneeded_wildcard_pattern.rs:13:16 | LL | if let (0, _, ..) = t {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:16:13 + --> tests/ui/unneeded_wildcard_pattern.rs:15:13 | LL | if let (_, .., 0) = t {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:18:15 + --> tests/ui/unneeded_wildcard_pattern.rs:17:15 | LL | if let (.., _, 0) = t {}; | ^^^ help: remove it error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:20:16 + --> tests/ui/unneeded_wildcard_pattern.rs:19:16 | LL | if let (0, _, _, ..) = t {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:22:18 + --> tests/ui/unneeded_wildcard_pattern.rs:21:18 | LL | if let (0, .., _, _) = t {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:32:22 + --> tests/ui/unneeded_wildcard_pattern.rs:31:22 | LL | if let (0, .., _, _,) = t {}; | ^^^^^^ help: remove them error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:40:19 + --> tests/ui/unneeded_wildcard_pattern.rs:39:19 | LL | if let S(0, .., _) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:42:17 + --> tests/ui/unneeded_wildcard_pattern.rs:41:17 | LL | if let S(0, _, ..) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:44:14 + --> tests/ui/unneeded_wildcard_pattern.rs:43:14 | LL | if let S(_, .., 0) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:46:16 + --> tests/ui/unneeded_wildcard_pattern.rs:45:16 | LL | if let S(.., _, 0) = s {}; | ^^^ help: remove it error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:48:17 + --> tests/ui/unneeded_wildcard_pattern.rs:47:17 | LL | if let S(0, _, _, ..) = s {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:50:19 + --> tests/ui/unneeded_wildcard_pattern.rs:49:19 | LL | if let S(0, .., _, _) = s {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:60:23 + --> tests/ui/unneeded_wildcard_pattern.rs:59:23 | LL | if let S(0, .., _, _,) = s {}; | ^^^^^^ help: remove them error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:83:33 + --> tests/ui/unneeded_wildcard_pattern.rs:82:33 | LL | let Struct4 { mut a, mut b, c: _, .. } = fourval; | ^^^^^^ help: remove it error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:85:26 + --> tests/ui/unneeded_wildcard_pattern.rs:84:26 | LL | let Struct4 { mut b, c: _, d: _, .. } = fourval; | ^^^^^^^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> tests/ui/unneeded_wildcard_pattern.rs:89:19 + --> tests/ui/unneeded_wildcard_pattern.rs:88:19 | LL | let Struct4 { b: _, c: _, .. } = fourval; | ^^^^^^^^^^^^ help: remove them error: this pattern is unneeded as the `..` pattern can match that element - --> tests/ui/unneeded_wildcard_pattern.rs:91:19 + --> tests/ui/unneeded_wildcard_pattern.rs:90:19 | LL | let Struct4 { c: _, .. } = fourval; | ^^^^^^ help: remove it diff --git a/tests/ui/unnested_or_patterns.fixed b/tests/ui/unnested_or_patterns.fixed index 0391fb19b1f6f..f96088bd39a6d 100644 --- a/tests/ui/unnested_or_patterns.fixed +++ b/tests/ui/unnested_or_patterns.fixed @@ -1,13 +1,7 @@ #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] -#![allow( - clippy::cognitive_complexity, - clippy::match_ref_pats, - clippy::upper_case_acronyms, - clippy::needless_ifs, - clippy::manual_range_patterns -)] -#![allow(unreachable_patterns, irrefutable_let_patterns, unused)] +#![allow(clippy::manual_range_patterns)] +#![expect(irrefutable_let_patterns)] struct S { x: u8, diff --git a/tests/ui/unnested_or_patterns.rs b/tests/ui/unnested_or_patterns.rs index f0702668fa917..6f4ef615e9d16 100644 --- a/tests/ui/unnested_or_patterns.rs +++ b/tests/ui/unnested_or_patterns.rs @@ -1,13 +1,7 @@ #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] -#![allow( - clippy::cognitive_complexity, - clippy::match_ref_pats, - clippy::upper_case_acronyms, - clippy::needless_ifs, - clippy::manual_range_patterns -)] -#![allow(unreachable_patterns, irrefutable_let_patterns, unused)] +#![allow(clippy::manual_range_patterns)] +#![expect(irrefutable_let_patterns)] struct S { x: u8, diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr index d2b617c322c46..7298eabaa03e6 100644 --- a/tests/ui/unnested_or_patterns.stderr +++ b/tests/ui/unnested_or_patterns.stderr @@ -1,5 +1,5 @@ error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:21:12 + --> tests/ui/unnested_or_patterns.rs:15:12 | LL | if let box 0 | box 2 = Box::new(0) {} | ^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + if let box (0 | 2) = Box::new(0) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:23:12 + --> tests/ui/unnested_or_patterns.rs:17:12 | LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:26:12 + --> tests/ui/unnested_or_patterns.rs:20:12 | LL | if let Some(1) | C0 | Some(2) = None {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + if let Some(1 | 2) | C0 = None {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:28:12 + --> tests/ui/unnested_or_patterns.rs:22:12 | LL | if let &mut 0 | &mut 2 = &mut 0 {} | ^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + if let &mut (0 | 2) = &mut 0 {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:30:12 + --> tests/ui/unnested_or_patterns.rs:24:12 | LL | if let x @ 0 | x @ 2 = 0 {} | ^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + if let x @ (0 | 2) = 0 {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:32:12 + --> tests/ui/unnested_or_patterns.rs:26:12 | LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + if let (0, 1 | 2 | 3) = (0, 0) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:34:12 + --> tests/ui/unnested_or_patterns.rs:28:12 | LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + if let (1 | 2 | 3, 0) = (0, 0) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:36:12 + --> tests/ui/unnested_or_patterns.rs:30:12 | LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + if let (x, ..) | (x, 1 | 2) = (0, 1) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:38:12 + --> tests/ui/unnested_or_patterns.rs:32:12 | LL | if let [0] | [1] = [0] {} | ^^^^^^^^^ @@ -109,7 +109,7 @@ LL + if let [0 | 1] = [0] {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:40:12 + --> tests/ui/unnested_or_patterns.rs:34:12 | LL | if let [x, 0] | [x, 1] = [0, 1] {} | ^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + if let [x, 0 | 1] = [0, 1] {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:42:12 + --> tests/ui/unnested_or_patterns.rs:36:12 | LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + if let [x, 0 | 1 | 2] = [0, 1] {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:44:12 + --> tests/ui/unnested_or_patterns.rs:38:12 | LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + if let [x, ..] | [x, 1 | 2] = [0, 1] {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:47:12 + --> tests/ui/unnested_or_patterns.rs:41:12 | LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + if let TS(0 | 1, x) = TS(0, 0) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:49:12 + --> tests/ui/unnested_or_patterns.rs:43:12 | LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + if let TS(1 | 2 | 3, 0) = TS(0, 0) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:51:12 + --> tests/ui/unnested_or_patterns.rs:45:12 | LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:53:12 + --> tests/ui/unnested_or_patterns.rs:47:12 | LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:65:12 + --> tests/ui/unnested_or_patterns.rs:59:12 | LL | if let [1] | [53] = [0] {} | ^^^^^^^^^^ @@ -205,7 +205,7 @@ LL + if let [1 | 53] = [0] {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:71:13 + --> tests/ui/unnested_or_patterns.rs:65:13 | LL | let (0 | (1 | _)) = 0; | ^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL + let (0 | 1 | _) = 0; | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:74:16 + --> tests/ui/unnested_or_patterns.rs:68:16 | LL | if let (0 | (1 | _)) = 0 {} | ^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL + if let (0 | 1 | _) = 0 {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:78:20 + --> tests/ui/unnested_or_patterns.rs:72:20 | LL | fn or_in_param((x | (x | x)): i32) {} | ^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL + fn or_in_param((x | x | x): i32) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns.rs:94:12 + --> tests/ui/unnested_or_patterns.rs:88:12 | LL | if let S { y, x: 0 } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnested_or_patterns2.fixed b/tests/ui/unnested_or_patterns2.fixed index 852c4ddcfd712..d9625e78c246d 100644 --- a/tests/ui/unnested_or_patterns2.fixed +++ b/tests/ui/unnested_or_patterns2.fixed @@ -1,12 +1,6 @@ #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] -#![allow( - clippy::cognitive_complexity, - clippy::match_ref_pats, - clippy::needless_ifs, - clippy::manual_range_patterns -)] -#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)] +#![allow(clippy::manual_range_patterns)] fn main() { if let Some(Some(0 | 1)) = None {} diff --git a/tests/ui/unnested_or_patterns2.rs b/tests/ui/unnested_or_patterns2.rs index 12f3d3fca464e..d5215966fcb13 100644 --- a/tests/ui/unnested_or_patterns2.rs +++ b/tests/ui/unnested_or_patterns2.rs @@ -1,12 +1,6 @@ #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] -#![allow( - clippy::cognitive_complexity, - clippy::match_ref_pats, - clippy::needless_ifs, - clippy::manual_range_patterns -)] -#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)] +#![allow(clippy::manual_range_patterns)] fn main() { if let Some(Some(0)) | Some(Some(1)) = None {} diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr index 3deef33cf258e..776589e294ba5 100644 --- a/tests/ui/unnested_or_patterns2.stderr +++ b/tests/ui/unnested_or_patterns2.stderr @@ -1,5 +1,5 @@ error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:12:12 + --> tests/ui/unnested_or_patterns2.rs:6:12 | LL | if let Some(Some(0)) | Some(Some(1)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + if let Some(Some(0 | 1)) = None {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:14:12 + --> tests/ui/unnested_or_patterns2.rs:8:12 | LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + if let Some(Some(0 | 1 | 2)) = None {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:16:12 + --> tests/ui/unnested_or_patterns2.rs:10:12 | LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:18:12 + --> tests/ui/unnested_or_patterns2.rs:12:12 | LL | if let Some(Some(0) | Some(1 | 2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + if let Some(Some(0 | 1 | 2)) = None {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:20:12 + --> tests/ui/unnested_or_patterns2.rs:14:12 | LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + if let ((0 | 1 | 2,),) = ((0,),) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:22:12 + --> tests/ui/unnested_or_patterns2.rs:16:12 | LL | if let 0 | (1 | 2) = 0 {} | ^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + if let 0 | 1 | 2 = 0 {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:24:12 + --> tests/ui/unnested_or_patterns2.rs:18:12 | LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | error: unnested or-patterns - --> tests/ui/unnested_or_patterns2.rs:26:12 + --> tests/ui/unnested_or_patterns2.rs:20:12 | LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unsafe_derive_deserialize.rs b/tests/ui/unsafe_derive_deserialize.rs index d0022f3b6d93d..2d3cddc2d6e13 100644 --- a/tests/ui/unsafe_derive_deserialize.rs +++ b/tests/ui/unsafe_derive_deserialize.rs @@ -1,5 +1,5 @@ #![warn(clippy::unsafe_derive_deserialize)] -#![allow(unused, clippy::missing_safety_doc)] +#![expect(clippy::missing_safety_doc)] extern crate serde; diff --git a/tests/ui/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs index f3d318815c101..fe2b495611cc3 100644 --- a/tests/ui/unsafe_removed_from_name.rs +++ b/tests/ui/unsafe_removed_from_name.rs @@ -1,5 +1,3 @@ -#![allow(unused_imports)] -#![allow(dead_code)] #![warn(clippy::unsafe_removed_from_name)] use std::cell::UnsafeCell as TotallySafeCell; diff --git a/tests/ui/unsafe_removed_from_name.stderr b/tests/ui/unsafe_removed_from_name.stderr index cd3c1f80a3002..0010ce5d6e5b9 100644 --- a/tests/ui/unsafe_removed_from_name.stderr +++ b/tests/ui/unsafe_removed_from_name.stderr @@ -1,5 +1,5 @@ error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCell` - --> tests/ui/unsafe_removed_from_name.rs:5:1 + --> tests/ui/unsafe_removed_from_name.rs:3:1 | LL | use std::cell::UnsafeCell as TotallySafeCell; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,31 +8,31 @@ LL | use std::cell::UnsafeCell as TotallySafeCell; = help: to override `-D warnings` add `#[allow(clippy::unsafe_removed_from_name)]` error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` - --> tests/ui/unsafe_removed_from_name.rs:8:1 + --> tests/ui/unsafe_removed_from_name.rs:6:1 | LL | use std::cell::UnsafeCell as TotallySafeCellAgain; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` - --> tests/ui/unsafe_removed_from_name.rs:28:1 + --> tests/ui/unsafe_removed_from_name.rs:26:1 | LL | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `A` - --> tests/ui/unsafe_removed_from_name.rs:32:1 + --> tests/ui/unsafe_removed_from_name.rs:30:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `B` - --> tests/ui/unsafe_removed_from_name.rs:32:1 + --> tests/ui/unsafe_removed_from_name.rs:30:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `UnsafeTrait` in use as `FakeSafeTrait` - --> tests/ui/unsafe_removed_from_name.rs:47:1 + --> tests/ui/unsafe_removed_from_name.rs:45:1 | LL | use mod_with_some_unsafe_things::UnsafeTrait as FakeSafeTrait; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unseparated_prefix_literals.fixed b/tests/ui/unseparated_prefix_literals.fixed index e13dd561d627a..e90a7319263db 100644 --- a/tests/ui/unseparated_prefix_literals.fixed +++ b/tests/ui/unseparated_prefix_literals.fixed @@ -1,7 +1,6 @@ //@aux-build:proc_macro_derive.rs #![warn(clippy::unseparated_literal_suffix)] -#![allow(dead_code)] #[macro_use] extern crate proc_macro_derive; diff --git a/tests/ui/unseparated_prefix_literals.rs b/tests/ui/unseparated_prefix_literals.rs index 6f7b16ccba54c..8988ae7b879af 100644 --- a/tests/ui/unseparated_prefix_literals.rs +++ b/tests/ui/unseparated_prefix_literals.rs @@ -1,7 +1,6 @@ //@aux-build:proc_macro_derive.rs #![warn(clippy::unseparated_literal_suffix)] -#![allow(dead_code)] #[macro_use] extern crate proc_macro_derive; diff --git a/tests/ui/unseparated_prefix_literals.stderr b/tests/ui/unseparated_prefix_literals.stderr index 4cfbf5e4b74ea..67e47865108e1 100644 --- a/tests/ui/unseparated_prefix_literals.stderr +++ b/tests/ui/unseparated_prefix_literals.stderr @@ -1,5 +1,5 @@ error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:24:18 + --> tests/ui/unseparated_prefix_literals.rs:23:18 | LL | let _fail1 = 1234i32; | ^^^^^^^ help: add an underscore: `1234_i32` @@ -8,43 +8,43 @@ LL | let _fail1 = 1234i32; = help: to override `-D warnings` add `#[allow(clippy::unseparated_literal_suffix)]` error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:26:18 + --> tests/ui/unseparated_prefix_literals.rs:25:18 | LL | let _fail2 = 1234u32; | ^^^^^^^ help: add an underscore: `1234_u32` error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:28:18 + --> tests/ui/unseparated_prefix_literals.rs:27:18 | LL | let _fail3 = 1234isize; | ^^^^^^^^^ help: add an underscore: `1234_isize` error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:30:18 + --> tests/ui/unseparated_prefix_literals.rs:29:18 | LL | let _fail4 = 1234usize; | ^^^^^^^^^ help: add an underscore: `1234_usize` error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:32:18 + --> tests/ui/unseparated_prefix_literals.rs:31:18 | LL | let _fail5 = 0x123isize; | ^^^^^^^^^^ help: add an underscore: `0x123_isize` error: float type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:37:19 + --> tests/ui/unseparated_prefix_literals.rs:36:19 | LL | let _failf1 = 1.5f32; | ^^^^^^ help: add an underscore: `1.5_f32` error: float type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:39:19 + --> tests/ui/unseparated_prefix_literals.rs:38:19 | LL | let _failf2 = 1f32; | ^^^^ help: add an underscore: `1_f32` error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:15:9 + --> tests/ui/unseparated_prefix_literals.rs:14:9 | LL | 42usize | ^^^^^^^ help: add an underscore: `42_usize` @@ -55,7 +55,7 @@ LL | let _ = lit_from_macro!(); = note: this error originates in the macro `lit_from_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: integer type suffix should be separated by an underscore - --> tests/ui/unseparated_prefix_literals.rs:48:16 + --> tests/ui/unseparated_prefix_literals.rs:47:16 | LL | assert_eq!(4897u32, 32223); | ^^^^^^^ help: add an underscore: `4897_u32` diff --git a/tests/ui/unused_async.rs b/tests/ui/unused_async.rs index b6780d240b17c..6fcb55cb434f1 100644 --- a/tests/ui/unused_async.rs +++ b/tests/ui/unused_async.rs @@ -1,11 +1,10 @@ #![warn(clippy::unused_async)] -#![allow(incomplete_features)] use std::future::Future; use std::pin::Pin; mod issue10800 { - #![allow(dead_code, unused_must_use, clippy::no_effect)] + #![allow(clippy::no_effect)] use std::future::ready; diff --git a/tests/ui/unused_async.stderr b/tests/ui/unused_async.stderr index f95fdd8653001..513e0bb9b9ed4 100644 --- a/tests/ui/unused_async.stderr +++ b/tests/ui/unused_async.stderr @@ -1,5 +1,5 @@ error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:12:5 + --> tests/ui/unused_async.rs:11:5 | LL | / async fn async_block_await() { LL | | @@ -12,7 +12,7 @@ LL | | } | = help: consider removing the `async` from this function note: `await` used in an async block, which does not require the enclosing function to be `async` - --> tests/ui/unused_async.rs:16:23 + --> tests/ui/unused_async.rs:15:23 | LL | ready(()).await; | ^^^^^ @@ -20,7 +20,7 @@ LL | ready(()).await; = help: to override `-D warnings` add `#[allow(clippy::unused_async)]` error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:46:5 + --> tests/ui/unused_async.rs:45:5 | LL | async fn f3() {} | ^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | async fn f3() {} = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:75:1 + --> tests/ui/unused_async.rs:74:1 | LL | / async fn foo() -> i32 { LL | | @@ -40,7 +40,7 @@ LL | | } = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:88:5 + --> tests/ui/unused_async.rs:87:5 | LL | / async fn unused(&self) -> i32 { LL | | diff --git a/tests/ui/unused_enumerate_index.fixed b/tests/ui/unused_enumerate_index.fixed index 258e52971ceab..4e7a50825a3e3 100644 --- a/tests/ui/unused_enumerate_index.fixed +++ b/tests/ui/unused_enumerate_index.fixed @@ -1,5 +1,5 @@ -#![allow(unused, clippy::map_identity)] #![warn(clippy::unused_enumerate_index)] +#![allow(clippy::map_identity)] use std::iter::Enumerate; diff --git a/tests/ui/unused_enumerate_index.rs b/tests/ui/unused_enumerate_index.rs index a17e3259a9b07..13115e6ab322f 100644 --- a/tests/ui/unused_enumerate_index.rs +++ b/tests/ui/unused_enumerate_index.rs @@ -1,5 +1,5 @@ -#![allow(unused, clippy::map_identity)] #![warn(clippy::unused_enumerate_index)] +#![allow(clippy::map_identity)] use std::iter::Enumerate; diff --git a/tests/ui/unused_format_specs_width.rs b/tests/ui/unused_format_specs_width.rs index 3f0bfc0963a87..ea9f62e1e95e1 100644 --- a/tests/ui/unused_format_specs_width.rs +++ b/tests/ui/unused_format_specs_width.rs @@ -2,7 +2,7 @@ // Format width has no effect for certain traits (issue #15039) #![warn(clippy::unused_format_specs)] -#![allow(clippy::zero_ptr, clippy::manual_dangling_ptr)] +#![expect(clippy::manual_dangling_ptr, clippy::zero_ptr)] fn main() { // Integer formats with # (alternate): 0x/0o/0b prefix makes min width 4 diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index 32a50375806a3..5859dc20f6428 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -1,6 +1,5 @@ -#![allow(dead_code, clippy::needless_pass_by_ref_mut)] -#![allow(clippy::redundant_pattern_matching)] #![warn(clippy::unused_io_amount)] +#![expect(clippy::redundant_pattern_matching)] extern crate futures; use futures::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr index 71bb4c40de840..466487de894aa 100644 --- a/tests/ui/unused_io_amount.stderr +++ b/tests/ui/unused_io_amount.stderr @@ -1,5 +1,5 @@ error: written amount is not handled - --> tests/ui/unused_io_amount.rs:10:5 + --> tests/ui/unused_io_amount.rs:9:5 | LL | s.write(b"test")?; | ^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | s.write(b"test")?; = help: to override `-D warnings` add `#[allow(clippy::unused_io_amount)]` error: read amount is not handled - --> tests/ui/unused_io_amount.rs:13:5 + --> tests/ui/unused_io_amount.rs:12:5 | LL | s.read(&mut buf)?; | ^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | s.read(&mut buf)?; = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> tests/ui/unused_io_amount.rs:19:5 + --> tests/ui/unused_io_amount.rs:18:5 | LL | s.write(b"test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | s.write(b"test").unwrap(); = help: use `Write::write_all` instead, or handle partial writes error: read amount is not handled - --> tests/ui/unused_io_amount.rs:22:5 + --> tests/ui/unused_io_amount.rs:21:5 | LL | s.read(&mut buf).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,19 +33,19 @@ LL | s.read(&mut buf).unwrap(); = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> tests/ui/unused_io_amount.rs:27:5 + --> tests/ui/unused_io_amount.rs:26:5 | LL | s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: written amount is not handled - --> tests/ui/unused_io_amount.rs:29:5 + --> tests/ui/unused_io_amount.rs:28:5 | LL | s.write_vectored(&[io::IoSlice::new(&[])])?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: read amount is not handled - --> tests/ui/unused_io_amount.rs:37:5 + --> tests/ui/unused_io_amount.rs:36:5 | LL | reader.read(&mut result).ok()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL | reader.read(&mut result).ok()?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> tests/ui/unused_io_amount.rs:47:5 + --> tests/ui/unused_io_amount.rs:46:5 | LL | reader.read(&mut result).or_else(|err| Err(err))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | reader.read(&mut result).or_else(|err| Err(err))?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> tests/ui/unused_io_amount.rs:60:5 + --> tests/ui/unused_io_amount.rs:59:5 | LL | reader.read(&mut result).or(Err(Error::Kind))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL | reader.read(&mut result).or(Err(Error::Kind))?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> tests/ui/unused_io_amount.rs:68:5 + --> tests/ui/unused_io_amount.rs:67:5 | LL | / reader LL | | @@ -82,7 +82,7 @@ LL | | .expect("error"); = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> tests/ui/unused_io_amount.rs:78:5 + --> tests/ui/unused_io_amount.rs:77:5 | LL | s.write(b"ok").is_ok(); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | s.write(b"ok").is_ok(); = help: use `Write::write_all` instead, or handle partial writes error: written amount is not handled - --> tests/ui/unused_io_amount.rs:80:5 + --> tests/ui/unused_io_amount.rs:79:5 | LL | s.write(b"err").is_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -98,7 +98,7 @@ LL | s.write(b"err").is_err(); = help: use `Write::write_all` instead, or handle partial writes error: read amount is not handled - --> tests/ui/unused_io_amount.rs:83:5 + --> tests/ui/unused_io_amount.rs:82:5 | LL | s.read(&mut buf).is_ok(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -106,7 +106,7 @@ LL | s.read(&mut buf).is_ok(); = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> tests/ui/unused_io_amount.rs:85:5 + --> tests/ui/unused_io_amount.rs:84:5 | LL | s.read(&mut buf).is_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -114,7 +114,7 @@ LL | s.read(&mut buf).is_err(); = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> tests/ui/unused_io_amount.rs:90:5 + --> tests/ui/unused_io_amount.rs:89:5 | LL | w.write(b"hello world").await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | w.write(b"hello world").await.unwrap(); = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> tests/ui/unused_io_amount.rs:96:5 + --> tests/ui/unused_io_amount.rs:95:5 | LL | r.read(&mut buf[..]).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -130,7 +130,7 @@ LL | r.read(&mut buf[..]).await.unwrap(); = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> tests/ui/unused_io_amount.rs:104:5 + --> tests/ui/unused_io_amount.rs:103:5 | LL | w.write(b"hello world"); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -138,7 +138,7 @@ LL | w.write(b"hello world"); = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: written amount is not handled - --> tests/ui/unused_io_amount.rs:111:9 + --> tests/ui/unused_io_amount.rs:110:9 | LL | w.write(b"hello world").await?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -146,7 +146,7 @@ LL | w.write(b"hello world").await?; = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> tests/ui/unused_io_amount.rs:120:9 + --> tests/ui/unused_io_amount.rs:119:9 | LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?; = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> tests/ui/unused_io_amount.rs:129:5 + --> tests/ui/unused_io_amount.rs:128:5 | LL | w.write(b"hello world").await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -162,7 +162,7 @@ LL | w.write(b"hello world").await.unwrap(); = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> tests/ui/unused_io_amount.rs:135:5 + --> tests/ui/unused_io_amount.rs:134:5 | LL | r.read(&mut buf[..]).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -170,92 +170,92 @@ LL | r.read(&mut buf[..]).await.unwrap(); = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> tests/ui/unused_io_amount.rs:148:11 + --> tests/ui/unused_io_amount.rs:147:11 | LL | match s.write(b"test") { | ^^^^^^^^^^^^^^^^ | = help: use `Write::write_all` instead, or handle partial writes note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:150:9 + --> tests/ui/unused_io_amount.rs:149:9 | LL | Ok(_) => todo!(), | ^^^^^ error: read amount is not handled - --> tests/ui/unused_io_amount.rs:155:11 + --> tests/ui/unused_io_amount.rs:154:11 | LL | match s.read(&mut buf) { | ^^^^^^^^^^^^^^^^ | = help: use `Read::read_exact` instead, or handle partial reads note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:157:9 + --> tests/ui/unused_io_amount.rs:156:9 | LL | Ok(_) => todo!(), | ^^^^^ error: read amount is not handled - --> tests/ui/unused_io_amount.rs:163:11 + --> tests/ui/unused_io_amount.rs:162:11 | LL | match s.read(&mut [0u8; 4]) { | ^^^^^^^^^^^^^^^^^^^^^ | = help: use `Read::read_exact` instead, or handle partial reads note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:165:9 + --> tests/ui/unused_io_amount.rs:164:9 | LL | Ok(_) => todo!(), | ^^^^^ error: written amount is not handled - --> tests/ui/unused_io_amount.rs:171:11 + --> tests/ui/unused_io_amount.rs:170:11 | LL | match s.write(b"test") { | ^^^^^^^^^^^^^^^^ | = help: use `Write::write_all` instead, or handle partial writes note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:173:9 + --> tests/ui/unused_io_amount.rs:172:9 | LL | Ok(_) => todo!(), | ^^^^^ error: read amount is not handled - --> tests/ui/unused_io_amount.rs:183:8 + --> tests/ui/unused_io_amount.rs:182:8 | LL | if let Ok(_) = s.read(&mut [0u8; 4]) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `Read::read_exact` instead, or handle partial reads note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:183:12 + --> tests/ui/unused_io_amount.rs:182:12 | LL | if let Ok(_) = s.read(&mut [0u8; 4]) { | ^^^^^ error: written amount is not handled - --> tests/ui/unused_io_amount.rs:190:8 + --> tests/ui/unused_io_amount.rs:189:8 | LL | if let Ok(_) = s.write(b"test") { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `Write::write_all` instead, or handle partial writes note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:190:12 + --> tests/ui/unused_io_amount.rs:189:12 | LL | if let Ok(_) = s.write(b"test") { | ^^^^^ error: written amount is not handled - --> tests/ui/unused_io_amount.rs:197:8 + --> tests/ui/unused_io_amount.rs:196:8 | LL | if let Ok(..) = s.write(b"test") { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `Write::write_all` instead, or handle partial writes note: the result is consumed here, but the amount of I/O bytes remains unhandled - --> tests/ui/unused_io_amount.rs:197:12 + --> tests/ui/unused_io_amount.rs:196:12 | LL | if let Ok(..) = s.write(b"test") { | ^^^^^^ diff --git a/tests/ui/unused_peekable.rs b/tests/ui/unused_peekable.rs index 29e830fefb87d..8c5a3c6fa9fa6 100644 --- a/tests/ui/unused_peekable.rs +++ b/tests/ui/unused_peekable.rs @@ -1,5 +1,5 @@ #![warn(clippy::unused_peekable)] -#![allow(clippy::no_effect)] +#![expect(clippy::no_effect)] use std::iter::{Empty, Peekable}; diff --git a/tests/ui/unused_result_ok.fixed b/tests/ui/unused_result_ok.fixed index faedd96216c2e..91db7574b0c31 100644 --- a/tests/ui/unused_result_ok.fixed +++ b/tests/ui/unused_result_ok.fixed @@ -1,6 +1,5 @@ //@aux-build:proc_macros.rs #![warn(clippy::unused_result_ok)] -#![allow(dead_code)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/unused_result_ok.rs b/tests/ui/unused_result_ok.rs index 6ab974861b636..b02252db416c7 100644 --- a/tests/ui/unused_result_ok.rs +++ b/tests/ui/unused_result_ok.rs @@ -1,6 +1,5 @@ //@aux-build:proc_macros.rs #![warn(clippy::unused_result_ok)] -#![allow(dead_code)] #[macro_use] extern crate proc_macros; diff --git a/tests/ui/unused_result_ok.stderr b/tests/ui/unused_result_ok.stderr index 0e134ba3ccba2..e4560aa84dea1 100644 --- a/tests/ui/unused_result_ok.stderr +++ b/tests/ui/unused_result_ok.stderr @@ -1,5 +1,5 @@ error: ignoring a result with `.ok()` is misleading - --> tests/ui/unused_result_ok.rs:9:5 + --> tests/ui/unused_result_ok.rs:8:5 | LL | x.parse::().ok(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + let _ = x.parse::(); | error: ignoring a result with `.ok()` is misleading - --> tests/ui/unused_result_ok.rs:19:5 + --> tests/ui/unused_result_ok.rs:18:5 | LL | x . parse::() . ok (); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + let _ = x . parse::(); | error: ignoring a result with `.ok()` is misleading - --> tests/ui/unused_result_ok.rs:37:5 + --> tests/ui/unused_result_ok.rs:36:5 | LL | v!().ok(); | ^^^^^^^^^ @@ -37,7 +37,7 @@ LL + let _ = v!(); | error: ignoring a result with `.ok()` is misleading - --> tests/ui/unused_result_ok.rs:31:9 + --> tests/ui/unused_result_ok.rs:30:9 | LL | Ok::<(), ()>(()).ok(); | ^^^^^^^^^^^^^^^^^^^^^ From 02e9f20dc8a1430e4b47f8db8557eba930d6fd7b Mon Sep 17 00:00:00 2001 From: Eddie Roman Date: Sun, 19 Jul 2026 21:20:21 +0300 Subject: [PATCH 57/63] fix(lint-page): add accessible labels to filters --- tests/lint-page.rs | 21 +++++++++++++++++++++ util/gh-pages/index_template.html | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/lint-page.rs diff --git a/tests/lint-page.rs b/tests/lint-page.rs new file mode 100644 index 0000000000000..86ba035f3ce98 --- /dev/null +++ b/tests/lint-page.rs @@ -0,0 +1,21 @@ +#[test] +fn lint_page_accessibility() { + let template = include_str!("../util/gh-pages/index_template.html"); + + // The theme selector must have a programmatically associated label + assert!( + template.contains(r#"for="theme-choice""#), + "theme-choice {# #} {# #} {# #} @@ -118,9 +118,9 @@

Clippy Lints Total number: {{+ count {# #} {% for (sym, name) in [("≥", "gte"), ("≤", "lte"), ("=", "eq")] %}
  • {# #} - {#+ #} + {#+ #} 1. {# #} - {# #} + {# #} .0 {# #}
  • {# #} {% endfor %} From b9662e2876f3147ff974cf9cd4147b2eace6c189 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Sun, 19 Jul 2026 13:18:34 -0700 Subject: [PATCH 58/63] `cargo_common_metadata`: update link in documentation Update the link target to avoid a redirect from the rust-lang-nursery address, and wrap the URL in angle brackets so that it gets rendered as a link. --- clippy_lints/src/cargo/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/cargo/mod.rs b/clippy_lints/src/cargo/mod.rs index 0aa6e4c3e8e27..fc9061b1699d1 100644 --- a/clippy_lints/src/cargo/mod.rs +++ b/clippy_lints/src/cargo/mod.rs @@ -17,7 +17,7 @@ use rustc_span::DUMMY_SP; declare_clippy_lint! { /// ### What it does /// Checks to see if all common metadata is defined in - /// `Cargo.toml`. See: https://rust-lang-nursery.github.io/api-guidelines/documentation.html#cargotoml-includes-all-common-metadata-c-metadata + /// `Cargo.toml`. See: /// /// ### Why is this bad? /// It will be more difficult for users to discover the From 248bb5f49aef93f7f79844d78596bb95d2796e73 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Sun, 5 Jul 2026 00:18:48 -0400 Subject: [PATCH 59/63] Rewrite `min_ident_chars`. * Directly access the identifiers instead of using a visitor. * Don't lint functions with linking related attributes (e.g. `no_mangle`). * Delay checking for external macros. * Check the length in code-points and not bytes. * Only walk up the HIR tree if we need to check for trait impl function parameters. * State the number of missing characters in the lint message. --- clippy_lints/src/min_ident_chars.rs | 343 ++++++++---------- .../min_ident_chars/min_ident_chars.stderr | 17 +- tests/ui/min_ident_chars.rs | 37 +- tests/ui/min_ident_chars.stderr | 148 +++++--- 4 files changed, 294 insertions(+), 251 deletions(-) diff --git a/clippy_lints/src/min_ident_chars.rs b/clippy_lints/src/min_ident_chars.rs index 2bb574ac113c9..058c3ddb82054 100644 --- a/clippy_lints/src/min_ident_chars.rs +++ b/clippy_lints/src/min_ident_chars.rs @@ -1,18 +1,18 @@ use clippy_config::Conf; -use clippy_utils::diagnostics::span_lint; +use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::is_from_proc_macro; +use core::iter; +use core::num::NonZero; use rustc_data_structures::fx::FxHashSet; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::{Visitor, walk_item, walk_trait_item}; +use rustc_errors::pluralize; use rustc_hir::{ - GenericParamKind, HirId, Impl, ImplItem, ImplItemImplKind, ImplItemKind, Item, ItemKind, ItemLocalId, Node, Pat, - PatKind, TraitItem, UsePath, + FieldDef, HirId, ImplItem, ImplItemImplKind, ImplItemKind, Item, ItemKind, Node, Pat, PatKind, TraitFn, TraitItem, + TraitItemKind, UseKind, Variant, }; -use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; -use rustc_span::symbol::Ident; -use rustc_span::{Span, Symbol}; -use std::borrow::Cow; +use rustc_span::{Ident, Symbol}; +use std::borrow::Cow::{self, Borrowed, Owned}; declare_clippy_lint! { /// ### What it does @@ -50,234 +50,185 @@ impl_lint_pass!(MinIdentChars => [MIN_IDENT_CHARS]); pub struct MinIdentChars { allowed_idents_below_min_chars: FxHashSet, - min_ident_chars_threshold: u64, + min_chars_threshold: u64, + /// The number of parameter bindings which still need to be skipped for the current + /// function. + /// + /// Impl trait functions have special rules are handled in `check_impl_item` since + /// they have special rules. This is used to signal to `check_pat` the number of parameter + current_fn_params_remaining: u32, } impl MinIdentChars { pub fn new(conf: &'static Conf) -> Self { Self { allowed_idents_below_min_chars: conf.allowed_idents_below_min_chars.iter().cloned().collect(), - min_ident_chars_threshold: conf.min_ident_chars_threshold, + min_chars_threshold: conf.min_ident_chars_threshold, + current_fn_params_remaining: 0, } } #[expect(clippy::cast_possible_truncation)] - fn is_ident_too_short(&self, cx: &LateContext<'_>, str: &str, span: Span) -> bool { - !span.in_external_macro(cx.sess().source_map()) - && str.len() <= self.min_ident_chars_threshold as usize - && !str.starts_with('_') - && !str.is_empty() - && !self.allowed_idents_below_min_chars.contains(str) - } -} - -impl LateLintPass<'_> for MinIdentChars { - fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - if self.min_ident_chars_threshold == 0 { - return; + fn check_sym(&self, s: Symbol) -> Option> { + let s = s.as_str(); + if s.len() / 4 <= self.min_chars_threshold as usize + && !s.starts_with('_') + && !self.allowed_idents_below_min_chars.contains(s) + && let len = s.chars().count() + && let Some(missing) = (self.min_chars_threshold as usize).checked_sub(len) + { + NonZero::new(missing + 1) + } else { + None } - - walk_item(&mut IdentVisitor { conf: self, cx }, item); } - fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) { - if self.min_ident_chars_threshold == 0 { - return; + fn lint_msg(&self, missing: NonZero) -> Cow<'static, str> { + if self.min_chars_threshold == 1 { + Borrowed("this identifier consists of only a single character") + } else { + let n = missing.get(); + Owned(format!("this identifier is {n} character{} too short", pluralize!(n))) } + } - // If the function is declared but not defined in a trait, check_pat isn't called so we need to - // check this explicitly - if matches!(&item.kind, rustc_hir::TraitItemKind::Fn(_, _)) { - let param_names = cx.tcx.fn_arg_idents(item.owner_id.to_def_id()); - for ident in param_names.iter().flatten() { - let str = ident.as_str(); - if self.is_ident_too_short(cx, str, ident.span) { - emit_min_ident_chars(self, cx, str, ident.span); + fn emit(&self, cx: &LateContext<'_>, ident: Ident, missing: NonZero) { + if !ident.span.in_external_macro(cx.tcx.sess.source_map()) && !is_from_proc_macro(cx, &ident) { + span_lint_and_then(cx, MIN_IDENT_CHARS, ident.span, self.lint_msg(missing), |diag| { + // FIXME(@Jarcho): Capture a span from the config and point to it here. + if self.min_chars_threshold != 1 { + diag.note_once(format!("the configured threshold is {}", self.min_chars_threshold)); } - } + }); } - - walk_trait_item(&mut IdentVisitor { conf: self, cx }, item); } - // This is necessary as `Node::Pat`s are not visited in `visit_id`. :/ - fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) { - if let PatKind::Binding(_, _, ident, ..) = pat.kind - && let str = ident.as_str() - && self.is_ident_too_short(cx, str, ident.span) - && is_not_in_trait_impl(cx, pat, ident) - { - emit_min_ident_chars(self, cx, str, ident.span); + fn emit_hir(&self, cx: &LateContext<'_>, id: HirId, ident: Ident, missing: NonZero) { + if !ident.span.in_external_macro(cx.tcx.sess.source_map()) && !is_from_proc_macro(cx, &ident) { + span_lint_hir_and_then(cx, MIN_IDENT_CHARS, id, ident.span, self.lint_msg(missing), |diag| { + diag.note_once(format!("the configured threshold is {}", self.min_chars_threshold)); + }); } } } -struct IdentVisitor<'cx, 'tcx> { - conf: &'cx MinIdentChars, - cx: &'cx LateContext<'tcx>, -} - -impl Visitor<'_> for IdentVisitor<'_, '_> { - fn visit_id(&mut self, hir_id: HirId) { - let Self { conf, cx } = *self; - // FIXME(#112534) Reimplementation of `find`, as it uses indexing, which can (and will in - // async functions, or really anything async) panic. This should probably be fixed on the - // rustc side, this is just a temporary workaround. - let node = if hir_id.local_id == ItemLocalId::from_u32(0) { - // In this case, we can just use `find`, `Owner`'s `node` field is private anyway so we can't - // reimplement it even if we wanted to - Some(cx.tcx.hir_node(hir_id)) - } else { - let owner = cx.tcx.hir_owner_nodes(hir_id.owner); - owner.nodes.get(hir_id.local_id).copied().map(|p| p.node) - }; - let Some(node) = node else { - return; - }; - let Some(ident) = node.ident() else { +impl LateLintPass<'_> for MinIdentChars { + fn check_item(&mut self, cx: &LateContext<'_>, i: &Item<'_>) { + if self.min_chars_threshold == 0 { return; - }; - - let str = ident.as_str(); - if conf.is_ident_too_short(cx, str, ident.span) { - // Check whether the node is part of a `impl` for a trait. - if matches!(cx.tcx.parent_hir_node(hir_id), Node::TraitRef(_)) { - return; - } - - // Check whether the node is part of a `use` statement. We don't want to emit a warning if the user - // has no control over the type. - let usenode = opt_as_use_node(node).or_else(|| { - cx.tcx - .hir_parent_iter(hir_id) - .find_map(|(_, node)| opt_as_use_node(node)) - }); - - // If the name of the identifier is the same as the one of the imported item, this means that we - // found a `use foo::bar`. We can early-return to not emit the warning. - // If however the identifier is different, this means it is an alias (`use foo::bar as baz`). In - // this case, we need to emit the warning for `baz`. - if let Some(imported_item_path) = usenode - // use `present_items` because it could be in any of type_ns, value_ns, macro_ns - && let Some(Res::Def(_, imported_item_defid)) = imported_item_path.res.value_ns - && cx.tcx.item_name(imported_item_defid).as_str() == str + } + let ident = match i.kind { + ItemKind::Const(ident, ..) + | ItemKind::Enum(ident, ..) + | ItemKind::ExternCrate(None, ident) + | ItemKind::Fn { ident, .. } + | ItemKind::Macro(ident, ..) + | ItemKind::Mod(ident, _) + | ItemKind::Static(_, ident, ..) + | ItemKind::Struct(ident, ..) + | ItemKind::Trait { ident, .. } + | ItemKind::TraitAlias(_, ident, ..) + | ItemKind::TyAlias(ident, ..) + | ItemKind::Union(ident, ..) => ident, + ItemKind::Use(path, UseKind::Single(ident)) + if path.segments.last().is_some_and(|p| p.ident.span != ident.span) => { - return; - } + ident + }, + + ItemKind::ExternCrate(..) + | ItemKind::ForeignMod { .. } + | ItemKind::GlobalAsm { .. } + | ItemKind::Impl(_) + | ItemKind::Use(..) => return, + }; + if let Some(missing) = self.check_sym(ident.name) + && !(matches!(i.kind, ItemKind::Fn { .. }) + && cx.tcx.codegen_fn_attrs(i.owner_id.def_id).contains_extern_indicator()) + { + self.emit(cx, ident, missing); + } + } - // `struct Array([T; N])` - // ^ ^ - if let Node::PathSegment(path) = node { - if let Res::Def(def_kind, ..) = path.res - && let DefKind::TyParam | DefKind::ConstParam = def_kind - { - return; - } - if matches!(path.res, Res::PrimTy(..)) || path.res.opt_def_id().is_some_and(|def_id| !def_id.is_local()) + fn check_trait_item(&mut self, cx: &LateContext<'_>, i: &TraitItem<'_>) { + if self.min_chars_threshold == 0 { + return; + } + if let TraitItemKind::Fn(_, TraitFn::Required(idents)) = i.kind { + for &ident in idents { + if let Some(ident) = ident + && let Some(missing) = self.check_sym(ident.name) { - return; + self.emit(cx, ident, missing); } } - // `struct Awa(T)` - // ^ - if let Node::GenericParam(generic_param) = node - && let GenericParamKind::Type { .. } = generic_param.kind - { - return; - } - - // `struct Array([T; N])` - // ^ - if let Node::GenericParam(generic_param) = node - && let GenericParamKind::Const { .. } = generic_param.kind - { - return; - } + } + if let Some(missing) = self.check_sym(i.ident.name) + && !(matches!(i.kind, TraitItemKind::Fn(_, TraitFn::Provided(_))) + && cx.tcx.codegen_fn_attrs(i.owner_id.def_id).contains_extern_indicator()) + { + self.emit(cx, i.ident, missing); + } + } - if is_from_proc_macro(cx, &ident) { - return; + fn check_impl_item(&mut self, cx: &LateContext<'_>, i: &ImplItem<'_>) { + if self.min_chars_threshold == 0 { + return; + } + if let ImplItemImplKind::Trait { + trait_item_def_id: Ok(trait_item), + .. + } = i.impl_kind + { + // For trait impls only lint if the parameter names are different from the trait's. + if let ImplItemKind::Fn(_, body) = i.kind { + let mut named_params_count = 0; + for (trait_ident, param) in iter::zip(cx.tcx.fn_arg_idents(trait_item), cx.tcx.hir_body(body).params) { + if let PatKind::Binding(_, _, ident, _) = param.pat.kind { + named_params_count += 1; + if trait_ident.is_none_or(|trait_ident| ident.name != trait_ident.name) + && let Some(missing) = self.check_sym(ident.name) + { + self.emit_hir(cx, param.pat.hir_id, ident, missing); + } + } + } + // Signal the number of parameters to skip to `check_pat`. + // This needs to be added since impl items can technically appear inside + // both the function signature and generic predicates. + self.current_fn_params_remaining += named_params_count; } - - emit_min_ident_chars(conf, cx, str, ident.span); + } else if let Some(missing) = self.check_sym(i.ident.name) + && !(matches!(i.kind, ImplItemKind::Fn(..)) + && cx.tcx.codegen_fn_attrs(i.owner_id.def_id).contains_extern_indicator()) + { + self.emit(cx, i.ident, missing); } } -} - -fn emit_min_ident_chars(conf: &MinIdentChars, cx: &impl LintContext, ident: &str, span: Span) { - let help = if conf.min_ident_chars_threshold == 1 { - Cow::Borrowed("this ident consists of a single char") - } else { - Cow::Owned(format!( - "this ident is too short ({} <= {})", - ident.len(), - conf.min_ident_chars_threshold, - )) - }; - span_lint(cx, MIN_IDENT_CHARS, span, help); -} -/// Attempt to convert the node to an [`ItemKind::Use`] node. -/// -/// If it is, return the [`UsePath`] contained within. -fn opt_as_use_node(node: Node<'_>) -> Option<&'_ UsePath<'_>> { - if let Node::Item(item) = node - && let ItemKind::Use(path, _) = item.kind - { - Some(path) - } else { - None + fn check_field_def(&mut self, cx: &LateContext<'_>, f: &FieldDef<'_>) { + if let Some(missing) = self.check_sym(f.ident.name) { + self.emit(cx, f.ident, missing); + } } -} -/// Check if a pattern is a function param in an impl block for a trait and that the param name is -/// the same than in the trait definition. -fn is_not_in_trait_impl(cx: &LateContext<'_>, pat: &Pat<'_>, ident: Ident) -> bool { - let parent_node = cx.tcx.parent_hir_node(pat.hir_id); - if !matches!(parent_node, Node::Param(_)) { - return true; + fn check_variant(&mut self, cx: &LateContext<'_>, v: &Variant<'_>) { + if let Some(missing) = self.check_sym(v.ident.name) { + self.emit(cx, v.ident, missing); + } } - for (_, parent_node) in cx.tcx.hir_parent_iter(pat.hir_id) { - if let Node::ImplItem(impl_item) = parent_node - && matches!(impl_item.kind, ImplItemKind::Fn(_, _)) + fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) { + if let PatKind::Binding(_, _, ident, ..) = pat.kind + && self.min_chars_threshold != 0 { - let impl_parent_node = cx.tcx.parent_hir_node(impl_item.hir_id()); - if let Node::Item(parent_item) = impl_parent_node - && let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = &parent_item.kind - && let Some(name) = get_param_name(impl_item, cx, ident) + if self.current_fn_params_remaining != 0 + && let Node::Param(_) = cx.tcx.parent_hir_node(pat.hir_id) { - return name != ident.name; + self.current_fn_params_remaining -= 1; + } else if let Some(missing) = self.check_sym(ident.name) { + self.emit(cx, ident, missing); } - - return true; } } - - true -} - -fn get_param_name(impl_item: &ImplItem<'_>, cx: &LateContext<'_>, ident: Ident) -> Option { - if let ImplItemImplKind::Trait { - trait_item_def_id: Ok(trait_item_def_id), - .. - } = impl_item.impl_kind - { - let trait_param_names = cx.tcx.fn_arg_idents(trait_item_def_id); - - let ImplItemKind::Fn(_, body_id) = impl_item.kind else { - return None; - }; - - if let Some(param_index) = cx - .tcx - .hir_body_param_idents(body_id) - .position(|param_ident| param_ident.is_some_and(|param_ident| param_ident.span == ident.span)) - && let Some(trait_param_name) = trait_param_names.get(param_index) - && let Some(trait_param_ident) = trait_param_name - { - return Some(trait_param_ident.name); - } - } - - None } diff --git a/tests/ui-toml/min_ident_chars/min_ident_chars.stderr b/tests/ui-toml/min_ident_chars/min_ident_chars.stderr index be795f4daff24..5e5ffd3c98fd4 100644 --- a/tests/ui-toml/min_ident_chars/min_ident_chars.stderr +++ b/tests/ui-toml/min_ident_chars/min_ident_chars.stderr @@ -1,49 +1,50 @@ -error: this ident is too short (1 <= 3) +error: this identifier is 3 characters too short --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:6:41 | LL | use extern_types::{Aaa, LONGER, M, N as W}; | ^ | + = note: the configured threshold is 3 = note: `-D clippy::min-ident-chars` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]` -error: this ident is too short (1 <= 3) +error: this identifier is 3 characters too short --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:9:11 | LL | pub const N: u32 = 0; | ^ -error: this ident is too short (3 <= 3) +error: this identifier is 1 character too short --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:15:5 | LL | aaa: Aaa, | ^^^ -error: this ident is too short (3 <= 3) +error: this identifier is 1 character too short --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:21:9 | LL | let vvv = 1; | ^^^ -error: this ident is too short (3 <= 3) +error: this identifier is 1 character too short --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:23:9 | LL | let uuu = 1; | ^^^ -error: this ident is too short (1 <= 3) +error: this identifier is 3 characters too short --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:25:14 | LL | let (mut a, mut b) = (1, 2); | ^ -error: this ident is too short (1 <= 3) +error: this identifier is 3 characters too short --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:25:21 | LL | let (mut a, mut b) = (1, 2); | ^ -error: this ident is too short (1 <= 3) +error: this identifier is 3 characters too short --> tests/ui-toml/min_ident_chars/min_ident_chars.rs:28:9 | LL | for i in 0..1000 {} diff --git a/tests/ui/min_ident_chars.rs b/tests/ui/min_ident_chars.rs index 298798be7a1e6..c9348b545cb39 100644 --- a/tests/ui/min_ident_chars.rs +++ b/tests/ui/min_ident_chars.rs @@ -1,7 +1,7 @@ //@aux-build:proc_macros.rs #![warn(clippy::min_ident_chars)] #![expect(irrefutable_let_patterns, nonstandard_style)] -#![allow(clippy::struct_field_names)] +#![allow(non_local_definitions, clippy::struct_field_names)] extern crate proc_macros; use proc_macros::{external, with_span}; @@ -173,3 +173,38 @@ impl D for Issue13396 { } fn long(long: i32) {} } + +const _: () = { + trait A { + //~^ min_ident_chars + fn f(h: [u32; 0]); + //~^ min_ident_chars + //~| min_ident_chars + } + impl A for () { + fn f( + h: [u32; { + impl A for u32 { + fn f( + h: [u32; { + impl A for i32 { + fn f(h: [u32; 0]) { + let h = 0; //~ min_ident_chars + } + } + let h = 0; //~ min_ident_chars + 0 + }], + ) { + let h = 0; //~ min_ident_chars + } + } + let h = 0; //~ min_ident_chars + 0 + }], + ) { + let h = 0; //~ min_ident_chars + } + } + let h = 0; //~ min_ident_chars +}; diff --git a/tests/ui/min_ident_chars.stderr b/tests/ui/min_ident_chars.stderr index 36bf89e79f004..07082bbc82936 100644 --- a/tests/ui/min_ident_chars.stderr +++ b/tests/ui/min_ident_chars.stderr @@ -1,4 +1,4 @@ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:9:8 | LL | struct A { @@ -7,269 +7,325 @@ LL | struct A { = note: `-D clippy::min-ident-chars` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]` -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:11:5 | LL | a: u32, | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:14:5 | LL | A: u32, | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:16:5 | LL | I: u32, | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:20:8 | LL | struct B(u32); | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:23:8 | LL | struct O { | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:25:5 | LL | o: u32, | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:31:6 | LL | enum C { | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:33:5 | LL | D, | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:35:5 | LL | E, | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:37:5 | LL | F, | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:52:11 | LL | const A: u32 = 0; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:54:10 | LL | type A; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:56:8 | LL | fn a() {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:71:9 | LL | let h = 1; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:73:9 | LL | let e = 2; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:75:9 | LL | let l = 3; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:77:9 | LL | let l = 4; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:79:9 | LL | let o = 6; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:84:10 | LL | let (h, o, w) = (1, 2, 3); | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:84:13 | LL | let (h, o, w) = (1, 2, 3); | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:87:10 | LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:87:14 | LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:87:17 | LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:92:16 | LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:92:19 | LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:92:29 | LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:99:9 | LL | let o = 1; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:101:9 | LL | let o = O { o }; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:116:4 | LL | fn b() {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:118:21 | LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 { | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:118:29 | LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 { | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:137:19 | LL | fn fmt(&self, g: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ^ + | + = note: the configured threshold is 1 -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:144:14 | LL | let a = |f: i8| f; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:144:9 | LL | let a = |f: i8| f; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:149:7 | LL | trait D { | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:151:10 | LL | fn f(g: i32); | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:151:8 | LL | fn f(g: i32); | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:156:8 | LL | fn g(arg: i8) { | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:158:12 | LL | fn c(d: u8) {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:158:14 | LL | fn c(d: u8) {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:166:12 | LL | fn h() {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:168:18 | LL | fn inner(a: i32) {} | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:170:18 | LL | let a = |f: String| f; | ^ -error: this ident consists of a single char +error: this identifier consists of only a single character --> tests/ui/min_ident_chars.rs:170:13 | LL | let a = |f: String| f; | ^ -error: aborting due to 45 previous errors +error: this identifier consists of only a single character + --> tests/ui/min_ident_chars.rs:178:11 + | +LL | trait A { + | ^ + +error: this identifier consists of only a single character + --> tests/ui/min_ident_chars.rs:180:14 + | +LL | fn f(h: [u32; 0]); + | ^ + +error: this identifier consists of only a single character + --> tests/ui/min_ident_chars.rs:180:12 + | +LL | fn f(h: [u32; 0]); + | ^ + +error: this identifier consists of only a single character + --> tests/ui/min_ident_chars.rs:192:41 + | +LL | ... let h = 0; + | ^ + +error: this identifier consists of only a single character + --> tests/ui/min_ident_chars.rs:195:33 + | +LL | ... let h = 0; + | ^ + +error: this identifier consists of only a single character + --> tests/ui/min_ident_chars.rs:199:29 + | +LL | let h = 0; + | ^ + +error: this identifier consists of only a single character + --> tests/ui/min_ident_chars.rs:202:21 + | +LL | let h = 0; + | ^ + +error: this identifier consists of only a single character + --> tests/ui/min_ident_chars.rs:206:17 + | +LL | let h = 0; + | ^ + +error: this identifier consists of only a single character + --> tests/ui/min_ident_chars.rs:209:9 + | +LL | let h = 0; + | ^ + +error: aborting due to 54 previous errors From 120e4933a9864fee70522481ea4a40f78d136a70 Mon Sep 17 00:00:00 2001 From: Eddie Roman Date: Tue, 21 Jul 2026 09:08:26 +0300 Subject: [PATCH 60/63] Explain why the lint page accessibility test exists --- tests/lint-page.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/lint-page.rs b/tests/lint-page.rs index 86ba035f3ce98..49a1ef290552a 100644 --- a/tests/lint-page.rs +++ b/tests/lint-page.rs @@ -1,3 +1,16 @@ +// This test checks that the lint list page stays accessible: the controls must +// keep the `