From 36a50008d007d258a8de38619935d689730e6d1f Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 8 Aug 2023 18:28:20 +0800 Subject: [PATCH 01/79] rustc: Move `crate_types` from `Session` to `GlobalCtxt` Removes a piece of mutable state. Follow up to #114578. --- clippy_lints/src/missing_inline.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index a41d5a9ce8d2f..93f6025c71d67 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -74,7 +74,6 @@ fn is_executable_or_proc_macro(cx: &LateContext<'_>) -> bool { use rustc_session::config::CrateType; cx.tcx - .sess .crate_types() .iter() .any(|t: &CrateType| matches!(t, CrateType::Executable | CrateType::ProcMacro)) From 42186af21e7a0a0d410c40540b534c6c9f02b557 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 10 Aug 2023 16:06:17 +0200 Subject: [PATCH 02/79] Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT --- clippy_lints/src/needless_pass_by_ref_mut.rs | 105 +++++++++++++++---- 1 file changed, 82 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index c634de960d137..6eb17d675e971 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -5,14 +5,16 @@ use clippy_utils::{get_parent_node, inherits_cfg, is_from_proc_macro, is_self}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_qpath, FnKind, Visitor}; -use rustc_hir::{Body, ExprKind, FnDecl, HirId, HirIdMap, HirIdSet, Impl, ItemKind, Mutability, Node, PatKind, QPath}; +use rustc_hir::{ + Body, Closure, Expr, ExprKind, FnDecl, HirId, HirIdMap, HirIdSet, Impl, ItemKind, Mutability, Node, PatKind, QPath, +}; use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::associated_body; use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, Ty, UpvarId, UpvarPath}; +use rustc_middle::ty::{self, Ty, TyCtxt, UpvarId, UpvarPath}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; @@ -147,22 +149,36 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { // Collect variables mutably used and spans which will need dereferencings from the // function body. let MutablyUsedVariablesCtxt { mutably_used_vars, .. } = { - let mut ctx = MutablyUsedVariablesCtxt::default(); + let mut ctx = MutablyUsedVariablesCtxt { + mutably_used_vars: HirIdSet::default(), + prev_bind: None, + prev_move_to_closure: HirIdSet::default(), + aliases: HirIdMap::default(), + async_closures: FxHashSet::default(), + tcx: cx.tcx, + }; let infcx = cx.tcx.infer_ctxt().build(); euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); if is_async { - let closures = ctx.async_closures.clone(); - let hir = cx.tcx.hir(); - for closure in closures { - ctx.prev_bind = None; - ctx.prev_move_to_closure.clear(); - if let Some(body) = hir - .find_by_def_id(closure) - .and_then(associated_body) - .map(|(_, body_id)| hir.body(body_id)) - { - euv::ExprUseVisitor::new(&mut ctx, &infcx, closure, cx.param_env, cx.typeck_results()) - .consume_body(body); + let mut checked_closures = FxHashSet::default(); + while !ctx.async_closures.is_empty() { + let closures = ctx.async_closures.clone(); + ctx.async_closures.clear(); + let hir = cx.tcx.hir(); + for closure in closures { + if !checked_closures.insert(closure) { + continue; + } + ctx.prev_bind = None; + ctx.prev_move_to_closure.clear(); + if let Some(body) = hir + .find_by_def_id(closure) + .and_then(associated_body) + .map(|(_, body_id)| hir.body(body_id)) + { + euv::ExprUseVisitor::new(&mut ctx, &infcx, closure, cx.param_env, cx.typeck_results()) + .consume_body(body); + } } } } @@ -225,16 +241,16 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { } } -#[derive(Default)] -struct MutablyUsedVariablesCtxt { +struct MutablyUsedVariablesCtxt<'tcx> { mutably_used_vars: HirIdSet, prev_bind: Option, prev_move_to_closure: HirIdSet, aliases: HirIdMap, async_closures: FxHashSet, + tcx: TyCtxt<'tcx>, } -impl MutablyUsedVariablesCtxt { +impl<'tcx> MutablyUsedVariablesCtxt<'tcx> { fn add_mutably_used_var(&mut self, mut used_id: HirId) { while let Some(id) = self.aliases.get(&used_id) { self.mutably_used_vars.insert(used_id); @@ -242,9 +258,27 @@ impl MutablyUsedVariablesCtxt { } self.mutably_used_vars.insert(used_id); } + + fn would_be_alias_cycle(&self, alias: HirId, mut target: HirId) -> bool { + while let Some(id) = self.aliases.get(&target) { + if *id == alias { + return true; + } + target = *id; + } + false + } + + fn add_alias(&mut self, alias: HirId, target: HirId) { + // This is to prevent alias loop. + if alias == target || self.would_be_alias_cycle(alias, target) { + return; + } + self.aliases.insert(alias, target); + } } -impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { +impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt<'tcx> { fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _id: HirId) { if let euv::Place { base: @@ -259,7 +293,7 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { { if let Some(bind_id) = self.prev_bind.take() { if bind_id != *vid { - self.aliases.insert(bind_id, *vid); + self.add_alias(bind_id, *vid); } } else if !self.prev_move_to_closure.contains(vid) && matches!(base_ty.ref_mutability(), Some(Mutability::Mut)) @@ -271,7 +305,7 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { } } - fn borrow(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _id: HirId, borrow: ty::BorrowKind) { + fn borrow(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, id: HirId, borrow: ty::BorrowKind) { self.prev_bind = None; if let euv::Place { base: euv::PlaceBase::Local(vid), @@ -289,6 +323,25 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { { self.add_mutably_used_var(*vid); } + } else if borrow == ty::ImmBorrow { + // If there is an `async block`, it'll contain a call to a closure which we need to + // go into to ensure all "mutate" checks are found. + if let Node::Expr(Expr { + kind: + ExprKind::Call( + _, + [ + Expr { + kind: ExprKind::Closure(Closure { def_id, .. }), + .. + }, + ], + ), + .. + }) = self.tcx.hir().get(id) + { + self.async_closures.insert(*def_id); + } } } @@ -296,7 +349,12 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { self.prev_bind = None; if let euv::Place { projections, - base: euv::PlaceBase::Local(vid), + base: + euv::PlaceBase::Local(vid) + | euv::PlaceBase::Upvar(UpvarId { + var_path: UpvarPath { hir_id: vid }, + .. + }), .. } = &cmt.place { @@ -329,8 +387,9 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { // Seems like we are inside an async function. We need to store the closure `DefId` // to go through it afterwards. self.async_closures.insert(inner); - self.aliases.insert(cmt.hir_id, *vid); + self.add_alias(cmt.hir_id, *vid); self.prev_move_to_closure.insert(*vid); + self.prev_bind = None; } } } From 1d01f1bac189674a288a5cd0f1f13994a1bd7fe7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 10 Aug 2023 16:06:27 +0200 Subject: [PATCH 03/79] Update UI test for async blocks for NEEDLESS_PASS_BY_REF_MUT --- tests/ui/needless_pass_by_ref_mut.rs | 25 ++++++++++++++++++++++++ tests/ui/needless_pass_by_ref_mut.stderr | 14 ++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index ae7b018d0e256..a20de47ab323c 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -196,6 +196,31 @@ mod foo { //~| NOTE: this is cfg-gated and may require further changes } +// Should not warn. +async fn inner_async(x: &mut i32, y: &mut u32) { + async { + *y += 1; + *x += 1; + } + .await; +} + +async fn inner_async2(x: &mut i32, y: &mut u32) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + async { + *x += 1; + } + .await; +} + +async fn inner_async3(x: &mut i32, y: &mut u32) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + async { + *y += 1; + } + .await; +} + fn main() { let mut u = 0; let mut v = vec![0]; diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index 0d426ce32f9d5..2e06e7252d9ba 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -94,5 +94,17 @@ LL | fn cfg_warn(s: &mut u32) {} | = note: this is cfg-gated and may require further changes -error: aborting due to 15 previous errors +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:208:39 + | +LL | async fn inner_async2(x: &mut i32, y: &mut u32) { + | ^^^^^^^^ help: consider changing to: `&u32` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:216:26 + | +LL | async fn inner_async3(x: &mut i32, y: &mut u32) { + | ^^^^^^^^ help: consider changing to: `&i32` + +error: aborting due to 17 previous errors From 1ec0501bcabc0fd6aafabda6ac6c75e0bf8f0bfd Mon Sep 17 00:00:00 2001 From: Catherine Flores Date: Thu, 10 Aug 2023 22:03:20 +0000 Subject: [PATCH 04/79] Revert "New lint [`filter_map_bool_then`]" This reverts commits 978b1daf99d8326718684381704902fdaaf71b18 and 3235d9d612909bc64550eea3a0d387e1187e93dd. --- CHANGELOG.md | 1 - clippy_lints/src/declared_lints.rs | 1 - .../src/methods/filter_map_bool_then.rs | 45 ------------------- clippy_lints/src/methods/mod.rs | 34 -------------- clippy_utils/src/paths.rs | 2 - tests/ui/filter_map_bool_then.fixed | 44 ------------------ tests/ui/filter_map_bool_then.rs | 44 ------------------ tests/ui/filter_map_bool_then.stderr | 34 -------------- 8 files changed, 205 deletions(-) delete mode 100644 clippy_lints/src/methods/filter_map_bool_then.rs delete mode 100644 tests/ui/filter_map_bool_then.fixed delete mode 100644 tests/ui/filter_map_bool_then.rs delete mode 100644 tests/ui/filter_map_bool_then.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 2655d93599e7e..6357511cc4cbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4844,7 +4844,6 @@ Released 2018-09-13 [`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default [`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file [`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map -[`filter_map_bool_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_bool_then [`filter_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity [`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next [`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index d4e0d2863348b..9a9998cca4ac7 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -337,7 +337,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::methods::EXPECT_USED_INFO, crate::methods::EXTEND_WITH_DRAIN_INFO, crate::methods::FILETYPE_IS_FILE_INFO, - crate::methods::FILTER_MAP_BOOL_THEN_INFO, crate::methods::FILTER_MAP_IDENTITY_INFO, crate::methods::FILTER_MAP_NEXT_INFO, crate::methods::FILTER_NEXT_INFO, diff --git a/clippy_lints/src/methods/filter_map_bool_then.rs b/clippy_lints/src/methods/filter_map_bool_then.rs deleted file mode 100644 index 4aee22a4afc3b..0000000000000 --- a/clippy_lints/src/methods/filter_map_bool_then.rs +++ /dev/null @@ -1,45 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::paths::BOOL_THEN; -use clippy_utils::source::snippet_opt; -use clippy_utils::ty::is_copy; -use clippy_utils::{is_from_proc_macro, is_trait_method, match_def_path, peel_blocks}; -use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LintContext}; -use rustc_middle::lint::in_external_macro; -use rustc_span::{sym, Span}; - -use super::FILTER_MAP_BOOL_THEN; - -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &Expr<'_>, call_span: Span) { - if !in_external_macro(cx.sess(), expr.span) - && is_trait_method(cx, expr, sym::Iterator) - && let ExprKind::Closure(closure) = arg.kind - && let body = cx.tcx.hir().body(closure.body) - && let value = peel_blocks(body.value) - // Indexing should be fine as `filter_map` always has 1 input, we unfortunately need both - // `inputs` and `params` here as we need both the type and the span - && let param_ty = closure.fn_decl.inputs[0] - && let param = body.params[0] - && is_copy(cx, cx.typeck_results().node_type(param_ty.hir_id).peel_refs()) - && let ExprKind::MethodCall(_, recv, [then_arg], _) = value.kind - && let ExprKind::Closure(then_closure) = then_arg.kind - && let then_body = peel_blocks(cx.tcx.hir().body(then_closure.body).value) - && let Some(def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id) - && match_def_path(cx, def_id, &BOOL_THEN) - && !is_from_proc_macro(cx, expr) - && let Some(param_snippet) = snippet_opt(cx, param.span) - && let Some(filter) = snippet_opt(cx, recv.span) - && let Some(map) = snippet_opt(cx, then_body.span) - { - span_lint_and_sugg( - cx, - FILTER_MAP_BOOL_THEN, - call_span, - "usage of `bool::then` in `filter_map`", - "use `filter` then `map` instead", - format!("filter(|&{param_snippet}| {filter}).map(|{param_snippet}| {map})"), - Applicability::MachineApplicable, - ); - } -} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index dd694ce7393e2..28a8978973fed 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -21,7 +21,6 @@ mod expect_used; mod extend_with_drain; mod filetype_is_file; mod filter_map; -mod filter_map_bool_then; mod filter_map_identity; mod filter_map_next; mod filter_next; @@ -3477,37 +3476,6 @@ declare_clippy_lint! { "disallows `.skip(0)`" } -declare_clippy_lint! { - /// ### What it does - /// Checks for usage of `bool::then` in `Iterator::filter_map`. - /// - /// ### Why is this bad? - /// This can be written with `filter` then `map` instead, which would reduce nesting and - /// separates the filtering from the transformation phase. This comes with no cost to - /// performance and is just cleaner. - /// - /// ### Limitations - /// Does not lint `bool::then_some`, as it eagerly evaluates its arguments rather than lazily. - /// This can create differing behavior, so better safe than sorry. - /// - /// ### Example - /// ```rust - /// # fn really_expensive_fn(i: i32) -> i32 { i } - /// # let v = vec![]; - /// _ = v.into_iter().filter_map(|i| (i % 2 == 0).then(|| really_expensive_fn(i))); - /// ``` - /// Use instead: - /// ```rust - /// # fn really_expensive_fn(i: i32) -> i32 { i } - /// # let v = vec![]; - /// _ = v.into_iter().filter(|i| i % 2 == 0).map(|i| really_expensive_fn(i)); - /// ``` - #[clippy::version = "1.72.0"] - pub FILTER_MAP_BOOL_THEN, - style, - "checks for usage of `bool::then` in `Iterator::filter_map`" -} - declare_clippy_lint! { /// ### What it does /// Looks for calls to `RwLock::write` where the lock is only used for reading. @@ -3676,7 +3644,6 @@ impl_lint_pass!(Methods => [ FORMAT_COLLECT, STRING_LIT_CHARS_ANY, ITER_SKIP_ZERO, - FILTER_MAP_BOOL_THEN, READONLY_WRITE_LOCK ]); @@ -3955,7 +3922,6 @@ impl Methods { }, ("filter_map", [arg]) => { unnecessary_filter_map::check(cx, expr, arg, name); - filter_map_bool_then::check(cx, expr, arg, call_span); filter_map_identity::check(cx, expr, arg, span); }, ("find_map", [arg]) => { diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 914ea85ac2809..8d96d3cfe50b4 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -163,5 +163,3 @@ pub const OPTION_EXPECT: [&str; 4] = ["core", "option", "Option", "expect"]; pub const FORMATTER: [&str; 3] = ["core", "fmt", "Formatter"]; pub const DEBUG_STRUCT: [&str; 4] = ["core", "fmt", "builders", "DebugStruct"]; pub const ORD_CMP: [&str; 4] = ["core", "cmp", "Ord", "cmp"]; -#[expect(clippy::invalid_paths)] // not sure why it thinks this, it works so -pub const BOOL_THEN: [&str; 4] = ["core", "bool", "", "then"]; diff --git a/tests/ui/filter_map_bool_then.fixed b/tests/ui/filter_map_bool_then.fixed deleted file mode 100644 index 3e72fee4b072a..0000000000000 --- a/tests/ui/filter_map_bool_then.fixed +++ /dev/null @@ -1,44 +0,0 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro -#![allow( - clippy::clone_on_copy, - clippy::map_identity, - clippy::unnecessary_lazy_evaluations, - unused -)] -#![warn(clippy::filter_map_bool_then)] - -#[macro_use] -extern crate proc_macros; - -#[derive(Clone, PartialEq)] -struct NonCopy; - -fn main() { - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1); - v.clone().into_iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1); - v.clone() - .into_iter() - .filter(|&i| (i % 2 == 0)).map(|i| i + 1); - v.clone() - .into_iter() - .filter(|&i| i != 1000) - .filter(|&i| (i % 2 == 0)).map(|i| i + 1); - v.iter() - .copied() - .filter(|&i| i != 1000) - .filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1); - // Do not lint - let v = vec![NonCopy, NonCopy]; - v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i)); - external! { - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - } - with_span! { - span - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - } -} diff --git a/tests/ui/filter_map_bool_then.rs b/tests/ui/filter_map_bool_then.rs deleted file mode 100644 index 38a04e57de456..0000000000000 --- a/tests/ui/filter_map_bool_then.rs +++ /dev/null @@ -1,44 +0,0 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro -#![allow( - clippy::clone_on_copy, - clippy::map_identity, - clippy::unnecessary_lazy_evaluations, - unused -)] -#![warn(clippy::filter_map_bool_then)] - -#[macro_use] -extern crate proc_macros; - -#[derive(Clone, PartialEq)] -struct NonCopy; - -fn main() { - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - v.clone() - .into_iter() - .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); - v.clone() - .into_iter() - .filter(|&i| i != 1000) - .filter_map(|i| (i % 2 == 0).then(|| i + 1)); - v.iter() - .copied() - .filter(|&i| i != 1000) - .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); - // Do not lint - let v = vec![NonCopy, NonCopy]; - v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i)); - external! { - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - } - with_span! { - span - let v = vec![1, 2, 3, 4, 5, 6]; - v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - } -} diff --git a/tests/ui/filter_map_bool_then.stderr b/tests/ui/filter_map_bool_then.stderr deleted file mode 100644 index b411cd83dfd29..0000000000000 --- a/tests/ui/filter_map_bool_then.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:19:22 - | -LL | v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` - | - = note: `-D clippy::filter-map-bool-then` implied by `-D warnings` - -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:20:27 - | -LL | v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` - -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:23:10 - | -LL | .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` - -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:27:10 - | -LL | .filter_map(|i| (i % 2 == 0).then(|| i + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` - -error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:31:10 - | -LL | .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1)` - -error: aborting due to 5 previous errors - From f730a2655a0ea22da4cf104d3e97f9fa17c0658f Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Fri, 11 Aug 2023 14:05:13 +0200 Subject: [PATCH 05/79] Merge commit '1e8fdf492808a25d78a97e1242b835ace9924e4d' into clippyup --- CHANGELOG.md | 4 + clippy_dev/src/main.rs | 2 +- clippy_dev/src/setup/vscode.rs | 2 +- clippy_lints/src/casts/ptr_as_ptr.rs | 64 ++--- clippy_lints/src/declared_lints.rs | 4 + clippy_lints/src/derive.rs | 50 ++-- clippy_lints/src/doc.rs | 5 +- clippy_lints/src/eta_reduction.rs | 4 +- clippy_lints/src/ignored_unit_patterns.rs | 52 ++++ clippy_lints/src/lib.rs | 2 + clippy_lints/src/loops/never_loop.rs | 4 +- clippy_lints/src/manual_float_methods.rs | 2 +- clippy_lints/src/matches/redundant_guards.rs | 10 +- clippy_lints/src/methods/expect_used.rs | 44 ---- .../src/methods/filter_map_bool_then.rs | 53 ++++ clippy_lints/src/methods/mod.rs | 121 +++++++--- .../src/methods/unwrap_expect_used.rs | 83 +++++++ clippy_lints/src/methods/unwrap_used.rs | 53 ---- clippy_lints/src/mut_reference.rs | 5 + .../src/operators/const_comparisons.rs | 207 ++++++++++++++++ clippy_lints/src/operators/mod.rs | 43 ++++ clippy_lints/src/option_if_let_else.rs | 2 +- clippy_lints/src/question_mark.rs | 12 +- clippy_lints/src/redundant_locals.rs | 13 + .../src/redundant_type_annotations.rs | 11 +- .../src/slow_vector_initialization.rs | 20 +- .../src/suspicious_xor_used_as_pow.rs | 48 ++-- .../src/utils/internal_lints/invalid_paths.rs | 2 +- clippy_utils/src/ast_utils.rs | 4 +- clippy_utils/src/consts.rs | 2 +- clippy_utils/src/paths.rs | 2 + clippy_utils/src/qualify_min_const_fn.rs | 4 +- clippy_utils/src/sugg.rs | 2 +- clippy_utils/src/ty.rs | 5 + rust-toolchain | 2 +- tests/ui-internal/custom_ice_message.stderr | 3 +- tests/ui-toml/expect_used/expect_used.stderr | 4 +- tests/ui-toml/unwrap_used/unwrap_used.stderr | 39 ++- tests/ui/const_comparisons.rs | 93 +++++++ tests/ui/const_comparisons.stderr | 228 ++++++++++++++++++ tests/ui/expect.stderr | 6 +- tests/ui/filter_map_bool_then.fixed | 58 +++++ tests/ui/filter_map_bool_then.rs | 58 +++++ tests/ui/filter_map_bool_then.stderr | 40 +++ tests/ui/get_unwrap.stderr | 39 ++- tests/ui/ignored_unit_patterns.fixed | 17 ++ tests/ui/ignored_unit_patterns.rs | 17 ++ tests/ui/ignored_unit_patterns.stderr | 28 +++ tests/ui/mut_reference.rs | 15 +- tests/ui/mut_reference.stderr | 8 +- tests/ui/ptr_as_ptr.fixed | 16 +- tests/ui/ptr_as_ptr.rs | 16 +- tests/ui/ptr_as_ptr.stderr | 28 ++- tests/ui/question_mark.fixed | 17 ++ tests/ui/question_mark.rs | 17 ++ tests/ui/question_mark.stderr | 6 +- tests/ui/range_contains.fixed | 2 + tests/ui/range_contains.rs | 2 + tests/ui/range_contains.stderr | 42 ++-- tests/ui/redundant_guards.fixed | 13 + tests/ui/redundant_guards.rs | 13 + tests/ui/redundant_guards.stderr | 16 +- tests/ui/redundant_locals.rs | 9 + tests/ui/redundant_locals.stderr | 22 +- tests/ui/redundant_type_annotations.rs | 20 +- tests/ui/redundant_type_annotations.stderr | 28 +-- tests/ui/rename.fixed | 2 +- tests/ui/rename.rs | 2 +- tests/ui/suspicious_xor_used_as_pow.stderr | 10 +- tests/ui/unwrap.stderr | 9 +- tests/ui/unwrap_expect_used.rs | 11 + tests/ui/unwrap_expect_used.stderr | 24 +- 72 files changed, 1543 insertions(+), 378 deletions(-) create mode 100644 clippy_lints/src/ignored_unit_patterns.rs delete mode 100644 clippy_lints/src/methods/expect_used.rs create mode 100644 clippy_lints/src/methods/filter_map_bool_then.rs create mode 100644 clippy_lints/src/methods/unwrap_expect_used.rs delete mode 100644 clippy_lints/src/methods/unwrap_used.rs create mode 100644 clippy_lints/src/operators/const_comparisons.rs create mode 100644 tests/ui/const_comparisons.rs create mode 100644 tests/ui/const_comparisons.stderr create mode 100644 tests/ui/filter_map_bool_then.fixed create mode 100644 tests/ui/filter_map_bool_then.rs create mode 100644 tests/ui/filter_map_bool_then.stderr create mode 100644 tests/ui/ignored_unit_patterns.fixed create mode 100644 tests/ui/ignored_unit_patterns.rs create mode 100644 tests/ui/ignored_unit_patterns.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 6357511cc4cbb..71671273c57b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4844,6 +4844,7 @@ Released 2018-09-13 [`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default [`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file [`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map +[`filter_map_bool_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_bool_then [`filter_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity [`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next [`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next @@ -4889,12 +4890,14 @@ Released 2018-09-13 [`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else [`if_then_some_else_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none [`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond +[`ignored_unit_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns [`impl_trait_in_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#impl_trait_in_params [`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone [`implicit_hasher`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher [`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return [`implicit_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_add [`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub +[`impossible_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#impossible_comparisons [`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops [`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping [`inconsistent_struct_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_struct_constructor @@ -5189,6 +5192,7 @@ Released 2018-09-13 [`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure [`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call [`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls +[`redundant_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_comparisons [`redundant_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else [`redundant_feature_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_feature_names [`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 43eaccdf5a31a..fca750fafc792 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -41,7 +41,7 @@ fn main() { matches.get_one::("type").map(String::as_str), matches.get_flag("msrv"), ) { - Ok(_) => update_lints::update(update_lints::UpdateMode::Change), + Ok(()) => update_lints::update(update_lints::UpdateMode::Change), Err(e) => eprintln!("Unable to create lint: {e}"), } }, diff --git a/clippy_dev/src/setup/vscode.rs b/clippy_dev/src/setup/vscode.rs index dbcdc9b59e529..204f4af2cf1be 100644 --- a/clippy_dev/src/setup/vscode.rs +++ b/clippy_dev/src/setup/vscode.rs @@ -47,7 +47,7 @@ fn check_install_precondition(force_override: bool) -> bool { } } else { match fs::create_dir(vs_dir_path) { - Ok(_) => { + Ok(()) => { println!("info: created `{VSCODE_DIR}` directory for clippy"); }, Err(err) => { diff --git a/clippy_lints/src/casts/ptr_as_ptr.rs b/clippy_lints/src/casts/ptr_as_ptr.rs index 15ffb00da88ba..181dbcf6e9a86 100644 --- a/clippy_lints/src/casts/ptr_as_ptr.rs +++ b/clippy_lints/src/casts/ptr_as_ptr.rs @@ -1,9 +1,7 @@ -use std::borrow::Cow; - use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::{self, Msrv}; +use clippy_utils::source::snippet_with_applicability; use clippy_utils::sugg::Sugg; -use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, Mutability, TyKind}; use rustc_lint::LateContext; @@ -16,33 +14,41 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) { return; } - if_chain! { - if let ExprKind::Cast(cast_expr, cast_to_hir_ty) = expr.kind; - let (cast_from, cast_to) = (cx.typeck_results().expr_ty(cast_expr), cx.typeck_results().expr_ty(expr)); - if let ty::RawPtr(TypeAndMut { mutbl: from_mutbl, .. }) = cast_from.kind(); - if let ty::RawPtr(TypeAndMut { ty: to_pointee_ty, mutbl: to_mutbl }) = cast_to.kind(); - if matches!((from_mutbl, to_mutbl), - (Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut)); + if let ExprKind::Cast(cast_expr, cast_to_hir_ty) = expr.kind + && let (cast_from, cast_to) = (cx.typeck_results().expr_ty(cast_expr), cx.typeck_results().expr_ty(expr)) + && let ty::RawPtr(TypeAndMut { mutbl: from_mutbl, .. }) = cast_from.kind() + && let ty::RawPtr(TypeAndMut { ty: to_pointee_ty, mutbl: to_mutbl }) = cast_to.kind() + && matches!((from_mutbl, to_mutbl), + (Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut)) // The `U` in `pointer::cast` have to be `Sized` // as explained here: https://github.com/rust-lang/rust/issues/60602. - if to_pointee_ty.is_sized(cx.tcx, cx.param_env); - then { - let mut applicability = Applicability::MachineApplicable; - let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut applicability); - let turbofish = match &cast_to_hir_ty.kind { - TyKind::Infer => Cow::Borrowed(""), - TyKind::Ptr(mut_ty) if matches!(mut_ty.ty.kind, TyKind::Infer) => Cow::Borrowed(""), - _ => Cow::Owned(format!("::<{to_pointee_ty}>")), - }; - span_lint_and_sugg( - cx, - PTR_AS_PTR, - expr.span, - "`as` casting between raw pointers without changing its mutability", - "try `pointer::cast`, a safer alternative", - format!("{}.cast{turbofish}()", cast_expr_sugg.maybe_par()), - applicability, - ); - } + && to_pointee_ty.is_sized(cx.tcx, cx.param_env) + { + let mut app = Applicability::MachineApplicable; + let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut app); + let turbofish = match &cast_to_hir_ty.kind { + TyKind::Infer => String::new(), + TyKind::Ptr(mut_ty) => { + if matches!(mut_ty.ty.kind, TyKind::Infer) { + String::new() + } else { + format!( + "::<{}>", + snippet_with_applicability(cx, mut_ty.ty.span, "/* type */", &mut app) + ) + } + }, + _ => return, + }; + + span_lint_and_sugg( + cx, + PTR_AS_PTR, + expr.span, + "`as` casting between raw pointers without changing its mutability", + "try `pointer::cast`, a safer alternative", + format!("{}.cast{turbofish}()", cast_expr_sugg.maybe_par()), + app, + ); } } diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 9a9998cca4ac7..db114abfc869c 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -203,6 +203,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::if_let_mutex::IF_LET_MUTEX_INFO, crate::if_not_else::IF_NOT_ELSE_INFO, crate::if_then_some_else_none::IF_THEN_SOME_ELSE_NONE_INFO, + crate::ignored_unit_patterns::IGNORED_UNIT_PATTERNS_INFO, crate::implicit_hasher::IMPLICIT_HASHER_INFO, crate::implicit_return::IMPLICIT_RETURN_INFO, crate::implicit_saturating_add::IMPLICIT_SATURATING_ADD_INFO, @@ -337,6 +338,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::methods::EXPECT_USED_INFO, crate::methods::EXTEND_WITH_DRAIN_INFO, crate::methods::FILETYPE_IS_FILE_INFO, + crate::methods::FILTER_MAP_BOOL_THEN_INFO, crate::methods::FILTER_MAP_IDENTITY_INFO, crate::methods::FILTER_MAP_NEXT_INFO, crate::methods::FILTER_NEXT_INFO, @@ -516,6 +518,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::operators::FLOAT_CMP_CONST_INFO, crate::operators::FLOAT_EQUALITY_WITHOUT_ABS_INFO, crate::operators::IDENTITY_OP_INFO, + crate::operators::IMPOSSIBLE_COMPARISONS_INFO, crate::operators::INEFFECTIVE_BIT_MASK_INFO, crate::operators::INTEGER_DIVISION_INFO, crate::operators::MISREFACTORED_ASSIGN_OP_INFO, @@ -524,6 +527,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::operators::NEEDLESS_BITWISE_BOOL_INFO, crate::operators::OP_REF_INFO, crate::operators::PTR_EQ_INFO, + crate::operators::REDUNDANT_COMPARISONS_INFO, crate::operators::SELF_ASSIGNMENT_INFO, crate::operators::VERBOSE_BIT_MASK_INFO, crate::option_env_unwrap::OPTION_ENV_UNWRAP_INFO, diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 9900dbdee6be1..d3311792cfa8b 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -1,6 +1,4 @@ -use clippy_utils::diagnostics::{ - span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, -}; +use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::ty::{implements_trait, implements_trait_with_env, is_copy}; use clippy_utils::{is_lint_allowed, match_def_path, paths}; use if_chain::if_chain; @@ -8,15 +6,14 @@ use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor}; use rustc_hir::{ - self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, - UnsafeSource, Unsafety, + self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ - self, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, - ToPredicate, TraitPredicate, Ty, TyCtxt, + self, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, ToPredicate, TraitPredicate, Ty, + TyCtxt, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::def_id::LocalDefId; @@ -207,10 +204,13 @@ declare_lint_pass!(Derive => [ impl<'tcx> LateLintPass<'tcx> for Derive { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), .. }) = item.kind { + if let ItemKind::Impl(Impl { + of_trait: Some(ref trait_ref), + .. + }) = item.kind + { let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); - let is_automatically_derived = - cx.tcx.has_attr(item.owner_id, sym::automatically_derived); + let is_automatically_derived = cx.tcx.has_attr(item.owner_id, sym::automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived); @@ -327,12 +327,7 @@ fn check_ord_partial_ord<'tcx>( } /// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint. -fn check_copy_clone<'tcx>( - cx: &LateContext<'tcx>, - item: &Item<'_>, - trait_ref: &hir::TraitRef<'_>, - ty: Ty<'tcx>, -) { +fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) { let clone_id = match cx.tcx.lang_items().clone_trait() { Some(id) if trait_ref.trait_def_id() == Some(id) => id, _ => return, @@ -350,9 +345,10 @@ fn check_copy_clone<'tcx>( if !is_copy(cx, ty) { if ty_subs.non_erasable_generics().next().is_some() { let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(©_id).map_or(false, |impls| { - impls - .iter() - .any(|&id| matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did())) + impls.iter().any(|&id| { + matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _) + if ty_adt.did() == adt.did()) + }) }); if !has_copy_impl { return; @@ -431,14 +427,7 @@ struct UnsafeVisitor<'a, 'tcx> { impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { type NestedFilter = nested_filter::All; - fn visit_fn( - &mut self, - kind: FnKind<'tcx>, - decl: &'tcx FnDecl<'_>, - body_id: BodyId, - _: Span, - id: LocalDefId, - ) { + fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: LocalDefId) { if self.has_unsafe { return; } @@ -474,12 +463,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> { } /// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint. -fn check_partial_eq_without_eq<'tcx>( - cx: &LateContext<'tcx>, - span: Span, - trait_ref: &hir::TraitRef<'_>, - ty: Ty<'tcx>, -) { +fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) { if_chain! { if let ty::Adt(adt, args) = ty.kind(); if cx.tcx.visibility(adt.did()).is_public(); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 2c4d93e33ba76..e29ab634c9790 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -716,10 +716,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) { let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false); - let emitter = EmitterWriter::new( - Box::new(io::sink()), - fallback_bundle, - ); + let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle); let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings(); let sess = ParseSess::with_span_handler(handler, sm); diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index ba7957b0decc2..38066503c0793 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -10,8 +10,8 @@ use rustc_hir::{BindingAnnotation, Expr, ExprKind, FnRetTy, Param, PatKind, QPat use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{ - self, Binder, ClosureArgs, ClosureKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, - GenericArgsRef, ImplPolarity, List, Region, RegionKind, Ty, TypeVisitableExt, TypeckResults, + self, Binder, ClosureArgs, ClosureKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, GenericArgsRef, + ImplPolarity, List, Region, RegionKind, Ty, TypeVisitableExt, TypeckResults, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::sym; diff --git a/clippy_lints/src/ignored_unit_patterns.rs b/clippy_lints/src/ignored_unit_patterns.rs new file mode 100644 index 0000000000000..c635120b88245 --- /dev/null +++ b/clippy_lints/src/ignored_unit_patterns.rs @@ -0,0 +1,52 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; +use hir::PatKind; +use rustc_errors::Applicability; +use rustc_hir as hir; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_session::{declare_lint_pass, declare_tool_lint}; + +declare_clippy_lint! { + /// ### What it does + /// Checks for usage of `_` in patterns of type `()`. + /// + /// ### Why is this bad? + /// Matching with `()` explicitly instead of `_` outlines + /// the fact that the pattern contains no data. Also it + /// would detect a type change that `_` would ignore. + /// + /// ### Example + /// ```rust + /// match std::fs::create_dir("tmp-work-dir") { + /// Ok(_) => println!("Working directory created"), + /// Err(s) => eprintln!("Could not create directory: {s}"), + /// } + /// ``` + /// Use instead: + /// ```rust + /// match std::fs::create_dir("tmp-work-dir") { + /// Ok(()) => println!("Working directory created"), + /// Err(s) => eprintln!("Could not create directory: {s}"), + /// } + /// ``` + #[clippy::version = "1.73.0"] + pub IGNORED_UNIT_PATTERNS, + pedantic, + "suggest replacing `_` by `()` in patterns where appropriate" +} +declare_lint_pass!(IgnoredUnitPatterns => [IGNORED_UNIT_PATTERNS]); + +impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns { + fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx hir::Pat<'tcx>) { + if matches!(pat.kind, PatKind::Wild) && cx.typeck_results().pat_ty(pat).is_unit() { + span_lint_and_sugg( + cx, + IGNORED_UNIT_PATTERNS, + pat.span, + "matching over `()` is more explicit", + "use `()` instead of `_`", + String::from("()"), + Applicability::MachineApplicable, + ); + } + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 9d6096ccb2ae8..358004cf460b1 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -147,6 +147,7 @@ mod future_not_send; mod if_let_mutex; mod if_not_else; mod if_then_some_else_none; +mod ignored_unit_patterns; mod implicit_hasher; mod implicit_return; mod implicit_saturating_add; @@ -1093,6 +1094,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: }) }); store.register_late_pass(|_| Box::new(redundant_locals::RedundantLocals)); + store.register_late_pass(|_| Box::new(ignored_unit_patterns::IgnoredUnitPatterns)); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index dd77c69ef88a7..cc19ac55e5e44 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -162,7 +162,9 @@ fn never_loop_expr<'tcx>( ExprKind::Binary(_, e1, e2) | ExprKind::Assign(e1, e2, _) | ExprKind::AssignOp(_, e1, e2) - | ExprKind::Index(e1, e2, _) => never_loop_expr_all(cx, &mut [e1, e2].iter().copied(), ignore_ids, main_loop_id), + | ExprKind::Index(e1, e2, _) => { + never_loop_expr_all(cx, &mut [e1, e2].iter().copied(), ignore_ids, main_loop_id) + }, ExprKind::Loop(b, _, _, _) => { // Break can come from the inner loop so remove them. absorb_break(never_loop_block(cx, b, ignore_ids, main_loop_id)) diff --git a/clippy_lints/src/manual_float_methods.rs b/clippy_lints/src/manual_float_methods.rs index f48a5d9d24564..88db7ae6aece0 100644 --- a/clippy_lints/src/manual_float_methods.rs +++ b/clippy_lints/src/manual_float_methods.rs @@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if !in_external_macro(cx.sess(), expr.span) && ( - matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst) + matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst) || cx.tcx.features().active(sym!(const_float_classify)) ) && let ExprKind::Binary(kind, lhs, rhs) = expr.kind && let ExprKind::Binary(lhs_kind, lhs_lhs, lhs_rhs) = lhs.kind diff --git a/clippy_lints/src/matches/redundant_guards.rs b/clippy_lints/src/matches/redundant_guards.rs index 6383326aa38df..29af4812351e3 100644 --- a/clippy_lints/src/matches/redundant_guards.rs +++ b/clippy_lints/src/matches/redundant_guards.rs @@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::path_to_local; use clippy_utils::source::snippet_with_applicability; use clippy_utils::visitors::{for_each_expr, is_local_used}; +use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Arm, BinOpKind, Expr, ExprKind, Guard, MatchSource, Node, Pat, PatKind}; @@ -160,6 +161,11 @@ fn emit_redundant_guards<'tcx>( } /// Checks if the given `Expr` can also be represented as a `Pat`. +/// +/// All literals generally also work as patterns, however float literals are special. +/// They are currently (as of 2023/08/08) still allowed in patterns, but that will become +/// an error in the future, and rustc already actively warns against this (see rust#41620), +/// so we don't consider those as usable within patterns for linting purposes. fn expr_can_be_pat(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { for_each_expr(expr, |expr| { if match expr.kind { @@ -177,8 +183,8 @@ fn expr_can_be_pat(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { ExprKind::AddrOf(..) | ExprKind::Array(..) | ExprKind::Tup(..) - | ExprKind::Struct(..) - | ExprKind::Lit(..) => true, + | ExprKind::Struct(..) => true, + ExprKind::Lit(lit) if !matches!(lit.node, LitKind::Float(..)) => true, _ => false, } { return ControlFlow::Continue(()); diff --git a/clippy_lints/src/methods/expect_used.rs b/clippy_lints/src/methods/expect_used.rs deleted file mode 100644 index 614610335a134..0000000000000 --- a/clippy_lints/src/methods/expect_used.rs +++ /dev/null @@ -1,44 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::is_type_diagnostic_item; -use clippy_utils::{is_in_cfg_test, is_in_test_function}; -use rustc_hir as hir; -use rustc_lint::LateContext; -use rustc_span::sym; - -use super::EXPECT_USED; - -/// lint use of `expect()` or `expect_err` for `Result` and `expect()` for `Option`. -pub(super) fn check( - cx: &LateContext<'_>, - expr: &hir::Expr<'_>, - recv: &hir::Expr<'_>, - is_err: bool, - allow_expect_in_tests: bool, -) { - let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs(); - - let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) && !is_err { - Some((EXPECT_USED, "an `Option`", "None", "")) - } else if is_type_diagnostic_item(cx, obj_ty, sym::Result) { - Some((EXPECT_USED, "a `Result`", if is_err { "Ok" } else { "Err" }, "an ")) - } else { - None - }; - - let method = if is_err { "expect_err" } else { "expect" }; - - if allow_expect_in_tests && (is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id)) { - return; - } - - if let Some((lint, kind, none_value, none_prefix)) = mess { - span_lint_and_help( - cx, - lint, - expr.span, - &format!("used `{method}()` on {kind} value"), - None, - &format!("if this value is {none_prefix}`{none_value}`, it will panic"), - ); - } -} diff --git a/clippy_lints/src/methods/filter_map_bool_then.rs b/clippy_lints/src/methods/filter_map_bool_then.rs new file mode 100644 index 0000000000000..fafc970977009 --- /dev/null +++ b/clippy_lints/src/methods/filter_map_bool_then.rs @@ -0,0 +1,53 @@ +use super::FILTER_MAP_BOOL_THEN; +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::paths::BOOL_THEN; +use clippy_utils::source::snippet_opt; +use clippy_utils::ty::is_copy; +use clippy_utils::{is_from_proc_macro, is_trait_method, match_def_path, peel_blocks}; +use rustc_errors::Applicability; +use rustc_hir::{Expr, ExprKind}; +use rustc_lint::{LateContext, LintContext}; +use rustc_middle::lint::in_external_macro; +use rustc_middle::ty::Binder; +use rustc_span::{sym, Span}; + +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &Expr<'_>, call_span: Span) { + if !in_external_macro(cx.sess(), expr.span) + && is_trait_method(cx, expr, sym::Iterator) + && let ExprKind::Closure(closure) = arg.kind + && let body = cx.tcx.hir().body(closure.body) + && let value = peel_blocks(body.value) + // Indexing should be fine as `filter_map` always has 1 input, we unfortunately need both + // `inputs` and `params` here as we need both the type and the span + && let param_ty = closure.fn_decl.inputs[0] + && let param = body.params[0] + // Issue #11309 + && let param_ty = cx.tcx.liberate_late_bound_regions( + closure.def_id.to_def_id(), + Binder::bind_with_vars( + cx.typeck_results().node_type(param_ty.hir_id), + cx.tcx.late_bound_vars(cx.tcx.hir().local_def_id_to_hir_id(closure.def_id)), + ), + ) + && is_copy(cx, param_ty) + && let ExprKind::MethodCall(_, recv, [then_arg], _) = value.kind + && let ExprKind::Closure(then_closure) = then_arg.kind + && let then_body = peel_blocks(cx.tcx.hir().body(then_closure.body).value) + && let Some(def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id) + && match_def_path(cx, def_id, &BOOL_THEN) + && !is_from_proc_macro(cx, expr) + && let Some(param_snippet) = snippet_opt(cx, param.span) + && let Some(filter) = snippet_opt(cx, recv.span) + && let Some(map) = snippet_opt(cx, then_body.span) + { + span_lint_and_sugg( + cx, + FILTER_MAP_BOOL_THEN, + call_span, + "usage of `bool::then` in `filter_map`", + "use `filter` then `map` instead", + format!("filter(|&{param_snippet}| {filter}).map(|{param_snippet}| {map})"), + Applicability::MachineApplicable, + ); + } +} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 28a8978973fed..42756b27d014d 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -17,10 +17,10 @@ mod collapsible_str_replace; mod drain_collect; mod err_expect; mod expect_fun_call; -mod expect_used; mod extend_with_drain; mod filetype_is_file; mod filter_map; +mod filter_map_bool_then; mod filter_map_identity; mod filter_map_next; mod filter_next; @@ -104,7 +104,7 @@ mod unnecessary_lazy_eval; mod unnecessary_literal_unwrap; mod unnecessary_sort_by; mod unnecessary_to_owned; -mod unwrap_used; +mod unwrap_expect_used; mod useless_asref; mod utils; mod vec_resize_to_zero; @@ -3476,6 +3476,37 @@ declare_clippy_lint! { "disallows `.skip(0)`" } +declare_clippy_lint! { + /// ### What it does + /// Checks for usage of `bool::then` in `Iterator::filter_map`. + /// + /// ### Why is this bad? + /// This can be written with `filter` then `map` instead, which would reduce nesting and + /// separates the filtering from the transformation phase. This comes with no cost to + /// performance and is just cleaner. + /// + /// ### Limitations + /// Does not lint `bool::then_some`, as it eagerly evaluates its arguments rather than lazily. + /// This can create differing behavior, so better safe than sorry. + /// + /// ### Example + /// ```rust + /// # fn really_expensive_fn(i: i32) -> i32 { i } + /// # let v = vec![]; + /// _ = v.into_iter().filter_map(|i| (i % 2 == 0).then(|| really_expensive_fn(i))); + /// ``` + /// Use instead: + /// ```rust + /// # fn really_expensive_fn(i: i32) -> i32 { i } + /// # let v = vec![]; + /// _ = v.into_iter().filter(|i| i % 2 == 0).map(|i| really_expensive_fn(i)); + /// ``` + #[clippy::version = "1.72.0"] + pub FILTER_MAP_BOOL_THEN, + style, + "checks for usage of `bool::then` in `Iterator::filter_map`" +} + declare_clippy_lint! { /// ### What it does /// Looks for calls to `RwLock::write` where the lock is only used for reading. @@ -3644,6 +3675,7 @@ impl_lint_pass!(Methods => [ FORMAT_COLLECT, STRING_LIT_CHARS_ANY, ITER_SKIP_ZERO, + FILTER_MAP_BOOL_THEN, READONLY_WRITE_LOCK ]); @@ -3848,6 +3880,13 @@ impl Methods { unnecessary_lazy_eval::check(cx, expr, recv, arg, "and"); } }, + ("any", [arg]) if let ExprKind::Closure(arg) = arg.kind + && let body = cx.tcx.hir().body(arg.body) + && let [param] = body.params + && let Some(("chars", recv, _, _, _)) = method_call(recv) => + { + string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), &self.msrv); + } ("arg", [arg]) => { suspicious_command_arg_space::check(cx, recv, arg, span); } @@ -3908,13 +3947,27 @@ impl Methods { match method_call(recv) { Some(("ok", recv, [], _, _)) => ok_expect::check(cx, expr, recv), Some(("err", recv, [], err_span, _)) => err_expect::check(cx, expr, recv, span, err_span, &self.msrv), - _ => expect_used::check(cx, expr, recv, false, self.allow_expect_in_tests), + _ => unwrap_expect_used::check( + cx, + expr, + recv, + false, + self.allow_expect_in_tests, + unwrap_expect_used::Variant::Expect, + ), } unnecessary_literal_unwrap::check(cx, expr, recv, name, args); }, ("expect_err", [_]) => { unnecessary_literal_unwrap::check(cx, expr, recv, name, args); - expect_used::check(cx, expr, recv, true, self.allow_expect_in_tests); + unwrap_expect_used::check( + cx, + expr, + recv, + true, + self.allow_expect_in_tests, + unwrap_expect_used::Variant::Expect, + ); }, ("extend", [arg]) => { string_extend_chars::check(cx, expr, recv, arg); @@ -3922,6 +3975,7 @@ impl Methods { }, ("filter_map", [arg]) => { unnecessary_filter_map::check(cx, expr, arg, name); + filter_map_bool_then::check(cx, expr, arg, call_span); filter_map_identity::check(cx, expr, arg, span); }, ("find_map", [arg]) => { @@ -3965,20 +4019,9 @@ impl Methods { unnecessary_join::check(cx, expr, recv, join_arg, span); } }, - ("skip", [arg]) => { - iter_skip_zero::check(cx, expr, arg); - - if let Some((name2, recv2, args2, _span2, _)) = method_call(recv) { - if let ("cloned", []) = (name2, args2) { - iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); - } - } - } ("last", []) => { - if let Some((name2, recv2, args2, _span2, _)) = method_call(recv) { - if let ("cloned", []) = (name2, args2) { - iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); - } + if let Some(("cloned", recv2, [], _span2, _)) = method_call(recv) { + iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); } }, ("lock", []) => { @@ -4026,13 +4069,6 @@ impl Methods { } } }, - ("any", [arg]) if let ExprKind::Closure(arg) = arg.kind - && let body = cx.tcx.hir().body(arg.body) - && let [param] = body.params - && let Some(("chars", recv, _, _, _)) = method_call(recv) => - { - string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), &self.msrv); - } ("nth", [n_arg]) => match method_call(recv) { Some(("bytes", recv2, [], _, _)) => bytes_nth::check(cx, expr, recv2, n_arg), Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, false), @@ -4086,6 +4122,13 @@ impl Methods { seek_to_start_instead_of_rewind::check(cx, expr, recv, arg, span); } }, + ("skip", [arg]) => { + iter_skip_zero::check(cx, expr, arg); + + if let Some(("cloned", recv2, [], _span2, _)) = method_call(recv) { + iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); + } + } ("sort", []) => { stable_sort_primitive::check(cx, expr, recv); }, @@ -4108,10 +4151,8 @@ impl Methods { }, ("step_by", [arg]) => iterator_step_by_zero::check(cx, expr, arg), ("take", [_arg]) => { - if let Some((name2, recv2, args2, _span2, _)) = method_call(recv) { - if let ("cloned", []) = (name2, args2) { - iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); - } + if let Some(("cloned", recv2, [], _span2, _)) = method_call(recv) { + iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); } }, ("take", []) => needless_option_take::check(cx, expr, recv), @@ -4146,11 +4187,25 @@ impl Methods { _ => {}, } unnecessary_literal_unwrap::check(cx, expr, recv, name, args); - unwrap_used::check(cx, expr, recv, false, self.allow_unwrap_in_tests); + unwrap_expect_used::check( + cx, + expr, + recv, + false, + self.allow_unwrap_in_tests, + unwrap_expect_used::Variant::Unwrap, + ); }, ("unwrap_err", []) => { unnecessary_literal_unwrap::check(cx, expr, recv, name, args); - unwrap_used::check(cx, expr, recv, true, self.allow_unwrap_in_tests); + unwrap_expect_used::check( + cx, + expr, + recv, + true, + self.allow_unwrap_in_tests, + unwrap_expect_used::Variant::Unwrap, + ); }, ("unwrap_or", [u_arg]) => { match method_call(recv) { @@ -4180,6 +4235,9 @@ impl Methods { } unnecessary_literal_unwrap::check(cx, expr, recv, name, args); }, + ("write", []) => { + readonly_write_lock::check(cx, expr, recv); + } ("zip", [arg]) => { if let ExprKind::MethodCall(name, iter_recv, [], _) = recv.kind && name.ident.name == sym::iter @@ -4187,9 +4245,6 @@ impl Methods { range_zip_with_len::check(cx, expr, iter_recv, arg); } }, - ("write", []) => { - readonly_write_lock::check(cx, expr, recv); - } _ => {}, } } diff --git a/clippy_lints/src/methods/unwrap_expect_used.rs b/clippy_lints/src/methods/unwrap_expect_used.rs new file mode 100644 index 0000000000000..7bd16b473ce40 --- /dev/null +++ b/clippy_lints/src/methods/unwrap_expect_used.rs @@ -0,0 +1,83 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::ty::{is_never_like, is_type_diagnostic_item}; +use clippy_utils::{is_in_cfg_test, is_in_test_function, is_lint_allowed}; +use rustc_hir::Expr; +use rustc_lint::{LateContext, Lint}; +use rustc_middle::ty; +use rustc_span::sym; + +use super::{EXPECT_USED, UNWRAP_USED}; + +#[derive(Clone, Copy, Eq, PartialEq)] +pub(super) enum Variant { + Unwrap, + Expect, +} + +impl Variant { + fn method_name(self, is_err: bool) -> &'static str { + match (self, is_err) { + (Variant::Unwrap, true) => "unwrap_err", + (Variant::Unwrap, false) => "unwrap", + (Variant::Expect, true) => "expect_err", + (Variant::Expect, false) => "expect", + } + } + + fn lint(self) -> &'static Lint { + match self { + Variant::Unwrap => UNWRAP_USED, + Variant::Expect => EXPECT_USED, + } + } +} + +/// Lint usage of `unwrap` or `unwrap_err` for `Result` and `unwrap()` for `Option` (and their +/// `expect` counterparts). +pub(super) fn check( + cx: &LateContext<'_>, + expr: &Expr<'_>, + recv: &Expr<'_>, + is_err: bool, + allow_unwrap_in_tests: bool, + variant: Variant, +) { + let ty = cx.typeck_results().expr_ty(recv).peel_refs(); + + let (kind, none_value, none_prefix) = if is_type_diagnostic_item(cx, ty, sym::Option) && !is_err { + ("an `Option`", "None", "") + } else if is_type_diagnostic_item(cx, ty, sym::Result) + && let ty::Adt(_, substs) = ty.kind() + && let Some(t_or_e_ty) = substs[usize::from(!is_err)].as_type() + { + if is_never_like(t_or_e_ty) { + return; + } + + ("a `Result`", if is_err { "Ok" } else { "Err" }, "an ") + } else { + return; + }; + + let method_suffix = if is_err { "_err" } else { "" }; + + if allow_unwrap_in_tests && (is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id)) { + return; + } + + span_lint_and_then( + cx, + variant.lint(), + expr.span, + &format!("used `{}()` on {kind} value", variant.method_name(is_err)), + |diag| { + diag.note(format!("if this value is {none_prefix}`{none_value}`, it will panic")); + + if variant == Variant::Unwrap && is_lint_allowed(cx, EXPECT_USED, expr.hir_id) { + diag.help(format!( + "consider using `expect{method_suffix}()` to provide a better panic message" + )); + } + }, + ); +} diff --git a/clippy_lints/src/methods/unwrap_used.rs b/clippy_lints/src/methods/unwrap_used.rs deleted file mode 100644 index 5e4c3daee6447..0000000000000 --- a/clippy_lints/src/methods/unwrap_used.rs +++ /dev/null @@ -1,53 +0,0 @@ -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::is_type_diagnostic_item; -use clippy_utils::{is_in_cfg_test, is_in_test_function, is_lint_allowed}; -use rustc_hir as hir; -use rustc_lint::LateContext; -use rustc_span::sym; - -use super::{EXPECT_USED, UNWRAP_USED}; - -/// lint use of `unwrap()` or `unwrap_err` for `Result` and `unwrap()` for `Option`. -pub(super) fn check( - cx: &LateContext<'_>, - expr: &hir::Expr<'_>, - recv: &hir::Expr<'_>, - is_err: bool, - allow_unwrap_in_tests: bool, -) { - let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs(); - - let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) && !is_err { - Some((UNWRAP_USED, "an `Option`", "None", "")) - } else if is_type_diagnostic_item(cx, obj_ty, sym::Result) { - Some((UNWRAP_USED, "a `Result`", if is_err { "Ok" } else { "Err" }, "an ")) - } else { - None - }; - - let method_suffix = if is_err { "_err" } else { "" }; - - if allow_unwrap_in_tests && (is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id)) { - return; - } - - if let Some((lint, kind, none_value, none_prefix)) = mess { - let help = if is_lint_allowed(cx, EXPECT_USED, expr.hir_id) { - format!( - "if you don't want to handle the `{none_value}` case gracefully, consider \ - using `expect{method_suffix}()` to provide a better panic message" - ) - } else { - format!("if this value is {none_prefix}`{none_value}`, it will panic") - }; - - span_lint_and_help( - cx, - lint, - expr.span, - &format!("used `unwrap{method_suffix}()` on {kind} value"), - None, - &help, - ); - } -} diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 4b20aecad4a19..e53e146ec5dbe 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -37,6 +37,11 @@ declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]); impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { + if e.span.from_expansion() { + // Issue #11268 + return; + } + match e.kind { ExprKind::Call(fn_expr, arguments) => { if let ExprKind::Path(ref path) = fn_expr.kind { diff --git a/clippy_lints/src/operators/const_comparisons.rs b/clippy_lints/src/operators/const_comparisons.rs new file mode 100644 index 0000000000000..abe8df1954348 --- /dev/null +++ b/clippy_lints/src/operators/const_comparisons.rs @@ -0,0 +1,207 @@ +#![allow(clippy::match_same_arms)] + +use std::cmp::Ordering; + +use clippy_utils::consts::{constant, Constant}; +use if_chain::if_chain; +use rustc_hir::{BinOpKind, Expr, ExprKind}; +use rustc_lint::LateContext; +use rustc_middle::ty::layout::HasTyCtxt; +use rustc_middle::ty::{Ty, TypeckResults}; +use rustc_span::source_map::{Span, Spanned}; + +use clippy_utils::diagnostics::span_lint_and_note; +use clippy_utils::source::snippet; +use clippy_utils::SpanlessEq; + +use super::{IMPOSSIBLE_COMPARISONS, REDUNDANT_COMPARISONS}; + +// Extract a comparison between a const and non-const +// Flip yoda conditionals, turnings expressions like `42 < x` into `x > 42` +fn comparison_to_const<'tcx>( + cx: &LateContext<'tcx>, + typeck: &TypeckResults<'tcx>, + expr: &'tcx Expr<'tcx>, +) -> Option<(CmpOp, &'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Constant<'tcx>, Ty<'tcx>)> { + if_chain! { + if let ExprKind::Binary(operator, left, right) = expr.kind; + if let Ok(cmp_op) = CmpOp::try_from(operator.node); + then { + match (constant(cx, typeck, left), constant(cx, typeck, right)) { + (Some(_), Some(_)) => None, + (_, Some(con)) => Some((cmp_op, left, right, con, typeck.expr_ty(right))), + (Some(con), _) => Some((cmp_op.reverse(), right, left, con, typeck.expr_ty(left))), + _ => None, + } + } else { + None + } + } +} + +pub(super) fn check<'tcx>( + cx: &LateContext<'tcx>, + and_op: Spanned, + left_cond: &'tcx Expr<'tcx>, + right_cond: &'tcx Expr<'tcx>, + span: Span, +) { + if_chain! { + // Ensure that the binary operator is && + if and_op.node == BinOpKind::And; + + // Check that both operands to '&&' are themselves a binary operation + // The `comparison_to_const` step also checks this, so this step is just an optimization + if let ExprKind::Binary(_, _, _) = left_cond.kind; + if let ExprKind::Binary(_, _, _) = right_cond.kind; + + let typeck = cx.typeck_results(); + + // Check that both operands to '&&' compare a non-literal to a literal + if let Some((left_cmp_op, left_expr, left_const_expr, left_const, left_type)) = + comparison_to_const(cx, typeck, left_cond); + if let Some((right_cmp_op, right_expr, right_const_expr, right_const, right_type)) = + comparison_to_const(cx, typeck, right_cond); + + if left_type == right_type; + + // Check that the same expression is compared in both comparisons + if SpanlessEq::new(cx).eq_expr(left_expr, right_expr); + + if !left_expr.can_have_side_effects(); + + // Compare the two constant expressions + if let Some(ordering) = Constant::partial_cmp(cx.tcx(), left_type, &left_const, &right_const); + + // Rule out the `x >= 42 && x <= 42` corner case immediately + // Mostly to simplify the implementation, but it is also covered by `clippy::double_comparisons` + if !matches!( + (&left_cmp_op, &right_cmp_op, ordering), + (CmpOp::Le | CmpOp::Ge, CmpOp::Le | CmpOp::Ge, Ordering::Equal) + ); + + then { + if left_cmp_op.direction() == right_cmp_op.direction() { + let lhs_str = snippet(cx, left_cond.span, ""); + let rhs_str = snippet(cx, right_cond.span, ""); + // We already know that either side of `&&` has no effect, + // but emit a different error message depending on which side it is + if left_side_is_useless(left_cmp_op, ordering) { + span_lint_and_note( + cx, + REDUNDANT_COMPARISONS, + span, + "left-hand side of `&&` operator has no effect", + Some(left_cond.span.until(right_cond.span)), + &format!("`if `{rhs_str}` evaluates to true, {lhs_str}` will always evaluate to true as well"), + ); + } else { + span_lint_and_note( + cx, + REDUNDANT_COMPARISONS, + span, + "right-hand side of `&&` operator has no effect", + Some(and_op.span.to(right_cond.span)), + &format!("`if `{lhs_str}` evaluates to true, {rhs_str}` will always evaluate to true as well"), + ); + } + // We could autofix this error but choose not to, + // because code triggering this lint probably not behaving correctly in the first place + } + else if !comparison_is_possible(left_cmp_op.direction(), ordering) { + let expr_str = snippet(cx, left_expr.span, ".."); + let lhs_str = snippet(cx, left_const_expr.span, ""); + let rhs_str = snippet(cx, right_const_expr.span, ""); + let note = match ordering { + Ordering::Less => format!("since `{lhs_str}` < `{rhs_str}`, the expression evaluates to false for any value of `{expr_str}`"), + Ordering::Equal => format!("`{expr_str}` cannot simultaneously be greater than and less than `{lhs_str}`"), + Ordering::Greater => format!("since `{lhs_str}` > `{rhs_str}`, the expression evaluates to false for any value of `{expr_str}`"), + }; + span_lint_and_note( + cx, + IMPOSSIBLE_COMPARISONS, + span, + "boolean expression will never evaluate to 'true'", + None, + ¬e, + ); + }; + } + } +} + +fn left_side_is_useless(left_cmp_op: CmpOp, ordering: Ordering) -> bool { + // Special-case for equal constants with an inclusive comparison + if ordering == Ordering::Equal { + match left_cmp_op { + CmpOp::Lt | CmpOp::Gt => false, + CmpOp::Le | CmpOp::Ge => true, + } + } else { + match (left_cmp_op.direction(), ordering) { + (CmpOpDirection::Lesser, Ordering::Less) => false, + (CmpOpDirection::Lesser, Ordering::Equal) => false, + (CmpOpDirection::Lesser, Ordering::Greater) => true, + (CmpOpDirection::Greater, Ordering::Less) => true, + (CmpOpDirection::Greater, Ordering::Equal) => false, + (CmpOpDirection::Greater, Ordering::Greater) => false, + } + } +} + +fn comparison_is_possible(left_cmp_direction: CmpOpDirection, ordering: Ordering) -> bool { + match (left_cmp_direction, ordering) { + (CmpOpDirection::Lesser, Ordering::Less | Ordering::Equal) => false, + (CmpOpDirection::Lesser, Ordering::Greater) => true, + (CmpOpDirection::Greater, Ordering::Greater | Ordering::Equal) => false, + (CmpOpDirection::Greater, Ordering::Less) => true, + } +} + +#[derive(PartialEq, Eq, Clone, Copy)] +enum CmpOpDirection { + Lesser, + Greater, +} + +#[derive(Clone, Copy)] +enum CmpOp { + Lt, + Le, + Ge, + Gt, +} + +impl CmpOp { + fn reverse(self) -> Self { + match self { + CmpOp::Lt => CmpOp::Gt, + CmpOp::Le => CmpOp::Ge, + CmpOp::Ge => CmpOp::Le, + CmpOp::Gt => CmpOp::Lt, + } + } + + fn direction(self) -> CmpOpDirection { + match self { + CmpOp::Lt => CmpOpDirection::Lesser, + CmpOp::Le => CmpOpDirection::Lesser, + CmpOp::Ge => CmpOpDirection::Greater, + CmpOp::Gt => CmpOpDirection::Greater, + } + } +} + +impl TryFrom for CmpOp { + type Error = (); + + fn try_from(bin_op: BinOpKind) -> Result { + match bin_op { + BinOpKind::Lt => Ok(CmpOp::Lt), + BinOpKind::Le => Ok(CmpOp::Le), + BinOpKind::Ge => Ok(CmpOp::Ge), + BinOpKind::Gt => Ok(CmpOp::Gt), + _ => Err(()), + } + } +} diff --git a/clippy_lints/src/operators/mod.rs b/clippy_lints/src/operators/mod.rs index 2cf15adda01a2..4635e1164cd31 100644 --- a/clippy_lints/src/operators/mod.rs +++ b/clippy_lints/src/operators/mod.rs @@ -2,6 +2,7 @@ mod absurd_extreme_comparisons; mod assign_op_pattern; mod bit_mask; mod cmp_owned; +mod const_comparisons; mod double_comparison; mod duration_subsec; mod eq_op; @@ -298,6 +299,45 @@ declare_clippy_lint! { "unnecessary double comparisons that can be simplified" } +declare_clippy_lint! { + /// ### What it does + /// Checks for double comparisons that can never succeed + /// + /// ### Why is this bad? + /// The whole expression can be replaced by `false`, + /// which is probably not the programmer's intention + /// + /// ### Example + /// ```rust + /// # let status_code = 200; + /// if status_code <= 400 && status_code > 500 {} + /// ``` + #[clippy::version = "1.71.0"] + pub IMPOSSIBLE_COMPARISONS, + correctness, + "double comparisons that will never evaluate to `true`" +} + +declare_clippy_lint! { + /// ### What it does + /// Checks for ineffective double comparisons against constants. + /// + /// ### Why is this bad? + /// Only one of the comparisons has any effect on the result, the programmer + /// probably intended to flip one of the comparison operators, or compare a + /// different value entirely. + /// + /// ### Example + /// ```rust + /// # let status_code = 200; + /// if status_code <= 400 && status_code < 500 {} + /// ``` + #[clippy::version = "1.71.0"] + pub REDUNDANT_COMPARISONS, + correctness, + "double comparisons where one of them can be removed" +} + declare_clippy_lint! { /// ### What it does /// Checks for calculation of subsecond microseconds or milliseconds @@ -742,6 +782,8 @@ impl_lint_pass!(Operators => [ INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK, DOUBLE_COMPARISONS, + IMPOSSIBLE_COMPARISONS, + REDUNDANT_COMPARISONS, DURATION_SUBSEC, EQ_OP, OP_REF, @@ -786,6 +828,7 @@ impl<'tcx> LateLintPass<'tcx> for Operators { bit_mask::check(cx, e, op.node, lhs, rhs); verbose_bit_mask::check(cx, e, op.node, lhs, rhs, self.verbose_bit_mask_threshold); double_comparison::check(cx, op.node, lhs, rhs, e.span); + const_comparisons::check(cx, op, lhs, rhs, e.span); duration_subsec::check(cx, e, op.node, lhs, rhs); float_equality_without_abs::check(cx, e, op.node, lhs, rhs); integer_division::check(cx, e, op.node, lhs, rhs); diff --git a/clippy_lints/src/option_if_let_else.rs b/clippy_lints/src/option_if_let_else.rs index 40da002f4ff0d..a7a7f4fd8fa2c 100644 --- a/clippy_lints/src/option_if_let_else.rs +++ b/clippy_lints/src/option_if_let_else.rs @@ -155,7 +155,7 @@ fn try_get_option_occurrence<'tcx>( }); if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(local_id), .. })) = e.kind { match some_captures.get(local_id) - .or_else(|| (method_sugg == "map_or_else").then_some(()).and_then(|_| none_captures.get(local_id))) + .or_else(|| (method_sugg == "map_or_else").then_some(()).and_then(|()| none_captures.get(local_id))) { Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return None, Some(CaptureKind::Ref(Mutability::Not)) if as_mut => return None, diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index f5502cffb6693..734ca2914f5d4 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -1,11 +1,13 @@ use crate::manual_let_else::{MatchLintBehaviour, MANUAL_LET_ELSE}; +use crate::question_mark_used::QUESTION_MARK_USED; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::msrvs::Msrv; use clippy_utils::source::snippet_with_applicability; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{ - eq_expr_value, get_parent_node, higher, in_constant, is_else_clause, is_path_lang_item, is_res_lang_ctor, - pat_and_expr_can_be_question_mark, path_to_local, path_to_local_id, peel_blocks, peel_blocks_with_stmt, + eq_expr_value, get_parent_node, higher, in_constant, is_else_clause, is_lint_allowed, is_path_lang_item, + is_res_lang_ctor, pat_and_expr_can_be_question_mark, path_to_local, path_to_local_id, peel_blocks, + peel_blocks_with_stmt, }; use if_chain::if_chain; use rustc_errors::Applicability; @@ -299,13 +301,17 @@ fn is_try_block(cx: &LateContext<'_>, bl: &rustc_hir::Block<'_>) -> bool { impl<'tcx> LateLintPass<'tcx> for QuestionMark { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { + if !is_lint_allowed(cx, QUESTION_MARK_USED, stmt.hir_id) { + return; + } + if !in_constant(cx, stmt.hir_id) { check_let_some_else_return_none(cx, stmt); } self.check_manual_let_else(cx, stmt); } fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if !in_constant(cx, expr.hir_id) { + if !in_constant(cx, expr.hir_id) && is_lint_allowed(cx, QUESTION_MARK_USED, expr.hir_id) { self.check_is_none_or_err_and_early_return(cx, expr); self.check_if_let_some_or_err_and_early_return(cx, expr); } diff --git a/clippy_lints/src/redundant_locals.rs b/clippy_lints/src/redundant_locals.rs index 896bd79b20bf4..0c89c7ee47d36 100644 --- a/clippy_lints/src/redundant_locals.rs +++ b/clippy_lints/src/redundant_locals.rs @@ -1,6 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::is_from_proc_macro; use clippy_utils::ty::needs_ordered_drop; +use rustc_ast::Mutability; use rustc_hir::def::Res; use rustc_hir::{ BindingAnnotation, ByRef, Expr, ExprKind, HirId, Local, Node, Pat, PatKind, QPath, @@ -9,6 +10,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::{in_external_macro, is_from_async_await}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::Ident; +use rustc_span::DesugaringKind; declare_clippy_lint! { /// ### What it does @@ -47,6 +49,7 @@ declare_lint_pass!(RedundantLocals => [REDUNDANT_LOCALS]); impl<'tcx> LateLintPass<'tcx> for RedundantLocals { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { if_chain! { + if !local.span.is_desugaring(DesugaringKind::Async); // the pattern is a single by-value binding if let PatKind::Binding(BindingAnnotation(ByRef::No, mutability), _, ident, None) = local.pat.kind; // the binding is not type-ascribed @@ -62,6 +65,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals { if let Node::Pat(binding_pat) = cx.tcx.hir().get(binding_id); // the previous binding has the same mutability if find_binding(binding_pat, ident).unwrap().1 == mutability; + // the local does not change the effect of assignments to the binding. see #11290 + if !affects_assignments(cx, mutability, binding_id, local.hir_id); // the local does not affect the code's drop behavior if !affects_drop_behavior(cx, binding_id, local.hir_id, expr); // the local is user-controlled @@ -97,6 +102,14 @@ fn find_binding(pat: &Pat<'_>, name: Ident) -> Option { ret } +/// Check if a rebinding of a local changes the effect of assignments to the binding. +fn affects_assignments(cx: &LateContext<'_>, mutability: Mutability, bind: HirId, rebind: HirId) -> bool { + let hir = cx.tcx.hir(); + + // the binding is mutable and the rebinding is in a different scope than the original binding + mutability == Mutability::Mut && hir.get_enclosing_scope(bind) != hir.get_enclosing_scope(rebind) +} + /// Check if a rebinding of a local affects the code's drop behavior. fn affects_drop_behavior<'tcx>( cx: &LateContext<'tcx>, diff --git a/clippy_lints/src/redundant_type_annotations.rs b/clippy_lints/src/redundant_type_annotations.rs index 8e9234bba3c86..3e963d7989280 100644 --- a/clippy_lints/src/redundant_type_annotations.rs +++ b/clippy_lints/src/redundant_type_annotations.rs @@ -1,6 +1,8 @@ use clippy_utils::diagnostics::span_lint; +use clippy_utils::is_lint_allowed; use rustc_ast::LitKind; use rustc_hir as hir; +use rustc_hir::def::DefKind; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -45,8 +47,8 @@ fn is_same_type<'tcx>(cx: &LateContext<'tcx>, ty_resolved_path: hir::def::Res, f return primty.name() == func_return_type_sym; } - // type annotation is any other non generic type - if let hir::def::Res::Def(_, defid) = ty_resolved_path + // type annotation is a non generic type + if let hir::def::Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum, defid) = ty_resolved_path && let Some(annotation_ty) = cx.tcx.type_of(defid).no_bound_vars() { return annotation_ty == func_return_type; @@ -130,8 +132,9 @@ fn extract_primty(ty_kind: &hir::TyKind<'_>) -> Option { impl LateLintPass<'_> for RedundantTypeAnnotations { fn check_local<'tcx>(&mut self, cx: &LateContext<'tcx>, local: &'tcx rustc_hir::Local<'tcx>) { - // type annotation part - if !local.span.from_expansion() + if !is_lint_allowed(cx, REDUNDANT_TYPE_ANNOTATIONS, local.hir_id) + // type annotation part + && !local.span.from_expansion() && let Some(ty) = &local.ty // initialization part diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 54a33eb2986d3..c9ab622ad25d3 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -20,18 +20,27 @@ declare_clippy_lint! { /// These structures are non-idiomatic and less efficient than simply using /// `vec![0; len]`. /// + /// Specifically, for `vec![0; len]`, the compiler can use a specialized type of allocation + /// that also zero-initializes the allocated memory in the same call + /// (see: [alloc_zeroed](https://doc.rust-lang.org/stable/std/alloc/trait.GlobalAlloc.html#method.alloc_zeroed)). + /// + /// Writing `Vec::new()` followed by `vec.resize(len, 0)` is suboptimal because, + /// while it does do the same number of allocations, + /// it involves two operations for allocating and initializing. + /// The `resize` call first allocates memory (since `Vec::new()` did not), and only *then* zero-initializes it. + /// /// ### Example /// ```rust /// # use core::iter::repeat; /// # let len = 4; - /// let mut vec1 = Vec::with_capacity(len); + /// let mut vec1 = Vec::new(); /// vec1.resize(len, 0); /// - /// let mut vec1 = Vec::with_capacity(len); - /// vec1.resize(vec1.capacity(), 0); - /// /// let mut vec2 = Vec::with_capacity(len); - /// vec2.extend(repeat(0).take(len)); + /// vec2.resize(len, 0); + /// + /// let mut vec3 = Vec::with_capacity(len); + /// vec3.extend(repeat(0).take(len)); /// ``` /// /// Use instead: @@ -39,6 +48,7 @@ declare_clippy_lint! { /// # let len = 4; /// let mut vec1 = vec![0; len]; /// let mut vec2 = vec![0; len]; + /// let mut vec3 = vec![0; len]; /// ``` #[clippy::version = "1.32.0"] pub SLOW_VECTOR_INITIALIZATION, diff --git a/clippy_lints/src/suspicious_xor_used_as_pow.rs b/clippy_lints/src/suspicious_xor_used_as_pow.rs index 6fa49afe0ecd7..8e156b8829b9c 100644 --- a/clippy_lints/src/suspicious_xor_used_as_pow.rs +++ b/clippy_lints/src/suspicious_xor_used_as_pow.rs @@ -1,5 +1,7 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::numeric_literal::NumericLiteral; -use clippy_utils::source::snippet_with_context; +use clippy_utils::source::snippet; +use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -28,27 +30,29 @@ declare_lint_pass!(ConfusingXorAndPow => [SUSPICIOUS_XOR_USED_AS_POW]); impl LateLintPass<'_> for ConfusingXorAndPow { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - if !in_external_macro(cx.sess(), expr.span) && - let ExprKind::Binary(op, left, right) = &expr.kind && - op.node == BinOpKind::BitXor && - left.span.ctxt() == right.span.ctxt() && - let ExprKind::Lit(lit_left) = &left.kind && - let ExprKind::Lit(lit_right) = &right.kind && - let snip_left = snippet_with_context(cx, lit_left.span, lit_left.span.ctxt(), "..", &mut Applicability::MaybeIncorrect) && - let snip_right = snippet_with_context(cx, lit_right.span, lit_right.span.ctxt(), "..", &mut Applicability::MaybeIncorrect) && - let Some(left_val) = NumericLiteral::from_lit_kind(&snip_left.0, &lit_left.node) && - let Some(right_val) = NumericLiteral::from_lit_kind(&snip_right.0, &lit_right.node) && - left_val.is_decimal() && - right_val.is_decimal() { - clippy_utils::diagnostics::span_lint_and_sugg( - cx, - SUSPICIOUS_XOR_USED_AS_POW, - expr.span, - "`^` is not the exponentiation operator", - "did you mean to write", - format!("{}.pow({})", left_val.format(), right_val.format()), - Applicability::MaybeIncorrect, - ); + if !in_external_macro(cx.sess(), expr.span) + && let ExprKind::Binary(op, left, right) = &expr.kind + && op.node == BinOpKind::BitXor + && left.span.ctxt() == right.span.ctxt() + && 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()) + { + span_lint_and_sugg( + cx, + SUSPICIOUS_XOR_USED_AS_POW, + expr.span, + "`^` is not the exponentiation operator", + "did you mean to write", + format!( + "{}.pow({})", + lit_left.node, + lit_right.node + ), + Applicability::MaybeIncorrect, + ); } } } diff --git a/clippy_lints/src/utils/internal_lints/invalid_paths.rs b/clippy_lints/src/utils/internal_lints/invalid_paths.rs index e4906944c8d0a..4ed985f54d0e2 100644 --- a/clippy_lints/src/utils/internal_lints/invalid_paths.rs +++ b/clippy_lints/src/utils/internal_lints/invalid_paths.rs @@ -34,7 +34,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidPaths { let mod_name = &cx.tcx.item_name(local_def_id.to_def_id()); if_chain! { if mod_name.as_str() == "paths"; - if let hir::ItemKind::Const(ty, body_id) = item.kind; + if let hir::ItemKind::Const(ty, _, body_id) = item.kind; let ty = hir_ty_to_ty(cx.tcx, ty); if let ty::Array(el_ty, _) = &ty.kind(); if let ty::Ref(_, el_ty, _) = &el_ty.kind(); diff --git a/clippy_utils/src/ast_utils.rs b/clippy_utils/src/ast_utils.rs index 2d0d6f559ad67..140cfa2194fcb 100644 --- a/clippy_utils/src/ast_utils.rs +++ b/clippy_utils/src/ast_utils.rs @@ -178,7 +178,9 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Yield(l), Yield(r)) | (Ret(l), Ret(r)) => eq_expr_opt(l, r), (Break(ll, le), Break(rl, re)) => eq_label(ll, rl) && eq_expr_opt(le, re), (Continue(ll), Continue(rl)) => eq_label(ll, rl), - (Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2, _), Index(r1, r2, _)) => eq_expr(l1, r1) && eq_expr(l2, r2), + (Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2, _), Index(r1, r2, _)) => { + eq_expr(l1, r1) && eq_expr(l2, r2) + }, (AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv), (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp), (Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, eq_arm), diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index d38e3f1ae76bd..adeb673b6b9dc 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -329,7 +329,7 @@ pub struct ConstEvalLateContext<'a, 'tcx> { } impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { - fn new(lcx: &'a LateContext<'tcx>, typeck_results: &'a ty::TypeckResults<'tcx>) -> Self { + pub fn new(lcx: &'a LateContext<'tcx>, typeck_results: &'a ty::TypeckResults<'tcx>) -> Self { Self { lcx, typeck_results, diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 8d96d3cfe50b4..914ea85ac2809 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -163,3 +163,5 @@ pub const OPTION_EXPECT: [&str; 4] = ["core", "option", "Option", "expect"]; pub const FORMATTER: [&str; 3] = ["core", "fmt", "Formatter"]; pub const DEBUG_STRUCT: [&str; 4] = ["core", "fmt", "builders", "DebugStruct"]; pub const ORD_CMP: [&str; 4] = ["core", "cmp", "Ord", "cmp"]; +#[expect(clippy::invalid_paths)] // not sure why it thinks this, it works so +pub const BOOL_THEN: [&str; 4] = ["core", "bool", "", "then"]; diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index f0a777c5b895d..4c695cb9b6e1f 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -14,7 +14,7 @@ use rustc_middle::mir::{ Body, CastKind, NonDivergingIntrinsic, NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, }; -use rustc_middle::traits::{ImplSource, ObligationCause, BuiltinImplSource}; +use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause}; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::{self, GenericArgKind, TraitRef, Ty, TyCtxt}; use rustc_semver::RustcVersion; @@ -425,5 +425,5 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx> ocx.select_all_or_error().is_empty() } - !ty.needs_drop(tcx, ConstCx::new(tcx, body).param_env) + !ty.needs_drop(tcx, ConstCx::new(tcx, body).param_env) } diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs index a43a81bc63a13..ee5a49a207331 100644 --- a/clippy_utils/src/sugg.rs +++ b/clippy_utils/src/sugg.rs @@ -1010,7 +1010,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { projections_handled = true; }, // note: unable to trigger `Subslice` kind in tests - ProjectionKind::Subslice => (), + ProjectionKind::Subslice | // Doesn't have surface syntax. Only occurs in patterns. ProjectionKind::OpaqueCast => (), ProjectionKind::Deref => { diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index 7176648053562..a05f682aa8cda 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -1093,6 +1093,11 @@ fn assert_generic_args_match<'tcx>(tcx: TyCtxt<'tcx>, did: DefId, args: &[Generi } } +/// Returns whether `ty` is never-like; i.e., `!` (never) or an enum with zero variants. +pub fn is_never_like(ty: Ty<'_>) -> bool { + ty.is_never() || (ty.is_enum() && ty.ty_adt_def().is_some_and(|def| def.variants().is_empty())) +} + /// Makes the projection type for the named associated type in the given impl or trait impl. /// /// This function is for associated types which are "known" to exist, and as such, will only return diff --git a/rust-toolchain b/rust-toolchain index 833608faff06f..8b3f819f0cde1 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-07-28" +channel = "nightly-2023-08-10" components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] diff --git a/tests/ui-internal/custom_ice_message.stderr b/tests/ui-internal/custom_ice_message.stderr index 31df0ebd9fd6b..d8b158816c9f8 100644 --- a/tests/ui-internal/custom_ice_message.stderr +++ b/tests/ui-internal/custom_ice_message.stderr @@ -1,4 +1,5 @@ -thread '' panicked at 'Would you like some help with that?', clippy_lints/src/utils/internal_lints/produce_ice.rs +thread '' panicked at clippy_lints/src/utils/internal_lints/produce_ice.rs: +Would you like some help with that? note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace error: the compiler unexpectedly panicked. this is a bug. diff --git a/tests/ui-toml/expect_used/expect_used.stderr b/tests/ui-toml/expect_used/expect_used.stderr index 9eef0e1bfaa12..815d009350f3c 100644 --- a/tests/ui-toml/expect_used/expect_used.stderr +++ b/tests/ui-toml/expect_used/expect_used.stderr @@ -4,7 +4,7 @@ error: used `expect()` on an `Option` value LL | let _ = opt.expect(""); | ^^^^^^^^^^^^^^ | - = help: if this value is `None`, it will panic + = note: if this value is `None`, it will panic = note: `-D clippy::expect-used` implied by `-D warnings` error: used `expect()` on a `Result` value @@ -13,7 +13,7 @@ error: used `expect()` on a `Result` value LL | let _ = res.expect(""); | ^^^^^^^^^^^^^^ | - = help: if this value is an `Err`, it will panic + = note: if this value is an `Err`, it will panic error: aborting due to 2 previous errors diff --git a/tests/ui-toml/unwrap_used/unwrap_used.stderr b/tests/ui-toml/unwrap_used/unwrap_used.stderr index 4c9bdfa9dba73..10219beaf9719 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -12,7 +12,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message = note: `-D clippy::unwrap-used` implied by `-D warnings` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise @@ -27,7 +28,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:40:17 @@ -41,7 +43,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:41:17 @@ -55,7 +58,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:42:17 @@ -69,7 +73,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:43:17 @@ -83,7 +88,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:47:21 @@ -97,7 +103,8 @@ error: used `unwrap()` on an `Option` value LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:52:9 @@ -111,7 +118,8 @@ error: used `unwrap()` on an `Option` value LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:53:9 @@ -125,7 +133,8 @@ error: used `unwrap()` on an `Option` value LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:54:9 @@ -139,7 +148,8 @@ error: used `unwrap()` on an `Option` value LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:55:9 @@ -153,7 +163,8 @@ error: used `unwrap()` on an `Option` value LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:67:17 @@ -167,7 +178,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:68:17 @@ -181,7 +193,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:75:13 diff --git a/tests/ui/const_comparisons.rs b/tests/ui/const_comparisons.rs new file mode 100644 index 0000000000000..8e265c9141c16 --- /dev/null +++ b/tests/ui/const_comparisons.rs @@ -0,0 +1,93 @@ +#![allow(unused)] +#![warn(clippy::impossible_comparisons)] +#![warn(clippy::redundant_comparisons)] +#![allow(clippy::no_effect)] +#![allow(clippy::short_circuit_statement)] +#![allow(clippy::manual_range_contains)] + +const STATUS_BAD_REQUEST: u16 = 400; +const STATUS_SERVER_ERROR: u16 = 500; + +struct Status { + code: u16, +} + +impl PartialEq for Status { + fn eq(&self, other: &u16) -> bool { + self.code == *other + } +} + +impl PartialOrd for Status { + fn partial_cmp(&self, other: &u16) -> Option { + self.code.partial_cmp(other) + } +} + +impl PartialEq for u16 { + fn eq(&self, other: &Status) -> bool { + *self == other.code + } +} + +impl PartialOrd for u16 { + fn partial_cmp(&self, other: &Status) -> Option { + self.partial_cmp(&other.code) + } +} + +fn main() { + let status_code = 500; // Value doesn't matter for the lint + let status = Status { code: status_code }; + + status_code >= 400 && status_code < 500; // Correct + status_code <= 400 && status_code > 500; + status_code > 500 && status_code < 400; + status_code < 500 && status_code > 500; + + // More complex expressions + status_code < { 400 } && status_code > { 500 }; + status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; + status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; + status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; + + // Comparing two different types, via the `impl PartialOrd for Status` + status < { 400 } && status > { 500 }; + status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; + status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; + status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; + + // Yoda conditions + 500 <= status_code && 600 > status_code; // Correct + 500 <= status_code && status_code <= 600; // Correct + 500 >= status_code && 600 < status_code; // Incorrect + 500 >= status_code && status_code > 600; // Incorrect + + // Yoda conditions, comparing two different types + 500 <= status && 600 > status; // Correct + 500 <= status && status <= 600; // Correct + 500 >= status && 600 < status; // Incorrect + 500 >= status && status > 600; // Incorrect + + // Expressions where one of the sides has no effect + status_code < 200 && status_code <= 299; + status_code > 200 && status_code >= 299; + + status_code >= 500 && status_code > 500; // Useless left + status_code > 500 && status_code >= 500; // Useless right + status_code <= 500 && status_code < 500; // Useless left + status_code < 500 && status_code <= 500; // Useless right + + // Other types + let name = "Steve"; + name < "Jennifer" && name > "Shannon"; + + let numbers = [1, 2]; + numbers < [3, 4] && numbers > [5, 6]; + + let letter = 'a'; + letter < 'b' && letter > 'c'; + + let area = 42.0; + area < std::f32::consts::E && area > std::f32::consts::PI; +} diff --git a/tests/ui/const_comparisons.stderr b/tests/ui/const_comparisons.stderr new file mode 100644 index 0000000000000..90e6db647621a --- /dev/null +++ b/tests/ui/const_comparisons.stderr @@ -0,0 +1,228 @@ +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:44:5 + | +LL | status_code <= 400 && status_code > 500; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `400` < `500`, the expression evaluates to false for any value of `status_code` + = note: `-D clippy::impossible-comparisons` implied by `-D warnings` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:45:5 + | +LL | status_code > 500 && status_code < 400; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `500` > `400`, the expression evaluates to false for any value of `status_code` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:46:5 + | +LL | status_code < 500 && status_code > 500; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `status_code` cannot simultaneously be greater than and less than `500` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:49:5 + | +LL | status_code < { 400 } && status_code > { 500 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status_code` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:50:5 + | +LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:51:5 + | +LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:52:5 + | +LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `status_code` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:55:5 + | +LL | status < { 400 } && status > { 500 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:56:5 + | +LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:57:5 + | +LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:58:5 + | +LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `status` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:63:5 + | +LL | 500 >= status_code && 600 < status_code; // Incorrect + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:64:5 + | +LL | 500 >= status_code && status_code > 600; // Incorrect + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:69:5 + | +LL | 500 >= status && 600 < status; // Incorrect + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `500` < `600`, the expression evaluates to false for any value of `status` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:70:5 + | +LL | 500 >= status && status > 600; // Incorrect + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `500` < `600`, the expression evaluates to false for any value of `status` + +error: right-hand side of `&&` operator has no effect + --> $DIR/const_comparisons.rs:73:5 + | +LL | status_code < 200 && status_code <= 299; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: `if `status_code < 200` evaluates to true, status_code <= 299` will always evaluate to true as well + --> $DIR/const_comparisons.rs:73:23 + | +LL | status_code < 200 && status_code <= 299; + | ^^^^^^^^^^^^^^^^^^^^^ + = note: `-D clippy::redundant-comparisons` implied by `-D warnings` + +error: left-hand side of `&&` operator has no effect + --> $DIR/const_comparisons.rs:74:5 + | +LL | status_code > 200 && status_code >= 299; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: `if `status_code >= 299` evaluates to true, status_code > 200` will always evaluate to true as well + --> $DIR/const_comparisons.rs:74:5 + | +LL | status_code > 200 && status_code >= 299; + | ^^^^^^^^^^^^^^^^^^^^^ + +error: left-hand side of `&&` operator has no effect + --> $DIR/const_comparisons.rs:76:5 + | +LL | status_code >= 500 && status_code > 500; // Useless left + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well + --> $DIR/const_comparisons.rs:76:5 + | +LL | status_code >= 500 && status_code > 500; // Useless left + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: right-hand side of `&&` operator has no effect + --> $DIR/const_comparisons.rs:77:5 + | +LL | status_code > 500 && status_code >= 500; // Useless right + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well + --> $DIR/const_comparisons.rs:77:23 + | +LL | status_code > 500 && status_code >= 500; // Useless right + | ^^^^^^^^^^^^^^^^^^^^^ + +error: left-hand side of `&&` operator has no effect + --> $DIR/const_comparisons.rs:78:5 + | +LL | status_code <= 500 && status_code < 500; // Useless left + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well + --> $DIR/const_comparisons.rs:78:5 + | +LL | status_code <= 500 && status_code < 500; // Useless left + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: right-hand side of `&&` operator has no effect + --> $DIR/const_comparisons.rs:79:5 + | +LL | status_code < 500 && status_code <= 500; // Useless right + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well + --> $DIR/const_comparisons.rs:79:23 + | +LL | status_code < 500 && status_code <= 500; // Useless right + | ^^^^^^^^^^^^^^^^^^^^^ + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:83:5 + | +LL | name < "Jennifer" && name > "Shannon"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any value of `name` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:86:5 + | +LL | numbers < [3, 4] && numbers > [5, 6]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value of `numbers` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:89:5 + | +LL | letter < 'b' && letter > 'c'; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `'b'` < `'c'`, the expression evaluates to false for any value of `letter` + +error: boolean expression will never evaluate to 'true' + --> $DIR/const_comparisons.rs:92:5 + | +LL | area < std::f32::consts::E && area > std::f32::consts::PI; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: since `std::f32::consts::E` < `std::f32::consts::PI`, the expression evaluates to false for any value of `area` + +error: aborting due to 25 previous errors + diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr index be340340d4773..f787fa973a32e 100644 --- a/tests/ui/expect.stderr +++ b/tests/ui/expect.stderr @@ -4,7 +4,7 @@ error: used `expect()` on an `Option` value LL | let _ = opt.expect(""); | ^^^^^^^^^^^^^^ | - = help: if this value is `None`, it will panic + = note: if this value is `None`, it will panic = note: `-D clippy::expect-used` implied by `-D warnings` error: used `expect()` on a `Result` value @@ -13,7 +13,7 @@ error: used `expect()` on a `Result` value LL | let _ = res.expect(""); | ^^^^^^^^^^^^^^ | - = help: if this value is an `Err`, it will panic + = note: if this value is an `Err`, it will panic error: used `expect_err()` on a `Result` value --> $DIR/expect.rs:12:13 @@ -21,7 +21,7 @@ error: used `expect_err()` on a `Result` value LL | let _ = res.expect_err(""); | ^^^^^^^^^^^^^^^^^^ | - = help: if this value is an `Ok`, it will panic + = note: if this value is an `Ok`, it will panic error: aborting due to 3 previous errors diff --git a/tests/ui/filter_map_bool_then.fixed b/tests/ui/filter_map_bool_then.fixed new file mode 100644 index 0000000000000..e5c9f783f6b32 --- /dev/null +++ b/tests/ui/filter_map_bool_then.fixed @@ -0,0 +1,58 @@ +//@run-rustfix +//@aux-build:proc_macros.rs:proc-macro +#![allow( + clippy::clone_on_copy, + clippy::map_identity, + clippy::unnecessary_lazy_evaluations, + clippy::unnecessary_filter_map, + unused +)] +#![warn(clippy::filter_map_bool_then)] + +#[macro_use] +extern crate proc_macros; + +#[derive(Clone, PartialEq)] +struct NonCopy; + +fn main() { + let v = vec![1, 2, 3, 4, 5, 6]; + v.clone().iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1); + v.clone().into_iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1); + v.clone() + .into_iter() + .filter(|&i| (i % 2 == 0)).map(|i| i + 1); + v.clone() + .into_iter() + .filter(|&i| i != 1000) + .filter(|&i| (i % 2 == 0)).map(|i| i + 1); + v.iter() + .copied() + .filter(|&i| i != 1000) + .filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1); + // Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`, + // and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`), + // we can lint this and still get the same input type. + // See: + let v = vec![NonCopy, NonCopy]; + v.clone().iter().filter(|&i| (i == &NonCopy)).map(|i| i); + // Do not lint + let v = vec![NonCopy, NonCopy]; + v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i)); + // `&mut` is `!Copy`. + let v = vec![NonCopy, NonCopy]; + v.clone().iter_mut().filter_map(|i| (i == &mut NonCopy).then(|| i)); + external! { + let v = vec![1, 2, 3, 4, 5, 6]; + v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + } + with_span! { + span + let v = vec![1, 2, 3, 4, 5, 6]; + v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + } +} + +fn issue11309<'a>(iter: impl Iterator) -> Vec<&'a str> { + iter.filter_map(|(_, s): (&str, _)| Some(s)).collect() +} diff --git a/tests/ui/filter_map_bool_then.rs b/tests/ui/filter_map_bool_then.rs new file mode 100644 index 0000000000000..7c9b99df78cbb --- /dev/null +++ b/tests/ui/filter_map_bool_then.rs @@ -0,0 +1,58 @@ +//@run-rustfix +//@aux-build:proc_macros.rs:proc-macro +#![allow( + clippy::clone_on_copy, + clippy::map_identity, + clippy::unnecessary_lazy_evaluations, + clippy::unnecessary_filter_map, + unused +)] +#![warn(clippy::filter_map_bool_then)] + +#[macro_use] +extern crate proc_macros; + +#[derive(Clone, PartialEq)] +struct NonCopy; + +fn main() { + let v = vec![1, 2, 3, 4, 5, 6]; + v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + v.clone() + .into_iter() + .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); + v.clone() + .into_iter() + .filter(|&i| i != 1000) + .filter_map(|i| (i % 2 == 0).then(|| i + 1)); + v.iter() + .copied() + .filter(|&i| i != 1000) + .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); + // Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`, + // and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`), + // we can lint this and still get the same input type. + // See: + let v = vec![NonCopy, NonCopy]; + v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i)); + // Do not lint + let v = vec![NonCopy, NonCopy]; + v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i)); + // `&mut` is `!Copy`. + let v = vec![NonCopy, NonCopy]; + v.clone().iter_mut().filter_map(|i| (i == &mut NonCopy).then(|| i)); + external! { + let v = vec![1, 2, 3, 4, 5, 6]; + v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + } + with_span! { + span + let v = vec![1, 2, 3, 4, 5, 6]; + v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + } +} + +fn issue11309<'a>(iter: impl Iterator) -> Vec<&'a str> { + iter.filter_map(|(_, s): (&str, _)| Some(s)).collect() +} diff --git a/tests/ui/filter_map_bool_then.stderr b/tests/ui/filter_map_bool_then.stderr new file mode 100644 index 0000000000000..fffa5252e5f6c --- /dev/null +++ b/tests/ui/filter_map_bool_then.stderr @@ -0,0 +1,40 @@ +error: usage of `bool::then` in `filter_map` + --> $DIR/filter_map_bool_then.rs:20:22 + | +LL | v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` + | + = note: `-D clippy::filter-map-bool-then` implied by `-D warnings` + +error: usage of `bool::then` in `filter_map` + --> $DIR/filter_map_bool_then.rs:21:27 + | +LL | v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` + +error: usage of `bool::then` in `filter_map` + --> $DIR/filter_map_bool_then.rs:24:10 + | +LL | .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` + +error: usage of `bool::then` in `filter_map` + --> $DIR/filter_map_bool_then.rs:28:10 + | +LL | .filter_map(|i| (i % 2 == 0).then(|| i + 1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` + +error: usage of `bool::then` in `filter_map` + --> $DIR/filter_map_bool_then.rs:32:10 + | +LL | .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1)` + +error: usage of `bool::then` in `filter_map` + --> $DIR/filter_map_bool_then.rs:38:22 + | +LL | v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i == &NonCopy)).map(|i| i)` + +error: aborting due to 6 previous errors + diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr index c567ed319b5b9..19dc9071fe7bb 100644 --- a/tests/ui/get_unwrap.stderr +++ b/tests/ui/get_unwrap.stderr @@ -16,7 +16,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message = note: `-D clippy::unwrap-used` implied by `-D warnings` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise @@ -31,7 +32,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:40:17 @@ -45,7 +47,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:41:17 @@ -59,7 +62,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:42:17 @@ -73,7 +77,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:43:17 @@ -87,7 +92,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:47:21 @@ -101,7 +107,8 @@ error: used `unwrap()` on an `Option` value LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:52:9 @@ -115,7 +122,8 @@ error: used `unwrap()` on an `Option` value LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:53:9 @@ -129,7 +137,8 @@ error: used `unwrap()` on an `Option` value LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:54:9 @@ -143,7 +152,8 @@ error: used `unwrap()` on an `Option` value LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:55:9 @@ -157,7 +167,8 @@ error: used `unwrap()` on an `Option` value LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:67:17 @@ -171,7 +182,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:68:17 @@ -185,7 +197,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/get_unwrap.rs:78:24 diff --git a/tests/ui/ignored_unit_patterns.fixed b/tests/ui/ignored_unit_patterns.fixed new file mode 100644 index 0000000000000..492219fe44711 --- /dev/null +++ b/tests/ui/ignored_unit_patterns.fixed @@ -0,0 +1,17 @@ +//@run-rustfix + +#![warn(clippy::ignored_unit_patterns)] +#![allow(clippy::redundant_pattern_matching, clippy::single_match)] + +fn foo() -> Result<(), ()> { + unimplemented!() +} + +fn main() { + match foo() { + Ok(()) => {}, + Err(()) => {}, + } + if let Ok(()) = foo() {} + let _ = foo().map_err(|()| todo!()); +} diff --git a/tests/ui/ignored_unit_patterns.rs b/tests/ui/ignored_unit_patterns.rs new file mode 100644 index 0000000000000..90af36f8e5ed8 --- /dev/null +++ b/tests/ui/ignored_unit_patterns.rs @@ -0,0 +1,17 @@ +//@run-rustfix + +#![warn(clippy::ignored_unit_patterns)] +#![allow(clippy::redundant_pattern_matching, clippy::single_match)] + +fn foo() -> Result<(), ()> { + unimplemented!() +} + +fn main() { + match foo() { + Ok(_) => {}, + Err(_) => {}, + } + if let Ok(_) = foo() {} + let _ = foo().map_err(|_| todo!()); +} diff --git a/tests/ui/ignored_unit_patterns.stderr b/tests/ui/ignored_unit_patterns.stderr new file mode 100644 index 0000000000000..8feea3cc2a835 --- /dev/null +++ b/tests/ui/ignored_unit_patterns.stderr @@ -0,0 +1,28 @@ +error: matching over `()` is more explicit + --> $DIR/ignored_unit_patterns.rs:12:12 + | +LL | Ok(_) => {}, + | ^ help: use `()` instead of `_`: `()` + | + = note: `-D clippy::ignored-unit-patterns` implied by `-D warnings` + +error: matching over `()` is more explicit + --> $DIR/ignored_unit_patterns.rs:13:13 + | +LL | Err(_) => {}, + | ^ help: use `()` instead of `_`: `()` + +error: matching over `()` is more explicit + --> $DIR/ignored_unit_patterns.rs:15:15 + | +LL | if let Ok(_) = foo() {} + | ^ help: use `()` instead of `_`: `()` + +error: matching over `()` is more explicit + --> $DIR/ignored_unit_patterns.rs:16:28 + | +LL | let _ = foo().map_err(|_| todo!()); + | ^ help: use `()` instead of `_`: `()` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/mut_reference.rs b/tests/ui/mut_reference.rs index 73906121c402e..00661c51a78f9 100644 --- a/tests/ui/mut_reference.rs +++ b/tests/ui/mut_reference.rs @@ -1,8 +1,21 @@ -#![allow(unused_variables)] +#![allow(unused_variables, dead_code)] fn takes_an_immutable_reference(a: &i32) {} fn takes_a_mutable_reference(a: &mut i32) {} +mod issue11268 { + macro_rules! x { + ($f:expr) => { + $f(&mut 1); + }; + } + + fn f() { + x!(super::takes_an_immutable_reference); + x!(super::takes_a_mutable_reference); + } +} + struct MyStruct; impl MyStruct { diff --git a/tests/ui/mut_reference.stderr b/tests/ui/mut_reference.stderr index 1fdfbf9227e31..d8a71d264610a 100644 --- a/tests/ui/mut_reference.stderr +++ b/tests/ui/mut_reference.stderr @@ -1,5 +1,5 @@ error: the function `takes_an_immutable_reference` doesn't need a mutable reference - --> $DIR/mut_reference.rs:17:34 + --> $DIR/mut_reference.rs:30:34 | LL | takes_an_immutable_reference(&mut 42); | ^^^^^^^ @@ -7,19 +7,19 @@ LL | takes_an_immutable_reference(&mut 42); = note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` error: the function `as_ptr` doesn't need a mutable reference - --> $DIR/mut_reference.rs:19:12 + --> $DIR/mut_reference.rs:32:12 | LL | as_ptr(&mut 42); | ^^^^^^^ error: the method `takes_an_immutable_reference` doesn't need a mutable reference - --> $DIR/mut_reference.rs:23:44 + --> $DIR/mut_reference.rs:36:44 | LL | my_struct.takes_an_immutable_reference(&mut 42); | ^^^^^^^ error: this argument is a mutable reference, but not used mutably - --> $DIR/mut_reference.rs:11:44 + --> $DIR/mut_reference.rs:24:44 | LL | fn takes_a_mutable_reference(&self, a: &mut i32) {} | ^^^^^^^^ help: consider changing to: `&i32` diff --git a/tests/ui/ptr_as_ptr.fixed b/tests/ui/ptr_as_ptr.fixed index 26a64c861cf4d..84babb974161d 100644 --- a/tests/ui/ptr_as_ptr.fixed +++ b/tests/ui/ptr_as_ptr.fixed @@ -3,8 +3,22 @@ #![warn(clippy::ptr_as_ptr)] +#[macro_use] extern crate proc_macros; -use proc_macros::{external, inline_macros}; + +mod issue_11278_a { + #[derive(Debug)] + pub struct T { + pub p: D, + } +} + +mod issue_11278_b { + pub fn f(o: &mut super::issue_11278_a::T) -> super::issue_11278_a::T { + // Retain `super` + *unsafe { Box::from_raw(Box::into_raw(Box::new(o)).cast::>()) } + } +} #[inline_macros] fn main() { diff --git a/tests/ui/ptr_as_ptr.rs b/tests/ui/ptr_as_ptr.rs index ea40d4947331b..34fd76428b229 100644 --- a/tests/ui/ptr_as_ptr.rs +++ b/tests/ui/ptr_as_ptr.rs @@ -3,8 +3,22 @@ #![warn(clippy::ptr_as_ptr)] +#[macro_use] extern crate proc_macros; -use proc_macros::{external, inline_macros}; + +mod issue_11278_a { + #[derive(Debug)] + pub struct T { + pub p: D, + } +} + +mod issue_11278_b { + pub fn f(o: &mut super::issue_11278_a::T) -> super::issue_11278_a::T { + // Retain `super` + *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::issue_11278_a::T) } + } +} #[inline_macros] fn main() { diff --git a/tests/ui/ptr_as_ptr.stderr b/tests/ui/ptr_as_ptr.stderr index 78d733994ac69..e64f3351505f9 100644 --- a/tests/ui/ptr_as_ptr.stderr +++ b/tests/ui/ptr_as_ptr.stderr @@ -1,37 +1,43 @@ error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:14:13 + --> $DIR/ptr_as_ptr.rs:19:33 | -LL | let _ = ptr as *const i32; - | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::()` +LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::issue_11278_a::T) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `Box::into_raw(Box::new(o)).cast::>()` | = note: `-D clippy::ptr-as-ptr` implied by `-D warnings` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:15:13 + --> $DIR/ptr_as_ptr.rs:28:13 + | +LL | let _ = ptr as *const i32; + | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::()` + +error: `as` casting between raw pointers without changing its mutability + --> $DIR/ptr_as_ptr.rs:29:13 | LL | let _ = mut_ptr as *mut i32; | ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:20:17 + --> $DIR/ptr_as_ptr.rs:34:17 | LL | let _ = *ptr_ptr as *const i32; | ^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(*ptr_ptr).cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:33:25 + --> $DIR/ptr_as_ptr.rs:47:25 | LL | let _: *const i32 = ptr as *const _; | ^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:34:23 + --> $DIR/ptr_as_ptr.rs:48:23 | LL | let _: *mut i32 = mut_ptr as _; | ^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:37:21 + --> $DIR/ptr_as_ptr.rs:51:21 | LL | let _ = inline!($ptr as *const i32); | ^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `$ptr.cast::()` @@ -39,16 +45,16 @@ LL | let _ = inline!($ptr as *const i32); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:58:13 + --> $DIR/ptr_as_ptr.rs:72:13 | LL | let _ = ptr as *const i32; | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:59:13 + --> $DIR/ptr_as_ptr.rs:73:13 | LL | let _ = mut_ptr as *mut i32; | ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::()` -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors diff --git a/tests/ui/question_mark.fixed b/tests/ui/question_mark.fixed index 2d8920ccc42f9..20b9e42a7aab0 100644 --- a/tests/ui/question_mark.fixed +++ b/tests/ui/question_mark.fixed @@ -138,6 +138,23 @@ fn result_func(x: Result) -> Result { // no warning let _ = if let Err(e) = x { Err(e) } else { Ok(0) }; + // issue #11283 + // no warning + #[warn(clippy::question_mark_used)] + { + if let Err(err) = Ok(()) { + return Err(err); + } + + if Err::(0).is_err() { + return Err(0); + } else { + return Ok(0); + } + + unreachable!() + } + Ok(y) } diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs index 69451c17ee7a6..8bdafd46e8fa9 100644 --- a/tests/ui/question_mark.rs +++ b/tests/ui/question_mark.rs @@ -170,6 +170,23 @@ fn result_func(x: Result) -> Result { // no warning let _ = if let Err(e) = x { Err(e) } else { Ok(0) }; + // issue #11283 + // no warning + #[warn(clippy::question_mark_used)] + { + if let Err(err) = Ok(()) { + return Err(err); + } + + if Err::(0).is_err() { + return Err(0); + } else { + return Ok(0); + } + + unreachable!() + } + Ok(y) } diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr index 2cfd75863081b..62489c8c8c479 100644 --- a/tests/ui/question_mark.stderr +++ b/tests/ui/question_mark.stderr @@ -115,7 +115,7 @@ LL | | } | |_____^ help: replace it with: `x?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:197:5 + --> $DIR/question_mark.rs:214:5 | LL | / if let Err(err) = func_returning_result() { LL | | return Err(err); @@ -123,7 +123,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:204:5 + --> $DIR/question_mark.rs:221:5 | LL | / if let Err(err) = func_returning_result() { LL | | return Err(err); @@ -131,7 +131,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:281:13 + --> $DIR/question_mark.rs:298:13 | LL | / if a.is_none() { LL | | return None; diff --git a/tests/ui/range_contains.fixed b/tests/ui/range_contains.fixed index 0a92ee7c8dd30..47c5248118eac 100644 --- a/tests/ui/range_contains.fixed +++ b/tests/ui/range_contains.fixed @@ -5,6 +5,8 @@ #![allow(clippy::no_effect)] #![allow(clippy::short_circuit_statement)] #![allow(clippy::unnecessary_operation)] +#![allow(clippy::impossible_comparisons)] +#![allow(clippy::redundant_comparisons)] fn main() { let x = 9_i32; diff --git a/tests/ui/range_contains.rs b/tests/ui/range_contains.rs index 7a83be609571f..a35315a649d85 100644 --- a/tests/ui/range_contains.rs +++ b/tests/ui/range_contains.rs @@ -5,6 +5,8 @@ #![allow(clippy::no_effect)] #![allow(clippy::short_circuit_statement)] #![allow(clippy::unnecessary_operation)] +#![allow(clippy::impossible_comparisons)] +#![allow(clippy::redundant_comparisons)] fn main() { let x = 9_i32; diff --git a/tests/ui/range_contains.stderr b/tests/ui/range_contains.stderr index ea34023a46645..1265db695bfb1 100644 --- a/tests/ui/range_contains.stderr +++ b/tests/ui/range_contains.stderr @@ -1,5 +1,5 @@ error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:13:5 + --> $DIR/range_contains.rs:15:5 | LL | x >= 8 && x < 12; | ^^^^^^^^^^^^^^^^ help: use: `(8..12).contains(&x)` @@ -7,121 +7,121 @@ LL | x >= 8 && x < 12; = note: `-D clippy::manual-range-contains` implied by `-D warnings` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:14:5 + --> $DIR/range_contains.rs:16:5 | LL | x < 42 && x >= 21; | ^^^^^^^^^^^^^^^^^ help: use: `(21..42).contains(&x)` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:15:5 + --> $DIR/range_contains.rs:17:5 | LL | 100 > x && 1 <= x; | ^^^^^^^^^^^^^^^^^ help: use: `(1..100).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:18:5 + --> $DIR/range_contains.rs:20:5 | LL | x >= 9 && x <= 99; | ^^^^^^^^^^^^^^^^^ help: use: `(9..=99).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:19:5 + --> $DIR/range_contains.rs:21:5 | LL | x <= 33 && x >= 1; | ^^^^^^^^^^^^^^^^^ help: use: `(1..=33).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:20:5 + --> $DIR/range_contains.rs:22:5 | LL | 999 >= x && 1 <= x; | ^^^^^^^^^^^^^^^^^^ help: use: `(1..=999).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:23:5 + --> $DIR/range_contains.rs:25:5 | LL | x < 8 || x >= 12; | ^^^^^^^^^^^^^^^^ help: use: `!(8..12).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:24:5 + --> $DIR/range_contains.rs:26:5 | LL | x >= 42 || x < 21; | ^^^^^^^^^^^^^^^^^ help: use: `!(21..42).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:25:5 + --> $DIR/range_contains.rs:27:5 | LL | 100 <= x || 1 > x; | ^^^^^^^^^^^^^^^^^ help: use: `!(1..100).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:28:5 + --> $DIR/range_contains.rs:30:5 | LL | x < 9 || x > 99; | ^^^^^^^^^^^^^^^ help: use: `!(9..=99).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:29:5 + --> $DIR/range_contains.rs:31:5 | LL | x > 33 || x < 1; | ^^^^^^^^^^^^^^^ help: use: `!(1..=33).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:30:5 + --> $DIR/range_contains.rs:32:5 | LL | 999 < x || 1 > x; | ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:45:5 + --> $DIR/range_contains.rs:47:5 | LL | y >= 0. && y < 1.; | ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:46:5 + --> $DIR/range_contains.rs:48:5 | LL | y < 0. || y > 1.; | ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:49:5 + --> $DIR/range_contains.rs:51:5 | LL | x >= -10 && x <= 10; | ^^^^^^^^^^^^^^^^^^^ help: use: `(-10..=10).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:51:5 + --> $DIR/range_contains.rs:53:5 | LL | y >= -3. && y <= 3.; | ^^^^^^^^^^^^^^^^^^^ help: use: `(-3. ..=3.).contains(&y)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:56:30 + --> $DIR/range_contains.rs:58:30 | LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&z)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:56:5 + --> $DIR/range_contains.rs:58:5 | LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:57:29 + --> $DIR/range_contains.rs:59:29 | LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10); | ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&z)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:57:5 + --> $DIR/range_contains.rs:59:5 | LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10); | ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&x)` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:76:5 + --> $DIR/range_contains.rs:78:5 | LL | x >= 8 && x < 35; | ^^^^^^^^^^^^^^^^ help: use: `(8..35).contains(&x)` diff --git a/tests/ui/redundant_guards.fixed b/tests/ui/redundant_guards.fixed index 77ac76668649b..49d7336ee3717 100644 --- a/tests/ui/redundant_guards.fixed +++ b/tests/ui/redundant_guards.fixed @@ -15,6 +15,19 @@ struct B { struct C(u32, u32); +#[derive(PartialEq)] +struct FloatWrapper(f32); +fn issue11304() { + match 0.1 { + x if x == 0.0 => todo!(), + _ => todo!(), + } + match FloatWrapper(0.1) { + x if x == FloatWrapper(0.0) => todo!(), + _ => todo!(), + } +} + fn main() { let c = C(1, 2); match c { diff --git a/tests/ui/redundant_guards.rs b/tests/ui/redundant_guards.rs index b072e4ea14d1d..87761010de2ce 100644 --- a/tests/ui/redundant_guards.rs +++ b/tests/ui/redundant_guards.rs @@ -15,6 +15,19 @@ struct B { struct C(u32, u32); +#[derive(PartialEq)] +struct FloatWrapper(f32); +fn issue11304() { + match 0.1 { + x if x == 0.0 => todo!(), + _ => todo!(), + } + match FloatWrapper(0.1) { + x if x == FloatWrapper(0.0) => todo!(), + _ => todo!(), + } +} + fn main() { let c = C(1, 2); match c { diff --git a/tests/ui/redundant_guards.stderr b/tests/ui/redundant_guards.stderr index c2a92071d1dfb..5bdf43d23c533 100644 --- a/tests/ui/redundant_guards.stderr +++ b/tests/ui/redundant_guards.stderr @@ -1,5 +1,5 @@ error: redundant guard - --> $DIR/redundant_guards.rs:21:20 + --> $DIR/redundant_guards.rs:34:20 | LL | C(x, y) if let 1 = y => .., | ^^^^^^^^^ @@ -12,7 +12,7 @@ LL + C(x, 1) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:27:20 + --> $DIR/redundant_guards.rs:40:20 | LL | Some(x) if matches!(x, Some(1) if true) => .., | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | Some(Some(1)) if true => .., | ~~~~~~~ ~~~~~~~ error: redundant guard - --> $DIR/redundant_guards.rs:28:20 + --> $DIR/redundant_guards.rs:41:20 | LL | Some(x) if matches!(x, Some(1)) => { | ^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ LL + Some(Some(1)) => { | error: redundant guard - --> $DIR/redundant_guards.rs:32:20 + --> $DIR/redundant_guards.rs:45:20 | LL | Some(x) if let Some(1) = x => .., | ^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL + Some(Some(1)) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:33:20 + --> $DIR/redundant_guards.rs:46:20 | LL | Some(x) if x == Some(2) => .., | ^^^^^^^^^^^^ @@ -59,7 +59,7 @@ LL + Some(Some(2)) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:56:20 + --> $DIR/redundant_guards.rs:69:20 | LL | B { e } if matches!(e, Some(A(2))) => .., | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +71,7 @@ LL + B { e: Some(A(2)) } => .., | error: redundant guard - --> $DIR/redundant_guards.rs:93:20 + --> $DIR/redundant_guards.rs:106:20 | LL | E::A(y) if y == "not from an or pattern" => {}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL + E::A("not from an or pattern") => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:100:14 + --> $DIR/redundant_guards.rs:113:14 | LL | x if matches!(x, Some(0)) => .., | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_locals.rs b/tests/ui/redundant_locals.rs index e74c78a50b672..80af38f47b86d 100644 --- a/tests/ui/redundant_locals.rs +++ b/tests/ui/redundant_locals.rs @@ -27,6 +27,15 @@ fn downgraded_mutability() { let x = x; } +// see #11290 +fn shadow_mutation() { + let mut x = 1; + { + let mut x = x; + x = 2; + } +} + fn coercion(par: &mut i32) { let par: &i32 = par; diff --git a/tests/ui/redundant_locals.stderr b/tests/ui/redundant_locals.stderr index df07dd2f453b1..587de05752476 100644 --- a/tests/ui/redundant_locals.stderr +++ b/tests/ui/redundant_locals.stderr @@ -20,7 +20,7 @@ LL | let mut x = x; = help: remove the redefinition of `x` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:37:14 + --> $DIR/redundant_locals.rs:46:14 | LL | fn parameter(x: i32) { | ^ @@ -30,7 +30,7 @@ LL | let x = x; = help: remove the redefinition of `x` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:42:9 + --> $DIR/redundant_locals.rs:51:9 | LL | let x = 1; | ^ @@ -40,7 +40,7 @@ LL | let x = x; = help: remove the redefinition of `x` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:43:9 + --> $DIR/redundant_locals.rs:52:9 | LL | let x = x; | ^ @@ -50,7 +50,7 @@ LL | let x = x; = help: remove the redefinition of `x` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:44:9 + --> $DIR/redundant_locals.rs:53:9 | LL | let x = x; | ^ @@ -60,7 +60,7 @@ LL | let x = x; = help: remove the redefinition of `x` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:45:9 + --> $DIR/redundant_locals.rs:54:9 | LL | let x = x; | ^ @@ -70,7 +70,7 @@ LL | let x = x; = help: remove the redefinition of `x` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:50:9 + --> $DIR/redundant_locals.rs:59:9 | LL | let a = 1; | ^ @@ -81,7 +81,7 @@ LL | let a = a; = help: remove the redefinition of `a` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:51:9 + --> $DIR/redundant_locals.rs:60:9 | LL | let b = 2; | ^ @@ -92,7 +92,7 @@ LL | let b = b; = help: remove the redefinition of `b` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:58:13 + --> $DIR/redundant_locals.rs:67:13 | LL | let x = 1; | ^ @@ -102,7 +102,7 @@ LL | let x = x; = help: remove the redefinition of `x` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:65:13 + --> $DIR/redundant_locals.rs:74:13 | LL | let x = 1; | ^ @@ -112,7 +112,7 @@ LL | let x = x; = help: remove the redefinition of `x` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:68:6 + --> $DIR/redundant_locals.rs:77:6 | LL | |x: i32| { | ^ @@ -122,7 +122,7 @@ LL | let x = x; = help: remove the redefinition of `x` error: redundant redefinition of a binding - --> $DIR/redundant_locals.rs:85:9 + --> $DIR/redundant_locals.rs:94:9 | LL | let x = 1; | ^ diff --git a/tests/ui/redundant_type_annotations.rs b/tests/ui/redundant_type_annotations.rs index cc507b8d658ce..09dbd3c9b39e1 100644 --- a/tests/ui/redundant_type_annotations.rs +++ b/tests/ui/redundant_type_annotations.rs @@ -6,8 +6,8 @@ struct Cake { _data: T, } -fn make_something() -> T { - T::default() +fn make_something() -> T { + unimplemented!() } fn make_cake() -> Cake { @@ -117,7 +117,15 @@ fn test_non_locals() { let _closure_arg = |x: u32| x; } -fn test_complex_types() { +trait Trait { + type AssocTy; +} + +impl Trait for () { + type AssocTy = String; +} + +fn test_complex_types() { // Shouldn't be lint, since the literal will be i32 otherwise let _u8: u8 = 128; @@ -135,6 +143,10 @@ fn test_complex_types() { // Shouldn't be lint let _array: [u32; 2] = [8, 9]; + + let ty_param: T = make_something(); + + let assoc_ty: <() as Trait>::AssocTy = String::new(); } fn test_functions() { @@ -173,4 +185,6 @@ fn test_simple_types() { let _var: bool = false; } +fn issue11190() {} + fn main() {} diff --git a/tests/ui/redundant_type_annotations.stderr b/tests/ui/redundant_type_annotations.stderr index e8b2fe5c3847a..988ebe6372268 100644 --- a/tests/ui/redundant_type_annotations.stderr +++ b/tests/ui/redundant_type_annotations.stderr @@ -19,85 +19,85 @@ LL | let v: &Slice = self.return_a_ref_to_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:143:5 + --> $DIR/redundant_type_annotations.rs:155:5 | LL | let _return: String = return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:145:5 + --> $DIR/redundant_type_annotations.rs:157:5 | LL | let _return: Pie = return_a_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:147:5 + --> $DIR/redundant_type_annotations.rs:159:5 | LL | let _return: Pizza = return_an_enum(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:149:5 + --> $DIR/redundant_type_annotations.rs:161:5 | LL | let _return: u32 = return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:151:5 + --> $DIR/redundant_type_annotations.rs:163:5 | LL | let _return: String = String::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:153:5 + --> $DIR/redundant_type_annotations.rs:165:5 | LL | let new_pie: Pie = Pie::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:155:5 + --> $DIR/redundant_type_annotations.rs:167:5 | LL | let _return: u32 = new_pie.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:157:5 + --> $DIR/redundant_type_annotations.rs:169:5 | LL | let _return: u32 = Pie::associated_return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:159:5 + --> $DIR/redundant_type_annotations.rs:171:5 | LL | let _return: String = Pie::associated_return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:165:5 + --> $DIR/redundant_type_annotations.rs:177:5 | LL | let _var: u32 = u32::MAX; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:167:5 + --> $DIR/redundant_type_annotations.rs:179:5 | LL | let _var: u32 = 5_u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:169:5 + --> $DIR/redundant_type_annotations.rs:181:5 | LL | let _var: &str = "test"; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:171:5 + --> $DIR/redundant_type_annotations.rs:183:5 | LL | let _var: &[u8] = b"test"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:173:5 + --> $DIR/redundant_type_annotations.rs:185:5 | LL | let _var: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index 8257bf2947ab0..e78b9e5c9c12e 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -29,9 +29,9 @@ #![allow(clippy::recursive_format_impl)] #![allow(clippy::unwrap_or_default)] #![allow(clippy::invisible_characters)] +#![allow(invalid_reference_casting)] #![allow(suspicious_double_ref_op)] #![allow(invalid_nan_comparisons)] -#![allow(invalid_reference_casting)] #![allow(drop_bounds)] #![allow(dropping_copy_types)] #![allow(dropping_references)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 6569dad18d406..2e6ef60cb7984 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -29,9 +29,9 @@ #![allow(clippy::recursive_format_impl)] #![allow(clippy::unwrap_or_default)] #![allow(clippy::invisible_characters)] +#![allow(invalid_reference_casting)] #![allow(suspicious_double_ref_op)] #![allow(invalid_nan_comparisons)] -#![allow(invalid_reference_casting)] #![allow(drop_bounds)] #![allow(dropping_copy_types)] #![allow(dropping_references)] diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index 8bb3c8fbeebd3..d93a55ba9065c 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -10,31 +10,31 @@ error: `^` is not the exponentiation operator --> $DIR/suspicious_xor_used_as_pow.rs:20:13 | LL | let _ = 2i32 ^ 9i32; - | ^^^^^^^^^^^ help: did you mean to write: `2_i32.pow(9_i32)` + | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(9i32)` error: `^` is not the exponentiation operator --> $DIR/suspicious_xor_used_as_pow.rs:21:13 | LL | let _ = 2i32 ^ 2i32; - | ^^^^^^^^^^^ help: did you mean to write: `2_i32.pow(2_i32)` + | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(2i32)` error: `^` is not the exponentiation operator --> $DIR/suspicious_xor_used_as_pow.rs:22:13 | LL | let _ = 50i32 ^ 3i32; - | ^^^^^^^^^^^^ help: did you mean to write: `50_i32.pow(3_i32)` + | ^^^^^^^^^^^^ help: did you mean to write: `50i32.pow(3i32)` error: `^` is not the exponentiation operator --> $DIR/suspicious_xor_used_as_pow.rs:23:13 | LL | let _ = 5i32 ^ 8i32; - | ^^^^^^^^^^^ help: did you mean to write: `5_i32.pow(8_i32)` + | ^^^^^^^^^^^ help: did you mean to write: `5i32.pow(8i32)` error: `^` is not the exponentiation operator --> $DIR/suspicious_xor_used_as_pow.rs:24:13 | LL | let _ = 2i32 ^ 32i32; - | ^^^^^^^^^^^^ help: did you mean to write: `2_i32.pow(32_i32)` + | ^^^^^^^^^^^^ help: did you mean to write: `2i32.pow(32i32)` error: `^` is not the exponentiation operator --> $DIR/suspicious_xor_used_as_pow.rs:13:9 diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr index 3796d942ff9fc..41db819f6fb75 100644 --- a/tests/ui/unwrap.stderr +++ b/tests/ui/unwrap.stderr @@ -4,7 +4,8 @@ error: used `unwrap()` on an `Option` value LL | let _ = opt.unwrap(); | ^^^^^^^^^^^^ | - = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is `None`, it will panic + = help: consider using `expect()` to provide a better panic message = note: `-D clippy::unwrap-used` implied by `-D warnings` error: used `unwrap()` on a `Result` value @@ -13,7 +14,8 @@ error: used `unwrap()` on a `Result` value LL | let _ = res.unwrap(); | ^^^^^^^^^^^^ | - = help: if you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message + = note: if this value is an `Err`, it will panic + = help: consider using `expect()` to provide a better panic message error: used `unwrap_err()` on a `Result` value --> $DIR/unwrap.rs:12:13 @@ -21,7 +23,8 @@ error: used `unwrap_err()` on a `Result` value LL | let _ = res.unwrap_err(); | ^^^^^^^^^^^^^^^^ | - = help: if you don't want to handle the `Ok` case gracefully, consider using `expect_err()` to provide a better panic message + = note: if this value is an `Ok`, it will panic + = help: consider using `expect_err()` to provide a better panic message error: aborting due to 3 previous errors diff --git a/tests/ui/unwrap_expect_used.rs b/tests/ui/unwrap_expect_used.rs index 7f57efc53c9c8..26f92ccdefaa3 100644 --- a/tests/ui/unwrap_expect_used.rs +++ b/tests/ui/unwrap_expect_used.rs @@ -1,5 +1,8 @@ #![warn(clippy::unwrap_used, clippy::expect_used)] #![allow(clippy::unnecessary_literal_unwrap)] +#![feature(never_type)] + +use std::convert::Infallible; trait OptionExt { type Item; @@ -28,6 +31,14 @@ fn main() { Some(3).unwrap_err(); Some(3).expect_err("Hellow none!"); + // Issue #11245: The `Err` variant can never be constructed so do not lint this. + let x: Result<(), !> = Ok(()); + x.unwrap(); + x.expect("is `!` (never)"); + let x: Result<(), Infallible> = Ok(()); + x.unwrap(); + x.expect("is never-like (0 variants)"); + let a: Result = Ok(3); a.unwrap(); a.expect("Hello world!"); diff --git a/tests/ui/unwrap_expect_used.stderr b/tests/ui/unwrap_expect_used.stderr index 1a551ab5ab8ea..f66e47612add4 100644 --- a/tests/ui/unwrap_expect_used.stderr +++ b/tests/ui/unwrap_expect_used.stderr @@ -1,52 +1,52 @@ error: used `unwrap()` on an `Option` value - --> $DIR/unwrap_expect_used.rs:24:5 + --> $DIR/unwrap_expect_used.rs:27:5 | LL | Some(3).unwrap(); | ^^^^^^^^^^^^^^^^ | - = help: if this value is `None`, it will panic + = note: if this value is `None`, it will panic = note: `-D clippy::unwrap-used` implied by `-D warnings` error: used `expect()` on an `Option` value - --> $DIR/unwrap_expect_used.rs:25:5 + --> $DIR/unwrap_expect_used.rs:28:5 | LL | Some(3).expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if this value is `None`, it will panic + = note: if this value is `None`, it will panic = note: `-D clippy::expect-used` implied by `-D warnings` error: used `unwrap()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:32:5 + --> $DIR/unwrap_expect_used.rs:43:5 | LL | a.unwrap(); | ^^^^^^^^^^ | - = help: if this value is an `Err`, it will panic + = note: if this value is an `Err`, it will panic error: used `expect()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:33:5 + --> $DIR/unwrap_expect_used.rs:44:5 | LL | a.expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if this value is an `Err`, it will panic + = note: if this value is an `Err`, it will panic error: used `unwrap_err()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:34:5 + --> $DIR/unwrap_expect_used.rs:45:5 | LL | a.unwrap_err(); | ^^^^^^^^^^^^^^ | - = help: if this value is an `Ok`, it will panic + = note: if this value is an `Ok`, it will panic error: used `expect_err()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:35:5 + --> $DIR/unwrap_expect_used.rs:46:5 | LL | a.expect_err("Hello error!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: if this value is an `Ok`, it will panic + = note: if this value is an `Ok`, it will panic error: aborting due to 6 previous errors From 4c779da913ffbc0010681ea7e623e57374fbb5e2 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 3 Aug 2023 13:11:06 +0000 Subject: [PATCH 06/79] Remove some leftover cruft from compiletest-rs --- tests/compile-test.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index e46f8bf6fabdf..f9f15f1640ca8 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -126,12 +126,6 @@ fn base_config(test_dir: &str) -> compiletest::Config { out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap_or("target".into())).join("ui_test"), ..compiletest::Config::rustc(Path::new("tests").join(test_dir)) }; - - if let Some(_path) = option_env!("RUSTC_LIB_PATH") { - //let path = PathBuf::from(path); - //config.run_lib_path = path.clone(); - //config.compile_lib_path = path; - } let current_exe_path = env::current_exe().unwrap(); let deps_path = current_exe_path.parent().unwrap(); let profile_path = deps_path.parent().unwrap(); From 0afd38b093a3de1e4a5a505f4138bcc1397263e7 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 7 Aug 2023 09:42:24 +0000 Subject: [PATCH 07/79] Make a panic message more informative if binary files are accidentally created somewhere in the test folder --- tests/headers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/headers.rs b/tests/headers.rs index 1d1e566cbf6fe..7eec9a9cdd2b9 100644 --- a/tests/headers.rs +++ b/tests/headers.rs @@ -16,7 +16,7 @@ fn old_test_headers() { continue; } - let file = fs::read_to_string(entry.path()).unwrap(); + let file = fs::read_to_string(entry.path()).unwrap_or_else(|err| panic!("{}: {err}", entry.path().display())); if let Some(header) = old_headers.find(&file) { println!("Found header `{}` in {}", header.as_str(), entry.path().display()); From 3d88fae050578fe165b6544d49fbac2f23e60391 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 27 Jul 2023 11:40:22 +0000 Subject: [PATCH 08/79] Update ui test crate --- .cargo/config.toml | 6 +- Cargo.toml | 2 +- book/src/development/adding_lints.md | 4 +- clippy_dev/src/update_lints.rs | 1 - tests/compile-test.rs | 122 +--- .../collapsible_span_lint_calls.fixed | 2 +- .../collapsible_span_lint_calls.rs | 1 - .../interning_defined_symbol.fixed | 2 +- tests/ui-internal/interning_defined_symbol.rs | 1 - .../ui-internal/invalid_msrv_attr_impl.fixed | 2 +- tests/ui-internal/invalid_msrv_attr_impl.rs | 2 - tests/ui-internal/outer_expn_data.fixed | 2 +- tests/ui-internal/outer_expn_data.rs | 2 - tests/ui-internal/unnecessary_def_path.fixed | 2 +- tests/ui-internal/unnecessary_def_path.rs | 1 - .../ui-internal/unnecessary_symbol_str.fixed | 2 +- tests/ui-internal/unnecessary_symbol_str.rs | 1 - .../uninlined_format_args.fixed | 1 - .../uninlined_format_args.rs | 1 - .../uninlined_format_args.stderr | 12 +- .../array_size_threshold.rs | 2 +- tests/ui-toml/dbg_macro/dbg_macro.rs | 2 +- .../doc_markdown.fixed | 12 + .../doc_markdown.fixed | 12 + .../ui-toml/large_futures/large_futures.fixed | 27 + .../lint_decimal_readability/test.fixed | 23 + .../index_refutable_slice.fixed | 24 + .../min_rust_version/min_rust_version.fixed | 98 +++ .../conf_missing_enforced_import_rename.fixed | 16 + .../conf_nonstandard_macro_braces.fixed | 1 - .../conf_nonstandard_macro_braces.rs | 1 - .../conf_nonstandard_macro_braces.stderr | 16 +- tests/ui-toml/semicolon_block/both.fixed | 1 - tests/ui-toml/semicolon_block/both.rs | 1 - tests/ui-toml/semicolon_block/both.stderr | 8 +- .../semicolon_inside_block.fixed | 1 - .../semicolon_block/semicolon_inside_block.rs | 1 - .../semicolon_inside_block.stderr | 2 +- .../semicolon_outside_block.fixed | 1 - .../semicolon_outside_block.rs | 1 - .../semicolon_outside_block.stderr | 6 +- tests/ui-toml/toml_trivially_copy/test.rs | 2 +- tests/ui-toml/unwrap_used/unwrap_used.fixed | 95 +++ .../upper_case_acronyms.fixed | 44 ++ tests/ui-toml/vec_box_sized/test.fixed | 16 + tests/ui/allow_attributes.fixed | 1 - tests/ui/allow_attributes.rs | 1 - tests/ui/allow_attributes.stderr | 4 +- tests/ui/almost_complete_range.fixed | 1 - tests/ui/almost_complete_range.rs | 1 - tests/ui/almost_complete_range.stderr | 54 +- tests/ui/as_ptr_cast_mut.rs | 1 + tests/ui/as_ptr_cast_mut.stderr | 4 +- tests/ui/as_underscore.fixed | 2 - tests/ui/as_underscore.rs | 2 - tests/ui/as_underscore.stderr | 4 +- tests/ui/assertions_on_result_states.fixed | 1 - tests/ui/assertions_on_result_states.rs | 1 - tests/ui/assertions_on_result_states.stderr | 14 +- tests/ui/assign_ops.fixed | 2 - tests/ui/assign_ops.rs | 2 - tests/ui/assign_ops.stderr | 22 +- tests/ui/assign_ops2.rs | 1 + tests/ui/assign_ops2.stderr | 20 +- tests/ui/async_yields_async.fixed | 1 - tests/ui/async_yields_async.rs | 1 - tests/ui/async_yields_async.stderr | 12 +- tests/ui/bind_instead_of_map.fixed | 1 - tests/ui/bind_instead_of_map.rs | 1 - tests/ui/bind_instead_of_map.stderr | 8 +- tests/ui/bind_instead_of_map_multipart.fixed | 1 - tests/ui/bind_instead_of_map_multipart.rs | 1 - tests/ui/bind_instead_of_map_multipart.stderr | 12 +- tests/ui/blocks_in_if_conditions.fixed | 1 - tests/ui/blocks_in_if_conditions.rs | 1 - tests/ui/blocks_in_if_conditions.stderr | 6 +- tests/ui/bool_assert_comparison.fixed | 2 - tests/ui/bool_assert_comparison.rs | 2 - tests/ui/bool_assert_comparison.stderr | 66 +- tests/ui/bool_comparison.fixed | 2 - tests/ui/bool_comparison.rs | 2 - tests/ui/bool_comparison.stderr | 44 +- tests/ui/bool_to_int_with_if.fixed | 2 - tests/ui/bool_to_int_with_if.rs | 2 - tests/ui/bool_to_int_with_if.stderr | 18 +- tests/ui/borrow_as_ptr.fixed | 1 - tests/ui/borrow_as_ptr.rs | 1 - tests/ui/borrow_as_ptr.stderr | 4 +- tests/ui/borrow_as_ptr_no_std.fixed | 1 - tests/ui/borrow_as_ptr_no_std.rs | 1 - tests/ui/borrow_as_ptr_no_std.stderr | 4 +- tests/ui/borrow_box.rs | 1 + tests/ui/borrow_box.stderr | 20 +- tests/ui/borrow_deref_ref.fixed | 1 - tests/ui/borrow_deref_ref.rs | 1 - tests/ui/borrow_deref_ref.stderr | 6 +- tests/ui/borrow_deref_ref_unfixable.rs | 1 + tests/ui/borrow_deref_ref_unfixable.stderr | 2 +- tests/ui/box_default.fixed | 1 - tests/ui/box_default.rs | 1 - tests/ui/box_default.stderr | 32 +- .../branches_sharing_code/shared_at_bottom.rs | 2 +- .../ui/branches_sharing_code/shared_at_top.rs | 2 +- .../shared_at_top_and_bottom.rs | 2 +- tests/ui/bytecount.rs | 2 + tests/ui/bytecount.stderr | 8 +- tests/ui/bytes_count_to_len.fixed | 1 - tests/ui/bytes_count_to_len.rs | 1 - tests/ui/bytes_count_to_len.stderr | 8 +- tests/ui/bytes_nth.fixed | 2 - tests/ui/bytes_nth.rs | 2 - tests/ui/bytes_nth.stderr | 6 +- ...sensitive_file_extension_comparisons.fixed | 1 - ...se_sensitive_file_extension_comparisons.rs | 1 - ...ensitive_file_extension_comparisons.stderr | 12 +- tests/ui/cast.rs | 2 + tests/ui/cast.stderr | 102 +-- tests/ui/cast_abs_to_unsigned.fixed | 2 - tests/ui/cast_abs_to_unsigned.rs | 2 - tests/ui/cast_abs_to_unsigned.stderr | 36 +- tests/ui/cast_lossless_bool.fixed | 2 - tests/ui/cast_lossless_bool.rs | 2 - tests/ui/cast_lossless_bool.stderr | 28 +- tests/ui/cast_lossless_float.fixed | 2 - tests/ui/cast_lossless_float.rs | 2 - tests/ui/cast_lossless_float.stderr | 22 +- tests/ui/cast_lossless_integer.fixed | 2 - tests/ui/cast_lossless_integer.rs | 2 - tests/ui/cast_lossless_integer.stderr | 38 +- tests/ui/cast_raw_slice_pointer_cast.fixed | 1 - tests/ui/cast_raw_slice_pointer_cast.rs | 1 - tests/ui/cast_raw_slice_pointer_cast.stderr | 14 +- tests/ui/cast_size.rs | 1 + tests/ui/cast_slice_different_sizes.rs | 1 + tests/ui/cast_slice_different_sizes.stderr | 28 +- tests/ui/cfg_attr_rustfmt.fixed | 2 +- tests/ui/cfg_attr_rustfmt.rs | 2 +- tests/ui/cfg_features.fixed | 12 + tests/ui/char_lit_as_u8_suggestions.fixed | 2 - tests/ui/char_lit_as_u8_suggestions.rs | 2 - tests/ui/char_lit_as_u8_suggestions.stderr | 8 +- tests/ui/checked_conversions.fixed | 2 - tests/ui/checked_conversions.rs | 2 - tests/ui/checked_conversions.stderr | 34 +- .../complex_conditionals_nested.rs | 2 +- .../ui/checked_unwrap/simple_conditionals.rs | 1 + .../checked_unwrap/simple_conditionals.stderr | 38 +- tests/ui/clear_with_drain.fixed | 1 - tests/ui/clear_with_drain.rs | 1 - tests/ui/clear_with_drain.stderr | 42 +- tests/ui/clone_on_copy.fixed | 2 - tests/ui/clone_on_copy.rs | 2 - tests/ui/clone_on_copy.stderr | 18 +- tests/ui/cloned_instead_of_copied.fixed | 2 - tests/ui/cloned_instead_of_copied.rs | 2 - tests/ui/cloned_instead_of_copied.stderr | 16 +- .../ui/cmp_owned/asymmetric_partial_eq.fixed | 1 - tests/ui/cmp_owned/asymmetric_partial_eq.rs | 1 - .../ui/cmp_owned/asymmetric_partial_eq.stderr | 12 +- tests/ui/cmp_owned/comparison_flip.fixed | 2 - tests/ui/cmp_owned/comparison_flip.rs | 2 - tests/ui/cmp_owned/comparison_flip.stderr | 4 +- tests/ui/cmp_owned/with_suggestion.fixed | 2 - tests/ui/cmp_owned/with_suggestion.rs | 2 - tests/ui/cmp_owned/with_suggestion.stderr | 12 +- tests/ui/collapsible_else_if.fixed | 1 - tests/ui/collapsible_else_if.rs | 1 - tests/ui/collapsible_else_if.stderr | 16 +- tests/ui/collapsible_if.fixed | 1 - tests/ui/collapsible_if.rs | 1 - tests/ui/collapsible_if.stderr | 18 +- tests/ui/collapsible_str_replace.fixed | 2 - tests/ui/collapsible_str_replace.rs | 2 - tests/ui/collapsible_str_replace.stderr | 28 +- tests/ui/comparison_to_empty.fixed | 2 - tests/ui/comparison_to_empty.rs | 2 - tests/ui/comparison_to_empty.stderr | 18 +- tests/ui/crashes/ice-10148.rs | 2 +- tests/ui/crashes/ice-10912.rs | 2 +- tests/ui/crashes/ice-2774.fixed | 27 + tests/ui/crashes/ice-360.rs | 2 +- tests/ui/crashes/ice-3717.fixed | 10 + tests/ui/crashes/ice-5835.fixed | 9 + tests/ui/crashes/ice-5872.fixed | 5 + tests/ui/crashes/ice-6250.rs | 2 +- tests/ui/crashes/ice-6251.rs | 2 +- tests/ui/crashes/ice-6252.rs | 1 + tests/ui/crashes/ice-6252.stderr | 6 +- tests/ui/crashes/ice-7169.fixed | 11 + tests/ui/crashes/ice-8250.fixed | 6 + tests/ui/crashes/ice-8821.fixed | 8 + tests/ui/crashes/ice-8850.fixed | 27 + tests/ui/crashes/ice-9041.rs | 2 +- tests/ui/crashes/ice-96721.fixed | 10 + .../needless_lifetimes_impl_trait.fixed | 20 + .../needless_pass_by_value-w-late-bound.fixed | 9 + tests/ui/crate_in_macro_def.fixed | 1 - tests/ui/crate_in_macro_def.rs | 1 - tests/ui/crate_in_macro_def.stderr | 2 +- tests/ui/crate_level_checks/no_std_swap.fixed | 13 + tests/ui/create_dir.fixed | 1 - tests/ui/create_dir.rs | 1 - tests/ui/create_dir.stderr | 4 +- tests/ui/dbg_macro.rs | 2 + tests/ui/dbg_macro.stderr | 36 +- tests/ui/decimal_literal_representation.fixed | 2 - tests/ui/decimal_literal_representation.rs | 2 - .../ui/decimal_literal_representation.stderr | 14 +- .../ui/default_constructed_unit_structs.fixed | 2 - tests/ui/default_constructed_unit_structs.rs | 2 - .../default_constructed_unit_structs.stderr | 12 +- tests/ui/default_instead_of_iter_empty.fixed | 1 - tests/ui/default_instead_of_iter_empty.rs | 1 - tests/ui/default_instead_of_iter_empty.stderr | 6 +- tests/ui/default_numeric_fallback_f64.fixed | 1 - tests/ui/default_numeric_fallback_f64.rs | 1 - tests/ui/default_numeric_fallback_f64.stderr | 48 +- tests/ui/default_numeric_fallback_i32.fixed | 1 - tests/ui/default_numeric_fallback_i32.rs | 1 - tests/ui/default_numeric_fallback_i32.stderr | 52 +- tests/ui/default_trait_access.fixed | 1 - tests/ui/default_trait_access.rs | 1 - tests/ui/default_trait_access.stderr | 18 +- tests/ui/deref_addrof.fixed | 1 - tests/ui/deref_addrof.rs | 1 - tests/ui/deref_addrof.stderr | 20 +- tests/ui/deref_addrof_double_trigger.rs | 2 +- tests/ui/deref_by_slicing.fixed | 2 - tests/ui/deref_by_slicing.rs | 2 - tests/ui/deref_by_slicing.stderr | 18 +- tests/ui/derivable_impls.fixed | 2 - tests/ui/derivable_impls.rs | 2 - tests/ui/derivable_impls.stderr | 16 +- tests/ui/derive_partial_eq_without_eq.fixed | 2 - tests/ui/derive_partial_eq_without_eq.rs | 2 - tests/ui/derive_partial_eq_without_eq.stderr | 22 +- tests/ui/doc/doc-fixable.fixed | 2 +- tests/ui/doc/doc-fixable.rs | 2 +- tests/ui/doc/unbalanced_ticks.rs | 2 +- tests/ui/double_comparison.fixed | 1 - tests/ui/double_comparison.rs | 1 - tests/ui/double_comparison.stderr | 16 +- tests/ui/drain_collect.fixed | 2 - tests/ui/drain_collect.rs | 2 - tests/ui/drain_collect.stderr | 22 +- tests/ui/duration_subsec.fixed | 1 - tests/ui/duration_subsec.rs | 1 - tests/ui/duration_subsec.stderr | 10 +- tests/ui/empty_drop.fixed | 1 - tests/ui/empty_drop.rs | 1 - tests/ui/empty_drop.stderr | 4 +- tests/ui/empty_structs_with_brackets.fixed | 1 - tests/ui/empty_structs_with_brackets.rs | 1 - tests/ui/empty_structs_with_brackets.stderr | 4 +- tests/ui/entry.fixed | 1 - tests/ui/entry.rs | 1 - tests/ui/entry.stderr | 20 +- tests/ui/entry_btree.fixed | 2 - tests/ui/entry_btree.rs | 2 - tests/ui/entry_btree.stderr | 2 +- tests/ui/entry_with_else.fixed | 2 - tests/ui/entry_with_else.rs | 2 - tests/ui/entry_with_else.stderr | 14 +- tests/ui/enum_glob_use.fixed | 2 - tests/ui/enum_glob_use.rs | 2 - tests/ui/enum_glob_use.stderr | 6 +- tests/ui/eprint_with_newline.fixed | 55 ++ tests/ui/equatable_if_let.fixed | 1 - tests/ui/equatable_if_let.rs | 1 - tests/ui/equatable_if_let.stderr | 28 +- tests/ui/err_expect.fixed | 2 - tests/ui/err_expect.rs | 2 - tests/ui/err_expect.stderr | 4 +- tests/ui/eta.fixed | 1 - tests/ui/eta.rs | 1 - tests/ui/eta.stderr | 54 +- tests/ui/excessive_precision.fixed | 1 - tests/ui/excessive_precision.rs | 1 - tests/ui/excessive_precision.stderr | 30 +- tests/ui/exhaustive_items.fixed | 2 - tests/ui/exhaustive_items.rs | 2 - tests/ui/exhaustive_items.stderr | 10 +- tests/ui/expect_fun_call.fixed | 1 - tests/ui/expect_fun_call.rs | 1 - tests/ui/expect_fun_call.stderr | 30 +- tests/ui/explicit_auto_deref.fixed | 2 - tests/ui/explicit_auto_deref.rs | 2 - tests/ui/explicit_auto_deref.stderr | 78 +-- tests/ui/explicit_counter_loop.rs | 2 +- tests/ui/explicit_deref_methods.fixed | 1 - tests/ui/explicit_deref_methods.rs | 1 - tests/ui/explicit_deref_methods.stderr | 24 +- tests/ui/explicit_into_iter_loop.fixed | 1 - tests/ui/explicit_into_iter_loop.rs | 1 - tests/ui/explicit_into_iter_loop.stderr | 12 +- tests/ui/explicit_iter_loop.fixed | 1 - tests/ui/explicit_iter_loop.rs | 1 - tests/ui/explicit_iter_loop.stderr | 46 +- tests/ui/explicit_write.fixed | 1 - tests/ui/explicit_write.rs | 1 - tests/ui/explicit_write.stderr | 26 +- tests/ui/extend_with_drain.fixed | 1 - tests/ui/extend_with_drain.rs | 1 - tests/ui/extend_with_drain.stderr | 8 +- tests/ui/extra_unused_type_parameters.fixed | 1 - tests/ui/extra_unused_type_parameters.rs | 1 - tests/ui/extra_unused_type_parameters.stderr | 16 +- tests/ui/filter_map_bool_then.fixed | 1 - tests/ui/filter_map_bool_then.rs | 1 - tests/ui/filter_map_bool_then.stderr | 12 +- tests/ui/filter_map_identity.fixed | 2 - tests/ui/filter_map_identity.rs | 2 - tests/ui/filter_map_identity.stderr | 8 +- tests/ui/filter_map_next_fixable.fixed | 2 - tests/ui/filter_map_next_fixable.rs | 2 - tests/ui/filter_map_next_fixable.stderr | 4 +- tests/ui/flat_map_identity.fixed | 2 - tests/ui/flat_map_identity.rs | 2 - tests/ui/flat_map_identity.stderr | 6 +- tests/ui/flat_map_option.fixed | 1 - tests/ui/flat_map_option.rs | 1 - tests/ui/flat_map_option.stderr | 4 +- tests/ui/float_cmp.rs | 2 +- tests/ui/float_cmp_const.rs | 2 +- tests/ui/float_equality_without_abs.rs | 2 +- tests/ui/floating_point_abs.fixed | 1 - tests/ui/floating_point_abs.rs | 1 - tests/ui/floating_point_abs.stderr | 16 +- tests/ui/floating_point_exp.fixed | 1 - tests/ui/floating_point_exp.rs | 1 - tests/ui/floating_point_exp.stderr | 10 +- tests/ui/floating_point_hypot.fixed | 1 - tests/ui/floating_point_hypot.rs | 1 - tests/ui/floating_point_hypot.stderr | 6 +- tests/ui/floating_point_log.fixed | 1 - tests/ui/floating_point_log.rs | 1 - tests/ui/floating_point_log.stderr | 58 +- tests/ui/floating_point_logbase.fixed | 1 - tests/ui/floating_point_logbase.rs | 1 - tests/ui/floating_point_logbase.stderr | 10 +- tests/ui/floating_point_mul_add.fixed | 1 - tests/ui/floating_point_mul_add.rs | 1 - tests/ui/floating_point_mul_add.stderr | 24 +- tests/ui/floating_point_powf.fixed | 1 - tests/ui/floating_point_powf.rs | 1 - tests/ui/floating_point_powf.stderr | 62 +- tests/ui/floating_point_powi.fixed | 1 - tests/ui/floating_point_powi.rs | 1 - tests/ui/floating_point_powi.stderr | 28 +- tests/ui/floating_point_rad.fixed | 1 - tests/ui/floating_point_rad.rs | 1 - tests/ui/floating_point_rad.stderr | 16 +- tests/ui/fn_to_numeric_cast.rs | 2 +- tests/ui/fn_to_numeric_cast_any.rs | 2 +- tests/ui/for_kv_map.fixed | 50 ++ tests/ui/format.fixed | 1 - tests/ui/format.rs | 1 - tests/ui/format.stderr | 30 +- tests/ui/format_args.fixed | 1 - tests/ui/format_args.rs | 1 - tests/ui/format_args.stderr | 50 +- tests/ui/four_forward_slashes.fixed | 2 +- tests/ui/four_forward_slashes.rs | 2 +- .../ui/four_forward_slashes_first_line.fixed | 1 - tests/ui/four_forward_slashes_first_line.rs | 1 - tests/ui/from_iter_instead_of_collect.fixed | 2 - tests/ui/from_iter_instead_of_collect.rs | 2 - tests/ui/from_iter_instead_of_collect.stderr | 30 +- tests/ui/from_over_into.fixed | 2 - tests/ui/from_over_into.rs | 2 - tests/ui/from_over_into.stderr | 12 +- tests/ui/from_str_radix_10.fixed | 52 ++ tests/ui/get_first.fixed | 1 - tests/ui/get_first.rs | 1 - tests/ui/get_first.stderr | 6 +- tests/ui/get_last_with_len.fixed | 2 - tests/ui/get_last_with_len.rs | 2 - tests/ui/get_last_with_len.stderr | 12 +- tests/ui/get_unwrap.fixed | 2 - tests/ui/get_unwrap.rs | 2 - tests/ui/get_unwrap.stderr | 62 +- tests/ui/identity_op.fixed | 1 - tests/ui/identity_op.rs | 1 - tests/ui/identity_op.stderr | 80 +-- tests/ui/ignored_unit_patterns.fixed | 2 - tests/ui/ignored_unit_patterns.rs | 2 - tests/ui/ignored_unit_patterns.stderr | 8 +- tests/ui/impl_trait_in_params.rs | 2 +- tests/ui/implicit_clone.fixed | 1 - tests/ui/implicit_clone.rs | 1 - tests/ui/implicit_clone.stderr | 24 +- tests/ui/implicit_hasher.rs | 2 +- tests/ui/implicit_return.fixed | 1 - tests/ui/implicit_return.rs | 1 - tests/ui/implicit_return.stderr | 32 +- tests/ui/implicit_saturating_add.fixed | 2 - tests/ui/implicit_saturating_add.rs | 2 - tests/ui/implicit_saturating_add.stderr | 48 +- tests/ui/implicit_saturating_sub.fixed | 1 - tests/ui/implicit_saturating_sub.rs | 1 - tests/ui/implicit_saturating_sub.stderr | 46 +- tests/ui/inconsistent_digit_grouping.fixed | 1 - tests/ui/inconsistent_digit_grouping.rs | 1 - tests/ui/inconsistent_digit_grouping.stderr | 22 +- .../ui/inconsistent_struct_constructor.fixed | 1 - tests/ui/inconsistent_struct_constructor.rs | 1 - .../ui/inconsistent_struct_constructor.stderr | 4 +- .../incorrect_clone_impl_on_copy_type.fixed | 1 - tests/ui/incorrect_clone_impl_on_copy_type.rs | 1 - .../incorrect_clone_impl_on_copy_type.stderr | 8 +- ...correct_partial_ord_impl_on_ord_type.fixed | 1 - .../incorrect_partial_ord_impl_on_ord_type.rs | 1 - ...orrect_partial_ord_impl_on_ord_type.stderr | 4 +- ...partial_ord_impl_on_ord_type_fully_qual.rs | 2 +- .../if_let_slice_binding.fixed | 167 +++++ .../slice_indexing_in_macro.fixed | 28 + tests/ui/inefficient_to_string.fixed | 1 - tests/ui/inefficient_to_string.rs | 1 - tests/ui/inefficient_to_string.stderr | 14 +- tests/ui/infallible_destructuring_match.fixed | 1 - tests/ui/infallible_destructuring_match.rs | 1 - .../ui/infallible_destructuring_match.stderr | 8 +- tests/ui/infinite_loop.rs | 2 + tests/ui/infinite_loop.stderr | 24 +- tests/ui/inline_fn_without_body.fixed | 2 - tests/ui/inline_fn_without_body.rs | 2 - tests/ui/inline_fn_without_body.stderr | 6 +- tests/ui/int_plus_one.fixed | 2 - tests/ui/int_plus_one.rs | 2 - tests/ui/int_plus_one.stderr | 8 +- tests/ui/into_iter_on_ref.fixed | 1 - tests/ui/into_iter_on_ref.rs | 1 - tests/ui/into_iter_on_ref.stderr | 54 +- tests/ui/invalid_null_ptr_usage.fixed | 2 - tests/ui/invalid_null_ptr_usage.rs | 2 - tests/ui/invalid_null_ptr_usage.stderr | 50 +- tests/ui/is_digit_ascii_radix.fixed | 2 - tests/ui/is_digit_ascii_radix.rs | 2 - tests/ui/is_digit_ascii_radix.stderr | 6 +- tests/ui/issue_2356.fixed | 1 - tests/ui/issue_2356.rs | 1 - tests/ui/issue_2356.stderr | 4 +- tests/ui/iter_cloned_collect.fixed | 2 - tests/ui/iter_cloned_collect.rs | 2 - tests/ui/iter_cloned_collect.stderr | 10 +- tests/ui/iter_count.fixed | 1 - tests/ui/iter_count.rs | 1 - tests/ui/iter_count.stderr | 50 +- tests/ui/iter_kv_map.fixed | 2 - tests/ui/iter_kv_map.rs | 2 - tests/ui/iter_kv_map.stderr | 56 +- tests/ui/iter_next_slice.fixed | 1 - tests/ui/iter_next_slice.rs | 1 - tests/ui/iter_next_slice.stderr | 8 +- tests/ui/iter_nth_zero.fixed | 2 - tests/ui/iter_nth_zero.rs | 2 - tests/ui/iter_nth_zero.stderr | 6 +- tests/ui/iter_on_empty_collections.fixed | 1 - tests/ui/iter_on_empty_collections.rs | 1 - tests/ui/iter_on_empty_collections.stderr | 12 +- tests/ui/iter_on_single_items.fixed | 1 - tests/ui/iter_on_single_items.rs | 1 - tests/ui/iter_on_single_items.stderr | 12 +- tests/ui/iter_overeager_cloned.fixed | 1 - tests/ui/iter_overeager_cloned.rs | 1 - tests/ui/iter_overeager_cloned.stderr | 14 +- tests/ui/iter_skip_next.fixed | 1 - tests/ui/iter_skip_next.rs | 1 - tests/ui/iter_skip_next.stderr | 14 +- tests/ui/iter_skip_next_unfixable.rs | 2 +- tests/ui/iter_skip_zero.fixed | 1 - tests/ui/iter_skip_zero.rs | 1 - tests/ui/iter_skip_zero.stderr | 10 +- tests/ui/iter_with_drain.fixed | 1 - tests/ui/iter_with_drain.rs | 1 - tests/ui/iter_with_drain.stderr | 12 +- tests/ui/large_const_arrays.fixed | 2 - tests/ui/large_const_arrays.rs | 2 - tests/ui/large_const_arrays.stderr | 18 +- tests/ui/large_digit_groups.fixed | 1 - tests/ui/large_digit_groups.rs | 1 - tests/ui/large_digit_groups.stderr | 10 +- tests/ui/large_enum_variant.rs | 2 +- tests/ui/large_futures.fixed | 62 ++ tests/ui/large_types_passed_by_value.rs | 2 +- tests/ui/len_zero.fixed | 2 - tests/ui/len_zero.rs | 2 - tests/ui/len_zero.stderr | 46 +- tests/ui/len_zero_ranges.fixed | 2 - tests/ui/len_zero_ranges.rs | 2 - tests/ui/len_zero_ranges.stderr | 4 +- tests/ui/let_and_return.fixed | 182 +++++ tests/ui/let_if_seq.rs | 2 +- tests/ui/let_underscore_future.rs | 2 +- tests/ui/let_unit.fixed | 2 - tests/ui/let_unit.rs | 2 - tests/ui/let_unit.stderr | 20 +- tests/ui/lines_filter_map_ok.fixed | 2 - tests/ui/lines_filter_map_ok.rs | 2 - tests/ui/lines_filter_map_ok.stderr | 16 +- tests/ui/literals.rs | 1 + tests/ui/literals.stderr | 40 +- tests/ui/lossy_float_literal.fixed | 1 - tests/ui/lossy_float_literal.rs | 1 - tests/ui/lossy_float_literal.stderr | 22 +- tests/ui/macro_use_imports.fixed | 2 +- tests/ui/macro_use_imports.rs | 2 +- tests/ui/macro_use_imports.stderr | 16 +- tests/ui/manual_assert.edition2018.fixed | 1 - tests/ui/manual_assert.edition2018.stderr | 18 +- tests/ui/manual_assert.edition2021.fixed | 1 - tests/ui/manual_assert.edition2021.stderr | 18 +- tests/ui/manual_assert.rs | 1 - tests/ui/manual_async_fn.fixed | 1 - tests/ui/manual_async_fn.rs | 1 - tests/ui/manual_async_fn.stderr | 26 +- tests/ui/manual_bits.fixed | 2 - tests/ui/manual_bits.rs | 2 - tests/ui/manual_bits.stderr | 58 +- tests/ui/manual_clamp.fixed | 260 ++++++++ tests/ui/manual_filter.fixed | 2 - tests/ui/manual_filter.rs | 2 - tests/ui/manual_filter.stderr | 30 +- tests/ui/manual_filter_map.fixed | 1 - tests/ui/manual_filter_map.rs | 1 - tests/ui/manual_filter_map.stderr | 76 +-- tests/ui/manual_find.rs | 2 +- tests/ui/manual_find_fixable.fixed | 1 - tests/ui/manual_find_fixable.rs | 1 - tests/ui/manual_find_fixable.stderr | 24 +- tests/ui/manual_find_map.fixed | 1 - tests/ui/manual_find_map.rs | 1 - tests/ui/manual_find_map.stderr | 78 +-- tests/ui/manual_flatten.rs | 2 +- tests/ui/manual_float_methods.rs | 1 + tests/ui/manual_float_methods.stderr | 12 +- tests/ui/manual_instant_elapsed.fixed | 1 - tests/ui/manual_instant_elapsed.rs | 1 - tests/ui/manual_instant_elapsed.stderr | 4 +- tests/ui/manual_is_ascii_check.fixed | 2 - tests/ui/manual_is_ascii_check.rs | 2 - tests/ui/manual_is_ascii_check.stderr | 40 +- tests/ui/manual_let_else.rs | 2 +- tests/ui/manual_let_else_match.fixed | 135 ++++ tests/ui/manual_let_else_question_mark.fixed | 1 - tests/ui/manual_let_else_question_mark.rs | 1 - tests/ui/manual_let_else_question_mark.stderr | 12 +- tests/ui/manual_main_separator_str.fixed | 2 - tests/ui/manual_main_separator_str.rs | 2 - tests/ui/manual_main_separator_str.stderr | 8 +- tests/ui/manual_map_option.fixed | 2 - tests/ui/manual_map_option.rs | 2 - tests/ui/manual_map_option.stderr | 42 +- tests/ui/manual_map_option_2.fixed | 2 - tests/ui/manual_map_option_2.rs | 2 - tests/ui/manual_map_option_2.stderr | 10 +- tests/ui/manual_memcpy/with_loop_counters.rs | 2 +- .../ui/manual_memcpy/without_loop_counters.rs | 2 +- tests/ui/manual_next_back.fixed | 2 - tests/ui/manual_next_back.rs | 2 - tests/ui/manual_next_back.stderr | 4 +- tests/ui/manual_non_exhaustive_enum.rs | 2 +- tests/ui/manual_non_exhaustive_struct.rs | 2 +- tests/ui/manual_ok_or.fixed | 1 - tests/ui/manual_ok_or.rs | 1 - tests/ui/manual_ok_or.stderr | 8 +- tests/ui/manual_range_patterns.fixed | 2 - tests/ui/manual_range_patterns.rs | 2 - tests/ui/manual_range_patterns.stderr | 18 +- tests/ui/manual_rem_euclid.fixed | 1 - tests/ui/manual_rem_euclid.rs | 1 - tests/ui/manual_rem_euclid.stderr | 20 +- tests/ui/manual_retain.fixed | 1 - tests/ui/manual_retain.rs | 1 - tests/ui/manual_retain.stderr | 38 +- tests/ui/manual_saturating_arithmetic.fixed | 2 - tests/ui/manual_saturating_arithmetic.rs | 2 - tests/ui/manual_saturating_arithmetic.stderr | 48 +- tests/ui/manual_slice_size_calculation.fixed | 1 - tests/ui/manual_slice_size_calculation.rs | 1 - tests/ui/manual_slice_size_calculation.stderr | 14 +- tests/ui/manual_split_once.fixed | 2 - tests/ui/manual_split_once.rs | 2 - tests/ui/manual_split_once.stderr | 38 +- tests/ui/manual_str_repeat.fixed | 2 - tests/ui/manual_str_repeat.rs | 2 - tests/ui/manual_str_repeat.stderr | 20 +- tests/ui/manual_string_new.fixed | 2 - tests/ui/manual_string_new.rs | 2 - tests/ui/manual_string_new.stderr | 18 +- tests/ui/manual_strip.rs | 2 +- tests/ui/manual_try_fold.rs | 2 +- tests/ui/manual_unwrap_or.fixed | 1 - tests/ui/manual_unwrap_or.rs | 1 - tests/ui/manual_unwrap_or.stderr | 28 +- tests/ui/manual_while_let_some.fixed | 2 - tests/ui/manual_while_let_some.rs | 2 - tests/ui/manual_while_let_some.stderr | 14 +- tests/ui/map_clone.fixed | 1 - tests/ui/map_clone.rs | 1 - tests/ui/map_clone.stderr | 12 +- tests/ui/map_collect_result_unit.fixed | 1 - tests/ui/map_collect_result_unit.rs | 1 - tests/ui/map_collect_result_unit.stderr | 4 +- tests/ui/map_flatten.rs | 2 +- tests/ui/map_flatten_fixable.fixed | 2 - tests/ui/map_flatten_fixable.rs | 2 - tests/ui/map_flatten_fixable.stderr | 18 +- tests/ui/map_identity.fixed | 1 - tests/ui/map_identity.rs | 1 - tests/ui/map_identity.stderr | 12 +- tests/ui/map_unwrap_or.rs | 2 +- tests/ui/map_unwrap_or_fixable.fixed | 1 - tests/ui/map_unwrap_or_fixable.rs | 1 - tests/ui/map_unwrap_or_fixable.stderr | 4 +- tests/ui/match_as_ref.fixed | 2 - tests/ui/match_as_ref.rs | 2 - tests/ui/match_as_ref.stderr | 6 +- tests/ui/match_bool.rs | 1 + tests/ui/match_bool.stderr | 18 +- tests/ui/match_expr_like_matches_macro.fixed | 2 - tests/ui/match_expr_like_matches_macro.rs | 2 - tests/ui/match_expr_like_matches_macro.stderr | 28 +- tests/ui/match_on_vec_items.rs | 2 +- tests/ui/match_ref_pats.fixed | 1 - tests/ui/match_ref_pats.rs | 1 - tests/ui/match_ref_pats.stderr | 10 +- tests/ui/match_result_ok.fixed | 1 - tests/ui/match_result_ok.rs | 1 - tests/ui/match_result_ok.stderr | 6 +- tests/ui/match_same_arms.rs | 1 + tests/ui/match_same_arms.stderr | 32 +- tests/ui/match_same_arms2.rs | 2 +- tests/ui/match_same_arms_non_exhaustive.rs | 2 +- tests/ui/match_single_binding.fixed | 1 - tests/ui/match_single_binding.rs | 1 - tests/ui/match_single_binding.stderr | 48 +- tests/ui/match_single_binding2.fixed | 1 - tests/ui/match_single_binding2.rs | 1 - tests/ui/match_single_binding2.stderr | 8 +- tests/ui/match_str_case_mismatch.fixed | 1 - tests/ui/match_str_case_mismatch.rs | 1 - tests/ui/match_str_case_mismatch.stderr | 14 +- .../match_wildcard_for_single_variants.fixed | 2 - .../ui/match_wildcard_for_single_variants.rs | 2 - .../match_wildcard_for_single_variants.stderr | 20 +- tests/ui/mem_replace.fixed | 2 - tests/ui/mem_replace.rs | 2 - tests/ui/mem_replace.stderr | 48 +- tests/ui/methods_fixable.fixed | 2 - tests/ui/methods_fixable.rs | 2 - tests/ui/methods_fixable.stderr | 2 +- tests/ui/methods_unfixable.rs | 2 +- tests/ui/mismatched_target_os_non_unix.fixed | 2 - tests/ui/mismatched_target_os_non_unix.rs | 2 - tests/ui/mismatched_target_os_non_unix.stderr | 8 +- tests/ui/mismatched_target_os_unix.fixed | 2 - tests/ui/mismatched_target_os_unix.rs | 2 - tests/ui/mismatched_target_os_unix.stderr | 34 +- tests/ui/misnamed_getters.fixed | 124 ++++ tests/ui/missing_spin_loop.fixed | 1 - tests/ui/missing_spin_loop.rs | 1 - tests/ui/missing_spin_loop.stderr | 12 +- tests/ui/missing_spin_loop_no_std.fixed | 1 - tests/ui/missing_spin_loop_no_std.rs | 1 - tests/ui/missing_spin_loop_no_std.stderr | 2 +- tests/ui/mistyped_literal_suffix.fixed | 1 - tests/ui/mistyped_literal_suffix.rs | 1 - tests/ui/mistyped_literal_suffix.stderr | 32 +- tests/ui/must_use_candidates.fixed | 1 - tests/ui/must_use_candidates.rs | 1 - tests/ui/must_use_candidates.stderr | 10 +- tests/ui/must_use_unit.fixed | 1 - tests/ui/must_use_unit.rs | 1 - tests/ui/must_use_unit.stderr | 6 +- tests/ui/mut_key.rs | 2 +- tests/ui/mut_mutex_lock.fixed | 1 - tests/ui/mut_mutex_lock.rs | 1 - tests/ui/mut_mutex_lock.stderr | 2 +- tests/ui/mut_reference.rs | 2 +- tests/ui/needless_arbitrary_self_type.fixed | 2 - tests/ui/needless_arbitrary_self_type.rs | 2 - tests/ui/needless_arbitrary_self_type.stderr | 12 +- ...edless_arbitrary_self_type_unfixable.fixed | 46 ++ tests/ui/needless_bitwise_bool.fixed | 2 - tests/ui/needless_bitwise_bool.rs | 2 - tests/ui/needless_bitwise_bool.stderr | 2 +- tests/ui/needless_bool/fixable.fixed | 2 - tests/ui/needless_bool/fixable.rs | 2 - tests/ui/needless_bool/fixable.stderr | 42 +- tests/ui/needless_bool_assign.fixed | 2 - tests/ui/needless_bool_assign.rs | 2 - tests/ui/needless_bool_assign.stderr | 10 +- tests/ui/needless_borrow.fixed | 1 - tests/ui/needless_borrow.rs | 1 - tests/ui/needless_borrow.stderr | 72 +- tests/ui/needless_borrow_pat.fixed | 150 +++++ tests/ui/needless_borrowed_ref.fixed | 2 - tests/ui/needless_borrowed_ref.rs | 2 - tests/ui/needless_borrowed_ref.stderr | 34 +- tests/ui/needless_collect.fixed | 2 - tests/ui/needless_collect.rs | 2 - tests/ui/needless_collect.stderr | 38 +- tests/ui/needless_collect_indirect.rs | 2 +- tests/ui/needless_else.fixed | 1 - tests/ui/needless_else.rs | 1 - tests/ui/needless_else.stderr | 2 +- tests/ui/needless_for_each_fixable.fixed | 1 - tests/ui/needless_for_each_fixable.rs | 1 - tests/ui/needless_for_each_fixable.stderr | 16 +- tests/ui/needless_for_each_unfixable.rs | 1 + tests/ui/needless_for_each_unfixable.stderr | 2 +- tests/ui/needless_if.fixed | 1 - tests/ui/needless_if.rs | 1 - tests/ui/needless_if.stderr | 14 +- tests/ui/needless_late_init.fixed | 1 - tests/ui/needless_late_init.rs | 1 - tests/ui/needless_late_init.stderr | 32 +- tests/ui/needless_lifetimes.fixed | 1 - tests/ui/needless_lifetimes.rs | 1 - tests/ui/needless_lifetimes.stderr | 92 +-- tests/ui/needless_match.fixed | 1 - tests/ui/needless_match.rs | 1 - tests/ui/needless_match.stderr | 26 +- tests/ui/needless_option_as_deref.fixed | 2 - tests/ui/needless_option_as_deref.rs | 2 - tests/ui/needless_option_as_deref.stderr | 6 +- tests/ui/needless_option_take.fixed | 2 - tests/ui/needless_option_take.rs | 2 - tests/ui/needless_option_take.stderr | 2 +- .../needless_parens_on_range_literals.fixed | 1 - tests/ui/needless_parens_on_range_literals.rs | 1 - .../needless_parens_on_range_literals.stderr | 12 +- tests/ui/needless_pass_by_ref_mut.rs | 2 +- tests/ui/needless_pass_by_value.rs | 2 +- tests/ui/needless_pub_self.fixed | 2 +- tests/ui/needless_pub_self.rs | 2 +- tests/ui/needless_question_mark.fixed | 2 - tests/ui/needless_question_mark.rs | 2 - tests/ui/needless_question_mark.stderr | 28 +- tests/ui/needless_range_loop.rs | 2 +- tests/ui/needless_range_loop2.rs | 2 +- tests/ui/needless_raw_string.fixed | 1 - tests/ui/needless_raw_string.rs | 1 - tests/ui/needless_raw_string.stderr | 4 +- tests/ui/needless_raw_string_hashes.fixed | 1 - tests/ui/needless_raw_string_hashes.rs | 1 - tests/ui/needless_raw_string_hashes.stderr | 12 +- tests/ui/needless_return.fixed | 2 - tests/ui/needless_return.rs | 2 - tests/ui/needless_return.stderr | 104 +-- .../needless_return_with_question_mark.fixed | 1 - .../ui/needless_return_with_question_mark.rs | 1 - .../needless_return_with_question_mark.stderr | 2 +- tests/ui/needless_splitn.fixed | 1 - tests/ui/needless_splitn.rs | 1 - tests/ui/needless_splitn.stderr | 26 +- tests/ui/neg_multiply.fixed | 1 - tests/ui/neg_multiply.rs | 1 - tests/ui/neg_multiply.stderr | 16 +- tests/ui/never_loop.rs | 2 +- tests/ui/new_without_default.fixed | 275 ++++++++ tests/ui/no_effect_return.rs | 1 + tests/ui/no_effect_return.stderr | 18 +- tests/ui/no_mangle_with_rust_abi.rs | 1 + tests/ui/no_mangle_with_rust_abi.stderr | 10 +- tests/ui/non_minimal_cfg.fixed | 2 - tests/ui/non_minimal_cfg.rs | 2 - tests/ui/non_minimal_cfg.stderr | 8 +- tests/ui/non_octal_unix_permissions.fixed | 2 +- tests/ui/non_octal_unix_permissions.rs | 2 +- tests/ui/nonminimal_bool.rs | 1 + tests/ui/nonminimal_bool.stderr | 26 +- tests/ui/nonminimal_bool_methods.fixed | 1 - tests/ui/nonminimal_bool_methods.rs | 1 - tests/ui/nonminimal_bool_methods.stderr | 26 +- tests/ui/numbered_fields.fixed | 1 - tests/ui/numbered_fields.rs | 1 - tests/ui/numbered_fields.stderr | 4 +- tests/ui/obfuscated_if_else.fixed | 2 - tests/ui/obfuscated_if_else.rs | 2 - tests/ui/obfuscated_if_else.stderr | 2 +- tests/ui/octal_escapes.rs | 1 + tests/ui/octal_escapes.stderr | 18 +- tests/ui/only_used_in_recursion.rs | 2 +- tests/ui/only_used_in_recursion2.rs | 2 +- tests/ui/op_ref.fixed | 94 +++ tests/ui/option_as_ref_deref.fixed | 2 - tests/ui/option_as_ref_deref.rs | 2 - tests/ui/option_as_ref_deref.stderr | 36 +- tests/ui/option_filter_map.fixed | 1 - tests/ui/option_filter_map.rs | 1 - tests/ui/option_filter_map.stderr | 16 +- tests/ui/option_if_let_else.fixed | 1 - tests/ui/option_if_let_else.rs | 1 - tests/ui/option_if_let_else.stderr | 46 +- tests/ui/option_map_or_none.fixed | 2 - tests/ui/option_map_or_none.rs | 2 - tests/ui/option_map_or_none.stderr | 10 +- tests/ui/option_map_unit_fn_fixable.fixed | 1 - tests/ui/option_map_unit_fn_fixable.rs | 1 - tests/ui/option_map_unit_fn_fixable.stderr | 38 +- tests/ui/or_fun_call.fixed | 1 - tests/ui/or_fun_call.rs | 1 - tests/ui/or_fun_call.stderr | 62 +- tests/ui/or_then_unwrap.fixed | 2 - tests/ui/or_then_unwrap.rs | 2 - tests/ui/or_then_unwrap.stderr | 6 +- tests/ui/overly_complex_bool_expr.fixed | 34 + tests/ui/partialeq_to_none.fixed | 1 - tests/ui/partialeq_to_none.rs | 1 - tests/ui/partialeq_to_none.stderr | 30 +- tests/ui/path_buf_push_overwrite.fixed | 1 - tests/ui/path_buf_push_overwrite.rs | 1 - tests/ui/path_buf_push_overwrite.stderr | 2 +- tests/ui/patterns.fixed | 1 - tests/ui/patterns.rs | 1 - tests/ui/patterns.stderr | 6 +- tests/ui/precedence.fixed | 1 - tests/ui/precedence.rs | 1 - tests/ui/precedence.stderr | 24 +- tests/ui/print_in_format_impl.rs | 2 +- tests/ui/print_literal.fixed | 45 ++ tests/ui/print_with_newline.fixed | 1 - tests/ui/print_with_newline.rs | 1 - tests/ui/print_with_newline.stderr | 18 +- tests/ui/println_empty_string.fixed | 1 - tests/ui/println_empty_string.rs | 1 - tests/ui/println_empty_string.stderr | 8 +- tests/ui/ptr_arg.rs | 2 +- tests/ui/ptr_as_ptr.fixed | 1 - tests/ui/ptr_as_ptr.rs | 1 - tests/ui/ptr_as_ptr.stderr | 18 +- tests/ui/ptr_cast_constness.fixed | 1 - tests/ui/ptr_cast_constness.rs | 1 - tests/ui/ptr_cast_constness.stderr | 14 +- tests/ui/ptr_eq.fixed | 1 - tests/ui/ptr_eq.rs | 1 - tests/ui/ptr_eq.stderr | 4 +- tests/ui/ptr_offset_with_cast.fixed | 1 - tests/ui/ptr_offset_with_cast.rs | 1 - tests/ui/ptr_offset_with_cast.stderr | 4 +- 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 | 1 - tests/ui/question_mark.rs | 1 - tests/ui/question_mark.stderr | 32 +- tests/ui/range_contains.fixed | 2 - tests/ui/range_contains.rs | 2 - tests/ui/range_contains.stderr | 42 +- tests/ui/range_plus_minus_one.fixed | 2 - tests/ui/range_plus_minus_one.rs | 2 - tests/ui/range_plus_minus_one.stderr | 18 +- tests/ui/rc_buffer.fixed | 1 - tests/ui/rc_buffer.rs | 1 - tests/ui/rc_buffer.stderr | 16 +- tests/ui/rc_buffer_arc.fixed | 1 - tests/ui/rc_buffer_arc.rs | 1 - tests/ui/rc_buffer_arc.stderr | 16 +- tests/ui/rc_clone_in_vec_init/arc.rs | 1 + tests/ui/rc_clone_in_vec_init/arc.stderr | 8 +- tests/ui/rc_clone_in_vec_init/rc.rs | 1 + tests/ui/rc_clone_in_vec_init/rc.stderr | 8 +- tests/ui/rc_clone_in_vec_init/weak.rs | 1 + tests/ui/rc_clone_in_vec_init/weak.stderr | 16 +- tests/ui/read_line_without_trim.fixed | 2 - tests/ui/read_line_without_trim.rs | 2 - tests/ui/read_line_without_trim.stderr | 20 +- tests/ui/read_zero_byte_vec.rs | 2 +- tests/ui/readonly_write_lock.fixed | 42 ++ tests/ui/redundant_allocation_fixable.fixed | 1 - tests/ui/redundant_allocation_fixable.rs | 1 - tests/ui/redundant_allocation_fixable.stderr | 24 +- tests/ui/redundant_async_block.fixed | 2 - tests/ui/redundant_async_block.rs | 2 - tests/ui/redundant_async_block.stderr | 20 +- tests/ui/redundant_at_rest_pattern.fixed | 1 - tests/ui/redundant_at_rest_pattern.rs | 1 - tests/ui/redundant_at_rest_pattern.stderr | 12 +- tests/ui/redundant_clone.fixed | 1 - tests/ui/redundant_clone.rs | 1 - tests/ui/redundant_clone.stderr | 60 +- tests/ui/redundant_closure_call_fixable.fixed | 2 - tests/ui/redundant_closure_call_fixable.rs | 2 - .../ui/redundant_closure_call_fixable.stderr | 28 +- tests/ui/redundant_field_names.fixed | 2 - tests/ui/redundant_field_names.rs | 2 - tests/ui/redundant_field_names.stderr | 16 +- tests/ui/redundant_guards.fixed | 1 - tests/ui/redundant_guards.rs | 1 - tests/ui/redundant_guards.stderr | 16 +- ...edundant_pattern_matching_drop_order.fixed | 2 - .../redundant_pattern_matching_drop_order.rs | 2 - ...dundant_pattern_matching_drop_order.stderr | 44 +- .../redundant_pattern_matching_ipaddr.fixed | 1 - tests/ui/redundant_pattern_matching_ipaddr.rs | 1 - .../redundant_pattern_matching_ipaddr.stderr | 36 +- .../redundant_pattern_matching_option.fixed | 2 - tests/ui/redundant_pattern_matching_option.rs | 2 - .../redundant_pattern_matching_option.stderr | 60 +- .../ui/redundant_pattern_matching_poll.fixed | 2 - tests/ui/redundant_pattern_matching_poll.rs | 2 - .../ui/redundant_pattern_matching_poll.stderr | 36 +- .../redundant_pattern_matching_result.fixed | 1 - tests/ui/redundant_pattern_matching_result.rs | 1 - .../redundant_pattern_matching_result.stderr | 56 +- tests/ui/redundant_pub_crate.fixed | 1 - tests/ui/redundant_pub_crate.rs | 1 - tests/ui/redundant_pub_crate.stderr | 32 +- tests/ui/redundant_slicing.fixed | 2 - tests/ui/redundant_slicing.rs | 2 - tests/ui/redundant_slicing.stderr | 6 +- tests/ui/redundant_static_lifetimes.fixed | 2 - tests/ui/redundant_static_lifetimes.rs | 2 - tests/ui/redundant_static_lifetimes.stderr | 36 +- .../ui/redundant_static_lifetimes_multiple.rs | 1 + ...redundant_static_lifetimes_multiple.stderr | 20 +- tests/ui/ref_binding_to_reference.rs | 2 +- tests/ui/ref_option_ref.rs | 2 +- tests/ui/rename.fixed | 2 - tests/ui/rename.rs | 2 - tests/ui/rename.stderr | 108 +-- tests/ui/renamed_builtin_attr.fixed | 2 - tests/ui/renamed_builtin_attr.rs | 2 - tests/ui/renamed_builtin_attr.stderr | 2 +- tests/ui/repeat_once.fixed | 1 - tests/ui/repeat_once.rs | 1 - tests/ui/repeat_once.stderr | 12 +- tests/ui/repl_uninit.rs | 2 +- tests/ui/result_map_or_into_option.fixed | 2 - tests/ui/result_map_or_into_option.rs | 2 - tests/ui/result_map_or_into_option.stderr | 2 +- tests/ui/result_map_unit_fn_fixable.fixed | 1 - tests/ui/result_map_unit_fn_fixable.rs | 1 - tests/ui/result_map_unit_fn_fixable.stderr | 36 +- tests/ui/result_map_unit_fn_unfixable.rs | 2 +- tests/ui/reversed_empty_ranges_fixable.fixed | 1 - tests/ui/reversed_empty_ranges_fixable.rs | 1 - tests/ui/reversed_empty_ranges_fixable.stderr | 8 +- .../reversed_empty_ranges_loops_fixable.fixed | 1 - .../ui/reversed_empty_ranges_loops_fixable.rs | 1 - ...reversed_empty_ranges_loops_fixable.stderr | 12 +- tests/ui/search_is_some.rs | 2 +- tests/ui/search_is_some_fixable_none.fixed | 1 - tests/ui/search_is_some_fixable_none.rs | 1 - tests/ui/search_is_some_fixable_none.stderr | 86 +-- tests/ui/search_is_some_fixable_some.fixed | 1 - tests/ui/search_is_some_fixable_some.rs | 1 - tests/ui/search_is_some_fixable_some.stderr | 94 +-- tests/ui/seek_from_current.fixed | 1 - tests/ui/seek_from_current.rs | 1 - tests/ui/seek_from_current.stderr | 2 +- .../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/semicolon_if_nothing_returned.fixed | 1 - tests/ui/semicolon_if_nothing_returned.rs | 1 - tests/ui/semicolon_if_nothing_returned.stderr | 10 +- tests/ui/semicolon_inside_block.fixed | 1 - tests/ui/semicolon_inside_block.rs | 1 - tests/ui/semicolon_inside_block.stderr | 8 +- tests/ui/semicolon_outside_block.fixed | 1 - tests/ui/semicolon_outside_block.rs | 1 - tests/ui/semicolon_outside_block.stderr | 8 +- tests/ui/short_circuit_statement.fixed | 2 - tests/ui/short_circuit_statement.rs | 2 - tests/ui/short_circuit_statement.stderr | 6 +- tests/ui/should_impl_trait/method_list_2.rs | 2 +- tests/ui/significant_drop_in_scrutinee.fixed | 627 ------------------ tests/ui/significant_drop_in_scrutinee.rs | 2 +- tests/ui/significant_drop_tightening.fixed | 2 - tests/ui/significant_drop_tightening.rs | 2 - tests/ui/significant_drop_tightening.stderr | 8 +- tests/ui/single_char_add_str.fixed | 1 - tests/ui/single_char_add_str.rs | 1 - tests/ui/single_char_add_str.stderr | 30 +- tests/ui/single_char_pattern.fixed | 2 - tests/ui/single_char_pattern.rs | 2 - tests/ui/single_char_pattern.stderr | 78 +-- tests/ui/single_component_path_imports.fixed | 1 - tests/ui/single_component_path_imports.rs | 1 - tests/ui/single_component_path_imports.stderr | 4 +- ...gle_component_path_imports_nested_first.rs | 2 +- tests/ui/single_element_loop.fixed | 1 - tests/ui/single_element_loop.rs | 1 - tests/ui/single_element_loop.stderr | 14 +- tests/ui/single_match.fixed | 1 - tests/ui/single_match.rs | 1 - tests/ui/single_match.stderr | 36 +- tests/ui/single_match_else.fixed | 1 - tests/ui/single_match_else.rs | 1 - tests/ui/single_match_else.stderr | 18 +- tests/ui/single_range_in_vec_init.rs | 1 + tests/ui/single_range_in_vec_init.stderr | 20 +- tests/ui/slow_vector_initialization.rs | 2 +- tests/ui/stable_sort_primitive.fixed | 1 - tests/ui/stable_sort_primitive.rs | 1 - tests/ui/stable_sort_primitive.stderr | 14 +- tests/ui/starts_ends_with.fixed | 1 - tests/ui/starts_ends_with.rs | 1 - tests/ui/starts_ends_with.stderr | 32 +- tests/ui/string_add.rs | 2 +- tests/ui/string_add_assign.fixed | 2 - tests/ui/string_add_assign.rs | 2 - tests/ui/string_add_assign.stderr | 6 +- tests/ui/string_extend.fixed | 2 - tests/ui/string_extend.rs | 2 - tests/ui/string_extend.stderr | 8 +- tests/ui/string_from_utf8_as_bytes.fixed | 1 - tests/ui/string_from_utf8_as_bytes.rs | 1 - tests/ui/string_from_utf8_as_bytes.stderr | 2 +- tests/ui/string_lit_as_bytes.fixed | 1 - tests/ui/string_lit_as_bytes.rs | 1 - tests/ui/string_lit_as_bytes.stderr | 14 +- tests/ui/string_lit_chars_any.fixed | 1 - tests/ui/string_lit_chars_any.rs | 1 - tests/ui/string_lit_chars_any.stderr | 10 +- tests/ui/strlen_on_c_strings.fixed | 2 - tests/ui/strlen_on_c_strings.rs | 2 - tests/ui/strlen_on_c_strings.stderr | 14 +- tests/ui/suspicious_command_arg_space.fixed | 10 + 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_operation_groupings.fixed | 1 - tests/ui/suspicious_operation_groupings.rs | 1 - .../ui/suspicious_operation_groupings.stderr | 52 +- tests/ui/suspicious_to_owned.rs | 1 + tests/ui/suspicious_to_owned.stderr | 12 +- tests/ui/suspicious_xor_used_as_pow.rs | 2 +- tests/ui/swap.fixed | 1 - tests/ui/swap.rs | 1 - tests/ui/swap.stderr | 34 +- tests/ui/swap_ptr_to_ref.fixed | 2 - tests/ui/swap_ptr_to_ref.rs | 2 - tests/ui/swap_ptr_to_ref.stderr | 8 +- tests/ui/tabs_in_doc_comments.fixed | 2 - tests/ui/tabs_in_doc_comments.rs | 2 - tests/ui/tabs_in_doc_comments.stderr | 16 +- tests/ui/to_digit_is_some.fixed | 2 - tests/ui/to_digit_is_some.rs | 2 - tests/ui/to_digit_is_some.stderr | 4 +- ...to_string_in_format_args_incremental.fixed | 1 - .../to_string_in_format_args_incremental.rs | 1 - ...o_string_in_format_args_incremental.stderr | 2 +- tests/ui/toplevel_ref_arg.fixed | 1 - tests/ui/toplevel_ref_arg.rs | 1 - tests/ui/toplevel_ref_arg.stderr | 12 +- tests/ui/trailing_zeros.fixed | 10 + tests/ui/trait_duplication_in_bounds.fixed | 1 - tests/ui/trait_duplication_in_bounds.rs | 1 - tests/ui/trait_duplication_in_bounds.stderr | 20 +- tests/ui/transmute.rs | 2 +- tests/ui/transmute_float_to_int.fixed | 25 + tests/ui/transmute_int_to_non_zero.fixed | 41 ++ tests/ui/transmute_ptr_to_ptr.fixed | 63 ++ tests/ui/transmute_ptr_to_ref.fixed | 2 - tests/ui/transmute_ptr_to_ref.rs | 2 - tests/ui/transmute_ptr_to_ref.stderr | 44 +- .../transmutes_expressible_as_ptr_casts.fixed | 1 - .../ui/transmutes_expressible_as_ptr_casts.rs | 1 - ...transmutes_expressible_as_ptr_casts.stderr | 20 +- tests/ui/trim_split_whitespace.fixed | 1 - tests/ui/trim_split_whitespace.rs | 1 - tests/ui/trim_split_whitespace.stderr | 16 +- tests/ui/trivially_copy_pass_by_ref.rs | 2 +- tests/ui/try_err.fixed | 1 - tests/ui/try_err.rs | 1 - tests/ui/try_err.stderr | 24 +- tests/ui/type_id_on_box.fixed | 2 - tests/ui/type_id_on_box.rs | 2 - tests/ui/type_id_on_box.stderr | 6 +- tests/ui/types.fixed | 2 - tests/ui/types.rs | 2 - tests/ui/types.stderr | 2 +- tests/ui/unchecked_duration_subtraction.fixed | 1 - tests/ui/unchecked_duration_subtraction.rs | 1 - .../ui/unchecked_duration_subtraction.stderr | 8 +- tests/ui/unicode.fixed | 1 - tests/ui/unicode.rs | 1 - tests/ui/unicode.stderr | 20 +- tests/ui/uninlined_format_args.fixed | 2 +- tests/ui/uninlined_format_args.rs | 2 +- ...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 | 12 +- tests/ui/uninlined_format_args_panic.rs | 1 - tests/ui/unit_arg.rs | 1 + tests/ui/unit_arg.stderr | 20 +- tests/ui/unit_arg_empty_blocks.fixed | 1 - tests/ui/unit_arg_empty_blocks.rs | 1 - tests/ui/unit_arg_empty_blocks.stderr | 8 +- tests/ui/unit_hash.fixed | 28 + tests/ui/unknown_clippy_lints.fixed | 2 - tests/ui/unknown_clippy_lints.rs | 2 - tests/ui/unknown_clippy_lints.stderr | 16 +- tests/ui/unnecessary_box_returns.rs | 2 +- tests/ui/unnecessary_cast.fixed | 1 - tests/ui/unnecessary_cast.rs | 1 - tests/ui/unnecessary_cast.stderr | 80 +-- tests/ui/unnecessary_cast_unfixable.rs | 2 +- tests/ui/unnecessary_clone.rs | 2 +- tests/ui/unnecessary_fold.fixed | 2 - tests/ui/unnecessary_fold.rs | 2 - tests/ui/unnecessary_fold.stderr | 30 +- tests/ui/unnecessary_iter_cloned.fixed | 2 - tests/ui/unnecessary_iter_cloned.rs | 2 - tests/ui/unnecessary_iter_cloned.stderr | 4 +- tests/ui/unnecessary_join.fixed | 1 - tests/ui/unnecessary_join.rs | 1 - tests/ui/unnecessary_join.stderr | 4 +- tests/ui/unnecessary_lazy_eval.fixed | 1 - tests/ui/unnecessary_lazy_eval.rs | 1 - tests/ui/unnecessary_lazy_eval.stderr | 76 +-- tests/ui/unnecessary_lazy_eval_unfixable.rs | 2 +- tests/ui/unnecessary_literal_unwrap.fixed | 1 - tests/ui/unnecessary_literal_unwrap.rs | 1 - tests/ui/unnecessary_literal_unwrap.stderr | 106 +-- .../unnecessary_literal_unwrap_unfixable.rs | 2 +- tests/ui/unnecessary_operation.fixed | 2 - tests/ui/unnecessary_operation.rs | 2 - tests/ui/unnecessary_operation.stderr | 38 +- .../ui/unnecessary_owned_empty_strings.fixed | 2 - tests/ui/unnecessary_owned_empty_strings.rs | 2 - .../ui/unnecessary_owned_empty_strings.stderr | 4 +- tests/ui/unnecessary_self_imports.fixed | 1 - tests/ui/unnecessary_self_imports.rs | 1 - tests/ui/unnecessary_self_imports.stderr | 4 +- tests/ui/unnecessary_sort_by.fixed | 2 - tests/ui/unnecessary_sort_by.rs | 2 - tests/ui/unnecessary_sort_by.stderr | 24 +- .../unnecessary_struct_initialization.fixed | 2 - tests/ui/unnecessary_struct_initialization.rs | 2 - .../unnecessary_struct_initialization.stderr | 12 +- tests/ui/unnecessary_to_owned.fixed | 2 - tests/ui/unnecessary_to_owned.rs | 2 - tests/ui/unnecessary_to_owned.stderr | 168 ++--- tests/ui/unnecessary_wraps.rs | 1 + tests/ui/unnecessary_wraps.stderr | 14 +- tests/ui/unneeded_wildcard_pattern.fixed | 1 - tests/ui/unneeded_wildcard_pattern.rs | 1 - tests/ui/unneeded_wildcard_pattern.stderr | 30 +- tests/ui/unnested_or_patterns.fixed | 2 - tests/ui/unnested_or_patterns.rs | 2 - tests/ui/unnested_or_patterns.stderr | 34 +- tests/ui/unnested_or_patterns2.fixed | 2 - tests/ui/unnested_or_patterns2.rs | 2 - tests/ui/unnested_or_patterns2.stderr | 16 +- tests/ui/unreadable_literal.fixed | 2 - tests/ui/unreadable_literal.rs | 2 - tests/ui/unreadable_literal.stderr | 20 +- tests/ui/unseparated_prefix_literals.fixed | 1 - tests/ui/unseparated_prefix_literals.rs | 1 - tests/ui/unseparated_prefix_literals.stderr | 18 +- tests/ui/unused_format_specs_unfixable.rs | 2 +- tests/ui/unused_rounding.fixed | 1 - tests/ui/unused_rounding.rs | 1 - tests/ui/unused_rounding.stderr | 10 +- tests/ui/unused_unit.fixed | 2 +- tests/ui/unused_unit.rs | 2 +- tests/ui/unwrap_or.fixed | 10 + tests/ui/unwrap_or_else_default.fixed | 2 - tests/ui/unwrap_or_else_default.rs | 2 - tests/ui/unwrap_or_else_default.stderr | 32 +- tests/ui/upper_case_acronyms.fixed | 50 ++ tests/ui/use_self.fixed | 1 - tests/ui/use_self.rs | 1 - tests/ui/use_self.stderr | 84 +-- tests/ui/use_self_trait.fixed | 2 - tests/ui/use_self_trait.rs | 2 - tests/ui/use_self_trait.stderr | 32 +- tests/ui/useless_asref.fixed | 1 - tests/ui/useless_asref.rs | 1 - tests/ui/useless_asref.stderr | 24 +- tests/ui/useless_attribute.fixed | 1 - tests/ui/useless_attribute.rs | 1 - tests/ui/useless_attribute.stderr | 6 +- tests/ui/useless_conversion.fixed | 2 - tests/ui/useless_conversion.rs | 2 - tests/ui/useless_conversion.stderr | 60 +- tests/ui/vec.fixed | 1 - tests/ui/vec.rs | 1 - tests/ui/vec.stderr | 38 +- tests/ui/vec_box_sized.fixed | 2 - tests/ui/vec_box_sized.rs | 2 - tests/ui/vec_box_sized.stderr | 12 +- tests/ui/vec_init_then_push.rs | 2 +- tests/ui/vec_resize_to_zero.fixed | 19 + tests/ui/while_let_loop.rs | 2 +- tests/ui/while_let_on_iterator.fixed | 1 - tests/ui/while_let_on_iterator.rs | 1 - tests/ui/while_let_on_iterator.stderr | 52 +- tests/ui/wildcard_enum_match_arm.fixed | 1 - tests/ui/wildcard_enum_match_arm.rs | 1 - tests/ui/wildcard_enum_match_arm.stderr | 14 +- tests/ui/wildcard_imports.fixed | 2 +- tests/ui/wildcard_imports.rs | 2 +- .../wildcard_imports_2021.edition2018.fixed | 2 +- .../wildcard_imports_2021.edition2021.fixed | 2 +- tests/ui/wildcard_imports_2021.rs | 2 +- tests/ui/write_literal.fixed | 45 ++ tests/ui/write_literal_2.rs | 1 + tests/ui/write_literal_2.stderr | 36 +- tests/ui/write_with_newline.fixed | 3 +- tests/ui/write_with_newline.rs | 1 - tests/ui/write_with_newline.stderr | 18 +- tests/ui/writeln_empty_string.fixed | 2 - tests/ui/writeln_empty_string.rs | 2 - tests/ui/writeln_empty_string.stderr | 4 +- tests/ui/zero_ptr.fixed | 1 - tests/ui/zero_ptr.rs | 1 - tests/ui/zero_ptr.stderr | 10 +- tests/ui/zero_ptr_no_std.fixed | 2 - tests/ui/zero_ptr_no_std.rs | 2 - tests/ui/zero_ptr_no_std.stderr | 8 +- 1219 files changed, 6850 insertions(+), 5810 deletions(-) create mode 100644 tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed create mode 100644 tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed create mode 100644 tests/ui-toml/large_futures/large_futures.fixed create mode 100644 tests/ui-toml/lint_decimal_readability/test.fixed create mode 100644 tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed create mode 100644 tests/ui-toml/min_rust_version/min_rust_version.fixed create mode 100644 tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed create mode 100644 tests/ui-toml/unwrap_used/unwrap_used.fixed create mode 100644 tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed create mode 100644 tests/ui-toml/vec_box_sized/test.fixed create mode 100644 tests/ui/cfg_features.fixed create mode 100644 tests/ui/crashes/ice-2774.fixed create mode 100644 tests/ui/crashes/ice-3717.fixed create mode 100644 tests/ui/crashes/ice-5835.fixed create mode 100644 tests/ui/crashes/ice-5872.fixed create mode 100644 tests/ui/crashes/ice-7169.fixed create mode 100644 tests/ui/crashes/ice-8250.fixed create mode 100644 tests/ui/crashes/ice-8821.fixed create mode 100644 tests/ui/crashes/ice-8850.fixed create mode 100644 tests/ui/crashes/ice-96721.fixed create mode 100644 tests/ui/crashes/needless_lifetimes_impl_trait.fixed create mode 100644 tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed create mode 100644 tests/ui/crate_level_checks/no_std_swap.fixed create mode 100644 tests/ui/eprint_with_newline.fixed create mode 100644 tests/ui/for_kv_map.fixed create mode 100644 tests/ui/from_str_radix_10.fixed create mode 100644 tests/ui/index_refutable_slice/if_let_slice_binding.fixed create mode 100644 tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed create mode 100644 tests/ui/large_futures.fixed create mode 100644 tests/ui/let_and_return.fixed create mode 100644 tests/ui/manual_clamp.fixed create mode 100644 tests/ui/manual_let_else_match.fixed create mode 100644 tests/ui/misnamed_getters.fixed create mode 100644 tests/ui/needless_arbitrary_self_type_unfixable.fixed create mode 100644 tests/ui/needless_borrow_pat.fixed create mode 100644 tests/ui/new_without_default.fixed create mode 100644 tests/ui/op_ref.fixed create mode 100644 tests/ui/overly_complex_bool_expr.fixed create mode 100644 tests/ui/print_literal.fixed create mode 100644 tests/ui/readonly_write_lock.fixed delete mode 100644 tests/ui/significant_drop_in_scrutinee.fixed create mode 100644 tests/ui/suspicious_command_arg_space.fixed create mode 100644 tests/ui/trailing_zeros.fixed create mode 100644 tests/ui/transmute_float_to_int.fixed create mode 100644 tests/ui/transmute_int_to_non_zero.fixed create mode 100644 tests/ui/transmute_ptr_to_ptr.fixed create mode 100644 tests/ui/unit_hash.fixed create mode 100644 tests/ui/unwrap_or.fixed create mode 100644 tests/ui/upper_case_acronyms.fixed create mode 100644 tests/ui/vec_resize_to_zero.fixed create mode 100644 tests/ui/write_literal.fixed diff --git a/.cargo/config.toml b/.cargo/config.toml index 48a63e4856815..40e841081260f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,7 +1,7 @@ [alias] -uitest = "test --test compile-test" -uibless = "test --test compile-test -- -- --bless" -bless = "test -- -- --bless" +uitest = "test --test compile-test -- --check" +uibless = "test --test compile-test" +bless = "test" dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --" lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- " collect-metadata = "test --test dogfood --features internal -- run_metadata_collection_lint --ignored" diff --git a/Cargo.toml b/Cargo.toml index 0fb3a3a984b19..e957cee3d4216 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ tempfile = { version = "3.2", optional = true } termize = "0.1" [dev-dependencies] -ui_test = "0.11.5" +ui_test = "0.12" tester = "0.9" regex = "1.5" toml = "0.7.3" diff --git a/book/src/development/adding_lints.md b/book/src/development/adding_lints.md index a0db808925021..f6f0c95c72933 100644 --- a/book/src/development/adding_lints.md +++ b/book/src/development/adding_lints.md @@ -161,8 +161,8 @@ The process of generating the `.stderr` file is the same, and prepending the ## Rustfix tests If the lint you are working on is making use of structured suggestions, the test -file should include a `//@run-rustfix` comment at the top. This will -additionally run [rustfix] for that test. Rustfix will apply the suggestions +will create a `.fixed` file by running [rustfix] for that test. +Rustfix will apply the suggestions from the lint to the code of the test file and compare that to the contents of a `.fixed` file. diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs index 7c2e06ea69a65..842aeed2aa401 100644 --- a/clippy_dev/src/update_lints.rs +++ b/clippy_dev/src/update_lints.rs @@ -690,7 +690,6 @@ fn gen_deprecated_lints_test(lints: &[DeprecatedLint]) -> String { fn gen_renamed_lints_test(lints: &[RenamedLint]) -> String { let mut seen_lints = HashSet::new(); let mut res: String = GENERATED_FILE_COMMENT.into(); - res.push_str("//@run-rustfix\n\n"); for lint in lints { if seen_lints.insert(&lint.new_name) { writeln!(res, "#![allow({})]", lint.new_name).unwrap(); diff --git a/tests/compile-test.rs b/tests/compile-test.rs index f9f15f1640ca8..8f90aeb213936 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -5,7 +5,7 @@ #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(unused_extern_crates)] -use compiletest::{status_emitter, CommandBuilder, OutputConflictHandling}; +use compiletest::{status_emitter, Args, CommandBuilder, OutputConflictHandling}; use ui_test as compiletest; use ui_test::Mode as TestMode; @@ -110,13 +110,14 @@ mod test_utils; // whether to run internal tests or not const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal"); -fn base_config(test_dir: &str) -> compiletest::Config { +fn base_config(test_dir: &str) -> (compiletest::Config, Args) { + let args = Args::test(); let mut config = compiletest::Config { mode: TestMode::Yolo, stderr_filters: vec![], stdout_filters: vec![], - output_conflict_handling: if var_os("RUSTC_BLESS").is_some_and(|v| v != "0") - || env::args().any(|arg| arg == "--bless") + output_conflict_handling: if var_os("GITHUB_ACTION").is_none() + && (var_os("RUSTC_BLESS").is_some_and(|v| v != "0") || !args.check) { OutputConflictHandling::Bless } else { @@ -158,7 +159,7 @@ fn base_config(test_dir: &str) -> compiletest::Config { } else { "clippy-driver" }); - config + (config, args) } fn test_filter() -> Box bool> { @@ -171,7 +172,7 @@ fn test_filter() -> Box bool> { } fn run_ui() { - let config = base_config("ui"); + let (config, args) = base_config("ui"); //config.rustfix_coverage = true; // use tests/clippy.toml let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap()); @@ -189,12 +190,12 @@ fn run_ui() { compiletest::run_tests_generic( config, - move |path| compiletest::default_file_filter(path) && test_filter(path), + args, + move |path, args| compiletest::default_file_filter(path, args) && test_filter(path), compiletest::default_per_file_config, - status_emitter::Text, + status_emitter::Text::verbose(), ) .unwrap(); - check_rustfix_coverage(); } fn run_internal_tests() { @@ -202,23 +203,24 @@ fn run_internal_tests() { if !RUN_INTERNAL_TESTS { return; } - let mut config = base_config("ui-internal"); + let (mut config, args) = base_config("ui-internal"); if let OutputConflictHandling::Error(err) = &mut config.output_conflict_handling { - *err = "cargo uitest --features internal -- -- --bless".into(); + *err = "cargo uitest --features internal".into(); } let test_filter = test_filter(); compiletest::run_tests_generic( config, - move |path| compiletest::default_file_filter(path) && test_filter(path), + args, + move |path, args| compiletest::default_file_filter(path, args) && test_filter(path), compiletest::default_per_file_config, - status_emitter::Text, + status_emitter::Text::verbose(), ) .unwrap(); } fn run_ui_toml() { - let mut config = base_config("ui-toml"); + let (mut config, args) = base_config("ui-toml"); config.stderr_filter( ®ex::escape( @@ -237,7 +239,8 @@ fn run_ui_toml() { ui_test::run_tests_generic( config, - |path| compiletest::default_file_filter(path) && test_filter(path), + args, + |path, args| compiletest::default_file_filter(path, args) && test_filter(path), |config, path| { let mut config = config.clone(); config @@ -246,7 +249,7 @@ fn run_ui_toml() { .push(("CLIPPY_CONF_DIR".into(), Some(path.parent().unwrap().into()))); Some(config) }, - status_emitter::Text, + status_emitter::Text::verbose(), ) .unwrap(); } @@ -256,7 +259,7 @@ fn run_ui_cargo() { return; } - let mut config = base_config("ui-cargo"); + let (mut config, args) = base_config("ui-cargo"); config.program.input_file_flag = CommandBuilder::cargo().input_file_flag; config.program.out_dir_flag = CommandBuilder::cargo().out_dir_flag; config.program.args = vec!["clippy".into(), "--color".into(), "never".into(), "--quiet".into()]; @@ -291,13 +294,14 @@ fn run_ui_cargo() { ui_test::run_tests_generic( config, - |path| test_filter(path) && path.ends_with("Cargo.toml"), + args, + |path, _args| test_filter(path) && path.ends_with("Cargo.toml"), |config, path| { let mut config = config.clone(); config.out_dir = PathBuf::from("target/ui_test_cargo/").join(path.parent().unwrap()); Some(config) }, - status_emitter::Text, + status_emitter::Text::verbose(), ) .unwrap(); } @@ -322,7 +326,6 @@ fn main() { "cargo" => run_ui_cargo as fn(), "toml" => run_ui_toml as fn(), "internal" => run_internal_tests as fn(), - "rustfix-coverage-known-exceptions-accuracy" => rustfix_coverage_known_exceptions_accuracy as fn(), "ui-cargo-toml-metadata" => ui_cargo_toml_metadata as fn(), _ => panic!("unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]"), @@ -349,89 +352,10 @@ fn main() { run_ui_toml(); run_ui_cargo(); run_internal_tests(); - rustfix_coverage_known_exceptions_accuracy(); ui_cargo_toml_metadata(); } } -const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS: &[&str] = &[ - "assign_ops2.rs", - "borrow_deref_ref_unfixable.rs", - "cast_size_32bit.rs", - "char_lit_as_u8.rs", - "cmp_owned/without_suggestion.rs", - "dbg_macro.rs", - "deref_addrof_double_trigger.rs", - "doc/unbalanced_ticks.rs", - "eprint_with_newline.rs", - "explicit_counter_loop.rs", - "iter_skip_next_unfixable.rs", - "let_and_return.rs", - "literals.rs", - "map_flatten.rs", - "map_unwrap_or.rs", - "match_bool.rs", - "mem_replace_macro.rs", - "needless_arbitrary_self_type_unfixable.rs", - "needless_borrow_pat.rs", - "needless_for_each_unfixable.rs", - "nonminimal_bool.rs", - "print_literal.rs", - "redundant_static_lifetimes_multiple.rs", - "ref_binding_to_reference.rs", - "repl_uninit.rs", - "result_map_unit_fn_unfixable.rs", - "search_is_some.rs", - "single_component_path_imports_nested_first.rs", - "string_add.rs", - "suspicious_to_owned.rs", - "toplevel_ref_arg_non_rustfix.rs", - "unit_arg.rs", - "unnecessary_clone.rs", - "unnecessary_lazy_eval_unfixable.rs", - "write_literal.rs", - "write_literal_2.rs", -]; - -fn check_rustfix_coverage() { - let missing_coverage_path = Path::new("debug/test/ui/rustfix_missing_coverage.txt"); - let missing_coverage_path = if let Ok(target_dir) = std::env::var("CARGO_TARGET_DIR") { - PathBuf::from(target_dir).join(missing_coverage_path) - } else { - missing_coverage_path.to_path_buf() - }; - - if let Ok(missing_coverage_contents) = std::fs::read_to_string(missing_coverage_path) { - assert!(RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.iter().is_sorted_by_key(Path::new)); - - for rs_file in missing_coverage_contents.lines() { - let rs_path = Path::new(rs_file); - if rs_path.starts_with("tests/ui/crashes") { - continue; - } - assert!(rs_path.starts_with("tests/ui/"), "{rs_file:?}"); - let filename = rs_path.strip_prefix("tests/ui/").unwrap(); - assert!( - RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS - .binary_search_by_key(&filename, Path::new) - .is_ok(), - "`{rs_file}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \ - Please either add `//@run-rustfix` at the top of the file or add the file to \ - `RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS` in `tests/compile-test.rs`.", - ); - } - } -} - -fn rustfix_coverage_known_exceptions_accuracy() { - for filename in RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS { - let rs_path = Path::new("tests/ui").join(filename); - assert!(rs_path.exists(), "`{}` does not exist", rs_path.display()); - let fixed_path = rs_path.with_extension("fixed"); - assert!(!fixed_path.exists(), "`{}` exists", fixed_path.display()); - } -} - fn ui_cargo_toml_metadata() { let ui_cargo_path = Path::new("tests/ui-cargo"); let cargo_common_metadata_path = ui_cargo_path.join("cargo_common_metadata"); diff --git a/tests/ui-internal/collapsible_span_lint_calls.fixed b/tests/ui-internal/collapsible_span_lint_calls.fixed index 72c04bf80b6b1..92c5d994c246d 100644 --- a/tests/ui-internal/collapsible_span_lint_calls.fixed +++ b/tests/ui-internal/collapsible_span_lint_calls.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/tests/ui-internal/collapsible_span_lint_calls.rs b/tests/ui-internal/collapsible_span_lint_calls.rs index 76f7c3ce94d67..1baf6142b3499 100644 --- a/tests/ui-internal/collapsible_span_lint_calls.rs +++ b/tests/ui-internal/collapsible_span_lint_calls.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/tests/ui-internal/interning_defined_symbol.fixed b/tests/ui-internal/interning_defined_symbol.fixed index a1a10c0798e3a..d6f2852c79d78 100644 --- a/tests/ui-internal/interning_defined_symbol.fixed +++ b/tests/ui-internal/interning_defined_symbol.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute, clippy::let_unit_value)] #![feature(rustc_private)] diff --git a/tests/ui-internal/interning_defined_symbol.rs b/tests/ui-internal/interning_defined_symbol.rs index 32dbfe5dcac22..92e92d4fbc16a 100644 --- a/tests/ui-internal/interning_defined_symbol.rs +++ b/tests/ui-internal/interning_defined_symbol.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute, clippy::let_unit_value)] #![feature(rustc_private)] diff --git a/tests/ui-internal/invalid_msrv_attr_impl.fixed b/tests/ui-internal/invalid_msrv_attr_impl.fixed index ac0752774f3f0..fb323794fd511 100644 --- a/tests/ui-internal/invalid_msrv_attr_impl.fixed +++ b/tests/ui-internal/invalid_msrv_attr_impl.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] diff --git a/tests/ui-internal/invalid_msrv_attr_impl.rs b/tests/ui-internal/invalid_msrv_attr_impl.rs index 56f778621a449..50b28648ccc9f 100644 --- a/tests/ui-internal/invalid_msrv_attr_impl.rs +++ b/tests/ui-internal/invalid_msrv_attr_impl.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/tests/ui-internal/outer_expn_data.fixed b/tests/ui-internal/outer_expn_data.fixed index d8a08bc999709..43f919cb35f1a 100644 --- a/tests/ui-internal/outer_expn_data.fixed +++ b/tests/ui-internal/outer_expn_data.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] diff --git a/tests/ui-internal/outer_expn_data.rs b/tests/ui-internal/outer_expn_data.rs index f7af0e9d8be2e..fb453be661c8b 100644 --- a/tests/ui-internal/outer_expn_data.rs +++ b/tests/ui-internal/outer_expn_data.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/tests/ui-internal/unnecessary_def_path.fixed b/tests/ui-internal/unnecessary_def_path.fixed index fce24412f8439..ab2412683b6d0 100644 --- a/tests/ui-internal/unnecessary_def_path.fixed +++ b/tests/ui-internal/unnecessary_def_path.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + //@aux-build:paths.rs #![deny(clippy::internal)] #![feature(rustc_private)] diff --git a/tests/ui-internal/unnecessary_def_path.rs b/tests/ui-internal/unnecessary_def_path.rs index b10bc9e46e2d7..632e26215a4db 100644 --- a/tests/ui-internal/unnecessary_def_path.rs +++ b/tests/ui-internal/unnecessary_def_path.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:paths.rs #![deny(clippy::internal)] #![feature(rustc_private)] diff --git a/tests/ui-internal/unnecessary_symbol_str.fixed b/tests/ui-internal/unnecessary_symbol_str.fixed index b802de1cbc650..5845f7f8d7cb5 100644 --- a/tests/ui-internal/unnecessary_symbol_str.fixed +++ b/tests/ui-internal/unnecessary_symbol_str.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + #![feature(rustc_private)] #![deny(clippy::internal)] #![allow( diff --git a/tests/ui-internal/unnecessary_symbol_str.rs b/tests/ui-internal/unnecessary_symbol_str.rs index c1bead5bdc98e..bbea13af92a54 100644 --- a/tests/ui-internal/unnecessary_symbol_str.rs +++ b/tests/ui-internal/unnecessary_symbol_str.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(rustc_private)] #![deny(clippy::internal)] #![allow( diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed index c908568452809..c04543da94b95 100644 --- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed +++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::uninlined_format_args)] #![allow(clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs index 661350c5c6d54..813830d80b830 100644 --- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs +++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::uninlined_format_args)] #![allow(clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr index eb1180e60b807..c5912b7af9e5c 100644 --- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr +++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr @@ -1,5 +1,5 @@ error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:10:5 + --> $DIR/uninlined_format_args.rs:9:5 | LL | println!("val='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:11:5 + --> $DIR/uninlined_format_args.rs:10:5 | LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + println!("Hello {} is {local_f64:.local_i32$}", "x"); | error: literal with an empty format string - --> $DIR/uninlined_format_args.rs:11:35 + --> $DIR/uninlined_format_args.rs:10:35 | LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ^^^ @@ -37,7 +37,7 @@ LL + println!("Hello x is {:.*}", local_i32, local_f64); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:12:5 + --> $DIR/uninlined_format_args.rs:11:5 | LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:13:5 + --> $DIR/uninlined_format_args.rs:12:5 | LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:14:5 + --> $DIR/uninlined_format_args.rs:13:5 | LL | println!("{}, {}", local_i32, local_opt.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.rs b/tests/ui-toml/array_size_threshold/array_size_threshold.rs index 7f623c7a9ec54..d36159e126392 100644 --- a/tests/ui-toml/array_size_threshold/array_size_threshold.rs +++ b/tests/ui-toml/array_size_threshold/array_size_threshold.rs @@ -1,6 +1,6 @@ #![allow(unused)] #![warn(clippy::large_const_arrays, clippy::large_stack_arrays)] - +//@no-rustfix const ABOVE: [u8; 11] = [0; 11]; const BELOW: [u8; 10] = [0; 10]; diff --git a/tests/ui-toml/dbg_macro/dbg_macro.rs b/tests/ui-toml/dbg_macro/dbg_macro.rs index 21e4fce26e4e6..67129e6247712 100644 --- a/tests/ui-toml/dbg_macro/dbg_macro.rs +++ b/tests/ui-toml/dbg_macro/dbg_macro.rs @@ -1,6 +1,6 @@ //@compile-flags: --test #![warn(clippy::dbg_macro)] - +//@no-rustfix fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } } diff --git a/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed b/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed new file mode 100644 index 0000000000000..f16e138da2be8 --- /dev/null +++ b/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed @@ -0,0 +1,12 @@ +#![warn(clippy::doc_markdown)] + +/// This is a special interface for ClipPy which doesn't require backticks +fn allowed_name() {} + +/// OAuth and LaTeX are inside Clippy's default list. +fn default_name() {} + +/// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. +fn unknown_name() {} + +fn main() {} diff --git a/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed new file mode 100644 index 0000000000000..af6ec675e81b6 --- /dev/null +++ b/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed @@ -0,0 +1,12 @@ +#![warn(clippy::doc_markdown)] + +/// This is a special interface for ClipPy which doesn't require backticks +fn allowed_name() {} + +/// `OAuth` and `LaTeX` are inside Clippy's default list. +fn default_name() {} + +/// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. +fn unknown_name() {} + +fn main() {} diff --git a/tests/ui-toml/large_futures/large_futures.fixed b/tests/ui-toml/large_futures/large_futures.fixed new file mode 100644 index 0000000000000..7dea9fb95b4bb --- /dev/null +++ b/tests/ui-toml/large_futures/large_futures.fixed @@ -0,0 +1,27 @@ +#![warn(clippy::large_futures)] + +fn main() {} + +pub async fn should_warn() { + let x = [0u8; 1024]; + async {}.await; + dbg!(x); +} + +pub async fn should_not_warn() { + let x = [0u8; 1020]; + async {}.await; + dbg!(x); +} + +pub async fn bar() { + Box::pin(should_warn()).await; + + async { + let x = [0u8; 1024]; + dbg!(x); + } + .await; + + should_not_warn().await; +} diff --git a/tests/ui-toml/lint_decimal_readability/test.fixed b/tests/ui-toml/lint_decimal_readability/test.fixed new file mode 100644 index 0000000000000..f013153f51662 --- /dev/null +++ b/tests/ui-toml/lint_decimal_readability/test.fixed @@ -0,0 +1,23 @@ +#![allow(clippy::excessive_precision)] +#![warn(clippy::unreadable_literal)] + +fn allow_inconsistent_digit_grouping() { + #![allow(clippy::inconsistent_digit_grouping)] + let _pass1 = 100_200_300.123456789; +} + +fn main() { + allow_inconsistent_digit_grouping(); + + let _pass1 = 100_200_300.100_200_300; + let _pass2 = 1.123456789; + let _pass3 = 1.0; + let _pass4 = 10000.00001; + let _pass5 = 1.123456789e1; + + // due to clippy::inconsistent-digit-grouping + let _fail1 = 100_200_300.123_456_789; + + // fail due to the integer part + let _fail2 = 100_200_300.300_200_100; +} diff --git a/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed b/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed new file mode 100644 index 0000000000000..36540bf1dcf73 --- /dev/null +++ b/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed @@ -0,0 +1,24 @@ +#![deny(clippy::index_refutable_slice)] + +fn below_limit() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some([_, _, _, _, _, _, _, slice_7, ..]) = slice { + //~^ ERROR: binding can be a slice pattern + // This would usually not be linted but is included now due to the + // index limit in the config file + println!("{}", slice_7); + } +} + +fn above_limit() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice) = slice { + // This will not be linted as 8 is above the limit + println!("{}", slice[8]); + } +} + +fn main() { + below_limit(); + above_limit(); +} diff --git a/tests/ui-toml/min_rust_version/min_rust_version.fixed b/tests/ui-toml/min_rust_version/min_rust_version.fixed new file mode 100644 index 0000000000000..6c58e07d846ea --- /dev/null +++ b/tests/ui-toml/min_rust_version/min_rust_version.fixed @@ -0,0 +1,98 @@ +#![allow(clippy::redundant_clone, clippy::unnecessary_operation)] +#![warn(clippy::manual_non_exhaustive, clippy::borrow_as_ptr, clippy::manual_bits)] + +use std::mem::{size_of, size_of_val}; +use std::ops::Deref; + +mod enums { + enum E { + A, + B, + #[doc(hidden)] + _C, + } + + // user forgot to remove the marker + #[non_exhaustive] + enum Ep { + A, + B, + #[doc(hidden)] + _C, + } +} + +fn option_as_ref_deref() { + let mut opt = Some(String::from("123")); + + let _ = opt.as_ref().map(String::as_str); + let _ = opt.as_ref().map(|x| x.as_str()); + let _ = opt.as_mut().map(String::as_mut_str); + let _ = opt.as_mut().map(|x| x.as_mut_str()); +} + +fn match_like_matches() { + let _y = match Some(5) { + Some(0) => true, + _ => false, + }; +} + +fn match_same_arms() { + match (1, 2, 3) { + (1, .., 3) => 42, + (.., 3) => 42, + _ => 0, + }; +} + +fn match_same_arms2() { + let _ = match Some(42) { + Some(_) => 24, + None => 24, + }; +} + +fn manual_strip_msrv() { + let s = "hello, world!"; + if s.starts_with("hello, ") { + assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); + } +} + +fn check_index_refutable_slice() { + // This shouldn't trigger `clippy::index_refutable_slice` as the suggestion + // would only be valid from 1.42.0 onward + let slice: Option<&[u32]> = Some(&[1]); + if let Some(slice) = slice { + println!("{}", slice[0]); + } +} + +fn map_clone_suggest_copied() { + // This should still trigger the lint but suggest `cloned()` instead of `copied()` + let _: Option = Some(&16).cloned(); +} + +fn borrow_as_ptr() { + let val = 1; + let _p = &val as *const i32; + + let mut val_mut = 1; + let _p_mut = &mut val_mut as *mut i32; +} + +fn manual_bits() { + size_of::() * 8; + size_of_val(&0u32) * 8; +} + +fn main() { + option_as_ref_deref(); + match_like_matches(); + match_same_arms(); + match_same_arms2(); + manual_strip_msrv(); + check_index_refutable_slice(); + borrow_as_ptr(); +} diff --git a/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed new file mode 100644 index 0000000000000..5f4f007cf5c7f --- /dev/null +++ b/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed @@ -0,0 +1,16 @@ +#![warn(clippy::missing_enforced_import_renames)] + +use std::alloc as colla; +use std::option::Option as Maybe; +use std::process::{exit as goodbye, Child as Kid}; +use std::thread::sleep as thread_sleep; +#[rustfmt::skip] +use std::{ + any::{type_name as ident, Any}, + clone as foo, + sync :: Mutex as StdMutie, +}; + +fn main() { + use std::collections::BTreeMap as Map; +} 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 054db5d933059..f7484101760bc 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 @@ -1,5 +1,4 @@ //@aux-build:proc_macro_derive.rs:proc-macro -//@run-rustfix #![warn(clippy::nonstandard_macro_braces)] 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 95d1a2297e531..4e01299f81e90 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 @@ -1,5 +1,4 @@ //@aux-build:proc_macro_derive.rs:proc-macro -//@run-rustfix #![warn(clippy::nonstandard_macro_braces)] 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 7ae3815978c77..cfff1fffe80a9 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,5 +1,5 @@ error: use of irregular braces for `vec!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:44:13 + --> $DIR/conf_nonstandard_macro_braces.rs:43:13 | LL | let _ = vec! {1, 2, 3}; | ^^^^^^^^^^^^^^ help: consider writing: `vec![1, 2, 3]` @@ -7,31 +7,31 @@ LL | let _ = vec! {1, 2, 3}; = note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings` error: use of irregular braces for `format!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:45:13 + --> $DIR/conf_nonstandard_macro_braces.rs:44: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 - --> $DIR/conf_nonstandard_macro_braces.rs:46:13 + --> $DIR/conf_nonstandard_macro_braces.rs:45:13 | LL | let _ = matches!{{}, ()}; | ^^^^^^^^^^^^^^^^ help: consider writing: `matches!({}, ())` error: use of irregular braces for `quote!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:47:13 + --> $DIR/conf_nonstandard_macro_braces.rs:46:13 | LL | let _ = quote!(let x = 1;); | ^^^^^^^^^^^^^^^^^^ help: consider writing: `quote!{let x = 1;}` error: use of irregular braces for `quote::quote!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:48:13 + --> $DIR/conf_nonstandard_macro_braces.rs:47:13 | LL | let _ = quote::quote!(match match match); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `quote::quote!{match match match}` error: use of irregular braces for `vec!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:19:9 + --> $DIR/conf_nonstandard_macro_braces.rs:18:9 | LL | vec!{0, 0, 0} | ^^^^^^^^^^^^^ help: consider writing: `vec![0, 0, 0]` @@ -42,13 +42,13 @@ LL | let _ = test!(); // trigger when macro def is inside our own crate = 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 - --> $DIR/conf_nonstandard_macro_braces.rs:57:12 + --> $DIR/conf_nonstandard_macro_braces.rs:56:12 | LL | let _: type_pos!(usize) = vec![]; | ^^^^^^^^^^^^^^^^ help: consider writing: `type_pos![usize]` error: use of irregular braces for `eprint!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:59:5 + --> $DIR/conf_nonstandard_macro_braces.rs:58:5 | LL | eprint!("test if user config overrides defaults"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `eprint!["test if user config overrides defaults"]` diff --git a/tests/ui-toml/semicolon_block/both.fixed b/tests/ui-toml/semicolon_block/both.fixed index fc8038a090715..306cd23c8239a 100644 --- a/tests/ui-toml/semicolon_block/both.fixed +++ b/tests/ui-toml/semicolon_block/both.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui-toml/semicolon_block/both.rs b/tests/ui-toml/semicolon_block/both.rs index 52ce1f0387ee1..b9f012cfbb0dc 100644 --- a/tests/ui-toml/semicolon_block/both.rs +++ b/tests/ui-toml/semicolon_block/both.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui-toml/semicolon_block/both.stderr b/tests/ui-toml/semicolon_block/both.stderr index 2f58842eab01b..49b5806746720 100644 --- a/tests/ui-toml/semicolon_block/both.stderr +++ b/tests/ui-toml/semicolon_block/both.stderr @@ -1,5 +1,5 @@ error: consider moving the `;` outside the block for consistent formatting - --> $DIR/both.rs:43:5 + --> $DIR/both.rs:42:5 | LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/both.rs:44:5 + --> $DIR/both.rs:43:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/both.rs:49:5 + --> $DIR/both.rs:48:5 | LL | / { LL | | unit_fn_block(); @@ -40,7 +40,7 @@ LL ~ } | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/both.rs:63:5 + --> $DIR/both.rs:62:5 | LL | { m!(()); } | ^^^^^^^^^^^ diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed b/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed index 23df983017735..5b7f8e00c7a00 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.rs b/tests/ui-toml/semicolon_block/semicolon_inside_block.rs index e8516f79b20cd..3a81661cd16f5 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.rs +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr index 2569dc4b4e453..13ba9750f4b82 100644 --- a/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr +++ b/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr @@ -1,5 +1,5 @@ error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:48:5 + --> $DIR/semicolon_inside_block.rs:47:5 | LL | / { LL | | unit_fn_block(); diff --git a/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed b/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed index 7e9055e71106a..14604eaea7e42 100644 --- a/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed +++ b/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui-toml/semicolon_block/semicolon_outside_block.rs b/tests/ui-toml/semicolon_block/semicolon_outside_block.rs index 4dc956d8a4b51..c767201469ab6 100644 --- a/tests/ui-toml/semicolon_block/semicolon_outside_block.rs +++ b/tests/ui-toml/semicolon_block/semicolon_outside_block.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr b/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr index 6dd3577dd09f0..3c619ebe73d1e 100644 --- a/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr +++ b/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr @@ -1,5 +1,5 @@ error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:42:5 + --> $DIR/semicolon_outside_block.rs:41:5 | LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:43:5 + --> $DIR/semicolon_outside_block.rs:42:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:62:5 + --> $DIR/semicolon_outside_block.rs:61:5 | LL | { m!(()); } | ^^^^^^^^^^^ diff --git a/tests/ui-toml/toml_trivially_copy/test.rs b/tests/ui-toml/toml_trivially_copy/test.rs index 78784bfff0fd0..145a2ce441d39 100644 --- a/tests/ui-toml/toml_trivially_copy/test.rs +++ b/tests/ui-toml/toml_trivially_copy/test.rs @@ -1,6 +1,6 @@ //@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)" //@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)" - +//@no-rustfix #![warn(clippy::trivially_copy_pass_by_ref)] #![allow(clippy::needless_pass_by_ref_mut)] diff --git a/tests/ui-toml/unwrap_used/unwrap_used.fixed b/tests/ui-toml/unwrap_used/unwrap_used.fixed new file mode 100644 index 0000000000000..baf939af24efb --- /dev/null +++ b/tests/ui-toml/unwrap_used/unwrap_used.fixed @@ -0,0 +1,95 @@ +//@compile-flags: --test + +#![allow( + unused_mut, + clippy::get_first, + clippy::from_iter_instead_of_collect, + clippy::useless_vec +)] +#![warn(clippy::unwrap_used)] +#![warn(clippy::get_unwrap)] + +use std::collections::{BTreeMap, HashMap, VecDeque}; + +struct GetFalsePositive { + arr: [u32; 3], +} + +impl GetFalsePositive { + fn get(&self, pos: usize) -> Option<&u32> { + self.arr.get(pos) + } + fn get_mut(&mut self, pos: usize) -> Option<&mut u32> { + self.arr.get_mut(pos) + } +} + +fn main() { + let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); + let mut some_slice = &mut [0, 1, 2, 3]; + let mut some_vec = vec![0, 1, 2, 3]; + let mut some_vecdeque: VecDeque<_> = some_vec.iter().cloned().collect(); + let mut some_hashmap: HashMap = HashMap::from_iter(vec![(1, 'a'), (2, 'b')]); + let mut some_btreemap: BTreeMap = BTreeMap::from_iter(vec![(1, 'a'), (2, 'b')]); + let mut false_positive = GetFalsePositive { arr: [0, 1, 2] }; + + { + // Test `get().unwrap()` + let _ = &boxed_slice[1]; + let _ = &some_slice[0]; + let _ = &some_vec[0]; + let _ = &some_vecdeque[0]; + let _ = &some_hashmap[&1]; + let _ = &some_btreemap[&1]; + #[allow(clippy::unwrap_used)] + let _ = false_positive.get(0).unwrap(); + // Test with deref + let _: u8 = boxed_slice[1]; + } + + { + // Test `get_mut().unwrap()` + boxed_slice[0] = 1; + some_slice[0] = 1; + some_vec[0] = 1; + some_vecdeque[0] = 1; + // Check false positives + #[allow(clippy::unwrap_used)] + { + *some_hashmap.get_mut(&1).unwrap() = 'b'; + *some_btreemap.get_mut(&1).unwrap() = 'b'; + *false_positive.get_mut(0).unwrap() = 1; + } + } + + { + // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` + let _ = some_vec[0..1].to_vec(); + let _ = some_vec[0..1].to_vec(); + } +} + +#[test] +fn test() { + let boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); + let _ = &boxed_slice[1]; +} + +#[cfg(test)] +mod issue9612 { + // should not lint in `#[cfg(test)]` modules + #[test] + fn test_fn() { + let _a: u8 = 2.try_into().unwrap(); + let _a: u8 = 3.try_into().expect(""); + + util(); + } + + fn util() { + let _a: u8 = 4.try_into().unwrap(); + let _a: u8 = 5.try_into().expect(""); + // should still warn + let _ = &Box::new([0])[1]; + } +} diff --git a/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed new file mode 100644 index 0000000000000..afb889f157f0c --- /dev/null +++ b/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed @@ -0,0 +1,44 @@ +#![warn(clippy::upper_case_acronyms)] + +struct HttpResponse; // not linted by default, but with cfg option + +struct CString; // not linted + +enum Flags { + Ns, // not linted + Cwr, + Ece, + Urg, + Ack, + Psh, + Rst, + Syn, + Fin, +} + +// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of +// `GccLlvmSomething` +struct GccllvmSomething; + +// don't warn on public items +pub struct MIXEDCapital; + +pub struct FULLCAPITAL; + +// enum variants should not be linted if the num is pub +pub enum ParseError { + FULLCAPITAL(u8), + MIXEDCapital(String), + Utf8(std::string::FromUtf8Error), + Parse(T, String), +} + +// private, do lint here +enum ParseErrorPrivate { + Wasd(u8), + WasdMixed(String), + Utf8(std::string::FromUtf8Error), + Parse(T, String), +} + +fn main() {} diff --git a/tests/ui-toml/vec_box_sized/test.fixed b/tests/ui-toml/vec_box_sized/test.fixed new file mode 100644 index 0000000000000..bb4936401ceba --- /dev/null +++ b/tests/ui-toml/vec_box_sized/test.fixed @@ -0,0 +1,16 @@ +struct S { + x: u64, +} + +struct C { + y: u16, +} + +struct Foo(Vec); +struct Bar(Vec); +struct Quux(Vec>); +struct Baz(Vec>); +struct BarBaz(Vec>); +struct FooBarBaz(Vec); + +fn main() {} diff --git a/tests/ui/allow_attributes.fixed b/tests/ui/allow_attributes.fixed index cc95a06817d69..1351a1a4eb495 100644 --- a/tests/ui/allow_attributes.fixed +++ b/tests/ui/allow_attributes.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(unused)] #![warn(clippy::allow_attributes)] diff --git a/tests/ui/allow_attributes.rs b/tests/ui/allow_attributes.rs index 2eb6ad304ea47..e14e24e52b532 100644 --- a/tests/ui/allow_attributes.rs +++ b/tests/ui/allow_attributes.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(unused)] #![warn(clippy::allow_attributes)] diff --git a/tests/ui/allow_attributes.stderr b/tests/ui/allow_attributes.stderr index d17fd86cb866c..30a947b0648bd 100644 --- a/tests/ui/allow_attributes.stderr +++ b/tests/ui/allow_attributes.stderr @@ -1,5 +1,5 @@ error: #[allow] attribute found - --> $DIR/allow_attributes.rs:14:3 + --> $DIR/allow_attributes.rs:13:3 | LL | #[allow(dead_code)] | ^^^^^ help: replace it with: `expect` @@ -7,7 +7,7 @@ LL | #[allow(dead_code)] = note: `-D clippy::allow-attributes` implied by `-D warnings` error: #[allow] attribute found - --> $DIR/allow_attributes.rs:23:30 + --> $DIR/allow_attributes.rs:22:30 | LL | #[cfg_attr(panic = "unwind", allow(dead_code))] | ^^^^^ help: replace it with: `expect` diff --git a/tests/ui/almost_complete_range.fixed b/tests/ui/almost_complete_range.fixed index 50a13f16b4456..b4de1b97336db 100644 --- a/tests/ui/almost_complete_range.fixed +++ b/tests/ui/almost_complete_range.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 //@aux-build:proc_macros.rs:proc-macro diff --git a/tests/ui/almost_complete_range.rs b/tests/ui/almost_complete_range.rs index fd8223a2309c2..b0e8d69476e9c 100644 --- a/tests/ui/almost_complete_range.rs +++ b/tests/ui/almost_complete_range.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 //@aux-build:proc_macros.rs:proc-macro diff --git a/tests/ui/almost_complete_range.stderr b/tests/ui/almost_complete_range.stderr index 34521c13ab3ed..9a6d91b7d8b39 100644 --- a/tests/ui/almost_complete_range.stderr +++ b/tests/ui/almost_complete_range.stderr @@ -1,5 +1,5 @@ error: almost complete ascii range - --> $DIR/almost_complete_range.rs:19:17 + --> $DIR/almost_complete_range.rs:18:17 | LL | let _ = ('a') ..'z'; | ^^^^^^--^^^ @@ -9,7 +9,7 @@ LL | let _ = ('a') ..'z'; = note: `-D clippy::almost-complete-range` implied by `-D warnings` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:20:17 + --> $DIR/almost_complete_range.rs:19:17 | LL | let _ = 'A' .. ('Z'); | ^^^^--^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = 'A' .. ('Z'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:21:17 + --> $DIR/almost_complete_range.rs:20:17 | LL | let _ = ((('0'))) .. ('9'); | ^^^^^^^^^^--^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = ((('0'))) .. ('9'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:28:13 + --> $DIR/almost_complete_range.rs:27:13 | LL | let _ = (b'a')..(b'z'); | ^^^^^^--^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = (b'a')..(b'z'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:29:13 + --> $DIR/almost_complete_range.rs:28:13 | LL | let _ = b'A'..b'Z'; | ^^^^--^^^^ @@ -41,7 +41,7 @@ LL | let _ = b'A'..b'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:30:13 + --> $DIR/almost_complete_range.rs:29:13 | LL | let _ = b'0'..b'9'; | ^^^^--^^^^ @@ -49,7 +49,7 @@ LL | let _ = b'0'..b'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:36:13 + --> $DIR/almost_complete_range.rs:35:13 | LL | let _ = inline!('a')..'z'; | ^^^^^^^^^^^^--^^^ @@ -57,7 +57,7 @@ LL | let _ = inline!('a')..'z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:37:13 + --> $DIR/almost_complete_range.rs:36:13 | LL | let _ = inline!('A')..'Z'; | ^^^^^^^^^^^^--^^^ @@ -65,7 +65,7 @@ LL | let _ = inline!('A')..'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:38:13 + --> $DIR/almost_complete_range.rs:37:13 | LL | let _ = inline!('0')..'9'; | ^^^^^^^^^^^^--^^^ @@ -73,7 +73,7 @@ LL | let _ = inline!('0')..'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:41:9 + --> $DIR/almost_complete_range.rs:40:9 | LL | b'a'..b'z' if true => 1, | ^^^^--^^^^ @@ -81,7 +81,7 @@ LL | b'a'..b'z' if true => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:42:9 + --> $DIR/almost_complete_range.rs:41:9 | LL | b'A'..b'Z' if true => 2, | ^^^^--^^^^ @@ -89,7 +89,7 @@ LL | b'A'..b'Z' if true => 2, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:43:9 + --> $DIR/almost_complete_range.rs:42:9 | LL | b'0'..b'9' if true => 3, | ^^^^--^^^^ @@ -97,7 +97,7 @@ LL | b'0'..b'9' if true => 3, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:51:9 + --> $DIR/almost_complete_range.rs:50:9 | LL | 'a'..'z' if true => 1, | ^^^--^^^ @@ -105,7 +105,7 @@ LL | 'a'..'z' if true => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:52:9 + --> $DIR/almost_complete_range.rs:51:9 | LL | 'A'..'Z' if true => 2, | ^^^--^^^ @@ -113,7 +113,7 @@ LL | 'A'..'Z' if true => 2, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:53:9 + --> $DIR/almost_complete_range.rs:52:9 | LL | '0'..'9' if true => 3, | ^^^--^^^ @@ -121,7 +121,7 @@ LL | '0'..'9' if true => 3, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:66:17 + --> $DIR/almost_complete_range.rs:65:17 | LL | let _ = 'a'..'z'; | ^^^--^^^ @@ -131,7 +131,7 @@ LL | let _ = 'a'..'z'; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: almost complete ascii range - --> $DIR/almost_complete_range.rs:67:17 + --> $DIR/almost_complete_range.rs:66:17 | LL | let _ = 'A'..'Z'; | ^^^--^^^ @@ -141,7 +141,7 @@ LL | let _ = 'A'..'Z'; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: almost complete ascii range - --> $DIR/almost_complete_range.rs:68:17 + --> $DIR/almost_complete_range.rs:67:17 | LL | let _ = '0'..'9'; | ^^^--^^^ @@ -151,7 +151,7 @@ LL | let _ = '0'..'9'; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: almost complete ascii range - --> $DIR/almost_complete_range.rs:75:9 + --> $DIR/almost_complete_range.rs:74:9 | LL | 'a'..'z' => 1, | ^^^--^^^ @@ -159,7 +159,7 @@ LL | 'a'..'z' => 1, | help: use an inclusive range: `...` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:76:9 + --> $DIR/almost_complete_range.rs:75:9 | LL | 'A'..'Z' => 2, | ^^^--^^^ @@ -167,7 +167,7 @@ LL | 'A'..'Z' => 2, | help: use an inclusive range: `...` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:77:9 + --> $DIR/almost_complete_range.rs:76:9 | LL | '0'..'9' => 3, | ^^^--^^^ @@ -175,7 +175,7 @@ LL | '0'..'9' => 3, | help: use an inclusive range: `...` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:84:13 + --> $DIR/almost_complete_range.rs:83:13 | LL | let _ = 'a'..'z'; | ^^^--^^^ @@ -183,7 +183,7 @@ LL | let _ = 'a'..'z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:85:13 + --> $DIR/almost_complete_range.rs:84:13 | LL | let _ = 'A'..'Z'; | ^^^--^^^ @@ -191,7 +191,7 @@ LL | let _ = 'A'..'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:86:13 + --> $DIR/almost_complete_range.rs:85:13 | LL | let _ = '0'..'9'; | ^^^--^^^ @@ -199,7 +199,7 @@ LL | let _ = '0'..'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:88:9 + --> $DIR/almost_complete_range.rs:87:9 | LL | 'a'..'z' => 1, | ^^^--^^^ @@ -207,7 +207,7 @@ LL | 'a'..'z' => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:89:9 + --> $DIR/almost_complete_range.rs:88:9 | LL | 'A'..'Z' => 1, | ^^^--^^^ @@ -215,7 +215,7 @@ LL | 'A'..'Z' => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:90:9 + --> $DIR/almost_complete_range.rs:89:9 | LL | '0'..'9' => 3, | ^^^--^^^ diff --git a/tests/ui/as_ptr_cast_mut.rs b/tests/ui/as_ptr_cast_mut.rs index 7d71947e42814..74dad7a493577 100644 --- a/tests/ui/as_ptr_cast_mut.rs +++ b/tests/ui/as_ptr_cast_mut.rs @@ -1,6 +1,7 @@ #![allow(unused)] #![warn(clippy::as_ptr_cast_mut)] #![allow(clippy::wrong_self_convention, clippy::unnecessary_cast)] +//@no-rustfix struct MutPtrWrapper(Vec); impl MutPtrWrapper { diff --git a/tests/ui/as_ptr_cast_mut.stderr b/tests/ui/as_ptr_cast_mut.stderr index 2189c3d2f8556..9255f4e048b26 100644 --- a/tests/ui/as_ptr_cast_mut.stderr +++ b/tests/ui/as_ptr_cast_mut.stderr @@ -1,5 +1,5 @@ error: casting the result of `as_ptr` to *mut u8 - --> $DIR/as_ptr_cast_mut.rs:21:13 + --> $DIR/as_ptr_cast_mut.rs:22:13 | LL | let _ = string.as_ptr() as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()` @@ -7,7 +7,7 @@ LL | let _ = string.as_ptr() as *mut u8; = note: `-D clippy::as-ptr-cast-mut` implied by `-D warnings` error: casting the result of `as_ptr` to *mut i8 - --> $DIR/as_ptr_cast_mut.rs:22:22 + --> $DIR/as_ptr_cast_mut.rs:23:22 | LL | let _: *mut i8 = string.as_ptr() as *mut _; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()` diff --git a/tests/ui/as_underscore.fixed b/tests/ui/as_underscore.fixed index 69af84a0eaec5..c7f26e64cce78 100644 --- a/tests/ui/as_underscore.fixed +++ b/tests/ui/as_underscore.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::as_underscore)] fn foo(_n: usize) {} diff --git a/tests/ui/as_underscore.rs b/tests/ui/as_underscore.rs index a8cfb81d9a3f0..70f3b386631c4 100644 --- a/tests/ui/as_underscore.rs +++ b/tests/ui/as_underscore.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::as_underscore)] fn foo(_n: usize) {} diff --git a/tests/ui/as_underscore.stderr b/tests/ui/as_underscore.stderr index d7cd58d965acb..21d7884445d97 100644 --- a/tests/ui/as_underscore.stderr +++ b/tests/ui/as_underscore.stderr @@ -1,5 +1,5 @@ error: using `as _` conversion - --> $DIR/as_underscore.rs:9:9 + --> $DIR/as_underscore.rs:7:9 | LL | foo(n as _); | ^^^^^- @@ -9,7 +9,7 @@ LL | foo(n as _); = note: `-D clippy::as-underscore` implied by `-D warnings` error: using `as _` conversion - --> $DIR/as_underscore.rs:12:18 + --> $DIR/as_underscore.rs:10:18 | LL | let _n: u8 = n as _; | ^^^^^- diff --git a/tests/ui/assertions_on_result_states.fixed b/tests/ui/assertions_on_result_states.fixed index 3152bd3cae1a6..14d9b8b99d5e5 100644 --- a/tests/ui/assertions_on_result_states.fixed +++ b/tests/ui/assertions_on_result_states.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::assertions_on_result_states)] #![allow(clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui/assertions_on_result_states.rs b/tests/ui/assertions_on_result_states.rs index 42755e935aa41..ac1911d87c93a 100644 --- a/tests/ui/assertions_on_result_states.rs +++ b/tests/ui/assertions_on_result_states.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::assertions_on_result_states)] #![allow(clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui/assertions_on_result_states.stderr b/tests/ui/assertions_on_result_states.stderr index be581030cb67b..298d63c9c34fb 100644 --- a/tests/ui/assertions_on_result_states.stderr +++ b/tests/ui/assertions_on_result_states.stderr @@ -1,5 +1,5 @@ error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:25:5 + --> $DIR/assertions_on_result_states.rs:24:5 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` @@ -7,37 +7,37 @@ LL | assert!(r.is_ok()); = note: `-D clippy::assertions-on-result-states` implied by `-D warnings` error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:43:5 + --> $DIR/assertions_on_result_states.rs:42:5 | LL | assert!(get_ok().is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `get_ok().unwrap()` error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:46:5 + --> $DIR/assertions_on_result_states.rs:45:5 | LL | assert!(get_ok_macro!().is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `get_ok_macro!().unwrap()` error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:59:5 + --> $DIR/assertions_on_result_states.rs:58:5 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:65:9 + --> $DIR/assertions_on_result_states.rs:64:9 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` error: called `assert!` with `Result::is_err` - --> $DIR/assertions_on_result_states.rs:73:5 + --> $DIR/assertions_on_result_states.rs:72:5 | LL | assert!(r.is_err()); | ^^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap_err()` error: called `assert!` with `Result::is_err` - --> $DIR/assertions_on_result_states.rs:83:5 + --> $DIR/assertions_on_result_states.rs:82:5 | LL | assert!(res.is_err()) | ^^^^^^^^^^^^^^^^^^^^^ help: replace with: `res.unwrap_err();` diff --git a/tests/ui/assign_ops.fixed b/tests/ui/assign_ops.fixed index ef45e97d1de14..2bd0807f42628 100644 --- a/tests/ui/assign_ops.fixed +++ b/tests/ui/assign_ops.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - use core::num::Wrapping; #[allow(dead_code, unused_assignments, clippy::useless_vec)] diff --git a/tests/ui/assign_ops.rs b/tests/ui/assign_ops.rs index ae87afc485ed8..be3491a44c7eb 100644 --- a/tests/ui/assign_ops.rs +++ b/tests/ui/assign_ops.rs @@ -1,5 +1,3 @@ -//@run-rustfix - use core::num::Wrapping; #[allow(dead_code, unused_assignments, clippy::useless_vec)] diff --git a/tests/ui/assign_ops.stderr b/tests/ui/assign_ops.stderr index 63a938ab4b435..525ce592b4920 100644 --- a/tests/ui/assign_ops.stderr +++ b/tests/ui/assign_ops.stderr @@ -1,5 +1,5 @@ error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:9:5 + --> $DIR/assign_ops.rs:7:5 | LL | a = a + 1; | ^^^^^^^^^ help: replace it with: `a += 1` @@ -7,61 +7,61 @@ LL | a = a + 1; = note: `-D clippy::assign-op-pattern` implied by `-D warnings` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:10:5 + --> $DIR/assign_ops.rs:8:5 | LL | a = 1 + a; | ^^^^^^^^^ help: replace it with: `a += 1` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:11:5 + --> $DIR/assign_ops.rs:9:5 | LL | a = a - 1; | ^^^^^^^^^ help: replace it with: `a -= 1` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:12:5 + --> $DIR/assign_ops.rs:10:5 | LL | a = a * 99; | ^^^^^^^^^^ help: replace it with: `a *= 99` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:13:5 + --> $DIR/assign_ops.rs:11:5 | LL | a = 42 * a; | ^^^^^^^^^^ help: replace it with: `a *= 42` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:14:5 + --> $DIR/assign_ops.rs:12:5 | LL | a = a / 2; | ^^^^^^^^^ help: replace it with: `a /= 2` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:15:5 + --> $DIR/assign_ops.rs:13:5 | LL | a = a % 5; | ^^^^^^^^^ help: replace it with: `a %= 5` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:16:5 + --> $DIR/assign_ops.rs:14:5 | LL | a = a & 1; | ^^^^^^^^^ help: replace it with: `a &= 1` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:22:5 + --> $DIR/assign_ops.rs:20:5 | LL | s = s + "bla"; | ^^^^^^^^^^^^^ help: replace it with: `s += "bla"` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:26:5 + --> $DIR/assign_ops.rs:24:5 | LL | a = a + Wrapping(1u32); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a += Wrapping(1u32)` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:28:5 + --> $DIR/assign_ops.rs:26:5 | LL | v[0] = v[0] + v[1]; | ^^^^^^^^^^^^^^^^^^ help: replace it with: `v[0] += v[1]` diff --git a/tests/ui/assign_ops2.rs b/tests/ui/assign_ops2.rs index 2c876a96c55da..2be333df09902 100644 --- a/tests/ui/assign_ops2.rs +++ b/tests/ui/assign_ops2.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(clippy::uninlined_format_args)] #[allow(unused_assignments)] diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index 25e74602244df..e5ff3ff3a477a 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -1,5 +1,5 @@ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:7:5 + --> $DIR/assign_ops2.rs:8:5 | LL | a += a + 1; | ^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | a = a + a + 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:8:5 + --> $DIR/assign_ops2.rs:9:5 | LL | a += 1 + a; | ^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | a = a + 1 + a; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:9:5 + --> $DIR/assign_ops2.rs:10:5 | LL | a -= a - 1; | ^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | a = a - (a - 1); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:10:5 + --> $DIR/assign_ops2.rs:11:5 | LL | a *= a * 99; | ^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | a = a * a * 99; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:11:5 + --> $DIR/assign_ops2.rs:12:5 | LL | a *= 42 * a; | ^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL | a = a * 42 * a; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:12:5 + --> $DIR/assign_ops2.rs:13:5 | LL | a /= a / 2; | ^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | a = a / (a / 2); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:13:5 + --> $DIR/assign_ops2.rs:14:5 | LL | a %= a % 5; | ^^^^^^^^^^ @@ -105,7 +105,7 @@ LL | a = a % (a % 5); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:14:5 + --> $DIR/assign_ops2.rs:15:5 | LL | a &= a & 1; | ^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | a = a & a & 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:15:5 + --> $DIR/assign_ops2.rs:16:5 | LL | a *= a * a; | ^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | a = a * a * a; | ~~~~~~~~~~~~~ error: manual implementation of an assign operation - --> $DIR/assign_ops2.rs:52:5 + --> $DIR/assign_ops2.rs:53:5 | LL | buf = buf + cows.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()` diff --git a/tests/ui/async_yields_async.fixed b/tests/ui/async_yields_async.fixed index 8d9b023893f79..cfad78138053d 100644 --- a/tests/ui/async_yields_async.fixed +++ b/tests/ui/async_yields_async.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![feature(async_closure)] #![warn(clippy::async_yields_async)] diff --git a/tests/ui/async_yields_async.rs b/tests/ui/async_yields_async.rs index bed79062f015e..7bc26647943f9 100644 --- a/tests/ui/async_yields_async.rs +++ b/tests/ui/async_yields_async.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![feature(async_closure)] #![warn(clippy::async_yields_async)] diff --git a/tests/ui/async_yields_async.stderr b/tests/ui/async_yields_async.stderr index 7f72534832b4e..22ce1c6f6471b 100644 --- a/tests/ui/async_yields_async.stderr +++ b/tests/ui/async_yields_async.stderr @@ -1,5 +1,5 @@ error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:40:9 + --> $DIR/async_yields_async.rs:39:9 | LL | let _h = async { | _____________________- @@ -19,7 +19,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:45:9 + --> $DIR/async_yields_async.rs:44:9 | LL | let _i = async { | ____________________- @@ -32,7 +32,7 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:51:9 + --> $DIR/async_yields_async.rs:50:9 | LL | let _j = async || { | ________________________- @@ -51,7 +51,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:56:9 + --> $DIR/async_yields_async.rs:55:9 | LL | let _k = async || { | _______________________- @@ -64,7 +64,7 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:58:23 + --> $DIR/async_yields_async.rs:57:23 | LL | let _l = async || CustomFutureType; | ^^^^^^^^^^^^^^^^ @@ -74,7 +74,7 @@ LL | let _l = async || CustomFutureType; | help: consider awaiting this value: `CustomFutureType.await` error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:64:9 + --> $DIR/async_yields_async.rs:63:9 | LL | let _m = async || { | _______________________- diff --git a/tests/ui/bind_instead_of_map.fixed b/tests/ui/bind_instead_of_map.fixed index ea2dc2e229327..910cec2f203dc 100644 --- a/tests/ui/bind_instead_of_map.fixed +++ b/tests/ui/bind_instead_of_map.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::bind_instead_of_map)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/bind_instead_of_map.rs b/tests/ui/bind_instead_of_map.rs index 1db58dae53860..6d66f659ba78b 100644 --- a/tests/ui/bind_instead_of_map.rs +++ b/tests/ui/bind_instead_of_map.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::bind_instead_of_map)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/bind_instead_of_map.stderr b/tests/ui/bind_instead_of_map.stderr index f17fee7460dc2..3af61e6d43b63 100644 --- a/tests/ui/bind_instead_of_map.stderr +++ b/tests/ui/bind_instead_of_map.stderr @@ -1,23 +1,23 @@ error: using `Option.and_then(Some)`, which is a no-op - --> $DIR/bind_instead_of_map.rs:9:13 + --> $DIR/bind_instead_of_map.rs:8:13 | LL | let _ = x.and_then(Some); | ^^^^^^^^^^^^^^^^ help: use the expression directly: `x` | note: the lint level is defined here - --> $DIR/bind_instead_of_map.rs:2:9 + --> $DIR/bind_instead_of_map.rs:1:9 | LL | #![deny(clippy::bind_instead_of_map)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map.rs:10:13 + --> $DIR/bind_instead_of_map.rs:9:13 | LL | let _ = x.and_then(|o| Some(o + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.map(|o| o + 1)` error: using `Result.and_then(Ok)`, which is a no-op - --> $DIR/bind_instead_of_map.rs:16:13 + --> $DIR/bind_instead_of_map.rs:15:13 | LL | let _ = x.and_then(Ok); | ^^^^^^^^^^^^^^ help: use the expression directly: `x` diff --git a/tests/ui/bind_instead_of_map_multipart.fixed b/tests/ui/bind_instead_of_map_multipart.fixed index 63c7aafcddb2c..8cbadc67d718d 100644 --- a/tests/ui/bind_instead_of_map_multipart.fixed +++ b/tests/ui/bind_instead_of_map_multipart.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::bind_instead_of_map)] #![allow(clippy::blocks_in_if_conditions)] diff --git a/tests/ui/bind_instead_of_map_multipart.rs b/tests/ui/bind_instead_of_map_multipart.rs index 69b982fa8a21b..91d9d11e3c110 100644 --- a/tests/ui/bind_instead_of_map_multipart.rs +++ b/tests/ui/bind_instead_of_map_multipart.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::bind_instead_of_map)] #![allow(clippy::blocks_in_if_conditions)] diff --git a/tests/ui/bind_instead_of_map_multipart.stderr b/tests/ui/bind_instead_of_map_multipart.stderr index cedbca785610a..63f25f26f2401 100644 --- a/tests/ui/bind_instead_of_map_multipart.stderr +++ b/tests/ui/bind_instead_of_map_multipart.stderr @@ -1,11 +1,11 @@ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:6:13 + --> $DIR/bind_instead_of_map_multipart.rs:5:13 | LL | let _ = Some("42").and_then(|s| if s.len() < 42 { Some(0) } else { Some(s.len()) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/bind_instead_of_map_multipart.rs:2:9 + --> $DIR/bind_instead_of_map_multipart.rs:1:9 | LL | #![deny(clippy::bind_instead_of_map)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); | ~~~ ~ ~~~~~~~ error: using `Result.and_then(|x| Ok(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:9:13 + --> $DIR/bind_instead_of_map_multipart.rs:8:13 | LL | let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { Ok(s.len()) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() | ~~~ ~ ~~~~~~~ error: using `Result.or_else(|x| Err(y))`, which is more succinctly expressed as `map_err(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:12:13 + --> $DIR/bind_instead_of_map_multipart.rs:11:13 | LL | let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + 20) } else { Err(s.len()) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } | ~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:20:5 + --> $DIR/bind_instead_of_map_multipart.rs:19:5 | LL | / Some("42").and_then(|s| { LL | | if { @@ -77,7 +77,7 @@ LL ~ _ => 1, | error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:61:13 + --> $DIR/bind_instead_of_map_multipart.rs:60:13 | LL | let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/blocks_in_if_conditions.fixed b/tests/ui/blocks_in_if_conditions.fixed index 2a3867ac8fc0e..f89c465047e42 100644 --- a/tests/ui/blocks_in_if_conditions.fixed +++ b/tests/ui/blocks_in_if_conditions.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::blocks_in_if_conditions)] #![allow(unused, clippy::let_and_return, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] diff --git a/tests/ui/blocks_in_if_conditions.rs b/tests/ui/blocks_in_if_conditions.rs index 704d09fbad3d9..34febc5fa2c47 100644 --- a/tests/ui/blocks_in_if_conditions.rs +++ b/tests/ui/blocks_in_if_conditions.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::blocks_in_if_conditions)] #![allow(unused, clippy::let_and_return, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] diff --git a/tests/ui/blocks_in_if_conditions.stderr b/tests/ui/blocks_in_if_conditions.stderr index 079f2feb5c486..2af7f3128c154 100644 --- a/tests/ui/blocks_in_if_conditions.stderr +++ b/tests/ui/blocks_in_if_conditions.stderr @@ -1,5 +1,5 @@ error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` - --> $DIR/blocks_in_if_conditions.rs:24:5 + --> $DIR/blocks_in_if_conditions.rs:23:5 | LL | / if { LL | | let x = 3; @@ -17,13 +17,13 @@ LL ~ }; if res { | error: omit braces around single expression condition - --> $DIR/blocks_in_if_conditions.rs:35:8 + --> $DIR/blocks_in_if_conditions.rs:34:8 | LL | if { true } { 6 } else { 10 } | ^^^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> $DIR/blocks_in_if_conditions.rs:40:8 + --> $DIR/blocks_in_if_conditions.rs:39:8 | LL | if true && x == 3 { 6 } else { 10 } | ^^^^^^^^^^^^^^ help: try: `x == 3` diff --git a/tests/ui/bool_assert_comparison.fixed b/tests/ui/bool_assert_comparison.fixed index 53f63444aefe2..63b8e27e1c6c5 100644 --- a/tests/ui/bool_assert_comparison.fixed +++ b/tests/ui/bool_assert_comparison.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::assertions_on_constants)] #![warn(clippy::bool_assert_comparison)] diff --git a/tests/ui/bool_assert_comparison.rs b/tests/ui/bool_assert_comparison.rs index 151d93a9233b1..58f81fedb7959 100644 --- a/tests/ui/bool_assert_comparison.rs +++ b/tests/ui/bool_assert_comparison.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::assertions_on_constants)] #![warn(clippy::bool_assert_comparison)] diff --git a/tests/ui/bool_assert_comparison.stderr b/tests/ui/bool_assert_comparison.stderr index 89cefc95a9f69..e0d718c4ed846 100644 --- a/tests/ui/bool_assert_comparison.stderr +++ b/tests/ui/bool_assert_comparison.stderr @@ -1,5 +1,5 @@ error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:89:5 + --> $DIR/bool_assert_comparison.rs:87:5 | LL | assert_eq!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + assert!(!"a".is_empty()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:90:5 + --> $DIR/bool_assert_comparison.rs:88:5 | LL | assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + assert!("".is_empty()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:91:5 + --> $DIR/bool_assert_comparison.rs:89:5 | LL | assert_eq!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + assert!("".is_empty()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:96:5 + --> $DIR/bool_assert_comparison.rs:94:5 | LL | assert_eq!(b, true); | ^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + assert!(b); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:99:5 + --> $DIR/bool_assert_comparison.rs:97:5 | LL | assert_ne!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + assert!("a".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:100:5 + --> $DIR/bool_assert_comparison.rs:98:5 | LL | assert_ne!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL + assert!(!"".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:101:5 + --> $DIR/bool_assert_comparison.rs:99:5 | LL | assert_ne!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL + assert!(!"".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:106:5 + --> $DIR/bool_assert_comparison.rs:104:5 | LL | assert_ne!(b, true); | ^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + assert!(!b); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:109:5 + --> $DIR/bool_assert_comparison.rs:107:5 | LL | debug_assert_eq!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + debug_assert!(!"a".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:110:5 + --> $DIR/bool_assert_comparison.rs:108:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:111:5 + --> $DIR/bool_assert_comparison.rs:109:5 | LL | debug_assert_eq!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:116:5 + --> $DIR/bool_assert_comparison.rs:114:5 | LL | debug_assert_eq!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL + debug_assert!(b); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:119:5 + --> $DIR/bool_assert_comparison.rs:117:5 | LL | debug_assert_ne!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL + debug_assert!("a".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:120:5 + --> $DIR/bool_assert_comparison.rs:118:5 | LL | debug_assert_ne!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -168,7 +168,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:121:5 + --> $DIR/bool_assert_comparison.rs:119:5 | LL | debug_assert_ne!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -180,7 +180,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:126:5 + --> $DIR/bool_assert_comparison.rs:124:5 | LL | debug_assert_ne!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -192,7 +192,7 @@ LL + debug_assert!(!b); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:131:5 + --> $DIR/bool_assert_comparison.rs:129:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -204,7 +204,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", 1); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:132:5 + --> $DIR/bool_assert_comparison.rs:130:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -216,7 +216,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:133:5 + --> $DIR/bool_assert_comparison.rs:131:5 | LL | assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -228,7 +228,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", true); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:138:5 + --> $DIR/bool_assert_comparison.rs:136:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", 1); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:139:5 + --> $DIR/bool_assert_comparison.rs:137:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -252,7 +252,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", true); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:140:5 + --> $DIR/bool_assert_comparison.rs:138:5 | LL | debug_assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -264,7 +264,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:143:5 + --> $DIR/bool_assert_comparison.rs:141:5 | LL | assert_eq!(a!(), true); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -276,7 +276,7 @@ LL + assert!(a!()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:144:5 + --> $DIR/bool_assert_comparison.rs:142:5 | LL | assert_eq!(true, b!()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -288,7 +288,7 @@ LL + assert!(b!()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:148:5 + --> $DIR/bool_assert_comparison.rs:146:5 | LL | renamed!(b, true); | ^^^^^^^^^^^^^^^^^ @@ -300,7 +300,7 @@ LL + debug_assert!(b); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:162:5 + --> $DIR/bool_assert_comparison.rs:160:5 | LL | assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -312,7 +312,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:163:5 + --> $DIR/bool_assert_comparison.rs:161:5 | LL | assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -324,7 +324,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:164:5 + --> $DIR/bool_assert_comparison.rs:162:5 | LL | assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -336,7 +336,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:165:5 + --> $DIR/bool_assert_comparison.rs:163:5 | LL | assert_eq!("requires negation".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -348,7 +348,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:167:5 + --> $DIR/bool_assert_comparison.rs:165:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -360,7 +360,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:168:5 + --> $DIR/bool_assert_comparison.rs:166:5 | LL | debug_assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -372,7 +372,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:169:5 + --> $DIR/bool_assert_comparison.rs:167:5 | LL | debug_assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -384,7 +384,7 @@ LL + debug_assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:170:5 + --> $DIR/bool_assert_comparison.rs:168:5 | LL | debug_assert_eq!("requires negation".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/bool_comparison.fixed b/tests/ui/bool_comparison.fixed index 8689f89d2c33a..db85247f47d24 100644 --- a/tests/ui/bool_comparison.fixed +++ b/tests/ui/bool_comparison.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::needless_if)] #![warn(clippy::bool_comparison)] #![allow(clippy::incorrect_partial_ord_impl_on_ord_type)] diff --git a/tests/ui/bool_comparison.rs b/tests/ui/bool_comparison.rs index a1c94aff94b20..0915f88544bc7 100644 --- a/tests/ui/bool_comparison.rs +++ b/tests/ui/bool_comparison.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::needless_if)] #![warn(clippy::bool_comparison)] #![allow(clippy::incorrect_partial_ord_impl_on_ord_type)] diff --git a/tests/ui/bool_comparison.stderr b/tests/ui/bool_comparison.stderr index 19bdf30135803..31522d4a52519 100644 --- a/tests/ui/bool_comparison.stderr +++ b/tests/ui/bool_comparison.stderr @@ -1,5 +1,5 @@ error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:9:8 + --> $DIR/bool_comparison.rs:7:8 | LL | if x == true { | ^^^^^^^^^ help: try simplifying it as shown: `x` @@ -7,127 +7,127 @@ LL | if x == true { = note: `-D clippy::bool-comparison` implied by `-D warnings` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:14:8 + --> $DIR/bool_comparison.rs:12:8 | LL | if x == false { | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:19:8 + --> $DIR/bool_comparison.rs:17:8 | LL | if true == x { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:24:8 + --> $DIR/bool_comparison.rs:22:8 | LL | if false == x { | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against true can be replaced by a negation - --> $DIR/bool_comparison.rs:29:8 + --> $DIR/bool_comparison.rs:27:8 | LL | if x != true { | ^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against false are unnecessary - --> $DIR/bool_comparison.rs:34:8 + --> $DIR/bool_comparison.rs:32:8 | LL | if x != false { | ^^^^^^^^^^ help: try simplifying it as shown: `x` error: inequality checks against true can be replaced by a negation - --> $DIR/bool_comparison.rs:39:8 + --> $DIR/bool_comparison.rs:37:8 | LL | if true != x { | ^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against false are unnecessary - --> $DIR/bool_comparison.rs:44:8 + --> $DIR/bool_comparison.rs:42:8 | LL | if false != x { | ^^^^^^^^^^ help: try simplifying it as shown: `x` error: less than comparison against true can be replaced by a negation - --> $DIR/bool_comparison.rs:49:8 + --> $DIR/bool_comparison.rs:47:8 | LL | if x < true { | ^^^^^^^^ help: try simplifying it as shown: `!x` error: greater than checks against false are unnecessary - --> $DIR/bool_comparison.rs:54:8 + --> $DIR/bool_comparison.rs:52:8 | LL | if false < x { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: greater than checks against false are unnecessary - --> $DIR/bool_comparison.rs:59:8 + --> $DIR/bool_comparison.rs:57:8 | LL | if x > false { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: less than comparison against true can be replaced by a negation - --> $DIR/bool_comparison.rs:64:8 + --> $DIR/bool_comparison.rs:62:8 | LL | if true > x { | ^^^^^^^^ help: try simplifying it as shown: `!x` error: order comparisons between booleans can be simplified - --> $DIR/bool_comparison.rs:70:8 + --> $DIR/bool_comparison.rs:68:8 | LL | if x < y { | ^^^^^ help: try simplifying it as shown: `!x & y` error: order comparisons between booleans can be simplified - --> $DIR/bool_comparison.rs:75:8 + --> $DIR/bool_comparison.rs:73:8 | LL | if x > y { | ^^^^^ help: try simplifying it as shown: `x & !y` error: this comparison might be written more concisely - --> $DIR/bool_comparison.rs:123:8 + --> $DIR/bool_comparison.rs:121:8 | LL | if a == !b {}; | ^^^^^^^ help: try simplifying it as shown: `a != b` error: this comparison might be written more concisely - --> $DIR/bool_comparison.rs:124:8 + --> $DIR/bool_comparison.rs:122:8 | LL | if !a == b {}; | ^^^^^^^ help: try simplifying it as shown: `a != b` error: this comparison might be written more concisely - --> $DIR/bool_comparison.rs:128:8 + --> $DIR/bool_comparison.rs:126:8 | LL | if b == !a {}; | ^^^^^^^ help: try simplifying it as shown: `b != a` error: this comparison might be written more concisely - --> $DIR/bool_comparison.rs:129:8 + --> $DIR/bool_comparison.rs:127:8 | LL | if !b == a {}; | ^^^^^^^ help: try simplifying it as shown: `b != a` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:153:8 + --> $DIR/bool_comparison.rs:151:8 | LL | if false == m!(func) {} | ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)` error: equality checks against false can be replaced by a negation - --> $DIR/bool_comparison.rs:154:8 + --> $DIR/bool_comparison.rs:152:8 | LL | if m!(func) == false {} | ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)` error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:155:8 + --> $DIR/bool_comparison.rs:153:8 | LL | if true == m!(func) {} | ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)` error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:156:8 + --> $DIR/bool_comparison.rs:154:8 | LL | if m!(func) == true {} | ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)` diff --git a/tests/ui/bool_to_int_with_if.fixed b/tests/ui/bool_to_int_with_if.fixed index fbb10a133e2b0..44d7f6e6d7964 100644 --- a/tests/ui/bool_to_int_with_if.fixed +++ b/tests/ui/bool_to_int_with_if.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(let_chains, inline_const)] #![warn(clippy::bool_to_int_with_if)] #![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)] diff --git a/tests/ui/bool_to_int_with_if.rs b/tests/ui/bool_to_int_with_if.rs index 709a18d63e401..7d989ae4bb310 100644 --- a/tests/ui/bool_to_int_with_if.rs +++ b/tests/ui/bool_to_int_with_if.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(let_chains, inline_const)] #![warn(clippy::bool_to_int_with_if)] #![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)] diff --git a/tests/ui/bool_to_int_with_if.stderr b/tests/ui/bool_to_int_with_if.stderr index 3bdae75cad22b..b0581e96834c2 100644 --- a/tests/ui/bool_to_int_with_if.stderr +++ b/tests/ui/bool_to_int_with_if.stderr @@ -1,5 +1,5 @@ error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:16:5 + --> $DIR/bool_to_int_with_if.rs:14:5 | LL | / if a { LL | | 1 @@ -12,7 +12,7 @@ LL | | }; = note: `-D clippy::bool-to-int-with-if` implied by `-D warnings` error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:21:5 + --> $DIR/bool_to_int_with_if.rs:19:5 | LL | / if a { LL | | 0 @@ -24,7 +24,7 @@ LL | | }; = note: `!a as i32` or `(!a).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:26:5 + --> $DIR/bool_to_int_with_if.rs:24:5 | LL | / if !a { LL | | 1 @@ -36,7 +36,7 @@ LL | | }; = note: `!a as i32` or `(!a).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:31:5 + --> $DIR/bool_to_int_with_if.rs:29:5 | LL | / if a || b { LL | | 1 @@ -48,7 +48,7 @@ LL | | }; = note: `(a || b) as i32` or `(a || b).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:36:5 + --> $DIR/bool_to_int_with_if.rs:34:5 | LL | / if cond(a, b) { LL | | 1 @@ -60,7 +60,7 @@ LL | | }; = note: `cond(a, b) as i32` or `cond(a, b).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:41:5 + --> $DIR/bool_to_int_with_if.rs:39:5 | LL | / if x + y < 4 { LL | | 1 @@ -72,7 +72,7 @@ LL | | }; = note: `(x + y < 4) as i32` or `(x + y < 4).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:50:12 + --> $DIR/bool_to_int_with_if.rs:48:12 | LL | } else if b { | ____________^ @@ -85,7 +85,7 @@ LL | | }; = note: `b as i32` or `b.into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:59:12 + --> $DIR/bool_to_int_with_if.rs:57:12 | LL | } else if b { | ____________^ @@ -98,7 +98,7 @@ LL | | }; = note: `!b as i32` or `(!b).into()` can also be valid options error: boolean to int conversion using if - --> $DIR/bool_to_int_with_if.rs:126:5 + --> $DIR/bool_to_int_with_if.rs:124:5 | LL | if a { 1 } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(a)` diff --git a/tests/ui/borrow_as_ptr.fixed b/tests/ui/borrow_as_ptr.fixed index 996cc3650ff0a..6c0de96d65e36 100644 --- a/tests/ui/borrow_as_ptr.fixed +++ b/tests/ui/borrow_as_ptr.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::borrow_as_ptr)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/borrow_as_ptr.rs b/tests/ui/borrow_as_ptr.rs index 5eafaeb2fc306..c37c5357c82c0 100644 --- a/tests/ui/borrow_as_ptr.rs +++ b/tests/ui/borrow_as_ptr.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::borrow_as_ptr)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/borrow_as_ptr.stderr b/tests/ui/borrow_as_ptr.stderr index c9990bb6f2266..b0e4e9363f1ff 100644 --- a/tests/ui/borrow_as_ptr.stderr +++ b/tests/ui/borrow_as_ptr.stderr @@ -1,5 +1,5 @@ error: borrow as raw pointer - --> $DIR/borrow_as_ptr.rs:11:14 + --> $DIR/borrow_as_ptr.rs:10:14 | LL | let _p = &val as *const i32; | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::addr_of!(val)` @@ -7,7 +7,7 @@ LL | let _p = &val as *const i32; = note: `-D clippy::borrow-as-ptr` implied by `-D warnings` error: borrow as raw pointer - --> $DIR/borrow_as_ptr.rs:18:18 + --> $DIR/borrow_as_ptr.rs:17:18 | LL | let _p_mut = &mut val_mut as *mut i32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::addr_of_mut!(val_mut)` diff --git a/tests/ui/borrow_as_ptr_no_std.fixed b/tests/ui/borrow_as_ptr_no_std.fixed index 10f2727c793cd..a361a36474de5 100644 --- a/tests/ui/borrow_as_ptr_no_std.fixed +++ b/tests/ui/borrow_as_ptr_no_std.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::borrow_as_ptr)] #![feature(lang_items, start, libc)] #![no_std] diff --git a/tests/ui/borrow_as_ptr_no_std.rs b/tests/ui/borrow_as_ptr_no_std.rs index 311e9341aac25..b3fe01442b745 100644 --- a/tests/ui/borrow_as_ptr_no_std.rs +++ b/tests/ui/borrow_as_ptr_no_std.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::borrow_as_ptr)] #![feature(lang_items, start, libc)] #![no_std] diff --git a/tests/ui/borrow_as_ptr_no_std.stderr b/tests/ui/borrow_as_ptr_no_std.stderr index 84c8ba7d07f1e..4a0467cdbfe13 100644 --- a/tests/ui/borrow_as_ptr_no_std.stderr +++ b/tests/ui/borrow_as_ptr_no_std.stderr @@ -1,5 +1,5 @@ error: borrow as raw pointer - --> $DIR/borrow_as_ptr_no_std.rs:9:14 + --> $DIR/borrow_as_ptr_no_std.rs:8:14 | LL | let _p = &val as *const i32; | ^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::addr_of!(val)` @@ -7,7 +7,7 @@ LL | let _p = &val as *const i32; = note: `-D clippy::borrow-as-ptr` implied by `-D warnings` error: borrow as raw pointer - --> $DIR/borrow_as_ptr_no_std.rs:12:18 + --> $DIR/borrow_as_ptr_no_std.rs:11:18 | LL | let _p_mut = &mut val_mut as *mut i32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::addr_of_mut!(val_mut)` diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index 95b6b0f50383a..1c0fd470ddb04 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -5,6 +5,7 @@ clippy::disallowed_names, clippy::needless_pass_by_ref_mut )] +//@no-rustfix use std::fmt::Display; diff --git a/tests/ui/borrow_box.stderr b/tests/ui/borrow_box.stderr index 90e752211ff05..6f498d2338d99 100644 --- a/tests/ui/borrow_box.stderr +++ b/tests/ui/borrow_box.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:24:14 + --> $DIR/borrow_box.rs:25:14 | LL | let foo: &Box; | ^^^^^^^^^^ help: try: `&bool` @@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)] | ^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:28:10 + --> $DIR/borrow_box.rs:29:10 | LL | foo: &'a Box, | ^^^^^^^^^^^^^ help: try: `&'a bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:32:17 + --> $DIR/borrow_box.rs:33:17 | LL | fn test4(a: &Box); | ^^^^^^^^^^ help: try: `&bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:98:25 + --> $DIR/borrow_box.rs:99:25 | LL | pub fn test14(_display: &Box) {} | ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:99:25 + --> $DIR/borrow_box.rs:100:25 | LL | pub fn test15(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:100:29 + --> $DIR/borrow_box.rs:101:29 | LL | pub fn test16<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:102:25 + --> $DIR/borrow_box.rs:103:25 | LL | pub fn test17(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:103:25 + --> $DIR/borrow_box.rs:104:25 | LL | pub fn test18(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:104:29 + --> $DIR/borrow_box.rs:105:29 | LL | pub fn test19<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:109:25 + --> $DIR/borrow_box.rs:110:25 | LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` diff --git a/tests/ui/borrow_deref_ref.fixed b/tests/ui/borrow_deref_ref.fixed index b951ba04c37f4..c7c22c7a0c9f1 100644 --- a/tests/ui/borrow_deref_ref.fixed +++ b/tests/ui/borrow_deref_ref.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![allow(dead_code, unused_variables)] diff --git a/tests/ui/borrow_deref_ref.rs b/tests/ui/borrow_deref_ref.rs index 52980e55fbea0..9e004ad7041fb 100644 --- a/tests/ui/borrow_deref_ref.rs +++ b/tests/ui/borrow_deref_ref.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![allow(dead_code, unused_variables)] diff --git a/tests/ui/borrow_deref_ref.stderr b/tests/ui/borrow_deref_ref.stderr index 1e47cda679601..524cf597c7f27 100644 --- a/tests/ui/borrow_deref_ref.stderr +++ b/tests/ui/borrow_deref_ref.stderr @@ -1,5 +1,5 @@ error: deref on an immutable reference - --> $DIR/borrow_deref_ref.rs:14:17 + --> $DIR/borrow_deref_ref.rs:13:17 | LL | let b = &*a; | ^^^ help: if you would like to reborrow, try removing `&*`: `a` @@ -7,13 +7,13 @@ LL | let b = &*a; = note: `-D clippy::borrow-deref-ref` implied by `-D warnings` error: deref on an immutable reference - --> $DIR/borrow_deref_ref.rs:16:22 + --> $DIR/borrow_deref_ref.rs:15:22 | LL | let b = &mut &*bar(&12); | ^^^^^^^^^^ help: if you would like to reborrow, try removing `&*`: `bar(&12)` error: deref on an immutable reference - --> $DIR/borrow_deref_ref.rs:70:23 + --> $DIR/borrow_deref_ref.rs:69:23 | LL | let addr_y = &&*x as *const _ as usize; // assert ok | ^^^ help: if you would like to reborrow, try removing `&*`: `x` diff --git a/tests/ui/borrow_deref_ref_unfixable.rs b/tests/ui/borrow_deref_ref_unfixable.rs index a8e2bbfef0f5a..5e7a8d514b546 100644 --- a/tests/ui/borrow_deref_ref_unfixable.rs +++ b/tests/ui/borrow_deref_ref_unfixable.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(dead_code, unused_variables)] fn main() {} diff --git a/tests/ui/borrow_deref_ref_unfixable.stderr b/tests/ui/borrow_deref_ref_unfixable.stderr index 738b01e7ec1ee..5650f722b54bf 100644 --- a/tests/ui/borrow_deref_ref_unfixable.stderr +++ b/tests/ui/borrow_deref_ref_unfixable.stderr @@ -1,5 +1,5 @@ error: deref on an immutable reference - --> $DIR/borrow_deref_ref_unfixable.rs:8:23 + --> $DIR/borrow_deref_ref_unfixable.rs:9:23 | LL | let x: &str = &*s; | ^^^ diff --git a/tests/ui/box_default.fixed b/tests/ui/box_default.fixed index 840902b5323e7..22c034c88ab1c 100644 --- a/tests/ui/box_default.fixed +++ b/tests/ui/box_default.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::box_default)] #![allow(clippy::default_constructed_unit_structs)] diff --git a/tests/ui/box_default.rs b/tests/ui/box_default.rs index 3618486a4732e..89e3888ba211a 100644 --- a/tests/ui/box_default.rs +++ b/tests/ui/box_default.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::box_default)] #![allow(clippy::default_constructed_unit_structs)] diff --git a/tests/ui/box_default.stderr b/tests/ui/box_default.stderr index 13dfc5ae48a22..8c4778983d390 100644 --- a/tests/ui/box_default.stderr +++ b/tests/ui/box_default.stderr @@ -1,5 +1,5 @@ error: `Box::new(_)` of default value - --> $DIR/box_default.rs:23:32 + --> $DIR/box_default.rs:22:32 | LL | let _string: Box = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` @@ -7,91 +7,91 @@ LL | let _string: Box = Box::new(Default::default()); = note: `-D clippy::box-default` implied by `-D warnings` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:24:17 + --> $DIR/box_default.rs:23:17 | LL | let _byte = Box::new(u8::default()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:25:16 + --> $DIR/box_default.rs:24:16 | LL | let _vec = Box::new(Vec::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::>::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:26:17 + --> $DIR/box_default.rs:25:17 | LL | let _impl = Box::new(ImplementsDefault::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:27:18 + --> $DIR/box_default.rs:26:18 | LL | let _impl2 = Box::new(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:28:42 + --> $DIR/box_default.rs:27:42 | LL | let _impl3: Box = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:30:28 + --> $DIR/box_default.rs:29:28 | LL | let _in_macro = outer!(Box::new(String::new())); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:31:34 + --> $DIR/box_default.rs:30:34 | LL | let _string_default = outer!(Box::new(String::from(""))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:32:46 + --> $DIR/box_default.rs:31:46 | LL | let _vec2: Box> = Box::new(vec![]); | ^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:33:33 + --> $DIR/box_default.rs:32:33 | LL | let _vec3: Box> = Box::new(Vec::from([])); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:34:25 + --> $DIR/box_default.rs:33:25 | LL | let _vec4: Box<_> = Box::new(Vec::from([false; 0])); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::>::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:36:16 + --> $DIR/box_default.rs:35:16 | LL | call_ty_fn(Box::new(u8::default())); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:48:5 + --> $DIR/box_default.rs:47:5 | LL | Box::new(bool::default()) | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:65:28 + --> $DIR/box_default.rs:64:28 | LL | let _: Box = Box::new(ImplementsDefault::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:74:17 + --> $DIR/box_default.rs:73:17 | LL | let _ = Box::new(WeirdPathed::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:86:18 + --> $DIR/box_default.rs:85:18 | LL | Some(Box::new(Foo::default())) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` diff --git a/tests/ui/branches_sharing_code/shared_at_bottom.rs b/tests/ui/branches_sharing_code/shared_at_bottom.rs index 6a63008b5a74b..e2ce3f6ff28a5 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.rs +++ b/tests/ui/branches_sharing_code/shared_at_bottom.rs @@ -1,7 +1,7 @@ #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] #![allow(dead_code)] #![allow(clippy::equatable_if_let, clippy::uninlined_format_args)] - +//@no-rustfix // This tests the branches_sharing_code lint at the end of blocks fn simple_examples() { diff --git a/tests/ui/branches_sharing_code/shared_at_top.rs b/tests/ui/branches_sharing_code/shared_at_top.rs index 9e0b99f166651..ac206ac8741e9 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.rs +++ b/tests/ui/branches_sharing_code/shared_at_top.rs @@ -1,7 +1,7 @@ #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)] #![allow(dead_code)] #![allow(clippy::mixed_read_write_in_expression, clippy::uninlined_format_args)] - +//@no-rustfix // This tests the branches_sharing_code lint at the start of blocks fn simple_examples() { diff --git a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs index 93b8c6e10dae6..eb0b937e22089 100644 --- a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs +++ b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs @@ -1,7 +1,7 @@ #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)] #![allow(dead_code)] #![allow(clippy::uninlined_format_args)] - +//@no-rustfix // branches_sharing_code at the top and bottom of the if blocks struct DataPack { diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index 4d168bfeab93a..10a1d904bf6c7 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -1,3 +1,5 @@ +//@no-rustfix + #![allow(clippy::needless_borrow, clippy::useless_vec)] #[deny(clippy::naive_bytecount)] diff --git a/tests/ui/bytecount.stderr b/tests/ui/bytecount.stderr index 68d838c1f828a..2b7dc2ac08748 100644 --- a/tests/ui/bytecount.stderr +++ b/tests/ui/bytecount.stderr @@ -1,23 +1,23 @@ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:7:13 + --> $DIR/bytecount.rs:9:13 | LL | let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, 0)` | note: the lint level is defined here - --> $DIR/bytecount.rs:3:8 + --> $DIR/bytecount.rs:5:8 | LL | #[deny(clippy::naive_bytecount)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:9:13 + --> $DIR/bytecount.rs:11:13 | LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count((&x[..]), 0)` error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:21:13 + --> $DIR/bytecount.rs:23:13 | LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, b + 1)` diff --git a/tests/ui/bytes_count_to_len.fixed b/tests/ui/bytes_count_to_len.fixed index fb3d521badd52..d20af22535a00 100644 --- a/tests/ui/bytes_count_to_len.fixed +++ b/tests/ui/bytes_count_to_len.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::bytes_count_to_len)] use std::fs::File; use std::io::Read; diff --git a/tests/ui/bytes_count_to_len.rs b/tests/ui/bytes_count_to_len.rs index 8e256b8f0b8ab..340e6b412556b 100644 --- a/tests/ui/bytes_count_to_len.rs +++ b/tests/ui/bytes_count_to_len.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::bytes_count_to_len)] use std::fs::File; use std::io::Read; diff --git a/tests/ui/bytes_count_to_len.stderr b/tests/ui/bytes_count_to_len.stderr index 224deb779871c..fe2c8b0627dc2 100644 --- a/tests/ui/bytes_count_to_len.stderr +++ b/tests/ui/bytes_count_to_len.stderr @@ -1,5 +1,5 @@ error: using long and hard to read `.bytes().count()` - --> $DIR/bytes_count_to_len.rs:8:13 + --> $DIR/bytes_count_to_len.rs:7:13 | LL | let _ = String::from("foo").bytes().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `String::from("foo").len()` @@ -7,19 +7,19 @@ LL | let _ = String::from("foo").bytes().count(); = note: `-D clippy::bytes-count-to-len` implied by `-D warnings` error: using long and hard to read `.bytes().count()` - --> $DIR/bytes_count_to_len.rs:11:13 + --> $DIR/bytes_count_to_len.rs:10:13 | LL | let _ = s1.bytes().count(); | ^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `s1.len()` error: using long and hard to read `.bytes().count()` - --> $DIR/bytes_count_to_len.rs:14:13 + --> $DIR/bytes_count_to_len.rs:13:13 | LL | let _ = "foo".bytes().count(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `"foo".len()` error: using long and hard to read `.bytes().count()` - --> $DIR/bytes_count_to_len.rs:17:13 + --> $DIR/bytes_count_to_len.rs:16:13 | LL | let _ = s2.bytes().count(); | ^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `s2.len()` diff --git a/tests/ui/bytes_nth.fixed b/tests/ui/bytes_nth.fixed index d3e0f676b29f9..11deb2390fd49 100644 --- a/tests/ui/bytes_nth.fixed +++ b/tests/ui/bytes_nth.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::unnecessary_operation)] #![warn(clippy::bytes_nth)] diff --git a/tests/ui/bytes_nth.rs b/tests/ui/bytes_nth.rs index b7d813fe296a9..62d9c7a5ea79b 100644 --- a/tests/ui/bytes_nth.rs +++ b/tests/ui/bytes_nth.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::unnecessary_operation)] #![warn(clippy::bytes_nth)] diff --git a/tests/ui/bytes_nth.stderr b/tests/ui/bytes_nth.stderr index e8b15027829e3..d9ede64a3815a 100644 --- a/tests/ui/bytes_nth.stderr +++ b/tests/ui/bytes_nth.stderr @@ -1,5 +1,5 @@ error: called `.bytes().nth()` on a `String` - --> $DIR/bytes_nth.rs:8:13 + --> $DIR/bytes_nth.rs:6:13 | LL | let _ = s.bytes().nth(3); | ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3).copied()` @@ -7,13 +7,13 @@ LL | let _ = s.bytes().nth(3); = note: `-D clippy::bytes-nth` implied by `-D warnings` error: called `.bytes().nth().unwrap()` on a `String` - --> $DIR/bytes_nth.rs:9:14 + --> $DIR/bytes_nth.rs:7:14 | LL | let _ = &s.bytes().nth(3).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.as_bytes()[3]` error: called `.bytes().nth()` on a `str` - --> $DIR/bytes_nth.rs:10:13 + --> $DIR/bytes_nth.rs:8:13 | LL | let _ = s[..].bytes().nth(3); | ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3).copied()` diff --git a/tests/ui/case_sensitive_file_extension_comparisons.fixed b/tests/ui/case_sensitive_file_extension_comparisons.fixed index d5af22aefe5df..a816224c91c8d 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.fixed +++ b/tests/ui/case_sensitive_file_extension_comparisons.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::case_sensitive_file_extension_comparisons)] use std::string::String; diff --git a/tests/ui/case_sensitive_file_extension_comparisons.rs b/tests/ui/case_sensitive_file_extension_comparisons.rs index f5f0a0022a42a..994de2805f742 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.rs +++ b/tests/ui/case_sensitive_file_extension_comparisons.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::case_sensitive_file_extension_comparisons)] use std::string::String; diff --git a/tests/ui/case_sensitive_file_extension_comparisons.stderr b/tests/ui/case_sensitive_file_extension_comparisons.stderr index 44c8e3fdf7403..9abf8aaca93bf 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.stderr +++ b/tests/ui/case_sensitive_file_extension_comparisons.stderr @@ -1,5 +1,5 @@ error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:14:5 + --> $DIR/case_sensitive_file_extension_comparisons.rs:13:5 | LL | filename.ends_with(".rs") | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,7 +14,7 @@ LL + .map_or(false, |ext| ext.eq_ignore_ascii_case("rs")) | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:19:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:18:13 | LL | let _ = String::new().ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:20:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:19:13 | LL | let _ = "str".ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:24:17 + --> $DIR/case_sensitive_file_extension_comparisons.rs:23:17 | LL | let _ = "str".ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12")); | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:31:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:30:13 | LL | let _ = String::new().ends_with(".EXT12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12")); | error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:32:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:31:13 | LL | let _ = "str".ends_with(".EXT12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index 60a0eabf55b0b..d5ebe67c4e9fa 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -1,3 +1,5 @@ +//@no-rustfix + #![feature(repr128)] #![allow(incomplete_features)] #![warn( diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index de29af78ef30c..ff2a4294512b5 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -1,5 +1,5 @@ error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:14:5 + --> $DIR/cast.rs:16:5 | LL | x0 as f32; | ^^^^^^^^^ @@ -7,37 +7,37 @@ LL | x0 as f32; = note: `-D clippy::cast-precision-loss` implied by `-D warnings` error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:16:5 + --> $DIR/cast.rs:18:5 | LL | x1 as f32; | ^^^^^^^^^ error: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast.rs:17:5 + --> $DIR/cast.rs:19:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:19:5 + --> $DIR/cast.rs:21:5 | LL | x2 as f32; | ^^^^^^^^^ error: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:21:5 + --> $DIR/cast.rs:23:5 | LL | x3 as f32; | ^^^^^^^^^ error: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast.rs:22:5 + --> $DIR/cast.rs:24:5 | LL | x3 as f64; | ^^^^^^^^^ error: casting `f32` to `i32` may truncate the value - --> $DIR/cast.rs:24:5 + --> $DIR/cast.rs:26:5 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | 1f32 as i32; = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` error: casting `f32` to `u32` may truncate the value - --> $DIR/cast.rs:25:5 + --> $DIR/cast.rs:27:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | 1f32 as u32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:25:5 + --> $DIR/cast.rs:27:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL | 1f32 as u32; = note: `-D clippy::cast-sign-loss` implied by `-D warnings` error: casting `f64` to `f32` may truncate the value - --> $DIR/cast.rs:26:5 + --> $DIR/cast.rs:28:5 | LL | 1f64 as f32; | ^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | 1f64 as f32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `i32` to `i8` may truncate the value - --> $DIR/cast.rs:27:5 + --> $DIR/cast.rs:29:5 | LL | 1i32 as i8; | ^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | i8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u8` may truncate the value - --> $DIR/cast.rs:28:5 + --> $DIR/cast.rs:30:5 | LL | 1i32 as u8; | ^^^^^^^^^^ @@ -94,7 +94,7 @@ LL | u8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `f64` to `isize` may truncate the value - --> $DIR/cast.rs:29:5 + --> $DIR/cast.rs:31:5 | LL | 1f64 as isize; | ^^^^^^^^^^^^^ @@ -102,7 +102,7 @@ LL | 1f64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may truncate the value - --> $DIR/cast.rs:30:5 + --> $DIR/cast.rs:32:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ @@ -110,13 +110,13 @@ LL | 1f64 as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may lose the sign of the value - --> $DIR/cast.rs:30:5 + --> $DIR/cast.rs:32:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ error: casting `u32` to `u16` may truncate the value - --> $DIR/cast.rs:31:5 + --> $DIR/cast.rs:33:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^^^^^^^^ @@ -128,7 +128,7 @@ LL | u16::try_from(1f32 as u32); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `f32` to `u32` may truncate the value - --> $DIR/cast.rs:31:5 + --> $DIR/cast.rs:33:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ @@ -136,13 +136,13 @@ LL | 1f32 as u32 as u16; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:31:5 + --> $DIR/cast.rs:33:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ error: casting `i32` to `i8` may truncate the value - --> $DIR/cast.rs:33:22 + --> $DIR/cast.rs:35:22 | LL | let _x: i8 = 1i32 as _; | ^^^^^^^^^ @@ -154,7 +154,7 @@ LL | let _x: i8 = 1i32.try_into(); | ~~~~~~~~~~~~~~~ error: casting `f32` to `i32` may truncate the value - --> $DIR/cast.rs:34:9 + --> $DIR/cast.rs:36:9 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -162,7 +162,7 @@ LL | 1f32 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `i32` may truncate the value - --> $DIR/cast.rs:35:9 + --> $DIR/cast.rs:37:9 | LL | 1f64 as i32; | ^^^^^^^^^^^ @@ -170,7 +170,7 @@ LL | 1f64 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may truncate the value - --> $DIR/cast.rs:36:9 + --> $DIR/cast.rs:38:9 | LL | 1f32 as u8; | ^^^^^^^^^^ @@ -178,13 +178,13 @@ LL | 1f32 as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may lose the sign of the value - --> $DIR/cast.rs:36:9 + --> $DIR/cast.rs:38:9 | LL | 1f32 as u8; | ^^^^^^^^^^ error: casting `u8` to `i8` may wrap around the value - --> $DIR/cast.rs:39:5 + --> $DIR/cast.rs:41:5 | LL | 1u8 as i8; | ^^^^^^^^^ @@ -192,31 +192,31 @@ LL | 1u8 as i8; = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` error: casting `u16` to `i16` may wrap around the value - --> $DIR/cast.rs:40:5 + --> $DIR/cast.rs:42:5 | LL | 1u16 as i16; | ^^^^^^^^^^^ error: casting `u32` to `i32` may wrap around the value - --> $DIR/cast.rs:41:5 + --> $DIR/cast.rs:43:5 | LL | 1u32 as i32; | ^^^^^^^^^^^ error: casting `u64` to `i64` may wrap around the value - --> $DIR/cast.rs:42:5 + --> $DIR/cast.rs:44:5 | LL | 1u64 as i64; | ^^^^^^^^^^^ error: casting `usize` to `isize` may wrap around the value - --> $DIR/cast.rs:43:5 + --> $DIR/cast.rs:45:5 | LL | 1usize as isize; | ^^^^^^^^^^^^^^^ error: casting `usize` to `i8` may truncate the value - --> $DIR/cast.rs:44:5 + --> $DIR/cast.rs:46:5 | LL | 1usize as i8; // should not wrap, usize is never 8 bits | ^^^^^^^^^^^^ @@ -228,7 +228,7 @@ LL | i8::try_from(1usize); // should not wrap, usize is never 8 bits | ~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may truncate the value - --> $DIR/cast.rs:45:5 + --> $DIR/cast.rs:47:5 | LL | 1usize as i16; // wraps on 16 bit ptr size | ^^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL | i16::try_from(1usize); // wraps on 16 bit ptr size | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:45:5 + --> $DIR/cast.rs:47:5 | LL | 1usize as i16; // wraps on 16 bit ptr size | ^^^^^^^^^^^^^ @@ -249,7 +249,7 @@ LL | 1usize as i16; // wraps on 16 bit ptr size = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:46:5 + --> $DIR/cast.rs:48:5 | LL | 1usize as i32; // wraps on 32 bit ptr size | ^^^^^^^^^^^^^ @@ -261,19 +261,19 @@ LL | i32::try_from(1usize); // wraps on 32 bit ptr size | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:46:5 + --> $DIR/cast.rs:48:5 | LL | 1usize as i32; // wraps on 32 bit ptr size | ^^^^^^^^^^^^^ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:47:5 + --> $DIR/cast.rs:49:5 | LL | 1usize as i64; // wraps on 64 bit ptr size | ^^^^^^^^^^^^^ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:49:5 + --> $DIR/cast.rs:51:5 | LL | 1u16 as isize; // wraps on 16 bit ptr size | ^^^^^^^^^^^^^ @@ -282,13 +282,13 @@ LL | 1u16 as isize; // wraps on 16 bit ptr size = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:50:5 + --> $DIR/cast.rs:52:5 | LL | 1u32 as isize; // wraps on 32 bit ptr size | ^^^^^^^^^^^^^ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:53:5 | LL | 1u64 as isize; // wraps on 64 bit ptr size | ^^^^^^^^^^^^^ @@ -300,25 +300,25 @@ LL | isize::try_from(1u64); // wraps on 64 bit ptr size | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:53:5 | LL | 1u64 as isize; // wraps on 64 bit ptr size | ^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:54:5 + --> $DIR/cast.rs:56:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> $DIR/cast.rs:56:5 + --> $DIR/cast.rs:58:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> $DIR/cast.rs:123:5 + --> $DIR/cast.rs:125:5 | LL | (-99999999999i64).min(1) as i8; // should be linted because signed | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -330,7 +330,7 @@ LL | i8::try_from((-99999999999i64).min(1)); // should be linted because sig | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> $DIR/cast.rs:135:5 + --> $DIR/cast.rs:137:5 | LL | 999999u64.clamp(0, 256) as u8; // should still be linted | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -342,7 +342,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E2` to `u8` may truncate the value - --> $DIR/cast.rs:156:21 + --> $DIR/cast.rs:158:21 | LL | let _ = self as u8; | ^^^^^^^^^^ @@ -354,7 +354,7 @@ LL | let _ = u8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E2::B` to `u8` will truncate the value - --> $DIR/cast.rs:157:21 + --> $DIR/cast.rs:159:21 | LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ @@ -362,7 +362,7 @@ LL | let _ = Self::B as u8; = note: `-D clippy::cast-enum-truncation` implied by `-D warnings` error: casting `main::E5` to `i8` may truncate the value - --> $DIR/cast.rs:193:21 + --> $DIR/cast.rs:195:21 | LL | let _ = self as i8; | ^^^^^^^^^^ @@ -374,13 +374,13 @@ LL | let _ = i8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E5::A` to `i8` will truncate the value - --> $DIR/cast.rs:194:21 + --> $DIR/cast.rs:196:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> $DIR/cast.rs:208:21 + --> $DIR/cast.rs:210:21 | LL | let _ = self as i16; | ^^^^^^^^^^^ @@ -392,7 +392,7 @@ LL | let _ = i16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:223:21 + --> $DIR/cast.rs:225:21 | LL | let _ = self as usize; | ^^^^^^^^^^^^^ @@ -404,7 +404,7 @@ LL | let _ = usize::try_from(self); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E10` to `u16` may truncate the value - --> $DIR/cast.rs:264:21 + --> $DIR/cast.rs:266:21 | LL | let _ = self as u16; | ^^^^^^^^^^^ @@ -416,7 +416,7 @@ LL | let _ = u16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:272:13 + --> $DIR/cast.rs:274:13 | LL | let c = (q >> 16) as u8; | ^^^^^^^^^^^^^^^ @@ -428,7 +428,7 @@ LL | let c = u8::try_from(q >> 16); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:275:13 + --> $DIR/cast.rs:277:13 | LL | let c = (q / 1000) as u8; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_abs_to_unsigned.fixed b/tests/ui/cast_abs_to_unsigned.fixed index ef0a93b01d1f6..6ca01b7cc3670 100644 --- a/tests/ui/cast_abs_to_unsigned.fixed +++ b/tests/ui/cast_abs_to_unsigned.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::cast_abs_to_unsigned)] #![allow(clippy::uninlined_format_args, unused)] diff --git a/tests/ui/cast_abs_to_unsigned.rs b/tests/ui/cast_abs_to_unsigned.rs index 96ced670a0559..190a77c102326 100644 --- a/tests/ui/cast_abs_to_unsigned.rs +++ b/tests/ui/cast_abs_to_unsigned.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::cast_abs_to_unsigned)] #![allow(clippy::uninlined_format_args, unused)] diff --git a/tests/ui/cast_abs_to_unsigned.stderr b/tests/ui/cast_abs_to_unsigned.stderr index 4668554f4511c..94b87df0b6ece 100644 --- a/tests/ui/cast_abs_to_unsigned.stderr +++ b/tests/ui/cast_abs_to_unsigned.stderr @@ -1,5 +1,5 @@ error: casting the result of `i32::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:8:18 + --> $DIR/cast_abs_to_unsigned.rs:6:18 | LL | let y: u32 = x.abs() as u32; | ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()` @@ -7,103 +7,103 @@ LL | let y: u32 = x.abs() as u32; = note: `-D clippy::cast-abs-to-unsigned` implied by `-D warnings` error: casting the result of `i32::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:12:20 + --> $DIR/cast_abs_to_unsigned.rs:10:20 | LL | let _: usize = a.abs() as usize; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i32::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:13:20 + --> $DIR/cast_abs_to_unsigned.rs:11:20 | LL | let _: usize = a.abs() as _; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i32::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:14:13 + --> $DIR/cast_abs_to_unsigned.rs:12:13 | LL | let _ = a.abs() as usize; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:17:13 + --> $DIR/cast_abs_to_unsigned.rs:15:13 | LL | let _ = a.abs() as usize; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u8 - --> $DIR/cast_abs_to_unsigned.rs:18:13 + --> $DIR/cast_abs_to_unsigned.rs:16:13 | LL | let _ = a.abs() as u8; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u16 - --> $DIR/cast_abs_to_unsigned.rs:19:13 + --> $DIR/cast_abs_to_unsigned.rs:17:13 | LL | let _ = a.abs() as u16; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:20:13 + --> $DIR/cast_abs_to_unsigned.rs:18:13 | LL | let _ = a.abs() as u32; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u64 - --> $DIR/cast_abs_to_unsigned.rs:21:13 + --> $DIR/cast_abs_to_unsigned.rs:19:13 | LL | let _ = a.abs() as u64; | ^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u128 - --> $DIR/cast_abs_to_unsigned.rs:22:13 + --> $DIR/cast_abs_to_unsigned.rs:20:13 | LL | let _ = a.abs() as u128; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:25:13 + --> $DIR/cast_abs_to_unsigned.rs:23:13 | LL | let _ = a.abs() as usize; | ^^^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u8 - --> $DIR/cast_abs_to_unsigned.rs:26:13 + --> $DIR/cast_abs_to_unsigned.rs:24:13 | LL | let _ = a.abs() as u8; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u16 - --> $DIR/cast_abs_to_unsigned.rs:27:13 + --> $DIR/cast_abs_to_unsigned.rs:25:13 | LL | let _ = a.abs() as u16; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:28:13 + --> $DIR/cast_abs_to_unsigned.rs:26:13 | LL | let _ = a.abs() as u32; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u64 - --> $DIR/cast_abs_to_unsigned.rs:29:13 + --> $DIR/cast_abs_to_unsigned.rs:27:13 | LL | let _ = a.abs() as u64; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u128 - --> $DIR/cast_abs_to_unsigned.rs:30:13 + --> $DIR/cast_abs_to_unsigned.rs:28:13 | LL | let _ = a.abs() as u128; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:32:13 + --> $DIR/cast_abs_to_unsigned.rs:30:13 | LL | let _ = (x as i64 - y as i64).abs() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `(x as i64 - y as i64).unsigned_abs()` error: casting the result of `i32::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:44:23 + --> $DIR/cast_abs_to_unsigned.rs:42:23 | LL | assert_eq!(10u32, x.abs() as u32); | ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()` diff --git a/tests/ui/cast_lossless_bool.fixed b/tests/ui/cast_lossless_bool.fixed index c321cc6443784..a4ce1c6f928e7 100644 --- a/tests/ui/cast_lossless_bool.fixed +++ b/tests/ui/cast_lossless_bool.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] #![warn(clippy::cast_lossless)] diff --git a/tests/ui/cast_lossless_bool.rs b/tests/ui/cast_lossless_bool.rs index 632a718920d41..e5b1c30c10350 100644 --- a/tests/ui/cast_lossless_bool.rs +++ b/tests/ui/cast_lossless_bool.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] #![warn(clippy::cast_lossless)] diff --git a/tests/ui/cast_lossless_bool.stderr b/tests/ui/cast_lossless_bool.stderr index ce240b70f891d..891476f304df0 100644 --- a/tests/ui/cast_lossless_bool.stderr +++ b/tests/ui/cast_lossless_bool.stderr @@ -1,5 +1,5 @@ error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)` - --> $DIR/cast_lossless_bool.rs:8:13 + --> $DIR/cast_lossless_bool.rs:6:13 | LL | let _ = true as u8; | ^^^^^^^^^^ help: try: `u8::from(true)` @@ -7,79 +7,79 @@ LL | let _ = true as u8; = note: `-D clippy::cast-lossless` implied by `-D warnings` error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)` - --> $DIR/cast_lossless_bool.rs:9:13 + --> $DIR/cast_lossless_bool.rs:7:13 | LL | let _ = true as u16; | ^^^^^^^^^^^ help: try: `u16::from(true)` error: casting `bool` to `u32` is more cleanly stated with `u32::from(_)` - --> $DIR/cast_lossless_bool.rs:10:13 + --> $DIR/cast_lossless_bool.rs:8:13 | LL | let _ = true as u32; | ^^^^^^^^^^^ help: try: `u32::from(true)` error: casting `bool` to `u64` is more cleanly stated with `u64::from(_)` - --> $DIR/cast_lossless_bool.rs:11:13 + --> $DIR/cast_lossless_bool.rs:9:13 | LL | let _ = true as u64; | ^^^^^^^^^^^ help: try: `u64::from(true)` error: casting `bool` to `u128` is more cleanly stated with `u128::from(_)` - --> $DIR/cast_lossless_bool.rs:12:13 + --> $DIR/cast_lossless_bool.rs:10:13 | LL | let _ = true as u128; | ^^^^^^^^^^^^ help: try: `u128::from(true)` error: casting `bool` to `usize` is more cleanly stated with `usize::from(_)` - --> $DIR/cast_lossless_bool.rs:13:13 + --> $DIR/cast_lossless_bool.rs:11:13 | LL | let _ = true as usize; | ^^^^^^^^^^^^^ help: try: `usize::from(true)` error: casting `bool` to `i8` is more cleanly stated with `i8::from(_)` - --> $DIR/cast_lossless_bool.rs:15:13 + --> $DIR/cast_lossless_bool.rs:13:13 | LL | let _ = true as i8; | ^^^^^^^^^^ help: try: `i8::from(true)` error: casting `bool` to `i16` is more cleanly stated with `i16::from(_)` - --> $DIR/cast_lossless_bool.rs:16:13 + --> $DIR/cast_lossless_bool.rs:14:13 | LL | let _ = true as i16; | ^^^^^^^^^^^ help: try: `i16::from(true)` error: casting `bool` to `i32` is more cleanly stated with `i32::from(_)` - --> $DIR/cast_lossless_bool.rs:17:13 + --> $DIR/cast_lossless_bool.rs:15:13 | LL | let _ = true as i32; | ^^^^^^^^^^^ help: try: `i32::from(true)` error: casting `bool` to `i64` is more cleanly stated with `i64::from(_)` - --> $DIR/cast_lossless_bool.rs:18:13 + --> $DIR/cast_lossless_bool.rs:16:13 | LL | let _ = true as i64; | ^^^^^^^^^^^ help: try: `i64::from(true)` error: casting `bool` to `i128` is more cleanly stated with `i128::from(_)` - --> $DIR/cast_lossless_bool.rs:19:13 + --> $DIR/cast_lossless_bool.rs:17:13 | LL | let _ = true as i128; | ^^^^^^^^^^^^ help: try: `i128::from(true)` error: casting `bool` to `isize` is more cleanly stated with `isize::from(_)` - --> $DIR/cast_lossless_bool.rs:20:13 + --> $DIR/cast_lossless_bool.rs:18:13 | LL | let _ = true as isize; | ^^^^^^^^^^^^^ help: try: `isize::from(true)` error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)` - --> $DIR/cast_lossless_bool.rs:23:13 + --> $DIR/cast_lossless_bool.rs:21:13 | LL | let _ = (true | false) as u16; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::from(true | false)` error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)` - --> $DIR/cast_lossless_bool.rs:51:13 + --> $DIR/cast_lossless_bool.rs:49:13 | LL | let _ = true as u8; | ^^^^^^^^^^ help: try: `u8::from(true)` diff --git a/tests/ui/cast_lossless_float.fixed b/tests/ui/cast_lossless_float.fixed index e72a0096acce7..f4f2e4773a533 100644 --- a/tests/ui/cast_lossless_float.fixed +++ b/tests/ui/cast_lossless_float.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] diff --git a/tests/ui/cast_lossless_float.rs b/tests/ui/cast_lossless_float.rs index dbcbaa9b81500..fdd88ed36fc63 100644 --- a/tests/ui/cast_lossless_float.rs +++ b/tests/ui/cast_lossless_float.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] diff --git a/tests/ui/cast_lossless_float.stderr b/tests/ui/cast_lossless_float.stderr index 8326d40be7165..70dc4a1026481 100644 --- a/tests/ui/cast_lossless_float.stderr +++ b/tests/ui/cast_lossless_float.stderr @@ -1,5 +1,5 @@ error: casting `i8` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:9:13 + --> $DIR/cast_lossless_float.rs:7:13 | LL | let _ = x0 as f32; | ^^^^^^^^^ help: try: `f32::from(x0)` @@ -7,61 +7,61 @@ LL | let _ = x0 as f32; = note: `-D clippy::cast-lossless` implied by `-D warnings` error: casting `i8` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:10:13 + --> $DIR/cast_lossless_float.rs:8:13 | LL | let _ = x0 as f64; | ^^^^^^^^^ help: try: `f64::from(x0)` error: casting `u8` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:12:13 + --> $DIR/cast_lossless_float.rs:10:13 | LL | let _ = x1 as f32; | ^^^^^^^^^ help: try: `f32::from(x1)` error: casting `u8` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:13:13 + --> $DIR/cast_lossless_float.rs:11:13 | LL | let _ = x1 as f64; | ^^^^^^^^^ help: try: `f64::from(x1)` error: casting `i16` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:15:13 + --> $DIR/cast_lossless_float.rs:13:13 | LL | let _ = x2 as f32; | ^^^^^^^^^ help: try: `f32::from(x2)` error: casting `i16` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:16:13 + --> $DIR/cast_lossless_float.rs:14:13 | LL | let _ = x2 as f64; | ^^^^^^^^^ help: try: `f64::from(x2)` error: casting `u16` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:18:13 + --> $DIR/cast_lossless_float.rs:16:13 | LL | let _ = x3 as f32; | ^^^^^^^^^ help: try: `f32::from(x3)` error: casting `u16` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:19:13 + --> $DIR/cast_lossless_float.rs:17:13 | LL | let _ = x3 as f64; | ^^^^^^^^^ help: try: `f64::from(x3)` error: casting `i32` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:21:13 + --> $DIR/cast_lossless_float.rs:19:13 | LL | let _ = x4 as f64; | ^^^^^^^^^ help: try: `f64::from(x4)` error: casting `u32` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:23:13 + --> $DIR/cast_lossless_float.rs:21:13 | LL | let _ = x5 as f64; | ^^^^^^^^^ help: try: `f64::from(x5)` error: casting `f32` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:26:13 + --> $DIR/cast_lossless_float.rs:24:13 | LL | let _ = 1.0f32 as f64; | ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)` diff --git a/tests/ui/cast_lossless_integer.fixed b/tests/ui/cast_lossless_integer.fixed index 7dab02084fc9d..6547107f50060 100644 --- a/tests/ui/cast_lossless_integer.fixed +++ b/tests/ui/cast_lossless_integer.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] diff --git a/tests/ui/cast_lossless_integer.rs b/tests/ui/cast_lossless_integer.rs index c24f73960b03f..79af9a83ca286 100644 --- a/tests/ui/cast_lossless_integer.rs +++ b/tests/ui/cast_lossless_integer.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] diff --git a/tests/ui/cast_lossless_integer.stderr b/tests/ui/cast_lossless_integer.stderr index 721b94876cb2c..4891d934c5e17 100644 --- a/tests/ui/cast_lossless_integer.stderr +++ b/tests/ui/cast_lossless_integer.stderr @@ -1,5 +1,5 @@ error: casting `i8` to `i16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:8:13 + --> $DIR/cast_lossless_integer.rs:6:13 | LL | let _ = 1i8 as i16; | ^^^^^^^^^^ help: try: `i16::from(1i8)` @@ -7,109 +7,109 @@ LL | let _ = 1i8 as i16; = note: `-D clippy::cast-lossless` implied by `-D warnings` error: casting `i8` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:9:13 + --> $DIR/cast_lossless_integer.rs:7:13 | LL | let _ = 1i8 as i32; | ^^^^^^^^^^ help: try: `i32::from(1i8)` error: casting `i8` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:10:13 + --> $DIR/cast_lossless_integer.rs:8:13 | LL | let _ = 1i8 as i64; | ^^^^^^^^^^ help: try: `i64::from(1i8)` error: casting `u8` to `i16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:11:13 + --> $DIR/cast_lossless_integer.rs:9:13 | LL | let _ = 1u8 as i16; | ^^^^^^^^^^ help: try: `i16::from(1u8)` error: casting `u8` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:12:13 + --> $DIR/cast_lossless_integer.rs:10:13 | LL | let _ = 1u8 as i32; | ^^^^^^^^^^ help: try: `i32::from(1u8)` error: casting `u8` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:13:13 + --> $DIR/cast_lossless_integer.rs:11:13 | LL | let _ = 1u8 as i64; | ^^^^^^^^^^ help: try: `i64::from(1u8)` error: casting `u8` to `u16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:14:13 + --> $DIR/cast_lossless_integer.rs:12:13 | LL | let _ = 1u8 as u16; | ^^^^^^^^^^ help: try: `u16::from(1u8)` error: casting `u8` to `u32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:15:13 + --> $DIR/cast_lossless_integer.rs:13:13 | LL | let _ = 1u8 as u32; | ^^^^^^^^^^ help: try: `u32::from(1u8)` error: casting `u8` to `u64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:16:13 + --> $DIR/cast_lossless_integer.rs:14:13 | LL | let _ = 1u8 as u64; | ^^^^^^^^^^ help: try: `u64::from(1u8)` error: casting `i16` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:17:13 + --> $DIR/cast_lossless_integer.rs:15:13 | LL | let _ = 1i16 as i32; | ^^^^^^^^^^^ help: try: `i32::from(1i16)` error: casting `i16` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:18:13 + --> $DIR/cast_lossless_integer.rs:16:13 | LL | let _ = 1i16 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1i16)` error: casting `u16` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:19:13 + --> $DIR/cast_lossless_integer.rs:17:13 | LL | let _ = 1u16 as i32; | ^^^^^^^^^^^ help: try: `i32::from(1u16)` error: casting `u16` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:20:13 + --> $DIR/cast_lossless_integer.rs:18:13 | LL | let _ = 1u16 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1u16)` error: casting `u16` to `u32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:21:13 + --> $DIR/cast_lossless_integer.rs:19:13 | LL | let _ = 1u16 as u32; | ^^^^^^^^^^^ help: try: `u32::from(1u16)` error: casting `u16` to `u64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:22:13 + --> $DIR/cast_lossless_integer.rs:20:13 | LL | let _ = 1u16 as u64; | ^^^^^^^^^^^ help: try: `u64::from(1u16)` error: casting `i32` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:23:13 + --> $DIR/cast_lossless_integer.rs:21:13 | LL | let _ = 1i32 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1i32)` error: casting `u32` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:24:13 + --> $DIR/cast_lossless_integer.rs:22:13 | LL | let _ = 1u32 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1u32)` error: casting `u32` to `u64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:25:13 + --> $DIR/cast_lossless_integer.rs:23:13 | LL | let _ = 1u32 as u64; | ^^^^^^^^^^^ help: try: `u64::from(1u32)` error: casting `u8` to `u16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:28:13 + --> $DIR/cast_lossless_integer.rs:26:13 | LL | let _ = (1u8 + 1u8) as u16; | ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)` diff --git a/tests/ui/cast_raw_slice_pointer_cast.fixed b/tests/ui/cast_raw_slice_pointer_cast.fixed index 9b6fee270ee9b..e78bd66c3cb55 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.fixed +++ b/tests/ui/cast_raw_slice_pointer_cast.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::cast_slice_from_raw_parts)] #[allow(unused_imports, unused_unsafe)] diff --git a/tests/ui/cast_raw_slice_pointer_cast.rs b/tests/ui/cast_raw_slice_pointer_cast.rs index c0bb81379905c..c3d8c7bee9893 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.rs +++ b/tests/ui/cast_raw_slice_pointer_cast.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::cast_slice_from_raw_parts)] #[allow(unused_imports, unused_unsafe)] diff --git a/tests/ui/cast_raw_slice_pointer_cast.stderr b/tests/ui/cast_raw_slice_pointer_cast.stderr index f07801c197ccc..8316411202670 100644 --- a/tests/ui/cast_raw_slice_pointer_cast.stderr +++ b/tests/ui/cast_raw_slice_pointer_cast.stderr @@ -1,5 +1,5 @@ error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:9:35 + --> $DIR/cast_raw_slice_pointer_cast.rs:8:35 | LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) as *const [u8] }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` @@ -7,37 +7,37 @@ LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) as *co = note: `-D clippy::cast-slice-from-raw-parts` implied by `-D warnings` error: casting the result of `from_raw_parts_mut` to *mut [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:10:35 + --> $DIR/cast_raw_slice_pointer_cast.rs:9:35 | LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts_mut(mptr, 1) as *mut [u8] }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts_mut(mptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:11:26 + --> $DIR/cast_raw_slice_pointer_cast.rs:10:26 | LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:14:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:13:30 | LL | let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:16:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:15:30 | LL | let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:20:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:19:30 | LL | let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:22:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:21:30 | LL | let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)` diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index cd2184aea382a..4d4341ab55cf3 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -33,3 +33,4 @@ fn main() { 999_999_999 as f32; 9_999_999_999_999_999usize as f64; } +//@no-rustfix diff --git a/tests/ui/cast_slice_different_sizes.rs b/tests/ui/cast_slice_different_sizes.rs index 27e03ebb7197d..6d2f99b7db5d2 100644 --- a/tests/ui/cast_slice_different_sizes.rs +++ b/tests/ui/cast_slice_different_sizes.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(clippy::let_unit_value, clippy::unnecessary_cast)] fn main() { diff --git a/tests/ui/cast_slice_different_sizes.stderr b/tests/ui/cast_slice_different_sizes.stderr index 40721dcd05d5d..cd2cdfff32582 100644 --- a/tests/ui/cast_slice_different_sizes.stderr +++ b/tests/ui/cast_slice_different_sizes.stderr @@ -1,5 +1,5 @@ error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:9:13 + --> $DIR/cast_slice_different_sizes.rs:10:13 | LL | let b = a as *const [u8]; | ^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(a as *const u8, ..)` @@ -7,25 +7,25 @@ LL | let b = a as *const [u8]; = note: `#[deny(clippy::cast_slice_different_sizes)]` on by default error: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (element size 4) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:10:13 + --> $DIR/cast_slice_different_sizes.rs:11:13 | LL | let c = b as *const [u32]; | ^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(b as *const u32, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:13:16 + --> $DIR/cast_slice_different_sizes.rs:14:16 | LL | let loss = r_x as *const [i32] as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:20:24 + --> $DIR/cast_slice_different_sizes.rs:21:24 | LL | let loss_block_1 = { r_x as *const [i32] } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts({ r_x as *const [i32] } as *const u8, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:21:24 + --> $DIR/cast_slice_different_sizes.rs:22:24 | LL | let loss_block_2 = { | ________________________^ @@ -43,13 +43,13 @@ LL ~ } as *const u8, ..); | error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:38:27 + --> $DIR/cast_slice_different_sizes.rs:39:27 | LL | let long_chain_loss = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:53:36 + --> $DIR/cast_slice_different_sizes.rs:54:36 | LL | fn bar(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ @@ -58,7 +58,7 @@ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:57:36 + --> $DIR/cast_slice_different_sizes.rs:58:36 | LL | fn uwu(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ @@ -67,7 +67,7 @@ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:61:37 + --> $DIR/cast_slice_different_sizes.rs:62:37 | LL | fn bar2(x: *mut [u16]) -> *mut [u8] { | _____________________________________^ @@ -76,7 +76,7 @@ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:66:39 + --> $DIR/cast_slice_different_sizes.rs:67:39 | LL | fn bar3(x: *mut [u16]) -> *const [u8] { | _______________________________________^ @@ -85,7 +85,7 @@ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(x as *const u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:71:39 + --> $DIR/cast_slice_different_sizes.rs:72:39 | LL | fn bar4(x: *const [u16]) -> *mut [u8] { | _______________________________________^ @@ -94,7 +94,7 @@ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:76:39 + --> $DIR/cast_slice_different_sizes.rs:77:39 | LL | fn blocks(x: *mut [u16]) -> *mut [u8] { | _______________________________________^ @@ -103,7 +103,7 @@ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:80:44 + --> $DIR/cast_slice_different_sizes.rs:81:44 | LL | fn more_blocks(x: *mut [u16]) -> *mut [u8] { | ____________________________________________^ @@ -112,7 +112,7 @@ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:81:5 + --> $DIR/cast_slice_different_sizes.rs:82:5 | LL | { ({ x }) as _ } | ^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` diff --git a/tests/ui/cfg_attr_rustfmt.fixed b/tests/ui/cfg_attr_rustfmt.fixed index 13aadb7d3308f..05d5b3d10eaf8 100644 --- a/tests/ui/cfg_attr_rustfmt.fixed +++ b/tests/ui/cfg_attr_rustfmt.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + #![feature(stmt_expr_attributes)] #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] diff --git a/tests/ui/cfg_attr_rustfmt.rs b/tests/ui/cfg_attr_rustfmt.rs index 769c5d22b9da0..bc29e20210e8a 100644 --- a/tests/ui/cfg_attr_rustfmt.rs +++ b/tests/ui/cfg_attr_rustfmt.rs @@ -1,4 +1,4 @@ -//@run-rustfix + #![feature(stmt_expr_attributes)] #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] diff --git a/tests/ui/cfg_features.fixed b/tests/ui/cfg_features.fixed new file mode 100644 index 0000000000000..c3e570698d7dc --- /dev/null +++ b/tests/ui/cfg_features.fixed @@ -0,0 +1,12 @@ +#![warn(clippy::maybe_misused_cfg)] + +fn main() { + #[cfg(feature = "not-really-a-feature")] + let _ = 1 + 2; + + #[cfg(all(feature = "right", feature = "wrong"))] + let _ = 1 + 2; + + #[cfg(all(feature = "wrong1", any(feature = "right", feature = "wrong2", feature, features)))] + let _ = 1 + 2; +} diff --git a/tests/ui/char_lit_as_u8_suggestions.fixed b/tests/ui/char_lit_as_u8_suggestions.fixed index ce2f149dc05e4..6f13078a3ae95 100644 --- a/tests/ui/char_lit_as_u8_suggestions.fixed +++ b/tests/ui/char_lit_as_u8_suggestions.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::char_lit_as_u8)] fn main() { diff --git a/tests/ui/char_lit_as_u8_suggestions.rs b/tests/ui/char_lit_as_u8_suggestions.rs index ffad12fc6f950..7737eb5135fbb 100644 --- a/tests/ui/char_lit_as_u8_suggestions.rs +++ b/tests/ui/char_lit_as_u8_suggestions.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::char_lit_as_u8)] fn main() { diff --git a/tests/ui/char_lit_as_u8_suggestions.stderr b/tests/ui/char_lit_as_u8_suggestions.stderr index 586174c508820..f7e7b878bb153 100644 --- a/tests/ui/char_lit_as_u8_suggestions.stderr +++ b/tests/ui/char_lit_as_u8_suggestions.stderr @@ -1,5 +1,5 @@ error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8_suggestions.rs:6:13 + --> $DIR/char_lit_as_u8_suggestions.rs:4:13 | LL | let _ = 'a' as u8; | ^^^^^^^^^ help: use a byte literal instead: `b'a'` @@ -8,7 +8,7 @@ LL | let _ = 'a' as u8; = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8_suggestions.rs:7:13 + --> $DIR/char_lit_as_u8_suggestions.rs:5:13 | LL | let _ = '/n' as u8; | ^^^^^^^^^^ help: use a byte literal instead: `b'/n'` @@ -16,7 +16,7 @@ LL | let _ = '/n' as u8; = note: `char` is four bytes wide, but `u8` is a single byte error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8_suggestions.rs:8:13 + --> $DIR/char_lit_as_u8_suggestions.rs:6:13 | LL | let _ = '/0' as u8; | ^^^^^^^^^^ help: use a byte literal instead: `b'/0'` @@ -24,7 +24,7 @@ LL | let _ = '/0' as u8; = note: `char` is four bytes wide, but `u8` is a single byte error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8_suggestions.rs:9:13 + --> $DIR/char_lit_as_u8_suggestions.rs:7:13 | LL | let _ = '/x01' as u8; | ^^^^^^^^^^^^ help: use a byte literal instead: `b'/x01'` diff --git a/tests/ui/checked_conversions.fixed b/tests/ui/checked_conversions.fixed index 188e6d975952e..0e05a27429b0c 100644 --- a/tests/ui/checked_conversions.fixed +++ b/tests/ui/checked_conversions.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( clippy::cast_lossless, unused, diff --git a/tests/ui/checked_conversions.rs b/tests/ui/checked_conversions.rs index 70f0f0975acd9..ac78269926535 100644 --- a/tests/ui/checked_conversions.rs +++ b/tests/ui/checked_conversions.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( clippy::cast_lossless, unused, diff --git a/tests/ui/checked_conversions.stderr b/tests/ui/checked_conversions.stderr index 273ead73bda58..08457973a2188 100644 --- a/tests/ui/checked_conversions.stderr +++ b/tests/ui/checked_conversions.stderr @@ -1,5 +1,5 @@ error: checked cast can be simplified - --> $DIR/checked_conversions.rs:16:13 + --> $DIR/checked_conversions.rs:14:13 | LL | let _ = value <= (u32::max_value() as i64) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` @@ -7,97 +7,97 @@ LL | let _ = value <= (u32::max_value() as i64) && value >= 0; = note: `-D clippy::checked-conversions` implied by `-D warnings` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:17:13 + --> $DIR/checked_conversions.rs:15:13 | LL | let _ = value <= (u32::MAX as i64) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:21:13 + --> $DIR/checked_conversions.rs:19:13 | LL | let _ = value <= i64::from(u16::max_value()) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:22:13 + --> $DIR/checked_conversions.rs:20:13 | LL | let _ = value <= i64::from(u16::MAX) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:26:13 + --> $DIR/checked_conversions.rs:24:13 | LL | let _ = value <= (u8::max_value() as isize) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:27:13 + --> $DIR/checked_conversions.rs:25:13 | LL | let _ = value <= (u8::MAX as isize) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:33:13 + --> $DIR/checked_conversions.rs:31:13 | LL | let _ = value <= (i32::max_value() as i64) && value >= (i32::min_value() as i64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:34:13 + --> $DIR/checked_conversions.rs:32:13 | LL | let _ = value <= (i32::MAX as i64) && value >= (i32::MIN as i64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:38:13 + --> $DIR/checked_conversions.rs:36:13 | LL | let _ = value <= i64::from(i16::max_value()) && value >= i64::from(i16::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:39:13 + --> $DIR/checked_conversions.rs:37:13 | LL | let _ = value <= i64::from(i16::MAX) && value >= i64::from(i16::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:45:13 + --> $DIR/checked_conversions.rs:43:13 | LL | let _ = value <= i32::max_value() as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:46:13 + --> $DIR/checked_conversions.rs:44:13 | LL | let _ = value <= i32::MAX as u32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:50:13 + --> $DIR/checked_conversions.rs:48:13 | LL | let _ = value <= isize::max_value() as usize && value as i32 == 5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:51:13 + --> $DIR/checked_conversions.rs:49:13 | LL | let _ = value <= isize::MAX as usize && value as i32 == 5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:55:13 + --> $DIR/checked_conversions.rs:53:13 | LL | let _ = value <= u16::max_value() as u32 && value as i32 == 5; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:56:13 + --> $DIR/checked_conversions.rs:54:13 | LL | let _ = value <= u16::MAX as u32 && value as i32 == 5; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:89:13 + --> $DIR/checked_conversions.rs:87:13 | LL | let _ = value <= (u32::MAX as i64) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.rs b/tests/ui/checked_unwrap/complex_conditionals_nested.rs index e417cf833cbb9..e390cfab58d94 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.rs +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.rs @@ -4,7 +4,7 @@ clippy::branches_sharing_code, clippy::unnecessary_literal_unwrap )] - +//@no-rustfix fn test_nested() { fn nested() { let x = Some(()); diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 61042bb90d27a..15a246fce6403 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![feature(lint_reasons)] #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] #![allow( diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index 93809f6551add..dae7c88126268 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -1,5 +1,5 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:44:9 + --> $DIR/simple_conditionals.rs:45:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` @@ -7,13 +7,13 @@ LL | x.unwrap(); // unnecessary | ^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/simple_conditionals.rs:2:35 + --> $DIR/simple_conditionals.rs:3:35 | LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:45:9 + --> $DIR/simple_conditionals.rs:46:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` @@ -22,7 +22,7 @@ LL | x.expect("an error message"); // unnecessary | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:47:9 + --> $DIR/simple_conditionals.rs:48:9 | LL | if x.is_some() { | ----------- because of this check @@ -31,13 +31,13 @@ LL | x.unwrap(); // will panic | ^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/simple_conditionals.rs:2:9 + --> $DIR/simple_conditionals.rs:3:9 | LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:48:9 + --> $DIR/simple_conditionals.rs:49:9 | LL | if x.is_some() { | ----------- because of this check @@ -46,7 +46,7 @@ LL | x.expect("an error message"); // will panic | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:51:9 + --> $DIR/simple_conditionals.rs:52:9 | LL | if x.is_none() { | ----------- because of this check @@ -54,7 +54,7 @@ LL | x.unwrap(); // will panic | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_none` - --> $DIR/simple_conditionals.rs:53:9 + --> $DIR/simple_conditionals.rs:54:9 | LL | if x.is_none() { | -------------- help: try: `if let Some(..) = x` @@ -63,7 +63,7 @@ LL | x.unwrap(); // unnecessary | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:12:13 + --> $DIR/simple_conditionals.rs:13:13 | LL | if $a.is_some() { | --------------- help: try: `if let Some(..) = x` @@ -76,7 +76,7 @@ LL | m!(x); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:61:9 + --> $DIR/simple_conditionals.rs:62:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` @@ -84,7 +84,7 @@ LL | x.unwrap(); // unnecessary | ^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:62:9 + --> $DIR/simple_conditionals.rs:63:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` @@ -93,7 +93,7 @@ LL | x.expect("an error message"); // unnecessary | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:63:9 + --> $DIR/simple_conditionals.rs:64:9 | LL | if x.is_ok() { | --------- because of this check @@ -102,7 +102,7 @@ LL | x.unwrap_err(); // will panic | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:65:9 + --> $DIR/simple_conditionals.rs:66:9 | LL | if x.is_ok() { | --------- because of this check @@ -111,7 +111,7 @@ LL | x.unwrap(); // will panic | ^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:66:9 + --> $DIR/simple_conditionals.rs:67:9 | LL | if x.is_ok() { | --------- because of this check @@ -120,7 +120,7 @@ LL | x.expect("an error message"); // will panic | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:67:9 + --> $DIR/simple_conditionals.rs:68:9 | LL | if x.is_ok() { | ------------ help: try: `if let Err(..) = x` @@ -129,7 +129,7 @@ LL | x.unwrap_err(); // unnecessary | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:70:9 + --> $DIR/simple_conditionals.rs:71:9 | LL | if x.is_err() { | ---------- because of this check @@ -137,7 +137,7 @@ LL | x.unwrap(); // will panic | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:71:9 + --> $DIR/simple_conditionals.rs:72:9 | LL | if x.is_err() { | ------------- help: try: `if let Err(..) = x` @@ -146,7 +146,7 @@ LL | x.unwrap_err(); // unnecessary | ^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:73:9 + --> $DIR/simple_conditionals.rs:74:9 | LL | if x.is_err() { | ------------- help: try: `if let Ok(..) = x` @@ -155,7 +155,7 @@ LL | x.unwrap(); // unnecessary | ^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:74:9 + --> $DIR/simple_conditionals.rs:75:9 | LL | if x.is_err() { | ---------- because of this check diff --git a/tests/ui/clear_with_drain.fixed b/tests/ui/clear_with_drain.fixed index b68c7d867ec65..15777a4ea5b31 100644 --- a/tests/ui/clear_with_drain.fixed +++ b/tests/ui/clear_with_drain.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::clear_with_drain)] diff --git a/tests/ui/clear_with_drain.rs b/tests/ui/clear_with_drain.rs index 0f6562ecad5a2..1dea7235ef669 100644 --- a/tests/ui/clear_with_drain.rs +++ b/tests/ui/clear_with_drain.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::clear_with_drain)] diff --git a/tests/ui/clear_with_drain.stderr b/tests/ui/clear_with_drain.stderr index 20158da1121b7..db545c5fba4e9 100644 --- a/tests/ui/clear_with_drain.stderr +++ b/tests/ui/clear_with_drain.stderr @@ -1,5 +1,5 @@ error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:23:7 + --> $DIR/clear_with_drain.rs:22:7 | LL | v.drain(0..v.len()); | ^^^^^^^^^^^^^^^^^ help: try: `clear()` @@ -7,121 +7,121 @@ LL | v.drain(0..v.len()); = note: `-D clippy::clear-with-drain` implied by `-D warnings` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:27:7 + --> $DIR/clear_with_drain.rs:26:7 | LL | v.drain(usize::MIN..v.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:46:7 + --> $DIR/clear_with_drain.rs:45:7 | LL | v.drain(0..); | ^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:50:7 + --> $DIR/clear_with_drain.rs:49:7 | LL | v.drain(usize::MIN..); | ^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:66:7 + --> $DIR/clear_with_drain.rs:65:7 | LL | v.drain(..); | ^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:83:7 + --> $DIR/clear_with_drain.rs:82:7 | LL | v.drain(..v.len()); | ^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:121:11 + --> $DIR/clear_with_drain.rs:120:11 | LL | deque.drain(0..deque.len()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:125:11 + --> $DIR/clear_with_drain.rs:124:11 | LL | deque.drain(usize::MIN..deque.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:144:11 + --> $DIR/clear_with_drain.rs:143:11 | LL | deque.drain(0..); | ^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:148:11 + --> $DIR/clear_with_drain.rs:147:11 | LL | deque.drain(usize::MIN..); | ^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:164:11 + --> $DIR/clear_with_drain.rs:163:11 | LL | deque.drain(..); | ^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:181:11 + --> $DIR/clear_with_drain.rs:180:11 | LL | deque.drain(..deque.len()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:219:7 + --> $DIR/clear_with_drain.rs:218:7 | LL | s.drain(0..s.len()); | ^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:223:7 + --> $DIR/clear_with_drain.rs:222:7 | LL | s.drain(usize::MIN..s.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:242:7 + --> $DIR/clear_with_drain.rs:241:7 | LL | s.drain(0..); | ^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:246:7 + --> $DIR/clear_with_drain.rs:245:7 | LL | s.drain(usize::MIN..); | ^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:262:7 + --> $DIR/clear_with_drain.rs:261:7 | LL | s.drain(..); | ^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:279:7 + --> $DIR/clear_with_drain.rs:278:7 | LL | s.drain(..s.len()); | ^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `HashSet` - --> $DIR/clear_with_drain.rs:317:9 + --> $DIR/clear_with_drain.rs:316:9 | LL | set.drain(); | ^^^^^^^ help: try: `clear()` error: `drain` used to clear a `HashMap` - --> $DIR/clear_with_drain.rs:336:9 + --> $DIR/clear_with_drain.rs:335:9 | LL | map.drain(); | ^^^^^^^ help: try: `clear()` error: `drain` used to clear a `BinaryHeap` - --> $DIR/clear_with_drain.rs:355:10 + --> $DIR/clear_with_drain.rs:354:10 | LL | heap.drain(); | ^^^^^^^ help: try: `clear()` diff --git a/tests/ui/clone_on_copy.fixed b/tests/ui/clone_on_copy.fixed index a720711585bbb..9d9a5bf20f438 100644 --- a/tests/ui/clone_on_copy.fixed +++ b/tests/ui/clone_on_copy.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( unused, clippy::redundant_clone, diff --git a/tests/ui/clone_on_copy.rs b/tests/ui/clone_on_copy.rs index 2c5fac8faf56b..305bc6816e1b6 100644 --- a/tests/ui/clone_on_copy.rs +++ b/tests/ui/clone_on_copy.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( unused, clippy::redundant_clone, diff --git a/tests/ui/clone_on_copy.stderr b/tests/ui/clone_on_copy.stderr index 862234d204be3..053dee954481e 100644 --- a/tests/ui/clone_on_copy.stderr +++ b/tests/ui/clone_on_copy.stderr @@ -1,5 +1,5 @@ error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:25:5 + --> $DIR/clone_on_copy.rs:23:5 | LL | 42.clone(); | ^^^^^^^^^^ help: try removing the `clone` call: `42` @@ -7,49 +7,49 @@ LL | 42.clone(); = note: `-D clippy::clone-on-copy` implied by `-D warnings` error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:29:5 + --> $DIR/clone_on_copy.rs:27:5 | LL | (&42).clone(); | ^^^^^^^^^^^^^ help: try dereferencing it: `*(&42)` error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:32:5 + --> $DIR/clone_on_copy.rs:30:5 | LL | rc.borrow().clone(); | ^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*rc.borrow()` error: using `clone` on type `u32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:35:5 + --> $DIR/clone_on_copy.rs:33:5 | LL | x.clone().rotate_left(1); | ^^^^^^^^^ help: try removing the `clone` call: `x` error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:49:5 + --> $DIR/clone_on_copy.rs:47:5 | LL | m!(42).clone(); | ^^^^^^^^^^^^^^ help: try removing the `clone` call: `m!(42)` error: using `clone` on type `[u32; 2]` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:59:5 + --> $DIR/clone_on_copy.rs:57:5 | LL | x.clone()[0]; | ^^^^^^^^^ help: try dereferencing it: `(*x)` error: using `clone` on type `char` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:69:14 + --> $DIR/clone_on_copy.rs:67:14 | LL | is_ascii('z'.clone()); | ^^^^^^^^^^^ help: try removing the `clone` call: `'z'` error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:73:14 + --> $DIR/clone_on_copy.rs:71:14 | LL | vec.push(42.clone()); | ^^^^^^^^^^ help: try removing the `clone` call: `42` error: using `clone` on type `Option` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:77:17 + --> $DIR/clone_on_copy.rs:75:17 | LL | let value = opt.clone()?; // operator precedence needed (*opt)? | ^^^^^^^^^^^ help: try dereferencing it: `(*opt)` diff --git a/tests/ui/cloned_instead_of_copied.fixed b/tests/ui/cloned_instead_of_copied.fixed index 34bd2233440bf..bc939bb3dbb9c 100644 --- a/tests/ui/cloned_instead_of_copied.fixed +++ b/tests/ui/cloned_instead_of_copied.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::cloned_instead_of_copied)] #![allow(unused)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/cloned_instead_of_copied.rs b/tests/ui/cloned_instead_of_copied.rs index fa8444937b6b1..27346adbfbf1b 100644 --- a/tests/ui/cloned_instead_of_copied.rs +++ b/tests/ui/cloned_instead_of_copied.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::cloned_instead_of_copied)] #![allow(unused)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/cloned_instead_of_copied.stderr b/tests/ui/cloned_instead_of_copied.stderr index 3ce482006e949..247d15a015ab9 100644 --- a/tests/ui/cloned_instead_of_copied.stderr +++ b/tests/ui/cloned_instead_of_copied.stderr @@ -1,5 +1,5 @@ error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:9:24 + --> $DIR/cloned_instead_of_copied.rs:7:24 | LL | let _ = [1].iter().cloned(); | ^^^^^^ help: try: `copied` @@ -7,43 +7,43 @@ LL | let _ = [1].iter().cloned(); = note: `-D clippy::cloned-instead-of-copied` implied by `-D warnings` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:10:31 + --> $DIR/cloned_instead_of_copied.rs:8:31 | LL | let _ = vec!["hi"].iter().cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:11:22 + --> $DIR/cloned_instead_of_copied.rs:9:22 | LL | let _ = Some(&1).cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:12:34 + --> $DIR/cloned_instead_of_copied.rs:10:34 | LL | let _ = Box::new([1].iter()).cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:13:32 + --> $DIR/cloned_instead_of_copied.rs:11:32 | LL | let _ = Box::new(Some(&1)).cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:29:22 + --> $DIR/cloned_instead_of_copied.rs:27:22 | LL | let _ = Some(&1).cloned(); // Option::copied needs 1.35 | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:34:24 + --> $DIR/cloned_instead_of_copied.rs:32:24 | LL | let _ = [1].iter().cloned(); // Iterator::copied needs 1.36 | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:35:22 + --> $DIR/cloned_instead_of_copied.rs:33:22 | LL | let _ = Some(&1).cloned(); | ^^^^^^ help: try: `copied` diff --git a/tests/ui/cmp_owned/asymmetric_partial_eq.fixed b/tests/ui/cmp_owned/asymmetric_partial_eq.fixed index 118346348564b..9fc70ab6f4a0a 100644 --- a/tests/ui/cmp_owned/asymmetric_partial_eq.fixed +++ b/tests/ui/cmp_owned/asymmetric_partial_eq.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::needless_if, diff --git a/tests/ui/cmp_owned/asymmetric_partial_eq.rs b/tests/ui/cmp_owned/asymmetric_partial_eq.rs index 3a25d53a5d080..5cd43ea1d4114 100644 --- a/tests/ui/cmp_owned/asymmetric_partial_eq.rs +++ b/tests/ui/cmp_owned/asymmetric_partial_eq.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::needless_if, diff --git a/tests/ui/cmp_owned/asymmetric_partial_eq.stderr b/tests/ui/cmp_owned/asymmetric_partial_eq.stderr index 4714a0daaa68a..95c829e795e6e 100644 --- a/tests/ui/cmp_owned/asymmetric_partial_eq.stderr +++ b/tests/ui/cmp_owned/asymmetric_partial_eq.stderr @@ -1,5 +1,5 @@ error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:47:12 + --> $DIR/asymmetric_partial_eq.rs:46:12 | LL | if borrowed.to_owned() == owned {} | ^^^^^^^^^^^^^^^^^^^ help: try: `borrowed` @@ -7,7 +7,7 @@ LL | if borrowed.to_owned() == owned {} = note: `-D clippy::cmp-owned` implied by `-D warnings` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:48:21 + --> $DIR/asymmetric_partial_eq.rs:47:21 | LL | if owned == borrowed.to_owned() {} | ---------^^^^^^^^^^^^^^^^^^^ @@ -15,13 +15,13 @@ LL | if owned == borrowed.to_owned() {} | help: try: `borrowed == owned` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:66:21 + --> $DIR/asymmetric_partial_eq.rs:65:21 | LL | if owned == borrowed.to_owned() {} | ^^^^^^^^^^^^^^^^^^^ help: try: `borrowed` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:67:12 + --> $DIR/asymmetric_partial_eq.rs:66:12 | LL | if borrowed.to_owned() == owned {} | ^^^^^^^^^^^^^^^^^^^--------- @@ -29,7 +29,7 @@ LL | if borrowed.to_owned() == owned {} | help: try: `owned == borrowed` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:93:20 + --> $DIR/asymmetric_partial_eq.rs:92:20 | LL | if "Hi" == borrowed.to_string() {} | --------^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | if "Hi" == borrowed.to_string() {} | help: try: `borrowed == "Hi"` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:94:12 + --> $DIR/asymmetric_partial_eq.rs:93:12 | LL | if borrowed.to_string() == "Hi" {} | ^^^^^^^^^^^^^^^^^^^^ help: try: `borrowed` diff --git a/tests/ui/cmp_owned/comparison_flip.fixed b/tests/ui/cmp_owned/comparison_flip.fixed index b1133f2a59f74..40d7b5e49fcdf 100644 --- a/tests/ui/cmp_owned/comparison_flip.fixed +++ b/tests/ui/cmp_owned/comparison_flip.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - use std::fmt::{self, Display}; fn main() { diff --git a/tests/ui/cmp_owned/comparison_flip.rs b/tests/ui/cmp_owned/comparison_flip.rs index 091a9aa65c0ac..59a945668b2e0 100644 --- a/tests/ui/cmp_owned/comparison_flip.rs +++ b/tests/ui/cmp_owned/comparison_flip.rs @@ -1,5 +1,3 @@ -//@run-rustfix - use std::fmt::{self, Display}; fn main() { diff --git a/tests/ui/cmp_owned/comparison_flip.stderr b/tests/ui/cmp_owned/comparison_flip.stderr index e4d0d822bb1e3..76983578f4169 100644 --- a/tests/ui/cmp_owned/comparison_flip.stderr +++ b/tests/ui/cmp_owned/comparison_flip.stderr @@ -1,5 +1,5 @@ error: this creates an owned instance just for comparison - --> $DIR/comparison_flip.rs:8:8 + --> $DIR/comparison_flip.rs:6:8 | LL | if a.to_string() != "bar" { | ^^^^^^^^^^^^^ help: try: `a` @@ -7,7 +7,7 @@ LL | if a.to_string() != "bar" { = note: `-D clippy::cmp-owned` implied by `-D warnings` error: this creates an owned instance just for comparison - --> $DIR/comparison_flip.rs:12:17 + --> $DIR/comparison_flip.rs:10:17 | LL | if "bar" != a.to_string() { | ---------^^^^^^^^^^^^^ diff --git a/tests/ui/cmp_owned/with_suggestion.fixed b/tests/ui/cmp_owned/with_suggestion.fixed index bf1a58588a856..8846092fef40f 100644 --- a/tests/ui/cmp_owned/with_suggestion.fixed +++ b/tests/ui/cmp_owned/with_suggestion.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[warn(clippy::cmp_owned)] #[allow(clippy::unnecessary_operation, clippy::no_effect, unused_must_use, clippy::eq_op)] fn main() { diff --git a/tests/ui/cmp_owned/with_suggestion.rs b/tests/ui/cmp_owned/with_suggestion.rs index f3f663670eb18..cb5268734d32c 100644 --- a/tests/ui/cmp_owned/with_suggestion.rs +++ b/tests/ui/cmp_owned/with_suggestion.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[warn(clippy::cmp_owned)] #[allow(clippy::unnecessary_operation, clippy::no_effect, unused_must_use, clippy::eq_op)] fn main() { diff --git a/tests/ui/cmp_owned/with_suggestion.stderr b/tests/ui/cmp_owned/with_suggestion.stderr index 2f333e6ea8ecb..88e6da2f06710 100644 --- a/tests/ui/cmp_owned/with_suggestion.stderr +++ b/tests/ui/cmp_owned/with_suggestion.stderr @@ -1,5 +1,5 @@ error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:7:14 + --> $DIR/with_suggestion.rs:5:14 | LL | x != "foo".to_string(); | ^^^^^^^^^^^^^^^^^ help: try: `"foo"` @@ -7,31 +7,31 @@ LL | x != "foo".to_string(); = note: `-D clippy::cmp-owned` implied by `-D warnings` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:9:9 + --> $DIR/with_suggestion.rs:7:9 | LL | "foo".to_string() != x; | ^^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:16:10 + --> $DIR/with_suggestion.rs:14:10 | LL | x != "foo".to_owned(); | ^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:18:10 + --> $DIR/with_suggestion.rs:16:10 | LL | x != String::from("foo"); | ^^^^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:22:5 + --> $DIR/with_suggestion.rs:20:5 | LL | Foo.to_owned() == Foo; | ^^^^^^^^^^^^^^ help: try: `Foo` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:24:30 + --> $DIR/with_suggestion.rs:22:30 | LL | "abc".chars().filter(|c| c.to_owned() != 'X'); | ^^^^^^^^^^^^ help: try: `*c` diff --git a/tests/ui/collapsible_else_if.fixed b/tests/ui/collapsible_else_if.fixed index c4116cd8520c0..3b410b2f17b80 100644 --- a/tests/ui/collapsible_else_if.fixed +++ b/tests/ui/collapsible_else_if.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::assertions_on_constants, clippy::equatable_if_let, clippy::needless_if)] #[rustfmt::skip] diff --git a/tests/ui/collapsible_else_if.rs b/tests/ui/collapsible_else_if.rs index 8f51d0ee508ff..772ef6f9fc606 100644 --- a/tests/ui/collapsible_else_if.rs +++ b/tests/ui/collapsible_else_if.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::assertions_on_constants, clippy::equatable_if_let, clippy::needless_if)] #[rustfmt::skip] diff --git a/tests/ui/collapsible_else_if.stderr b/tests/ui/collapsible_else_if.stderr index 45b2094c9948b..b644205d9830e 100644 --- a/tests/ui/collapsible_else_if.stderr +++ b/tests/ui/collapsible_else_if.stderr @@ -1,5 +1,5 @@ error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:14:12 + --> $DIR/collapsible_else_if.rs:13:12 | LL | } else { | ____________^ @@ -18,7 +18,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:22:12 + --> $DIR/collapsible_else_if.rs:21:12 | LL | } else { | ____________^ @@ -36,7 +36,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:30:12 + --> $DIR/collapsible_else_if.rs:29:12 | LL | } else { | ____________^ @@ -59,7 +59,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:41:12 + --> $DIR/collapsible_else_if.rs:40:12 | LL | } else { | ____________^ @@ -82,7 +82,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:52:12 + --> $DIR/collapsible_else_if.rs:51:12 | LL | } else { | ____________^ @@ -105,7 +105,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:63:12 + --> $DIR/collapsible_else_if.rs:62:12 | LL | } else { | ____________^ @@ -128,7 +128,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:74:12 + --> $DIR/collapsible_else_if.rs:73:12 | LL | } else { | ____________^ @@ -151,7 +151,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:97:10 + --> $DIR/collapsible_else_if.rs:96:10 | LL | }else{ | __________^ diff --git a/tests/ui/collapsible_if.fixed b/tests/ui/collapsible_if.fixed index e305e1d7a8710..fff6bfcc753a9 100644 --- a/tests/ui/collapsible_if.fixed +++ b/tests/ui/collapsible_if.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( clippy::assertions_on_constants, clippy::equatable_if_let, diff --git a/tests/ui/collapsible_if.rs b/tests/ui/collapsible_if.rs index 7c52959d3b51b..70bfea231ae43 100644 --- a/tests/ui/collapsible_if.rs +++ b/tests/ui/collapsible_if.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( clippy::assertions_on_constants, clippy::equatable_if_let, diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr index 4a1a9e8a60aee..c687bae1acc52 100644 --- a/tests/ui/collapsible_if.stderr +++ b/tests/ui/collapsible_if.stderr @@ -1,5 +1,5 @@ error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:15:5 + --> $DIR/collapsible_if.rs:14:5 | LL | / if x == "hello" { LL | | if y == "world" { @@ -17,7 +17,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:21:5 + --> $DIR/collapsible_if.rs:20:5 | LL | / if x == "hello" || x == "world" { LL | | if y == "world" || y == "hello" { @@ -34,7 +34,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:27:5 + --> $DIR/collapsible_if.rs:26:5 | LL | / if x == "hello" && x == "world" { LL | | if y == "world" || y == "hello" { @@ -51,7 +51,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:33:5 + --> $DIR/collapsible_if.rs:32:5 | LL | / if x == "hello" || x == "world" { LL | | if y == "world" && y == "hello" { @@ -68,7 +68,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:39:5 + --> $DIR/collapsible_if.rs:38:5 | LL | / if x == "hello" && x == "world" { LL | | if y == "world" && y == "hello" { @@ -85,7 +85,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:45:5 + --> $DIR/collapsible_if.rs:44:5 | LL | / if 42 == 1337 { LL | | if 'a' != 'A' { @@ -102,7 +102,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:101:5 + --> $DIR/collapsible_if.rs:100:5 | LL | / if x == "hello" { LL | | if y == "world" { // Collapsible @@ -119,7 +119,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:160:5 + --> $DIR/collapsible_if.rs:159:5 | LL | / if matches!(true, true) { LL | | if matches!(true, true) {} @@ -127,7 +127,7 @@ LL | | } | |_____^ help: collapse nested if block: `if matches!(true, true) && matches!(true, true) {}` error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:165:5 + --> $DIR/collapsible_if.rs:164:5 | LL | / if matches!(true, true) && truth() { LL | | if matches!(true, true) {} diff --git a/tests/ui/collapsible_str_replace.fixed b/tests/ui/collapsible_str_replace.fixed index ba6c1769a9a38..03b393d5a6749 100644 --- a/tests/ui/collapsible_str_replace.fixed +++ b/tests/ui/collapsible_str_replace.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::collapsible_str_replace)] diff --git a/tests/ui/collapsible_str_replace.rs b/tests/ui/collapsible_str_replace.rs index f5871be65be12..364e5493b872e 100644 --- a/tests/ui/collapsible_str_replace.rs +++ b/tests/ui/collapsible_str_replace.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::collapsible_str_replace)] diff --git a/tests/ui/collapsible_str_replace.stderr b/tests/ui/collapsible_str_replace.stderr index 223358cf53f3e..0751a1043002d 100644 --- a/tests/ui/collapsible_str_replace.stderr +++ b/tests/ui/collapsible_str_replace.stderr @@ -1,5 +1,5 @@ error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:20:27 + --> $DIR/collapsible_str_replace.rs:18:27 | LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], "l")` @@ -7,19 +7,19 @@ LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l"); = note: `-D clippy::collapsible-str-replace` implied by `-D warnings` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:22:27 + --> $DIR/collapsible_str_replace.rs:20:27 | LL | let _ = "hesuo worpd".replace('s', l).replace('u', l); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], l)` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:24:27 + --> $DIR/collapsible_str_replace.rs:22:27 | LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u', 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:27:10 + --> $DIR/collapsible_str_replace.rs:25:10 | LL | .replace('s', "l") | __________^ @@ -29,61 +29,61 @@ LL | | .replace('d', "l"); | |__________________________^ help: replace with: `replace(['s', 'u', 'p', 'd'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:32:27 + --> $DIR/collapsible_str_replace.rs:30:27 | LL | let _ = "hesuo world".replace(s, "l").replace('u', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, 'u'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:34:27 + --> $DIR/collapsible_str_replace.rs:32:27 | LL | let _ = "hesuo worpd".replace(s, "l").replace('u', "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, 'u', 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:36:27 + --> $DIR/collapsible_str_replace.rs:34:27 | LL | let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, u, 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:38:27 + --> $DIR/collapsible_str_replace.rs:36:27 | LL | let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace(p, "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, u, p], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:40:27 + --> $DIR/collapsible_str_replace.rs:38:27 | LL | let _ = "hesuo worlp".replace('s', "l").replace('u', "l").replace('p', "d"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:42:45 + --> $DIR/collapsible_str_replace.rs:40:45 | LL | let _ = "hesuo worpd".replace('s', "x").replace('u', "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['u', 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:45:47 + --> $DIR/collapsible_str_replace.rs:43:47 | LL | let _ = "hesudo worpd".replace("su", "l").replace('d', "l").replace('p', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['d', 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:47:28 + --> $DIR/collapsible_str_replace.rs:45:28 | LL | let _ = "hesudo worpd".replace(d, "l").replace('p', "l").replace("su", "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([d, 'p'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:49:27 + --> $DIR/collapsible_str_replace.rs:47:27 | LL | let _ = "hesuo world".replace(get_filter(), "l").replace('s', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([get_filter(), 's'], "l")` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:86:16 + --> $DIR/collapsible_str_replace.rs:84:16 | LL | let _ = "".replace('a', "1.58").replace('b', "1.58"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['a', 'b'], "1.58")` diff --git a/tests/ui/comparison_to_empty.fixed b/tests/ui/comparison_to_empty.fixed index af219eed0b845..90eb50715a272 100644 --- a/tests/ui/comparison_to_empty.fixed +++ b/tests/ui/comparison_to_empty.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::comparison_to_empty)] #![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)] #![feature(let_chains)] diff --git a/tests/ui/comparison_to_empty.rs b/tests/ui/comparison_to_empty.rs index 21e65184d50d4..0964c4a20a9a7 100644 --- a/tests/ui/comparison_to_empty.rs +++ b/tests/ui/comparison_to_empty.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::comparison_to_empty)] #![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)] #![feature(let_chains)] diff --git a/tests/ui/comparison_to_empty.stderr b/tests/ui/comparison_to_empty.stderr index f29782ed80d1f..0a59caea8a2d7 100644 --- a/tests/ui/comparison_to_empty.stderr +++ b/tests/ui/comparison_to_empty.stderr @@ -1,5 +1,5 @@ error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:10:13 + --> $DIR/comparison_to_empty.rs:8:13 | LL | let _ = s == ""; | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` @@ -7,49 +7,49 @@ LL | let _ = s == ""; = note: `-D clippy::comparison-to-empty` implied by `-D warnings` error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:11:13 + --> $DIR/comparison_to_empty.rs:9:13 | LL | let _ = s != ""; | ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!s.is_empty()` error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:14:13 + --> $DIR/comparison_to_empty.rs:12:13 | LL | let _ = v == []; | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `v.is_empty()` error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:15:13 + --> $DIR/comparison_to_empty.rs:13:13 | LL | let _ = v != []; | ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()` error: comparison to empty slice using `if let` - --> $DIR/comparison_to_empty.rs:16:8 + --> $DIR/comparison_to_empty.rs:14:8 | LL | if let [] = &*v {} | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(*v).is_empty()` error: comparison to empty slice using `if let` - --> $DIR/comparison_to_empty.rs:18:8 + --> $DIR/comparison_to_empty.rs:16:8 | LL | if let [] = s {} | ^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` error: comparison to empty slice using `if let` - --> $DIR/comparison_to_empty.rs:19:8 + --> $DIR/comparison_to_empty.rs:17:8 | LL | if let [] = &*s {} | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` error: comparison to empty slice using `if let` - --> $DIR/comparison_to_empty.rs:20:8 + --> $DIR/comparison_to_empty.rs:18:8 | LL | if let [] = &*s && s == [] {} | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:20:24 + --> $DIR/comparison_to_empty.rs:18:24 | LL | if let [] = &*s && s == [] {} | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` diff --git a/tests/ui/crashes/ice-10148.rs b/tests/ui/crashes/ice-10148.rs index 0df22f41374f1..8060c8e3bf0df 100644 --- a/tests/ui/crashes/ice-10148.rs +++ b/tests/ui/crashes/ice-10148.rs @@ -1,5 +1,5 @@ //@aux-build:../auxiliary/proc_macros.rs:proc-macro - +//@no-rustfix extern crate proc_macros; use proc_macros::with_span; diff --git a/tests/ui/crashes/ice-10912.rs b/tests/ui/crashes/ice-10912.rs index 69d7f2f395fff..02f333070f948 100644 --- a/tests/ui/crashes/ice-10912.rs +++ b/tests/ui/crashes/ice-10912.rs @@ -1,4 +1,4 @@ #![warn(clippy::unreadable_literal)] fn f2() -> impl Sized { && 3.14159265358979323846E } - +//@no-rustfix fn main() {} diff --git a/tests/ui/crashes/ice-2774.fixed b/tests/ui/crashes/ice-2774.fixed new file mode 100644 index 0000000000000..d71b8fcad1f5b --- /dev/null +++ b/tests/ui/crashes/ice-2774.fixed @@ -0,0 +1,27 @@ +use std::collections::HashSet; + +// See rust-lang/rust-clippy#2774. + +#[derive(Eq, PartialEq, Debug, Hash)] +pub struct Bar { + foo: Foo, +} + +#[derive(Eq, PartialEq, Debug, Hash)] +pub struct Foo; + +#[allow(clippy::implicit_hasher)] +// This should not cause a "cannot relate bound region" ICE. +pub fn add_barfoos_to_foos(bars: &HashSet<&Bar>) { + let mut foos = HashSet::new(); + foos.extend(bars.iter().map(|b| &b.foo)); +} + +#[allow(clippy::implicit_hasher)] +// Also, this should not cause a "cannot relate bound region" ICE. +pub fn add_barfoos_to_foos2(bars: &HashSet<&Bar>) { + let mut foos = HashSet::new(); + foos.extend(bars.iter().map(|b| &b.foo)); +} + +fn main() {} diff --git a/tests/ui/crashes/ice-360.rs b/tests/ui/crashes/ice-360.rs index 6555c19ca6a26..2649674667be7 100644 --- a/tests/ui/crashes/ice-360.rs +++ b/tests/ui/crashes/ice-360.rs @@ -1,5 +1,5 @@ fn main() {} - +//@no-rustfix fn no_panic(slice: &[T]) { let mut iter = slice.iter(); loop { diff --git a/tests/ui/crashes/ice-3717.fixed b/tests/ui/crashes/ice-3717.fixed new file mode 100644 index 0000000000000..f48273e796a64 --- /dev/null +++ b/tests/ui/crashes/ice-3717.fixed @@ -0,0 +1,10 @@ +#![deny(clippy::implicit_hasher)] + +use std::collections::HashSet; + +fn main() {} + +pub fn ice_3717(_: &HashSet) { + let _ = [0u8; 0]; + let _: HashSet = HashSet::default(); +} diff --git a/tests/ui/crashes/ice-5835.fixed b/tests/ui/crashes/ice-5835.fixed new file mode 100644 index 0000000000000..c11f68e85ca1e --- /dev/null +++ b/tests/ui/crashes/ice-5835.fixed @@ -0,0 +1,9 @@ +#[rustfmt::skip] +pub struct Foo { + /// 位 + /// ^ Do not remove this tab character. + /// It was required to trigger the ICE. + pub bar: u8, +} + +fn main() {} diff --git a/tests/ui/crashes/ice-5872.fixed b/tests/ui/crashes/ice-5872.fixed new file mode 100644 index 0000000000000..b009b2323ba62 --- /dev/null +++ b/tests/ui/crashes/ice-5872.fixed @@ -0,0 +1,5 @@ +#![warn(clippy::needless_collect)] + +fn main() { + let _ = vec![1, 2, 3].into_iter().next().is_none(); +} diff --git a/tests/ui/crashes/ice-6250.rs b/tests/ui/crashes/ice-6250.rs index c33580ff6ab6a..32849f2ca6f08 100644 --- a/tests/ui/crashes/ice-6250.rs +++ b/tests/ui/crashes/ice-6250.rs @@ -1,6 +1,6 @@ // originally from glacier/fixed/77218.rs // ice while adjusting... - +//@no-rustfix pub struct Cache { data: Vec, } diff --git a/tests/ui/crashes/ice-6251.rs b/tests/ui/crashes/ice-6251.rs index 6aa779aaeb3b6..a81137a646558 100644 --- a/tests/ui/crashes/ice-6251.rs +++ b/tests/ui/crashes/ice-6251.rs @@ -1,6 +1,6 @@ // originally from glacier/fixed/77329.rs // assertion failed: `(left == right) ; different DefIds - +//@no-rustfix fn bug() -> impl Iterator { std::iter::empty() } diff --git a/tests/ui/crashes/ice-6252.rs b/tests/ui/crashes/ice-6252.rs index 0ccf0aae9d742..67fbb0ff699c7 100644 --- a/tests/ui/crashes/ice-6252.rs +++ b/tests/ui/crashes/ice-6252.rs @@ -1,5 +1,6 @@ // originally from glacier fixed/77919.rs // encountered errors resolving bounds after type-checking +//@no-rustfix trait TypeVal { const VAL: T; } diff --git a/tests/ui/crashes/ice-6252.stderr b/tests/ui/crashes/ice-6252.stderr index 4787282f504a6..cb65360d1291c 100644 --- a/tests/ui/crashes/ice-6252.stderr +++ b/tests/ui/crashes/ice-6252.stderr @@ -1,5 +1,5 @@ error[E0412]: cannot find type `PhantomData` in this scope - --> $DIR/ice-6252.rs:8:9 + --> $DIR/ice-6252.rs:9:9 | LL | _n: PhantomData, | ^^^^^^^^^^^ not found in this scope @@ -14,7 +14,7 @@ LL + use std::marker::PhantomData; | error[E0412]: cannot find type `VAL` in this scope - --> $DIR/ice-6252.rs:10:63 + --> $DIR/ice-6252.rs:11:63 | LL | impl TypeVal for Multiply where N: TypeVal {} | ^^^ not found in this scope @@ -25,7 +25,7 @@ LL | impl TypeVal for Multiply where N: TypeVal {} | +++++ error[E0046]: not all trait items implemented, missing: `VAL` - --> $DIR/ice-6252.rs:10:1 + --> $DIR/ice-6252.rs:11:1 | LL | const VAL: T; | ------------ `VAL` from trait diff --git a/tests/ui/crashes/ice-7169.fixed b/tests/ui/crashes/ice-7169.fixed new file mode 100644 index 0000000000000..91cfbb38b77af --- /dev/null +++ b/tests/ui/crashes/ice-7169.fixed @@ -0,0 +1,11 @@ +#![allow(clippy::needless_if)] + +#[derive(Default)] +struct A { + a: Vec>, + b: T, +} + +fn main() { + if Ok::<_, ()>(A::::default()).is_ok() {} +} diff --git a/tests/ui/crashes/ice-8250.fixed b/tests/ui/crashes/ice-8250.fixed new file mode 100644 index 0000000000000..478b3b49270f0 --- /dev/null +++ b/tests/ui/crashes/ice-8250.fixed @@ -0,0 +1,6 @@ +fn _f(s: &str) -> Option<()> { + let _ = s[1..].split('.').next()?; + Some(()) +} + +fn main() {} diff --git a/tests/ui/crashes/ice-8821.fixed b/tests/ui/crashes/ice-8821.fixed new file mode 100644 index 0000000000000..df297eea056ad --- /dev/null +++ b/tests/ui/crashes/ice-8821.fixed @@ -0,0 +1,8 @@ +#![warn(clippy::let_unit_value)] + +fn f() {} +static FN: fn() = f; + +fn main() { + FN(); +} diff --git a/tests/ui/crashes/ice-8850.fixed b/tests/ui/crashes/ice-8850.fixed new file mode 100644 index 0000000000000..2a5b4110c2441 --- /dev/null +++ b/tests/ui/crashes/ice-8850.fixed @@ -0,0 +1,27 @@ +fn fn_pointer_static() -> usize { + static FN: fn() -> usize = || 1; + + FN() + 1 +} + +fn fn_pointer_const() -> usize { + const FN: fn() -> usize = || 1; + + FN() + 1 +} + +fn deref_to_dyn_fn() -> usize { + struct Derefs; + impl std::ops::Deref for Derefs { + type Target = dyn Fn() -> usize; + + fn deref(&self) -> &Self::Target { + &|| 2 + } + } + static FN: Derefs = Derefs; + + FN() + 1 +} + +fn main() {} diff --git a/tests/ui/crashes/ice-9041.rs b/tests/ui/crashes/ice-9041.rs index 55cc9bc99a0ed..9adc30c680b6a 100644 --- a/tests/ui/crashes/ice-9041.rs +++ b/tests/ui/crashes/ice-9041.rs @@ -1,5 +1,5 @@ pub struct Thing; - +//@no-rustfix pub fn has_thing(things: &[Thing]) -> bool { let is_thing_ready = |_peer: &Thing| -> bool { todo!() }; things.iter().find(|p| is_thing_ready(p)).is_some() diff --git a/tests/ui/crashes/ice-96721.fixed b/tests/ui/crashes/ice-96721.fixed new file mode 100644 index 0000000000000..976189d0b6c9a --- /dev/null +++ b/tests/ui/crashes/ice-96721.fixed @@ -0,0 +1,10 @@ +macro_rules! foo { + () => { + "bar.rs" + }; +} + +#[path = "file"] //~ ERROR: malformed `path` attribute +mod abc {} + +fn main() {} diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed new file mode 100644 index 0000000000000..7b4def818152c --- /dev/null +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed @@ -0,0 +1,20 @@ +#![deny(clippy::needless_lifetimes)] +#![allow(dead_code)] + +trait Foo {} + +struct Bar; + +struct Baz<'a> { + bar: &'a Bar, +} + +impl<'a> Foo for Baz<'a> {} + +impl Bar { + fn baz(&self) -> impl Foo + '_ { + Baz { bar: self } + } +} + +fn main() {} diff --git a/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed b/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed new file mode 100644 index 0000000000000..517f9cdd42ccc --- /dev/null +++ b/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed @@ -0,0 +1,9 @@ +// https://github.com/rust-lang/rust/issues/107147 + +#![warn(clippy::needless_pass_by_value)] + +struct Foo<'a>(&'a [(); 100]); + +fn test(x: &Foo<'_>) {} + +fn main() {} diff --git a/tests/ui/crate_in_macro_def.fixed b/tests/ui/crate_in_macro_def.fixed index 12a7b9470b315..bd91389c8219d 100644 --- a/tests/ui/crate_in_macro_def.fixed +++ b/tests/ui/crate_in_macro_def.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::crate_in_macro_def)] mod hygienic { diff --git a/tests/ui/crate_in_macro_def.rs b/tests/ui/crate_in_macro_def.rs index a1a9eabf639bf..f6fa338eedbf3 100644 --- a/tests/ui/crate_in_macro_def.rs +++ b/tests/ui/crate_in_macro_def.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::crate_in_macro_def)] mod hygienic { diff --git a/tests/ui/crate_in_macro_def.stderr b/tests/ui/crate_in_macro_def.stderr index 9ac5937dcc063..faf2bca1d6298 100644 --- a/tests/ui/crate_in_macro_def.stderr +++ b/tests/ui/crate_in_macro_def.stderr @@ -1,5 +1,5 @@ error: `crate` references the macro call's crate - --> $DIR/crate_in_macro_def.rs:19:28 + --> $DIR/crate_in_macro_def.rs:18:28 | LL | println!("{}", crate::unhygienic::MESSAGE); | ^^^^^ help: to reference the macro definition's crate, use: `$crate` diff --git a/tests/ui/crate_level_checks/no_std_swap.fixed b/tests/ui/crate_level_checks/no_std_swap.fixed new file mode 100644 index 0000000000000..32bccd3a0ffc6 --- /dev/null +++ b/tests/ui/crate_level_checks/no_std_swap.fixed @@ -0,0 +1,13 @@ +#![no_std] +#![feature(lang_items, start, libc)] +#![crate_type = "lib"] + +use core::panic::PanicInfo; + +#[warn(clippy::all)] +fn main() { + let mut a = 42; + let mut b = 1337; + + core::mem::swap(&mut a, &mut b); +} diff --git a/tests/ui/create_dir.fixed b/tests/ui/create_dir.fixed index 5de3e9fea0bca..8fbf7dd19b83b 100644 --- a/tests/ui/create_dir.fixed +++ b/tests/ui/create_dir.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_must_use)] #![warn(clippy::create_dir)] diff --git a/tests/ui/create_dir.rs b/tests/ui/create_dir.rs index d375bfb4a688c..af2c326ec4363 100644 --- a/tests/ui/create_dir.rs +++ b/tests/ui/create_dir.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_must_use)] #![warn(clippy::create_dir)] diff --git a/tests/ui/create_dir.stderr b/tests/ui/create_dir.stderr index 67298fc47095c..5c005bee761e4 100644 --- a/tests/ui/create_dir.stderr +++ b/tests/ui/create_dir.stderr @@ -1,5 +1,5 @@ error: calling `std::fs::create_dir` where there may be a better way - --> $DIR/create_dir.rs:11:5 + --> $DIR/create_dir.rs:10:5 | LL | std::fs::create_dir("foo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("foo")` @@ -7,7 +7,7 @@ LL | std::fs::create_dir("foo"); = note: `-D clippy::create-dir` implied by `-D warnings` error: calling `std::fs::create_dir` where there may be a better way - --> $DIR/create_dir.rs:12:5 + --> $DIR/create_dir.rs:11:5 | LL | std::fs::create_dir("bar").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("bar")` diff --git a/tests/ui/dbg_macro.rs b/tests/ui/dbg_macro.rs index 6c63c098916b7..acbd463162ff2 100644 --- a/tests/ui/dbg_macro.rs +++ b/tests/ui/dbg_macro.rs @@ -1,3 +1,5 @@ +//@no-rustfix + #![warn(clippy::dbg_macro)] fn foo(n: u32) -> u32 { diff --git a/tests/ui/dbg_macro.stderr b/tests/ui/dbg_macro.stderr index 3d29262595902..aa58fb09aff15 100644 --- a/tests/ui/dbg_macro.stderr +++ b/tests/ui/dbg_macro.stderr @@ -1,5 +1,5 @@ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:4:22 + --> $DIR/dbg_macro.rs:6:22 | LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } | ^^^^^^^^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:9:8 + --> $DIR/dbg_macro.rs:11:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:10:9 + --> $DIR/dbg_macro.rs:12:9 | LL | dbg!(1) | ^^^^^^^ @@ -33,7 +33,7 @@ LL | 1 | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:12:9 + --> $DIR/dbg_macro.rs:14:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:17:5 + --> $DIR/dbg_macro.rs:19:5 | LL | dbg!(42); | ^^^^^^^^ @@ -55,7 +55,7 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:18:5 + --> $DIR/dbg_macro.rs:20:5 | LL | dbg!(dbg!(dbg!(42))); | ^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | dbg!(dbg!(42)); | ~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:19:14 + --> $DIR/dbg_macro.rs:21:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | foo(3) + factorial(4); | ~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:20:5 + --> $DIR/dbg_macro.rs:22:5 | LL | dbg!(1, 2, dbg!(3, 4)); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | (1, 2, dbg!(3, 4)); | ~~~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:21:5 + --> $DIR/dbg_macro.rs:23:5 | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | (1, 2, 3, 4, 5); | ~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:41:5 + --> $DIR/dbg_macro.rs:43:5 | LL | dbg!(); | ^^^^^^^ @@ -111,7 +111,7 @@ LL + | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:43:13 + --> $DIR/dbg_macro.rs:45:13 | LL | let _ = dbg!(); | ^^^^^^ @@ -122,7 +122,7 @@ LL | let _ = (); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:44:9 + --> $DIR/dbg_macro.rs:46:9 | LL | bar(dbg!()); | ^^^^^^ @@ -133,7 +133,7 @@ LL | bar(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:45:10 + --> $DIR/dbg_macro.rs:47:10 | LL | foo!(dbg!()); | ^^^^^^ @@ -144,7 +144,7 @@ LL | foo!(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:46:16 + --> $DIR/dbg_macro.rs:48:16 | LL | foo2!(foo!(dbg!())); | ^^^^^^ @@ -155,7 +155,7 @@ LL | foo2!(foo!(())); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:67:9 + --> $DIR/dbg_macro.rs:69:9 | LL | dbg!(2); | ^^^^^^^ @@ -166,7 +166,7 @@ LL | 2; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:73:5 + --> $DIR/dbg_macro.rs:75:5 | LL | dbg!(1); | ^^^^^^^ @@ -177,7 +177,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:78:5 + --> $DIR/dbg_macro.rs:80:5 | LL | dbg!(1); | ^^^^^^^ @@ -188,7 +188,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:84:9 + --> $DIR/dbg_macro.rs:86:9 | LL | dbg!(1); | ^^^^^^^ diff --git a/tests/ui/decimal_literal_representation.fixed b/tests/ui/decimal_literal_representation.fixed index a6eb8c214578f..e34f48b65dd1f 100644 --- a/tests/ui/decimal_literal_representation.fixed +++ b/tests/ui/decimal_literal_representation.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[warn(clippy::decimal_literal_representation)] #[allow(unused_variables)] #[rustfmt::skip] diff --git a/tests/ui/decimal_literal_representation.rs b/tests/ui/decimal_literal_representation.rs index 7c666d6d7a697..bcc4d0df9c0e1 100644 --- a/tests/ui/decimal_literal_representation.rs +++ b/tests/ui/decimal_literal_representation.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[warn(clippy::decimal_literal_representation)] #[allow(unused_variables)] #[rustfmt::skip] diff --git a/tests/ui/decimal_literal_representation.stderr b/tests/ui/decimal_literal_representation.stderr index 8d50c8f83db44..2f126073c3379 100644 --- a/tests/ui/decimal_literal_representation.stderr +++ b/tests/ui/decimal_literal_representation.stderr @@ -1,5 +1,5 @@ error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:18:9 + --> $DIR/decimal_literal_representation.rs:16:9 | LL | 32_773, // 0x8005 | ^^^^^^ help: consider: `0x8005` @@ -7,37 +7,37 @@ LL | 32_773, // 0x8005 = note: `-D clippy::decimal-literal-representation` implied by `-D warnings` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:19:9 + --> $DIR/decimal_literal_representation.rs:17:9 | LL | 65_280, // 0xFF00 | ^^^^^^ help: consider: `0xFF00` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:20:9 + --> $DIR/decimal_literal_representation.rs:18:9 | LL | 2_131_750_927, // 0x7F0F_F00F | ^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:21:9 + --> $DIR/decimal_literal_representation.rs:19:9 | LL | 2_147_483_647, // 0x7FFF_FFFF | ^^^^^^^^^^^^^ help: consider: `0x7FFF_FFFF` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:23:9 + --> $DIR/decimal_literal_representation.rs:21:9 | LL | 4_042_322_160, // 0xF0F0_F0F0 | ^^^^^^^^^^^^^ help: consider: `0xF0F0_F0F0` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:24:9 + --> $DIR/decimal_literal_representation.rs:22:9 | LL | 32_773usize, // 0x8005_usize | ^^^^^^^^^^^ help: consider: `0x8005_usize` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:25:9 + --> $DIR/decimal_literal_representation.rs:23:9 | LL | 2_131_750_927isize, // 0x7F0F_F00F_isize | ^^^^^^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F_isize` diff --git a/tests/ui/default_constructed_unit_structs.fixed b/tests/ui/default_constructed_unit_structs.fixed index ac5fe38ff4439..3047c221d4575 100644 --- a/tests/ui/default_constructed_unit_structs.fixed +++ b/tests/ui/default_constructed_unit_structs.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::default_constructed_unit_structs)] use std::marker::PhantomData; diff --git a/tests/ui/default_constructed_unit_structs.rs b/tests/ui/default_constructed_unit_structs.rs index de7f14ffbd95c..66afedb238013 100644 --- a/tests/ui/default_constructed_unit_structs.rs +++ b/tests/ui/default_constructed_unit_structs.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::default_constructed_unit_structs)] use std::marker::PhantomData; diff --git a/tests/ui/default_constructed_unit_structs.stderr b/tests/ui/default_constructed_unit_structs.stderr index 13abb9149da24..25128b89f2e9d 100644 --- a/tests/ui/default_constructed_unit_structs.stderr +++ b/tests/ui/default_constructed_unit_structs.stderr @@ -1,5 +1,5 @@ error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:13:13 + --> $DIR/default_constructed_unit_structs.rs:11:13 | LL | Self::default() | ^^^^^^^^^^^ help: remove this call to `default` @@ -7,31 +7,31 @@ LL | Self::default() = note: `-D clippy::default-constructed-unit-structs` implied by `-D warnings` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:55:31 + --> $DIR/default_constructed_unit_structs.rs:53:31 | LL | inner: PhantomData::default(), | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:128:33 + --> $DIR/default_constructed_unit_structs.rs:126:33 | LL | let _ = PhantomData::::default(); | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:129:42 + --> $DIR/default_constructed_unit_structs.rs:127:42 | LL | let _: PhantomData = PhantomData::default(); | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:130:55 + --> $DIR/default_constructed_unit_structs.rs:128:55 | LL | let _: PhantomData = std::marker::PhantomData::default(); | ^^^^^^^^^^^ help: remove this call to `default` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:131:23 + --> $DIR/default_constructed_unit_structs.rs:129:23 | LL | let _ = UnitStruct::default(); | ^^^^^^^^^^^ help: remove this call to `default` diff --git a/tests/ui/default_instead_of_iter_empty.fixed b/tests/ui/default_instead_of_iter_empty.fixed index f44d34576f680..3298a222bda6a 100644 --- a/tests/ui/default_instead_of_iter_empty.fixed +++ b/tests/ui/default_instead_of_iter_empty.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::default_instead_of_iter_empty)] #![allow(dead_code)] use std::collections::HashMap; diff --git a/tests/ui/default_instead_of_iter_empty.rs b/tests/ui/default_instead_of_iter_empty.rs index 1c649df253cca..75b088a99590a 100644 --- a/tests/ui/default_instead_of_iter_empty.rs +++ b/tests/ui/default_instead_of_iter_empty.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::default_instead_of_iter_empty)] #![allow(dead_code)] use std::collections::HashMap; diff --git a/tests/ui/default_instead_of_iter_empty.stderr b/tests/ui/default_instead_of_iter_empty.stderr index 460fc84def8a5..2763ad6120e79 100644 --- a/tests/ui/default_instead_of_iter_empty.stderr +++ b/tests/ui/default_instead_of_iter_empty.stderr @@ -1,5 +1,5 @@ error: `std::iter::empty()` is the more idiomatic way - --> $DIR/default_instead_of_iter_empty.rs:13:13 + --> $DIR/default_instead_of_iter_empty.rs:12:13 | LL | let _ = std::iter::Empty::::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty::()` @@ -7,13 +7,13 @@ LL | let _ = std::iter::Empty::::default(); = note: `-D clippy::default-instead-of-iter-empty` implied by `-D warnings` error: `std::iter::empty()` is the more idiomatic way - --> $DIR/default_instead_of_iter_empty.rs:14:13 + --> $DIR/default_instead_of_iter_empty.rs:13:13 | LL | let _ = std::iter::Empty::>::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty::>()` error: `std::iter::empty()` is the more idiomatic way - --> $DIR/default_instead_of_iter_empty.rs:15:41 + --> $DIR/default_instead_of_iter_empty.rs:14:41 | LL | let _foo: std::iter::Empty = std::iter::Empty::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` diff --git a/tests/ui/default_numeric_fallback_f64.fixed b/tests/ui/default_numeric_fallback_f64.fixed index 02eb78060130f..e1b242716f634 100644 --- a/tests/ui/default_numeric_fallback_f64.fixed +++ b/tests/ui/default_numeric_fallback_f64.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::default_numeric_fallback)] diff --git a/tests/ui/default_numeric_fallback_f64.rs b/tests/ui/default_numeric_fallback_f64.rs index 79a9669833fad..0e93088e1fa2b 100644 --- a/tests/ui/default_numeric_fallback_f64.rs +++ b/tests/ui/default_numeric_fallback_f64.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::default_numeric_fallback)] diff --git a/tests/ui/default_numeric_fallback_f64.stderr b/tests/ui/default_numeric_fallback_f64.stderr index b949cd1d50b18..7aa2ad2522852 100644 --- a/tests/ui/default_numeric_fallback_f64.stderr +++ b/tests/ui/default_numeric_fallback_f64.stderr @@ -1,5 +1,5 @@ error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:22:17 + --> $DIR/default_numeric_fallback_f64.rs:21:17 | LL | let x = 0.12; | ^^^^ help: consider adding suffix: `0.12_f64` @@ -7,139 +7,139 @@ LL | let x = 0.12; = note: `-D clippy::default-numeric-fallback` implied by `-D warnings` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:18 + --> $DIR/default_numeric_fallback_f64.rs:22:18 | LL | let x = [1., 2., 3.]; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:22 + --> $DIR/default_numeric_fallback_f64.rs:22:22 | LL | let x = [1., 2., 3.]; | ^^ help: consider adding suffix: `2.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:26 + --> $DIR/default_numeric_fallback_f64.rs:22:26 | LL | let x = [1., 2., 3.]; | ^^ help: consider adding suffix: `3.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:24:28 + --> $DIR/default_numeric_fallback_f64.rs:23:28 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:24:32 + --> $DIR/default_numeric_fallback_f64.rs:23:32 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `2.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:24:46 + --> $DIR/default_numeric_fallback_f64.rs:23:46 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `3.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:24:50 + --> $DIR/default_numeric_fallback_f64.rs:23:50 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; | ^^ help: consider adding suffix: `4.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:25:23 + --> $DIR/default_numeric_fallback_f64.rs:24:23 | LL | let x = match 1. { | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:26:18 + --> $DIR/default_numeric_fallback_f64.rs:25:18 | LL | _ => 1., | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:45:21 + --> $DIR/default_numeric_fallback_f64.rs:44:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:53:21 + --> $DIR/default_numeric_fallback_f64.rs:52:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:59:21 + --> $DIR/default_numeric_fallback_f64.rs:58:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:67:21 + --> $DIR/default_numeric_fallback_f64.rs:66:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:79:9 + --> $DIR/default_numeric_fallback_f64.rs:78:9 | LL | 1. | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:85:27 + --> $DIR/default_numeric_fallback_f64.rs:84:27 | LL | let f = || -> _ { 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:89:29 + --> $DIR/default_numeric_fallback_f64.rs:88:29 | LL | let f = || -> f64 { 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:103:21 + --> $DIR/default_numeric_fallback_f64.rs:102:21 | LL | generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:106:32 + --> $DIR/default_numeric_fallback_f64.rs:105:32 | LL | let x: _ = generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:124:28 + --> $DIR/default_numeric_fallback_f64.rs:123:28 | LL | GenericStruct { x: 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:127:36 + --> $DIR/default_numeric_fallback_f64.rs:126:36 | LL | let _ = GenericStruct { x: 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:145:24 + --> $DIR/default_numeric_fallback_f64.rs:144:24 | LL | GenericEnum::X(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:165:23 + --> $DIR/default_numeric_fallback_f64.rs:164:23 | LL | s.generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:175:25 + --> $DIR/default_numeric_fallback_f64.rs:174:25 | LL | inline!(let x = 22.;); | ^^^ help: consider adding suffix: `22.0_f64` diff --git a/tests/ui/default_numeric_fallback_i32.fixed b/tests/ui/default_numeric_fallback_i32.fixed index 23272d07eec66..d30403b9cc989 100644 --- a/tests/ui/default_numeric_fallback_i32.fixed +++ b/tests/ui/default_numeric_fallback_i32.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(lint_reasons)] diff --git a/tests/ui/default_numeric_fallback_i32.rs b/tests/ui/default_numeric_fallback_i32.rs index fb149141609dc..4da9623d0f411 100644 --- a/tests/ui/default_numeric_fallback_i32.rs +++ b/tests/ui/default_numeric_fallback_i32.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(lint_reasons)] diff --git a/tests/ui/default_numeric_fallback_i32.stderr b/tests/ui/default_numeric_fallback_i32.stderr index 48cd28102ce4b..586f4fc0c03da 100644 --- a/tests/ui/default_numeric_fallback_i32.stderr +++ b/tests/ui/default_numeric_fallback_i32.stderr @@ -1,5 +1,5 @@ error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:22:17 + --> $DIR/default_numeric_fallback_i32.rs:21:17 | LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` @@ -7,151 +7,151 @@ LL | let x = 22; = note: `-D clippy::default-numeric-fallback` implied by `-D warnings` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:18 + --> $DIR/default_numeric_fallback_i32.rs:22:18 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:21 + --> $DIR/default_numeric_fallback_i32.rs:22:21 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:24 + --> $DIR/default_numeric_fallback_i32.rs:22:24 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:24:28 + --> $DIR/default_numeric_fallback_i32.rs:23:28 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:24:31 + --> $DIR/default_numeric_fallback_i32.rs:23:31 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:24:44 + --> $DIR/default_numeric_fallback_i32.rs:23:44 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:24:47 + --> $DIR/default_numeric_fallback_i32.rs:23:47 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `4_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:25:23 + --> $DIR/default_numeric_fallback_i32.rs:24:23 | LL | let x = match 1 { | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:26:13 + --> $DIR/default_numeric_fallback_i32.rs:25:13 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:26:18 + --> $DIR/default_numeric_fallback_i32.rs:25:18 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:27:18 + --> $DIR/default_numeric_fallback_i32.rs:26:18 | LL | _ => 2, | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:46:21 + --> $DIR/default_numeric_fallback_i32.rs:45:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:54:21 + --> $DIR/default_numeric_fallback_i32.rs:53:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:60:21 + --> $DIR/default_numeric_fallback_i32.rs:59:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:68:21 + --> $DIR/default_numeric_fallback_i32.rs:67:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:80:9 + --> $DIR/default_numeric_fallback_i32.rs:79:9 | LL | 1 | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:86:27 + --> $DIR/default_numeric_fallback_i32.rs:85:27 | LL | let f = || -> _ { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:90:29 + --> $DIR/default_numeric_fallback_i32.rs:89:29 | LL | let f = || -> i32 { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:104:21 + --> $DIR/default_numeric_fallback_i32.rs:103:21 | LL | generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:107:32 + --> $DIR/default_numeric_fallback_i32.rs:106:32 | LL | let x: _ = generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:125:28 + --> $DIR/default_numeric_fallback_i32.rs:124:28 | LL | GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:128:36 + --> $DIR/default_numeric_fallback_i32.rs:127:36 | LL | let _ = GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:146:24 + --> $DIR/default_numeric_fallback_i32.rs:145:24 | LL | GenericEnum::X(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:166:23 + --> $DIR/default_numeric_fallback_i32.rs:165:23 | LL | s.generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:176:25 + --> $DIR/default_numeric_fallback_i32.rs:175:25 | LL | inline!(let x = 22;); | ^^ help: consider adding suffix: `22_i32` diff --git a/tests/ui/default_trait_access.fixed b/tests/ui/default_trait_access.fixed index 6e541473cb354..7f6e201444fcc 100644 --- a/tests/ui/default_trait_access.fixed +++ b/tests/ui/default_trait_access.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![deny(clippy::default_trait_access)] #![allow(dead_code, unused_imports)] diff --git a/tests/ui/default_trait_access.rs b/tests/ui/default_trait_access.rs index 2ffeb32fbdce5..a0937118429c9 100644 --- a/tests/ui/default_trait_access.rs +++ b/tests/ui/default_trait_access.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![deny(clippy::default_trait_access)] #![allow(dead_code, unused_imports)] diff --git a/tests/ui/default_trait_access.stderr b/tests/ui/default_trait_access.stderr index 103fccf6a1d35..e53c8e2c79ff1 100644 --- a/tests/ui/default_trait_access.stderr +++ b/tests/ui/default_trait_access.stderr @@ -1,53 +1,53 @@ error: calling `String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:14:22 + --> $DIR/default_trait_access.rs:13:22 | LL | let s1: String = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `String::default()` | note: the lint level is defined here - --> $DIR/default_trait_access.rs:3:9 + --> $DIR/default_trait_access.rs:2:9 | LL | #![deny(clippy::default_trait_access)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:18:22 + --> $DIR/default_trait_access.rs:17:22 | LL | let s3: String = D2::default(); | ^^^^^^^^^^^^^ help: try: `String::default()` error: calling `String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:20:22 + --> $DIR/default_trait_access.rs:19:22 | LL | let s4: String = std::default::Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()` error: calling `String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:24:22 + --> $DIR/default_trait_access.rs:23:22 | LL | let s6: String = default::Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()` error: calling `GenericDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:34:46 + --> $DIR/default_trait_access.rs:33:46 | LL | let s11: GenericDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `GenericDerivedDefault::default()` error: calling `TupleDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:40:36 + --> $DIR/default_trait_access.rs:39:36 | LL | let s14: TupleDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `TupleDerivedDefault::default()` error: calling `ArrayDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:42:36 + --> $DIR/default_trait_access.rs:41:36 | LL | let s15: ArrayDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `ArrayDerivedDefault::default()` error: calling `TupleStructDerivedDefault::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:46:42 + --> $DIR/default_trait_access.rs:45:42 | LL | let s17: TupleStructDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `TupleStructDerivedDefault::default()` diff --git a/tests/ui/deref_addrof.fixed b/tests/ui/deref_addrof.fixed index 0ecca1b8ffaaa..30093da9b9a8c 100644 --- a/tests/ui/deref_addrof.fixed +++ b/tests/ui/deref_addrof.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(clippy::return_self_not_must_use, clippy::useless_vec)] diff --git a/tests/ui/deref_addrof.rs b/tests/ui/deref_addrof.rs index 9f91310e61f3e..3902bbd09757e 100644 --- a/tests/ui/deref_addrof.rs +++ b/tests/ui/deref_addrof.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(clippy::return_self_not_must_use, clippy::useless_vec)] diff --git a/tests/ui/deref_addrof.stderr b/tests/ui/deref_addrof.stderr index 9dd1e246b3e45..5918a33f38bf0 100644 --- a/tests/ui/deref_addrof.stderr +++ b/tests/ui/deref_addrof.stderr @@ -1,5 +1,5 @@ error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:24:13 + --> $DIR/deref_addrof.rs:23:13 | LL | let b = *&a; | ^^^ help: try: `a` @@ -7,49 +7,49 @@ LL | let b = *&a; = note: `-D clippy::deref-addrof` implied by `-D warnings` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:26:13 + --> $DIR/deref_addrof.rs:25:13 | LL | let b = *&get_number(); | ^^^^^^^^^^^^^^ help: try: `get_number()` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:31:13 + --> $DIR/deref_addrof.rs:30:13 | LL | let b = *&bytes[1..2][0]; | ^^^^^^^^^^^^^^^^ help: try: `bytes[1..2][0]` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:35:13 + --> $DIR/deref_addrof.rs:34:13 | LL | let b = *&(a); | ^^^^^ help: try: `(a)` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:37:13 + --> $DIR/deref_addrof.rs:36:13 | LL | let b = *(&a); | ^^^^^ help: try: `a` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:40:13 + --> $DIR/deref_addrof.rs:39:13 | LL | let b = *((&a)); | ^^^^^^^ help: try: `a` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:42:13 + --> $DIR/deref_addrof.rs:41:13 | LL | let b = *&&a; | ^^^^ help: try: `&a` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:44:14 + --> $DIR/deref_addrof.rs:43:14 | LL | let b = **&aref; | ^^^^^^ help: try: `aref` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:54:17 + --> $DIR/deref_addrof.rs:53:17 | LL | inline!(*& $(@expr self)) | ^^^^^^^^^^^^^^^^ help: try: `$(@expr self)` @@ -57,7 +57,7 @@ LL | inline!(*& $(@expr self)) = note: this error originates in the macro `__inline_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info) error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:58:17 + --> $DIR/deref_addrof.rs:57:17 | LL | inline!(*&mut $(@expr self)) | ^^^^^^^^^^^^^^^^^^^ help: try: `$(@expr self)` diff --git a/tests/ui/deref_addrof_double_trigger.rs b/tests/ui/deref_addrof_double_trigger.rs index 4531943299cd1..190ca5cc0a242 100644 --- a/tests/ui/deref_addrof_double_trigger.rs +++ b/tests/ui/deref_addrof_double_trigger.rs @@ -1,5 +1,5 @@ // This test can't work with run-rustfix because it needs two passes of test+fix - +//@no-rustfix #[warn(clippy::deref_addrof)] #[allow(unused_variables, unused_mut)] fn main() { diff --git a/tests/ui/deref_by_slicing.fixed b/tests/ui/deref_by_slicing.fixed index f91a425c65da4..a3c2e84566681 100644 --- a/tests/ui/deref_by_slicing.fixed +++ b/tests/ui/deref_by_slicing.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::deref_by_slicing)] #![allow(clippy::borrow_deref_ref)] diff --git a/tests/ui/deref_by_slicing.rs b/tests/ui/deref_by_slicing.rs index 1bfdd0a981ba2..5b4a73712ee6e 100644 --- a/tests/ui/deref_by_slicing.rs +++ b/tests/ui/deref_by_slicing.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::deref_by_slicing)] #![allow(clippy::borrow_deref_ref)] diff --git a/tests/ui/deref_by_slicing.stderr b/tests/ui/deref_by_slicing.stderr index 8f042ef47ebe3..b22c18c492db2 100644 --- a/tests/ui/deref_by_slicing.stderr +++ b/tests/ui/deref_by_slicing.stderr @@ -1,5 +1,5 @@ error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:10:13 + --> $DIR/deref_by_slicing.rs:8:13 | LL | let _ = &vec[..]; | ^^^^^^^^ help: dereference the original value instead: `&*vec` @@ -7,49 +7,49 @@ LL | let _ = &vec[..]; = note: `-D clippy::deref-by-slicing` implied by `-D warnings` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:11:13 + --> $DIR/deref_by_slicing.rs:9:13 | LL | let _ = &mut vec[..]; | ^^^^^^^^^^^^ help: dereference the original value instead: `&mut *vec` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:14:13 + --> $DIR/deref_by_slicing.rs:12:13 | LL | let _ = &ref_vec[..]; | ^^^^^^^^^^^^ help: dereference the original value instead: `&**ref_vec` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:15:21 + --> $DIR/deref_by_slicing.rs:13:21 | LL | let mut_slice = &mut ref_vec[..]; | ^^^^^^^^^^^^^^^^ help: dereference the original value instead: `&mut **ref_vec` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:16:13 + --> $DIR/deref_by_slicing.rs:14:13 | LL | let _ = &mut mut_slice[..]; // Err, re-borrows slice | ^^^^^^^^^^^^^^^^^^ help: reborrow the original value instead: `&mut *mut_slice` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:19:13 + --> $DIR/deref_by_slicing.rs:17:13 | LL | let _ = &s[..]; | ^^^^^^ help: dereference the original value instead: `&*s` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:22:18 + --> $DIR/deref_by_slicing.rs:20:18 | LL | let _ = &mut &S[..]; // Err, re-borrows slice | ^^^^^^ help: reborrow the original value instead: `&*S` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:26:13 + --> $DIR/deref_by_slicing.rs:24:13 | LL | let _ = &slice_ref[..]; // Err, derefs slice | ^^^^^^^^^^^^^^ help: dereference the original value instead: `*slice_ref` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:29:13 + --> $DIR/deref_by_slicing.rs:27:13 | LL | let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice | ^^^^^^^^^^^^ help: reborrow the original value instead: `(&*bytes)` diff --git a/tests/ui/derivable_impls.fixed b/tests/ui/derivable_impls.fixed index a10f3d0107076..6cc202414f5f4 100644 --- a/tests/ui/derivable_impls.fixed +++ b/tests/ui/derivable_impls.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] use std::collections::HashMap; diff --git a/tests/ui/derivable_impls.rs b/tests/ui/derivable_impls.rs index 18cef1c5be895..0aa9acd752dcc 100644 --- a/tests/ui/derivable_impls.rs +++ b/tests/ui/derivable_impls.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] use std::collections::HashMap; diff --git a/tests/ui/derivable_impls.stderr b/tests/ui/derivable_impls.stderr index 8089f5ea0fcb2..b05af79e3fd6c 100644 --- a/tests/ui/derivable_impls.stderr +++ b/tests/ui/derivable_impls.stderr @@ -1,5 +1,5 @@ error: this `impl` can be derived - --> $DIR/derivable_impls.rs:22:1 + --> $DIR/derivable_impls.rs:20:1 | LL | / impl std::default::Default for FooDefault<'_> { LL | | fn default() -> Self { @@ -19,7 +19,7 @@ LL | struct FooDefault<'a> { | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:43:1 + --> $DIR/derivable_impls.rs:41:1 | LL | / impl std::default::Default for TupleDefault { LL | | fn default() -> Self { @@ -36,7 +36,7 @@ LL | struct TupleDefault(bool, i32, u64); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:95:1 + --> $DIR/derivable_impls.rs:93:1 | LL | / impl Default for StrDefault<'_> { LL | | fn default() -> Self { @@ -53,7 +53,7 @@ LL | struct StrDefault<'a>(&'a str); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:121:1 + --> $DIR/derivable_impls.rs:119:1 | LL | / impl Default for Y { LL | | fn default() -> Self { @@ -70,7 +70,7 @@ LL | struct Y(u32); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:160:1 + --> $DIR/derivable_impls.rs:158:1 | LL | / impl Default for WithoutSelfCurly { LL | | fn default() -> Self { @@ -87,7 +87,7 @@ LL | struct WithoutSelfCurly { | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:168:1 + --> $DIR/derivable_impls.rs:166:1 | LL | / impl Default for WithoutSelfParan { LL | | fn default() -> Self { @@ -104,7 +104,7 @@ LL | struct WithoutSelfParan(bool); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:218:1 + --> $DIR/derivable_impls.rs:216:1 | LL | / impl Default for RepeatDefault1 { LL | | fn default() -> Self { @@ -121,7 +121,7 @@ LL | pub struct RepeatDefault1 { | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:252:1 + --> $DIR/derivable_impls.rs:250:1 | LL | / impl Default for SimpleEnum { LL | | fn default() -> Self { diff --git a/tests/ui/derive_partial_eq_without_eq.fixed b/tests/ui/derive_partial_eq_without_eq.fixed index a1f29430c30f2..a7f5d3ec7cd08 100644 --- a/tests/ui/derive_partial_eq_without_eq.fixed +++ b/tests/ui/derive_partial_eq_without_eq.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::derive_partial_eq_without_eq)] diff --git a/tests/ui/derive_partial_eq_without_eq.rs b/tests/ui/derive_partial_eq_without_eq.rs index ff4d888559b73..476d2aee23a88 100644 --- a/tests/ui/derive_partial_eq_without_eq.rs +++ b/tests/ui/derive_partial_eq_without_eq.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::derive_partial_eq_without_eq)] diff --git a/tests/ui/derive_partial_eq_without_eq.stderr b/tests/ui/derive_partial_eq_without_eq.stderr index 794c5dab8445b..91729abc2bbbe 100644 --- a/tests/ui/derive_partial_eq_without_eq.stderr +++ b/tests/ui/derive_partial_eq_without_eq.stderr @@ -1,5 +1,5 @@ error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:13:17 + --> $DIR/derive_partial_eq_without_eq.rs:11:17 | LL | #[derive(Debug, PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` @@ -7,61 +7,61 @@ LL | #[derive(Debug, PartialEq)] = note: `-D clippy::derive-partial-eq-without-eq` implied by `-D warnings` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:55:10 + --> $DIR/derive_partial_eq_without_eq.rs:53:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:61:10 + --> $DIR/derive_partial_eq_without_eq.rs:59:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:67:10 + --> $DIR/derive_partial_eq_without_eq.rs:65:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:70:10 + --> $DIR/derive_partial_eq_without_eq.rs:68:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:76:10 + --> $DIR/derive_partial_eq_without_eq.rs:74:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:82:10 + --> $DIR/derive_partial_eq_without_eq.rs:80:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:95:17 + --> $DIR/derive_partial_eq_without_eq.rs:93:17 | LL | #[derive(Debug, PartialEq, Clone)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:98:10 + --> $DIR/derive_partial_eq_without_eq.rs:96:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:105:14 + --> $DIR/derive_partial_eq_without_eq.rs:103:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:108:14 + --> $DIR/derive_partial_eq_without_eq.rs:106:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` diff --git a/tests/ui/doc/doc-fixable.fixed b/tests/ui/doc/doc-fixable.fixed index 14444df4c10ec..f7c2f14a4824a 100644 --- a/tests/ui/doc/doc-fixable.fixed +++ b/tests/ui/doc/doc-fixable.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + //! This file tests for the `DOC_MARKDOWN` lint. #![allow(dead_code, incomplete_features)] diff --git a/tests/ui/doc/doc-fixable.rs b/tests/ui/doc/doc-fixable.rs index 542d33b13a4c5..51961e75b84c2 100644 --- a/tests/ui/doc/doc-fixable.rs +++ b/tests/ui/doc/doc-fixable.rs @@ -1,4 +1,4 @@ -//@run-rustfix + //! This file tests for the `DOC_MARKDOWN` lint. #![allow(dead_code, incomplete_features)] diff --git a/tests/ui/doc/unbalanced_ticks.rs b/tests/ui/doc/unbalanced_ticks.rs index 8e8324b30f0fb..101434b4f3be5 100644 --- a/tests/ui/doc/unbalanced_ticks.rs +++ b/tests/ui/doc/unbalanced_ticks.rs @@ -1,6 +1,6 @@ //! This file tests for the `DOC_MARKDOWN` lint, specifically cases //! where ticks are unbalanced (see issue #6753). - +//@no-rustfix #![allow(dead_code)] #![warn(clippy::doc_markdown)] diff --git a/tests/ui/double_comparison.fixed b/tests/ui/double_comparison.fixed index f8ca92ef0b34b..788f3224b4186 100644 --- a/tests/ui/double_comparison.fixed +++ b/tests/ui/double_comparison.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_if)] fn main() { diff --git a/tests/ui/double_comparison.rs b/tests/ui/double_comparison.rs index 47ff87bea0ab0..245a83d5709d4 100644 --- a/tests/ui/double_comparison.rs +++ b/tests/ui/double_comparison.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_if)] fn main() { diff --git a/tests/ui/double_comparison.stderr b/tests/ui/double_comparison.stderr index 4df1c28ac4871..05ef4e25f7f87 100644 --- a/tests/ui/double_comparison.stderr +++ b/tests/ui/double_comparison.stderr @@ -1,5 +1,5 @@ error: this binary expression can be simplified - --> $DIR/double_comparison.rs:7:8 + --> $DIR/double_comparison.rs:6:8 | LL | if x == y || x < y { | ^^^^^^^^^^^^^^^ help: try: `x <= y` @@ -7,43 +7,43 @@ LL | if x == y || x < y { = note: `-D clippy::double-comparisons` implied by `-D warnings` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:10:8 + --> $DIR/double_comparison.rs:9:8 | LL | if x < y || x == y { | ^^^^^^^^^^^^^^^ help: try: `x <= y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:13:8 + --> $DIR/double_comparison.rs:12:8 | LL | if x == y || x > y { | ^^^^^^^^^^^^^^^ help: try: `x >= y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:16:8 + --> $DIR/double_comparison.rs:15:8 | LL | if x > y || x == y { | ^^^^^^^^^^^^^^^ help: try: `x >= y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:19:8 + --> $DIR/double_comparison.rs:18:8 | LL | if x < y || x > y { | ^^^^^^^^^^^^^^ help: try: `x != y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:22:8 + --> $DIR/double_comparison.rs:21:8 | LL | if x > y || x < y { | ^^^^^^^^^^^^^^ help: try: `x != y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:25:8 + --> $DIR/double_comparison.rs:24:8 | LL | if x <= y && x >= y { | ^^^^^^^^^^^^^^^^ help: try: `x == y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:28:8 + --> $DIR/double_comparison.rs:27:8 | LL | if x >= y && x <= y { | ^^^^^^^^^^^^^^^^ help: try: `x == y` diff --git a/tests/ui/drain_collect.fixed b/tests/ui/drain_collect.fixed index 11001bd319f31..6f597243fe6fc 100644 --- a/tests/ui/drain_collect.fixed +++ b/tests/ui/drain_collect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::drain_collect)] #![allow(dead_code)] diff --git a/tests/ui/drain_collect.rs b/tests/ui/drain_collect.rs index 373a3ca3506da..353aac4da9a4f 100644 --- a/tests/ui/drain_collect.rs +++ b/tests/ui/drain_collect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::drain_collect)] #![allow(dead_code)] diff --git a/tests/ui/drain_collect.stderr b/tests/ui/drain_collect.stderr index 0792f0254cb54..3364466ec80be 100644 --- a/tests/ui/drain_collect.stderr +++ b/tests/ui/drain_collect.stderr @@ -1,65 +1,65 @@ error: you seem to be trying to move all elements into a new `BinaryHeap` - --> $DIR/drain_collect.rs:9:5 + --> $DIR/drain_collect.rs:7:5 | LL | b.drain().collect() | ^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` | note: the lint level is defined here - --> $DIR/drain_collect.rs:3:9 + --> $DIR/drain_collect.rs:1:9 | LL | #![deny(clippy::drain_collect)] | ^^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to move all elements into a new `HashMap` - --> $DIR/drain_collect.rs:17:5 + --> $DIR/drain_collect.rs:15:5 | LL | b.drain().collect() | ^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `HashSet` - --> $DIR/drain_collect.rs:25:5 + --> $DIR/drain_collect.rs:23:5 | LL | b.drain().collect() | ^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:33:5 + --> $DIR/drain_collect.rs:31:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:41:5 + --> $DIR/drain_collect.rs:39:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:45:5 + --> $DIR/drain_collect.rs:43:5 | LL | b.drain(0..).collect() | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:49:5 + --> $DIR/drain_collect.rs:47:5 | LL | b.drain(..b.len()).collect() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:53:5 + --> $DIR/drain_collect.rs:51:5 | LL | b.drain(0..b.len()).collect() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:58:5 + --> $DIR/drain_collect.rs:56:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(&mut b)` error: you seem to be trying to move all elements into a new `String` - --> $DIR/drain_collect.rs:66:5 + --> $DIR/drain_collect.rs:64:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` diff --git a/tests/ui/duration_subsec.fixed b/tests/ui/duration_subsec.fixed index bfd30f0042d55..114c516ed1a19 100644 --- a/tests/ui/duration_subsec.fixed +++ b/tests/ui/duration_subsec.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::needless_borrow)] #![warn(clippy::duration_subsec)] diff --git a/tests/ui/duration_subsec.rs b/tests/ui/duration_subsec.rs index 860233f084f37..8469fe086b10c 100644 --- a/tests/ui/duration_subsec.rs +++ b/tests/ui/duration_subsec.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::needless_borrow)] #![warn(clippy::duration_subsec)] diff --git a/tests/ui/duration_subsec.stderr b/tests/ui/duration_subsec.stderr index cdbeff6a03783..6c1fd433e7cc9 100644 --- a/tests/ui/duration_subsec.stderr +++ b/tests/ui/duration_subsec.stderr @@ -1,5 +1,5 @@ error: calling `subsec_millis()` is more concise than this calculation - --> $DIR/duration_subsec.rs:10:24 + --> $DIR/duration_subsec.rs:9:24 | LL | let bad_millis_1 = dur.subsec_micros() / 1_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_millis()` @@ -7,25 +7,25 @@ LL | let bad_millis_1 = dur.subsec_micros() / 1_000; = note: `-D clippy::duration-subsec` implied by `-D warnings` error: calling `subsec_millis()` is more concise than this calculation - --> $DIR/duration_subsec.rs:11:24 + --> $DIR/duration_subsec.rs:10:24 | LL | let bad_millis_2 = dur.subsec_nanos() / 1_000_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_millis()` error: calling `subsec_micros()` is more concise than this calculation - --> $DIR/duration_subsec.rs:16:22 + --> $DIR/duration_subsec.rs:15:22 | LL | let bad_micros = dur.subsec_nanos() / 1_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()` error: calling `subsec_micros()` is more concise than this calculation - --> $DIR/duration_subsec.rs:21:13 + --> $DIR/duration_subsec.rs:20:13 | LL | let _ = (&dur).subsec_nanos() / 1_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&dur).subsec_micros()` error: calling `subsec_micros()` is more concise than this calculation - --> $DIR/duration_subsec.rs:25:13 + --> $DIR/duration_subsec.rs:24:13 | LL | let _ = dur.subsec_nanos() / NANOS_IN_MICRO; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()` diff --git a/tests/ui/empty_drop.fixed b/tests/ui/empty_drop.fixed index fd0a9a7081eab..949d0d8b39972 100644 --- a/tests/ui/empty_drop.fixed +++ b/tests/ui/empty_drop.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::empty_drop)] #![allow(unused)] diff --git a/tests/ui/empty_drop.rs b/tests/ui/empty_drop.rs index 6c15cb9330276..74822ea50ec71 100644 --- a/tests/ui/empty_drop.rs +++ b/tests/ui/empty_drop.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::empty_drop)] #![allow(unused)] diff --git a/tests/ui/empty_drop.stderr b/tests/ui/empty_drop.stderr index 70f7880d03601..e952169372637 100644 --- a/tests/ui/empty_drop.stderr +++ b/tests/ui/empty_drop.stderr @@ -1,5 +1,5 @@ error: empty drop implementation - --> $DIR/empty_drop.rs:8:1 + --> $DIR/empty_drop.rs:7:1 | LL | / impl Drop for Foo { LL | | fn drop(&mut self) {} @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::empty-drop` implied by `-D warnings` error: empty drop implementation - --> $DIR/empty_drop.rs:24:1 + --> $DIR/empty_drop.rs:23:1 | LL | / impl Drop for Baz { LL | | fn drop(&mut self) { diff --git a/tests/ui/empty_structs_with_brackets.fixed b/tests/ui/empty_structs_with_brackets.fixed index 6fab30208393e..80572645f5d1c 100644 --- a/tests/ui/empty_structs_with_brackets.fixed +++ b/tests/ui/empty_structs_with_brackets.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::empty_structs_with_brackets)] #![allow(dead_code)] diff --git a/tests/ui/empty_structs_with_brackets.rs b/tests/ui/empty_structs_with_brackets.rs index 0caa3c49cd668..8fb3e247a4198 100644 --- a/tests/ui/empty_structs_with_brackets.rs +++ b/tests/ui/empty_structs_with_brackets.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::empty_structs_with_brackets)] #![allow(dead_code)] diff --git a/tests/ui/empty_structs_with_brackets.stderr b/tests/ui/empty_structs_with_brackets.stderr index 0308cb5571af2..ba3013750d56b 100644 --- a/tests/ui/empty_structs_with_brackets.stderr +++ b/tests/ui/empty_structs_with_brackets.stderr @@ -1,5 +1,5 @@ error: found empty brackets on struct declaration - --> $DIR/empty_structs_with_brackets.rs:5:25 + --> $DIR/empty_structs_with_brackets.rs:4:25 | LL | pub struct MyEmptyStruct {} // should trigger lint | ^^^ @@ -8,7 +8,7 @@ LL | pub struct MyEmptyStruct {} // should trigger lint = help: remove the brackets error: found empty brackets on struct declaration - --> $DIR/empty_structs_with_brackets.rs:6:26 + --> $DIR/empty_structs_with_brackets.rs:5:26 | LL | struct MyEmptyTupleStruct(); // should trigger lint | ^^^ diff --git a/tests/ui/entry.fixed b/tests/ui/entry.fixed index 7e82390605ccc..4099fe7e1393e 100644 --- a/tests/ui/entry.fixed +++ b/tests/ui/entry.fixed @@ -1,5 +1,4 @@ //@needs-asm-support -//@run-rustfix #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] diff --git a/tests/ui/entry.rs b/tests/ui/entry.rs index 742c932253576..409be0aa06019 100644 --- a/tests/ui/entry.rs +++ b/tests/ui/entry.rs @@ -1,5 +1,4 @@ //@needs-asm-support -//@run-rustfix #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] diff --git a/tests/ui/entry.stderr b/tests/ui/entry.stderr index e8a003e9cf674..e89d15cc1af70 100644 --- a/tests/ui/entry.stderr +++ b/tests/ui/entry.stderr @@ -1,5 +1,5 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:25:5 + --> $DIR/entry.rs:24:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::map-entry` implied by `-D warnings` error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:30:5 + --> $DIR/entry.rs:29:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -32,7 +32,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:39:5 + --> $DIR/entry.rs:38:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -55,7 +55,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:48:5 + --> $DIR/entry.rs:47:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -79,7 +79,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:58:5 + --> $DIR/entry.rs:57:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -96,7 +96,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:64:5 + --> $DIR/entry.rs:63:5 | LL | / if !m.contains_key(&k) { LL | | match 0 { @@ -122,7 +122,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:76:5 + --> $DIR/entry.rs:75:5 | LL | / if !m.contains_key(&k) { LL | | match 0 { @@ -146,7 +146,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:86:5 + --> $DIR/entry.rs:85:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -187,7 +187,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:120:5 + --> $DIR/entry.rs:119:5 | LL | / if !m.contains_key(&m!(k)) { LL | | m.insert(m!(k), m!(v)); @@ -195,7 +195,7 @@ LL | | } | |_____^ help: try: `m.entry(m!(k)).or_insert_with(|| m!(v));` error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:152:5 + --> $DIR/entry.rs:151:5 | LL | / if !m.contains_key(&k) { LL | | let x = (String::new(), String::new()); diff --git a/tests/ui/entry_btree.fixed b/tests/ui/entry_btree.fixed index 3baaacffd20d2..228212c79eaf8 100644 --- a/tests/ui/entry_btree.fixed +++ b/tests/ui/entry_btree.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::map_entry)] #![allow(dead_code)] diff --git a/tests/ui/entry_btree.rs b/tests/ui/entry_btree.rs index 770e8e91da23f..44703c5671135 100644 --- a/tests/ui/entry_btree.rs +++ b/tests/ui/entry_btree.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::map_entry)] #![allow(dead_code)] diff --git a/tests/ui/entry_btree.stderr b/tests/ui/entry_btree.stderr index 8f41581d6b6d9..e5a1365eae93c 100644 --- a/tests/ui/entry_btree.stderr +++ b/tests/ui/entry_btree.stderr @@ -1,5 +1,5 @@ error: usage of `contains_key` followed by `insert` on a `BTreeMap` - --> $DIR/entry_btree.rs:12:5 + --> $DIR/entry_btree.rs:10:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); diff --git a/tests/ui/entry_with_else.fixed b/tests/ui/entry_with_else.fixed index 71fe04fd64842..34804b9ee5d77 100644 --- a/tests/ui/entry_with_else.fixed +++ b/tests/ui/entry_with_else.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] diff --git a/tests/ui/entry_with_else.rs b/tests/ui/entry_with_else.rs index 80f74649a6033..0515748fd7336 100644 --- a/tests/ui/entry_with_else.rs +++ b/tests/ui/entry_with_else.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] diff --git a/tests/ui/entry_with_else.stderr b/tests/ui/entry_with_else.stderr index 0d0eb964937e6..a0f39568708c0 100644 --- a/tests/ui/entry_with_else.stderr +++ b/tests/ui/entry_with_else.stderr @@ -1,5 +1,5 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:16:5 + --> $DIR/entry_with_else.rs:14:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -22,7 +22,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:22:5 + --> $DIR/entry_with_else.rs:20:5 | LL | / if m.contains_key(&k) { LL | | m.insert(k, v); @@ -44,7 +44,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:28:5 + --> $DIR/entry_with_else.rs:26:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -63,7 +63,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:34:5 + --> $DIR/entry_with_else.rs:32:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -82,7 +82,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:40:5 + --> $DIR/entry_with_else.rs:38:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -104,7 +104,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:46:5 + --> $DIR/entry_with_else.rs:44:5 | LL | / if m.contains_key(&k) { LL | | if true { m.insert(k, v) } else { m.insert(k, v2) } @@ -127,7 +127,7 @@ LL ~ }; | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:52:5 + --> $DIR/entry_with_else.rs:50:5 | LL | / if m.contains_key(&k) { LL | | foo(); diff --git a/tests/ui/enum_glob_use.fixed b/tests/ui/enum_glob_use.fixed index 419370ffb1d27..9044e80268dbf 100644 --- a/tests/ui/enum_glob_use.fixed +++ b/tests/ui/enum_glob_use.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::enum_glob_use)] #![allow(unused)] #![warn(unused_imports)] diff --git a/tests/ui/enum_glob_use.rs b/tests/ui/enum_glob_use.rs index 645ed98325c9a..4f157a97cbc9b 100644 --- a/tests/ui/enum_glob_use.rs +++ b/tests/ui/enum_glob_use.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::enum_glob_use)] #![allow(unused)] #![warn(unused_imports)] diff --git a/tests/ui/enum_glob_use.stderr b/tests/ui/enum_glob_use.stderr index 69531aed39bd4..c1851f92765b8 100644 --- a/tests/ui/enum_glob_use.stderr +++ b/tests/ui/enum_glob_use.stderr @@ -1,5 +1,5 @@ error: usage of wildcard import for enum variants - --> $DIR/enum_glob_use.rs:7:5 + --> $DIR/enum_glob_use.rs:5:5 | LL | use std::cmp::Ordering::*; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::cmp::Ordering::Less` @@ -7,13 +7,13 @@ LL | use std::cmp::Ordering::*; = note: `-D clippy::enum-glob-use` implied by `-D warnings` error: usage of wildcard import for enum variants - --> $DIR/enum_glob_use.rs:13:5 + --> $DIR/enum_glob_use.rs:11:5 | LL | use self::Enum::*; | ^^^^^^^^^^^^^ help: try: `self::Enum::Foo` error: usage of wildcard import for enum variants - --> $DIR/enum_glob_use.rs:17:13 + --> $DIR/enum_glob_use.rs:15:13 | LL | use crate::Enum::*; | ^^^^^^^^^^^^^^ help: try: `crate::Enum::Foo` diff --git a/tests/ui/eprint_with_newline.fixed b/tests/ui/eprint_with_newline.fixed new file mode 100644 index 0000000000000..c63a657142026 --- /dev/null +++ b/tests/ui/eprint_with_newline.fixed @@ -0,0 +1,55 @@ +#![allow(clippy::print_literal)] +#![warn(clippy::print_with_newline)] + +fn main() { + eprintln!("Hello"); + eprintln!("Hello {}", "world"); + eprintln!("Hello {} {}", "world", "#2"); + eprintln!("{}", 1265); + eprintln!(); + + // these are all fine + eprint!(""); + eprint!("Hello"); + eprintln!("Hello"); + eprintln!("Hello\n"); + eprintln!("Hello {}\n", "world"); + eprint!("Issue\n{}", 1265); + eprint!("{}", 1265); + eprint!("\n{}", 1275); + eprint!("\n\n"); + eprint!("like eof\n\n"); + eprint!("Hello {} {}\n\n", "world", "#2"); + eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 + eprintln!("\nbla\n\n"); // #3126 + + // Escaping + eprint!("\\n"); // #3514 + eprintln!("\\"); // should fail + eprint!("\\\\n"); + + // Raw strings + eprint!(r"\n"); // #3778 + + // Literal newlines should also fail + eprintln!( + + ); + eprintln!( + + ); + + // Don't warn on CRLF (#4208) + eprint!("\r\n"); + eprint!("foo\r\n"); + eprintln!("\\r"); + eprint!("foo\rbar\n"); + + // Ignore expanded format strings + macro_rules! newline { + () => { + "\n" + }; + } + eprint!(newline!()); +} diff --git a/tests/ui/equatable_if_let.fixed b/tests/ui/equatable_if_let.fixed index 6cc070fb5526d..73094ad1e53f6 100644 --- a/tests/ui/equatable_if_let.fixed +++ b/tests/ui/equatable_if_let.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow( diff --git a/tests/ui/equatable_if_let.rs b/tests/ui/equatable_if_let.rs index f00a129bef1a0..460352734a313 100644 --- a/tests/ui/equatable_if_let.rs +++ b/tests/ui/equatable_if_let.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow( diff --git a/tests/ui/equatable_if_let.stderr b/tests/ui/equatable_if_let.stderr index 649495dded7df..3b6cbbabbe2ba 100644 --- a/tests/ui/equatable_if_let.stderr +++ b/tests/ui/equatable_if_let.stderr @@ -1,5 +1,5 @@ error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:65:8 + --> $DIR/equatable_if_let.rs:64:8 | LL | if let 2 = a {} | ^^^^^^^^^ help: try: `a == 2` @@ -7,79 +7,79 @@ LL | if let 2 = a {} = note: `-D clippy::equatable-if-let` implied by `-D warnings` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:66:8 + --> $DIR/equatable_if_let.rs:65:8 | LL | if let Ordering::Greater = a.cmp(&b) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.cmp(&b) == Ordering::Greater` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:67:8 + --> $DIR/equatable_if_let.rs:66:8 | LL | if let Some(2) = c {} | ^^^^^^^^^^^^^^^ help: try: `c == Some(2)` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:68:8 + --> $DIR/equatable_if_let.rs:67:8 | LL | if let Struct { a: 2, b: false } = d {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d == (Struct { a: 2, b: false })` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:69:8 + --> $DIR/equatable_if_let.rs:68:8 | LL | if let Enum::TupleVariant(32, 64) = e {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::TupleVariant(32, 64)` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:70:8 + --> $DIR/equatable_if_let.rs:69:8 | LL | if let Enum::RecordVariant { a: 64, b: 32 } = e {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == (Enum::RecordVariant { a: 64, b: 32 })` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:71:8 + --> $DIR/equatable_if_let.rs:70:8 | LL | if let Enum::UnitVariant = e {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::UnitVariant` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:72:8 + --> $DIR/equatable_if_let.rs:71:8 | LL | if let (Enum::UnitVariant, &Struct { a: 2, b: false }) = (e, &d) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false })` error: this pattern matching can be expressed using `matches!` - --> $DIR/equatable_if_let.rs:81:8 + --> $DIR/equatable_if_let.rs:80:8 | LL | if let NotPartialEq::A = f {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(f, NotPartialEq::A)` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:82:8 + --> $DIR/equatable_if_let.rs:81:8 | LL | if let NotStructuralEq::A = g {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `g == NotStructuralEq::A` error: this pattern matching can be expressed using `matches!` - --> $DIR/equatable_if_let.rs:83:8 + --> $DIR/equatable_if_let.rs:82:8 | LL | if let Some(NotPartialEq::A) = Some(f) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(Some(f), Some(NotPartialEq::A))` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:84:8 + --> $DIR/equatable_if_let.rs:83:8 | LL | if let Some(NotStructuralEq::A) = Some(g) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(g) == Some(NotStructuralEq::A)` error: this pattern matching can be expressed using `matches!` - --> $DIR/equatable_if_let.rs:85:8 + --> $DIR/equatable_if_let.rs:84:8 | LL | if let NoPartialEqStruct { a: 2, b: false } = h {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(h, NoPartialEqStruct { a: 2, b: false })` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:87:8 + --> $DIR/equatable_if_let.rs:86:8 | LL | if let inline!("abc") = "abc" { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"abc" == inline!("abc")` diff --git a/tests/ui/err_expect.fixed b/tests/ui/err_expect.fixed index 46e2816da5226..abbc6dbebedb5 100644 --- a/tests/ui/err_expect.fixed +++ b/tests/ui/err_expect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::unnecessary_literal_unwrap)] struct MyTypeNonDebug; diff --git a/tests/ui/err_expect.rs b/tests/ui/err_expect.rs index b9446034d50a2..0c7ad185dfbe8 100644 --- a/tests/ui/err_expect.rs +++ b/tests/ui/err_expect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::unnecessary_literal_unwrap)] struct MyTypeNonDebug; diff --git a/tests/ui/err_expect.stderr b/tests/ui/err_expect.stderr index 82c0754cfb00b..e3046a5a13a76 100644 --- a/tests/ui/err_expect.stderr +++ b/tests/ui/err_expect.stderr @@ -1,5 +1,5 @@ error: called `.err().expect()` on a `Result` value - --> $DIR/err_expect.rs:12:16 + --> $DIR/err_expect.rs:10:16 | LL | test_debug.err().expect("Testing debug type"); | ^^^^^^^^^^^^ help: try: `expect_err` @@ -7,7 +7,7 @@ LL | test_debug.err().expect("Testing debug type"); = note: `-D clippy::err-expect` implied by `-D warnings` error: called `.err().expect()` on a `Result` value - --> $DIR/err_expect.rs:27:7 + --> $DIR/err_expect.rs:25:7 | LL | x.err().expect("17"); | ^^^^^^^^^^^^ help: try: `expect_err` diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index ddabe7616d093..f1cac8c5fbc63 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)] #![allow(unused)] #![allow( diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index 92ecff6eb1afb..c7a470b5be6df 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)] #![allow(unused)] #![allow( diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index ff40a2074e561..db6184e36a430 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -1,5 +1,5 @@ error: redundant closure - --> $DIR/eta.rs:29:27 + --> $DIR/eta.rs:28:27 | LL | let a = Some(1u8).map(|a| foo(a)); | ^^^^^^^^^^ help: replace the closure with the function itself: `foo` @@ -7,31 +7,31 @@ LL | let a = Some(1u8).map(|a| foo(a)); = note: `-D clippy::redundant-closure` implied by `-D warnings` error: redundant closure - --> $DIR/eta.rs:33:40 + --> $DIR/eta.rs:32:40 | LL | let _: Option> = true.then(|| vec![]); // special case vec! | ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new` error: redundant closure - --> $DIR/eta.rs:34:35 + --> $DIR/eta.rs:33:35 | LL | let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted? | ^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo2` error: redundant closure - --> $DIR/eta.rs:35:26 + --> $DIR/eta.rs:34:26 | LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted | ^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `below` error: redundant closure - --> $DIR/eta.rs:42:27 + --> $DIR/eta.rs:41:27 | LL | let e = Some(1u8).map(|a| generic(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic` error: redundant closure - --> $DIR/eta.rs:94:51 + --> $DIR/eta.rs:93:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo` @@ -39,127 +39,127 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); = note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings` error: redundant closure - --> $DIR/eta.rs:95:51 + --> $DIR/eta.rs:94:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo()); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `TestTrait::trait_foo` error: redundant closure - --> $DIR/eta.rs:97:42 + --> $DIR/eta.rs:96:42 | LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear()); | ^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::vec::Vec::clear` error: redundant closure - --> $DIR/eta.rs:101:29 + --> $DIR/eta.rs:100:29 | LL | let e = Some("str").map(|s| s.to_string()); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string` error: redundant closure - --> $DIR/eta.rs:102:27 + --> $DIR/eta.rs:101:27 | LL | let e = Some('a').map(|s| s.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_uppercase` error: redundant closure - --> $DIR/eta.rs:104:65 + --> $DIR/eta.rs:103:65 | LL | let e: std::vec::Vec = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase` error: redundant closure - --> $DIR/eta.rs:167:22 + --> $DIR/eta.rs:166:22 | LL | requires_fn_once(|| x()); | ^^^^^^ help: replace the closure with the function itself: `x` error: redundant closure - --> $DIR/eta.rs:174:27 + --> $DIR/eta.rs:173:27 | LL | let a = Some(1u8).map(|a| foo_ptr(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr` error: redundant closure - --> $DIR/eta.rs:179:27 + --> $DIR/eta.rs:178:27 | LL | let a = Some(1u8).map(|a| closure(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure` error: redundant closure - --> $DIR/eta.rs:211:28 + --> $DIR/eta.rs:210:28 | LL | x.into_iter().for_each(|x| add_to_res(x)); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res` error: redundant closure - --> $DIR/eta.rs:212:28 + --> $DIR/eta.rs:211:28 | LL | y.into_iter().for_each(|x| add_to_res(x)); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res` error: redundant closure - --> $DIR/eta.rs:213:28 + --> $DIR/eta.rs:212:28 | LL | z.into_iter().for_each(|x| add_to_res(x)); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `add_to_res` error: redundant closure - --> $DIR/eta.rs:220:21 + --> $DIR/eta.rs:219:21 | LL | Some(1).map(|n| closure(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure` error: redundant closure - --> $DIR/eta.rs:224:21 + --> $DIR/eta.rs:223:21 | LL | Some(1).map(|n| in_loop(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop` error: redundant closure - --> $DIR/eta.rs:317:18 + --> $DIR/eta.rs:316:18 | LL | takes_fn_mut(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> $DIR/eta.rs:320:19 + --> $DIR/eta.rs:319:19 | LL | takes_fn_once(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> $DIR/eta.rs:324:26 + --> $DIR/eta.rs:323:26 | LL | move || takes_fn_mut(|| f_used_once()) | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once` error: redundant closure - --> $DIR/eta.rs:336:19 + --> $DIR/eta.rs:335:19 | LL | array_opt.map(|a| a.as_slice()); | ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice` error: redundant closure - --> $DIR/eta.rs:339:19 + --> $DIR/eta.rs:338:19 | LL | slice_opt.map(|s| s.len()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len` error: redundant closure - --> $DIR/eta.rs:342:17 + --> $DIR/eta.rs:341:17 | LL | ptr_opt.map(|p| p.is_null()); | ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null` error: redundant closure - --> $DIR/eta.rs:346:17 + --> $DIR/eta.rs:345:17 | LL | dyn_opt.map(|d| d.method_on_dyn()); | ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `::method_on_dyn` error: redundant closure - --> $DIR/eta.rs:389:19 + --> $DIR/eta.rs:388:19 | LL | let _ = f(&0, |x, y| f2(x, y)); | ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2` diff --git a/tests/ui/excessive_precision.fixed b/tests/ui/excessive_precision.fixed index 7bb4da453c1cb..cc5531035309b 100644 --- a/tests/ui/excessive_precision.fixed +++ b/tests/ui/excessive_precision.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::excessive_precision)] #![allow( dead_code, diff --git a/tests/ui/excessive_precision.rs b/tests/ui/excessive_precision.rs index e8d6ab6870a4e..fff986a8296ce 100644 --- a/tests/ui/excessive_precision.rs +++ b/tests/ui/excessive_precision.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::excessive_precision)] #![allow( dead_code, diff --git a/tests/ui/excessive_precision.stderr b/tests/ui/excessive_precision.stderr index 348ad183d7d7f..a1f874e93d44b 100644 --- a/tests/ui/excessive_precision.stderr +++ b/tests/ui/excessive_precision.stderr @@ -1,5 +1,5 @@ error: float has excessive precision - --> $DIR/excessive_precision.rs:21:26 + --> $DIR/excessive_precision.rs:20:26 | LL | const BAD32_1: f32 = 0.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79_f32` @@ -7,85 +7,85 @@ LL | const BAD32_1: f32 = 0.123_456_789_f32; = note: `-D clippy::excessive-precision` implied by `-D warnings` error: float has excessive precision - --> $DIR/excessive_precision.rs:22:26 + --> $DIR/excessive_precision.rs:21:26 | LL | const BAD32_2: f32 = 0.123_456_789; | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79` error: float has excessive precision - --> $DIR/excessive_precision.rs:23:26 + --> $DIR/excessive_precision.rs:22:26 | LL | const BAD32_3: f32 = 0.100_000_000_000_1; | ^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1` error: float has excessive precision - --> $DIR/excessive_precision.rs:24:29 + --> $DIR/excessive_precision.rs:23:29 | LL | const BAD32_EDGE: f32 = 1.000_000_9; | ^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.000_001` error: float has excessive precision - --> $DIR/excessive_precision.rs:28:26 + --> $DIR/excessive_precision.rs:27:26 | LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1` error: float has excessive precision - --> $DIR/excessive_precision.rs:31:22 + --> $DIR/excessive_precision.rs:30:22 | LL | println!("{:?}", 8.888_888_888_888_888_888_888); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `8.888_888_888_888_89` error: float has excessive precision - --> $DIR/excessive_precision.rs:42:22 + --> $DIR/excessive_precision.rs:41:22 | LL | let bad32: f32 = 1.123_456_789; | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8` error: float has excessive precision - --> $DIR/excessive_precision.rs:43:26 + --> $DIR/excessive_precision.rs:42:26 | LL | let bad32_suf: f32 = 1.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32` error: float has excessive precision - --> $DIR/excessive_precision.rs:44:21 + --> $DIR/excessive_precision.rs:43:21 | LL | let bad32_inf = 1.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32` error: float has excessive precision - --> $DIR/excessive_precision.rs:54:36 + --> $DIR/excessive_precision.rs:53:36 | LL | let bad_vec32: Vec = vec![0.123_456_789]; | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79` error: float has excessive precision - --> $DIR/excessive_precision.rs:55:36 + --> $DIR/excessive_precision.rs:54:36 | LL | let bad_vec64: Vec = vec![0.123_456_789_123_456_789]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_123_456_78` error: float has excessive precision - --> $DIR/excessive_precision.rs:59:24 + --> $DIR/excessive_precision.rs:58:24 | LL | let bad_e32: f32 = 1.123_456_788_888e-10; | ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8e-10` error: float has excessive precision - --> $DIR/excessive_precision.rs:62:27 + --> $DIR/excessive_precision.rs:61:27 | LL | let bad_bige32: f32 = 1.123_456_788_888E-10; | ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10` error: float has excessive precision - --> $DIR/excessive_precision.rs:71:13 + --> $DIR/excessive_precision.rs:70:13 | LL | let _ = 2.225_073_858_507_201_1e-308_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64` error: float has excessive precision - --> $DIR/excessive_precision.rs:74:13 + --> $DIR/excessive_precision.rs:73:13 | LL | let _ = 1.000_000_000_000_001e-324_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64` diff --git a/tests/ui/exhaustive_items.fixed b/tests/ui/exhaustive_items.fixed index 6c7b1cab6f20a..1bf33a5f2f13c 100644 --- a/tests/ui/exhaustive_items.fixed +++ b/tests/ui/exhaustive_items.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] #![allow(unused)] diff --git a/tests/ui/exhaustive_items.rs b/tests/ui/exhaustive_items.rs index d205bac2d2aba..1328791e186d9 100644 --- a/tests/ui/exhaustive_items.rs +++ b/tests/ui/exhaustive_items.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] #![allow(unused)] diff --git a/tests/ui/exhaustive_items.stderr b/tests/ui/exhaustive_items.stderr index f46ebd477b8f2..ae43e81c0d31f 100644 --- a/tests/ui/exhaustive_items.stderr +++ b/tests/ui/exhaustive_items.stderr @@ -1,5 +1,5 @@ error: exported enums should not be exhaustive - --> $DIR/exhaustive_items.rs:11:5 + --> $DIR/exhaustive_items.rs:9:5 | LL | / pub enum Exhaustive { LL | | Foo, @@ -10,7 +10,7 @@ LL | | } | |_____^ | note: the lint level is defined here - --> $DIR/exhaustive_items.rs:3:9 + --> $DIR/exhaustive_items.rs:1:9 | LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL ~ pub enum Exhaustive { | error: exported enums should not be exhaustive - --> $DIR/exhaustive_items.rs:20:5 + --> $DIR/exhaustive_items.rs:18:5 | LL | / pub enum ExhaustiveWithAttrs { LL | | Foo, @@ -38,7 +38,7 @@ LL ~ pub enum ExhaustiveWithAttrs { | error: exported structs should not be exhaustive - --> $DIR/exhaustive_items.rs:55:5 + --> $DIR/exhaustive_items.rs:53:5 | LL | / pub struct Exhaustive { LL | | pub foo: u8, @@ -47,7 +47,7 @@ LL | | } | |_____^ | note: the lint level is defined here - --> $DIR/exhaustive_items.rs:3:35 + --> $DIR/exhaustive_items.rs:1:35 | LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/expect_fun_call.fixed b/tests/ui/expect_fun_call.fixed index 73c6c97de84b1..6ac3c43ad2982 100644 --- a/tests/ui/expect_fun_call.fixed +++ b/tests/ui/expect_fun_call.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::expect_fun_call)] #![allow( clippy::to_string_in_format_args, diff --git a/tests/ui/expect_fun_call.rs b/tests/ui/expect_fun_call.rs index a786138631c8d..22ea2db504fa4 100644 --- a/tests/ui/expect_fun_call.rs +++ b/tests/ui/expect_fun_call.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::expect_fun_call)] #![allow( clippy::to_string_in_format_args, diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr index a621f681d9810..b5ab580ad000f 100644 --- a/tests/ui/expect_fun_call.stderr +++ b/tests/ui/expect_fun_call.stderr @@ -1,5 +1,5 @@ error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:38:26 + --> $DIR/expect_fun_call.rs:37:26 | LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` @@ -7,85 +7,85 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code = note: `-D clippy::expect-fun-call` implied by `-D warnings` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:41:26 + --> $DIR/expect_fun_call.rs:40:26 | LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:44:37 + --> $DIR/expect_fun_call.rs:43:37 | LL | with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", one!()))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:54:25 + --> $DIR/expect_fun_call.rs:53:25 | LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:57:25 + --> $DIR/expect_fun_call.rs:56:25 | LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:69:17 + --> $DIR/expect_fun_call.rs:68:17 | LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{} {}", 1, 2))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:90:21 + --> $DIR/expect_fun_call.rs:89:21 | LL | Some("foo").expect(&get_string()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:91:21 + --> $DIR/expect_fun_call.rs:90:21 | LL | Some("foo").expect(get_string().as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:92:21 + --> $DIR/expect_fun_call.rs:91:21 | LL | Some("foo").expect(get_string().as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:94:21 + --> $DIR/expect_fun_call.rs:93:21 | LL | Some("foo").expect(get_static_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_static_str()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:95:21 + --> $DIR/expect_fun_call.rs:94:21 | LL | Some("foo").expect(get_non_static_str(&0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:99:16 + --> $DIR/expect_fun_call.rs:98:16 | LL | Some(true).expect(&format!("key {}, {}", 1, 2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:105:17 + --> $DIR/expect_fun_call.rs:104:17 | LL | opt_ref.expect(&format!("{:?}", opt_ref)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{:?}", opt_ref))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:109:20 + --> $DIR/expect_fun_call.rs:108:20 | LL | format_capture.expect(&format!("{error_code}")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}"))` error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:112:30 + --> $DIR/expect_fun_call.rs:111:30 | LL | format_capture_and_value.expect(&format!("{error_code}, {}", 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}, {}", 1))` diff --git a/tests/ui/explicit_auto_deref.fixed b/tests/ui/explicit_auto_deref.fixed index 71a5ed96d5c46..86bee11eb8774 100644 --- a/tests/ui/explicit_auto_deref.fixed +++ b/tests/ui/explicit_auto_deref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(closure_lifetime_binder)] #![warn(clippy::explicit_auto_deref)] #![allow( diff --git a/tests/ui/explicit_auto_deref.rs b/tests/ui/explicit_auto_deref.rs index 9d0cafa150f6c..7a505bdf558c3 100644 --- a/tests/ui/explicit_auto_deref.rs +++ b/tests/ui/explicit_auto_deref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(closure_lifetime_binder)] #![warn(clippy::explicit_auto_deref)] #![allow( diff --git a/tests/ui/explicit_auto_deref.stderr b/tests/ui/explicit_auto_deref.stderr index afc311e3f7cdd..34ce188530c31 100644 --- a/tests/ui/explicit_auto_deref.stderr +++ b/tests/ui/explicit_auto_deref.stderr @@ -1,5 +1,5 @@ error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:70:19 + --> $DIR/explicit_auto_deref.rs:68:19 | LL | let _: &str = &*s; | ^^^ help: try: `&s` @@ -7,229 +7,229 @@ LL | let _: &str = &*s; = note: `-D clippy::explicit-auto-deref` implied by `-D warnings` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:71:19 + --> $DIR/explicit_auto_deref.rs:69:19 | LL | let _: &str = &*{ String::new() }; | ^^^^^^^^^^^^^^^^^^^ help: try: `&{ String::new() }` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:72:19 + --> $DIR/explicit_auto_deref.rs:70:19 | LL | let _: &str = &mut *{ String::new() }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut { String::new() }` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:76:11 + --> $DIR/explicit_auto_deref.rs:74:11 | LL | f_str(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:80:13 + --> $DIR/explicit_auto_deref.rs:78:13 | LL | f_str_t(&*s, &*s); // Don't lint second param. | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:83:24 + --> $DIR/explicit_auto_deref.rs:81:24 | LL | let _: &Box = &**b; | ^^^^ help: try: `&b` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:89:7 + --> $DIR/explicit_auto_deref.rs:87:7 | LL | c(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:95:9 + --> $DIR/explicit_auto_deref.rs:93:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:99:11 + --> $DIR/explicit_auto_deref.rs:97:11 | LL | { &**x } | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:103:9 + --> $DIR/explicit_auto_deref.rs:101:9 | LL | &**{ x } | ^^^^^^^^ help: try: `{ x }` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:107:9 + --> $DIR/explicit_auto_deref.rs:105:9 | LL | &***x | ^^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:124:12 + --> $DIR/explicit_auto_deref.rs:122:12 | LL | f1(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:125:12 + --> $DIR/explicit_auto_deref.rs:123:12 | LL | f2(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:126:12 + --> $DIR/explicit_auto_deref.rs:124:12 | LL | f3(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:127:27 + --> $DIR/explicit_auto_deref.rs:125:27 | LL | f4.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:128:12 + --> $DIR/explicit_auto_deref.rs:126:12 | LL | f5(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:129:12 + --> $DIR/explicit_auto_deref.rs:127:12 | LL | f6(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:130:27 + --> $DIR/explicit_auto_deref.rs:128:27 | LL | f7.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:131:25 + --> $DIR/explicit_auto_deref.rs:129:25 | LL | f8.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:132:12 + --> $DIR/explicit_auto_deref.rs:130:12 | LL | f9(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:133:13 + --> $DIR/explicit_auto_deref.rs:131:13 | LL | f10(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:134:26 + --> $DIR/explicit_auto_deref.rs:132:26 | LL | f11.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:138:16 + --> $DIR/explicit_auto_deref.rs:136:16 | LL | let _ = S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:143:21 + --> $DIR/explicit_auto_deref.rs:141:21 | LL | let _ = S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:159:30 + --> $DIR/explicit_auto_deref.rs:157:30 | LL | let _ = Self::S1(&**s); | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:160:35 + --> $DIR/explicit_auto_deref.rs:158:35 | LL | let _ = Self::S2 { s: &**s }; | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:163:20 + --> $DIR/explicit_auto_deref.rs:161:20 | LL | let _ = E1::S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:164:25 + --> $DIR/explicit_auto_deref.rs:162:25 | LL | let _ = E1::S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:182:13 + --> $DIR/explicit_auto_deref.rs:180:13 | LL | let _ = (*b).foo; | ^^^^ help: try: `b` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:183:13 + --> $DIR/explicit_auto_deref.rs:181:13 | LL | let _ = (**b).foo; | ^^^^^ help: try: `b` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:198:19 + --> $DIR/explicit_auto_deref.rs:196:19 | LL | let _ = f_str(*ref_str); | ^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:200:19 + --> $DIR/explicit_auto_deref.rs:198:19 | LL | let _ = f_str(**ref_ref_str); | ^^^^^^^^^^^^^ help: try: `ref_ref_str` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:210:13 + --> $DIR/explicit_auto_deref.rs:208:13 | LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references | ^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:211:12 + --> $DIR/explicit_auto_deref.rs:209:12 | LL | f_str(&&**ref_str); // `needless_borrow` will suggest removing only one reference | ^^^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:220:41 + --> $DIR/explicit_auto_deref.rs:218:41 | LL | let _ = || -> &'static str { return *s }; | ^^ help: try: `s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:239:9 + --> $DIR/explicit_auto_deref.rs:237:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:262:8 + --> $DIR/explicit_auto_deref.rs:260:8 | LL | c1(*x); | ^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:265:20 + --> $DIR/explicit_auto_deref.rs:263:20 | LL | return *x; | ^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:267:9 + --> $DIR/explicit_auto_deref.rs:265:9 | LL | *x | ^^ help: try: `x` diff --git a/tests/ui/explicit_counter_loop.rs b/tests/ui/explicit_counter_loop.rs index e02b8f62b3dd0..15dc9669efa96 100644 --- a/tests/ui/explicit_counter_loop.rs +++ b/tests/ui/explicit_counter_loop.rs @@ -1,6 +1,6 @@ #![warn(clippy::explicit_counter_loop)] #![allow(clippy::uninlined_format_args, clippy::useless_vec)] - +//@no-rustfix fn main() { let mut vec = vec![1, 2, 3, 4]; let mut _index = 0; diff --git a/tests/ui/explicit_deref_methods.fixed b/tests/ui/explicit_deref_methods.fixed index 4c0b0d8f275e0..7b2dd2fe6eb82 100644 --- a/tests/ui/explicit_deref_methods.fixed +++ b/tests/ui/explicit_deref_methods.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_deref_methods)] #![allow(unused_variables, unused_must_use)] #![allow( diff --git a/tests/ui/explicit_deref_methods.rs b/tests/ui/explicit_deref_methods.rs index bc5da35e52e3f..eb52cfb0d8577 100644 --- a/tests/ui/explicit_deref_methods.rs +++ b/tests/ui/explicit_deref_methods.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_deref_methods)] #![allow(unused_variables, unused_must_use)] #![allow( diff --git a/tests/ui/explicit_deref_methods.stderr b/tests/ui/explicit_deref_methods.stderr index e4d2fe3a1c3d5..362e559b21a57 100644 --- a/tests/ui/explicit_deref_methods.stderr +++ b/tests/ui/explicit_deref_methods.stderr @@ -1,5 +1,5 @@ error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:55:19 + --> $DIR/explicit_deref_methods.rs:54:19 | LL | let b: &str = a.deref(); | ^^^^^^^^^ help: try: `&*a` @@ -7,67 +7,67 @@ LL | let b: &str = a.deref(); = note: `-D clippy::explicit-deref-methods` implied by `-D warnings` error: explicit `deref_mut` method call - --> $DIR/explicit_deref_methods.rs:57:23 + --> $DIR/explicit_deref_methods.rs:56:23 | LL | let b: &mut str = a.deref_mut(); | ^^^^^^^^^^^^^ help: try: `&mut **a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:60:39 + --> $DIR/explicit_deref_methods.rs:59:39 | LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:60:50 + --> $DIR/explicit_deref_methods.rs:59:50 | LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:62:20 + --> $DIR/explicit_deref_methods.rs:61:20 | LL | println!("{}", a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:65:11 + --> $DIR/explicit_deref_methods.rs:64:11 | LL | match a.deref() { | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:69:28 + --> $DIR/explicit_deref_methods.rs:68:28 | LL | let b: String = concat(a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:71:13 + --> $DIR/explicit_deref_methods.rs:70:13 | LL | let b = just_return(a).deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:73:28 + --> $DIR/explicit_deref_methods.rs:72:28 | LL | let b: String = concat(just_return(a).deref()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:75:19 + --> $DIR/explicit_deref_methods.rs:74:19 | LL | let b: &str = a.deref().deref(); | ^^^^^^^^^^^^^^^^^ help: try: `&**a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:78:13 + --> $DIR/explicit_deref_methods.rs:77:13 | LL | let b = opt_a.unwrap().deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*opt_a.unwrap()` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:115:31 + --> $DIR/explicit_deref_methods.rs:114:31 | LL | let b: &str = expr_deref!(a.deref()); | ^^^^^^^^^ help: try: `&*a` diff --git a/tests/ui/explicit_into_iter_loop.fixed b/tests/ui/explicit_into_iter_loop.fixed index dcef634031143..2521bce6a58e1 100644 --- a/tests/ui/explicit_into_iter_loop.fixed +++ b/tests/ui/explicit_into_iter_loop.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_into_iter_loop)] fn main() { diff --git a/tests/ui/explicit_into_iter_loop.rs b/tests/ui/explicit_into_iter_loop.rs index bc048ed302bff..9eac96d182b9f 100644 --- a/tests/ui/explicit_into_iter_loop.rs +++ b/tests/ui/explicit_into_iter_loop.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_into_iter_loop)] fn main() { diff --git a/tests/ui/explicit_into_iter_loop.stderr b/tests/ui/explicit_into_iter_loop.stderr index fa89b884fa0fc..744be093b7b84 100644 --- a/tests/ui/explicit_into_iter_loop.stderr +++ b/tests/ui/explicit_into_iter_loop.stderr @@ -1,5 +1,5 @@ error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:10:18 + --> $DIR/explicit_into_iter_loop.rs:9:18 | LL | for _ in iterator.into_iter() {} | ^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `iterator` @@ -7,31 +7,31 @@ LL | for _ in iterator.into_iter() {} = note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:23:14 + --> $DIR/explicit_into_iter_loop.rs:22:14 | LL | for _ in t.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `&t` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:26:14 + --> $DIR/explicit_into_iter_loop.rs:25:14 | LL | for _ in r.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `r` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:34:14 + --> $DIR/explicit_into_iter_loop.rs:33:14 | LL | for _ in mr.into_iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&*mr` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:46:14 + --> $DIR/explicit_into_iter_loop.rs:45:14 | LL | for _ in u.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut u` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:49:14 + --> $DIR/explicit_into_iter_loop.rs:48:14 | LL | for _ in mr.into_iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *mr` diff --git a/tests/ui/explicit_iter_loop.fixed b/tests/ui/explicit_iter_loop.fixed index 746ef813c0481..57292114e3882 100644 --- a/tests/ui/explicit_iter_loop.fixed +++ b/tests/ui/explicit_iter_loop.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::explicit_iter_loop)] #![allow( clippy::linkedlist, diff --git a/tests/ui/explicit_iter_loop.rs b/tests/ui/explicit_iter_loop.rs index fba230ee0eeaa..66280c23843d2 100644 --- a/tests/ui/explicit_iter_loop.rs +++ b/tests/ui/explicit_iter_loop.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::explicit_iter_loop)] #![allow( clippy::linkedlist, diff --git a/tests/ui/explicit_iter_loop.stderr b/tests/ui/explicit_iter_loop.stderr index 94a264dcea8d5..c311096117f60 100644 --- a/tests/ui/explicit_iter_loop.stderr +++ b/tests/ui/explicit_iter_loop.stderr @@ -1,53 +1,53 @@ error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:17:14 + --> $DIR/explicit_iter_loop.rs:16:14 | LL | for _ in vec.iter() {} | ^^^^^^^^^^ help: to write this more concisely, try: `&vec` | note: the lint level is defined here - --> $DIR/explicit_iter_loop.rs:2:9 + --> $DIR/explicit_iter_loop.rs:1:9 | LL | #![deny(clippy::explicit_iter_loop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:18:14 + --> $DIR/explicit_iter_loop.rs:17:14 | LL | for _ in vec.iter_mut() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:21:14 + --> $DIR/explicit_iter_loop.rs:20:14 | LL | for _ in rvec.iter() {} | ^^^^^^^^^^^ help: to write this more concisely, try: `rvec` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:24:14 + --> $DIR/explicit_iter_loop.rs:23:14 | LL | for _ in rmvec.iter() {} | ^^^^^^^^^^^^ help: to write this more concisely, try: `&*rmvec` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:25:14 + --> $DIR/explicit_iter_loop.rs:24:14 | LL | for _ in rmvec.iter_mut() {} | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *rmvec` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:30:14 + --> $DIR/explicit_iter_loop.rs:29:14 | LL | for _ in [1, 2, 3].iter() {} | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:32:14 + --> $DIR/explicit_iter_loop.rs:31:14 | LL | for _ in (&mut [1, 2, 3]).iter() {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&*(&mut [1, 2, 3])` error: the method `iter` doesn't need a mutable reference - --> $DIR/explicit_iter_loop.rs:32:14 + --> $DIR/explicit_iter_loop.rs:31:14 | LL | for _ in (&mut [1, 2, 3]).iter() {} | ^^^^^^^^^^^^^^^^ @@ -55,85 +55,85 @@ LL | for _ in (&mut [1, 2, 3]).iter() {} = note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:34:14 + --> $DIR/explicit_iter_loop.rs:33:14 | LL | for _ in [0; 32].iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:35:14 + --> $DIR/explicit_iter_loop.rs:34:14 | LL | for _ in [0; 33].iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 33]` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:38:14 + --> $DIR/explicit_iter_loop.rs:37:14 | LL | for _ in ll.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&ll` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:40:14 + --> $DIR/explicit_iter_loop.rs:39:14 | LL | for _ in rll.iter() {} | ^^^^^^^^^^ help: to write this more concisely, try: `rll` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:43:14 + --> $DIR/explicit_iter_loop.rs:42:14 | LL | for _ in vd.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&vd` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:45:14 + --> $DIR/explicit_iter_loop.rs:44:14 | LL | for _ in rvd.iter() {} | ^^^^^^^^^^ help: to write this more concisely, try: `rvd` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:48:14 + --> $DIR/explicit_iter_loop.rs:47:14 | LL | for _ in bh.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bh` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:51:14 + --> $DIR/explicit_iter_loop.rs:50:14 | LL | for _ in hm.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&hm` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:54:14 + --> $DIR/explicit_iter_loop.rs:53:14 | LL | for _ in bt.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bt` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:57:14 + --> $DIR/explicit_iter_loop.rs:56:14 | LL | for _ in hs.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&hs` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:60:14 + --> $DIR/explicit_iter_loop.rs:59:14 | LL | for _ in bs.iter() {} | ^^^^^^^^^ help: to write this more concisely, try: `&bs` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:149:14 + --> $DIR/explicit_iter_loop.rs:148:14 | LL | for _ in x.iter() {} | ^^^^^^^^ help: to write this more concisely, try: `&x` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:150:14 + --> $DIR/explicit_iter_loop.rs:149:14 | LL | for _ in x.iter_mut() {} | ^^^^^^^^^^^^ help: to write this more concisely, try: `&mut x` error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:153:14 + --> $DIR/explicit_iter_loop.rs:152:14 | LL | for _ in r.iter() {} | ^^^^^^^^ help: to write this more concisely, try: `r` diff --git a/tests/ui/explicit_write.fixed b/tests/ui/explicit_write.fixed index 213485bc221b8..77a910dc1963a 100644 --- a/tests/ui/explicit_write.fixed +++ b/tests/ui/explicit_write.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_write)] #![allow(unused_imports)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/explicit_write.rs b/tests/ui/explicit_write.rs index 64acd7108bfa8..c77956264f6db 100644 --- a/tests/ui/explicit_write.rs +++ b/tests/ui/explicit_write.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_write)] #![allow(unused_imports)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/explicit_write.stderr b/tests/ui/explicit_write.stderr index b3aa7274c6d00..fa7751d920d9a 100644 --- a/tests/ui/explicit_write.stderr +++ b/tests/ui/explicit_write.stderr @@ -1,5 +1,5 @@ error: use of `write!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:24:9 + --> $DIR/explicit_write.rs:23:9 | LL | write!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `print!("test")` @@ -7,73 +7,73 @@ LL | write!(std::io::stdout(), "test").unwrap(); = note: `-D clippy::explicit-write` implied by `-D warnings` error: use of `write!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:25:9 + --> $DIR/explicit_write.rs:24:9 | LL | write!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprint!("test")` error: use of `writeln!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:26:9 + --> $DIR/explicit_write.rs:25:9 | LL | writeln!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:27:9 + --> $DIR/explicit_write.rs:26:9 | LL | writeln!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test")` error: use of `stdout().write_fmt(...).unwrap()` - --> $DIR/explicit_write.rs:28:9 + --> $DIR/explicit_write.rs:27:9 | LL | std::io::stdout().write_fmt(format_args!("test")).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `print!("test")` error: use of `stderr().write_fmt(...).unwrap()` - --> $DIR/explicit_write.rs:29:9 + --> $DIR/explicit_write.rs:28:9 | LL | std::io::stderr().write_fmt(format_args!("test")).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprint!("test")` error: use of `writeln!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:32:9 + --> $DIR/explicit_write.rs:31:9 | LL | writeln!(std::io::stdout(), "test/ntest").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test/ntest")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:33:9 + --> $DIR/explicit_write.rs:32:9 | LL | writeln!(std::io::stderr(), "test/ntest").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test/ntest")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:36:9 + --> $DIR/explicit_write.rs:35:9 | LL | writeln!(std::io::stderr(), "with {}", value).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {}", value)` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:37:9 + --> $DIR/explicit_write.rs:36:9 | LL | writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {} {}", 2, value)` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:38:9 + --> $DIR/explicit_write.rs:37:9 | LL | writeln!(std::io::stderr(), "with {value}").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {value}")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:39:9 + --> $DIR/explicit_write.rs:38:9 | LL | writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("macro arg {}", one!())` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:41:9 + --> $DIR/explicit_write.rs:40:9 | LL | writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("{:w$}", value, w = width)` diff --git a/tests/ui/extend_with_drain.fixed b/tests/ui/extend_with_drain.fixed index 594f2f6d4135e..856c1a42dafcd 100644 --- a/tests/ui/extend_with_drain.fixed +++ b/tests/ui/extend_with_drain.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::extend_with_drain)] #![allow(clippy::iter_with_drain)] use std::collections::BinaryHeap; diff --git a/tests/ui/extend_with_drain.rs b/tests/ui/extend_with_drain.rs index 3e2ad02052d78..7d538097639f5 100644 --- a/tests/ui/extend_with_drain.rs +++ b/tests/ui/extend_with_drain.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::extend_with_drain)] #![allow(clippy::iter_with_drain)] use std::collections::BinaryHeap; diff --git a/tests/ui/extend_with_drain.stderr b/tests/ui/extend_with_drain.stderr index eb2dd304d3707..2c06d71e10202 100644 --- a/tests/ui/extend_with_drain.stderr +++ b/tests/ui/extend_with_drain.stderr @@ -1,5 +1,5 @@ error: use of `extend` instead of `append` for adding the full range of a second vector - --> $DIR/extend_with_drain.rs:9:5 + --> $DIR/extend_with_drain.rs:8:5 | LL | vec2.extend(vec1.drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec2.append(&mut vec1)` @@ -7,19 +7,19 @@ LL | vec2.extend(vec1.drain(..)); = note: `-D clippy::extend-with-drain` implied by `-D warnings` error: use of `extend` instead of `append` for adding the full range of a second vector - --> $DIR/extend_with_drain.rs:14:5 + --> $DIR/extend_with_drain.rs:13:5 | LL | vec4.extend(vec3.drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec4.append(&mut vec3)` error: use of `extend` instead of `append` for adding the full range of a second vector - --> $DIR/extend_with_drain.rs:18:5 + --> $DIR/extend_with_drain.rs:17:5 | LL | vec11.extend(return_vector().drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec11.append(&mut return_vector())` error: use of `extend` instead of `append` for adding the full range of a second vector - --> $DIR/extend_with_drain.rs:49:5 + --> $DIR/extend_with_drain.rs:48:5 | LL | y.extend(ref_x.drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `y.append(ref_x)` diff --git a/tests/ui/extra_unused_type_parameters.fixed b/tests/ui/extra_unused_type_parameters.fixed index 8420df6634d90..3de027d77e424 100644 --- a/tests/ui/extra_unused_type_parameters.fixed +++ b/tests/ui/extra_unused_type_parameters.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(unused, clippy::needless_lifetimes)] diff --git a/tests/ui/extra_unused_type_parameters.rs b/tests/ui/extra_unused_type_parameters.rs index f63535d7ae6ee..14aa55d5314de 100644 --- a/tests/ui/extra_unused_type_parameters.rs +++ b/tests/ui/extra_unused_type_parameters.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(unused, clippy::needless_lifetimes)] diff --git a/tests/ui/extra_unused_type_parameters.stderr b/tests/ui/extra_unused_type_parameters.stderr index b5277d49861c9..82cdc95a1d15f 100644 --- a/tests/ui/extra_unused_type_parameters.stderr +++ b/tests/ui/extra_unused_type_parameters.stderr @@ -1,5 +1,5 @@ error: type parameter `T` goes unused in function definition - --> $DIR/extra_unused_type_parameters.rs:10:13 + --> $DIR/extra_unused_type_parameters.rs:9:13 | LL | fn unused_ty(x: u8) { | ^^^ help: consider removing the parameter @@ -7,19 +7,19 @@ LL | fn unused_ty(x: u8) { = note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings` error: type parameters go unused in function definition: T, U - --> $DIR/extra_unused_type_parameters.rs:14:16 + --> $DIR/extra_unused_type_parameters.rs:13:16 | LL | fn unused_multi(x: u8) { | ^^^^^^ help: consider removing the parameters error: type parameter `T` goes unused in function definition - --> $DIR/extra_unused_type_parameters.rs:18:21 + --> $DIR/extra_unused_type_parameters.rs:17:21 | LL | fn unused_with_lt<'a, T>(x: &'a u8) { | ^^^ help: consider removing the parameter error: type parameters go unused in function definition: T, V - --> $DIR/extra_unused_type_parameters.rs:30:19 + --> $DIR/extra_unused_type_parameters.rs:29:19 | LL | fn unused_bounded(x: U) { | ^^^^^^^^^^^^ ^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL + fn unused_bounded(x: U) { | error: type parameters go unused in function definition: A, D, E - --> $DIR/extra_unused_type_parameters.rs:34:16 + --> $DIR/extra_unused_type_parameters.rs:33:16 | LL | fn some_unused, E>(b: B, c: C) { | ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,19 +43,19 @@ LL + fn some_unused(b: B, c: C) { | error: type parameter `T` goes unused in function definition - --> $DIR/extra_unused_type_parameters.rs:59:22 + --> $DIR/extra_unused_type_parameters.rs:58:22 | LL | fn unused_ty_impl(&self) { | ^^^ help: consider removing the parameter error: type parameters go unused in function definition: A, B - --> $DIR/extra_unused_type_parameters.rs:81:17 + --> $DIR/extra_unused_type_parameters.rs:80:17 | LL | fn unused_opaque(dummy: impl Default) { | ^^^^^^ help: consider removing the parameters error: type parameter `U` goes unused in function definition - --> $DIR/extra_unused_type_parameters.rs:94:56 + --> $DIR/extra_unused_type_parameters.rs:93:56 | LL | fn unused_with_priv_trait_bound() { | ^^^ help: consider removing the parameter diff --git a/tests/ui/filter_map_bool_then.fixed b/tests/ui/filter_map_bool_then.fixed index e5c9f783f6b32..99188e07e45ee 100644 --- a/tests/ui/filter_map_bool_then.fixed +++ b/tests/ui/filter_map_bool_then.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow( clippy::clone_on_copy, diff --git a/tests/ui/filter_map_bool_then.rs b/tests/ui/filter_map_bool_then.rs index 7c9b99df78cbb..78b7daa1089ce 100644 --- a/tests/ui/filter_map_bool_then.rs +++ b/tests/ui/filter_map_bool_then.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow( clippy::clone_on_copy, diff --git a/tests/ui/filter_map_bool_then.stderr b/tests/ui/filter_map_bool_then.stderr index fffa5252e5f6c..c4215791c46fb 100644 --- a/tests/ui/filter_map_bool_then.stderr +++ b/tests/ui/filter_map_bool_then.stderr @@ -1,5 +1,5 @@ error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:20:22 + --> $DIR/filter_map_bool_then.rs:19:22 | LL | v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` @@ -7,31 +7,31 @@ LL | v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); = note: `-D clippy::filter-map-bool-then` implied by `-D warnings` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:21:27 + --> $DIR/filter_map_bool_then.rs:20:27 | LL | v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:24:10 + --> $DIR/filter_map_bool_then.rs:23:10 | LL | .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:28:10 + --> $DIR/filter_map_bool_then.rs:27:10 | LL | .filter_map(|i| (i % 2 == 0).then(|| i + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:32:10 + --> $DIR/filter_map_bool_then.rs:31:10 | LL | .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1)` error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:38:22 + --> $DIR/filter_map_bool_then.rs:37:22 | LL | v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i == &NonCopy)).map(|i| i)` diff --git a/tests/ui/filter_map_identity.fixed b/tests/ui/filter_map_identity.fixed index 44665b451adac..ad438afaca779 100644 --- a/tests/ui/filter_map_identity.fixed +++ b/tests/ui/filter_map_identity.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports, clippy::needless_return)] #![warn(clippy::filter_map_identity)] diff --git a/tests/ui/filter_map_identity.rs b/tests/ui/filter_map_identity.rs index 9832acb013f85..d7423276872ac 100644 --- a/tests/ui/filter_map_identity.rs +++ b/tests/ui/filter_map_identity.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports, clippy::needless_return)] #![warn(clippy::filter_map_identity)] diff --git a/tests/ui/filter_map_identity.stderr b/tests/ui/filter_map_identity.stderr index 43c9fdca4fbe0..248f6318f76ab 100644 --- a/tests/ui/filter_map_identity.stderr +++ b/tests/ui/filter_map_identity.stderr @@ -1,5 +1,5 @@ error: use of `filter_map` with an identity function - --> $DIR/filter_map_identity.rs:8:22 + --> $DIR/filter_map_identity.rs:6:22 | LL | let _ = iterator.filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` @@ -7,19 +7,19 @@ LL | let _ = iterator.filter_map(|x| x); = note: `-D clippy::filter-map-identity` implied by `-D warnings` error: use of `filter_map` with an identity function - --> $DIR/filter_map_identity.rs:11:22 + --> $DIR/filter_map_identity.rs:9:22 | LL | let _ = iterator.filter_map(std::convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> $DIR/filter_map_identity.rs:15:22 + --> $DIR/filter_map_identity.rs:13:22 | LL | let _ = iterator.filter_map(identity); | ^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> $DIR/filter_map_identity.rs:18:22 + --> $DIR/filter_map_identity.rs:16:22 | LL | let _ = iterator.filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` diff --git a/tests/ui/filter_map_next_fixable.fixed b/tests/ui/filter_map_next_fixable.fixed index efb37f8b1b73c..193ac3aea433f 100644 --- a/tests/ui/filter_map_next_fixable.fixed +++ b/tests/ui/filter_map_next_fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all, clippy::pedantic)] #![allow(unused)] diff --git a/tests/ui/filter_map_next_fixable.rs b/tests/ui/filter_map_next_fixable.rs index b10e20d359ed7..dab8d289817e8 100644 --- a/tests/ui/filter_map_next_fixable.rs +++ b/tests/ui/filter_map_next_fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all, clippy::pedantic)] #![allow(unused)] diff --git a/tests/ui/filter_map_next_fixable.stderr b/tests/ui/filter_map_next_fixable.stderr index 26d9c5e19da7f..fcbdbc31f3533 100644 --- a/tests/ui/filter_map_next_fixable.stderr +++ b/tests/ui/filter_map_next_fixable.stderr @@ -1,5 +1,5 @@ error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead - --> $DIR/filter_map_next_fixable.rs:9:32 + --> $DIR/filter_map_next_fixable.rs:7:32 | LL | let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.iter().find_map(|s| s.parse().ok())` @@ -7,7 +7,7 @@ LL | let element: Option = a.iter().filter_map(|s| s.parse().ok()).next = note: `-D clippy::filter-map-next` implied by `-D warnings` error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead - --> $DIR/filter_map_next_fixable.rs:22:26 + --> $DIR/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())` diff --git a/tests/ui/flat_map_identity.fixed b/tests/ui/flat_map_identity.fixed index 97091d6f1a5be..c142cf719808a 100644 --- a/tests/ui/flat_map_identity.fixed +++ b/tests/ui/flat_map_identity.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports, clippy::needless_return)] #![warn(clippy::flat_map_identity)] diff --git a/tests/ui/flat_map_identity.rs b/tests/ui/flat_map_identity.rs index 5607683a5d04e..8505ba9005d37 100644 --- a/tests/ui/flat_map_identity.rs +++ b/tests/ui/flat_map_identity.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports, clippy::needless_return)] #![warn(clippy::flat_map_identity)] diff --git a/tests/ui/flat_map_identity.stderr b/tests/ui/flat_map_identity.stderr index e776c9fdf512e..6e4637874acef 100644 --- a/tests/ui/flat_map_identity.stderr +++ b/tests/ui/flat_map_identity.stderr @@ -1,5 +1,5 @@ error: use of `flat_map` with an identity function - --> $DIR/flat_map_identity.rs:10:22 + --> $DIR/flat_map_identity.rs:8:22 | LL | let _ = iterator.flat_map(|x| x); | ^^^^^^^^^^^^^^^ help: try: `flatten()` @@ -7,13 +7,13 @@ LL | let _ = iterator.flat_map(|x| x); = note: `-D clippy::flat-map-identity` implied by `-D warnings` error: use of `flat_map` with an identity function - --> $DIR/flat_map_identity.rs:13:22 + --> $DIR/flat_map_identity.rs:11:22 | LL | let _ = iterator.flat_map(convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `flat_map` with an identity function - --> $DIR/flat_map_identity.rs:16:22 + --> $DIR/flat_map_identity.rs:14:22 | LL | let _ = iterator.flat_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` diff --git a/tests/ui/flat_map_option.fixed b/tests/ui/flat_map_option.fixed index eeab864c42ff7..e08d9a14533b2 100644 --- a/tests/ui/flat_map_option.fixed +++ b/tests/ui/flat_map_option.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::flat_map_option)] #![allow(clippy::redundant_closure, clippy::unnecessary_filter_map)] diff --git a/tests/ui/flat_map_option.rs b/tests/ui/flat_map_option.rs index ebc389f7f0294..4d0f32ac0fda7 100644 --- a/tests/ui/flat_map_option.rs +++ b/tests/ui/flat_map_option.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::flat_map_option)] #![allow(clippy::redundant_closure, clippy::unnecessary_filter_map)] diff --git a/tests/ui/flat_map_option.stderr b/tests/ui/flat_map_option.stderr index a9d8056dee978..c750902eb2fdb 100644 --- a/tests/ui/flat_map_option.stderr +++ b/tests/ui/flat_map_option.stderr @@ -1,5 +1,5 @@ error: used `flat_map` where `filter_map` could be used instead - --> $DIR/flat_map_option.rs:8:24 + --> $DIR/flat_map_option.rs:7:24 | LL | let _ = [1].iter().flat_map(c); | ^^^^^^^^ help: try: `filter_map` @@ -7,7 +7,7 @@ LL | let _ = [1].iter().flat_map(c); = note: `-D clippy::flat-map-option` implied by `-D warnings` error: used `flat_map` where `filter_map` could be used instead - --> $DIR/flat_map_option.rs:9:24 + --> $DIR/flat_map_option.rs:8:24 | LL | let _ = [1].iter().flat_map(Some); | ^^^^^^^^ help: try: `filter_map` diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index a34458b941951..b0a6a64a18aff 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -6,7 +6,7 @@ clippy::unnecessary_operation, clippy::cast_lossless )] - +//@no-rustfix use std::ops::Add; const ZERO: f32 = 0.0; diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs index 86ce3bf3bd992..1493d4f1d37f3 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -1,5 +1,5 @@ // does not test any rustfixable lints - +//@no-rustfix #![warn(clippy::float_cmp_const)] #![allow(clippy::float_cmp)] #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] diff --git a/tests/ui/float_equality_without_abs.rs b/tests/ui/float_equality_without_abs.rs index d40fa00c31551..4048c3a7855ba 100644 --- a/tests/ui/float_equality_without_abs.rs +++ b/tests/ui/float_equality_without_abs.rs @@ -1,5 +1,5 @@ #![warn(clippy::float_equality_without_abs)] - +//@no-rustfix pub fn is_roughly_equal(a: f32, b: f32) -> bool { (a - b) < f32::EPSILON } diff --git a/tests/ui/floating_point_abs.fixed b/tests/ui/floating_point_abs.fixed index 0cc572822e771..5312a8b29c67a 100644 --- a/tests/ui/floating_point_abs.fixed +++ b/tests/ui/floating_point_abs.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/tests/ui/floating_point_abs.rs b/tests/ui/floating_point_abs.rs index 6c732d398f068..8619177130c9f 100644 --- a/tests/ui/floating_point_abs.rs +++ b/tests/ui/floating_point_abs.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/tests/ui/floating_point_abs.stderr b/tests/ui/floating_point_abs.stderr index db8290423ae05..464a0af5f9f59 100644 --- a/tests/ui/floating_point_abs.stderr +++ b/tests/ui/floating_point_abs.stderr @@ -1,5 +1,5 @@ error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:16:5 + --> $DIR/floating_point_abs.rs:15:5 | LL | if num >= 0.0 { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` @@ -7,43 +7,43 @@ LL | if num >= 0.0 { num } else { -num } = note: `-D clippy::suboptimal-flops` implied by `-D warnings` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:20:5 + --> $DIR/floating_point_abs.rs:19:5 | LL | if 0.0 < num { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:24:5 + --> $DIR/floating_point_abs.rs:23:5 | LL | if a.a > 0.0 { a.a } else { -a.a } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:28:5 + --> $DIR/floating_point_abs.rs:27:5 | LL | if 0.0 >= num { -num } else { num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:32:5 + --> $DIR/floating_point_abs.rs:31:5 | LL | if a.a < 0.0 { -a.a } else { a.a } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()` error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:36:5 + --> $DIR/floating_point_abs.rs:35:5 | LL | if num < 0.0 { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:40:5 + --> $DIR/floating_point_abs.rs:39:5 | LL | if 0.0 >= num { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:45:12 + --> $DIR/floating_point_abs.rs:44:12 | LL | a: if a.a >= 0.0 { -a.a } else { a.a }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()` diff --git a/tests/ui/floating_point_exp.fixed b/tests/ui/floating_point_exp.fixed index 1a33b8153ecab..15072bb1ee9a5 100644 --- a/tests/ui/floating_point_exp.fixed +++ b/tests/ui/floating_point_exp.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_exp.rs b/tests/ui/floating_point_exp.rs index 4f4a5ec81ac9d..7d8b17946d0a5 100644 --- a/tests/ui/floating_point_exp.rs +++ b/tests/ui/floating_point_exp.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_exp.stderr b/tests/ui/floating_point_exp.stderr index b92fae56e421c..f84eede19872a 100644 --- a/tests/ui/floating_point_exp.stderr +++ b/tests/ui/floating_point_exp.stderr @@ -1,5 +1,5 @@ error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:7:13 + --> $DIR/floating_point_exp.rs:6:13 | LL | let _ = x.exp() - 1.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` @@ -7,25 +7,25 @@ LL | let _ = x.exp() - 1.0; = note: `-D clippy::imprecise-flops` implied by `-D warnings` error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:8:13 + --> $DIR/floating_point_exp.rs:7:13 | LL | let _ = x.exp() - 1.0 + 2.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:9:13 + --> $DIR/floating_point_exp.rs:8:13 | LL | let _ = (x as f32).exp() - 1.0 + 2.0; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:15:13 + --> $DIR/floating_point_exp.rs:14:13 | LL | let _ = x.exp() - 1.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:16:13 + --> $DIR/floating_point_exp.rs:15:13 | LL | let _ = x.exp() - 1.0 + 2.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` diff --git a/tests/ui/floating_point_hypot.fixed b/tests/ui/floating_point_hypot.fixed index 431cb2709787a..75a224440b0de 100644 --- a/tests/ui/floating_point_hypot.fixed +++ b/tests/ui/floating_point_hypot.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::imprecise_flops)] fn main() { diff --git a/tests/ui/floating_point_hypot.rs b/tests/ui/floating_point_hypot.rs index e5506ed391c02..ed4dbf6382e71 100644 --- a/tests/ui/floating_point_hypot.rs +++ b/tests/ui/floating_point_hypot.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::imprecise_flops)] fn main() { diff --git a/tests/ui/floating_point_hypot.stderr b/tests/ui/floating_point_hypot.stderr index 42069d9ee9efb..82b0ed31204ce 100644 --- a/tests/ui/floating_point_hypot.stderr +++ b/tests/ui/floating_point_hypot.stderr @@ -1,5 +1,5 @@ error: hypotenuse can be computed more accurately - --> $DIR/floating_point_hypot.rs:7:13 + --> $DIR/floating_point_hypot.rs:6:13 | LL | let _ = (x * x + y * y).sqrt(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` @@ -7,13 +7,13 @@ LL | let _ = (x * x + y * y).sqrt(); = note: `-D clippy::imprecise-flops` implied by `-D warnings` error: hypotenuse can be computed more accurately - --> $DIR/floating_point_hypot.rs:8:13 + --> $DIR/floating_point_hypot.rs:7:13 | LL | let _ = ((x + 1f32) * (x + 1f32) + y * y).sqrt(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 1f32).hypot(y)` error: hypotenuse can be computed more accurately - --> $DIR/floating_point_hypot.rs:9:13 + --> $DIR/floating_point_hypot.rs:8:13 | LL | let _ = (x.powi(2) + y.powi(2)).sqrt(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` diff --git a/tests/ui/floating_point_log.fixed b/tests/ui/floating_point_log.fixed index 6582c0a0f6c87..01f0fc5c671ad 100644 --- a/tests/ui/floating_point_log.fixed +++ b/tests/ui/floating_point_log.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)] #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] diff --git a/tests/ui/floating_point_log.rs b/tests/ui/floating_point_log.rs index 854d269fff59c..197e3e1ff9097 100644 --- a/tests/ui/floating_point_log.rs +++ b/tests/ui/floating_point_log.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)] #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] diff --git a/tests/ui/floating_point_log.stderr b/tests/ui/floating_point_log.stderr index 89800a13a6ecc..cbadd239aa2fb 100644 --- a/tests/ui/floating_point_log.stderr +++ b/tests/ui/floating_point_log.stderr @@ -1,5 +1,5 @@ error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:10:13 + --> $DIR/floating_point_log.rs:9:13 | LL | let _ = x.log(2f32); | ^^^^^^^^^^^ help: consider using: `x.log2()` @@ -7,55 +7,55 @@ LL | let _ = x.log(2f32); = note: `-D clippy::suboptimal-flops` implied by `-D warnings` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:11:13 + --> $DIR/floating_point_log.rs:10:13 | LL | let _ = x.log(10f32); | ^^^^^^^^^^^^ help: consider using: `x.log10()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:12:13 + --> $DIR/floating_point_log.rs:11:13 | LL | let _ = x.log(std::f32::consts::E); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:13:13 + --> $DIR/floating_point_log.rs:12:13 | LL | let _ = x.log(TWO); | ^^^^^^^^^^ help: consider using: `x.log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:14:13 + --> $DIR/floating_point_log.rs:13:13 | LL | let _ = x.log(E); | ^^^^^^^^ help: consider using: `x.ln()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:15:13 + --> $DIR/floating_point_log.rs:14:13 | LL | let _ = (x as f32).log(2f32); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:18:13 + --> $DIR/floating_point_log.rs:17:13 | LL | let _ = x.log(2f64); | ^^^^^^^^^^^ help: consider using: `x.log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:19:13 + --> $DIR/floating_point_log.rs:18:13 | LL | let _ = x.log(10f64); | ^^^^^^^^^^^^ help: consider using: `x.log10()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:20:13 + --> $DIR/floating_point_log.rs:19:13 | LL | let _ = x.log(std::f64::consts::E); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:25:13 + --> $DIR/floating_point_log.rs:24:13 | LL | let _ = (1f32 + 2.).ln(); | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` @@ -63,115 +63,115 @@ LL | let _ = (1f32 + 2.).ln(); = note: `-D clippy::imprecise-flops` implied by `-D warnings` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:26:13 + --> $DIR/floating_point_log.rs:25:13 | LL | let _ = (1f32 + 2.0).ln(); | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:27:13 + --> $DIR/floating_point_log.rs:26:13 | LL | let _ = (1.0 + x).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:28:13 + --> $DIR/floating_point_log.rs:27:13 | LL | let _ = (1.0 + x / 2.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:29:13 + --> $DIR/floating_point_log.rs:28:13 | LL | let _ = (1.0 + x.powi(3)).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:30:13 + --> $DIR/floating_point_log.rs:29:13 | LL | let _ = (1.0 + x.powi(3) / 2.0).ln(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x.powi(3) / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:31:13 + --> $DIR/floating_point_log.rs:30:13 | LL | let _ = (1.0 + (std::f32::consts::E - 1.0)).ln(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(std::f32::consts::E - 1.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:32:13 + --> $DIR/floating_point_log.rs:31:13 | LL | let _ = (x + 1.0).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:33:13 + --> $DIR/floating_point_log.rs:32:13 | LL | let _ = (x.powi(3) + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:34:13 + --> $DIR/floating_point_log.rs:33:13 | LL | let _ = (x + 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:35:13 + --> $DIR/floating_point_log.rs:34:13 | LL | let _ = (x / 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:43:13 + --> $DIR/floating_point_log.rs:42:13 | LL | let _ = (1f64 + 2.).ln(); | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:44:13 + --> $DIR/floating_point_log.rs:43:13 | LL | let _ = (1f64 + 2.0).ln(); | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f64.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:45:13 + --> $DIR/floating_point_log.rs:44:13 | LL | let _ = (1.0 + x).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:46:13 + --> $DIR/floating_point_log.rs:45:13 | LL | let _ = (1.0 + x / 2.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:47:13 + --> $DIR/floating_point_log.rs:46:13 | LL | let _ = (1.0 + x.powi(3)).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:48:13 + --> $DIR/floating_point_log.rs:47:13 | LL | let _ = (x + 1.0).ln(); | ^^^^^^^^^^^^^^ help: consider using: `x.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:49:13 + --> $DIR/floating_point_log.rs:48:13 | LL | let _ = (x.powi(3) + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(3).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:50:13 + --> $DIR/floating_point_log.rs:49:13 | LL | let _ = (x + 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x + 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:51:13 + --> $DIR/floating_point_log.rs:50:13 | LL | let _ = (x / 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` diff --git a/tests/ui/floating_point_logbase.fixed b/tests/ui/floating_point_logbase.fixed index 0783ecee1eec8..451673d109c64 100644 --- a/tests/ui/floating_point_logbase.fixed +++ b/tests/ui/floating_point_logbase.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_logbase.rs b/tests/ui/floating_point_logbase.rs index 80fcfab682525..c309114599d94 100644 --- a/tests/ui/floating_point_logbase.rs +++ b/tests/ui/floating_point_logbase.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_logbase.stderr b/tests/ui/floating_point_logbase.stderr index 9d736b5e1a274..384e3554cbbe1 100644 --- a/tests/ui/floating_point_logbase.stderr +++ b/tests/ui/floating_point_logbase.stderr @@ -1,5 +1,5 @@ error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:8:13 + --> $DIR/floating_point_logbase.rs:7:13 | LL | let _ = x.ln() / y.ln(); | ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` @@ -7,25 +7,25 @@ LL | let _ = x.ln() / y.ln(); = note: `-D clippy::suboptimal-flops` implied by `-D warnings` error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:9:13 + --> $DIR/floating_point_logbase.rs:8:13 | LL | let _ = (x as f32).ln() / y.ln(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).log(y)` error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:10:13 + --> $DIR/floating_point_logbase.rs:9:13 | LL | let _ = x.log2() / y.log2(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:11:13 + --> $DIR/floating_point_logbase.rs:10:13 | LL | let _ = x.log10() / y.log10(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:12:13 + --> $DIR/floating_point_logbase.rs:11:13 | LL | let _ = x.log(5f32) / y.log(5f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` diff --git a/tests/ui/floating_point_mul_add.fixed b/tests/ui/floating_point_mul_add.fixed index 8848981a11d8f..c23f4d7c4d3a2 100644 --- a/tests/ui/floating_point_mul_add.fixed +++ b/tests/ui/floating_point_mul_add.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/tests/ui/floating_point_mul_add.rs b/tests/ui/floating_point_mul_add.rs index b0edf5cb210c8..431badc8db44d 100644 --- a/tests/ui/floating_point_mul_add.rs +++ b/tests/ui/floating_point_mul_add.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/tests/ui/floating_point_mul_add.stderr b/tests/ui/floating_point_mul_add.stderr index a79ae94e8d431..613954724a5bb 100644 --- a/tests/ui/floating_point_mul_add.stderr +++ b/tests/ui/floating_point_mul_add.stderr @@ -1,5 +1,5 @@ error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:21:13 + --> $DIR/floating_point_mul_add.rs:20:13 | LL | let _ = a * b + c; | ^^^^^^^^^ help: consider using: `a.mul_add(b, c)` @@ -7,67 +7,67 @@ LL | let _ = a * b + c; = note: `-D clippy::suboptimal-flops` implied by `-D warnings` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:22:13 + --> $DIR/floating_point_mul_add.rs:21:13 | LL | let _ = a * b - c; | ^^^^^^^^^ help: consider using: `a.mul_add(b, -c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:23:13 + --> $DIR/floating_point_mul_add.rs:22:13 | LL | let _ = c + a * b; | ^^^^^^^^^ help: consider using: `a.mul_add(b, c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:24:13 + --> $DIR/floating_point_mul_add.rs:23:13 | LL | let _ = c - a * b; | ^^^^^^^^^ help: consider using: `a.mul_add(-b, c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:25:13 + --> $DIR/floating_point_mul_add.rs:24:13 | LL | let _ = a + 2.0 * 4.0; | ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4.0, a)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:26:13 + --> $DIR/floating_point_mul_add.rs:25:13 | LL | let _ = a + 2. * 4.; | ^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4., a)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:28:13 + --> $DIR/floating_point_mul_add.rs:27:13 | LL | let _ = (a * b) + c; | ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:29:13 + --> $DIR/floating_point_mul_add.rs:28:13 | LL | let _ = c + (a * b); | ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:30:13 + --> $DIR/floating_point_mul_add.rs:29:13 | LL | let _ = a * b * c + d; | ^^^^^^^^^^^^^ help: consider using: `(a * b).mul_add(c, d)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:32:13 + --> $DIR/floating_point_mul_add.rs:31:13 | LL | let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c))` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:33:13 + --> $DIR/floating_point_mul_add.rs:32:13 | LL | let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1234.567_f64.mul_add(45.67834_f64, 0.0004_f64)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:35:13 + --> $DIR/floating_point_mul_add.rs:34:13 | LL | let _ = (a * a + b).sqrt(); | ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)` diff --git a/tests/ui/floating_point_powf.fixed b/tests/ui/floating_point_powf.fixed index 1e660b140c583..c2884ca318c6a 100644 --- a/tests/ui/floating_point_powf.fixed +++ b/tests/ui/floating_point_powf.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_powf.rs b/tests/ui/floating_point_powf.rs index 71c2f5292053b..37d58af055133 100644 --- a/tests/ui/floating_point_powf.rs +++ b/tests/ui/floating_point_powf.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_powf.stderr b/tests/ui/floating_point_powf.stderr index 7c9d50db2f78e..e9693de8fc909 100644 --- a/tests/ui/floating_point_powf.stderr +++ b/tests/ui/floating_point_powf.stderr @@ -1,5 +1,5 @@ error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:7:13 + --> $DIR/floating_point_powf.rs:6:13 | LL | let _ = 2f32.powf(x); | ^^^^^^^^^^^^ help: consider using: `x.exp2()` @@ -7,43 +7,43 @@ LL | let _ = 2f32.powf(x); = note: `-D clippy::suboptimal-flops` implied by `-D warnings` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:8:13 + --> $DIR/floating_point_powf.rs:7:13 | LL | let _ = 2f32.powf(3.1); | ^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:9:13 + --> $DIR/floating_point_powf.rs:8:13 | LL | let _ = 2f32.powf(-3.1); | ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:10:13 + --> $DIR/floating_point_powf.rs:9:13 | LL | let _ = std::f32::consts::E.powf(x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:11:13 + --> $DIR/floating_point_powf.rs:10:13 | LL | let _ = std::f32::consts::E.powf(3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:12:13 + --> $DIR/floating_point_powf.rs:11:13 | LL | let _ = std::f32::consts::E.powf(-3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp()` error: square-root of a number can be computed more efficiently and accurately - --> $DIR/floating_point_powf.rs:13:13 + --> $DIR/floating_point_powf.rs:12:13 | LL | let _ = x.powf(1.0 / 2.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:14:13 + --> $DIR/floating_point_powf.rs:13:13 | LL | let _ = x.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` @@ -51,139 +51,139 @@ LL | let _ = x.powf(1.0 / 3.0); = note: `-D clippy::imprecise-flops` implied by `-D warnings` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:15:13 + --> $DIR/floating_point_powf.rs:14:13 | LL | let _ = (x as f32).powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).cbrt()` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:16:13 + --> $DIR/floating_point_powf.rs:15:13 | LL | let _ = x.powf(3.0); | ^^^^^^^^^^^ help: consider using: `x.powi(3)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:17:13 + --> $DIR/floating_point_powf.rs:16:13 | LL | let _ = x.powf(-2.0); | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:18:13 + --> $DIR/floating_point_powf.rs:17:13 | LL | let _ = x.powf(16_777_215.0); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(16_777_215)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:19:13 + --> $DIR/floating_point_powf.rs:18:13 | LL | let _ = x.powf(-16_777_215.0); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-16_777_215)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:20:13 + --> $DIR/floating_point_powf.rs:19:13 | LL | let _ = (x as f32).powf(-16_777_215.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).powi(-16_777_215)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:21:13 + --> $DIR/floating_point_powf.rs:20:13 | LL | let _ = (x as f32).powf(3.0); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).powi(3)` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:22:13 + --> $DIR/floating_point_powf.rs:21:13 | LL | let _ = (1.5_f32 + 1.0).powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(1.5_f32 + 1.0).cbrt()` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:23:13 + --> $DIR/floating_point_powf.rs:22:13 | LL | let _ = 1.5_f64.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.cbrt()` error: square-root of a number can be computed more efficiently and accurately - --> $DIR/floating_point_powf.rs:24:13 + --> $DIR/floating_point_powf.rs:23:13 | LL | let _ = 1.5_f64.powf(1.0 / 2.0); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.sqrt()` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:25:13 + --> $DIR/floating_point_powf.rs:24:13 | LL | let _ = 1.5_f64.powf(3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.powi(3)` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:34:13 + --> $DIR/floating_point_powf.rs:33:13 | LL | let _ = 2f64.powf(x); | ^^^^^^^^^^^^ help: consider using: `x.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:35:13 + --> $DIR/floating_point_powf.rs:34:13 | LL | let _ = 2f64.powf(3.1); | ^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:36:13 + --> $DIR/floating_point_powf.rs:35:13 | LL | let _ = 2f64.powf(-3.1); | ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:37:13 + --> $DIR/floating_point_powf.rs:36:13 | LL | let _ = std::f64::consts::E.powf(x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:38:13 + --> $DIR/floating_point_powf.rs:37:13 | LL | let _ = std::f64::consts::E.powf(3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:39:13 + --> $DIR/floating_point_powf.rs:38:13 | LL | let _ = std::f64::consts::E.powf(-3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp()` error: square-root of a number can be computed more efficiently and accurately - --> $DIR/floating_point_powf.rs:40:13 + --> $DIR/floating_point_powf.rs:39:13 | LL | let _ = x.powf(1.0 / 2.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:41:13 + --> $DIR/floating_point_powf.rs:40:13 | LL | let _ = x.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:42:13 + --> $DIR/floating_point_powf.rs:41:13 | LL | let _ = x.powf(3.0); | ^^^^^^^^^^^ help: consider using: `x.powi(3)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:43:13 + --> $DIR/floating_point_powf.rs:42:13 | LL | let _ = x.powf(-2.0); | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:44:13 + --> $DIR/floating_point_powf.rs:43:13 | LL | let _ = x.powf(-2_147_483_648.0); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-2_147_483_648)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:45:13 + --> $DIR/floating_point_powf.rs:44:13 | LL | let _ = x.powf(2_147_483_647.0); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2_147_483_647)` diff --git a/tests/ui/floating_point_powi.fixed b/tests/ui/floating_point_powi.fixed index 41d5288d6e0cf..cb033c899f310 100644 --- a/tests/ui/floating_point_powi.fixed +++ b/tests/ui/floating_point_powi.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_powi.rs b/tests/ui/floating_point_powi.rs index 7951aab31beba..f02e0e8ddb36b 100644 --- a/tests/ui/floating_point_powi.rs +++ b/tests/ui/floating_point_powi.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/tests/ui/floating_point_powi.stderr b/tests/ui/floating_point_powi.stderr index fdf6d088052ea..d60885e1b9a1e 100644 --- a/tests/ui/floating_point_powi.stderr +++ b/tests/ui/floating_point_powi.stderr @@ -1,5 +1,5 @@ error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:10:13 + --> $DIR/floating_point_powi.rs:9:13 | LL | let _ = x.powi(2) + y; | ^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)` @@ -7,79 +7,79 @@ LL | let _ = x.powi(2) + y; = note: `-D clippy::suboptimal-flops` implied by `-D warnings` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:11:13 + --> $DIR/floating_point_powi.rs:10:13 | LL | let _ = x.powi(2) - y; | ^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, -y)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:12:13 + --> $DIR/floating_point_powi.rs:11:13 | LL | let _ = x + y.powi(2); | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:13:13 + --> $DIR/floating_point_powi.rs:12:13 | LL | let _ = x - y.powi(2); | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(-y, x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:14:13 + --> $DIR/floating_point_powi.rs:13:13 | LL | let _ = x + (y as f32).powi(2); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y as f32).mul_add(y as f32, x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:15:13 + --> $DIR/floating_point_powi.rs:14:13 | LL | let _ = (x.powi(2) + y).sqrt(); | ^^^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:16:13 + --> $DIR/floating_point_powi.rs:15:13 | LL | let _ = (x + y.powi(2)).sqrt(); | ^^^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:18:13 + --> $DIR/floating_point_powi.rs:17:13 | LL | let _ = (x - 1.0).powi(2) - y; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x - 1.0).mul_add(x - 1.0, -y)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:19:13 + --> $DIR/floating_point_powi.rs:18:13 | LL | let _ = (x - 1.0).powi(2) - y + 3.0; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x - 1.0).mul_add(x - 1.0, -y)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:20:13 + --> $DIR/floating_point_powi.rs:19:13 | LL | let _ = (x - 1.0).powi(2) - (y + 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x - 1.0).mul_add(x - 1.0, -(y + 3.0))` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:21:13 + --> $DIR/floating_point_powi.rs:20:13 | LL | let _ = x - (y + 1.0).powi(2); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y + 1.0).mul_add(-(y + 1.0), x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:22:13 + --> $DIR/floating_point_powi.rs:21:13 | LL | let _ = x - (3.0 * y).powi(2); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(3.0 * y).mul_add(-(3.0 * y), x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:23:13 + --> $DIR/floating_point_powi.rs:22:13 | LL | let _ = x - (y + 1.0 + x).powi(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y + 1.0 + x).mul_add(-(y + 1.0 + x), x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:24:13 + --> $DIR/floating_point_powi.rs:23:13 | LL | let _ = x - (y + 1.0 + 2.0).powi(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y + 1.0 + 2.0).mul_add(-(y + 1.0 + 2.0), x)` diff --git a/tests/ui/floating_point_rad.fixed b/tests/ui/floating_point_rad.fixed index af23645271289..a710bd9bd6074 100644 --- a/tests/ui/floating_point_rad.fixed +++ b/tests/ui/floating_point_rad.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/tests/ui/floating_point_rad.rs b/tests/ui/floating_point_rad.rs index d7612c56a3e49..14656f021df45 100644 --- a/tests/ui/floating_point_rad.rs +++ b/tests/ui/floating_point_rad.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/tests/ui/floating_point_rad.stderr b/tests/ui/floating_point_rad.stderr index 979442f2c24a3..914358c98676d 100644 --- a/tests/ui/floating_point_rad.stderr +++ b/tests/ui/floating_point_rad.stderr @@ -1,5 +1,5 @@ error: conversion to radians can be done more accurately - --> $DIR/floating_point_rad.rs:12:13 + --> $DIR/floating_point_rad.rs:11:13 | LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_radians()` @@ -7,43 +7,43 @@ LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0; = note: `-D clippy::suboptimal-flops` implied by `-D warnings` error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:13:13 + --> $DIR/floating_point_rad.rs:12:13 | LL | let _ = degrees as f64 * 180.0 / std::f64::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_degrees()` error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:18:13 + --> $DIR/floating_point_rad.rs:17:13 | LL | let _ = x * 180f32 / std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_degrees()` error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:19:13 + --> $DIR/floating_point_rad.rs:18:13 | LL | let _ = 90. * 180f64 / std::f64::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_degrees()` error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:20:13 + --> $DIR/floating_point_rad.rs:19:13 | LL | let _ = 90.5 * 180f64 / std::f64::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_degrees()` error: conversion to radians can be done more accurately - --> $DIR/floating_point_rad.rs:21:13 + --> $DIR/floating_point_rad.rs:20:13 | LL | let _ = x * std::f32::consts::PI / 180f32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()` error: conversion to radians can be done more accurately - --> $DIR/floating_point_rad.rs:22:13 + --> $DIR/floating_point_rad.rs:21:13 | LL | let _ = 90. * std::f32::consts::PI / 180f32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_radians()` error: conversion to radians can be done more accurately - --> $DIR/floating_point_rad.rs:23:13 + --> $DIR/floating_point_rad.rs:22:13 | LL | let _ = 90.5 * std::f32::consts::PI / 180f32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_radians()` diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs index 4f6af87088992..05053270c5bc6 100644 --- a/tests/ui/fn_to_numeric_cast.rs +++ b/tests/ui/fn_to_numeric_cast.rs @@ -1,5 +1,5 @@ //@ignore-32bit - +//@no-rustfix #![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] fn foo() -> String { diff --git a/tests/ui/fn_to_numeric_cast_any.rs b/tests/ui/fn_to_numeric_cast_any.rs index 46704683926b2..b77aefd38e590 100644 --- a/tests/ui/fn_to_numeric_cast_any.rs +++ b/tests/ui/fn_to_numeric_cast_any.rs @@ -1,6 +1,6 @@ #![warn(clippy::fn_to_numeric_cast_any)] #![allow(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] - +//@no-rustfix fn foo() -> u8 { 0 } diff --git a/tests/ui/for_kv_map.fixed b/tests/ui/for_kv_map.fixed new file mode 100644 index 0000000000000..703ae98e8ed57 --- /dev/null +++ b/tests/ui/for_kv_map.fixed @@ -0,0 +1,50 @@ +#![warn(clippy::for_kv_map)] +#![allow(clippy::used_underscore_binding)] + +use std::collections::*; +use std::rc::Rc; + +fn main() { + let m: HashMap = HashMap::new(); + for v in m.values() { + let _v = v; + } + + let m: Rc> = Rc::new(HashMap::new()); + for v in (*m).values() { + let _v = v; + // Here the `*` is not actually necessary, but the test tests that we don't + // suggest + // `in *m.values()` as we used to + } + + let mut m: HashMap = HashMap::new(); + for v in m.values_mut() { + let _v = v; + } + + let m: &mut HashMap = &mut HashMap::new(); + for v in (*m).values_mut() { + let _v = v; + } + + let m: HashMap = HashMap::new(); + let rm = &m; + for k in rm.keys() { + let _k = k; + } + + // The following should not produce warnings. + + let m: HashMap = HashMap::new(); + // No error, _value is actually used + for (k, _value) in &m { + let _ = _value; + let _k = k; + } + + let m: HashMap = Default::default(); + for (_, v) in m { + let _v = v; + } +} diff --git a/tests/ui/format.fixed b/tests/ui/format.fixed index 2e24e07ea268f..36679a9c883d3 100644 --- a/tests/ui/format.fixed +++ b/tests/ui/format.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::useless_format)] #![allow( unused_tuple_struct_fields, diff --git a/tests/ui/format.rs b/tests/ui/format.rs index 0e64a310b01e2..b0920daf0886b 100644 --- a/tests/ui/format.rs +++ b/tests/ui/format.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::useless_format)] #![allow( unused_tuple_struct_fields, diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index 78a11a3354f6b..f456c11924e5a 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -1,5 +1,5 @@ error: useless use of `format!` - --> $DIR/format.rs:21:5 + --> $DIR/format.rs:20:5 | LL | format!("foo"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` @@ -7,19 +7,19 @@ LL | format!("foo"); = note: `-D clippy::useless-format` implied by `-D warnings` error: useless use of `format!` - --> $DIR/format.rs:22:5 + --> $DIR/format.rs:21:5 | LL | format!("{{}}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()` error: useless use of `format!` - --> $DIR/format.rs:23:5 + --> $DIR/format.rs:22:5 | LL | format!("{{}} abc {{}}"); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()` error: useless use of `format!` - --> $DIR/format.rs:24:5 + --> $DIR/format.rs:23:5 | LL | / format!( LL | | r##"foo {{}} @@ -34,67 +34,67 @@ LL ~ " bar"##.to_string(); | error: useless use of `format!` - --> $DIR/format.rs:29:13 + --> $DIR/format.rs:28:13 | LL | let _ = format!(""); | ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()` error: useless use of `format!` - --> $DIR/format.rs:31:5 + --> $DIR/format.rs:30:5 | LL | format!("{}", "foo"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` - --> $DIR/format.rs:39:5 + --> $DIR/format.rs:38:5 | LL | format!("{}", arg); | ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` - --> $DIR/format.rs:69:5 + --> $DIR/format.rs:68:5 | LL | format!("{}", 42.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()` error: useless use of `format!` - --> $DIR/format.rs:71:5 + --> $DIR/format.rs:70:5 | LL | format!("{}", x.display().to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()` error: useless use of `format!` - --> $DIR/format.rs:75:18 + --> $DIR/format.rs:74:18 | LL | let _ = Some(format!("{}", a + "bar")); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"` error: useless use of `format!` - --> $DIR/format.rs:79:22 + --> $DIR/format.rs:78:22 | LL | let _s: String = format!("{}", &*v.join("/n")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()` error: useless use of `format!` - --> $DIR/format.rs:85:13 + --> $DIR/format.rs:84:13 | LL | let _ = format!("{x}"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:87:13 + --> $DIR/format.rs:86:13 | LL | let _ = format!("{y}", y = x); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:91:13 + --> $DIR/format.rs:90:13 | LL | let _ = format!("{abc}"); | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()` error: useless use of `format!` - --> $DIR/format.rs:93:13 + --> $DIR/format.rs:92:13 | LL | let _ = format!("{xx}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()` diff --git a/tests/ui/format_args.fixed b/tests/ui/format_args.fixed index ea38368613570..ddd5976c408a3 100644 --- a/tests/ui/format_args.fixed +++ b/tests/ui/format_args.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::to_string_in_format_args)] #![allow(unused)] #![allow( diff --git a/tests/ui/format_args.rs b/tests/ui/format_args.rs index bfb324492467e..18e1bc1af67f1 100644 --- a/tests/ui/format_args.rs +++ b/tests/ui/format_args.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::to_string_in_format_args)] #![allow(unused)] #![allow( diff --git a/tests/ui/format_args.stderr b/tests/ui/format_args.stderr index f1832b970198a..a922f293b48ef 100644 --- a/tests/ui/format_args.stderr +++ b/tests/ui/format_args.stderr @@ -1,5 +1,5 @@ error: `to_string` applied to a type that implements `Display` in `format!` args - --> $DIR/format_args.rs:77:72 + --> $DIR/format_args.rs:76:72 | LL | let _ = format!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this @@ -7,145 +7,145 @@ LL | let _ = format!("error: something failed at {}", Location::caller().to_ = note: `-D clippy::to-string-in-format-args` implied by `-D warnings` error: `to_string` applied to a type that implements `Display` in `write!` args - --> $DIR/format_args.rs:81:27 + --> $DIR/format_args.rs:80:27 | LL | Location::caller().to_string() | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `writeln!` args - --> $DIR/format_args.rs:86:27 + --> $DIR/format_args.rs:85:27 | LL | Location::caller().to_string() | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args - --> $DIR/format_args.rs:88:63 + --> $DIR/format_args.rs:87:63 | LL | print!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:89:65 + --> $DIR/format_args.rs:88:65 | LL | println!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `eprint!` args - --> $DIR/format_args.rs:90:64 + --> $DIR/format_args.rs:89:64 | LL | eprint!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `eprintln!` args - --> $DIR/format_args.rs:91:66 + --> $DIR/format_args.rs:90:66 | LL | eprintln!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `format_args!` args - --> $DIR/format_args.rs:92:77 + --> $DIR/format_args.rs:91:77 | LL | let _ = format_args!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `assert!` args - --> $DIR/format_args.rs:93:70 + --> $DIR/format_args.rs:92:70 | LL | assert!(true, "error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `assert_eq!` args - --> $DIR/format_args.rs:94:73 + --> $DIR/format_args.rs:93:73 | LL | assert_eq!(0, 0, "error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `assert_ne!` args - --> $DIR/format_args.rs:95:73 + --> $DIR/format_args.rs:94:73 | LL | assert_ne!(0, 0, "error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `panic!` args - --> $DIR/format_args.rs:96:63 + --> $DIR/format_args.rs:95:63 | LL | panic!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:97:20 + --> $DIR/format_args.rs:96:20 | LL | println!("{}", X(1).to_string()); | ^^^^^^^^^^^^^^^^ help: use this: `*X(1)` error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:98:20 + --> $DIR/format_args.rs:97:20 | LL | println!("{}", Y(&X(1)).to_string()); | ^^^^^^^^^^^^^^^^^^^^ help: use this: `***Y(&X(1))` error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:99:24 + --> $DIR/format_args.rs:98:24 | LL | println!("{}", Z(1).to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:100:20 + --> $DIR/format_args.rs:99:20 | LL | println!("{}", x.to_string()); | ^^^^^^^^^^^^^ help: use this: `**x` error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:101:20 + --> $DIR/format_args.rs:100:20 | LL | println!("{}", x_ref.to_string()); | ^^^^^^^^^^^^^^^^^ help: use this: `***x_ref` error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:103:39 + --> $DIR/format_args.rs:102:39 | LL | println!("{foo}{bar}", foo = "foo".to_string(), bar = "bar"); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:104:52 + --> $DIR/format_args.rs:103:52 | LL | println!("{foo}{bar}", foo = "foo", bar = "bar".to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:105:39 + --> $DIR/format_args.rs:104:39 | LL | println!("{foo}{bar}", bar = "bar".to_string(), foo = "foo"); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:106:52 + --> $DIR/format_args.rs:105:52 | LL | println!("{foo}{bar}", bar = "bar", foo = "foo".to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args - --> $DIR/format_args.rs:118:37 + --> $DIR/format_args.rs:117:37 | LL | print!("{}", (Location::caller().to_string())); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `print!` args - --> $DIR/format_args.rs:119:39 + --> $DIR/format_args.rs:118:39 | LL | print!("{}", ((Location::caller()).to_string())); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `format!` args - --> $DIR/format_args.rs:147:38 + --> $DIR/format_args.rs:146:38 | LL | let x = format!("{} {}", a, b.to_string()); | ^^^^^^^^^^^^ help: remove this error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/format_args.rs:161:24 + --> $DIR/format_args.rs:160:24 | LL | println!("{}", original[..10].to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use this: `&original[..10]` diff --git a/tests/ui/four_forward_slashes.fixed b/tests/ui/four_forward_slashes.fixed index 54b2c414b6208..67c07ccbed74a 100644 --- a/tests/ui/four_forward_slashes.fixed +++ b/tests/ui/four_forward_slashes.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + //@aux-build:proc_macros.rs:proc-macro #![feature(custom_inner_attributes)] #![allow(unused)] diff --git a/tests/ui/four_forward_slashes.rs b/tests/ui/four_forward_slashes.rs index facdc8cb17dba..c86a925e5e6d8 100644 --- a/tests/ui/four_forward_slashes.rs +++ b/tests/ui/four_forward_slashes.rs @@ -1,4 +1,4 @@ -//@run-rustfix + //@aux-build:proc_macros.rs:proc-macro #![feature(custom_inner_attributes)] #![allow(unused)] diff --git a/tests/ui/four_forward_slashes_first_line.fixed b/tests/ui/four_forward_slashes_first_line.fixed index ce272b4c6cd78..5ef40015d88b6 100644 --- a/tests/ui/four_forward_slashes_first_line.fixed +++ b/tests/ui/four_forward_slashes_first_line.fixed @@ -1,7 +1,6 @@ /// borked doc comment on the first line. doesn't combust! fn a() {} -//@run-rustfix // This test's entire purpose is to make sure we don't panic if the comment with four slashes // extends to the first line of the file. This is likely pretty rare in production, but an ICE is an // ICE. diff --git a/tests/ui/four_forward_slashes_first_line.rs b/tests/ui/four_forward_slashes_first_line.rs index d8f82d4410b8a..9c835e745f654 100644 --- a/tests/ui/four_forward_slashes_first_line.rs +++ b/tests/ui/four_forward_slashes_first_line.rs @@ -1,7 +1,6 @@ //// borked doc comment on the first line. doesn't combust! fn a() {} -//@run-rustfix // This test's entire purpose is to make sure we don't panic if the comment with four slashes // extends to the first line of the file. This is likely pretty rare in production, but an ICE is an // ICE. diff --git a/tests/ui/from_iter_instead_of_collect.fixed b/tests/ui/from_iter_instead_of_collect.fixed index 1671987cb673e..82c8e1d8abdb4 100644 --- a/tests/ui/from_iter_instead_of_collect.fixed +++ b/tests/ui/from_iter_instead_of_collect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::from_iter_instead_of_collect)] #![allow(unused_imports, unused_tuple_struct_fields)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/from_iter_instead_of_collect.rs b/tests/ui/from_iter_instead_of_collect.rs index 48509b32f1092..2aed6b14be14c 100644 --- a/tests/ui/from_iter_instead_of_collect.rs +++ b/tests/ui/from_iter_instead_of_collect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::from_iter_instead_of_collect)] #![allow(unused_imports, unused_tuple_struct_fields)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/from_iter_instead_of_collect.stderr b/tests/ui/from_iter_instead_of_collect.stderr index 8f08ac8c3ff43..e42851bf84603 100644 --- a/tests/ui/from_iter_instead_of_collect.stderr +++ b/tests/ui/from_iter_instead_of_collect.stderr @@ -1,5 +1,5 @@ error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:19:9 + --> $DIR/from_iter_instead_of_collect.rs:17:9 | LL | >::from_iter(iter.into_iter().copied()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter.into_iter().copied().collect::()` @@ -7,85 +7,85 @@ LL | >::from_iter(iter.into_iter().copied()) = note: `-D clippy::from-iter-instead-of-collect` implied by `-D warnings` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:25:13 + --> $DIR/from_iter_instead_of_collect.rs:23:13 | LL | let _ = Vec::from_iter(iter_expr); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter_expr.collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:27:13 + --> $DIR/from_iter_instead_of_collect.rs:25:13 | LL | let _ = HashMap::::from_iter(vec![5, 5, 5, 5].iter().enumerate()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `vec![5, 5, 5, 5].iter().enumerate().collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:32:19 + --> $DIR/from_iter_instead_of_collect.rs:30:19 | LL | assert_eq!(a, Vec::from_iter(0..3)); | ^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:33:19 + --> $DIR/from_iter_instead_of_collect.rs:31:19 | LL | assert_eq!(a, Vec::::from_iter(0..3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:35:17 + --> $DIR/from_iter_instead_of_collect.rs:33:17 | LL | let mut b = VecDeque::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:38:17 + --> $DIR/from_iter_instead_of_collect.rs:36:17 | LL | let mut b = VecDeque::::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:43:21 + --> $DIR/from_iter_instead_of_collect.rs:41:21 | LL | let mut b = collections::VecDeque::::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:48:14 + --> $DIR/from_iter_instead_of_collect.rs:46:14 | LL | let bm = BTreeMap::from_iter(values.iter().cloned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `values.iter().cloned().collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:49:19 + --> $DIR/from_iter_instead_of_collect.rs:47:19 | LL | let mut bar = BTreeMap::from_iter(bm.range(0..2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `bm.range(0..2).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:52:19 + --> $DIR/from_iter_instead_of_collect.rs:50:19 | LL | let mut bts = BTreeSet::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:56:17 + --> $DIR/from_iter_instead_of_collect.rs:54:17 | LL | let _ = collections::BTreeSet::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:57:17 + --> $DIR/from_iter_instead_of_collect.rs:55:17 | LL | let _ = collections::BTreeSet::::from_iter(0..3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:60:15 + --> $DIR/from_iter_instead_of_collect.rs:58:15 | LL | for _i in Vec::from_iter([1, 2, 3].iter()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::>()` error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:61:15 + --> $DIR/from_iter_instead_of_collect.rs:59:15 | LL | for _i in Vec::<&i32>::from_iter([1, 2, 3].iter()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::>()` diff --git a/tests/ui/from_over_into.fixed b/tests/ui/from_over_into.fixed index d96b68a9159a7..18d285693e603 100644 --- a/tests/ui/from_over_into.fixed +++ b/tests/ui/from_over_into.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(type_alias_impl_trait)] #![warn(clippy::from_over_into)] #![allow(unused)] diff --git a/tests/ui/from_over_into.rs b/tests/ui/from_over_into.rs index da8fe04f47605..779ef709e9284 100644 --- a/tests/ui/from_over_into.rs +++ b/tests/ui/from_over_into.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(type_alias_impl_trait)] #![warn(clippy::from_over_into)] #![allow(unused)] diff --git a/tests/ui/from_over_into.stderr b/tests/ui/from_over_into.stderr index 498b00de5adb6..96afec3de30e3 100644 --- a/tests/ui/from_over_into.stderr +++ b/tests/ui/from_over_into.stderr @@ -1,5 +1,5 @@ error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:10:1 + --> $DIR/from_over_into.rs:8:1 | LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL ~ StringWrapper(val) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:18:1 + --> $DIR/from_over_into.rs:16:1 | LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL ~ SelfType(String::new()) | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:33:1 + --> $DIR/from_over_into.rs:31:1 | LL | impl Into for X { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL ~ let _: X = val; | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:45:1 + --> $DIR/from_over_into.rs:43:1 | LL | impl core::convert::Into for crate::ExplicitPaths { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -59,7 +59,7 @@ LL ~ val.0 | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:65:1 + --> $DIR/from_over_into.rs:63:1 | LL | impl Into for PathInExpansion { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL ~ fn from(val: PathInExpansion) -> Self { | error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into.rs:87:5 + --> $DIR/from_over_into.rs:85:5 | LL | impl Into> for Vec { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/from_str_radix_10.fixed b/tests/ui/from_str_radix_10.fixed new file mode 100644 index 0000000000000..b0fb88f988ada --- /dev/null +++ b/tests/ui/from_str_radix_10.fixed @@ -0,0 +1,52 @@ +#![warn(clippy::from_str_radix_10)] + +mod some_mod { + // fake function that shouldn't trigger the lint + pub fn from_str_radix(_: &str, _: u32) -> Result<(), std::num::ParseIntError> { + unimplemented!() + } +} + +// fake function that shouldn't trigger the lint +fn from_str_radix(_: &str, _: u32) -> Result<(), std::num::ParseIntError> { + unimplemented!() +} + +// to test parenthesis addition +struct Test; + +impl std::ops::Add for Test { + type Output = &'static str; + + fn add(self, _: Self) -> Self::Output { + "304" + } +} + +fn main() -> Result<(), Box> { + // all of these should trigger the lint + "30".parse::()?; + "24".parse::()?; + "100".parse::()?; + "7".parse::()?; + ("10".to_owned() + "5").parse::()?; + (Test + Test).parse::()?; + + let string = "300"; + string.parse::()?; + + let stringier = "400".to_string(); + stringier.parse::()?; + + // none of these should trigger the lint + u16::from_str_radix("20", 3)?; + i32::from_str_radix("45", 12)?; + usize::from_str_radix("10", 16)?; + i128::from_str_radix("10", 13)?; + some_mod::from_str_radix("50", 10)?; + some_mod::from_str_radix("50", 6)?; + from_str_radix("50", 10)?; + from_str_radix("50", 6)?; + + Ok(()) +} diff --git a/tests/ui/get_first.fixed b/tests/ui/get_first.fixed index bc2f86566bc07..b1a597fc4dd5b 100644 --- a/tests/ui/get_first.fixed +++ b/tests/ui/get_first.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::get_first)] #![allow(clippy::useless_vec)] use std::collections::{BTreeMap, HashMap, VecDeque}; diff --git a/tests/ui/get_first.rs b/tests/ui/get_first.rs index bc0e233fdee55..e27ee4be8c087 100644 --- a/tests/ui/get_first.rs +++ b/tests/ui/get_first.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::get_first)] #![allow(clippy::useless_vec)] use std::collections::{BTreeMap, HashMap, VecDeque}; diff --git a/tests/ui/get_first.stderr b/tests/ui/get_first.stderr index 0899a5905f300..51ebb1f3f06fa 100644 --- a/tests/ui/get_first.stderr +++ b/tests/ui/get_first.stderr @@ -1,5 +1,5 @@ error: accessing first element with `x.get(0)` - --> $DIR/get_first.rs:18:13 + --> $DIR/get_first.rs:17:13 | LL | let _ = x.get(0); // Use x.first() | ^^^^^^^^ help: try: `x.first()` @@ -7,13 +7,13 @@ LL | let _ = x.get(0); // Use x.first() = note: `-D clippy::get-first` implied by `-D warnings` error: accessing first element with `y.get(0)` - --> $DIR/get_first.rs:23:13 + --> $DIR/get_first.rs:22:13 | LL | let _ = y.get(0); // Use y.first() | ^^^^^^^^ help: try: `y.first()` error: accessing first element with `z.get(0)` - --> $DIR/get_first.rs:28:13 + --> $DIR/get_first.rs:27:13 | LL | let _ = z.get(0); // Use z.first() | ^^^^^^^^ help: try: `z.first()` diff --git a/tests/ui/get_last_with_len.fixed b/tests/ui/get_last_with_len.fixed index 01a83e5bf343f..377906cb24481 100644 --- a/tests/ui/get_last_with_len.fixed +++ b/tests/ui/get_last_with_len.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::get_last_with_len)] #![allow(unused, clippy::useless_vec)] diff --git a/tests/ui/get_last_with_len.rs b/tests/ui/get_last_with_len.rs index d82484b46d3ff..2735932043a35 100644 --- a/tests/ui/get_last_with_len.rs +++ b/tests/ui/get_last_with_len.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::get_last_with_len)] #![allow(unused, clippy::useless_vec)] diff --git a/tests/ui/get_last_with_len.stderr b/tests/ui/get_last_with_len.stderr index ac8dd6c2e41a8..8e852bbb26557 100644 --- a/tests/ui/get_last_with_len.stderr +++ b/tests/ui/get_last_with_len.stderr @@ -1,5 +1,5 @@ error: accessing last element with `x.get(x.len() - 1)` - --> $DIR/get_last_with_len.rs:10:13 + --> $DIR/get_last_with_len.rs:8:13 | LL | let _ = x.get(x.len() - 1); | ^^^^^^^^^^^^^^^^^^ help: try: `x.last()` @@ -7,31 +7,31 @@ LL | let _ = x.get(x.len() - 1); = note: `-D clippy::get-last-with-len` implied by `-D warnings` error: accessing last element with `s.field.get(s.field.len() - 1)` - --> $DIR/get_last_with_len.rs:34:13 + --> $DIR/get_last_with_len.rs:32:13 | LL | let _ = s.field.get(s.field.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.field.last()` error: accessing last element with `slice.get(slice.len() - 1)` - --> $DIR/get_last_with_len.rs:39:13 + --> $DIR/get_last_with_len.rs:37:13 | LL | let _ = slice.get(slice.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice.last()` error: accessing last element with `array.get(array.len() - 1)` - --> $DIR/get_last_with_len.rs:42:13 + --> $DIR/get_last_with_len.rs:40:13 | LL | let _ = array.get(array.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array.last()` error: accessing last element with `deq.get(deq.len() - 1)` - --> $DIR/get_last_with_len.rs:45:13 + --> $DIR/get_last_with_len.rs:43:13 | LL | let _ = deq.get(deq.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `deq.back()` error: accessing last element with `nested[0].get(nested[0].len() - 1)` - --> $DIR/get_last_with_len.rs:48:13 + --> $DIR/get_last_with_len.rs:46:13 | LL | let _ = nested[0].get(nested[0].len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `nested[0].last()` diff --git a/tests/ui/get_unwrap.fixed b/tests/ui/get_unwrap.fixed index fda334407a9bc..d5a4309db5945 100644 --- a/tests/ui/get_unwrap.fixed +++ b/tests/ui/get_unwrap.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( unused_mut, clippy::from_iter_instead_of_collect, diff --git a/tests/ui/get_unwrap.rs b/tests/ui/get_unwrap.rs index eaf6b005a36b0..5a9ad204f7025 100644 --- a/tests/ui/get_unwrap.rs +++ b/tests/ui/get_unwrap.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( unused_mut, clippy::from_iter_instead_of_collect, diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr index 19dc9071fe7bb..242c339bbf1da 100644 --- a/tests/ui/get_unwrap.stderr +++ b/tests/ui/get_unwrap.stderr @@ -1,17 +1,17 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:38:17 + --> $DIR/get_unwrap.rs:36:17 | LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]` | note: the lint level is defined here - --> $DIR/get_unwrap.rs:10:9 + --> $DIR/get_unwrap.rs:8:9 | LL | #![deny(clippy::get_unwrap)] | ^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:38:17 + --> $DIR/get_unwrap.rs:36:17 | LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,13 +21,13 @@ LL | let _ = boxed_slice.get(1).unwrap(); = note: `-D clippy::unwrap-used` implied by `-D warnings` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:39:17 + --> $DIR/get_unwrap.rs:37:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:39:17 + --> $DIR/get_unwrap.rs:37:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,13 +36,13 @@ LL | let _ = some_slice.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:40:17 + --> $DIR/get_unwrap.rs:38:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vec[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:40:17 + --> $DIR/get_unwrap.rs:38:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,13 +51,13 @@ LL | let _ = some_vec.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:41:17 + --> $DIR/get_unwrap.rs:39:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vecdeque[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:41:17 + --> $DIR/get_unwrap.rs:39:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,13 +66,13 @@ LL | let _ = some_vecdeque.get(0).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:42:17 + --> $DIR/get_unwrap.rs:40:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_hashmap[&1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:42:17 + --> $DIR/get_unwrap.rs:40:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,13 +81,13 @@ LL | let _ = some_hashmap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:43:17 + --> $DIR/get_unwrap.rs:41:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_btreemap[&1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:43:17 + --> $DIR/get_unwrap.rs:41:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,13 +96,13 @@ LL | let _ = some_btreemap.get(&1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:47:21 + --> $DIR/get_unwrap.rs:45:21 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:47:22 + --> $DIR/get_unwrap.rs:45:22 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,13 +111,13 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap(); = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:52:9 + --> $DIR/get_unwrap.rs:50:9 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:52:10 + --> $DIR/get_unwrap.rs:50:10 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -126,13 +126,13 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1; = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:53:9 + --> $DIR/get_unwrap.rs:51:9 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:53:10 + --> $DIR/get_unwrap.rs:51:10 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -141,13 +141,13 @@ LL | *some_slice.get_mut(0).unwrap() = 1; = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:54:9 + --> $DIR/get_unwrap.rs:52:9 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:54:10 + --> $DIR/get_unwrap.rs:52:10 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,13 +156,13 @@ LL | *some_vec.get_mut(0).unwrap() = 1; = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:55:9 + --> $DIR/get_unwrap.rs:53:9 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vecdeque[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:55:10 + --> $DIR/get_unwrap.rs:53:10 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -171,13 +171,13 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1; = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:67:17 + --> $DIR/get_unwrap.rs:65:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:67:17 + --> $DIR/get_unwrap.rs:65:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -186,13 +186,13 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec(); = help: consider using `expect()` to provide a better panic message error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:68:17 + --> $DIR/get_unwrap.rs:66:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:68:17 + --> $DIR/get_unwrap.rs:66:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -201,25 +201,25 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:78:24 + --> $DIR/get_unwrap.rs:76:24 | LL | let _x: &i32 = f.get(1 + 2).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `&f[1 + 2]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:81:18 + --> $DIR/get_unwrap.rs:79:18 | LL | let _x = f.get(1 + 2).unwrap().to_string(); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `f[1 + 2]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:84:18 + --> $DIR/get_unwrap.rs:82:18 | LL | let _x = f.get(1 + 2).unwrap().abs(); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `f[1 + 2]` error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:101:33 + --> $DIR/get_unwrap.rs:99:33 | LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut rest[linidx(j, k) - linidx(i, k) - 1]` diff --git a/tests/ui/identity_op.fixed b/tests/ui/identity_op.fixed index beb16000eca20..f3b4b1fffa0b5 100644 --- a/tests/ui/identity_op.fixed +++ b/tests/ui/identity_op.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::identity_op)] #![allow(unused)] #![allow( diff --git a/tests/ui/identity_op.rs b/tests/ui/identity_op.rs index 072e00c00f0ad..631aa3b0215f2 100644 --- a/tests/ui/identity_op.rs +++ b/tests/ui/identity_op.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::identity_op)] #![allow(unused)] #![allow( diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr index 3ba557d18b244..cb251935b6003 100644 --- a/tests/ui/identity_op.stderr +++ b/tests/ui/identity_op.stderr @@ -1,5 +1,5 @@ error: this operation has no effect - --> $DIR/identity_op.rs:43:5 + --> $DIR/identity_op.rs:42:5 | LL | x + 0; | ^^^^^ help: consider reducing it to: `x` @@ -7,235 +7,235 @@ LL | x + 0; = note: `-D clippy::identity-op` implied by `-D warnings` error: this operation has no effect - --> $DIR/identity_op.rs:44:5 + --> $DIR/identity_op.rs:43:5 | LL | x + (1 - 1); | ^^^^^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:46:5 + --> $DIR/identity_op.rs:45:5 | LL | 0 + x; | ^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:49:5 + --> $DIR/identity_op.rs:48:5 | LL | x | (0); | ^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:52:5 + --> $DIR/identity_op.rs:51:5 | LL | x * 1; | ^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:53:5 + --> $DIR/identity_op.rs:52:5 | LL | 1 * x; | ^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:59:5 + --> $DIR/identity_op.rs:58:5 | LL | -1 & x; | ^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:62:5 + --> $DIR/identity_op.rs:61:5 | LL | u & 255; | ^^^^^^^ help: consider reducing it to: `u` error: this operation has no effect - --> $DIR/identity_op.rs:65:5 + --> $DIR/identity_op.rs:64:5 | LL | 42 << 0; | ^^^^^^^ help: consider reducing it to: `42` error: this operation has no effect - --> $DIR/identity_op.rs:66:5 + --> $DIR/identity_op.rs:65:5 | LL | 1 >> 0; | ^^^^^^ help: consider reducing it to: `1` error: this operation has no effect - --> $DIR/identity_op.rs:67:5 + --> $DIR/identity_op.rs:66:5 | LL | 42 >> 0; | ^^^^^^^ help: consider reducing it to: `42` error: this operation has no effect - --> $DIR/identity_op.rs:68:5 + --> $DIR/identity_op.rs:67:5 | LL | &x >> 0; | ^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:69:5 + --> $DIR/identity_op.rs:68:5 | LL | x >> &0; | ^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:76:5 + --> $DIR/identity_op.rs:75:5 | LL | 2 % 3; | ^^^^^ help: consider reducing it to: `2` error: this operation has no effect - --> $DIR/identity_op.rs:77:5 + --> $DIR/identity_op.rs:76:5 | LL | -2 % 3; | ^^^^^^ help: consider reducing it to: `-2` error: this operation has no effect - --> $DIR/identity_op.rs:78:5 + --> $DIR/identity_op.rs:77:5 | LL | 2 % -3 + x; | ^^^^^^ help: consider reducing it to: `2` error: this operation has no effect - --> $DIR/identity_op.rs:79:5 + --> $DIR/identity_op.rs:78:5 | LL | -2 % -3 + x; | ^^^^^^^ help: consider reducing it to: `-2` error: this operation has no effect - --> $DIR/identity_op.rs:80:9 + --> $DIR/identity_op.rs:79:9 | LL | x + 1 % 3; | ^^^^^ help: consider reducing it to: `1` error: this operation has no effect - --> $DIR/identity_op.rs:88:5 + --> $DIR/identity_op.rs:87:5 | LL | 0 + if b { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if b { 1 } else { 2 })` error: this operation has no effect - --> $DIR/identity_op.rs:89:5 + --> $DIR/identity_op.rs:88:5 | LL | 0 + if b { 1 } else { 2 } + if b { 3 } else { 4 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if b { 1 } else { 2 })` error: this operation has no effect - --> $DIR/identity_op.rs:90:5 + --> $DIR/identity_op.rs:89:5 | LL | 0 + match a { 0 => 10, _ => 20 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(match a { 0 => 10, _ => 20 })` error: this operation has no effect - --> $DIR/identity_op.rs:91:5 + --> $DIR/identity_op.rs:90:5 | LL | 0 + match a { 0 => 10, _ => 20 } + match a { 0 => 30, _ => 40 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(match a { 0 => 10, _ => 20 })` error: this operation has no effect - --> $DIR/identity_op.rs:92:5 + --> $DIR/identity_op.rs:91:5 | LL | 0 + if b { 1 } else { 2 } + match a { 0 => 30, _ => 40 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if b { 1 } else { 2 })` error: this operation has no effect - --> $DIR/identity_op.rs:93:5 + --> $DIR/identity_op.rs:92:5 | LL | 0 + match a { 0 => 10, _ => 20 } + if b { 3 } else { 4 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(match a { 0 => 10, _ => 20 })` error: this operation has no effect - --> $DIR/identity_op.rs:94:5 + --> $DIR/identity_op.rs:93:5 | LL | (if b { 1 } else { 2 }) + 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if b { 1 } else { 2 })` error: this operation has no effect - --> $DIR/identity_op.rs:96:5 + --> $DIR/identity_op.rs:95:5 | LL | 0 + { a } + 3; | ^^^^^^^^^ help: consider reducing it to: `({ a })` error: this operation has no effect - --> $DIR/identity_op.rs:97:5 + --> $DIR/identity_op.rs:96:5 | LL | 0 + { a } * 2; | ^^^^^^^^^^^^^ help: consider reducing it to: `({ a } * 2)` error: this operation has no effect - --> $DIR/identity_op.rs:98:5 + --> $DIR/identity_op.rs:97:5 | LL | 0 + loop { let mut c = 0; if c == 10 { break c; } c += 1; } + { a * 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(loop { let mut c = 0; if c == 10 { break c; } c += 1; })` error: this operation has no effect - --> $DIR/identity_op.rs:103:7 + --> $DIR/identity_op.rs:102:7 | LL | f(1 * a + { 8 * 5 }); | ^^^^^ help: consider reducing it to: `a` error: this operation has no effect - --> $DIR/identity_op.rs:104:7 + --> $DIR/identity_op.rs:103:7 | LL | f(0 + if b { 1 } else { 2 } + 3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `if b { 1 } else { 2 }` error: this operation has no effect - --> $DIR/identity_op.rs:105:20 + --> $DIR/identity_op.rs:104:20 | LL | const _: i32 = { 2 * 4 } + 0 + 3; | ^^^^^^^^^^^^^ help: consider reducing it to: `{ 2 * 4 }` error: this operation has no effect - --> $DIR/identity_op.rs:106:20 + --> $DIR/identity_op.rs:105:20 | LL | const _: i32 = 0 + { 1 + 2 * 3 } + 3; | ^^^^^^^^^^^^^^^^^ help: consider reducing it to: `{ 1 + 2 * 3 }` error: this operation has no effect - --> $DIR/identity_op.rs:108:5 + --> $DIR/identity_op.rs:107:5 | LL | 0 + a as usize; | ^^^^^^^^^^^^^^ help: consider reducing it to: `a as usize` error: this operation has no effect - --> $DIR/identity_op.rs:109:13 + --> $DIR/identity_op.rs:108:13 | LL | let _ = 0 + a as usize; | ^^^^^^^^^^^^^^ help: consider reducing it to: `a as usize` error: this operation has no effect - --> $DIR/identity_op.rs:110:5 + --> $DIR/identity_op.rs:109:5 | LL | 0 + { a } as usize; | ^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `({ a } as usize)` error: this operation has no effect - --> $DIR/identity_op.rs:112:9 + --> $DIR/identity_op.rs:111:9 | LL | 2 * (0 + { a }); | ^^^^^^^^^^^ help: consider reducing it to: `{ a }` error: this operation has no effect - --> $DIR/identity_op.rs:113:5 + --> $DIR/identity_op.rs:112:5 | LL | 1 * ({ a } + 4); | ^^^^^^^^^^^^^^^ help: consider reducing it to: `(({ a } + 4))` error: this operation has no effect - --> $DIR/identity_op.rs:114:5 + --> $DIR/identity_op.rs:113:5 | LL | 1 * 1; | ^^^^^ help: consider reducing it to: `1` error: this operation has no effect - --> $DIR/identity_op.rs:118:18 + --> $DIR/identity_op.rs:117:18 | LL | let _: i32 = &x + 0; | ^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:122:5 + --> $DIR/identity_op.rs:121:5 | LL | 0 + if a { 1 } else { 2 } + if b { 3 } else { 5 } | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if a { 1 } else { 2 })` diff --git a/tests/ui/ignored_unit_patterns.fixed b/tests/ui/ignored_unit_patterns.fixed index 492219fe44711..2912eede4d9b6 100644 --- a/tests/ui/ignored_unit_patterns.fixed +++ b/tests/ui/ignored_unit_patterns.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::ignored_unit_patterns)] #![allow(clippy::redundant_pattern_matching, clippy::single_match)] diff --git a/tests/ui/ignored_unit_patterns.rs b/tests/ui/ignored_unit_patterns.rs index 90af36f8e5ed8..d180cd8d2fd36 100644 --- a/tests/ui/ignored_unit_patterns.rs +++ b/tests/ui/ignored_unit_patterns.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::ignored_unit_patterns)] #![allow(clippy::redundant_pattern_matching, clippy::single_match)] diff --git a/tests/ui/ignored_unit_patterns.stderr b/tests/ui/ignored_unit_patterns.stderr index 8feea3cc2a835..6cb8b60ac0ce8 100644 --- a/tests/ui/ignored_unit_patterns.stderr +++ b/tests/ui/ignored_unit_patterns.stderr @@ -1,5 +1,5 @@ error: matching over `()` is more explicit - --> $DIR/ignored_unit_patterns.rs:12:12 + --> $DIR/ignored_unit_patterns.rs:10:12 | LL | Ok(_) => {}, | ^ help: use `()` instead of `_`: `()` @@ -7,19 +7,19 @@ LL | Ok(_) => {}, = note: `-D clippy::ignored-unit-patterns` implied by `-D warnings` error: matching over `()` is more explicit - --> $DIR/ignored_unit_patterns.rs:13:13 + --> $DIR/ignored_unit_patterns.rs:11:13 | LL | Err(_) => {}, | ^ help: use `()` instead of `_`: `()` error: matching over `()` is more explicit - --> $DIR/ignored_unit_patterns.rs:15:15 + --> $DIR/ignored_unit_patterns.rs:13:15 | LL | if let Ok(_) = foo() {} | ^ help: use `()` instead of `_`: `()` error: matching over `()` is more explicit - --> $DIR/ignored_unit_patterns.rs:16:28 + --> $DIR/ignored_unit_patterns.rs:14:28 | LL | let _ = foo().map_err(|_| todo!()); | ^ help: use `()` instead of `_`: `()` diff --git a/tests/ui/impl_trait_in_params.rs b/tests/ui/impl_trait_in_params.rs index 07560101a4167..8944f6b58fd43 100644 --- a/tests/ui/impl_trait_in_params.rs +++ b/tests/ui/impl_trait_in_params.rs @@ -1,6 +1,6 @@ #![allow(unused)] #![warn(clippy::impl_trait_in_params)] - +//@no-rustfix pub trait Trait {} pub trait AnotherTrait {} diff --git a/tests/ui/implicit_clone.fixed b/tests/ui/implicit_clone.fixed index e62db8b40be68..04644b111bffa 100644 --- a/tests/ui/implicit_clone.fixed +++ b/tests/ui/implicit_clone.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::implicit_clone)] #![allow(clippy::clone_on_copy, clippy::redundant_clone)] use std::borrow::Borrow; diff --git a/tests/ui/implicit_clone.rs b/tests/ui/implicit_clone.rs index 88352b06af3cb..a064bd23a338a 100644 --- a/tests/ui/implicit_clone.rs +++ b/tests/ui/implicit_clone.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::implicit_clone)] #![allow(clippy::clone_on_copy, clippy::redundant_clone)] use std::borrow::Borrow; diff --git a/tests/ui/implicit_clone.stderr b/tests/ui/implicit_clone.stderr index 92c1aa58affb2..0f4124241907f 100644 --- a/tests/ui/implicit_clone.stderr +++ b/tests/ui/implicit_clone.stderr @@ -1,5 +1,5 @@ error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:66:13 + --> $DIR/implicit_clone.rs:65:13 | LL | let _ = vec.to_owned(); | ^^^^^^^^^^^^^^ help: consider using: `vec.clone()` @@ -7,67 +7,67 @@ LL | let _ = vec.to_owned(); = note: `-D clippy::implicit-clone` implied by `-D warnings` error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type - --> $DIR/implicit_clone.rs:67:13 + --> $DIR/implicit_clone.rs:66:13 | LL | let _ = vec.to_vec(); | ^^^^^^^^^^^^ help: consider using: `vec.clone()` error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:71:13 + --> $DIR/implicit_clone.rs:70:13 | LL | let _ = vec_ref.to_owned(); | ^^^^^^^^^^^^^^^^^^ help: consider using: `vec_ref.clone()` error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type - --> $DIR/implicit_clone.rs:72:13 + --> $DIR/implicit_clone.rs:71:13 | LL | let _ = vec_ref.to_vec(); | ^^^^^^^^^^^^^^^^ help: consider using: `vec_ref.clone()` error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:84:13 + --> $DIR/implicit_clone.rs:83:13 | LL | let _ = str.to_owned(); | ^^^^^^^^^^^^^^ help: consider using: `str.clone()` error: implicitly cloning a `Kitten` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:88:13 + --> $DIR/implicit_clone.rs:87:13 | LL | let _ = kitten.to_owned(); | ^^^^^^^^^^^^^^^^^ help: consider using: `kitten.clone()` error: implicitly cloning a `PathBuf` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:98:13 + --> $DIR/implicit_clone.rs:97:13 | LL | let _ = pathbuf.to_owned(); | ^^^^^^^^^^^^^^^^^^ help: consider using: `pathbuf.clone()` error: implicitly cloning a `PathBuf` by calling `to_path_buf` on its dereferenced type - --> $DIR/implicit_clone.rs:99:13 + --> $DIR/implicit_clone.rs:98:13 | LL | let _ = pathbuf.to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `pathbuf.clone()` error: implicitly cloning a `OsString` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:102:13 + --> $DIR/implicit_clone.rs:101:13 | LL | let _ = os_string.to_owned(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `os_string.clone()` error: implicitly cloning a `OsString` by calling `to_os_string` on its dereferenced type - --> $DIR/implicit_clone.rs:103:13 + --> $DIR/implicit_clone.rs:102:13 | LL | let _ = os_string.to_os_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `os_string.clone()` error: implicitly cloning a `PathBuf` by calling `to_path_buf` on its dereferenced type - --> $DIR/implicit_clone.rs:114:13 + --> $DIR/implicit_clone.rs:113:13 | LL | let _ = pathbuf_ref.to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(*pathbuf_ref).clone()` error: implicitly cloning a `PathBuf` by calling `to_path_buf` on its dereferenced type - --> $DIR/implicit_clone.rs:117:13 + --> $DIR/implicit_clone.rs:116:13 | LL | let _ = pathbuf_ref.to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(**pathbuf_ref).clone()` diff --git a/tests/ui/implicit_hasher.rs b/tests/ui/implicit_hasher.rs index 7ed7bf94a4b3c..5e7fa4faf27dd 100644 --- a/tests/ui/implicit_hasher.rs +++ b/tests/ui/implicit_hasher.rs @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs:proc-macro - +//@no-rustfix #![deny(clippy::implicit_hasher)] #![allow(unused)] diff --git a/tests/ui/implicit_return.fixed b/tests/ui/implicit_return.fixed index 64813eafda644..897f1b7661638 100644 --- a/tests/ui/implicit_return.fixed +++ b/tests/ui/implicit_return.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![warn(clippy::implicit_return)] #![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)] diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs index 39d47b110db7f..fcff67b58071b 100644 --- a/tests/ui/implicit_return.rs +++ b/tests/ui/implicit_return.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![warn(clippy::implicit_return)] #![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)] diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 522bc3bf895a7..a761b42739530 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -1,5 +1,5 @@ error: missing `return` statement - --> $DIR/implicit_return.rs:12:5 + --> $DIR/implicit_return.rs:11:5 | LL | true | ^^^^ help: add `return` as shown: `return true` @@ -7,85 +7,85 @@ LL | true = note: `-D clippy::implicit-return` implied by `-D warnings` error: missing `return` statement - --> $DIR/implicit_return.rs:16:15 + --> $DIR/implicit_return.rs:15:15 | LL | if true { true } else { false } | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:16:29 + --> $DIR/implicit_return.rs:15:29 | LL | if true { true } else { false } | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:22:17 + --> $DIR/implicit_return.rs:21:17 | LL | true => false, | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:23:20 + --> $DIR/implicit_return.rs:22:20 | LL | false => { true }, | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:36:9 + --> $DIR/implicit_return.rs:35:9 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:43:13 + --> $DIR/implicit_return.rs:42:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:51:13 + --> $DIR/implicit_return.rs:50:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:69:18 + --> $DIR/implicit_return.rs:68:18 | LL | let _ = || { true }; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:70:16 + --> $DIR/implicit_return.rs:69:16 | LL | let _ = || true; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:78:5 + --> $DIR/implicit_return.rs:77:5 | LL | format!("test {}", "test") | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")` error: missing `return` statement - --> $DIR/implicit_return.rs:87:5 + --> $DIR/implicit_return.rs:86:5 | LL | m!(true, false) | ^^^^^^^^^^^^^^^ help: add `return` as shown: `return m!(true, false)` error: missing `return` statement - --> $DIR/implicit_return.rs:93:13 + --> $DIR/implicit_return.rs:92:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:98:17 + --> $DIR/implicit_return.rs:97:17 | LL | break 'outer false; | ^^^^^^^^^^^^^^^^^^ help: change `break` to `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:113:5 + --> $DIR/implicit_return.rs:112:5 | LL | / loop { LL | | m!(true); @@ -100,7 +100,7 @@ LL + } | error: missing `return` statement - --> $DIR/implicit_return.rs:127:5 + --> $DIR/implicit_return.rs:126:5 | LL | true | ^^^^ help: add `return` as shown: `return true` diff --git a/tests/ui/implicit_saturating_add.fixed b/tests/ui/implicit_saturating_add.fixed index 7fc510d6b415d..4cf8e3587b619 100644 --- a/tests/ui/implicit_saturating_add.fixed +++ b/tests/ui/implicit_saturating_add.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::implicit_saturating_add)] diff --git a/tests/ui/implicit_saturating_add.rs b/tests/ui/implicit_saturating_add.rs index 3dcd91f42fedb..94513f34c2621 100644 --- a/tests/ui/implicit_saturating_add.rs +++ b/tests/ui/implicit_saturating_add.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::implicit_saturating_add)] diff --git a/tests/ui/implicit_saturating_add.stderr b/tests/ui/implicit_saturating_add.stderr index 42ae1b488853d..cfd600c53c362 100644 --- a/tests/ui/implicit_saturating_add.stderr +++ b/tests/ui/implicit_saturating_add.stderr @@ -1,5 +1,5 @@ error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:23:5 + --> $DIR/implicit_saturating_add.rs:21:5 | LL | / if u_8 != u8::MAX { LL | | u_8 += 1; @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::implicit-saturating-add` implied by `-D warnings` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:27:5 + --> $DIR/implicit_saturating_add.rs:25:5 | LL | / if u_8 < u8::MAX { LL | | u_8 += 1; @@ -17,7 +17,7 @@ LL | | } | |_____^ help: use instead: `u_8 = u_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:35:5 + --> $DIR/implicit_saturating_add.rs:33:5 | LL | / if u_16 != u16::MAX { LL | | u_16 += 1; @@ -25,7 +25,7 @@ LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:39:5 + --> $DIR/implicit_saturating_add.rs:37:5 | LL | / if u_16 < u16::MAX { LL | | u_16 += 1; @@ -33,7 +33,7 @@ LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:43:5 + --> $DIR/implicit_saturating_add.rs:41:5 | LL | / if u16::MAX > u_16 { LL | | u_16 += 1; @@ -41,7 +41,7 @@ LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:47:5 + --> $DIR/implicit_saturating_add.rs:45:5 | LL | / if u_32 != u32::MAX { LL | | u_32 += 1; @@ -49,7 +49,7 @@ LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:51:5 + --> $DIR/implicit_saturating_add.rs:49:5 | LL | / if u_32 < u32::MAX { LL | | u_32 += 1; @@ -57,7 +57,7 @@ LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:55:5 + --> $DIR/implicit_saturating_add.rs:53:5 | LL | / if u32::MAX > u_32 { LL | | u_32 += 1; @@ -65,7 +65,7 @@ LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:59:5 + --> $DIR/implicit_saturating_add.rs:57:5 | LL | / if u_64 != u64::MAX { LL | | u_64 += 1; @@ -73,7 +73,7 @@ LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:63:5 + --> $DIR/implicit_saturating_add.rs:61:5 | LL | / if u_64 < u64::MAX { LL | | u_64 += 1; @@ -81,7 +81,7 @@ LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:67:5 + --> $DIR/implicit_saturating_add.rs:65:5 | LL | / if u64::MAX > u_64 { LL | | u_64 += 1; @@ -89,7 +89,7 @@ LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:71:5 + --> $DIR/implicit_saturating_add.rs:69:5 | LL | / if i_8 != i8::MAX { LL | | i_8 += 1; @@ -97,7 +97,7 @@ LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:75:5 + --> $DIR/implicit_saturating_add.rs:73:5 | LL | / if i_8 < i8::MAX { LL | | i_8 += 1; @@ -105,7 +105,7 @@ LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:79:5 + --> $DIR/implicit_saturating_add.rs:77:5 | LL | / if i8::MAX > i_8 { LL | | i_8 += 1; @@ -113,7 +113,7 @@ LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:83:5 + --> $DIR/implicit_saturating_add.rs:81:5 | LL | / if i_16 != i16::MAX { LL | | i_16 += 1; @@ -121,7 +121,7 @@ LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:87:5 + --> $DIR/implicit_saturating_add.rs:85:5 | LL | / if i_16 < i16::MAX { LL | | i_16 += 1; @@ -129,7 +129,7 @@ LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:91:5 + --> $DIR/implicit_saturating_add.rs:89:5 | LL | / if i16::MAX > i_16 { LL | | i_16 += 1; @@ -137,7 +137,7 @@ LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:95:5 + --> $DIR/implicit_saturating_add.rs:93:5 | LL | / if i_32 != i32::MAX { LL | | i_32 += 1; @@ -145,7 +145,7 @@ LL | | } | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:99:5 + --> $DIR/implicit_saturating_add.rs:97:5 | LL | / if i_32 < i32::MAX { LL | | i_32 += 1; @@ -153,7 +153,7 @@ LL | | } | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:103:5 + --> $DIR/implicit_saturating_add.rs:101:5 | LL | / if i32::MAX > i_32 { LL | | i_32 += 1; @@ -161,7 +161,7 @@ LL | | } | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:107:5 + --> $DIR/implicit_saturating_add.rs:105:5 | LL | / if i_64 != i64::MAX { LL | | i_64 += 1; @@ -169,7 +169,7 @@ LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:111:5 + --> $DIR/implicit_saturating_add.rs:109:5 | LL | / if i_64 < i64::MAX { LL | | i_64 += 1; @@ -177,7 +177,7 @@ LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:115:5 + --> $DIR/implicit_saturating_add.rs:113:5 | LL | / if i64::MAX > i_64 { LL | | i_64 += 1; @@ -185,7 +185,7 @@ LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:151:12 + --> $DIR/implicit_saturating_add.rs:149:12 | LL | } else if u_32 < u32::MAX { | ____________^ diff --git a/tests/ui/implicit_saturating_sub.fixed b/tests/ui/implicit_saturating_sub.fixed index 1a11db0982f7b..27f679797dd9e 100644 --- a/tests/ui/implicit_saturating_sub.fixed +++ b/tests/ui/implicit_saturating_sub.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)] #![warn(clippy::implicit_saturating_sub)] diff --git a/tests/ui/implicit_saturating_sub.rs b/tests/ui/implicit_saturating_sub.rs index 9369df67430c5..5d7b95d2c652f 100644 --- a/tests/ui/implicit_saturating_sub.rs +++ b/tests/ui/implicit_saturating_sub.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)] #![warn(clippy::implicit_saturating_sub)] diff --git a/tests/ui/implicit_saturating_sub.stderr b/tests/ui/implicit_saturating_sub.stderr index 5e589d931e431..75d8a88e8d43c 100644 --- a/tests/ui/implicit_saturating_sub.stderr +++ b/tests/ui/implicit_saturating_sub.stderr @@ -1,5 +1,5 @@ error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:28:5 + --> $DIR/implicit_saturating_sub.rs:27:5 | LL | / if u_8 > 0 { LL | | u_8 = u_8 - 1; @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::implicit-saturating-sub` implied by `-D warnings` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:35:13 + --> $DIR/implicit_saturating_sub.rs:34:13 | LL | / if u_8 > 0 { LL | | u_8 -= 1; @@ -17,7 +17,7 @@ LL | | } | |_____________^ help: try: `u_8 = u_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:49:5 + --> $DIR/implicit_saturating_sub.rs:48:5 | LL | / if u_16 > 0 { LL | | u_16 -= 1; @@ -25,7 +25,7 @@ LL | | } | |_____^ help: try: `u_16 = u_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:59:5 + --> $DIR/implicit_saturating_sub.rs:58:5 | LL | / if u_32 != 0 { LL | | u_32 -= 1; @@ -33,7 +33,7 @@ LL | | } | |_____^ help: try: `u_32 = u_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:80:5 + --> $DIR/implicit_saturating_sub.rs:79:5 | LL | / if u_64 > 0 { LL | | u_64 -= 1; @@ -41,7 +41,7 @@ LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:85:5 + --> $DIR/implicit_saturating_sub.rs:84:5 | LL | / if 0 < u_64 { LL | | u_64 -= 1; @@ -49,7 +49,7 @@ LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:90:5 + --> $DIR/implicit_saturating_sub.rs:89:5 | LL | / if 0 != u_64 { LL | | u_64 -= 1; @@ -57,7 +57,7 @@ LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:111:5 + --> $DIR/implicit_saturating_sub.rs:110:5 | LL | / if u_usize > 0 { LL | | u_usize -= 1; @@ -65,7 +65,7 @@ LL | | } | |_____^ help: try: `u_usize = u_usize.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:123:5 + --> $DIR/implicit_saturating_sub.rs:122:5 | LL | / if i_8 > i8::MIN { LL | | i_8 -= 1; @@ -73,7 +73,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:128:5 + --> $DIR/implicit_saturating_sub.rs:127:5 | LL | / if i_8 > i8::MIN { LL | | i_8 -= 1; @@ -81,7 +81,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:133:5 + --> $DIR/implicit_saturating_sub.rs:132:5 | LL | / if i_8 != i8::MIN { LL | | i_8 -= 1; @@ -89,7 +89,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:138:5 + --> $DIR/implicit_saturating_sub.rs:137:5 | LL | / if i_8 != i8::MIN { LL | | i_8 -= 1; @@ -97,7 +97,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:148:5 + --> $DIR/implicit_saturating_sub.rs:147:5 | LL | / if i_16 > i16::MIN { LL | | i_16 -= 1; @@ -105,7 +105,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:153:5 + --> $DIR/implicit_saturating_sub.rs:152:5 | LL | / if i_16 > i16::MIN { LL | | i_16 -= 1; @@ -113,7 +113,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:158:5 + --> $DIR/implicit_saturating_sub.rs:157:5 | LL | / if i_16 != i16::MIN { LL | | i_16 -= 1; @@ -121,7 +121,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:163:5 + --> $DIR/implicit_saturating_sub.rs:162:5 | LL | / if i_16 != i16::MIN { LL | | i_16 -= 1; @@ -129,7 +129,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:173:5 + --> $DIR/implicit_saturating_sub.rs:172:5 | LL | / if i_32 > i32::MIN { LL | | i_32 -= 1; @@ -137,7 +137,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:178:5 + --> $DIR/implicit_saturating_sub.rs:177:5 | LL | / if i_32 > i32::MIN { LL | | i_32 -= 1; @@ -145,7 +145,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:183:5 + --> $DIR/implicit_saturating_sub.rs:182:5 | LL | / if i_32 != i32::MIN { LL | | i_32 -= 1; @@ -153,7 +153,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:188:5 + --> $DIR/implicit_saturating_sub.rs:187:5 | LL | / if i_32 != i32::MIN { LL | | i_32 -= 1; @@ -161,7 +161,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:198:5 + --> $DIR/implicit_saturating_sub.rs:197:5 | LL | / if i64::MIN < i_64 { LL | | i_64 -= 1; @@ -169,7 +169,7 @@ LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:203:5 + --> $DIR/implicit_saturating_sub.rs:202:5 | LL | / if i64::MIN != i_64 { LL | | i_64 -= 1; @@ -177,7 +177,7 @@ LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:208:5 + --> $DIR/implicit_saturating_sub.rs:207:5 | LL | / if i64::MIN < i_64 { LL | | i_64 -= 1; diff --git a/tests/ui/inconsistent_digit_grouping.fixed b/tests/ui/inconsistent_digit_grouping.fixed index 06919809ee926..3f1dfbbae97bd 100644 --- a/tests/ui/inconsistent_digit_grouping.fixed +++ b/tests/ui/inconsistent_digit_grouping.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #[warn(clippy::inconsistent_digit_grouping)] #[deny(clippy::unreadable_literal)] #[allow(unused_variables, clippy::excessive_precision)] diff --git a/tests/ui/inconsistent_digit_grouping.rs b/tests/ui/inconsistent_digit_grouping.rs index 04d9125f2bfa9..ac47ae1759483 100644 --- a/tests/ui/inconsistent_digit_grouping.rs +++ b/tests/ui/inconsistent_digit_grouping.rs @@ -1,4 +1,3 @@ -//@run-rustfix #[warn(clippy::inconsistent_digit_grouping)] #[deny(clippy::unreadable_literal)] #[allow(unused_variables, clippy::excessive_precision)] diff --git a/tests/ui/inconsistent_digit_grouping.stderr b/tests/ui/inconsistent_digit_grouping.stderr index b8ac915546200..485c1fdb9120d 100644 --- a/tests/ui/inconsistent_digit_grouping.stderr +++ b/tests/ui/inconsistent_digit_grouping.stderr @@ -1,5 +1,5 @@ error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:16 + --> $DIR/inconsistent_digit_grouping.rs:25:16 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^ help: consider: `123_456` @@ -7,61 +7,61 @@ LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:26 + --> $DIR/inconsistent_digit_grouping.rs:25:26 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^^^ help: consider: `12_345_678` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:38 + --> $DIR/inconsistent_digit_grouping.rs:25:38 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^ help: consider: `1_234_567` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:48 + --> $DIR/inconsistent_digit_grouping.rs:25:48 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^^^^^^^ help: consider: `1_234.567_8_f32` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:64 + --> $DIR/inconsistent_digit_grouping.rs:25:64 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^^^^^^^ help: consider: `1.234_567_8_f32` error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:29:13 + --> $DIR/inconsistent_digit_grouping.rs:28:13 | LL | let _ = 0x100000; | ^^^^^^^^ help: consider: `0x0010_0000` | note: the lint level is defined here - --> $DIR/inconsistent_digit_grouping.rs:3:8 + --> $DIR/inconsistent_digit_grouping.rs:2:8 | LL | #[deny(clippy::unreadable_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:30:13 + --> $DIR/inconsistent_digit_grouping.rs:29:13 | LL | let _ = 0x1000000; | ^^^^^^^^^ help: consider: `0x0100_0000` error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:31:13 + --> $DIR/inconsistent_digit_grouping.rs:30:13 | LL | let _ = 0x10000000; | ^^^^^^^^^^ help: consider: `0x1000_0000` error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:32:13 + --> $DIR/inconsistent_digit_grouping.rs:31:13 | LL | let _ = 0x100000000_u64; | ^^^^^^^^^^^^^^^ help: consider: `0x0001_0000_0000_u64` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:35:18 + --> $DIR/inconsistent_digit_grouping.rs:34:18 | LL | let _: f32 = 1_23_456.; | ^^^^^^^^^ help: consider: `123_456.` diff --git a/tests/ui/inconsistent_struct_constructor.fixed b/tests/ui/inconsistent_struct_constructor.fixed index d84346e8789d5..3c33e9c5611bd 100644 --- a/tests/ui/inconsistent_struct_constructor.fixed +++ b/tests/ui/inconsistent_struct_constructor.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::inconsistent_struct_constructor)] diff --git a/tests/ui/inconsistent_struct_constructor.rs b/tests/ui/inconsistent_struct_constructor.rs index 87fba7448e3a3..a3360582f1a2d 100644 --- a/tests/ui/inconsistent_struct_constructor.rs +++ b/tests/ui/inconsistent_struct_constructor.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::inconsistent_struct_constructor)] diff --git a/tests/ui/inconsistent_struct_constructor.stderr b/tests/ui/inconsistent_struct_constructor.stderr index 785a6dc9d53ad..a2bee121ebf2f 100644 --- a/tests/ui/inconsistent_struct_constructor.stderr +++ b/tests/ui/inconsistent_struct_constructor.stderr @@ -1,5 +1,5 @@ error: struct constructor field order is inconsistent with struct definition field order - --> $DIR/inconsistent_struct_constructor.rs:29:9 + --> $DIR/inconsistent_struct_constructor.rs:28:9 | LL | Foo { y, x, z }; | ^^^^^^^^^^^^^^^ help: try: `Foo { x, y, z }` @@ -7,7 +7,7 @@ LL | Foo { y, x, z }; = note: `-D clippy::inconsistent-struct-constructor` implied by `-D warnings` error: struct constructor field order is inconsistent with struct definition field order - --> $DIR/inconsistent_struct_constructor.rs:56:9 + --> $DIR/inconsistent_struct_constructor.rs:55:9 | LL | / Foo { LL | | z, diff --git a/tests/ui/incorrect_clone_impl_on_copy_type.fixed b/tests/ui/incorrect_clone_impl_on_copy_type.fixed index ac482dcda1eee..165702b304118 100644 --- a/tests/ui/incorrect_clone_impl_on_copy_type.fixed +++ b/tests/ui/incorrect_clone_impl_on_copy_type.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::clone_on_copy, unused)] #![no_main] diff --git a/tests/ui/incorrect_clone_impl_on_copy_type.rs b/tests/ui/incorrect_clone_impl_on_copy_type.rs index 00775874ff585..3b07dd5ce62f2 100644 --- a/tests/ui/incorrect_clone_impl_on_copy_type.rs +++ b/tests/ui/incorrect_clone_impl_on_copy_type.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::clone_on_copy, unused)] #![no_main] diff --git a/tests/ui/incorrect_clone_impl_on_copy_type.stderr b/tests/ui/incorrect_clone_impl_on_copy_type.stderr index 7bcba8ba45a24..566a1a4b14b58 100644 --- a/tests/ui/incorrect_clone_impl_on_copy_type.stderr +++ b/tests/ui/incorrect_clone_impl_on_copy_type.stderr @@ -1,5 +1,5 @@ error: incorrect implementation of `clone` on a `Copy` type - --> $DIR/incorrect_clone_impl_on_copy_type.rs:10:29 + --> $DIR/incorrect_clone_impl_on_copy_type.rs:9:29 | LL | fn clone(&self) -> Self { | _____________________________^ @@ -10,7 +10,7 @@ LL | | } = note: `#[deny(clippy::incorrect_clone_impl_on_copy_type)]` on by default error: incorrect implementation of `clone_from` on a `Copy` type - --> $DIR/incorrect_clone_impl_on_copy_type.rs:14:5 + --> $DIR/incorrect_clone_impl_on_copy_type.rs:13:5 | LL | / fn clone_from(&mut self, source: &Self) { LL | | source.clone(); @@ -19,7 +19,7 @@ LL | | } | |_____^ help: remove it error: incorrect implementation of `clone` on a `Copy` type - --> $DIR/incorrect_clone_impl_on_copy_type.rs:81:29 + --> $DIR/incorrect_clone_impl_on_copy_type.rs:80:29 | LL | fn clone(&self) -> Self { | _____________________________^ @@ -28,7 +28,7 @@ LL | | } | |_____^ help: change this to: `{ *self }` error: incorrect implementation of `clone_from` on a `Copy` type - --> $DIR/incorrect_clone_impl_on_copy_type.rs:85:5 + --> $DIR/incorrect_clone_impl_on_copy_type.rs:84:5 | LL | / fn clone_from(&mut self, source: &Self) { LL | | source.clone(); diff --git a/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed b/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed index 2f51bf274804f..db55cc094e3ac 100644 --- a/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed +++ b/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![no_main] use std::cmp::Ordering; diff --git a/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs b/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs index 47127bdaec229..52f4b85b9172f 100644 --- a/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs +++ b/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![no_main] use std::cmp::Ordering; diff --git a/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr b/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr index 66048fc90005b..1f706984662b6 100644 --- a/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr +++ b/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr @@ -1,5 +1,5 @@ error: incorrect implementation of `partial_cmp` on an `Ord` type - --> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:17:1 + --> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:16:1 | LL | / impl PartialOrd for A { LL | | fn partial_cmp(&self, other: &Self) -> Option { @@ -13,7 +13,7 @@ LL | | } = note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default error: incorrect implementation of `partial_cmp` on an `Ord` type - --> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:51:1 + --> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:50:1 | LL | / impl PartialOrd for C { LL | | fn partial_cmp(&self, _: &Self) -> Option { diff --git a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs index 3a3b84f93c462..2f8d5cf30c77a 100644 --- a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs +++ b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs @@ -2,7 +2,7 @@ // is not in scope. #![no_main] #![no_implicit_prelude] - +//@no-rustfix extern crate std; use std::cmp::{self, Eq, Ordering, PartialEq, PartialOrd}; diff --git a/tests/ui/index_refutable_slice/if_let_slice_binding.fixed b/tests/ui/index_refutable_slice/if_let_slice_binding.fixed new file mode 100644 index 0000000000000..1f0a9ca25a494 --- /dev/null +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.fixed @@ -0,0 +1,167 @@ +#![deny(clippy::index_refutable_slice)] +#![allow(clippy::uninlined_format_args)] + +enum SomeEnum { + One(T), + Two(T), + Three(T), + Four(T), +} + +fn lintable_examples() { + // Try with reference + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some([slice_0, ..]) = slice { + println!("{}", slice_0); + } + + // Try with copy + let slice: Option<[u32; 3]> = Some([1, 2, 3]); + if let Some([slice_0, ..]) = slice { + println!("{}", slice_0); + } + + // Try with long slice and small indices + let slice: Option<[u32; 9]> = Some([1, 2, 3, 4, 5, 6, 7, 8, 9]); + if let Some([slice_0, _, slice_2, ..]) = slice { + println!("{}", slice_2); + println!("{}", slice_0); + } + + // Multiple bindings + let slice_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([5, 6, 7]); + if let SomeEnum::One([slice_0, ..]) | SomeEnum::Three([slice_0, ..]) = slice_wrapped { + println!("{}", slice_0); + } + + // Two lintable slices in one if let + let a_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([9, 5, 1]); + let b_wrapped: Option<[u32; 2]> = Some([4, 6]); + if let (SomeEnum::Three([_, _, a_2, ..]), Some([_, b_1, ..])) = (a_wrapped, b_wrapped) { + println!("{} -> {}", a_2, b_1); + } + + // This requires the slice values to be borrowed as the slice values can only be + // borrowed and `String` doesn't implement copy + let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); + if let Some([_, ref slice_1, ..]) = slice { + println!("{:?}", slice_1); + } + println!("{:?}", slice); + + // This should not suggest using the `ref` keyword as the scrutinee is already + // a reference + let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); + if let Some([slice_0, ..]) = &slice { + println!("{:?}", slice_0); + } + println!("{:?}", slice); +} + +fn slice_index_above_limit() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + + if let Some(slice) = slice { + // Would cause a panic, IDK + println!("{}", slice[7]); + } +} + +fn slice_is_used() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice) = slice { + println!("{:?}", slice.len()); + } + + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice) = slice { + println!("{:?}", slice.to_vec()); + } + + let opt: Option<[String; 2]> = Some([String::from("Hello"), String::from("world")]); + if let Some(slice) = opt { + if !slice.is_empty() { + println!("first: {}", slice[0]); + } + } +} + +/// The slice is used by an external function and should therefore not be linted +fn check_slice_as_arg() { + fn is_interesting(slice: &[T; 2]) -> bool { + !slice.is_empty() + } + + let slice_wrapped: Option<[String; 2]> = Some([String::from("Hello"), String::from("world")]); + if let Some(slice) = &slice_wrapped { + if is_interesting(slice) { + println!("This is interesting {}", slice[0]); + } + } + println!("{:?}", slice_wrapped); +} + +fn check_slice_in_struct() { + #[derive(Debug)] + struct Wrapper<'a> { + inner: Option<&'a [String]>, + is_awesome: bool, + } + + impl<'a> Wrapper<'a> { + fn is_super_awesome(&self) -> bool { + self.is_awesome + } + } + + let inner = &[String::from("New"), String::from("World")]; + let wrap = Wrapper { + inner: Some(inner), + is_awesome: true, + }; + + // Test 1: Field access + if let Some([slice_0, ..]) = wrap.inner { + if wrap.is_awesome { + println!("This is awesome! {}", slice_0); + } + } + + // Test 2: function access + if let Some([slice_0, ..]) = wrap.inner { + if wrap.is_super_awesome() { + println!("This is super awesome! {}", slice_0); + } + } + println!("Complete wrap: {:?}", wrap); +} + +/// This would be a nice additional feature to have in the future, but adding it +/// now would make the PR too large. This is therefore only a test that we don't +/// lint cases we can't make a reasonable suggestion for +fn mutable_slice_index() { + // Mut access + let mut slice: Option<[String; 1]> = Some([String::from("Penguin")]); + if let Some(ref mut slice) = slice { + slice[0] = String::from("Mr. Penguin"); + } + println!("Use after modification: {:?}", slice); + + // Mut access on reference + let mut slice: Option<[String; 1]> = Some([String::from("Cat")]); + if let Some(slice) = &mut slice { + slice[0] = String::from("Lord Meow Meow"); + } + println!("Use after modification: {:?}", slice); +} + +/// The lint will ignore bindings with sub patterns as it would be hard +/// to build correct suggestions for these instances :) +fn binding_with_sub_pattern() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice @ [_, _, _]) = slice { + println!("{:?}", slice[2]); + } +} + +fn main() {} diff --git a/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed b/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed new file mode 100644 index 0000000000000..d07b469cf3f01 --- /dev/null +++ b/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed @@ -0,0 +1,28 @@ +#![deny(clippy::index_refutable_slice)] + +extern crate if_chain; +use if_chain::if_chain; + +macro_rules! if_let_slice_macro { + () => { + // This would normally be linted + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice) = slice { + println!("{}", slice[0]); + } + }; +} + +fn main() { + // Don't lint this + if_let_slice_macro!(); + + // Do lint this + if_chain! { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some([slice_0, ..]) = slice; + then { + println!("{}", slice_0); + } + } +} diff --git a/tests/ui/inefficient_to_string.fixed b/tests/ui/inefficient_to_string.fixed index 557f7fb73585d..1e19323113c5e 100644 --- a/tests/ui/inefficient_to_string.fixed +++ b/tests/ui/inefficient_to_string.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::inefficient_to_string)] use std::borrow::Cow; diff --git a/tests/ui/inefficient_to_string.rs b/tests/ui/inefficient_to_string.rs index 6503001e345bc..f027bae6fe34f 100644 --- a/tests/ui/inefficient_to_string.rs +++ b/tests/ui/inefficient_to_string.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::inefficient_to_string)] use std::borrow::Cow; diff --git a/tests/ui/inefficient_to_string.stderr b/tests/ui/inefficient_to_string.stderr index 914dc92bfb65a..4b93465c4f9dd 100644 --- a/tests/ui/inefficient_to_string.stderr +++ b/tests/ui/inefficient_to_string.stderr @@ -1,18 +1,18 @@ error: calling `to_string` on `&&str` - --> $DIR/inefficient_to_string.rs:11:21 + --> $DIR/inefficient_to_string.rs:10:21 | LL | let _: String = rrstr.to_string(); | ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstr).to_string()` | = help: `&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString` note: the lint level is defined here - --> $DIR/inefficient_to_string.rs:2:9 + --> $DIR/inefficient_to_string.rs:1:9 | LL | #![deny(clippy::inefficient_to_string)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `to_string` on `&&&str` - --> $DIR/inefficient_to_string.rs:12:21 + --> $DIR/inefficient_to_string.rs:11:21 | LL | let _: String = rrrstr.to_string(); | ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstr).to_string()` @@ -20,7 +20,7 @@ LL | let _: String = rrrstr.to_string(); = help: `&&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString` error: calling `to_string` on `&&std::string::String` - --> $DIR/inefficient_to_string.rs:20:21 + --> $DIR/inefficient_to_string.rs:19:21 | LL | let _: String = rrstring.to_string(); | ^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstring).to_string()` @@ -28,7 +28,7 @@ LL | let _: String = rrstring.to_string(); = help: `&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString` error: calling `to_string` on `&&&std::string::String` - --> $DIR/inefficient_to_string.rs:21:21 + --> $DIR/inefficient_to_string.rs:20:21 | LL | let _: String = rrrstring.to_string(); | ^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstring).to_string()` @@ -36,7 +36,7 @@ LL | let _: String = rrrstring.to_string(); = help: `&&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString` error: calling `to_string` on `&&std::borrow::Cow<'_, str>` - --> $DIR/inefficient_to_string.rs:29:21 + --> $DIR/inefficient_to_string.rs:28:21 | LL | let _: String = rrcow.to_string(); | ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrcow).to_string()` @@ -44,7 +44,7 @@ LL | let _: String = rrcow.to_string(); = help: `&std::borrow::Cow<'_, str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<'_, str>` has a fast specialization of `ToString` error: calling `to_string` on `&&&std::borrow::Cow<'_, str>` - --> $DIR/inefficient_to_string.rs:30:21 + --> $DIR/inefficient_to_string.rs:29:21 | LL | let _: String = rrrcow.to_string(); | ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()` diff --git a/tests/ui/infallible_destructuring_match.fixed b/tests/ui/infallible_destructuring_match.fixed index e396ae94aaab2..60304177b4242 100644 --- a/tests/ui/infallible_destructuring_match.fixed +++ b/tests/ui/infallible_destructuring_match.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(exhaustive_patterns, never_type)] #![allow(dead_code, unreachable_code, unused_variables)] #![allow(clippy::let_and_return)] diff --git a/tests/ui/infallible_destructuring_match.rs b/tests/ui/infallible_destructuring_match.rs index 3fce7bbb6c712..b77aac4a16c10 100644 --- a/tests/ui/infallible_destructuring_match.rs +++ b/tests/ui/infallible_destructuring_match.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(exhaustive_patterns, never_type)] #![allow(dead_code, unreachable_code, unused_variables)] #![allow(clippy::let_and_return)] diff --git a/tests/ui/infallible_destructuring_match.stderr b/tests/ui/infallible_destructuring_match.stderr index 004260a1d648e..ada02741692f5 100644 --- a/tests/ui/infallible_destructuring_match.stderr +++ b/tests/ui/infallible_destructuring_match.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:29:5 + --> $DIR/infallible_destructuring_match.rs:28:5 | LL | / let data = match wrapper { LL | | SingleVariantEnum::Variant(i) => i, @@ -9,7 +9,7 @@ LL | | }; = note: `-D clippy::infallible-destructuring-match` implied by `-D warnings` error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:61:5 + --> $DIR/infallible_destructuring_match.rs:60:5 | LL | / let data = match wrapper { LL | | TupleStruct(i) => i, @@ -17,7 +17,7 @@ LL | | }; | |______^ help: try: `let TupleStruct(data) = wrapper;` error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:85:5 + --> $DIR/infallible_destructuring_match.rs:84:5 | LL | / let data = match wrapper { LL | | TupleStructWithNonCopy(ref n) => n, @@ -25,7 +25,7 @@ LL | | }; | |______^ help: try: `let TupleStructWithNonCopy(ref data) = wrapper;` error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let` - --> $DIR/infallible_destructuring_match.rs:104:5 + --> $DIR/infallible_destructuring_match.rs:103:5 | LL | / let data = match wrapper { LL | | Ok(i) => i, diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs index 38e64b9ac0ada..d68889751d86a 100644 --- a/tests/ui/infinite_loop.rs +++ b/tests/ui/infinite_loop.rs @@ -1,3 +1,5 @@ +//@no-rustfix + fn fn_val(i: i32) -> i32 { unimplemented!() } diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 04559f9ada431..2312612d3aa00 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -1,5 +1,5 @@ error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:20:11 + --> $DIR/infinite_loop.rs:22:11 | LL | while y < 10 { | ^^^^^^ @@ -8,7 +8,7 @@ LL | while y < 10 { = note: `#[deny(clippy::while_immutable_condition)]` on by default error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:25:11 + --> $DIR/infinite_loop.rs:27:11 | LL | while y < 10 && x < 3 { | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | while y < 10 && x < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:32:11 + --> $DIR/infinite_loop.rs:34:11 | LL | while !cond { | ^^^^^ @@ -24,7 +24,7 @@ LL | while !cond { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:76:11 + --> $DIR/infinite_loop.rs:78:11 | LL | while i < 3 { | ^^^^^ @@ -32,7 +32,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:81:11 + --> $DIR/infinite_loop.rs:83:11 | LL | while i < 3 && j > 0 { | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | while i < 3 && j > 0 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:85:11 + --> $DIR/infinite_loop.rs:87:11 | LL | while i < 3 { | ^^^^^ @@ -48,7 +48,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:100:11 + --> $DIR/infinite_loop.rs:102:11 | LL | while i < 3 { | ^^^^^ @@ -56,7 +56,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:105:11 + --> $DIR/infinite_loop.rs:107:11 | LL | while i < 3 { | ^^^^^ @@ -64,7 +64,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:171:15 + --> $DIR/infinite_loop.rs:173:15 | LL | while self.count < n { | ^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | while self.count < n { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:179:11 + --> $DIR/infinite_loop.rs:181:11 | LL | while y < 10 { | ^^^^^^ @@ -82,7 +82,7 @@ LL | while y < 10 { = help: rewrite it as `if cond { loop { } }` error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:186:11 + --> $DIR/infinite_loop.rs:188:11 | LL | while y < 10 { | ^^^^^^ @@ -92,7 +92,7 @@ LL | while y < 10 { = help: rewrite it as `if cond { loop { } }` error: this argument is a mutable reference, but not used mutably - --> $DIR/infinite_loop.rs:7:17 + --> $DIR/infinite_loop.rs:9:17 | LL | fn fn_mutref(i: &mut i32) { | ^^^^^^^^ help: consider changing to: `&i32` diff --git a/tests/ui/inline_fn_without_body.fixed b/tests/ui/inline_fn_without_body.fixed index 9c5819558feab..acd808ed49bb7 100644 --- a/tests/ui/inline_fn_without_body.fixed +++ b/tests/ui/inline_fn_without_body.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::inline_fn_without_body)] #![allow(clippy::inline_always)] diff --git a/tests/ui/inline_fn_without_body.rs b/tests/ui/inline_fn_without_body.rs index 43ffaf8122b6d..af81feaa374a7 100644 --- a/tests/ui/inline_fn_without_body.rs +++ b/tests/ui/inline_fn_without_body.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::inline_fn_without_body)] #![allow(clippy::inline_always)] diff --git a/tests/ui/inline_fn_without_body.stderr b/tests/ui/inline_fn_without_body.stderr index 32d35e209b01b..87d2da71280d8 100644 --- a/tests/ui/inline_fn_without_body.stderr +++ b/tests/ui/inline_fn_without_body.stderr @@ -1,5 +1,5 @@ error: use of `#[inline]` on trait method `default_inline` which has no body - --> $DIR/inline_fn_without_body.rs:7:5 + --> $DIR/inline_fn_without_body.rs:5:5 | LL | #[inline] | _____-^^^^^^^^ @@ -9,7 +9,7 @@ LL | | fn default_inline(); = note: `-D clippy::inline-fn-without-body` implied by `-D warnings` error: use of `#[inline]` on trait method `always_inline` which has no body - --> $DIR/inline_fn_without_body.rs:10:5 + --> $DIR/inline_fn_without_body.rs:8:5 | LL | #[inline(always)] | _____-^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | | fn always_inline(); | |____- help: remove error: use of `#[inline]` on trait method `never_inline` which has no body - --> $DIR/inline_fn_without_body.rs:13:5 + --> $DIR/inline_fn_without_body.rs:11:5 | LL | #[inline(never)] | _____-^^^^^^^^^^^^^^^ diff --git a/tests/ui/int_plus_one.fixed b/tests/ui/int_plus_one.fixed index 5a36ec462d4c6..77d9cd3f773a9 100644 --- a/tests/ui/int_plus_one.fixed +++ b/tests/ui/int_plus_one.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[allow(clippy::no_effect, clippy::unnecessary_operation)] #[warn(clippy::int_plus_one)] fn main() { diff --git a/tests/ui/int_plus_one.rs b/tests/ui/int_plus_one.rs index bffa4afd6b080..57c87819dbfe9 100644 --- a/tests/ui/int_plus_one.rs +++ b/tests/ui/int_plus_one.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[allow(clippy::no_effect, clippy::unnecessary_operation)] #[warn(clippy::int_plus_one)] fn main() { diff --git a/tests/ui/int_plus_one.stderr b/tests/ui/int_plus_one.stderr index c5b020ba8ced5..a0c5b32a205f4 100644 --- a/tests/ui/int_plus_one.stderr +++ b/tests/ui/int_plus_one.stderr @@ -1,5 +1,5 @@ error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:9:13 + --> $DIR/int_plus_one.rs:7:13 | LL | let _ = x >= y + 1; | ^^^^^^^^^^ help: change it to: `x > y` @@ -7,19 +7,19 @@ LL | let _ = x >= y + 1; = note: `-D clippy::int-plus-one` implied by `-D warnings` error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:10:13 + --> $DIR/int_plus_one.rs:8:13 | LL | let _ = y + 1 <= x; | ^^^^^^^^^^ help: change it to: `y < x` error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:12:13 + --> $DIR/int_plus_one.rs:10:13 | LL | let _ = x - 1 >= y; | ^^^^^^^^^^ help: change it to: `x > y` error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:13:13 + --> $DIR/int_plus_one.rs:11:13 | LL | let _ = y <= x - 1; | ^^^^^^^^^^ help: change it to: `y < x` diff --git a/tests/ui/into_iter_on_ref.fixed b/tests/ui/into_iter_on_ref.fixed index af197e33fd835..c03d91c797c8d 100644 --- a/tests/ui/into_iter_on_ref.fixed +++ b/tests/ui/into_iter_on_ref.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::useless_vec, clippy::needless_borrow)] #![warn(clippy::into_iter_on_ref)] diff --git a/tests/ui/into_iter_on_ref.rs b/tests/ui/into_iter_on_ref.rs index 3ac13d7dd3e1d..93c732fd6ccf9 100644 --- a/tests/ui/into_iter_on_ref.rs +++ b/tests/ui/into_iter_on_ref.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::useless_vec, clippy::needless_borrow)] #![warn(clippy::into_iter_on_ref)] diff --git a/tests/ui/into_iter_on_ref.stderr b/tests/ui/into_iter_on_ref.stderr index 06014a93f8c18..2c81518d8db4c 100644 --- a/tests/ui/into_iter_on_ref.stderr +++ b/tests/ui/into_iter_on_ref.stderr @@ -1,5 +1,5 @@ error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec` - --> $DIR/into_iter_on_ref.rs:14:30 + --> $DIR/into_iter_on_ref.rs:13:30 | LL | let _ = (&vec![1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` @@ -7,157 +7,157 @@ LL | let _ = (&vec![1, 2, 3]).into_iter(); = note: `-D clippy::into-iter-on-ref` implied by `-D warnings` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> $DIR/into_iter_on_ref.rs:15:46 + --> $DIR/into_iter_on_ref.rs:14:46 | LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> $DIR/into_iter_on_ref.rs:16:41 + --> $DIR/into_iter_on_ref.rs:15:41 | LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> $DIR/into_iter_on_ref.rs:17:44 + --> $DIR/into_iter_on_ref.rs:16:44 | LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:19:32 + --> $DIR/into_iter_on_ref.rs:18:32 | LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:20:36 + --> $DIR/into_iter_on_ref.rs:19:36 | LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:21:40 + --> $DIR/into_iter_on_ref.rs:20:40 | LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Option` - --> $DIR/into_iter_on_ref.rs:23:24 + --> $DIR/into_iter_on_ref.rs:22:24 | LL | let _ = (&Some(4)).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Option` - --> $DIR/into_iter_on_ref.rs:24:28 + --> $DIR/into_iter_on_ref.rs:23:28 | LL | let _ = (&mut Some(5)).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Result` - --> $DIR/into_iter_on_ref.rs:25:32 + --> $DIR/into_iter_on_ref.rs:24:32 | LL | let _ = (&Ok::<_, i32>(6)).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Result` - --> $DIR/into_iter_on_ref.rs:26:37 + --> $DIR/into_iter_on_ref.rs:25:37 | LL | let _ = (&mut Err::(7)).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec` - --> $DIR/into_iter_on_ref.rs:27:34 + --> $DIR/into_iter_on_ref.rs:26:34 | LL | let _ = (&Vec::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Vec` - --> $DIR/into_iter_on_ref.rs:28:38 + --> $DIR/into_iter_on_ref.rs:27:38 | LL | let _ = (&mut Vec::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BTreeMap` - --> $DIR/into_iter_on_ref.rs:29:44 + --> $DIR/into_iter_on_ref.rs:28:44 | LL | let _ = (&BTreeMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `BTreeMap` - --> $DIR/into_iter_on_ref.rs:30:48 + --> $DIR/into_iter_on_ref.rs:29:48 | LL | let _ = (&mut BTreeMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `VecDeque` - --> $DIR/into_iter_on_ref.rs:31:39 + --> $DIR/into_iter_on_ref.rs:30:39 | LL | let _ = (&VecDeque::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `VecDeque` - --> $DIR/into_iter_on_ref.rs:32:43 + --> $DIR/into_iter_on_ref.rs:31:43 | LL | let _ = (&mut VecDeque::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `LinkedList` - --> $DIR/into_iter_on_ref.rs:33:41 + --> $DIR/into_iter_on_ref.rs:32:41 | LL | let _ = (&LinkedList::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `LinkedList` - --> $DIR/into_iter_on_ref.rs:34:45 + --> $DIR/into_iter_on_ref.rs:33:45 | LL | let _ = (&mut LinkedList::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `HashMap` - --> $DIR/into_iter_on_ref.rs:35:43 + --> $DIR/into_iter_on_ref.rs:34:43 | LL | let _ = (&HashMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `HashMap` - --> $DIR/into_iter_on_ref.rs:36:47 + --> $DIR/into_iter_on_ref.rs:35:47 | LL | let _ = (&mut HashMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BTreeSet` - --> $DIR/into_iter_on_ref.rs:38:39 + --> $DIR/into_iter_on_ref.rs:37:39 | LL | let _ = (&BTreeSet::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BinaryHeap` - --> $DIR/into_iter_on_ref.rs:39:41 + --> $DIR/into_iter_on_ref.rs:38:41 | LL | let _ = (&BinaryHeap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `HashSet` - --> $DIR/into_iter_on_ref.rs:40:38 + --> $DIR/into_iter_on_ref.rs:39:38 | LL | let _ = (&HashSet::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Path` - --> $DIR/into_iter_on_ref.rs:41:43 + --> $DIR/into_iter_on_ref.rs:40:43 | LL | let _ = std::path::Path::new("12/34").into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `PathBuf` - --> $DIR/into_iter_on_ref.rs:42:47 + --> $DIR/into_iter_on_ref.rs:41:47 | LL | let _ = std::path::PathBuf::from("12/34").into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:44:26 + --> $DIR/into_iter_on_ref.rs:43:26 | LL | let _ = (&[1, 2, 3]).into_iter().next(); | ^^^^^^^^^ help: call directly: `iter` diff --git a/tests/ui/invalid_null_ptr_usage.fixed b/tests/ui/invalid_null_ptr_usage.fixed index 9264fb7e9e7d8..eeddc2349a133 100644 --- a/tests/ui/invalid_null_ptr_usage.fixed +++ b/tests/ui/invalid_null_ptr_usage.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - fn main() { unsafe { let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); diff --git a/tests/ui/invalid_null_ptr_usage.rs b/tests/ui/invalid_null_ptr_usage.rs index 80c942d775729..8569b77408458 100644 --- a/tests/ui/invalid_null_ptr_usage.rs +++ b/tests/ui/invalid_null_ptr_usage.rs @@ -1,5 +1,3 @@ -//@run-rustfix - fn main() { unsafe { let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); diff --git a/tests/ui/invalid_null_ptr_usage.stderr b/tests/ui/invalid_null_ptr_usage.stderr index 532c36abe5196..22efa0d84ad42 100644 --- a/tests/ui/invalid_null_ptr_usage.stderr +++ b/tests/ui/invalid_null_ptr_usage.stderr @@ -1,5 +1,5 @@ error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:5:59 + --> $DIR/invalid_null_ptr_usage.rs:3:59 | LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` @@ -7,145 +7,145 @@ LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), = note: `#[deny(clippy::invalid_null_ptr_usage)]` on by default error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:6:59 + --> $DIR/invalid_null_ptr_usage.rs:4:59 | LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:8:63 + --> $DIR/invalid_null_ptr_usage.rs:6:63 | LL | let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:10:33 + --> $DIR/invalid_null_ptr_usage.rs:8:33 | LL | std::ptr::copy::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:11:73 + --> $DIR/invalid_null_ptr_usage.rs:9:73 | LL | std::ptr::copy::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:13:48 + --> $DIR/invalid_null_ptr_usage.rs:11:48 | LL | std::ptr::copy_nonoverlapping::(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:14:88 + --> $DIR/invalid_null_ptr_usage.rs:12:88 | LL | std::ptr::copy_nonoverlapping::(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:19:36 + --> $DIR/invalid_null_ptr_usage.rs:17:36 | LL | let _a: A = std::ptr::read(std::ptr::null()); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:20:36 + --> $DIR/invalid_null_ptr_usage.rs:18:36 | LL | let _a: A = std::ptr::read(std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:22:46 + --> $DIR/invalid_null_ptr_usage.rs:20:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null()); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:23:46 + --> $DIR/invalid_null_ptr_usage.rs:21:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:25:45 + --> $DIR/invalid_null_ptr_usage.rs:23:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null()); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:26:45 + --> $DIR/invalid_null_ptr_usage.rs:24:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:28:39 + --> $DIR/invalid_null_ptr_usage.rs:26:39 | LL | let _a: A = std::ptr::replace(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:30:69 + --> $DIR/invalid_null_ptr_usage.rs:28:69 | LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:31:69 + --> $DIR/invalid_null_ptr_usage.rs:29:69 | LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:33:73 + --> $DIR/invalid_null_ptr_usage.rs:31:73 | LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:35:29 + --> $DIR/invalid_null_ptr_usage.rs:33:29 | LL | std::ptr::swap::(std::ptr::null_mut(), &mut A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:36:37 + --> $DIR/invalid_null_ptr_usage.rs:34:37 | LL | std::ptr::swap::(&mut A, std::ptr::null_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:38:44 + --> $DIR/invalid_null_ptr_usage.rs:36:44 | LL | std::ptr::swap_nonoverlapping::(std::ptr::null_mut(), &mut A, 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:39:52 + --> $DIR/invalid_null_ptr_usage.rs:37:52 | LL | std::ptr::swap_nonoverlapping::(&mut A, std::ptr::null_mut(), 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:41:25 + --> $DIR/invalid_null_ptr_usage.rs:39:25 | LL | std::ptr::write(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:43:35 + --> $DIR/invalid_null_ptr_usage.rs:41:35 | LL | std::ptr::write_unaligned(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:45:34 + --> $DIR/invalid_null_ptr_usage.rs:43:34 | LL | std::ptr::write_volatile(std::ptr::null_mut(), A); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:47:40 + --> $DIR/invalid_null_ptr_usage.rs:45:40 | LL | std::ptr::write_bytes::(std::ptr::null_mut(), 42, 0); | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` diff --git a/tests/ui/is_digit_ascii_radix.fixed b/tests/ui/is_digit_ascii_radix.fixed index bc43303a680df..62953ff74cfcf 100644 --- a/tests/ui/is_digit_ascii_radix.fixed +++ b/tests/ui/is_digit_ascii_radix.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::is_digit_ascii_radix)] const TEN: u32 = 10; diff --git a/tests/ui/is_digit_ascii_radix.rs b/tests/ui/is_digit_ascii_radix.rs index 93cba5c8e4e56..229f530f611df 100644 --- a/tests/ui/is_digit_ascii_radix.rs +++ b/tests/ui/is_digit_ascii_radix.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::is_digit_ascii_radix)] const TEN: u32 = 10; diff --git a/tests/ui/is_digit_ascii_radix.stderr b/tests/ui/is_digit_ascii_radix.stderr index dc5cb2913ae15..7bc21b216d536 100644 --- a/tests/ui/is_digit_ascii_radix.stderr +++ b/tests/ui/is_digit_ascii_radix.stderr @@ -1,5 +1,5 @@ error: use of `char::is_digit` with literal radix of 10 - --> $DIR/is_digit_ascii_radix.rs:11:13 + --> $DIR/is_digit_ascii_radix.rs:9:13 | LL | let _ = c.is_digit(10); | ^^^^^^^^^^^^^^ help: try: `c.is_ascii_digit()` @@ -7,13 +7,13 @@ LL | let _ = c.is_digit(10); = note: `-D clippy::is-digit-ascii-radix` implied by `-D warnings` error: use of `char::is_digit` with literal radix of 16 - --> $DIR/is_digit_ascii_radix.rs:12:13 + --> $DIR/is_digit_ascii_radix.rs:10:13 | LL | let _ = c.is_digit(16); | ^^^^^^^^^^^^^^ help: try: `c.is_ascii_hexdigit()` error: use of `char::is_digit` with literal radix of 16 - --> $DIR/is_digit_ascii_radix.rs:13:13 + --> $DIR/is_digit_ascii_radix.rs:11:13 | LL | let _ = c.is_digit(0x10); | ^^^^^^^^^^^^^^^^ help: try: `c.is_ascii_hexdigit()` diff --git a/tests/ui/issue_2356.fixed b/tests/ui/issue_2356.fixed index a69f5ebdc08c5..892aa4e34216c 100644 --- a/tests/ui/issue_2356.fixed +++ b/tests/ui/issue_2356.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::while_let_on_iterator)] #![allow(unused_mut)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/issue_2356.rs b/tests/ui/issue_2356.rs index 50e1bce1f8c91..da0eead15b392 100644 --- a/tests/ui/issue_2356.rs +++ b/tests/ui/issue_2356.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::while_let_on_iterator)] #![allow(unused_mut)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/issue_2356.stderr b/tests/ui/issue_2356.stderr index a24b0b32e4708..d04b49e52a55a 100644 --- a/tests/ui/issue_2356.stderr +++ b/tests/ui/issue_2356.stderr @@ -1,11 +1,11 @@ error: this loop could be written as a `for` loop - --> $DIR/issue_2356.rs:18:9 + --> $DIR/issue_2356.rs:17:9 | LL | while let Some(e) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for e in it` | note: the lint level is defined here - --> $DIR/issue_2356.rs:2:9 + --> $DIR/issue_2356.rs:1:9 | LL | #![deny(clippy::while_let_on_iterator)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/iter_cloned_collect.fixed b/tests/ui/iter_cloned_collect.fixed index 636f572a343e3..1d623642a7133 100644 --- a/tests/ui/iter_cloned_collect.fixed +++ b/tests/ui/iter_cloned_collect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/iter_cloned_collect.rs b/tests/ui/iter_cloned_collect.rs index 518cb75affe5d..091bd9eaf081e 100644 --- a/tests/ui/iter_cloned_collect.rs +++ b/tests/ui/iter_cloned_collect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/iter_cloned_collect.stderr b/tests/ui/iter_cloned_collect.stderr index b2cc497bf433a..36f70d5aec295 100644 --- a/tests/ui/iter_cloned_collect.stderr +++ b/tests/ui/iter_cloned_collect.stderr @@ -1,5 +1,5 @@ error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:10:27 + --> $DIR/iter_cloned_collect.rs:8:27 | LL | let v2: Vec = v.iter().cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` @@ -7,13 +7,13 @@ LL | let v2: Vec = v.iter().cloned().collect(); = note: `-D clippy::iter-cloned-collect` implied by `-D warnings` error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:15:38 + --> $DIR/iter_cloned_collect.rs:13:38 | LL | let _: Vec = vec![1, 2, 3].iter().cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:20:24 + --> $DIR/iter_cloned_collect.rs:18:24 | LL | .to_bytes() | ________________________^ @@ -23,13 +23,13 @@ LL | | .collect(); | |______________________^ help: try: `.to_vec()` error: called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:28:24 + --> $DIR/iter_cloned_collect.rs:26:24 | LL | let _: Vec<_> = arr.iter().cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` error: called `iter().copied().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable - --> $DIR/iter_cloned_collect.rs:31:26 + --> $DIR/iter_cloned_collect.rs:29:26 | LL | let _: Vec = v.iter().copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` diff --git a/tests/ui/iter_count.fixed b/tests/ui/iter_count.fixed index b6208201409f1..75c007bb0c997 100644 --- a/tests/ui/iter_count.fixed +++ b/tests/ui/iter_count.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::iter_count)] diff --git a/tests/ui/iter_count.rs b/tests/ui/iter_count.rs index fb2161312098a..cd8207b2c5dc8 100644 --- a/tests/ui/iter_count.rs +++ b/tests/ui/iter_count.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::iter_count)] diff --git a/tests/ui/iter_count.stderr b/tests/ui/iter_count.stderr index f9aee0b7846d3..2e3d7fc35de9c 100644 --- a/tests/ui/iter_count.stderr +++ b/tests/ui/iter_count.stderr @@ -1,5 +1,5 @@ error: called `.iter().count()` on a `slice` - --> $DIR/iter_count.rs:55:6 + --> $DIR/iter_count.rs:54:6 | LL | &vec[..].iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` @@ -7,145 +7,145 @@ LL | &vec[..].iter().count(); = note: `-D clippy::iter-count` implied by `-D warnings` error: called `.iter().count()` on a `Vec` - --> $DIR/iter_count.rs:56:5 + --> $DIR/iter_count.rs:55:5 | LL | vec.iter().count(); | ^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.iter().count()` on a `slice` - --> $DIR/iter_count.rs:57:5 + --> $DIR/iter_count.rs:56:5 | LL | boxed_slice.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice.len()` error: called `.iter().count()` on a `VecDeque` - --> $DIR/iter_count.rs:58:5 + --> $DIR/iter_count.rs:57:5 | LL | vec_deque.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.iter().count()` on a `HashSet` - --> $DIR/iter_count.rs:59:5 + --> $DIR/iter_count.rs:58:5 | LL | hash_set.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` error: called `.iter().count()` on a `HashMap` - --> $DIR/iter_count.rs:60:5 + --> $DIR/iter_count.rs:59:5 | LL | hash_map.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.iter().count()` on a `BTreeMap` - --> $DIR/iter_count.rs:61:5 + --> $DIR/iter_count.rs:60:5 | LL | b_tree_map.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.iter().count()` on a `BTreeSet` - --> $DIR/iter_count.rs:62:5 + --> $DIR/iter_count.rs:61:5 | LL | b_tree_set.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` error: called `.iter().count()` on a `LinkedList` - --> $DIR/iter_count.rs:63:5 + --> $DIR/iter_count.rs:62:5 | LL | linked_list.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.iter().count()` on a `BinaryHeap` - --> $DIR/iter_count.rs:64:5 + --> $DIR/iter_count.rs:63:5 | LL | binary_heap.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` error: called `.iter_mut().count()` on a `Vec` - --> $DIR/iter_count.rs:66:5 + --> $DIR/iter_count.rs:65:5 | LL | vec.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.iter_mut().count()` on a `slice` - --> $DIR/iter_count.rs:67:6 + --> $DIR/iter_count.rs:66:6 | LL | &vec[..].iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.iter_mut().count()` on a `VecDeque` - --> $DIR/iter_count.rs:68:5 + --> $DIR/iter_count.rs:67:5 | LL | vec_deque.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.iter_mut().count()` on a `HashMap` - --> $DIR/iter_count.rs:69:5 + --> $DIR/iter_count.rs:68:5 | LL | hash_map.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.iter_mut().count()` on a `BTreeMap` - --> $DIR/iter_count.rs:70:5 + --> $DIR/iter_count.rs:69:5 | LL | b_tree_map.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.iter_mut().count()` on a `LinkedList` - --> $DIR/iter_count.rs:71:5 + --> $DIR/iter_count.rs:70:5 | LL | linked_list.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.into_iter().count()` on a `slice` - --> $DIR/iter_count.rs:73:6 + --> $DIR/iter_count.rs:72:6 | LL | &vec[..].into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.into_iter().count()` on a `Vec` - --> $DIR/iter_count.rs:74:5 + --> $DIR/iter_count.rs:73:5 | LL | vec.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.into_iter().count()` on a `VecDeque` - --> $DIR/iter_count.rs:75:5 + --> $DIR/iter_count.rs:74:5 | LL | vec_deque.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.into_iter().count()` on a `HashSet` - --> $DIR/iter_count.rs:76:5 + --> $DIR/iter_count.rs:75:5 | LL | hash_set.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` error: called `.into_iter().count()` on a `HashMap` - --> $DIR/iter_count.rs:77:5 + --> $DIR/iter_count.rs:76:5 | LL | hash_map.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.into_iter().count()` on a `BTreeMap` - --> $DIR/iter_count.rs:78:5 + --> $DIR/iter_count.rs:77:5 | LL | b_tree_map.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.into_iter().count()` on a `BTreeSet` - --> $DIR/iter_count.rs:79:5 + --> $DIR/iter_count.rs:78:5 | LL | b_tree_set.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` error: called `.into_iter().count()` on a `LinkedList` - --> $DIR/iter_count.rs:80:5 + --> $DIR/iter_count.rs:79:5 | LL | linked_list.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.into_iter().count()` on a `BinaryHeap` - --> $DIR/iter_count.rs:81:5 + --> $DIR/iter_count.rs:80:5 | LL | binary_heap.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` diff --git a/tests/ui/iter_kv_map.fixed b/tests/ui/iter_kv_map.fixed index 64201b553fdde..566a5b690d84f 100644 --- a/tests/ui/iter_kv_map.fixed +++ b/tests/ui/iter_kv_map.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::iter_kv_map)] #![allow(unused_mut, clippy::redundant_clone, clippy::suspicious_map, clippy::map_identity)] diff --git a/tests/ui/iter_kv_map.rs b/tests/ui/iter_kv_map.rs index ec0231ba5727b..d85e501da487f 100644 --- a/tests/ui/iter_kv_map.rs +++ b/tests/ui/iter_kv_map.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::iter_kv_map)] #![allow(unused_mut, clippy::redundant_clone, clippy::suspicious_map, clippy::map_identity)] diff --git a/tests/ui/iter_kv_map.stderr b/tests/ui/iter_kv_map.stderr index e00da223b4dd2..75804af01ce2e 100644 --- a/tests/ui/iter_kv_map.stderr +++ b/tests/ui/iter_kv_map.stderr @@ -1,5 +1,5 @@ error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:16:13 + --> $DIR/iter_kv_map.rs:14:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` @@ -7,73 +7,73 @@ LL | let _ = map.iter().map(|(key, _)| key).collect::>(); = note: `-D clippy::iter-kv-map` implied by `-D warnings` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:17:13 + --> $DIR/iter_kv_map.rs:15:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:18:13 + --> $DIR/iter_kv_map.rs:16:13 | LL | let _ = map.iter().map(|(_, v)| v + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:20:13 + --> $DIR/iter_kv_map.rs:18:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:21:13 + --> $DIR/iter_kv_map.rs:19:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:23:13 + --> $DIR/iter_kv_map.rs:21:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:24:13 + --> $DIR/iter_kv_map.rs:22:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:26:13 + --> $DIR/iter_kv_map.rs:24:13 | LL | let _ = map.clone().iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:27:13 + --> $DIR/iter_kv_map.rs:25:13 | LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:37:13 + --> $DIR/iter_kv_map.rs:35:13 | LL | let _ = map.iter().map(|(key, _value)| key * 9).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:38:13 + --> $DIR/iter_kv_map.rs:36:13 | LL | let _ = map.iter().map(|(_key, value)| value * 17).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:41:13 + --> $DIR/iter_kv_map.rs:39:13 | LL | let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|ref val| ref_acceptor(val))` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:44:13 + --> $DIR/iter_kv_map.rs:42:13 | LL | let _ = map | _____________^ @@ -95,85 +95,85 @@ LL + }) | error: iterating on a map's values - --> $DIR/iter_kv_map.rs:54:13 + --> $DIR/iter_kv_map.rs:52:13 | LL | let _ = map.clone().into_iter().map(|(_, mut val)| val).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:58:13 + --> $DIR/iter_kv_map.rs:56:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:59:13 + --> $DIR/iter_kv_map.rs:57:13 | LL | let _ = map.iter().map(|(_, value)| value).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:60:13 + --> $DIR/iter_kv_map.rs:58:13 | LL | let _ = map.iter().map(|(_, v)| v + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:62:13 + --> $DIR/iter_kv_map.rs:60:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:63:13 + --> $DIR/iter_kv_map.rs:61:13 | LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:65:13 + --> $DIR/iter_kv_map.rs:63:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:66:13 + --> $DIR/iter_kv_map.rs:64:13 | LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:68:13 + --> $DIR/iter_kv_map.rs:66:13 | LL | let _ = map.clone().iter().map(|(_, val)| val).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:69:13 + --> $DIR/iter_kv_map.rs:67:13 | LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:79:13 + --> $DIR/iter_kv_map.rs:77:13 | LL | let _ = map.iter().map(|(key, _value)| key * 9).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:80:13 + --> $DIR/iter_kv_map.rs:78:13 | LL | let _ = map.iter().map(|(_key, value)| value * 17).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:83:13 + --> $DIR/iter_kv_map.rs:81:13 | LL | let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|ref val| ref_acceptor(val))` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:86:13 + --> $DIR/iter_kv_map.rs:84:13 | LL | let _ = map | _____________^ @@ -195,7 +195,7 @@ LL + }) | error: iterating on a map's values - --> $DIR/iter_kv_map.rs:96:13 + --> $DIR/iter_kv_map.rs:94:13 | LL | let _ = map.clone().into_iter().map(|(_, mut val)| val).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` diff --git a/tests/ui/iter_next_slice.fixed b/tests/ui/iter_next_slice.fixed index 702edccdbad0d..83be12c4e2549 100644 --- a/tests/ui/iter_next_slice.fixed +++ b/tests/ui/iter_next_slice.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_next_slice)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/iter_next_slice.rs b/tests/ui/iter_next_slice.rs index 30bfc72de1793..1b257514d23ec 100644 --- a/tests/ui/iter_next_slice.rs +++ b/tests/ui/iter_next_slice.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_next_slice)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/iter_next_slice.stderr b/tests/ui/iter_next_slice.stderr index 0db8201a1325c..d8b89061ff895 100644 --- a/tests/ui/iter_next_slice.stderr +++ b/tests/ui/iter_next_slice.stderr @@ -1,5 +1,5 @@ error: using `.iter().next()` on an array - --> $DIR/iter_next_slice.rs:10:13 + --> $DIR/iter_next_slice.rs:9:13 | LL | let _ = s.iter().next(); | ^^^^^^^^^^^^^^^ help: try calling: `s.first()` @@ -7,19 +7,19 @@ LL | let _ = s.iter().next(); = note: `-D clippy::iter-next-slice` implied by `-D warnings` error: using `.iter().next()` on a Slice without end index - --> $DIR/iter_next_slice.rs:13:13 + --> $DIR/iter_next_slice.rs:12:13 | LL | let _ = s[2..].iter().next(); | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)` error: using `.iter().next()` on a Slice without end index - --> $DIR/iter_next_slice.rs:16:13 + --> $DIR/iter_next_slice.rs:15:13 | LL | let _ = v[5..].iter().next(); | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)` error: using `.iter().next()` on an array - --> $DIR/iter_next_slice.rs:19:13 + --> $DIR/iter_next_slice.rs:18:13 | LL | let _ = v.iter().next(); | ^^^^^^^^^^^^^^^ help: try calling: `v.first()` diff --git a/tests/ui/iter_nth_zero.fixed b/tests/ui/iter_nth_zero.fixed index 91f4a7ba0d2fc..a3cdb2e59bff2 100644 --- a/tests/ui/iter_nth_zero.fixed +++ b/tests/ui/iter_nth_zero.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::iter_nth_zero)] use std::collections::HashSet; diff --git a/tests/ui/iter_nth_zero.rs b/tests/ui/iter_nth_zero.rs index 160a895bb7b4e..64229b5128a39 100644 --- a/tests/ui/iter_nth_zero.rs +++ b/tests/ui/iter_nth_zero.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::iter_nth_zero)] use std::collections::HashSet; diff --git a/tests/ui/iter_nth_zero.stderr b/tests/ui/iter_nth_zero.stderr index 29c56f3a94f5f..8338d7f7b93a0 100644 --- a/tests/ui/iter_nth_zero.stderr +++ b/tests/ui/iter_nth_zero.stderr @@ -1,5 +1,5 @@ error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> $DIR/iter_nth_zero.rs:20:14 + --> $DIR/iter_nth_zero.rs:18:14 | LL | let _x = s.iter().nth(0); | ^^^^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `s.iter().next()` @@ -7,13 +7,13 @@ LL | let _x = s.iter().nth(0); = note: `-D clippy::iter-nth-zero` implied by `-D warnings` error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> $DIR/iter_nth_zero.rs:25:14 + --> $DIR/iter_nth_zero.rs:23:14 | LL | let _y = iter.nth(0); | ^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter.next()` error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> $DIR/iter_nth_zero.rs:30:22 + --> $DIR/iter_nth_zero.rs:28:22 | LL | let _unwrapped = iter2.nth(0).unwrap(); | ^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter2.next()` diff --git a/tests/ui/iter_on_empty_collections.fixed b/tests/ui/iter_on_empty_collections.fixed index 4616f0cdc45e5..794629f240eb1 100644 --- a/tests/ui/iter_on_empty_collections.fixed +++ b/tests/ui/iter_on_empty_collections.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_on_empty_collections)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] diff --git a/tests/ui/iter_on_empty_collections.rs b/tests/ui/iter_on_empty_collections.rs index 81cc7265e11e4..a6461a702eb2a 100644 --- a/tests/ui/iter_on_empty_collections.rs +++ b/tests/ui/iter_on_empty_collections.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_on_empty_collections)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] diff --git a/tests/ui/iter_on_empty_collections.stderr b/tests/ui/iter_on_empty_collections.stderr index cbd6117695696..c115c1278389b 100644 --- a/tests/ui/iter_on_empty_collections.stderr +++ b/tests/ui/iter_on_empty_collections.stderr @@ -1,5 +1,5 @@ error: `into_iter` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:6:16 + --> $DIR/iter_on_empty_collections.rs:5:16 | LL | assert_eq!([].into_iter().next(), Option::::None); | ^^^^^^^^^^^^^^ help: try: `std::iter::empty()` @@ -7,31 +7,31 @@ LL | assert_eq!([].into_iter().next(), Option::::None); = note: `-D clippy::iter-on-empty-collections` implied by `-D warnings` error: `iter_mut` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:7:16 + --> $DIR/iter_on_empty_collections.rs:6:16 | LL | assert_eq!([].iter_mut().next(), Option::<&mut i32>::None); | ^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:8:16 + --> $DIR/iter_on_empty_collections.rs:7:16 | LL | assert_eq!([].iter().next(), Option::<&i32>::None); | ^^^^^^^^^ help: try: `std::iter::empty()` error: `into_iter` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:9:16 + --> $DIR/iter_on_empty_collections.rs:8:16 | LL | assert_eq!(None.into_iter().next(), Option::::None); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter_mut` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:10:16 + --> $DIR/iter_on_empty_collections.rs:9:16 | LL | assert_eq!(None.iter_mut().next(), Option::<&mut i32>::None); | ^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:11:16 + --> $DIR/iter_on_empty_collections.rs:10:16 | LL | assert_eq!(None.iter().next(), Option::<&i32>::None); | ^^^^^^^^^^^ help: try: `std::iter::empty()` diff --git a/tests/ui/iter_on_single_items.fixed b/tests/ui/iter_on_single_items.fixed index 80dbe454b4708..117ec8429c375 100644 --- a/tests/ui/iter_on_single_items.fixed +++ b/tests/ui/iter_on_single_items.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_on_single_items)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] diff --git a/tests/ui/iter_on_single_items.rs b/tests/ui/iter_on_single_items.rs index 71c8c7a3f94cc..d059370d996c1 100644 --- a/tests/ui/iter_on_single_items.rs +++ b/tests/ui/iter_on_single_items.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_on_single_items)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] diff --git a/tests/ui/iter_on_single_items.stderr b/tests/ui/iter_on_single_items.stderr index d6c547116363a..c6714143ba5a8 100644 --- a/tests/ui/iter_on_single_items.stderr +++ b/tests/ui/iter_on_single_items.stderr @@ -1,5 +1,5 @@ error: `into_iter` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:6:16 + --> $DIR/iter_on_single_items.rs:5:16 | LL | assert_eq!([123].into_iter().next(), Some(123)); | ^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(123)` @@ -7,31 +7,31 @@ LL | assert_eq!([123].into_iter().next(), Some(123)); = note: `-D clippy::iter-on-single-items` implied by `-D warnings` error: `iter_mut` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:7:16 + --> $DIR/iter_on_single_items.rs:6:16 | LL | assert_eq!([123].iter_mut().next(), Some(&mut 123)); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&mut 123)` error: `iter` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:8:16 + --> $DIR/iter_on_single_items.rs:7:16 | LL | assert_eq!([123].iter().next(), Some(&123)); | ^^^^^^^^^^^^ help: try: `std::iter::once(&123)` error: `into_iter` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:9:16 + --> $DIR/iter_on_single_items.rs:8:16 | LL | assert_eq!(Some(123).into_iter().next(), Some(123)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(123)` error: `iter_mut` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:10:16 + --> $DIR/iter_on_single_items.rs:9:16 | LL | assert_eq!(Some(123).iter_mut().next(), Some(&mut 123)); | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&mut 123)` error: `iter` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:11:16 + --> $DIR/iter_on_single_items.rs:10:16 | LL | assert_eq!(Some(123).iter().next(), Some(&123)); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&123)` diff --git a/tests/ui/iter_overeager_cloned.fixed b/tests/ui/iter_overeager_cloned.fixed index 2874513c049b8..ba26fe33d8925 100644 --- a/tests/ui/iter_overeager_cloned.fixed +++ b/tests/ui/iter_overeager_cloned.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_overeager_cloned, clippy::redundant_clone, clippy::filter_next)] #![allow(dead_code, clippy::let_unit_value, clippy::useless_vec)] diff --git a/tests/ui/iter_overeager_cloned.rs b/tests/ui/iter_overeager_cloned.rs index 26f39734a5124..2d3c4ea7c2015 100644 --- a/tests/ui/iter_overeager_cloned.rs +++ b/tests/ui/iter_overeager_cloned.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_overeager_cloned, clippy::redundant_clone, clippy::filter_next)] #![allow(dead_code, clippy::let_unit_value, clippy::useless_vec)] diff --git a/tests/ui/iter_overeager_cloned.stderr b/tests/ui/iter_overeager_cloned.stderr index eaac48be88094..2be2b7e07a468 100644 --- a/tests/ui/iter_overeager_cloned.stderr +++ b/tests/ui/iter_overeager_cloned.stderr @@ -1,5 +1,5 @@ error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:8:29 + --> $DIR/iter_overeager_cloned.rs:7:29 | LL | let _: Option = vec.iter().cloned().last(); | ^^^^^^^^^^---------------- @@ -9,7 +9,7 @@ LL | let _: Option = vec.iter().cloned().last(); = note: `-D clippy::iter-overeager-cloned` implied by `-D warnings` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:10:29 + --> $DIR/iter_overeager_cloned.rs:9:29 | LL | let _: Option = vec.iter().chain(vec.iter()).cloned().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------- @@ -17,7 +17,7 @@ LL | let _: Option = vec.iter().chain(vec.iter()).cloned().next(); | help: try: `.next().cloned()` error: unneeded cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:12:20 + --> $DIR/iter_overeager_cloned.rs:11:20 | LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------- @@ -27,7 +27,7 @@ LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); = note: `-D clippy::redundant-clone` implied by `-D warnings` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:14:21 + --> $DIR/iter_overeager_cloned.rs:13:21 | LL | let _: Vec<_> = vec.iter().cloned().take(2).collect(); | ^^^^^^^^^^----------------- @@ -35,7 +35,7 @@ LL | let _: Vec<_> = vec.iter().cloned().take(2).collect(); | help: try: `.take(2).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:16:21 + --> $DIR/iter_overeager_cloned.rs:15:21 | LL | let _: Vec<_> = vec.iter().cloned().skip(2).collect(); | ^^^^^^^^^^----------------- @@ -43,7 +43,7 @@ LL | let _: Vec<_> = vec.iter().cloned().skip(2).collect(); | help: try: `.skip(2).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:18:13 + --> $DIR/iter_overeager_cloned.rs:17:13 | LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------- @@ -51,7 +51,7 @@ LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2); | help: try: `.nth(2).cloned()` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:20:13 + --> $DIR/iter_overeager_cloned.rs:19:13 | LL | let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] | _____________^ diff --git a/tests/ui/iter_skip_next.fixed b/tests/ui/iter_skip_next.fixed index b888d965e8d7e..310b24a9cde17 100644 --- a/tests/ui/iter_skip_next.fixed +++ b/tests/ui/iter_skip_next.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::iter_skip_next)] diff --git a/tests/ui/iter_skip_next.rs b/tests/ui/iter_skip_next.rs index e44efdebc4718..222d6a2a1848b 100644 --- a/tests/ui/iter_skip_next.rs +++ b/tests/ui/iter_skip_next.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::iter_skip_next)] diff --git a/tests/ui/iter_skip_next.stderr b/tests/ui/iter_skip_next.stderr index 4ee26e088ce35..ca6970b27f16c 100644 --- a/tests/ui/iter_skip_next.stderr +++ b/tests/ui/iter_skip_next.stderr @@ -1,5 +1,5 @@ error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:17:28 + --> $DIR/iter_skip_next.rs:16:28 | LL | let _ = some_vec.iter().skip(42).next(); | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` @@ -7,37 +7,37 @@ LL | let _ = some_vec.iter().skip(42).next(); = note: `-D clippy::iter-skip-next` implied by `-D warnings` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:18:36 + --> $DIR/iter_skip_next.rs:17:36 | LL | let _ = some_vec.iter().cycle().skip(42).next(); | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:19:20 + --> $DIR/iter_skip_next.rs:18:20 | LL | let _ = (1..10).skip(10).next(); | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:20:33 + --> $DIR/iter_skip_next.rs:19:33 | LL | let _ = &some_vec[..].iter().skip(3).next(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(3)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:28:26 + --> $DIR/iter_skip_next.rs:27:26 | LL | let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:30:29 + --> $DIR/iter_skip_next.rs:29:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next.rs:36:29 + --> $DIR/iter_skip_next.rs:35:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` diff --git a/tests/ui/iter_skip_next_unfixable.rs b/tests/ui/iter_skip_next_unfixable.rs index 3607330cfa0d3..4dd8cb599d52b 100644 --- a/tests/ui/iter_skip_next_unfixable.rs +++ b/tests/ui/iter_skip_next_unfixable.rs @@ -1,6 +1,6 @@ #![warn(clippy::iter_skip_next)] #![allow(dead_code)] - +//@no-rustfix /// Checks implementation of `ITER_SKIP_NEXT` lint fn main() { // fix #8128 diff --git a/tests/ui/iter_skip_zero.fixed b/tests/ui/iter_skip_zero.fixed index 1eb0984fe073f..f31c8634d4d75 100644 --- a/tests/ui/iter_skip_zero.fixed +++ b/tests/ui/iter_skip_zero.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(clippy::useless_vec, unused)] #![warn(clippy::iter_skip_zero)] diff --git a/tests/ui/iter_skip_zero.rs b/tests/ui/iter_skip_zero.rs index 8c103ab1d5b32..188ae547d8041 100644 --- a/tests/ui/iter_skip_zero.rs +++ b/tests/ui/iter_skip_zero.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(clippy::useless_vec, unused)] #![warn(clippy::iter_skip_zero)] diff --git a/tests/ui/iter_skip_zero.stderr b/tests/ui/iter_skip_zero.stderr index 80fecd59e6d10..6616020d0bdc0 100644 --- a/tests/ui/iter_skip_zero.stderr +++ b/tests/ui/iter_skip_zero.stderr @@ -1,5 +1,5 @@ error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:12:35 + --> $DIR/iter_skip_zero.rs:11:35 | LL | let _ = [1, 2, 3].iter().skip(0); | ^ help: if you meant to skip the first element, use: `1` @@ -8,7 +8,7 @@ LL | let _ = [1, 2, 3].iter().skip(0); = note: `-D clippy::iter-skip-zero` implied by `-D warnings` error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:13:39 + --> $DIR/iter_skip_zero.rs:12:39 | LL | let _ = vec![1, 2, 3].iter().skip(0); | ^ help: if you meant to skip the first element, use: `1` @@ -16,7 +16,7 @@ LL | let _ = vec![1, 2, 3].iter().skip(0); = note: this call to `skip` does nothing and is useless; remove it error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:14:34 + --> $DIR/iter_skip_zero.rs:13:34 | LL | let _ = once([1, 2, 3]).skip(0); | ^ help: if you meant to skip the first element, use: `1` @@ -24,7 +24,7 @@ LL | let _ = once([1, 2, 3]).skip(0); = note: this call to `skip` does nothing and is useless; remove it error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:15:71 + --> $DIR/iter_skip_zero.rs:14:71 | LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); | ^ help: if you meant to skip the first element, use: `1` @@ -32,7 +32,7 @@ LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); = note: this call to `skip` does nothing and is useless; remove it error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:15:62 + --> $DIR/iter_skip_zero.rs:14:62 | LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); | ^ help: if you meant to skip the first element, use: `1` diff --git a/tests/ui/iter_with_drain.fixed b/tests/ui/iter_with_drain.fixed index 7a8c677010104..a03efceed4caa 100644 --- a/tests/ui/iter_with_drain.fixed +++ b/tests/ui/iter_with_drain.fixed @@ -1,4 +1,3 @@ -//@run-rustfix // will emits unused mut warnings after fixing #![allow(unused_mut)] // will emits needless collect warnings after fixing diff --git a/tests/ui/iter_with_drain.rs b/tests/ui/iter_with_drain.rs index cf3a935c349a4..a8cd47f83d04d 100644 --- a/tests/ui/iter_with_drain.rs +++ b/tests/ui/iter_with_drain.rs @@ -1,4 +1,3 @@ -//@run-rustfix // will emits unused mut warnings after fixing #![allow(unused_mut)] // will emits needless collect warnings after fixing diff --git a/tests/ui/iter_with_drain.stderr b/tests/ui/iter_with_drain.stderr index bfaed29a099c5..0a3026570882b 100644 --- a/tests/ui/iter_with_drain.stderr +++ b/tests/ui/iter_with_drain.stderr @@ -1,5 +1,5 @@ error: `drain(..)` used on a `Vec` - --> $DIR/iter_with_drain.rs:11:34 + --> $DIR/iter_with_drain.rs:10:34 | LL | let mut a: BinaryHeap<_> = a.drain(..).collect(); | ^^^^^^^^^ help: try: `into_iter()` @@ -7,31 +7,31 @@ LL | let mut a: BinaryHeap<_> = a.drain(..).collect(); = note: `-D clippy::iter-with-drain` implied by `-D warnings` error: `drain(..)` used on a `VecDeque` - --> $DIR/iter_with_drain.rs:14:27 + --> $DIR/iter_with_drain.rs:13:27 | LL | let mut a: Vec<_> = a.drain(..).collect(); | ^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> $DIR/iter_with_drain.rs:15:34 + --> $DIR/iter_with_drain.rs:14:34 | LL | let mut a: HashMap<_, _> = a.drain(..).map(|x| (x.clone(), x)).collect(); | ^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> $DIR/iter_with_drain.rs:21:34 + --> $DIR/iter_with_drain.rs:20:34 | LL | let mut a: BinaryHeap<_> = a.drain(0..).collect(); | ^^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `VecDeque` - --> $DIR/iter_with_drain.rs:24:27 + --> $DIR/iter_with_drain.rs:23:27 | LL | let mut a: Vec<_> = a.drain(..a.len()).collect(); | ^^^^^^^^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> $DIR/iter_with_drain.rs:25:34 + --> $DIR/iter_with_drain.rs:24:34 | LL | let mut a: HashMap<_, _> = a.drain(0..a.len()).map(|x| (x.clone(), x)).collect(); | ^^^^^^^^^^^^^^^^^ help: try: `into_iter()` diff --git a/tests/ui/large_const_arrays.fixed b/tests/ui/large_const_arrays.fixed index f7ce6fbe6bb4c..6011bb99dec25 100644 --- a/tests/ui/large_const_arrays.fixed +++ b/tests/ui/large_const_arrays.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::large_const_arrays)] #![allow(dead_code)] diff --git a/tests/ui/large_const_arrays.rs b/tests/ui/large_const_arrays.rs index 002ac77ddda9c..a78425d7bc627 100644 --- a/tests/ui/large_const_arrays.rs +++ b/tests/ui/large_const_arrays.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::large_const_arrays)] #![allow(dead_code)] diff --git a/tests/ui/large_const_arrays.stderr b/tests/ui/large_const_arrays.stderr index 3fb0acbca67de..e2348629088d1 100644 --- a/tests/ui/large_const_arrays.stderr +++ b/tests/ui/large_const_arrays.stderr @@ -1,5 +1,5 @@ error: large array defined as const - --> $DIR/large_const_arrays.rs:12:1 + --> $DIR/large_const_arrays.rs:10:1 | LL | pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; = note: `-D clippy::large-const-arrays` implied by `-D warnings` error: large array defined as const - --> $DIR/large_const_arrays.rs:13:1 + --> $DIR/large_const_arrays.rs:11:1 | LL | pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:14:1 + --> $DIR/large_const_arrays.rs:12:1 | LL | const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:23:5 + --> $DIR/large_const_arrays.rs:21:5 | LL | pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:24:5 + --> $DIR/large_const_arrays.rs:22:5 | LL | const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:25:5 + --> $DIR/large_const_arrays.rs:23:5 | LL | pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:26:5 + --> $DIR/large_const_arrays.rs:24:5 | LL | const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:27:5 + --> $DIR/large_const_arrays.rs:25:5 | LL | pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; | help: make this a static item: `static` error: large array defined as const - --> $DIR/large_const_arrays.rs:28:5 + --> $DIR/large_const_arrays.rs:26:5 | LL | const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/large_digit_groups.fixed b/tests/ui/large_digit_groups.fixed index f42fcd96d7955..cdb001e47e2bd 100644 --- a/tests/ui/large_digit_groups.fixed +++ b/tests/ui/large_digit_groups.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::large_digit_groups)] fn main() { diff --git a/tests/ui/large_digit_groups.rs b/tests/ui/large_digit_groups.rs index 3db9da6a3a58a..3c30c86702848 100644 --- a/tests/ui/large_digit_groups.rs +++ b/tests/ui/large_digit_groups.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::large_digit_groups)] fn main() { diff --git a/tests/ui/large_digit_groups.stderr b/tests/ui/large_digit_groups.stderr index 19c0fae98a645..7e5ce7ad8d539 100644 --- a/tests/ui/large_digit_groups.stderr +++ b/tests/ui/large_digit_groups.stderr @@ -1,5 +1,5 @@ error: digits of hex, binary or octal literal not in groups of equal size - --> $DIR/large_digit_groups.rs:23:9 + --> $DIR/large_digit_groups.rs:22:9 | LL | 0xd_e_adbee_f_usize, | ^^^^^^^^^^^^^^^^^^^ help: consider: `0xdead_beef_usize` @@ -7,7 +7,7 @@ LL | 0xd_e_adbee_f_usize, = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:24:9 + --> $DIR/large_digit_groups.rs:23:9 | LL | 1_23456_f32, | ^^^^^^^^^^^ help: consider: `123_456_f32` @@ -15,19 +15,19 @@ LL | 1_23456_f32, = note: `-D clippy::large-digit-groups` implied by `-D warnings` error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:25:9 + --> $DIR/large_digit_groups.rs:24:9 | LL | 1_23456.12_f32, | ^^^^^^^^^^^^^^ help: consider: `123_456.12_f32` error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:26:9 + --> $DIR/large_digit_groups.rs:25:9 | LL | 1_23456.12345_f64, | ^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_45_f64` error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:27:9 + --> $DIR/large_digit_groups.rs:26:9 | LL | 1_23456.12345_6_f64, | ^^^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_456_f64` diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index e677cc9a7b95c..0aac6875346ec 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs:proc-macro - +//@no-rustfix #![allow(dead_code)] #![allow(unused_variables)] #![warn(clippy::large_enum_variant)] diff --git a/tests/ui/large_futures.fixed b/tests/ui/large_futures.fixed new file mode 100644 index 0000000000000..afe89cf6e94d8 --- /dev/null +++ b/tests/ui/large_futures.fixed @@ -0,0 +1,62 @@ +#![feature(generators)] +#![warn(clippy::large_futures)] +#![allow(clippy::never_loop)] +#![allow(clippy::future_not_send)] +#![allow(clippy::manual_async_fn)] + +async fn big_fut(_arg: [u8; 1024 * 16]) {} + +async fn wait() { + let f = async { + Box::pin(big_fut([0u8; 1024 * 16])).await; + }; + Box::pin(f).await +} +async fn calls_fut(fut: impl std::future::Future) { + loop { + Box::pin(wait()).await; + if true { + return fut.await; + } else { + Box::pin(wait()).await; + } + } +} + +pub async fn test() { + let fut = big_fut([0u8; 1024 * 16]); + Box::pin(foo()).await; + Box::pin(calls_fut(fut)).await; +} + +pub fn foo() -> impl std::future::Future { + async { + let x = [0i32; 1024 * 16]; + async {}.await; + dbg!(x); + } +} + +pub async fn lines() { + Box::pin(async { + let x = [0i32; 1024 * 16]; + async {}.await; + println!("{:?}", x); + }) + .await; +} + +pub async fn macro_expn() { + macro_rules! macro_ { + () => { + Box::pin(async { + let x = [0i32; 1024 * 16]; + async {}.await; + println!("macro: {:?}", x); + }) + }; + } + macro_!().await +} + +fn main() {} diff --git a/tests/ui/large_types_passed_by_value.rs b/tests/ui/large_types_passed_by_value.rs index f9e3c7192ad5b..78994a2988a22 100644 --- a/tests/ui/large_types_passed_by_value.rs +++ b/tests/ui/large_types_passed_by_value.rs @@ -1,6 +1,6 @@ //@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)" //@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)" - +//@no-rustfix #![warn(clippy::large_types_passed_by_value)] pub struct Large([u8; 2048]); diff --git a/tests/ui/len_zero.fixed b/tests/ui/len_zero.fixed index fafee6a0d41d5..745fc7e1a8b36 100644 --- a/tests/ui/len_zero.fixed +++ b/tests/ui/len_zero.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::len_zero)] #![allow(dead_code, unused, clippy::needless_if, clippy::len_without_is_empty)] diff --git a/tests/ui/len_zero.rs b/tests/ui/len_zero.rs index 6a9006c477999..048ad2f4fd34d 100644 --- a/tests/ui/len_zero.rs +++ b/tests/ui/len_zero.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::len_zero)] #![allow(dead_code, unused, clippy::needless_if, clippy::len_without_is_empty)] diff --git a/tests/ui/len_zero.stderr b/tests/ui/len_zero.stderr index 396cfb75fb620..45130a3008d3d 100644 --- a/tests/ui/len_zero.stderr +++ b/tests/ui/len_zero.stderr @@ -1,5 +1,5 @@ error: length comparison to zero - --> $DIR/len_zero.rs:84:8 + --> $DIR/len_zero.rs:82:8 | LL | if x.len() == 0 { | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `x.is_empty()` @@ -7,13 +7,13 @@ LL | if x.len() == 0 { = note: `-D clippy::len-zero` implied by `-D warnings` error: length comparison to zero - --> $DIR/len_zero.rs:88:8 + --> $DIR/len_zero.rs:86:8 | LL | if "".len() == 0 {} | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `"".is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:97:20 + --> $DIR/len_zero.rs:95:20 | LL | println!("{}", *s1 == ""); | ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s1.is_empty()` @@ -21,121 +21,121 @@ LL | println!("{}", *s1 == ""); = note: `-D clippy::comparison-to-empty` implied by `-D warnings` error: comparison to empty slice - --> $DIR/len_zero.rs:98:20 + --> $DIR/len_zero.rs:96:20 | LL | println!("{}", **s2 == ""); | ^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s2.is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:99:20 + --> $DIR/len_zero.rs:97:20 | LL | println!("{}", ***s3 == ""); | ^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s3.is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:100:20 + --> $DIR/len_zero.rs:98:20 | LL | println!("{}", ****s4 == ""); | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s4.is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:101:20 + --> $DIR/len_zero.rs:99:20 | LL | println!("{}", *****s5 == ""); | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s5.is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:102:20 + --> $DIR/len_zero.rs:100:20 | LL | println!("{}", ******(s6) == ""); | ^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(s6).is_empty()` error: comparison to empty slice - --> $DIR/len_zero.rs:105:20 + --> $DIR/len_zero.rs:103:20 | LL | println!("{}", &**d2s == ""); | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(**d2s).is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:120:8 + --> $DIR/len_zero.rs:118:8 | LL | if has_is_empty.len() == 0 { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:123:8 + --> $DIR/len_zero.rs:121:8 | LL | if has_is_empty.len() != 0 { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:126:8 + --> $DIR/len_zero.rs:124:8 | LL | if has_is_empty.len() > 0 { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to one - --> $DIR/len_zero.rs:129:8 + --> $DIR/len_zero.rs:127:8 | LL | if has_is_empty.len() < 1 { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to one - --> $DIR/len_zero.rs:132:8 + --> $DIR/len_zero.rs:130:8 | LL | if has_is_empty.len() >= 1 { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:143:8 + --> $DIR/len_zero.rs:141:8 | LL | if 0 == has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:146:8 + --> $DIR/len_zero.rs:144:8 | LL | if 0 != has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:149:8 + --> $DIR/len_zero.rs:147:8 | LL | if 0 < has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to one - --> $DIR/len_zero.rs:152:8 + --> $DIR/len_zero.rs:150:8 | LL | if 1 <= has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to one - --> $DIR/len_zero.rs:155:8 + --> $DIR/len_zero.rs:153:8 | LL | if 1 > has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:169:8 + --> $DIR/len_zero.rs:167:8 | LL | if with_is_empty.len() == 0 { | ^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `with_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:181:6 + --> $DIR/len_zero.rs:179:6 | LL | (has_is_empty.len() > 0).then(|| println!("This can happen.")); | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:182:6 + --> $DIR/len_zero.rs:180:6 | LL | (has_is_empty.len() == 0).then(|| println!("Or this!")); | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> $DIR/len_zero.rs:186:8 + --> $DIR/len_zero.rs:184:8 | LL | if b.len() != 0 {} | ^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!b.is_empty()` diff --git a/tests/ui/len_zero_ranges.fixed b/tests/ui/len_zero_ranges.fixed index 4b1241ec86b44..1fdeb2c7a37b9 100644 --- a/tests/ui/len_zero_ranges.fixed +++ b/tests/ui/len_zero_ranges.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::len_zero)] #![allow(unused)] diff --git a/tests/ui/len_zero_ranges.rs b/tests/ui/len_zero_ranges.rs index 4b47132c76618..a5c9a969aaa65 100644 --- a/tests/ui/len_zero_ranges.rs +++ b/tests/ui/len_zero_ranges.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::len_zero)] #![allow(unused)] diff --git a/tests/ui/len_zero_ranges.stderr b/tests/ui/len_zero_ranges.stderr index d0defb5a79edc..25a940181d498 100644 --- a/tests/ui/len_zero_ranges.stderr +++ b/tests/ui/len_zero_ranges.stderr @@ -1,5 +1,5 @@ error: length comparison to zero - --> $DIR/len_zero_ranges.rs:9:17 + --> $DIR/len_zero_ranges.rs:7:17 | LL | let _ = (0..42).len() == 0; | ^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(0..42).is_empty()` @@ -7,7 +7,7 @@ LL | let _ = (0..42).len() == 0; = note: `-D clippy::len-zero` implied by `-D warnings` error: length comparison to zero - --> $DIR/len_zero_ranges.rs:13:17 + --> $DIR/len_zero_ranges.rs:11:17 | LL | let _ = (0_u8..=42).len() == 0; | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(0_u8..=42).is_empty()` diff --git a/tests/ui/let_and_return.fixed b/tests/ui/let_and_return.fixed new file mode 100644 index 0000000000000..32119996e3d9b --- /dev/null +++ b/tests/ui/let_and_return.fixed @@ -0,0 +1,182 @@ +#![allow(unused)] +#![warn(clippy::let_and_return)] + +use std::cell::RefCell; + +fn test() -> i32 { + let _y = 0; // no warning + + 5 +} + +fn test_inner() -> i32 { + if true { + + 5 + } else { + 0 + } +} + +fn test_nowarn_1() -> i32 { + let mut x = 5; + x += 1; + x +} + +fn test_nowarn_2() -> i32 { + let x = 5; + x + 1 +} + +fn test_nowarn_3() -> (i32, i32) { + // this should technically warn, but we do not compare complex patterns + let (x, y) = (5, 9); + (x, y) +} + +fn test_nowarn_4() -> i32 { + // this should technically warn, but not b/c of clippy::let_and_return, but b/c of useless type + let x: i32 = 5; + x +} + +fn test_nowarn_5(x: i16) -> u16 { + #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + let x = x as u16; + x +} + +// False positive example +trait Decode { + fn decode(d: D) -> Result + where + Self: Sized; +} + +macro_rules! tuple_encode { + ($($x:ident),*) => ( + impl<$($x: Decode),*> Decode for ($($x),*) { + #[inline] + #[allow(non_snake_case)] + fn decode(mut d: D) -> Result { + // Shouldn't trigger lint + Ok(($({let $x = Decode::decode(&mut d)?; $x }),*)) + } + } + ); +} + +fn issue_3792() -> String { + use std::io::{self, BufRead, Stdin}; + + let stdin = io::stdin(); + // `Stdin::lock` returns `StdinLock<'static>` so `line` doesn't borrow from `stdin` + // https://github.com/rust-lang/rust/pull/93965 + + stdin.lock().lines().next().unwrap().unwrap() +} + +tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); + +mod no_lint_if_stmt_borrows { + use std::cell::RefCell; + use std::rc::{Rc, Weak}; + struct Bar; + + impl Bar { + fn new() -> Self { + Bar {} + } + fn baz(&self) -> u32 { + 0 + } + } + + fn issue_3324(value: Weak>) -> u32 { + let value = value.upgrade().unwrap(); + let ret = value.borrow().baz(); + ret + } + + fn borrows_in_closure(value: Weak>) -> u32 { + fn f(mut x: impl FnMut() -> u32) -> impl FnMut() -> u32 { + x + } + + let value = value.upgrade().unwrap(); + let ret = f(|| value.borrow().baz())(); + ret + } + + mod free_function { + struct Inner; + + struct Foo<'a> { + inner: &'a Inner, + } + + impl Drop for Foo<'_> { + fn drop(&mut self) {} + } + + impl<'a> Foo<'a> { + fn new(inner: &'a Inner) -> Self { + Self { inner } + } + + fn value(&self) -> i32 { + 42 + } + } + + fn some_foo(inner: &Inner) -> Foo<'_> { + Foo { inner } + } + + fn test() -> i32 { + let x = Inner {}; + let value = some_foo(&x).value(); + value + } + + fn test2() -> i32 { + let x = Inner {}; + let value = Foo::new(&x).value(); + value + } + } +} + +mod issue_5729 { + use std::sync::Arc; + + trait Foo {} + + trait FooStorage { + fn foo_cloned(&self) -> Arc; + } + + struct FooStorageImpl { + foo: Arc, + } + + impl FooStorage for FooStorageImpl { + fn foo_cloned(&self) -> Arc { + + Arc::clone(&self.foo) as _ + } + } +} + +// https://github.com/rust-lang/rust-clippy/issues/11167 +macro_rules! fn_in_macro { + ($b:block) => { + fn f() -> usize $b + } +} +fn_in_macro!({ + return 1; +}); + +fn main() {} diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs index 959567f686703..1271a1c123607 100644 --- a/tests/ui/let_if_seq.rs +++ b/tests/ui/let_if_seq.rs @@ -7,7 +7,7 @@ clippy::needless_late_init )] #![warn(clippy::useless_let_if_seq)] - +//@no-rustfix fn f() -> bool { true } diff --git a/tests/ui/let_underscore_future.rs b/tests/ui/let_underscore_future.rs index d8f54cdca9120..f904868577db2 100644 --- a/tests/ui/let_underscore_future.rs +++ b/tests/ui/let_underscore_future.rs @@ -1,5 +1,5 @@ use std::future::Future; - +//@no-rustfix async fn some_async_fn() {} fn sync_side_effects() {} diff --git a/tests/ui/let_unit.fixed b/tests/ui/let_unit.fixed index 8ba89ec78bbde..57374bd5fcdad 100644 --- a/tests/ui/let_unit.fixed +++ b/tests/ui/let_unit.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lint_reasons)] #![warn(clippy::let_unit_value)] #![allow(unused, clippy::no_effect, clippy::needless_late_init, path_statements)] diff --git a/tests/ui/let_unit.rs b/tests/ui/let_unit.rs index 7e8764a482a20..09077c60d5019 100644 --- a/tests/ui/let_unit.rs +++ b/tests/ui/let_unit.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lint_reasons)] #![warn(clippy::let_unit_value)] #![allow(unused, clippy::no_effect, clippy::needless_late_init, path_statements)] diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr index 49da74ca7e1c7..c54d4392a3469 100644 --- a/tests/ui/let_unit.stderr +++ b/tests/ui/let_unit.stderr @@ -1,5 +1,5 @@ error: this let-binding has unit value - --> $DIR/let_unit.rs:14:5 + --> $DIR/let_unit.rs:12:5 | LL | let _x = println!("x"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `println!("x");` @@ -7,13 +7,13 @@ LL | let _x = println!("x"); = note: `-D clippy::let-unit-value` implied by `-D warnings` error: this let-binding has unit value - --> $DIR/let_unit.rs:18:9 + --> $DIR/let_unit.rs:16:9 | LL | let _a = (); | ^^^^^^^^^^^^ help: omit the `let` binding: `();` error: this let-binding has unit value - --> $DIR/let_unit.rs:53:5 + --> $DIR/let_unit.rs:51:5 | LL | / let _ = v LL | | .into_iter() @@ -36,7 +36,7 @@ LL + .unwrap(); | error: this let-binding has unit value - --> $DIR/let_unit.rs:80:5 + --> $DIR/let_unit.rs:78:5 | LL | let x: () = f(); // Lint. | ^^^^-^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | let x: () = f(); // Lint. | help: use a wild (`_`) binding: `_` error: this let-binding has unit value - --> $DIR/let_unit.rs:83:5 + --> $DIR/let_unit.rs:81:5 | LL | let x: () = f2(0i32); // Lint. | ^^^^-^^^^^^^^^^^^^^^^ @@ -52,19 +52,19 @@ LL | let x: () = f2(0i32); // Lint. | help: use a wild (`_`) binding: `_` error: this let-binding has unit value - --> $DIR/let_unit.rs:85:5 + --> $DIR/let_unit.rs:83:5 | LL | let _: () = f3(()); // Lint | ^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `f3(());` error: this let-binding has unit value - --> $DIR/let_unit.rs:86:5 + --> $DIR/let_unit.rs:84:5 | LL | let x: () = f3(()); // Lint | ^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `f3(());` error: this let-binding has unit value - --> $DIR/let_unit.rs:102:5 + --> $DIR/let_unit.rs:100:5 | LL | let x: () = if true { f() } else { f2(0) }; // Lint | ^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | let x: () = if true { f() } else { f2(0) }; // Lint | help: use a wild (`_`) binding: `_` error: this let-binding has unit value - --> $DIR/let_unit.rs:113:5 + --> $DIR/let_unit.rs:111:5 | LL | / let _: () = match Some(0) { LL | | None => f2(1), @@ -93,7 +93,7 @@ LL + }; | error: this let-binding has unit value - --> $DIR/let_unit.rs:160:13 + --> $DIR/let_unit.rs:158:13 | LL | let _: () = z; | ^^^^^^^^^^^^^^ help: omit the `let` binding: `z;` diff --git a/tests/ui/lines_filter_map_ok.fixed b/tests/ui/lines_filter_map_ok.fixed index 64114f6585d31..74ef6f72957f7 100644 --- a/tests/ui/lines_filter_map_ok.fixed +++ b/tests/ui/lines_filter_map_ok.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::map_identity)] #![warn(clippy::lines_filter_map_ok)] diff --git a/tests/ui/lines_filter_map_ok.rs b/tests/ui/lines_filter_map_ok.rs index 5aedc68633607..345f4dc5f3045 100644 --- a/tests/ui/lines_filter_map_ok.rs +++ b/tests/ui/lines_filter_map_ok.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::map_identity)] #![warn(clippy::lines_filter_map_ok)] diff --git a/tests/ui/lines_filter_map_ok.stderr b/tests/ui/lines_filter_map_ok.stderr index cddd403d589c3..4244d85b448ad 100644 --- a/tests/ui/lines_filter_map_ok.stderr +++ b/tests/ui/lines_filter_map_ok.stderr @@ -1,48 +1,48 @@ error: `filter_map()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:11:31 + --> $DIR/lines_filter_map_ok.rs:9:31 | LL | BufReader::new(f).lines().filter_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error - --> $DIR/lines_filter_map_ok.rs:11:5 + --> $DIR/lines_filter_map_ok.rs:9:5 | LL | BufReader::new(f).lines().filter_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::lines-filter-map-ok` implied by `-D warnings` error: `flat_map()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:14:31 + --> $DIR/lines_filter_map_ok.rs:12:31 | LL | BufReader::new(f).lines().flat_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error - --> $DIR/lines_filter_map_ok.rs:14:5 + --> $DIR/lines_filter_map_ok.rs:12:5 | LL | BufReader::new(f).lines().flat_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `filter_map()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:17:25 + --> $DIR/lines_filter_map_ok.rs:15:25 | LL | io::stdin().lines().filter_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error - --> $DIR/lines_filter_map_ok.rs:17:5 + --> $DIR/lines_filter_map_ok.rs:15:5 | LL | io::stdin().lines().filter_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^ error: `filter_map()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:19:25 + --> $DIR/lines_filter_map_ok.rs:17:25 | LL | io::stdin().lines().filter_map(|x| x.ok()).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)` | note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error - --> $DIR/lines_filter_map_ok.rs:19:5 + --> $DIR/lines_filter_map_ok.rs:17:5 | LL | io::stdin().lines().filter_map(|x| x.ok()).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/literals.rs b/tests/ui/literals.rs index 1a646e49ce3ae..1a276153c7383 100644 --- a/tests/ui/literals.rs +++ b/tests/ui/literals.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions // does not test any rustfixable lints #![warn(clippy::mixed_case_hex_literals)] diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index 9bc7948c7cc1f..2a7785d4fb245 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -1,5 +1,5 @@ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:12:15 + --> $DIR/literals.rs:13:15 | LL | let ok4 = 0xab_cd_i32; | ^^^^^^^^^^^ help: remove the underscore: `0xab_cdi32` @@ -7,19 +7,19 @@ LL | let ok4 = 0xab_cd_i32; = note: `-D clippy::separated-literal-suffix` implied by `-D warnings` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:13:15 + --> $DIR/literals.rs:14:15 | LL | let ok5 = 0xAB_CD_u32; | ^^^^^^^^^^^ help: remove the underscore: `0xAB_CDu32` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:14:15 + --> $DIR/literals.rs:15:15 | LL | let ok5 = 0xAB_CD_isize; | ^^^^^^^^^^^^^ help: remove the underscore: `0xAB_CDisize` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:15:17 + --> $DIR/literals.rs:16:17 | LL | let fail1 = 0xabCD; | ^^^^^^ @@ -27,31 +27,31 @@ LL | let fail1 = 0xabCD; = note: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:16:17 + --> $DIR/literals.rs:17:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ help: remove the underscore: `0xabCDu32` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:16:17 + --> $DIR/literals.rs:17:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:17:17 + --> $DIR/literals.rs:18:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ help: remove the underscore: `0xabCDisize` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:17:17 + --> $DIR/literals.rs:18:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ error: integer type suffix should be separated by an underscore - --> $DIR/literals.rs:18:27 + --> $DIR/literals.rs:19:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ help: add an underscore: `000_123_usize` @@ -59,7 +59,7 @@ LL | let fail_multi_zero = 000_123usize; = note: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` error: this is a decimal constant - --> $DIR/literals.rs:18:27 + --> $DIR/literals.rs:19:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ @@ -75,13 +75,13 @@ LL | let fail_multi_zero = 0o123usize; | ~~~~~~~~~~ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:21:16 + --> $DIR/literals.rs:22:16 | LL | let ok10 = 0_i64; | ^^^^^ help: remove the underscore: `0i64` error: this is a decimal constant - --> $DIR/literals.rs:22:17 + --> $DIR/literals.rs:23:17 | LL | let fail8 = 0123; | ^^^^ @@ -96,13 +96,13 @@ LL | let fail8 = 0o123; | ~~~~~ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:31:16 + --> $DIR/literals.rs:32:16 | LL | let ok17 = 0x123_4567_8901_usize; | ^^^^^^^^^^^^^^^^^^^^^ help: remove the underscore: `0x123_4567_8901usize` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:34:18 + --> $DIR/literals.rs:35:18 | LL | let fail19 = 12_3456_21; | ^^^^^^^^^^ help: consider: `12_345_621` @@ -110,19 +110,19 @@ LL | let fail19 = 12_3456_21; = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:35:18 + --> $DIR/literals.rs:36:18 | LL | let fail22 = 3__4___23; | ^^^^^^^^^ help: consider: `3_423` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:36:18 + --> $DIR/literals.rs:37:18 | LL | let fail23 = 3__16___23; | ^^^^^^^^^^ help: consider: `31_623` error: digits of hex, binary or octal literal not in groups of equal size - --> $DIR/literals.rs:38:18 + --> $DIR/literals.rs:39:18 | LL | let fail24 = 0xAB_ABC_AB; | ^^^^^^^^^^^ help: consider: `0x0ABA_BCAB` @@ -130,7 +130,7 @@ LL | let fail24 = 0xAB_ABC_AB; = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` error: this is a decimal constant - --> $DIR/literals.rs:46:13 + --> $DIR/literals.rs:47:13 | LL | let _ = 08; | ^^ @@ -141,7 +141,7 @@ LL | let _ = 8; | ~ error: this is a decimal constant - --> $DIR/literals.rs:47:13 + --> $DIR/literals.rs:48:13 | LL | let _ = 09; | ^^ @@ -152,7 +152,7 @@ LL | let _ = 9; | ~ error: this is a decimal constant - --> $DIR/literals.rs:48:13 + --> $DIR/literals.rs:49:13 | LL | let _ = 089; | ^^^ diff --git a/tests/ui/lossy_float_literal.fixed b/tests/ui/lossy_float_literal.fixed index e19f4980cd70d..92a0084a6aebb 100644 --- a/tests/ui/lossy_float_literal.fixed +++ b/tests/ui/lossy_float_literal.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::lossy_float_literal)] #![allow(overflowing_literals, unused)] diff --git a/tests/ui/lossy_float_literal.rs b/tests/ui/lossy_float_literal.rs index a2a1cfb317e11..5abef3c442eca 100644 --- a/tests/ui/lossy_float_literal.rs +++ b/tests/ui/lossy_float_literal.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::lossy_float_literal)] #![allow(overflowing_literals, unused)] diff --git a/tests/ui/lossy_float_literal.stderr b/tests/ui/lossy_float_literal.stderr index 2d72b16430c40..d2193c0c81955 100644 --- a/tests/ui/lossy_float_literal.stderr +++ b/tests/ui/lossy_float_literal.stderr @@ -1,5 +1,5 @@ error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:7:18 + --> $DIR/lossy_float_literal.rs:6:18 | LL | let _: f32 = 16_777_217.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_216.0` @@ -7,61 +7,61 @@ LL | let _: f32 = 16_777_217.0; = note: `-D clippy::lossy-float-literal` implied by `-D warnings` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:8:18 + --> $DIR/lossy_float_literal.rs:7:18 | LL | let _: f32 = 16_777_219.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:9:18 + --> $DIR/lossy_float_literal.rs:8:18 | LL | let _: f32 = 16_777_219.; | ^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:10:18 + --> $DIR/lossy_float_literal.rs:9:18 | LL | let _: f32 = 16_777_219.000; | ^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:11:13 + --> $DIR/lossy_float_literal.rs:10:13 | LL | let _ = 16_777_219f32; | ^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220_f32` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:12:19 + --> $DIR/lossy_float_literal.rs:11:19 | LL | let _: f32 = -16_777_219.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:13:18 + --> $DIR/lossy_float_literal.rs:12:18 | LL | let _: f64 = 9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:14:18 + --> $DIR/lossy_float_literal.rs:13:18 | LL | let _: f64 = 9_007_199_254_740_993.; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:15:18 + --> $DIR/lossy_float_literal.rs:14:18 | LL | let _: f64 = 9_007_199_254_740_993.00; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:16:13 + --> $DIR/lossy_float_literal.rs:15:13 | LL | let _ = 9_007_199_254_740_993f64; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992_f64` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:17:19 + --> $DIR/lossy_float_literal.rs:16:19 | LL | let _: f64 = -9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` diff --git a/tests/ui/macro_use_imports.fixed b/tests/ui/macro_use_imports.fixed index 53b6a0250f99a..2d8ac229226bc 100644 --- a/tests/ui/macro_use_imports.fixed +++ b/tests/ui/macro_use_imports.fixed @@ -1,7 +1,7 @@ //@aux-build:macro_rules.rs //@aux-build:macro_use_helper.rs //@aux-build:proc_macro_derive.rs:proc-macro -//@run-rustfix + //@ignore-32bit #![feature(lint_reasons)] diff --git a/tests/ui/macro_use_imports.rs b/tests/ui/macro_use_imports.rs index a40fa389895aa..3ad81ef671947 100644 --- a/tests/ui/macro_use_imports.rs +++ b/tests/ui/macro_use_imports.rs @@ -1,7 +1,7 @@ //@aux-build:macro_rules.rs //@aux-build:macro_use_helper.rs //@aux-build:proc_macro_derive.rs:proc-macro -//@run-rustfix + //@ignore-32bit #![feature(lint_reasons)] diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr index 67a833e85e046..72ae0bea1fa9f 100644 --- a/tests/ui/macro_use_imports.stderr +++ b/tests/ui/macro_use_imports.stderr @@ -1,28 +1,28 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:19:5 + --> $DIR/macro_use_imports.rs:23:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};` | = note: `-D clippy::macro-use-imports` implied by `-D warnings` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:23:5 + --> $DIR/macro_use_imports.rs:19:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:25:5 + --> $DIR/macro_use_imports.rs:21:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:21:5 + --> $DIR/macro_use_imports.rs:25:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` error: aborting due to 4 previous errors diff --git a/tests/ui/manual_assert.edition2018.fixed b/tests/ui/manual_assert.edition2018.fixed index d8dde0236eae1..75beedfa45086 100644 --- a/tests/ui/manual_assert.edition2018.fixed +++ b/tests/ui/manual_assert.edition2018.fixed @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::manual_assert)] #![allow(dead_code, unused_doc_comments)] diff --git a/tests/ui/manual_assert.edition2018.stderr b/tests/ui/manual_assert.edition2018.stderr index 3555ac29243a1..1bf61fa33bf04 100644 --- a/tests/ui/manual_assert.edition2018.stderr +++ b/tests/ui/manual_assert.edition2018.stderr @@ -1,5 +1,5 @@ error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:31:5 + --> $DIR/manual_assert.rs:30:5 | LL | / if !a.is_empty() { LL | | panic!("qaqaq{:?}", a); @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::manual-assert` implied by `-D warnings` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:34:5 + --> $DIR/manual_assert.rs:33:5 | LL | / if !a.is_empty() { LL | | panic!("qwqwq"); @@ -17,7 +17,7 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:51:5 + --> $DIR/manual_assert.rs:50:5 | LL | / if b.is_empty() { LL | | panic!("panic1"); @@ -25,7 +25,7 @@ LL | | } | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:54:5 + --> $DIR/manual_assert.rs:53:5 | LL | / if b.is_empty() && a.is_empty() { LL | | panic!("panic2"); @@ -33,7 +33,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:57:5 + --> $DIR/manual_assert.rs:56:5 | LL | / if a.is_empty() && !b.is_empty() { LL | | panic!("panic3"); @@ -41,7 +41,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:60:5 + --> $DIR/manual_assert.rs:59:5 | LL | / if b.is_empty() || a.is_empty() { LL | | panic!("panic4"); @@ -49,7 +49,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:63:5 + --> $DIR/manual_assert.rs:62:5 | LL | / if a.is_empty() || !b.is_empty() { LL | | panic!("panic5"); @@ -57,7 +57,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:66:5 + --> $DIR/manual_assert.rs:65:5 | LL | / if a.is_empty() { LL | | panic!("with expansion {}", one!()) @@ -65,7 +65,7 @@ LL | | } | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:78:5 + --> $DIR/manual_assert.rs:77:5 | LL | / if a > 2 { LL | | // comment diff --git a/tests/ui/manual_assert.edition2021.fixed b/tests/ui/manual_assert.edition2021.fixed index d8dde0236eae1..75beedfa45086 100644 --- a/tests/ui/manual_assert.edition2021.fixed +++ b/tests/ui/manual_assert.edition2021.fixed @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::manual_assert)] #![allow(dead_code, unused_doc_comments)] diff --git a/tests/ui/manual_assert.edition2021.stderr b/tests/ui/manual_assert.edition2021.stderr index 3555ac29243a1..1bf61fa33bf04 100644 --- a/tests/ui/manual_assert.edition2021.stderr +++ b/tests/ui/manual_assert.edition2021.stderr @@ -1,5 +1,5 @@ error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:31:5 + --> $DIR/manual_assert.rs:30:5 | LL | / if !a.is_empty() { LL | | panic!("qaqaq{:?}", a); @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::manual-assert` implied by `-D warnings` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:34:5 + --> $DIR/manual_assert.rs:33:5 | LL | / if !a.is_empty() { LL | | panic!("qwqwq"); @@ -17,7 +17,7 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:51:5 + --> $DIR/manual_assert.rs:50:5 | LL | / if b.is_empty() { LL | | panic!("panic1"); @@ -25,7 +25,7 @@ LL | | } | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:54:5 + --> $DIR/manual_assert.rs:53:5 | LL | / if b.is_empty() && a.is_empty() { LL | | panic!("panic2"); @@ -33,7 +33,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:57:5 + --> $DIR/manual_assert.rs:56:5 | LL | / if a.is_empty() && !b.is_empty() { LL | | panic!("panic3"); @@ -41,7 +41,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:60:5 + --> $DIR/manual_assert.rs:59:5 | LL | / if b.is_empty() || a.is_empty() { LL | | panic!("panic4"); @@ -49,7 +49,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:63:5 + --> $DIR/manual_assert.rs:62:5 | LL | / if a.is_empty() || !b.is_empty() { LL | | panic!("panic5"); @@ -57,7 +57,7 @@ LL | | } | |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:66:5 + --> $DIR/manual_assert.rs:65:5 | LL | / if a.is_empty() { LL | | panic!("with expansion {}", one!()) @@ -65,7 +65,7 @@ LL | | } | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:78:5 + --> $DIR/manual_assert.rs:77:5 | LL | / if a > 2 { LL | | // comment diff --git a/tests/ui/manual_assert.rs b/tests/ui/manual_assert.rs index 0f87d6e2d2c93..5979496ca8361 100644 --- a/tests/ui/manual_assert.rs +++ b/tests/ui/manual_assert.rs @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::manual_assert)] #![allow(dead_code, unused_doc_comments)] diff --git a/tests/ui/manual_async_fn.fixed b/tests/ui/manual_async_fn.fixed index e609b4b1bdb03..18444090a4260 100644 --- a/tests/ui/manual_async_fn.fixed +++ b/tests/ui/manual_async_fn.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_async_fn)] #![allow(clippy::needless_pub_self, unused)] diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs index 6c1a9edaa110d..d42165bbe3d8c 100644 --- a/tests/ui/manual_async_fn.rs +++ b/tests/ui/manual_async_fn.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_async_fn)] #![allow(clippy::needless_pub_self, unused)] diff --git a/tests/ui/manual_async_fn.stderr b/tests/ui/manual_async_fn.stderr index f5ee3eb7cccba..b196614dff96b 100644 --- a/tests/ui/manual_async_fn.stderr +++ b/tests/ui/manual_async_fn.stderr @@ -1,5 +1,5 @@ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:7:1 + --> $DIR/manual_async_fn.rs:6:1 | LL | fn fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | fn fut() -> impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:12:1 + --> $DIR/manual_async_fn.rs:11:1 | LL | fn fut2() ->impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | fn fut2() ->impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:17:1 + --> $DIR/manual_async_fn.rs:16:1 | LL | fn fut3()-> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | fn fut3()-> impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:21:1 + --> $DIR/manual_async_fn.rs:20:1 | LL | fn empty_fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | fn empty_fut() -> impl Future {} | ~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:26:1 + --> $DIR/manual_async_fn.rs:25:1 | LL | fn empty_fut2() ->impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL | fn empty_fut2() ->impl Future {} | ~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:31:1 + --> $DIR/manual_async_fn.rs:30:1 | LL | fn empty_fut3()-> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | fn empty_fut3()-> impl Future {} | ~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:35:1 + --> $DIR/manual_async_fn.rs:34:1 | LL | fn core_fut() -> impl core::future::Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ LL | fn core_fut() -> impl core::future::Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:57:5 + --> $DIR/manual_async_fn.rs:56:5 | LL | fn inh_fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL + } | error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:92:1 + --> $DIR/manual_async_fn.rs:91:1 | LL | fn elided(_: &i32) -> impl Future + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -147,7 +147,7 @@ LL | fn elided(_: &i32) -> impl Future + '_ { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:101:1 + --> $DIR/manual_async_fn.rs:100:1 | LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -162,7 +162,7 @@ LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:130:1 + --> $DIR/manual_async_fn.rs:129:1 | LL | pub fn issue_10450() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | pub fn issue_10450() -> impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:134:1 + --> $DIR/manual_async_fn.rs:133:1 | LL | pub(crate) fn issue_10450_2() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -192,7 +192,7 @@ LL | pub(crate) fn issue_10450_2() -> impl Future { 42 } | ~~~~~~ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:138:1 + --> $DIR/manual_async_fn.rs:137:1 | LL | pub(self) fn issue_10450_3() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_bits.fixed b/tests/ui/manual_bits.fixed index 037de0262e2f2..4de01905e8ad1 100644 --- a/tests/ui/manual_bits.fixed +++ b/tests/ui/manual_bits.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_bits)] #![allow( clippy::no_effect, diff --git a/tests/ui/manual_bits.rs b/tests/ui/manual_bits.rs index b15a531ec1751..d4f369fcf87d8 100644 --- a/tests/ui/manual_bits.rs +++ b/tests/ui/manual_bits.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_bits)] #![allow( clippy::no_effect, diff --git a/tests/ui/manual_bits.stderr b/tests/ui/manual_bits.stderr index 652fafbc41d81..95910650da93b 100644 --- a/tests/ui/manual_bits.stderr +++ b/tests/ui/manual_bits.stderr @@ -1,5 +1,5 @@ error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:16:5 + --> $DIR/manual_bits.rs:14:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `i8::BITS as usize` @@ -7,169 +7,169 @@ LL | size_of::() * 8; = note: `-D clippy::manual-bits` implied by `-D warnings` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:17:5 + --> $DIR/manual_bits.rs:15:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i16::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:18:5 + --> $DIR/manual_bits.rs:16:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i32::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:19:5 + --> $DIR/manual_bits.rs:17:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i64::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:20:5 + --> $DIR/manual_bits.rs:18:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `i128::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:21:5 + --> $DIR/manual_bits.rs:19:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `isize::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:23:5 + --> $DIR/manual_bits.rs:21:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `u8::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:24:5 + --> $DIR/manual_bits.rs:22:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u16::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:25:5 + --> $DIR/manual_bits.rs:23:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u32::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:26:5 + --> $DIR/manual_bits.rs:24:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u64::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:27:5 + --> $DIR/manual_bits.rs:25:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:28:5 + --> $DIR/manual_bits.rs:26:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `usize::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:30:5 + --> $DIR/manual_bits.rs:28:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `i8::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:31:5 + --> $DIR/manual_bits.rs:29:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i16::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:32:5 + --> $DIR/manual_bits.rs:30:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i32::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:33:5 + --> $DIR/manual_bits.rs:31:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i64::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:34:5 + --> $DIR/manual_bits.rs:32:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `i128::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:35:5 + --> $DIR/manual_bits.rs:33:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `isize::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:37:5 + --> $DIR/manual_bits.rs:35:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `u8::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:38:5 + --> $DIR/manual_bits.rs:36:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u16::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:39:5 + --> $DIR/manual_bits.rs:37:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u32::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:40:5 + --> $DIR/manual_bits.rs:38:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u64::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:41:5 + --> $DIR/manual_bits.rs:39:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:42:5 + --> $DIR/manual_bits.rs:40:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `usize::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:52:5 + --> $DIR/manual_bits.rs:50:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `Word::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:56:18 + --> $DIR/manual_bits.rs:54:18 | LL | let _: u32 = (size_of::() * 8) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:57:18 + --> $DIR/manual_bits.rs:55:18 | LL | let _: u32 = (size_of::() * 8).try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:58:13 + --> $DIR/manual_bits.rs:56:13 | LL | let _ = (size_of::() * 8).pow(5); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(u128::BITS as usize)` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:59:14 + --> $DIR/manual_bits.rs:57:14 | LL | let _ = &(size_of::() * 8); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(u128::BITS as usize)` diff --git a/tests/ui/manual_clamp.fixed b/tests/ui/manual_clamp.fixed new file mode 100644 index 0000000000000..592d172228147 --- /dev/null +++ b/tests/ui/manual_clamp.fixed @@ -0,0 +1,260 @@ +#![warn(clippy::manual_clamp)] +#![allow( + unused, + dead_code, + clippy::unnecessary_operation, + clippy::no_effect, + clippy::if_same_then_else +)] + +use std::cmp::{max as cmp_max, min as cmp_min}; + +const CONST_MAX: i32 = 10; +const CONST_MIN: i32 = 4; + +const CONST_F64_MAX: f64 = 10.0; +const CONST_F64_MIN: f64 = 4.0; + +fn main() { + let (input, min, max) = (0, -2, 3); + // Lint + let x0 = input.clamp(min, max); + + let x1 = input.clamp(min, max); + + let x2 = input.clamp(min, max); + + let x3 = input.clamp(min, max); + + let x4 = input.clamp(min, max); + + let x5 = input.clamp(min, max); + + let x6 = input.clamp(min, max); + + let x7 = input.clamp(min, max); + + let x8 = input.clamp(min, max); + + let mut x9 = input; + x9 = x9.clamp(min, max); + + let x10 = input.clamp(min, max); + + let mut x11 = input; + let _ = 1; + x11 = x11.clamp(min, max); + + let mut x12 = input; + x12 = x12.clamp(min, max); + + let mut x13 = input; + x13 = x13.clamp(min, max); + + let x14 = input.clamp(CONST_MIN, CONST_MAX); + { + let (input, min, max) = (0.0f64, -2.0, 3.0); + let x15 = input.clamp(min, max); + } + { + let input: i32 = cmp_min_max(1); + // These can only be detected if exactly one of the arguments to the inner function is const. + let x16 = input.clamp(CONST_MIN, CONST_MAX); + let x17 = input.clamp(CONST_MIN, CONST_MAX); + let x18 = input.clamp(CONST_MIN, CONST_MAX); + let x19 = input.clamp(CONST_MIN, CONST_MAX); + let x20 = input.clamp(CONST_MIN, CONST_MAX); + let x21 = input.clamp(CONST_MIN, CONST_MAX); + let x22 = input.clamp(CONST_MIN, CONST_MAX); + let x23 = input.clamp(CONST_MIN, CONST_MAX); + let input: f64 = cmp_min_max(1) as f64; + let x24 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + let x25 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + let x26 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + let x27 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + let x28 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + let x29 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + let x30 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + let x31 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + } + let mut x32 = input; + x32 = x32.clamp(min, max); + + // It's important this be the last set of statements + let mut x33 = input; + x33 = x33.clamp(min, max); +} + +// This code intentionally nonsense. +fn no_lint() { + let (input, min, max) = (0, -2, 3); + let x0 = if max < input { + max + } else if min > input { + max + } else { + min + }; + + let x1 = if input > max { + max + } else if input > min { + min + } else { + max + }; + + let x2 = if max < min { + min + } else if input > max { + input + } else { + input + }; + + let x3 = if min > input { + input + } else if max < input { + max + } else { + max + }; + + let x6 = match input { + x if x < max => x, + x if x < min => x, + x => x, + }; + + let x7 = match input { + x if x < min => max, + x if x > max => min, + x => x, + }; + + let x8 = match input { + x if max > x => max, + x if min > x => min, + x => x, + }; + + let mut x9 = input; + if x9 > min { + x9 = min; + } + if x9 > max { + x9 = max; + } + + let x10 = match input { + x if min > x => min, + x if max < x => max, + x => min, + }; + + let mut x11 = input; + if x11 > max { + x11 = min; + } + if x11 < min { + x11 = max; + } + + let mut x12 = input; + if min > x12 { + x12 = max * 3; + } + if max < x12 { + x12 = min; + } + + let mut x13 = input; + if max < x13 { + let x13 = max; + } + if min > x13 { + x13 = min; + } + let mut x14 = input; + if x14 < min { + x14 = 3; + } else if x14 > max { + x14 = max; + } + { + let input: i32 = cmp_min_max(1); + // These can only be detected if exactly one of the arguments to the inner function is const. + let x16 = cmp_max(cmp_max(input, CONST_MAX), CONST_MIN); + let x17 = cmp_min(cmp_min(input, CONST_MIN), CONST_MAX); + let x18 = cmp_max(CONST_MIN, cmp_max(input, CONST_MAX)); + let x19 = cmp_min(CONST_MAX, cmp_min(input, CONST_MIN)); + let x20 = cmp_max(cmp_max(CONST_MAX, input), CONST_MIN); + let x21 = cmp_min(cmp_min(CONST_MIN, input), CONST_MAX); + let x22 = cmp_max(CONST_MIN, cmp_max(CONST_MAX, input)); + let x23 = cmp_min(CONST_MAX, cmp_min(CONST_MIN, input)); + let input: f64 = cmp_min_max(1) as f64; + let x24 = f64::max(f64::max(input, CONST_F64_MAX), CONST_F64_MIN); + let x25 = f64::min(f64::min(input, CONST_F64_MIN), CONST_F64_MAX); + let x26 = f64::max(CONST_F64_MIN, f64::max(input, CONST_F64_MAX)); + let x27 = f64::min(CONST_F64_MAX, f64::min(input, CONST_F64_MIN)); + let x28 = f64::max(f64::max(CONST_F64_MAX, input), CONST_F64_MIN); + let x29 = f64::min(f64::min(CONST_F64_MIN, input), CONST_F64_MAX); + let x30 = f64::max(CONST_F64_MIN, f64::max(CONST_F64_MAX, input)); + let x31 = f64::min(CONST_F64_MAX, f64::min(CONST_F64_MIN, input)); + let x32 = f64::min(CONST_F64_MAX, f64::min(CONST_F64_MIN, CONST_F64_MAX)); + } +} + +fn dont_tell_me_what_to_do() { + let (input, min, max) = (0, -2, 3); + let mut x_never = input; + #[allow(clippy::manual_clamp)] + if x_never < min { + x_never = min; + } + if x_never > max { + x_never = max; + } +} + +/// Just to ensure this isn't const evaled +fn cmp_min_max(input: i32) -> i32 { + input * 3 +} + +#[clippy::msrv = "1.49"] +fn msrv_1_49() { + let (input, min, max) = (0, -1, 2); + let _ = if input < min { + min + } else if input > max { + max + } else { + input + }; +} + +#[clippy::msrv = "1.50"] +fn msrv_1_50() { + let (input, min, max) = (0, -1, 2); + let _ = input.clamp(min, max); +} + +const fn _const() { + let (input, min, max) = (0, -1, 2); + let _ = if input < min { + min + } else if input > max { + max + } else { + input + }; + + let mut x = input; + if max < x { + let x = max; + } + if min > x { + x = min; + } +} diff --git a/tests/ui/manual_filter.fixed b/tests/ui/manual_filter.fixed index 5e3b12e510b84..c1bc4aae92ead 100644 --- a/tests/ui/manual_filter.fixed +++ b/tests/ui/manual_filter.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_filter)] #![allow(unused_variables, dead_code, clippy::useless_vec)] diff --git a/tests/ui/manual_filter.rs b/tests/ui/manual_filter.rs index b81604b0372b5..06968f8bae4ad 100644 --- a/tests/ui/manual_filter.rs +++ b/tests/ui/manual_filter.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_filter)] #![allow(unused_variables, dead_code, clippy::useless_vec)] diff --git a/tests/ui/manual_filter.stderr b/tests/ui/manual_filter.stderr index f62d3e960594b..a2d56f87b64ab 100644 --- a/tests/ui/manual_filter.stderr +++ b/tests/ui/manual_filter.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:7:5 + --> $DIR/manual_filter.rs:5:5 | LL | / match Some(0) { LL | | None => None, @@ -13,7 +13,7 @@ LL | | }; = note: `-D clippy::manual-filter` implied by `-D warnings` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:18:5 + --> $DIR/manual_filter.rs:16:5 | LL | / match Some(1) { LL | | Some(x) => { @@ -25,7 +25,7 @@ LL | | }; | |_____^ help: try: `Some(1).filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:29:5 + --> $DIR/manual_filter.rs:27:5 | LL | / match Some(2) { LL | | Some(x) => { @@ -37,7 +37,7 @@ LL | | }; | |_____^ help: try: `Some(2).filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:40:5 + --> $DIR/manual_filter.rs:38:5 | LL | / match Some(3) { LL | | Some(x) => { @@ -49,7 +49,7 @@ LL | | }; | |_____^ help: try: `Some(3).filter(|&x| x > 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:52:5 + --> $DIR/manual_filter.rs:50:5 | LL | / match y { LL | | // Some(4) @@ -61,7 +61,7 @@ LL | | }; | |_____^ help: try: `y.filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:64:5 + --> $DIR/manual_filter.rs:62:5 | LL | / match Some(5) { LL | | Some(x) => { @@ -73,7 +73,7 @@ LL | | }; | |_____^ help: try: `Some(5).filter(|&x| x > 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:75:5 + --> $DIR/manual_filter.rs:73:5 | LL | / match Some(6) { LL | | Some(ref x) => { @@ -85,7 +85,7 @@ LL | | }; | |_____^ help: try: `Some(6).as_ref().filter(|&x| x > &0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:87:5 + --> $DIR/manual_filter.rs:85:5 | LL | / match Some(String::new()) { LL | | Some(x) => { @@ -97,7 +97,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).filter(|x| external_cond)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:98:5 + --> $DIR/manual_filter.rs:96:5 | LL | / if let Some(x) = Some(7) { LL | | if external_cond { Some(x) } else { None } @@ -107,7 +107,7 @@ LL | | }; | |_____^ help: try: `Some(7).filter(|&x| external_cond)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:104:5 + --> $DIR/manual_filter.rs:102:5 | LL | / match &Some(8) { LL | | &Some(x) => { @@ -119,7 +119,7 @@ LL | | }; | |_____^ help: try: `Some(8).filter(|&x| x != 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:115:5 + --> $DIR/manual_filter.rs:113:5 | LL | / match Some(9) { LL | | Some(x) => { @@ -131,7 +131,7 @@ LL | | }; | |_____^ help: try: `Some(9).filter(|&x| x > 10 && x < 100)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:141:5 + --> $DIR/manual_filter.rs:139:5 | LL | / match Some(11) { LL | | // Lint, statement is preserved by `.filter` @@ -151,7 +151,7 @@ LL ~ }); | error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:185:13 + --> $DIR/manual_filter.rs:183:13 | LL | let _ = match Some(14) { | _____________^ @@ -164,7 +164,7 @@ LL | | }; | |_____^ help: try: `Some(14).filter(|&x| unsafe { f(x) })` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:195:13 + --> $DIR/manual_filter.rs:193:13 | LL | let _ = match Some(15) { | _____________^ @@ -176,7 +176,7 @@ LL | | }; | |_____^ help: try: `Some(15).filter(|&x| unsafe { f(x) })` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:205:12 + --> $DIR/manual_filter.rs:203:12 | LL | } else if let Some(x) = Some(16) { | ____________^ diff --git a/tests/ui/manual_filter_map.fixed b/tests/ui/manual_filter_map.fixed index 35872a39a7117..4de45e39b1004 100644 --- a/tests/ui/manual_filter_map.fixed +++ b/tests/ui/manual_filter_map.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::manual_filter_map)] #![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure diff --git a/tests/ui/manual_filter_map.rs b/tests/ui/manual_filter_map.rs index 50d8d2722c238..22f316f90b6a1 100644 --- a/tests/ui/manual_filter_map.rs +++ b/tests/ui/manual_filter_map.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::manual_filter_map)] #![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure diff --git a/tests/ui/manual_filter_map.stderr b/tests/ui/manual_filter_map.stderr index 0e8672c029309..5b8a553f84f9e 100644 --- a/tests/ui/manual_filter_map.stderr +++ b/tests/ui/manual_filter_map.stderr @@ -1,42 +1,42 @@ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:9:19 + --> $DIR/manual_filter_map.rs:8:19 | LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_opt(a))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:9:30 + --> $DIR/manual_filter_map.rs:8:30 | LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^ = note: `-D clippy::manual-filter-map` implied by `-D warnings` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:12:19 + --> $DIR/manual_filter_map.rs:11:19 | LL | let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_opt(a))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:12:31 + --> $DIR/manual_filter_map.rs:11:31 | LL | let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); | ^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:15:19 + --> $DIR/manual_filter_map.rs:14:19 | LL | let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_res(a).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:15:31 + --> $DIR/manual_filter_map.rs:14:31 | LL | let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); | ^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:18:10 + --> $DIR/manual_filter_map.rs:17:10 | LL | .filter(|&x| to_ref(to_opt(x)).is_some()) | __________^ @@ -44,13 +44,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap()); | |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:18:22 + --> $DIR/manual_filter_map.rs:17:22 | LL | .filter(|&x| to_ref(to_opt(x)).is_some()) | ^^^^^^^^^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:21:10 + --> $DIR/manual_filter_map.rs:20:10 | LL | .filter(|x| to_ref(to_opt(*x)).is_some()) | __________^ @@ -58,13 +58,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap()); | |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:21:21 + --> $DIR/manual_filter_map.rs:20:21 | LL | .filter(|x| to_ref(to_opt(*x)).is_some()) | ^^^^^^^^^^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:25:10 + --> $DIR/manual_filter_map.rs:24:10 | LL | .filter(|&x| to_ref(to_res(x)).is_ok()) | __________^ @@ -72,13 +72,13 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap()); | |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:25:22 + --> $DIR/manual_filter_map.rs:24:22 | LL | .filter(|&x| to_ref(to_res(x)).is_ok()) | ^^^^^^^^^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:28:10 + --> $DIR/manual_filter_map.rs:27:10 | LL | .filter(|x| to_ref(to_res(*x)).is_ok()) | __________^ @@ -86,13 +86,13 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap()); | |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:28:21 + --> $DIR/manual_filter_map.rs:27:21 | LL | .filter(|x| to_ref(to_res(*x)).is_ok()) | ^^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:34:27 + --> $DIR/manual_filter_map.rs:33:27 | LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` @@ -100,79 +100,79 @@ LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap() = note: `-D clippy::manual-find-map` implied by `-D warnings` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:35:28 + --> $DIR/manual_filter_map.rs:34:28 | LL | iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:36:31 + --> $DIR/manual_filter_map.rs:35:31 | LL | iter::<&Option>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:37:31 + --> $DIR/manual_filter_map.rs:36:31 | LL | iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:37:41 + --> $DIR/manual_filter_map.rs:36:41 | LL | iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:39:30 + --> $DIR/manual_filter_map.rs:38:30 | LL | iter::>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:40:31 + --> $DIR/manual_filter_map.rs:39:31 | LL | iter::<&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:41:32 + --> $DIR/manual_filter_map.rs:40:32 | LL | iter::<&&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:42:31 + --> $DIR/manual_filter_map.rs:41:31 | LL | iter::>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:43:32 + --> $DIR/manual_filter_map.rs:42:32 | LL | iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:44:35 + --> $DIR/manual_filter_map.rs:43:35 | LL | iter::<&Result>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_filter_map.rs:45:35 + --> $DIR/manual_filter_map.rs:44:35 | LL | iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned().ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_filter_map.rs:45:45 + --> $DIR/manual_filter_map.rs:44:45 | LL | iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:93:10 + --> $DIR/manual_filter_map.rs:92:10 | LL | .filter(|f| f.option_field.is_some()) | __________^ @@ -180,7 +180,7 @@ LL | | .map(|f| f.option_field.clone().unwrap()); | |_________________________________________________^ help: try: `filter_map(|f| f.option_field.clone())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:98:10 + --> $DIR/manual_filter_map.rs:97:10 | LL | .filter(|f| f.ref_field.is_some()) | __________^ @@ -188,7 +188,7 @@ LL | | .map(|f| f.ref_field.cloned().unwrap()); | |_______________________________________________^ help: try: `filter_map(|f| f.ref_field.cloned())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:103:10 + --> $DIR/manual_filter_map.rs:102:10 | LL | .filter(|f| f.ref_field.is_some()) | __________^ @@ -196,7 +196,7 @@ LL | | .map(|f| f.ref_field.copied().unwrap()); | |_______________________________________________^ help: try: `filter_map(|f| f.ref_field.copied())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:108:10 + --> $DIR/manual_filter_map.rs:107:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -204,7 +204,7 @@ LL | | .map(|f| f.result_field.clone().unwrap()); | |_________________________________________________^ help: try: `filter_map(|f| f.result_field.clone().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:113:10 + --> $DIR/manual_filter_map.rs:112:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -212,7 +212,7 @@ LL | | .map(|f| f.result_field.as_ref().unwrap()); | |__________________________________________________^ help: try: `filter_map(|f| f.result_field.as_ref().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:118:10 + --> $DIR/manual_filter_map.rs:117:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -220,7 +220,7 @@ LL | | .map(|f| f.result_field.as_deref().unwrap()); | |____________________________________________________^ help: try: `filter_map(|f| f.result_field.as_deref().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:123:10 + --> $DIR/manual_filter_map.rs:122:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -228,7 +228,7 @@ LL | | .map(|f| f.result_field.as_mut().unwrap()); | |__________________________________________________^ help: try: `filter_map(|f| f.result_field.as_mut().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:128:10 + --> $DIR/manual_filter_map.rs:127:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -236,7 +236,7 @@ LL | | .map(|f| f.result_field.as_deref_mut().unwrap()); | |________________________________________________________^ help: try: `filter_map(|f| f.result_field.as_deref_mut().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:133:10 + --> $DIR/manual_filter_map.rs:132:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -244,7 +244,7 @@ LL | | .map(|f| f.result_field.to_owned().unwrap()); | |____________________________________________________^ help: try: `filter_map(|f| f.result_field.to_owned().ok())` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:146:27 + --> $DIR/manual_filter_map.rs:145:27 | LL | let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x { | ___________________________^ @@ -254,7 +254,7 @@ LL | | }); | |______^ help: try: `filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })` error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:156:10 + --> $DIR/manual_filter_map.rs:155:10 | LL | .filter(|x| matches!(x, Enum::A(_))) | __________^ diff --git a/tests/ui/manual_find.rs b/tests/ui/manual_find.rs index 257fe045f78a1..bab37c465353a 100644 --- a/tests/ui/manual_find.rs +++ b/tests/ui/manual_find.rs @@ -1,6 +1,6 @@ #![allow(unused)] #![warn(clippy::manual_find)] - +//@no-rustfix fn vec_string(strings: Vec) -> Option { for s in strings { if s == String::new() { diff --git a/tests/ui/manual_find_fixable.fixed b/tests/ui/manual_find_fixable.fixed index 9c5eb20c81cb0..5e6849a4dfb0f 100644 --- a/tests/ui/manual_find_fixable.fixed +++ b/tests/ui/manual_find_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_find)] #![allow(unused)] #![allow(clippy::needless_return, clippy::uninlined_format_args)] diff --git a/tests/ui/manual_find_fixable.rs b/tests/ui/manual_find_fixable.rs index 7b670320ee336..56c3f2629c7a2 100644 --- a/tests/ui/manual_find_fixable.rs +++ b/tests/ui/manual_find_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_find)] #![allow(unused)] #![allow(clippy::needless_return, clippy::uninlined_format_args)] diff --git a/tests/ui/manual_find_fixable.stderr b/tests/ui/manual_find_fixable.stderr index dbc4ff69a740b..2c6f79e928a61 100644 --- a/tests/ui/manual_find_fixable.stderr +++ b/tests/ui/manual_find_fixable.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:11:5 + --> $DIR/manual_find_fixable.rs:10:5 | LL | / for &v in ARRAY { LL | | if v == n { @@ -12,7 +12,7 @@ LL | | None = note: `-D clippy::manual-find` implied by `-D warnings` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:20:5 + --> $DIR/manual_find_fixable.rs:19:5 | LL | / for (a, _) in arr { LL | | if a % 2 == 0 { @@ -23,7 +23,7 @@ LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|(a, _)| a).find(|&a| a % 2 == 0)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:33:5 + --> $DIR/manual_find_fixable.rs:32:5 | LL | / for el in arr { LL | | if el.name.len() == 10 { @@ -36,7 +36,7 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:43:5 + --> $DIR/manual_find_fixable.rs:42:5 | LL | / for Tuple(a, _) in arr { LL | | if a >= 3 { @@ -47,7 +47,7 @@ LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|Tuple(a, _)| a).find(|&a| a >= 3)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:58:5 + --> $DIR/manual_find_fixable.rs:57:5 | LL | / for el in arr { LL | | if el.should_keep() { @@ -60,7 +60,7 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:68:5 + --> $DIR/manual_find_fixable.rs:67:5 | LL | / for el in arr { LL | | if f(el) == 20 { @@ -71,7 +71,7 @@ LL | | None | |________^ help: replace with an iterator: `arr.into_iter().find(|&el| f(el) == 20)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:78:5 + --> $DIR/manual_find_fixable.rs:77:5 | LL | / for &el in arr.values() { LL | | if f(el) { @@ -82,7 +82,7 @@ LL | | None | |________^ help: replace with an iterator: `arr.values().find(|&&el| f(el)).copied()` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:87:5 + --> $DIR/manual_find_fixable.rs:86:5 | LL | / for el in arr { LL | | if el.is_true { @@ -95,7 +95,7 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:117:5 + --> $DIR/manual_find_fixable.rs:116:5 | LL | / for (_, &x) in v { LL | | if x > 10 { @@ -106,7 +106,7 @@ LL | | None | |________^ help: replace with an iterator: `v.into_iter().map(|(_, &x)| x).find(|&x| x > 10)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:126:5 + --> $DIR/manual_find_fixable.rs:125:5 | LL | / for &(_, &x) in v { LL | | if x > 10 { @@ -117,7 +117,7 @@ LL | | None | |________^ help: replace with an iterator: `v.iter().map(|&(_, &x)| x).find(|&x| x > 10)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:135:5 + --> $DIR/manual_find_fixable.rs:134:5 | LL | / for x in arr { LL | | if x >= 5 { @@ -128,7 +128,7 @@ LL | | return None; | |________________^ help: replace with an iterator: `arr.into_iter().find(|&x| x >= 5)` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:190:9 + --> $DIR/manual_find_fixable.rs:189:9 | LL | / for x in arr { LL | | if x < 1 { diff --git a/tests/ui/manual_find_map.fixed b/tests/ui/manual_find_map.fixed index 0c8eebf04b5c0..0e92d25e68f1c 100644 --- a/tests/ui/manual_find_map.fixed +++ b/tests/ui/manual_find_map.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::manual_find_map)] #![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure diff --git a/tests/ui/manual_find_map.rs b/tests/ui/manual_find_map.rs index b2feb48a839b7..b2568c823ebcf 100644 --- a/tests/ui/manual_find_map.rs +++ b/tests/ui/manual_find_map.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::manual_find_map)] #![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure diff --git a/tests/ui/manual_find_map.stderr b/tests/ui/manual_find_map.stderr index 4e52b5efacf15..67523711cc8e4 100644 --- a/tests/ui/manual_find_map.stderr +++ b/tests/ui/manual_find_map.stderr @@ -1,42 +1,42 @@ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:9:19 + --> $DIR/manual_find_map.rs:8:19 | LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_opt(a))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:9:28 + --> $DIR/manual_find_map.rs:8:28 | LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^ = note: `-D clippy::manual-find-map` implied by `-D warnings` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:12:19 + --> $DIR/manual_find_map.rs:11:19 | LL | let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_opt(a))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:12:29 + --> $DIR/manual_find_map.rs:11:29 | LL | let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi")); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:15:19 + --> $DIR/manual_find_map.rs:14:19 | LL | let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_res(a).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:15:29 + --> $DIR/manual_find_map.rs:14:29 | LL | let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1)); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:18:10 + --> $DIR/manual_find_map.rs:17:10 | LL | .find(|&x| to_ref(to_opt(x)).is_some()) | __________^ @@ -44,13 +44,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap()); | |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:18:20 + --> $DIR/manual_find_map.rs:17:20 | LL | .find(|&x| to_ref(to_opt(x)).is_some()) | ^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:21:10 + --> $DIR/manual_find_map.rs:20:10 | LL | .find(|x| to_ref(to_opt(*x)).is_some()) | __________^ @@ -58,13 +58,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap()); | |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:21:19 + --> $DIR/manual_find_map.rs:20:19 | LL | .find(|x| to_ref(to_opt(*x)).is_some()) | ^^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:25:10 + --> $DIR/manual_find_map.rs:24:10 | LL | .find(|&x| to_ref(to_res(x)).is_ok()) | __________^ @@ -72,13 +72,13 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap()); | |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:25:20 + --> $DIR/manual_find_map.rs:24:20 | LL | .find(|&x| to_ref(to_res(x)).is_ok()) | ^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:28:10 + --> $DIR/manual_find_map.rs:27:10 | LL | .find(|x| to_ref(to_res(*x)).is_ok()) | __________^ @@ -86,109 +86,109 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap()); | |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:28:19 + --> $DIR/manual_find_map.rs:27:19 | LL | .find(|x| to_ref(to_res(*x)).is_ok()) | ^^^^^^^^^^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:34:26 + --> $DIR/manual_find_map.rs:33:26 | LL | iter::>().find(|x| x.is_some()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x)` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:35:27 + --> $DIR/manual_find_map.rs:34:27 | LL | iter::<&Option>().find(|x| x.is_some()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| *x)` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:36:28 + --> $DIR/manual_find_map.rs:35:28 | LL | iter::<&&Option>().find(|x| x.is_some()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| **x)` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:37:27 + --> $DIR/manual_find_map.rs:36:27 | LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:38:28 + --> $DIR/manual_find_map.rs:37:28 | LL | iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:39:31 + --> $DIR/manual_find_map.rs:38:31 | LL | iter::<&Option>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:40:31 + --> $DIR/manual_find_map.rs:39:31 | LL | iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:40:41 + --> $DIR/manual_find_map.rs:39:41 | LL | iter::>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:42:30 + --> $DIR/manual_find_map.rs:41:30 | LL | iter::>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:43:31 + --> $DIR/manual_find_map.rs:42:31 | LL | iter::<&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:44:32 + --> $DIR/manual_find_map.rs:43:32 | LL | iter::<&&Result>().find(|x| x.is_ok()).map(|x| x.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:45:31 + --> $DIR/manual_find_map.rs:44:31 | LL | iter::>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:46:32 + --> $DIR/manual_find_map.rs:45:32 | LL | iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:47:35 + --> $DIR/manual_find_map.rs:46:35 | LL | iter::<&Result>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:48:35 + --> $DIR/manual_find_map.rs:47:35 | LL | iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned().ok())` | note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once - --> $DIR/manual_find_map.rs:48:45 + --> $DIR/manual_find_map.rs:47:45 | LL | iter::>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap()); | ^^^^^^^^^ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:96:10 + --> $DIR/manual_find_map.rs:95:10 | LL | .find(|f| f.option_field.is_some()) | __________^ @@ -196,7 +196,7 @@ LL | | .map(|f| f.option_field.clone().unwrap()); | |_________________________________________________^ help: try: `find_map(|f| f.option_field.clone())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:101:10 + --> $DIR/manual_find_map.rs:100:10 | LL | .find(|f| f.ref_field.is_some()) | __________^ @@ -204,7 +204,7 @@ LL | | .map(|f| f.ref_field.cloned().unwrap()); | |_______________________________________________^ help: try: `find_map(|f| f.ref_field.cloned())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:106:10 + --> $DIR/manual_find_map.rs:105:10 | LL | .find(|f| f.ref_field.is_some()) | __________^ @@ -212,7 +212,7 @@ LL | | .map(|f| f.ref_field.copied().unwrap()); | |_______________________________________________^ help: try: `find_map(|f| f.ref_field.copied())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:111:10 + --> $DIR/manual_find_map.rs:110:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -220,7 +220,7 @@ LL | | .map(|f| f.result_field.clone().unwrap()); | |_________________________________________________^ help: try: `find_map(|f| f.result_field.clone().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:116:10 + --> $DIR/manual_find_map.rs:115:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -228,7 +228,7 @@ LL | | .map(|f| f.result_field.as_ref().unwrap()); | |__________________________________________________^ help: try: `find_map(|f| f.result_field.as_ref().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:121:10 + --> $DIR/manual_find_map.rs:120:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -236,7 +236,7 @@ LL | | .map(|f| f.result_field.as_deref().unwrap()); | |____________________________________________________^ help: try: `find_map(|f| f.result_field.as_deref().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:126:10 + --> $DIR/manual_find_map.rs:125:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -244,7 +244,7 @@ LL | | .map(|f| f.result_field.as_mut().unwrap()); | |__________________________________________________^ help: try: `find_map(|f| f.result_field.as_mut().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:131:10 + --> $DIR/manual_find_map.rs:130:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -252,7 +252,7 @@ LL | | .map(|f| f.result_field.as_deref_mut().unwrap()); | |________________________________________________________^ help: try: `find_map(|f| f.result_field.as_deref_mut().ok())` error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:136:10 + --> $DIR/manual_find_map.rs:135:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ diff --git a/tests/ui/manual_flatten.rs b/tests/ui/manual_flatten.rs index 552213a7ff229..b7ea0644d29a9 100644 --- a/tests/ui/manual_flatten.rs +++ b/tests/ui/manual_flatten.rs @@ -1,6 +1,6 @@ #![warn(clippy::manual_flatten)] #![allow(clippy::useless_vec, clippy::uninlined_format_args)] - +//@no-rustfix fn main() { // Test for loop over implicitly adjusted `Iterator` with `if let` expression let x = vec![Some(1), Some(2), Some(3)]; diff --git a/tests/ui/manual_float_methods.rs b/tests/ui/manual_float_methods.rs index af9076cfb71fc..2a89a9e998239 100644 --- a/tests/ui/manual_float_methods.rs +++ b/tests/ui/manual_float_methods.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions //@aux-build:proc_macros.rs:proc-macro #![allow(clippy::needless_if, unused)] #![warn(clippy::manual_is_infinite, clippy::manual_is_finite)] diff --git a/tests/ui/manual_float_methods.stderr b/tests/ui/manual_float_methods.stderr index a56118b316ae3..35beb6fec7334 100644 --- a/tests/ui/manual_float_methods.stderr +++ b/tests/ui/manual_float_methods.stderr @@ -1,5 +1,5 @@ error: manually checking if a float is infinite - --> $DIR/manual_float_methods.rs:22:8 + --> $DIR/manual_float_methods.rs:23:8 | LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` @@ -7,7 +7,7 @@ LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} = note: `-D clippy::manual-is-infinite` implied by `-D warnings` error: manually checking if a float is finite - --> $DIR/manual_float_methods.rs:23:8 + --> $DIR/manual_float_methods.rs:24:8 | LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,13 +27,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> $DIR/manual_float_methods.rs:24:8 + --> $DIR/manual_float_methods.rs:25:8 | LL | if x == INFINITE || x == NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` error: manually checking if a float is finite - --> $DIR/manual_float_methods.rs:25:8 + --> $DIR/manual_float_methods.rs:26:8 | LL | if x != INFINITE && x != NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,13 +52,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> $DIR/manual_float_methods.rs:27:8 + --> $DIR/manual_float_methods.rs:28:8 | LL | if x == f64::INFINITY || x == f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` error: manually checking if a float is finite - --> $DIR/manual_float_methods.rs:28:8 + --> $DIR/manual_float_methods.rs:29:8 | LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_instant_elapsed.fixed b/tests/ui/manual_instant_elapsed.fixed index 55073c3b57cf9..1811337652dd5 100644 --- a/tests/ui/manual_instant_elapsed.fixed +++ b/tests/ui/manual_instant_elapsed.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_instant_elapsed)] #![allow(clippy::unnecessary_operation)] #![allow(clippy::unchecked_duration_subtraction)] diff --git a/tests/ui/manual_instant_elapsed.rs b/tests/ui/manual_instant_elapsed.rs index c9029a049408f..fedca38b158aa 100644 --- a/tests/ui/manual_instant_elapsed.rs +++ b/tests/ui/manual_instant_elapsed.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_instant_elapsed)] #![allow(clippy::unnecessary_operation)] #![allow(clippy::unchecked_duration_subtraction)] diff --git a/tests/ui/manual_instant_elapsed.stderr b/tests/ui/manual_instant_elapsed.stderr index 4ce1f689107e9..5537f5642a23c 100644 --- a/tests/ui/manual_instant_elapsed.stderr +++ b/tests/ui/manual_instant_elapsed.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Instant::elapsed` - --> $DIR/manual_instant_elapsed.rs:18:20 + --> $DIR/manual_instant_elapsed.rs:17:20 | LL | let duration = Instant::now() - prev_instant; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `prev_instant.elapsed()` @@ -7,7 +7,7 @@ LL | let duration = Instant::now() - prev_instant; = note: `-D clippy::manual-instant-elapsed` implied by `-D warnings` error: manual implementation of `Instant::elapsed` - --> $DIR/manual_instant_elapsed.rs:27:5 + --> $DIR/manual_instant_elapsed.rs:26:5 | LL | Instant::now() - *ref_to_instant; // to ensure parens are added correctly | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*ref_to_instant).elapsed()` diff --git a/tests/ui/manual_is_ascii_check.fixed b/tests/ui/manual_is_ascii_check.fixed index 87e866586683b..5be2dd280b821 100644 --- a/tests/ui/manual_is_ascii_check.fixed +++ b/tests/ui/manual_is_ascii_check.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, dead_code)] #![warn(clippy::manual_is_ascii_check)] diff --git a/tests/ui/manual_is_ascii_check.rs b/tests/ui/manual_is_ascii_check.rs index 931f0f20276bb..f9249e22a026d 100644 --- a/tests/ui/manual_is_ascii_check.rs +++ b/tests/ui/manual_is_ascii_check.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, dead_code)] #![warn(clippy::manual_is_ascii_check)] diff --git a/tests/ui/manual_is_ascii_check.stderr b/tests/ui/manual_is_ascii_check.stderr index ee60188506d6f..0497259b69b4d 100644 --- a/tests/ui/manual_is_ascii_check.stderr +++ b/tests/ui/manual_is_ascii_check.stderr @@ -1,5 +1,5 @@ error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:7:13 + --> $DIR/manual_is_ascii_check.rs:5:13 | LL | assert!(matches!('x', 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_lowercase()` @@ -7,115 +7,115 @@ LL | assert!(matches!('x', 'a'..='z')); = note: `-D clippy::manual-is-ascii-check` implied by `-D warnings` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:8:13 + --> $DIR/manual_is_ascii_check.rs:6:13 | LL | assert!(matches!('X', 'A'..='Z')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:9:13 + --> $DIR/manual_is_ascii_check.rs:7:13 | LL | assert!(matches!(b'x', b'a'..=b'z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'x'.is_ascii_lowercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:10:13 + --> $DIR/manual_is_ascii_check.rs:8:13 | LL | assert!(matches!(b'X', b'A'..=b'Z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'X'.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:13:13 + --> $DIR/manual_is_ascii_check.rs:11:13 | LL | assert!(matches!(num, '0'..='9')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:14:13 + --> $DIR/manual_is_ascii_check.rs:12:13 | LL | assert!(matches!(b'1', b'0'..=b'9')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:15:13 + --> $DIR/manual_is_ascii_check.rs:13:13 | LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:19:5 + --> $DIR/manual_is_ascii_check.rs:17:5 | LL | (b'0'..=b'9').contains(&b'0'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'0'.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:20:5 + --> $DIR/manual_is_ascii_check.rs:18:5 | LL | (b'a'..=b'z').contains(&b'a'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'a'.is_ascii_lowercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:21:5 + --> $DIR/manual_is_ascii_check.rs:19:5 | LL | (b'A'..=b'Z').contains(&b'A'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'A'.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:23:5 + --> $DIR/manual_is_ascii_check.rs:21:5 | LL | ('0'..='9').contains(&'0'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'0'.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:24:5 + --> $DIR/manual_is_ascii_check.rs:22:5 | LL | ('a'..='z').contains(&'a'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'a'.is_ascii_lowercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:25:5 + --> $DIR/manual_is_ascii_check.rs:23:5 | LL | ('A'..='Z').contains(&'A'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'A'.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:28:5 + --> $DIR/manual_is_ascii_check.rs:26:5 | LL | ('0'..='9').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:29:5 + --> $DIR/manual_is_ascii_check.rs:27:5 | LL | ('a'..='z').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_lowercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:30:5 + --> $DIR/manual_is_ascii_check.rs:28:5 | LL | ('A'..='Z').contains(cool_letter); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:42:13 + --> $DIR/manual_is_ascii_check.rs:40:13 | LL | assert!(matches!(b'1', b'0'..=b'9')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:43:13 + --> $DIR/manual_is_ascii_check.rs:41:13 | LL | assert!(matches!('X', 'A'..='Z')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:44:13 + --> $DIR/manual_is_ascii_check.rs:42:13 | LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:54:23 + --> $DIR/manual_is_ascii_check.rs:52:23 | LL | const FOO: bool = matches!('x', '0'..='9'); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()` diff --git a/tests/ui/manual_let_else.rs b/tests/ui/manual_let_else.rs index 381b83409e9d2..0cb525566809f 100644 --- a/tests/ui/manual_let_else.rs +++ b/tests/ui/manual_let_else.rs @@ -8,7 +8,7 @@ clippy::needless_if )] #![warn(clippy::manual_let_else)] - +//@no-rustfix enum Variant { A(usize, usize), B(usize), diff --git a/tests/ui/manual_let_else_match.fixed b/tests/ui/manual_let_else_match.fixed new file mode 100644 index 0000000000000..09b713f04101e --- /dev/null +++ b/tests/ui/manual_let_else_match.fixed @@ -0,0 +1,135 @@ +#![allow(unused_braces, unused_variables, dead_code)] +#![allow( + clippy::collapsible_else_if, + clippy::let_unit_value, + clippy::redundant_at_rest_pattern +)] +#![warn(clippy::manual_let_else)] +// Ensure that we don't conflict with match -> if let lints +#![warn(clippy::single_match_else, clippy::single_match)] + +fn f() -> Result { + Ok(0) +} + +fn g() -> Option<()> { + None +} + +fn h() -> (Option<()>, Option<()>) { + (None, None) +} + +enum Variant { + Foo, + Bar(u32), + Baz(u32), +} + +fn build_enum() -> Variant { + Variant::Foo +} + +fn main() {} + +fn fire() { + let Some(v) = g() else { return }; + + let Some(v) = g() else { return }; + + loop { + // More complex pattern for the identity arm and diverging arm + let ((Some(v), None) | (None, Some(v))) = h() else { continue }; + // Custom enums are supported as long as the "else" arm is a simple _ + let (Variant::Bar(v) | Variant::Baz(v)) = build_enum() else { continue }; + } + + // There is a _ in the diverging arm + // TODO also support unused bindings aka _v + let Ok(v) = f() else { return }; + + // Err(()) is an allowed pattern + let Ok(v) = f().map_err(|_| ()) else { return }; + + let f = Variant::Bar(1); + + let (Variant::Bar(_value) | Variant::Baz(_value)) = f else { return }; + + let Some(Variant::Bar(_value) | Variant::Baz(_value)) = Some(build_enum()) else { return }; + + let data = [1_u8, 2, 3, 4, 0, 0, 0, 0]; + let ([data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0]) = data.as_slice() else { return }; +} + +fn not_fire() { + // Multiple diverging arms + let v = match h() { + _ => panic!(), + (None, Some(_v)) => return, + (Some(v), None) => v, + }; + + // Multiple identity arms + let v = match h() { + _ => panic!(), + (None, Some(v)) => v, + (Some(v), None) => v, + }; + + // No diverging arm at all, only identity arms. + // This is no case for let else, but destructuring assignment. + let v = match f() { + Ok(v) => v, + Err(e) => e, + }; + + // The identity arm has a guard + let v = match g() { + Some(v) if g().is_none() => v, + _ => return, + }; + + // The diverging arm has a guard + let v = match f() { + Err(v) if v > 0 => panic!(), + Ok(v) | Err(v) => v, + }; + + // The diverging arm creates a binding + let v = match f() { + Ok(v) => v, + Err(e) => panic!("error: {e}"), + }; + + // Custom enum where the diverging arm + // explicitly mentions the variant + let v = match build_enum() { + Variant::Foo => return, + Variant::Bar(v) | Variant::Baz(v) => v, + }; + + // The custom enum is surrounded by an Err() + let v = match Err(build_enum()) { + Ok(v) | Err(Variant::Bar(v) | Variant::Baz(v)) => v, + Err(Variant::Foo) => return, + }; + + // Issue 10241 + // The non-divergent arm arrives in second position and + // may cover values already matched in the first arm. + let v = match h() { + (Some(_), Some(_)) | (None, None) => return, + (Some(v), _) | (None, Some(v)) => v, + }; + + let v = match build_enum() { + _ => return, + Variant::Bar(v) | Variant::Baz(v) => v, + }; + + let data = [1_u8, 2, 3, 4, 0, 0, 0, 0]; + let data = match data.as_slice() { + [] | [0, 0] => return, + [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ ..] => data, + }; +} diff --git a/tests/ui/manual_let_else_question_mark.fixed b/tests/ui/manual_let_else_question_mark.fixed index 02308bc7c4c13..b555186cc22a4 100644 --- a/tests/ui/manual_let_else_question_mark.fixed +++ b/tests/ui/manual_let_else_question_mark.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_braces, unused_variables, dead_code)] #![allow( clippy::collapsible_else_if, diff --git a/tests/ui/manual_let_else_question_mark.rs b/tests/ui/manual_let_else_question_mark.rs index 9c7ad386dc99f..5852c7094a4f4 100644 --- a/tests/ui/manual_let_else_question_mark.rs +++ b/tests/ui/manual_let_else_question_mark.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_braces, unused_variables, dead_code)] #![allow( clippy::collapsible_else_if, diff --git a/tests/ui/manual_let_else_question_mark.stderr b/tests/ui/manual_let_else_question_mark.stderr index d7d2e127ea3f3..ea35618e3c108 100644 --- a/tests/ui/manual_let_else_question_mark.stderr +++ b/tests/ui/manual_let_else_question_mark.stderr @@ -1,5 +1,5 @@ error: this `let...else` may be rewritten with the `?` operator - --> $DIR/manual_let_else_question_mark.rs:30:5 + --> $DIR/manual_let_else_question_mark.rs:29:5 | LL | let Some(v) = g() else { return None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `let v = g()?;` @@ -7,19 +7,19 @@ LL | let Some(v) = g() else { return None }; = note: `-D clippy::question-mark` implied by `-D warnings` error: this `let...else` may be rewritten with the `?` operator - --> $DIR/manual_let_else_question_mark.rs:36:5 + --> $DIR/manual_let_else_question_mark.rs:35:5 | LL | let Some((v, w)) = g() else { return None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `let (v, w) = g()?;` error: this block may be rewritten with the `?` operator - --> $DIR/manual_let_else_question_mark.rs:39:13 + --> $DIR/manual_let_else_question_mark.rs:38:13 | LL | let v = if let Some(v_some) = g() { v_some } else { return None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `g()?` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_question_mark.rs:43:5 + --> $DIR/manual_let_else_question_mark.rs:42:5 | LL | / let v = if let Some(v_some) = g() { LL | | v_some @@ -37,7 +37,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_question_mark.rs:54:9 + --> $DIR/manual_let_else_question_mark.rs:53:9 | LL | / let v = match g() { LL | | Some(v_some) => v_some, @@ -46,7 +46,7 @@ LL | | }; | |__________^ help: consider writing: `let Some(v) = g() else { return None };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_question_mark.rs:64:9 + --> $DIR/manual_let_else_question_mark.rs:63:9 | LL | let v = if let Some(v_some) = g() { v_some } else { return None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return None };` diff --git a/tests/ui/manual_main_separator_str.fixed b/tests/ui/manual_main_separator_str.fixed index 7e7da8f20bb3e..6441d6edef8cf 100644 --- a/tests/ui/manual_main_separator_str.fixed +++ b/tests/ui/manual_main_separator_str.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_main_separator_str)] diff --git a/tests/ui/manual_main_separator_str.rs b/tests/ui/manual_main_separator_str.rs index cf90e12efc33a..339dfd8bb473b 100644 --- a/tests/ui/manual_main_separator_str.rs +++ b/tests/ui/manual_main_separator_str.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_main_separator_str)] diff --git a/tests/ui/manual_main_separator_str.stderr b/tests/ui/manual_main_separator_str.stderr index e6cefde66a7d2..f7612efa5006e 100644 --- a/tests/ui/manual_main_separator_str.stderr +++ b/tests/ui/manual_main_separator_str.stderr @@ -1,5 +1,5 @@ error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` - --> $DIR/manual_main_separator_str.rs:23:19 + --> $DIR/manual_main_separator_str.rs:21:19 | LL | let _: &str = &MAIN_SEPARATOR.to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` @@ -7,19 +7,19 @@ LL | let _: &str = &MAIN_SEPARATOR.to_string(); = note: `-D clippy::manual-main-separator-str` implied by `-D warnings` error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` - --> $DIR/manual_main_separator_str.rs:24:17 + --> $DIR/manual_main_separator_str.rs:22:17 | LL | let _ = len(&MAIN_SEPARATOR.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` - --> $DIR/manual_main_separator_str.rs:25:23 + --> $DIR/manual_main_separator_str.rs:23:23 | LL | let _: Vec = MAIN_SEPARATOR.to_string().encode_utf16().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` - --> $DIR/manual_main_separator_str.rs:29:12 + --> $DIR/manual_main_separator_str.rs:27:12 | LL | f: &MAIN_SEPARATOR.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` diff --git a/tests/ui/manual_map_option.fixed b/tests/ui/manual_map_option.fixed index e8ff65cad6aa5..f6a964da418a2 100644 --- a/tests/ui/manual_map_option.fixed +++ b/tests/ui/manual_map_option.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_map)] #![allow( clippy::no_effect, diff --git a/tests/ui/manual_map_option.rs b/tests/ui/manual_map_option.rs index b06a96451ce75..df9dc256d3038 100644 --- a/tests/ui/manual_map_option.rs +++ b/tests/ui/manual_map_option.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_map)] #![allow( clippy::no_effect, diff --git a/tests/ui/manual_map_option.stderr b/tests/ui/manual_map_option.stderr index 3f9caad4e89ed..3e5fd923df826 100644 --- a/tests/ui/manual_map_option.stderr +++ b/tests/ui/manual_map_option.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:15:5 + --> $DIR/manual_map_option.rs:13:5 | LL | / match Some(0) { LL | | Some(_) => Some(2), @@ -10,7 +10,7 @@ LL | | }; = note: `-D clippy::manual-map` implied by `-D warnings` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:20:5 + --> $DIR/manual_map_option.rs:18:5 | LL | / match Some(0) { LL | | Some(x) => Some(x + 1), @@ -19,7 +19,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| x + 1)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:25:5 + --> $DIR/manual_map_option.rs:23:5 | LL | / match Some("") { LL | | Some(x) => Some(x.is_empty()), @@ -28,7 +28,7 @@ LL | | }; | |_____^ help: try: `Some("").map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:30:5 + --> $DIR/manual_map_option.rs:28:5 | LL | / if let Some(x) = Some(0) { LL | | Some(!x) @@ -38,7 +38,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| !x)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:37:5 + --> $DIR/manual_map_option.rs:35:5 | LL | / match Some(0) { LL | | Some(x) => { Some(std::convert::identity(x)) } @@ -47,7 +47,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(std::convert::identity)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:42:5 + --> $DIR/manual_map_option.rs:40:5 | LL | / match Some(&String::new()) { LL | | Some(x) => Some(str::len(x)), @@ -56,7 +56,7 @@ LL | | }; | |_____^ help: try: `Some(&String::new()).map(|x| str::len(x))` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:52:5 + --> $DIR/manual_map_option.rs:50:5 | LL | / match &Some([0, 1]) { LL | | Some(x) => Some(x[0]), @@ -65,7 +65,7 @@ LL | | }; | |_____^ help: try: `Some([0, 1]).as_ref().map(|x| x[0])` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:57:5 + --> $DIR/manual_map_option.rs:55:5 | LL | / match &Some(0) { LL | | &Some(x) => Some(x * 2), @@ -74,7 +74,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| x * 2)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:62:5 + --> $DIR/manual_map_option.rs:60:5 | LL | / match Some(String::new()) { LL | | Some(ref x) => Some(x.is_empty()), @@ -83,7 +83,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:67:5 + --> $DIR/manual_map_option.rs:65:5 | LL | / match &&Some(String::new()) { LL | | Some(x) => Some(x.len()), @@ -92,7 +92,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:72:5 + --> $DIR/manual_map_option.rs:70:5 | LL | / match &&Some(0) { LL | | &&Some(x) => Some(x + x), @@ -101,7 +101,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| x + x)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:85:9 + --> $DIR/manual_map_option.rs:83:9 | LL | / match &mut Some(String::new()) { LL | | Some(x) => Some(x.push_str("")), @@ -110,7 +110,7 @@ LL | | }; | |_________^ help: try: `Some(String::new()).as_mut().map(|x| x.push_str(""))` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:91:5 + --> $DIR/manual_map_option.rs:89:5 | LL | / match &mut Some(String::new()) { LL | | Some(ref x) => Some(x.len()), @@ -119,7 +119,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:96:5 + --> $DIR/manual_map_option.rs:94:5 | LL | / match &mut &Some(String::new()) { LL | | Some(x) => Some(x.is_empty()), @@ -128,7 +128,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:101:5 + --> $DIR/manual_map_option.rs:99:5 | LL | / match Some((0, 1, 2)) { LL | | Some((x, y, z)) => Some(x + y + z), @@ -137,7 +137,7 @@ LL | | }; | |_____^ help: try: `Some((0, 1, 2)).map(|(x, y, z)| x + y + z)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:106:5 + --> $DIR/manual_map_option.rs:104:5 | LL | / match Some([1, 2, 3]) { LL | | Some([first, ..]) => Some(first), @@ -146,7 +146,7 @@ LL | | }; | |_____^ help: try: `Some([1, 2, 3]).map(|[first, ..]| first)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:111:5 + --> $DIR/manual_map_option.rs:109:5 | LL | / match &Some((String::new(), "test")) { LL | | Some((x, y)) => Some((y, x)), @@ -155,7 +155,7 @@ LL | | }; | |_____^ help: try: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:169:5 + --> $DIR/manual_map_option.rs:167:5 | LL | / match Some(0) { LL | | Some(x) => Some(vec![x]), @@ -164,7 +164,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| vec![x])` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:174:5 + --> $DIR/manual_map_option.rs:172:5 | LL | / match option_env!("") { LL | | Some(x) => Some(String::from(x)), @@ -173,7 +173,7 @@ LL | | }; | |_____^ help: try: `option_env!("").map(String::from)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:194:12 + --> $DIR/manual_map_option.rs:192:12 | LL | } else if let Some(x) = Some(0) { | ____________^ @@ -184,7 +184,7 @@ LL | | }; | |_____^ help: try: `{ Some(0).map(|x| x + 1) }` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:202:12 + --> $DIR/manual_map_option.rs:200:12 | LL | } else if let Some(x) = Some(0) { | ____________^ diff --git a/tests/ui/manual_map_option_2.fixed b/tests/ui/manual_map_option_2.fixed index dc72287824874..513f6e32340a2 100644 --- a/tests/ui/manual_map_option_2.fixed +++ b/tests/ui/manual_map_option_2.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_map)] #![allow(clippy::toplevel_ref_arg)] diff --git a/tests/ui/manual_map_option_2.rs b/tests/ui/manual_map_option_2.rs index c495ab0fa6e0e..fd186743fe241 100644 --- a/tests/ui/manual_map_option_2.rs +++ b/tests/ui/manual_map_option_2.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_map)] #![allow(clippy::toplevel_ref_arg)] diff --git a/tests/ui/manual_map_option_2.stderr b/tests/ui/manual_map_option_2.stderr index 8c78fcffca8c5..e71000dd5d540 100644 --- a/tests/ui/manual_map_option_2.stderr +++ b/tests/ui/manual_map_option_2.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:8:13 + --> $DIR/manual_map_option_2.rs:6:13 | LL | let _ = match Some(0) { | _____________^ @@ -21,7 +21,7 @@ LL ~ }); | error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:50:13 + --> $DIR/manual_map_option_2.rs:48:13 | LL | let _ = match &s { | _____________^ @@ -40,7 +40,7 @@ LL ~ }); | error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:62:17 + --> $DIR/manual_map_option_2.rs:60:17 | LL | let _ = match Some(0) { | _________________^ @@ -50,7 +50,7 @@ LL | | }; | |_________^ help: try: `Some(0).map(|x| f(x))` error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:67:13 + --> $DIR/manual_map_option_2.rs:65:13 | LL | let _ = match Some(0) { | _____________^ @@ -60,7 +60,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| unsafe { f(x) })` error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:71:13 + --> $DIR/manual_map_option_2.rs:69:13 | LL | let _ = match Some(0) { | _____________^ diff --git a/tests/ui/manual_memcpy/with_loop_counters.rs b/tests/ui/manual_memcpy/with_loop_counters.rs index c826b082adff1..5f70221ec6eef 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.rs +++ b/tests/ui/manual_memcpy/with_loop_counters.rs @@ -1,5 +1,5 @@ #![warn(clippy::needless_range_loop, clippy::manual_memcpy)] - +//@no-rustfix pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let mut count = 0; for i in 3..src.len() { diff --git a/tests/ui/manual_memcpy/without_loop_counters.rs b/tests/ui/manual_memcpy/without_loop_counters.rs index 4d5c70f19a064..1a1db6a632998 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.rs +++ b/tests/ui/manual_memcpy/without_loop_counters.rs @@ -1,6 +1,6 @@ #![warn(clippy::needless_range_loop, clippy::manual_memcpy)] #![allow(clippy::useless_vec)] - +//@no-rustfix const LOOP_OFFSET: usize = 5000; pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { diff --git a/tests/ui/manual_next_back.fixed b/tests/ui/manual_next_back.fixed index e8a47063ad613..75828f355d900 100644 --- a/tests/ui/manual_next_back.fixed +++ b/tests/ui/manual_next_back.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_next_back)] diff --git a/tests/ui/manual_next_back.rs b/tests/ui/manual_next_back.rs index 9ec89242241c8..b980e90e11447 100644 --- a/tests/ui/manual_next_back.rs +++ b/tests/ui/manual_next_back.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_next_back)] diff --git a/tests/ui/manual_next_back.stderr b/tests/ui/manual_next_back.stderr index 94ccaa9e4cc3f..d2e52b40b4f4e 100644 --- a/tests/ui/manual_next_back.stderr +++ b/tests/ui/manual_next_back.stderr @@ -1,5 +1,5 @@ error: manual backwards iteration - --> $DIR/manual_next_back.rs:34:20 + --> $DIR/manual_next_back.rs:32:20 | LL | let _ = (0..10).rev().next().unwrap(); | ^^^^^^^^^^^^^ help: use: `.next_back()` @@ -7,7 +7,7 @@ LL | let _ = (0..10).rev().next().unwrap(); = note: `-D clippy::manual-next-back` implied by `-D warnings` error: manual backwards iteration - --> $DIR/manual_next_back.rs:35:32 + --> $DIR/manual_next_back.rs:33:32 | LL | let _ = "something".bytes().rev().next(); | ^^^^^^^^^^^^^ help: use: `.next_back()` diff --git a/tests/ui/manual_non_exhaustive_enum.rs b/tests/ui/manual_non_exhaustive_enum.rs index 03b2433f6666b..b5199065017a8 100644 --- a/tests/ui/manual_non_exhaustive_enum.rs +++ b/tests/ui/manual_non_exhaustive_enum.rs @@ -1,7 +1,7 @@ #![feature(lint_reasons)] #![warn(clippy::manual_non_exhaustive)] #![allow(unused)] - +//@no-rustfix enum E { A, B, diff --git a/tests/ui/manual_non_exhaustive_struct.rs b/tests/ui/manual_non_exhaustive_struct.rs index 498eee4447b88..9935427f50100 100644 --- a/tests/ui/manual_non_exhaustive_struct.rs +++ b/tests/ui/manual_non_exhaustive_struct.rs @@ -1,6 +1,6 @@ #![warn(clippy::manual_non_exhaustive)] #![allow(unused)] - +//@no-rustfix mod structs { struct S { pub a: i32, diff --git a/tests/ui/manual_ok_or.fixed b/tests/ui/manual_ok_or.fixed index d8901dc3b037a..cc53cb416a22f 100644 --- a/tests/ui/manual_ok_or.fixed +++ b/tests/ui/manual_ok_or.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_ok_or)] #![allow(clippy::or_fun_call)] #![allow(clippy::disallowed_names)] diff --git a/tests/ui/manual_ok_or.rs b/tests/ui/manual_ok_or.rs index 7188a521357ec..39c61a1e490f2 100644 --- a/tests/ui/manual_ok_or.rs +++ b/tests/ui/manual_ok_or.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_ok_or)] #![allow(clippy::or_fun_call)] #![allow(clippy::disallowed_names)] diff --git a/tests/ui/manual_ok_or.stderr b/tests/ui/manual_ok_or.stderr index b4a17f143e3fc..65459a097384b 100644 --- a/tests/ui/manual_ok_or.stderr +++ b/tests/ui/manual_ok_or.stderr @@ -1,5 +1,5 @@ error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:12:5 + --> $DIR/manual_ok_or.rs:11:5 | LL | foo.map_or(Err("error"), |v| Ok(v)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` @@ -7,19 +7,19 @@ LL | foo.map_or(Err("error"), |v| Ok(v)); = note: `-D clippy::manual-ok-or` implied by `-D warnings` error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:15:5 + --> $DIR/manual_ok_or.rs:14:5 | LL | foo.map_or(Err("error"), Ok); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:18:5 + --> $DIR/manual_ok_or.rs:17:5 | LL | None::.map_or(Err("error"), |v| Ok(v)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `None::.ok_or("error")` error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:22:5 + --> $DIR/manual_ok_or.rs:21:5 | LL | / foo.map_or(Err::( LL | | &format!( diff --git a/tests/ui/manual_range_patterns.fixed b/tests/ui/manual_range_patterns.fixed index 6bfcf263aa5e2..ea06e27d1534e 100644 --- a/tests/ui/manual_range_patterns.fixed +++ b/tests/ui/manual_range_patterns.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_range_patterns)] #![feature(exclusive_range_pattern)] diff --git a/tests/ui/manual_range_patterns.rs b/tests/ui/manual_range_patterns.rs index 4a429bb2aed32..eb29987b89fd1 100644 --- a/tests/ui/manual_range_patterns.rs +++ b/tests/ui/manual_range_patterns.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_range_patterns)] #![feature(exclusive_range_pattern)] diff --git a/tests/ui/manual_range_patterns.stderr b/tests/ui/manual_range_patterns.stderr index b1b55d483e723..1cf58d7df6a3f 100644 --- a/tests/ui/manual_range_patterns.stderr +++ b/tests/ui/manual_range_patterns.stderr @@ -1,5 +1,5 @@ error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:10:25 + --> $DIR/manual_range_patterns.rs:8:25 | LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` @@ -7,49 +7,49 @@ LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); = note: `-D clippy::manual-range-patterns` implied by `-D warnings` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:11:25 + --> $DIR/manual_range_patterns.rs:9:25 | LL | let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:20:25 + --> $DIR/manual_range_patterns.rs:18:25 | LL | let _ = matches!(f, (1..=10) | (2..=13) | (14..=48324728) | 48324729); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=48324729` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:21:25 + --> $DIR/manual_range_patterns.rs:19:25 | LL | let _ = matches!(f, 0 | (1..=10) | 48324730 | (2..=13) | (14..=48324728) | 48324729); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=48324730` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:22:25 + --> $DIR/manual_range_patterns.rs:20:25 | LL | let _ = matches!(f, 0..=1 | 0..=2 | 0..=3); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=3` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:25:9 + --> $DIR/manual_range_patterns.rs:23:9 | LL | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:28:25 + --> $DIR/manual_range_patterns.rs:26:25 | LL | let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-5..=3` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:30:25 + --> $DIR/manual_range_patterns.rs:28:25 | LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1000001..=1000001` error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:35:26 + --> $DIR/manual_range_patterns.rs:33:26 | LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` diff --git a/tests/ui/manual_rem_euclid.fixed b/tests/ui/manual_rem_euclid.fixed index 594a76897bbe2..f774f4cfcbd58 100644 --- a/tests/ui/manual_rem_euclid.fixed +++ b/tests/ui/manual_rem_euclid.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::manual_rem_euclid)] diff --git a/tests/ui/manual_rem_euclid.rs b/tests/ui/manual_rem_euclid.rs index d5f98e71517ee..9a64720698014 100644 --- a/tests/ui/manual_rem_euclid.rs +++ b/tests/ui/manual_rem_euclid.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::manual_rem_euclid)] diff --git a/tests/ui/manual_rem_euclid.stderr b/tests/ui/manual_rem_euclid.stderr index a43707f89c49e..c93d37a8bd4d7 100644 --- a/tests/ui/manual_rem_euclid.stderr +++ b/tests/ui/manual_rem_euclid.stderr @@ -1,5 +1,5 @@ error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:14:18 + --> $DIR/manual_rem_euclid.rs:13:18 | LL | let _: i32 = ((value % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` @@ -7,31 +7,31 @@ LL | let _: i32 = ((value % 4) + 4) % 4; = note: `-D clippy::manual-rem-euclid` implied by `-D warnings` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:15:18 + --> $DIR/manual_rem_euclid.rs:14:18 | LL | let _: i32 = (4 + (value % 4)) % 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:16:18 + --> $DIR/manual_rem_euclid.rs:15:18 | LL | let _: i32 = (value % 4 + 4) % 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:17:18 + --> $DIR/manual_rem_euclid.rs:16:18 | LL | let _: i32 = (4 + value % 4) % 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:18:22 + --> $DIR/manual_rem_euclid.rs:17:22 | LL | let _: i32 = 1 + (4 + value % 4) % 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:38:22 + --> $DIR/manual_rem_euclid.rs:37:22 | LL | let _: i32 = ((value % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` @@ -39,25 +39,25 @@ LL | let _: i32 = ((value % 4) + 4) % 4; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:50:5 + --> $DIR/manual_rem_euclid.rs:49:5 | LL | ((num % 4) + 4) % 4 | ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:55:5 + --> $DIR/manual_rem_euclid.rs:54:5 | LL | ((num % 4) + 4) % 4 | ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:67:18 + --> $DIR/manual_rem_euclid.rs:66:18 | LL | let _: i32 = ((x % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:80:18 + --> $DIR/manual_rem_euclid.rs:79:18 | LL | let _: i32 = ((x % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)` diff --git a/tests/ui/manual_retain.fixed b/tests/ui/manual_retain.fixed index c95d40fecba61..3afa2da6ab1db 100644 --- a/tests/ui/manual_retain.fixed +++ b/tests/ui/manual_retain.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_retain)] #![allow(unused, clippy::redundant_clone)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; diff --git a/tests/ui/manual_retain.rs b/tests/ui/manual_retain.rs index 9a3434f489def..43460da5eb0a8 100644 --- a/tests/ui/manual_retain.rs +++ b/tests/ui/manual_retain.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_retain)] #![allow(unused, clippy::redundant_clone)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; diff --git a/tests/ui/manual_retain.stderr b/tests/ui/manual_retain.stderr index 0936a23841ced..8b5f9f3a30ea5 100644 --- a/tests/ui/manual_retain.stderr +++ b/tests/ui/manual_retain.stderr @@ -1,5 +1,5 @@ error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:46:5 + --> $DIR/manual_retain.rs:45:5 | LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|k, _| k % 2 == 0)` @@ -7,13 +7,13 @@ LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect() = note: `-D clippy::manual-retain` implied by `-D warnings` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:47:5 + --> $DIR/manual_retain.rs:46:5 | LL | btree_map = btree_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|_, &mut v| v % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:48:5 + --> $DIR/manual_retain.rs:47:5 | LL | / btree_map = btree_map LL | | .into_iter() @@ -22,37 +22,37 @@ LL | | .collect(); | |__________________^ help: consider calling `.retain()` instead: `btree_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:70:5 + --> $DIR/manual_retain.rs:69:5 | LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:71:5 + --> $DIR/manual_retain.rs:70:5 | LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:72:5 + --> $DIR/manual_retain.rs:71:5 | LL | btree_set = btree_set.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:102:5 + --> $DIR/manual_retain.rs:101:5 | LL | hash_map = hash_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|k, _| k % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:103:5 + --> $DIR/manual_retain.rs:102:5 | LL | hash_map = hash_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|_, &mut v| v % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:104:5 + --> $DIR/manual_retain.rs:103:5 | LL | / hash_map = hash_map LL | | .into_iter() @@ -61,61 +61,61 @@ LL | | .collect(); | |__________________^ help: consider calling `.retain()` instead: `hash_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:125:5 + --> $DIR/manual_retain.rs:124:5 | LL | hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:126:5 + --> $DIR/manual_retain.rs:125:5 | LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:127:5 + --> $DIR/manual_retain.rs:126:5 | LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:156:5 + --> $DIR/manual_retain.rs:155:5 | LL | s = s.chars().filter(|&c| c != 'o').to_owned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `s.retain(|c| c != 'o')` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:168:5 + --> $DIR/manual_retain.rs:167:5 | LL | vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:169:5 + --> $DIR/manual_retain.rs:168:5 | LL | vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:170:5 + --> $DIR/manual_retain.rs:169:5 | LL | vec = vec.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:192:5 + --> $DIR/manual_retain.rs:191:5 | LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:193:5 + --> $DIR/manual_retain.rs:192:5 | LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:194:5 + --> $DIR/manual_retain.rs:193:5 | LL | vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` diff --git a/tests/ui/manual_saturating_arithmetic.fixed b/tests/ui/manual_saturating_arithmetic.fixed index 7dd4521fa78ef..8218f10881a75 100644 --- a/tests/ui/manual_saturating_arithmetic.fixed +++ b/tests/ui/manual_saturating_arithmetic.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports)] use std::{i128, i32, u128, u32}; diff --git a/tests/ui/manual_saturating_arithmetic.rs b/tests/ui/manual_saturating_arithmetic.rs index 463ee0692899b..60022b54b02d5 100644 --- a/tests/ui/manual_saturating_arithmetic.rs +++ b/tests/ui/manual_saturating_arithmetic.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports)] use std::{i128, i32, u128, u32}; diff --git a/tests/ui/manual_saturating_arithmetic.stderr b/tests/ui/manual_saturating_arithmetic.stderr index d985f2e754bc3..06f578b3c1d8c 100644 --- a/tests/ui/manual_saturating_arithmetic.stderr +++ b/tests/ui/manual_saturating_arithmetic.stderr @@ -1,5 +1,5 @@ error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:8:13 + --> $DIR/manual_saturating_arithmetic.rs:6:13 | LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)` @@ -7,19 +7,19 @@ LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); = note: `-D clippy::manual-saturating-arithmetic` implied by `-D warnings` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:9:13 + --> $DIR/manual_saturating_arithmetic.rs:7:13 | LL | let _ = 1u32.checked_add(1).unwrap_or(u32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:10:13 + --> $DIR/manual_saturating_arithmetic.rs:8:13 | LL | let _ = 1u8.checked_add(1).unwrap_or(255); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u8.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:11:13 + --> $DIR/manual_saturating_arithmetic.rs:9:13 | LL | let _ = 1u128 | _____________^ @@ -28,49 +28,49 @@ LL | | .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455); | |_______________________________________________________________________^ help: try using `saturating_add`: `1u128.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:16:13 + --> $DIR/manual_saturating_arithmetic.rs:14:13 | LL | let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_mul`: `1u32.saturating_mul(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:18:13 + --> $DIR/manual_saturating_arithmetic.rs:16:13 | LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:19:13 + --> $DIR/manual_saturating_arithmetic.rs:17:13 | LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:20:13 + --> $DIR/manual_saturating_arithmetic.rs:18:13 | LL | let _ = 1u8.checked_sub(1).unwrap_or(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u8.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:24:13 + --> $DIR/manual_saturating_arithmetic.rs:22:13 | LL | let _ = 1i32.checked_add(1).unwrap_or(i32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:25:13 + --> $DIR/manual_saturating_arithmetic.rs:23:13 | LL | let _ = 1i32.checked_add(1).unwrap_or(i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:26:13 + --> $DIR/manual_saturating_arithmetic.rs:24:13 | LL | let _ = 1i8.checked_add(1).unwrap_or(127); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:27:13 + --> $DIR/manual_saturating_arithmetic.rs:25:13 | LL | let _ = 1i128 | _____________^ @@ -79,25 +79,25 @@ LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); | |_______________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:30:13 + --> $DIR/manual_saturating_arithmetic.rs:28:13 | LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:31:13 + --> $DIR/manual_saturating_arithmetic.rs:29:13 | LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:32:13 + --> $DIR/manual_saturating_arithmetic.rs:30:13 | LL | let _ = 1i8.checked_add(-1).unwrap_or(-128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:33:13 + --> $DIR/manual_saturating_arithmetic.rs:31:13 | LL | let _ = 1i128 | _____________^ @@ -106,25 +106,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); | |________________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:40:13 + --> $DIR/manual_saturating_arithmetic.rs:38:13 | LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:41:13 + --> $DIR/manual_saturating_arithmetic.rs:39:13 | LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:42:13 + --> $DIR/manual_saturating_arithmetic.rs:40:13 | LL | let _ = 1i8.checked_sub(1).unwrap_or(-128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:43:13 + --> $DIR/manual_saturating_arithmetic.rs:41:13 | LL | let _ = 1i128 | _____________^ @@ -133,25 +133,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); | |________________________________________________________________________^ help: try using `saturating_sub`: `1i128.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:46:13 + --> $DIR/manual_saturating_arithmetic.rs:44:13 | LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:47:13 + --> $DIR/manual_saturating_arithmetic.rs:45:13 | LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:48:13 + --> $DIR/manual_saturating_arithmetic.rs:46:13 | LL | let _ = 1i8.checked_sub(-1).unwrap_or(127); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:49:13 + --> $DIR/manual_saturating_arithmetic.rs:47:13 | LL | let _ = 1i128 | _____________^ diff --git a/tests/ui/manual_slice_size_calculation.fixed b/tests/ui/manual_slice_size_calculation.fixed index 5b9629f4bc10f..ec1ee79251d84 100644 --- a/tests/ui/manual_slice_size_calculation.fixed +++ b/tests/ui/manual_slice_size_calculation.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(unused)] #![warn(clippy::manual_slice_size_calculation)] diff --git a/tests/ui/manual_slice_size_calculation.rs b/tests/ui/manual_slice_size_calculation.rs index 297887a9cfc82..404ba1268cc19 100644 --- a/tests/ui/manual_slice_size_calculation.rs +++ b/tests/ui/manual_slice_size_calculation.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(unused)] #![warn(clippy::manual_slice_size_calculation)] diff --git a/tests/ui/manual_slice_size_calculation.stderr b/tests/ui/manual_slice_size_calculation.stderr index e09d8057a3b98..812d02c96fcec 100644 --- a/tests/ui/manual_slice_size_calculation.stderr +++ b/tests/ui/manual_slice_size_calculation.stderr @@ -1,5 +1,5 @@ error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:16:13 + --> $DIR/manual_slice_size_calculation.rs:15:13 | LL | let _ = s_i32.len() * size_of::(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` @@ -7,37 +7,37 @@ LL | let _ = s_i32.len() * size_of::(); // WARNING = note: `-D clippy::manual-slice-size-calculation` implied by `-D warnings` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:17:13 + --> $DIR/manual_slice_size_calculation.rs:16:13 | LL | let _ = size_of::() * s_i32.len(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:18:13 + --> $DIR/manual_slice_size_calculation.rs:17:13 | LL | let _ = size_of::() * s_i32.len() * 5; // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:22:13 + --> $DIR/manual_slice_size_calculation.rs:21:13 | LL | let _ = len * size_of::(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:23:13 + --> $DIR/manual_slice_size_calculation.rs:22:13 | LL | let _ = s_i32.len() * size; // WARNING | ^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:24:13 + --> $DIR/manual_slice_size_calculation.rs:23:13 | LL | let _ = len * size; // WARNING | ^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:26:13 + --> $DIR/manual_slice_size_calculation.rs:25:13 | LL | let _ = external!(&[1u64][..]).len() * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(external!(&[1u64][..]))` diff --git a/tests/ui/manual_split_once.fixed b/tests/ui/manual_split_once.fixed index e317c597109b0..aaac6a048e1d0 100644 --- a/tests/ui/manual_split_once.fixed +++ b/tests/ui/manual_split_once.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_split_once)] #![allow(unused, clippy::iter_skip_next, clippy::iter_nth_zero)] diff --git a/tests/ui/manual_split_once.rs b/tests/ui/manual_split_once.rs index 7e2dc22bc4669..113e1737c97da 100644 --- a/tests/ui/manual_split_once.rs +++ b/tests/ui/manual_split_once.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_split_once)] #![allow(unused, clippy::iter_skip_next, clippy::iter_nth_zero)] diff --git a/tests/ui/manual_split_once.stderr b/tests/ui/manual_split_once.stderr index f454f95b41dce..d425f0881c0b6 100644 --- a/tests/ui/manual_split_once.stderr +++ b/tests/ui/manual_split_once.stderr @@ -1,5 +1,5 @@ error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:13:13 + --> $DIR/manual_split_once.rs:11:13 | LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1` @@ -7,79 +7,79 @@ LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap(); = note: `-D clippy::manual-split-once` implied by `-D warnings` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:14:13 + --> $DIR/manual_split_once.rs:12:13 | LL | let _ = "key=value".splitn(2, '=').skip(1).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:15:18 + --> $DIR/manual_split_once.rs:13:18 | LL | let (_, _) = "key=value".splitn(2, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=')` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:18:13 + --> $DIR/manual_split_once.rs:16:13 | LL | let _ = s.splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:21:13 + --> $DIR/manual_split_once.rs:19:13 | LL | let _ = s.splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:24:13 + --> $DIR/manual_split_once.rs:22:13 | LL | let _ = s.splitn(2, '=').skip(1).next().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:27:17 + --> $DIR/manual_split_once.rs:25:17 | LL | let _ = s.splitn(2, '=').nth(1)?; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=')?.1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:28:17 + --> $DIR/manual_split_once.rs:26:17 | LL | let _ = s.splitn(2, '=').skip(1).next()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=')?.1` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:29:17 + --> $DIR/manual_split_once.rs:27:17 | LL | let _ = s.rsplitn(2, '=').nth(1)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=')?.0` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:30:17 + --> $DIR/manual_split_once.rs:28:17 | LL | let _ = s.rsplitn(2, '=').skip(1).next()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=')?.0` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:38:13 + --> $DIR/manual_split_once.rs:36:13 | LL | let _ = "key=value".rsplitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".rsplit_once('=').unwrap().0` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:39:18 + --> $DIR/manual_split_once.rs:37:18 | LL | let (_, _) = "key=value".rsplitn(2, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".rsplit_once('=').map(|(x, y)| (y, x))` error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:40:13 + --> $DIR/manual_split_once.rs:38:13 | LL | let _ = s.rsplitn(2, '=').nth(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=').map(|x| x.0)` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:44:5 + --> $DIR/manual_split_once.rs:42:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL + | error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:48:5 + --> $DIR/manual_split_once.rs:46:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -129,7 +129,7 @@ LL + | error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:52:5 + --> $DIR/manual_split_once.rs:50:5 | LL | let mut iter = "a.b.c".rsplitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL + | error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:56:5 + --> $DIR/manual_split_once.rs:54:5 | LL | let mut iter = "a.b.c".rsplitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -179,13 +179,13 @@ LL + | error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:141:13 + --> $DIR/manual_split_once.rs:139:13 | LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:143:5 + --> $DIR/manual_split_once.rs:141:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/manual_str_repeat.fixed b/tests/ui/manual_str_repeat.fixed index 9468c3df9047a..888a466278ccc 100644 --- a/tests/ui/manual_str_repeat.fixed +++ b/tests/ui/manual_str_repeat.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_str_repeat)] use std::borrow::Cow; diff --git a/tests/ui/manual_str_repeat.rs b/tests/ui/manual_str_repeat.rs index baa0a10260d40..a366351ffa45a 100644 --- a/tests/ui/manual_str_repeat.rs +++ b/tests/ui/manual_str_repeat.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_str_repeat)] use std::borrow::Cow; diff --git a/tests/ui/manual_str_repeat.stderr b/tests/ui/manual_str_repeat.stderr index 331bb6ea575b3..e9067719cc666 100644 --- a/tests/ui/manual_str_repeat.stderr +++ b/tests/ui/manual_str_repeat.stderr @@ -1,5 +1,5 @@ error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:9:21 + --> $DIR/manual_str_repeat.rs:7:21 | LL | let _: String = std::iter::repeat("test").take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)` @@ -7,55 +7,55 @@ LL | let _: String = std::iter::repeat("test").take(10).collect(); = note: `-D clippy::manual-str-repeat` implied by `-D warnings` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:10:21 + --> $DIR/manual_str_repeat.rs:8:21 | LL | let _: String = std::iter::repeat('x').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"x".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:11:21 + --> $DIR/manual_str_repeat.rs:9:21 | LL | let _: String = std::iter::repeat('/'').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"'".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:12:21 + --> $DIR/manual_str_repeat.rs:10:21 | LL | let _: String = std::iter::repeat('"').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"/"".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:16:13 + --> $DIR/manual_str_repeat.rs:14:13 | LL | let _ = repeat(x).take(count + 2).collect::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count + 2)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:25:21 + --> $DIR/manual_str_repeat.rs:23:21 | LL | let _: String = repeat(*x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*x).repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:34:21 + --> $DIR/manual_str_repeat.rs:32:21 | LL | let _: String = repeat(x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:46:21 + --> $DIR/manual_str_repeat.rs:44:21 | LL | let _: String = repeat(Cow::Borrowed("test")).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Cow::Borrowed("test").repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:49:21 + --> $DIR/manual_str_repeat.rs:47:21 | LL | let _: String = repeat(x).take(count).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:64:21 + --> $DIR/manual_str_repeat.rs:62:21 | LL | let _: String = std::iter::repeat("test").take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)` diff --git a/tests/ui/manual_string_new.fixed b/tests/ui/manual_string_new.fixed index 0d1bab2330464..273be4e0fd2b3 100644 --- a/tests/ui/manual_string_new.fixed +++ b/tests/ui/manual_string_new.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_string_new)] macro_rules! create_strings_from_macro { diff --git a/tests/ui/manual_string_new.rs b/tests/ui/manual_string_new.rs index 2392ebfc32292..0d5514fc893e4 100644 --- a/tests/ui/manual_string_new.rs +++ b/tests/ui/manual_string_new.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_string_new)] macro_rules! create_strings_from_macro { diff --git a/tests/ui/manual_string_new.stderr b/tests/ui/manual_string_new.stderr index e5ecfc61947a3..02aac6fdfeb04 100644 --- a/tests/ui/manual_string_new.stderr +++ b/tests/ui/manual_string_new.stderr @@ -1,5 +1,5 @@ error: empty String is being created manually - --> $DIR/manual_string_new.rs:15:13 + --> $DIR/manual_string_new.rs:13:13 | LL | let _ = "".to_string(); | ^^^^^^^^^^^^^^ help: consider using: `String::new()` @@ -7,49 +7,49 @@ LL | let _ = "".to_string(); = note: `-D clippy::manual-string-new` implied by `-D warnings` error: empty String is being created manually - --> $DIR/manual_string_new.rs:18:13 + --> $DIR/manual_string_new.rs:16:13 | LL | let _ = "".to_owned(); | ^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:21:21 + --> $DIR/manual_string_new.rs:19:21 | LL | let _: String = "".into(); | ^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:28:13 + --> $DIR/manual_string_new.rs:26:13 | LL | let _ = String::from(""); | ^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:29:13 + --> $DIR/manual_string_new.rs:27:13 | LL | let _ = ::from(""); | ^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:34:13 + --> $DIR/manual_string_new.rs:32:13 | LL | let _ = String::try_from("").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:40:21 + --> $DIR/manual_string_new.rs:38:21 | LL | let _: String = From::from(""); | ^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:45:21 + --> $DIR/manual_string_new.rs:43:21 | LL | let _: String = TryFrom::try_from("").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:48:21 + --> $DIR/manual_string_new.rs:46:21 | LL | let _: String = TryFrom::try_from("").expect("this should warn"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` diff --git a/tests/ui/manual_strip.rs b/tests/ui/manual_strip.rs index b0b1c262aeed8..99c83354419d7 100644 --- a/tests/ui/manual_strip.rs +++ b/tests/ui/manual_strip.rs @@ -1,5 +1,5 @@ #![warn(clippy::manual_strip)] - +//@no-rustfix fn main() { let s = "abc"; diff --git a/tests/ui/manual_try_fold.rs b/tests/ui/manual_try_fold.rs index 05c658579a5f8..79d8a35e2b376 100644 --- a/tests/ui/manual_try_fold.rs +++ b/tests/ui/manual_try_fold.rs @@ -2,7 +2,7 @@ #![allow(clippy::unnecessary_fold, unused)] #![warn(clippy::manual_try_fold)] #![feature(try_trait_v2)] - +//@no-rustfix use std::ops::{ControlFlow, FromResidual, Try}; #[macro_use] diff --git a/tests/ui/manual_unwrap_or.fixed b/tests/ui/manual_unwrap_or.fixed index 20560b87c1a59..737d4c90dca45 100644 --- a/tests/ui/manual_unwrap_or.fixed +++ b/tests/ui/manual_unwrap_or.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs index 5dbc57565bff3..f59fb87529f81 100644 --- a/tests/ui/manual_unwrap_or.rs +++ b/tests/ui/manual_unwrap_or.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui/manual_unwrap_or.stderr b/tests/ui/manual_unwrap_or.stderr index 0e4cb798d455e..8b6de5d18bf82 100644 --- a/tests/ui/manual_unwrap_or.stderr +++ b/tests/ui/manual_unwrap_or.stderr @@ -1,5 +1,5 @@ error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:7:5 + --> $DIR/manual_unwrap_or.rs:6:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -10,7 +10,7 @@ LL | | }; = note: `-D clippy::manual-unwrap-or` implied by `-D warnings` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:13:5 + --> $DIR/manual_unwrap_or.rs:12:5 | LL | / match Some(1) { LL | | None => 42, @@ -19,7 +19,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:19:5 + --> $DIR/manual_unwrap_or.rs:18:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -28,7 +28,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(1 + 42)` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:26:5 + --> $DIR/manual_unwrap_or.rs:25:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -49,7 +49,7 @@ LL ~ }); | error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:36:5 + --> $DIR/manual_unwrap_or.rs:35:5 | LL | / match Some("Bob") { LL | | Some(i) => i, @@ -58,7 +58,7 @@ LL | | }; | |_____^ help: replace with: `Some("Bob").unwrap_or("Alice")` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:86:5 + --> $DIR/manual_unwrap_or.rs:85:5 | LL | / match Ok::(1) { LL | | Ok(i) => i, @@ -67,7 +67,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:93:5 + --> $DIR/manual_unwrap_or.rs:92:5 | LL | / match a { LL | | Ok(i) => i, @@ -76,7 +76,7 @@ LL | | }; | |_____^ help: replace with: `a.unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:99:5 + --> $DIR/manual_unwrap_or.rs:98:5 | LL | / match Ok(1) as Result { LL | | Ok(i) => i, @@ -85,7 +85,7 @@ LL | | }; | |_____^ help: replace with: `(Ok(1) as Result).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:112:5 + --> $DIR/manual_unwrap_or.rs:111:5 | LL | / match s.method() { LL | | Some(i) => i, @@ -94,7 +94,7 @@ LL | | }; | |_____^ help: replace with: `s.method().unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:118:5 + --> $DIR/manual_unwrap_or.rs:117:5 | LL | / match Ok::(1) { LL | | Err(_) => 42, @@ -103,7 +103,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:124:5 + --> $DIR/manual_unwrap_or.rs:123:5 | LL | / match Ok::(1) { LL | | Ok(i) => i, @@ -112,7 +112,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(1 + 42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:131:5 + --> $DIR/manual_unwrap_or.rs:130:5 | LL | / match Ok::(1) { LL | | Ok(i) => i, @@ -133,7 +133,7 @@ LL ~ }); | error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:141:5 + --> $DIR/manual_unwrap_or.rs:140:5 | LL | / match Ok::<&str, &str>("Bob") { LL | | Ok(i) => i, @@ -142,7 +142,7 @@ LL | | }; | |_____^ help: replace with: `Ok::<&str, &str>("Bob").unwrap_or("Alice")` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:201:17 + --> $DIR/manual_unwrap_or.rs:200:17 | LL | let _ = match some_macro!() { | _________________^ diff --git a/tests/ui/manual_while_let_some.fixed b/tests/ui/manual_while_let_some.fixed index 8b610919536c0..c70d258dfe6e1 100644 --- a/tests/ui/manual_while_let_some.fixed +++ b/tests/ui/manual_while_let_some.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_while_let_some)] diff --git a/tests/ui/manual_while_let_some.rs b/tests/ui/manual_while_let_some.rs index 85a0a084a424f..415bb57986673 100644 --- a/tests/ui/manual_while_let_some.rs +++ b/tests/ui/manual_while_let_some.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_while_let_some)] diff --git a/tests/ui/manual_while_let_some.stderr b/tests/ui/manual_while_let_some.stderr index 633fe05c49b84..33dd313b21a51 100644 --- a/tests/ui/manual_while_let_some.stderr +++ b/tests/ui/manual_while_let_some.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:23:9 + --> $DIR/manual_while_let_some.rs:21:9 | LL | let number = numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL ~ | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:31:9 + --> $DIR/manual_while_let_some.rs:29:9 | LL | let number = val.numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL ~ | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:35:20 + --> $DIR/manual_while_let_some.rs:33:20 | LL | accept_i32(numbers.pop().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL ~ accept_i32(element); | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:39:20 + --> $DIR/manual_while_let_some.rs:37:20 | LL | accept_i32(numbers.pop().expect("")); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL ~ accept_i32(element); | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:82:9 + --> $DIR/manual_while_let_some.rs:80:9 | LL | let (a, b) = numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL ~ | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:86:26 + --> $DIR/manual_while_let_some.rs:84:26 | LL | accept_i32_tuple(numbers.pop().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL ~ accept_i32_tuple(element); | error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:91:9 + --> $DIR/manual_while_let_some.rs:89:9 | LL | let Foo { a, b } = results.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/map_clone.fixed b/tests/ui/map_clone.fixed index 50c0eb1a81081..dd979013d3c1f 100644 --- a/tests/ui/map_clone.fixed +++ b/tests/ui/map_clone.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_clone)] #![allow( clippy::clone_on_copy, diff --git a/tests/ui/map_clone.rs b/tests/ui/map_clone.rs index 91a084f2844dd..96cba71965f0f 100644 --- a/tests/ui/map_clone.rs +++ b/tests/ui/map_clone.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_clone)] #![allow( clippy::clone_on_copy, diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr index d768af1f48c97..d84a5bf8d4de6 100644 --- a/tests/ui/map_clone.stderr +++ b/tests/ui/map_clone.stderr @@ -1,5 +1,5 @@ error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:12:22 + --> $DIR/map_clone.rs:11:22 | LL | let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()` @@ -7,31 +7,31 @@ LL | let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); = note: `-D clippy::map-clone` implied by `-D warnings` error: you are using an explicit closure for cloning elements - --> $DIR/map_clone.rs:13:26 + --> $DIR/map_clone.rs:12:26 | LL | let _: Vec = vec![String::new()].iter().map(|x| x.clone()).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()` error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:14:23 + --> $DIR/map_clone.rs:13:23 | LL | let _: Vec = vec![42, 43].iter().map(|&x| x).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![42, 43].iter().copied()` error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:16:26 + --> $DIR/map_clone.rs:15:26 | LL | let _: Option = Some(&16).map(|b| *b); | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&16).copied()` error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:17:25 + --> $DIR/map_clone.rs:16:25 | LL | let _: Option = Some(&1).map(|x| x.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&1).copied()` error: you are needlessly cloning iterator elements - --> $DIR/map_clone.rs:28:29 + --> $DIR/map_clone.rs:27:29 | LL | let _ = std::env::args().map(|v| v.clone()); | ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call diff --git a/tests/ui/map_collect_result_unit.fixed b/tests/ui/map_collect_result_unit.fixed index b00c2cf284ec9..374af105f889d 100644 --- a/tests/ui/map_collect_result_unit.fixed +++ b/tests/ui/map_collect_result_unit.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_collect_result_unit)] fn main() { diff --git a/tests/ui/map_collect_result_unit.rs b/tests/ui/map_collect_result_unit.rs index ad2198ec1fe75..5c6fb23e2372b 100644 --- a/tests/ui/map_collect_result_unit.rs +++ b/tests/ui/map_collect_result_unit.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_collect_result_unit)] fn main() { diff --git a/tests/ui/map_collect_result_unit.stderr b/tests/ui/map_collect_result_unit.stderr index 596e51e5741ee..3108582aa43be 100644 --- a/tests/ui/map_collect_result_unit.stderr +++ b/tests/ui/map_collect_result_unit.stderr @@ -1,5 +1,5 @@ error: `.map().collect()` can be replaced with `.try_for_each()` - --> $DIR/map_collect_result_unit.rs:6:17 + --> $DIR/map_collect_result_unit.rs:5:17 | LL | let _ = (0..3).map(|t| Err(t + 1)).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(0..3).try_for_each(|t| Err(t + 1))` @@ -7,7 +7,7 @@ LL | let _ = (0..3).map(|t| Err(t + 1)).collect::>(); = note: `-D clippy::map-collect-result-unit` implied by `-D warnings` error: `.map().collect()` can be replaced with `.try_for_each()` - --> $DIR/map_collect_result_unit.rs:7:32 + --> $DIR/map_collect_result_unit.rs:6:32 | LL | let _: Result<(), _> = (0..3).map(|t| Err(t + 1)).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(0..3).try_for_each(|t| Err(t + 1))` diff --git a/tests/ui/map_flatten.rs b/tests/ui/map_flatten.rs index 7d47ee09dc1ac..fca4fe0bcb780 100644 --- a/tests/ui/map_flatten.rs +++ b/tests/ui/map_flatten.rs @@ -1,6 +1,6 @@ #![warn(clippy::map_flatten)] #![feature(result_flattening)] - +//@no-rustfix // issue #8506, multi-line #[rustfmt::skip] fn long_span() { diff --git a/tests/ui/map_flatten_fixable.fixed b/tests/ui/map_flatten_fixable.fixed index 14816de1a636b..1932f412d2ca0 100644 --- a/tests/ui/map_flatten_fixable.fixed +++ b/tests/ui/map_flatten_fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::let_underscore_untyped)] #![allow(clippy::missing_docs_in_private_items)] diff --git a/tests/ui/map_flatten_fixable.rs b/tests/ui/map_flatten_fixable.rs index f38a00a59facf..093fd9b6cae29 100644 --- a/tests/ui/map_flatten_fixable.rs +++ b/tests/ui/map_flatten_fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::let_underscore_untyped)] #![allow(clippy::missing_docs_in_private_items)] diff --git a/tests/ui/map_flatten_fixable.stderr b/tests/ui/map_flatten_fixable.stderr index c91f0b9ae94fe..865929421532c 100644 --- a/tests/ui/map_flatten_fixable.stderr +++ b/tests/ui/map_flatten_fixable.stderr @@ -1,5 +1,5 @@ error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:18:47 + --> $DIR/map_flatten_fixable.rs:16:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id)` @@ -7,43 +7,43 @@ LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().coll = note: `-D clippy::map-flatten` implied by `-D warnings` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:19:47 + --> $DIR/map_flatten_fixable.rs:17:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_ref)` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:20:47 + --> $DIR/map_flatten_fixable.rs:18:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_closure)` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:21:47 + --> $DIR/map_flatten_fixable.rs:19:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(|x| x.checked_add(1))` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:24:47 + --> $DIR/map_flatten_fixable.rs:22:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `flat_map` and remove the `.flatten()`: `flat_map(|x| 0..x)` error: called `map(..).flatten()` on `Option` - --> $DIR/map_flatten_fixable.rs:27:40 + --> $DIR/map_flatten_fixable.rs:25:40 | LL | let _: Option<_> = (Some(Some(1))).map(|x| x).flatten(); | ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)` error: called `map(..).flatten()` on `Result` - --> $DIR/map_flatten_fixable.rs:30:42 + --> $DIR/map_flatten_fixable.rs:28:42 | LL | let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten(); | ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:39:10 + --> $DIR/map_flatten_fixable.rs:37:10 | LL | .map(|n| match n { | __________^ @@ -72,7 +72,7 @@ LL ~ }); | error: called `map(..).flatten()` on `Option` - --> $DIR/map_flatten_fixable.rs:59:10 + --> $DIR/map_flatten_fixable.rs:57:10 | LL | .map(|_| { | __________^ diff --git a/tests/ui/map_identity.fixed b/tests/ui/map_identity.fixed index 7fb7d8c121885..cc40b1620587c 100644 --- a/tests/ui/map_identity.fixed +++ b/tests/ui/map_identity.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_identity)] #![allow(clippy::needless_return)] diff --git a/tests/ui/map_identity.rs b/tests/ui/map_identity.rs index 7891c24262838..97a91aea6dc4e 100644 --- a/tests/ui/map_identity.rs +++ b/tests/ui/map_identity.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_identity)] #![allow(clippy::needless_return)] diff --git a/tests/ui/map_identity.stderr b/tests/ui/map_identity.stderr index b6a77281f6de2..97ff7ea70d78b 100644 --- a/tests/ui/map_identity.stderr +++ b/tests/ui/map_identity.stderr @@ -1,5 +1,5 @@ error: unnecessary map of the identity function - --> $DIR/map_identity.rs:8:47 + --> $DIR/map_identity.rs:7:47 | LL | let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); | ^^^^^^^^^^^^^^^^^^ help: remove the call to `map` @@ -7,25 +7,25 @@ LL | let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); = note: `-D clippy::map-identity` implied by `-D warnings` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:9:57 + --> $DIR/map_identity.rs:8:57 | LL | let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect(); | ^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:9:29 + --> $DIR/map_identity.rs:8:29 | LL | let _: Vec<_> = x.iter().map(std::convert::identity).map(|y| y).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:10:32 + --> $DIR/map_identity.rs:9:32 | LL | let _: Option = Some(3).map(|x| x); | ^^^^^^^^^^^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:11:36 + --> $DIR/map_identity.rs:10:36 | LL | let _: Result = Ok(-3).map(|x| { | ____________________________________^ @@ -34,7 +34,7 @@ LL | | }); | |______^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:21:36 + --> $DIR/map_identity.rs:20:36 | LL | let _: Result = Ok(1).map_err(|a| a); | ^^^^^^^^^^^^^^^ help: remove the call to `map_err` diff --git a/tests/ui/map_unwrap_or.rs b/tests/ui/map_unwrap_or.rs index bb36cb2c598b7..dfaa8f24f987f 100644 --- a/tests/ui/map_unwrap_or.rs +++ b/tests/ui/map_unwrap_or.rs @@ -1,5 +1,5 @@ //@aux-build:option_helpers.rs - +//@no-rustfix #![warn(clippy::map_unwrap_or)] #![allow(clippy::uninlined_format_args, clippy::unnecessary_lazy_evaluations)] diff --git a/tests/ui/map_unwrap_or_fixable.fixed b/tests/ui/map_unwrap_or_fixable.fixed index ea5b6a6691e58..90f3cf8bab047 100644 --- a/tests/ui/map_unwrap_or_fixable.fixed +++ b/tests/ui/map_unwrap_or_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::map_unwrap_or)] diff --git a/tests/ui/map_unwrap_or_fixable.rs b/tests/ui/map_unwrap_or_fixable.rs index f8bb9d8ca6a35..d3d0ae0154c15 100644 --- a/tests/ui/map_unwrap_or_fixable.rs +++ b/tests/ui/map_unwrap_or_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::map_unwrap_or)] diff --git a/tests/ui/map_unwrap_or_fixable.stderr b/tests/ui/map_unwrap_or_fixable.stderr index 71dc009f2ce61..0635a8c79bdc1 100644 --- a/tests/ui/map_unwrap_or_fixable.stderr +++ b/tests/ui/map_unwrap_or_fixable.stderr @@ -1,5 +1,5 @@ error: called `map().unwrap_or_else()` on an `Option` value. This can be done more directly by calling `map_or_else(, )` instead - --> $DIR/map_unwrap_or_fixable.rs:17:13 + --> $DIR/map_unwrap_or_fixable.rs:16:13 | LL | let _ = opt.map(|x| x + 1) | _____________^ @@ -10,7 +10,7 @@ LL | | .unwrap_or_else(|| 0); = note: `-D clippy::map-unwrap-or` implied by `-D warnings` error: called `map().unwrap_or_else()` on a `Result` value. This can be done more directly by calling `.map_or_else(, )` instead - --> $DIR/map_unwrap_or_fixable.rs:47:13 + --> $DIR/map_unwrap_or_fixable.rs:46:13 | LL | let _ = res.map(|x| x + 1) | _____________^ diff --git a/tests/ui/match_as_ref.fixed b/tests/ui/match_as_ref.fixed index 61d414bdf4be5..8c07076af4a49 100644 --- a/tests/ui/match_as_ref.fixed +++ b/tests/ui/match_as_ref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::match_as_ref)] diff --git a/tests/ui/match_as_ref.rs b/tests/ui/match_as_ref.rs index cd39514c59ac6..655e166236975 100644 --- a/tests/ui/match_as_ref.rs +++ b/tests/ui/match_as_ref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::match_as_ref)] diff --git a/tests/ui/match_as_ref.stderr b/tests/ui/match_as_ref.stderr index 2e6955eb8056e..79ca203ee13a6 100644 --- a/tests/ui/match_as_ref.stderr +++ b/tests/ui/match_as_ref.stderr @@ -1,5 +1,5 @@ error: use `as_ref()` instead - --> $DIR/match_as_ref.rs:8:33 + --> $DIR/match_as_ref.rs:6:33 | LL | let borrowed: Option<&()> = match owned { | _________________________________^ @@ -11,7 +11,7 @@ LL | | }; = note: `-D clippy::match-as-ref` implied by `-D warnings` error: use `as_mut()` instead - --> $DIR/match_as_ref.rs:14:39 + --> $DIR/match_as_ref.rs:12:39 | LL | let borrow_mut: Option<&mut ()> = match mut_owned { | _______________________________________^ @@ -21,7 +21,7 @@ LL | | }; | |_____^ help: try: `mut_owned.as_mut()` error: use `as_ref()` instead - --> $DIR/match_as_ref.rs:32:13 + --> $DIR/match_as_ref.rs:30:13 | LL | / match self.source { LL | | Some(ref s) => Some(s), diff --git a/tests/ui/match_bool.rs b/tests/ui/match_bool.rs index bcc999a49428d..d7a379f9ac320 100644 --- a/tests/ui/match_bool.rs +++ b/tests/ui/match_bool.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![deny(clippy::match_bool)] fn match_bool() { diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index 3fd0468e51de8..32311f73db345 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> $DIR/match_bool.rs:31:11 + --> $DIR/match_bool.rs:32:11 | LL | match test && test { | ^^^^^^^^^^^^ help: try: `test` @@ -7,7 +7,7 @@ LL | match test && test { = note: `-D clippy::nonminimal-bool` implied by `-D warnings` error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:6:5 + --> $DIR/match_bool.rs:7:5 | LL | / match test { LL | | true => 0, @@ -16,13 +16,13 @@ LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if test { 0 } else { 42 }` | note: the lint level is defined here - --> $DIR/match_bool.rs:1:9 + --> $DIR/match_bool.rs:2:9 | LL | #![deny(clippy::match_bool)] | ^^^^^^^^^^^^^^^^^^ error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:12:5 + --> $DIR/match_bool.rs:13:5 | LL | / match option == 1 { LL | | true => 1, @@ -31,7 +31,7 @@ LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if option == 1 { 1 } else { 0 }` error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:17:5 + --> $DIR/match_bool.rs:18:5 | LL | / match test { LL | | true => (), @@ -49,7 +49,7 @@ LL ~ }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:24:5 + --> $DIR/match_bool.rs:25:5 | LL | / match test { LL | | false => { @@ -67,7 +67,7 @@ LL ~ }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:31:5 + --> $DIR/match_bool.rs:32:5 | LL | / match test && test { LL | | false => { @@ -85,7 +85,7 @@ LL ~ }; | error: equal expressions as operands to `&&` - --> $DIR/match_bool.rs:31:11 + --> $DIR/match_bool.rs:32:11 | LL | match test && test { | ^^^^^^^^^^^^ @@ -93,7 +93,7 @@ LL | match test && test { = note: `#[deny(clippy::eq_op)]` on by default error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:38:5 + --> $DIR/match_bool.rs:39:5 | LL | / match test { LL | | false => { diff --git a/tests/ui/match_expr_like_matches_macro.fixed b/tests/ui/match_expr_like_matches_macro.fixed index f19149cf9def9..05edc024ba9f7 100644 --- a/tests/ui/match_expr_like_matches_macro.fixed +++ b/tests/ui/match_expr_like_matches_macro.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::match_like_matches_macro)] #![allow( unreachable_patterns, diff --git a/tests/ui/match_expr_like_matches_macro.rs b/tests/ui/match_expr_like_matches_macro.rs index 8f4e58981ea6a..d6a0313cde432 100644 --- a/tests/ui/match_expr_like_matches_macro.rs +++ b/tests/ui/match_expr_like_matches_macro.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::match_like_matches_macro)] #![allow( unreachable_patterns, diff --git a/tests/ui/match_expr_like_matches_macro.stderr b/tests/ui/match_expr_like_matches_macro.stderr index b57b26284ff36..06006e26aff21 100644 --- a/tests/ui/match_expr_like_matches_macro.stderr +++ b/tests/ui/match_expr_like_matches_macro.stderr @@ -1,5 +1,5 @@ error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:16:14 + --> $DIR/match_expr_like_matches_macro.rs:14:14 | LL | let _y = match x { | ______________^ @@ -11,7 +11,7 @@ LL | | }; = note: `-D clippy::match-like-matches-macro` implied by `-D warnings` error: redundant pattern matching, consider using `is_some()` - --> $DIR/match_expr_like_matches_macro.rs:22:14 + --> $DIR/match_expr_like_matches_macro.rs:20:14 | LL | let _w = match x { | ______________^ @@ -23,7 +23,7 @@ LL | | }; = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_none()` - --> $DIR/match_expr_like_matches_macro.rs:28:14 + --> $DIR/match_expr_like_matches_macro.rs:26:14 | LL | let _z = match x { | ______________^ @@ -33,7 +33,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:34:15 + --> $DIR/match_expr_like_matches_macro.rs:32:15 | LL | let _zz = match x { | _______________^ @@ -43,13 +43,13 @@ LL | | }; | |_____^ help: try: `!matches!(x, Some(r) if r == 0)` error: if let .. else expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:40:16 + --> $DIR/match_expr_like_matches_macro.rs:38:16 | LL | let _zzz = if let Some(5) = x { true } else { false }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(x, Some(5))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:64:20 + --> $DIR/match_expr_like_matches_macro.rs:62:20 | LL | let _ans = match x { | ____________________^ @@ -60,7 +60,7 @@ LL | | }; | |_________^ help: try: `matches!(x, E::A(_) | E::B(_))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:74:20 + --> $DIR/match_expr_like_matches_macro.rs:72:20 | LL | let _ans = match x { | ____________________^ @@ -73,7 +73,7 @@ LL | | }; | |_________^ help: try: `matches!(x, E::A(_) | E::B(_))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:84:20 + --> $DIR/match_expr_like_matches_macro.rs:82:20 | LL | let _ans = match x { | ____________________^ @@ -84,7 +84,7 @@ LL | | }; | |_________^ help: try: `!matches!(x, E::B(_) | E::C)` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:144:18 + --> $DIR/match_expr_like_matches_macro.rs:142:18 | LL | let _z = match &z { | __________________^ @@ -94,7 +94,7 @@ LL | | }; | |_________^ help: try: `matches!(z, Some(3))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:153:18 + --> $DIR/match_expr_like_matches_macro.rs:151:18 | LL | let _z = match &z { | __________________^ @@ -104,7 +104,7 @@ LL | | }; | |_________^ help: try: `matches!(&z, Some(3))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:170:21 + --> $DIR/match_expr_like_matches_macro.rs:168:21 | LL | let _ = match &z { | _____________________^ @@ -114,7 +114,7 @@ LL | | }; | |_____________^ help: try: `matches!(&z, AnEnum::X)` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:184:20 + --> $DIR/match_expr_like_matches_macro.rs:182:20 | LL | let _res = match &val { | ____________________^ @@ -124,7 +124,7 @@ LL | | }; | |_________^ help: try: `matches!(&val, &Some(ref _a))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:196:20 + --> $DIR/match_expr_like_matches_macro.rs:194:20 | LL | let _res = match &val { | ____________________^ @@ -134,7 +134,7 @@ LL | | }; | |_________^ help: try: `matches!(&val, &Some(ref _a))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:254:14 + --> $DIR/match_expr_like_matches_macro.rs:252:14 | LL | let _y = match Some(5) { | ______________^ diff --git a/tests/ui/match_on_vec_items.rs b/tests/ui/match_on_vec_items.rs index cf9c279cd2f16..45a74f5c5ddea 100644 --- a/tests/ui/match_on_vec_items.rs +++ b/tests/ui/match_on_vec_items.rs @@ -1,6 +1,6 @@ #![warn(clippy::match_on_vec_items)] #![allow(clippy::redundant_at_rest_pattern, clippy::useless_vec)] - +//@no-rustfix fn match_with_wildcard() { let arr = vec![0, 1, 2, 3]; let range = 1..3; diff --git a/tests/ui/match_ref_pats.fixed b/tests/ui/match_ref_pats.fixed index 50c3dcc1e0a82..f8d47b0fdc7da 100644 --- a/tests/ui/match_ref_pats.fixed +++ b/tests/ui/match_ref_pats.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_ref_pats)] #![allow(dead_code, unused_variables)] #![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)] diff --git a/tests/ui/match_ref_pats.rs b/tests/ui/match_ref_pats.rs index d29ddacc04ad3..bcd7bf7ab51b9 100644 --- a/tests/ui/match_ref_pats.rs +++ b/tests/ui/match_ref_pats.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_ref_pats)] #![allow(dead_code, unused_variables)] #![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)] diff --git a/tests/ui/match_ref_pats.stderr b/tests/ui/match_ref_pats.stderr index 1294e0fe56fd4..c65a2d100bee9 100644 --- a/tests/ui/match_ref_pats.stderr +++ b/tests/ui/match_ref_pats.stderr @@ -1,5 +1,5 @@ error: you don't need to add `&` to all patterns - --> $DIR/match_ref_pats.rs:9:9 + --> $DIR/match_ref_pats.rs:8:9 | LL | / match v { LL | | &Some(v) => println!("{:?}", v), @@ -16,7 +16,7 @@ LL ~ None => println!("none"), | error: you don't need to add `&` to both the expression and the patterns - --> $DIR/match_ref_pats.rs:26:5 + --> $DIR/match_ref_pats.rs:25:5 | LL | / match &w { LL | | &Some(v) => println!("{:?}", v), @@ -32,7 +32,7 @@ LL ~ None => println!("none"), | error: redundant pattern matching, consider using `is_none()` - --> $DIR/match_ref_pats.rs:38:12 + --> $DIR/match_ref_pats.rs:37:12 | LL | if let &None = a { | -------^^^^^---- help: try: `if a.is_none()` @@ -40,13 +40,13 @@ LL | if let &None = a { = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_none()` - --> $DIR/match_ref_pats.rs:43:12 + --> $DIR/match_ref_pats.rs:42:12 | LL | if let &None = &b { | -------^^^^^----- help: try: `if b.is_none()` error: you don't need to add `&` to all patterns - --> $DIR/match_ref_pats.rs:103:9 + --> $DIR/match_ref_pats.rs:102:9 | LL | / match foobar_variant!(0) { LL | | &FooBar::Foo => println!("Foo"), diff --git a/tests/ui/match_result_ok.fixed b/tests/ui/match_result_ok.fixed index fe67b225fa176..8d7cddc0ad749 100644 --- a/tests/ui/match_result_ok.fixed +++ b/tests/ui/match_result_ok.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_result_ok)] #![allow(dead_code)] #![allow(clippy::boxed_local, clippy::uninlined_format_args)] diff --git a/tests/ui/match_result_ok.rs b/tests/ui/match_result_ok.rs index eac382e1f623a..9a18b813aca30 100644 --- a/tests/ui/match_result_ok.rs +++ b/tests/ui/match_result_ok.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_result_ok)] #![allow(dead_code)] #![allow(clippy::boxed_local, clippy::uninlined_format_args)] diff --git a/tests/ui/match_result_ok.stderr b/tests/ui/match_result_ok.stderr index cbdc56aa28c44..2cf38624e576d 100644 --- a/tests/ui/match_result_ok.stderr +++ b/tests/ui/match_result_ok.stderr @@ -1,5 +1,5 @@ error: matching on `Some` with `ok()` is redundant - --> $DIR/match_result_ok.rs:9:5 + --> $DIR/match_result_ok.rs:8:5 | LL | if let Some(y) = x.parse().ok() { y } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | if let Ok(y) = x.parse() { y } else { 0 } | ~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant - --> $DIR/match_result_ok.rs:19:9 + --> $DIR/match_result_ok.rs:18:9 | LL | if let Some(y) = x . parse() . ok () { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | if let Ok(y) = x . parse() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant - --> $DIR/match_result_ok.rs:45:5 + --> $DIR/match_result_ok.rs:44:5 | LL | while let Some(a) = wat.next().ok() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_same_arms.rs b/tests/ui/match_same_arms.rs index fad6a7db988c4..2f4652dcf32b6 100644 --- a/tests/ui/match_same_arms.rs +++ b/tests/ui/match_same_arms.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::match_same_arms)] pub enum Abc { diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index 88b9a20a3726f..5f7e2b4755675 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -1,19 +1,19 @@ error: this match arm has an identical body to the `_` wildcard arm - --> $DIR/match_same_arms.rs:11:9 + --> $DIR/match_same_arms.rs:12:9 | LL | Abc::A => 0, | ^^^^^^^^^^^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms.rs:13:9 + --> $DIR/match_same_arms.rs:14:9 | LL | _ => 0, | ^^^^^^ = note: `-D clippy::match-same-arms` implied by `-D warnings` error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:17:9 + --> $DIR/match_same_arms.rs:18:9 | LL | (1, .., 3) => 42, | ----------^^^^^^ @@ -22,13 +22,13 @@ LL | (1, .., 3) => 42, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:18:9 + --> $DIR/match_same_arms.rs:19:9 | LL | (.., 3) => 42, | ^^^^^^^^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:24:9 + --> $DIR/match_same_arms.rs:25:9 | LL | 51 => 1, | --^^^^^ @@ -37,13 +37,13 @@ LL | 51 => 1, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:23:9 + --> $DIR/match_same_arms.rs:24:9 | LL | 42 => 1, | ^^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:25:9 + --> $DIR/match_same_arms.rs:26:9 | LL | 41 => 2, | --^^^^^ @@ -52,13 +52,13 @@ LL | 41 => 2, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:26:9 + --> $DIR/match_same_arms.rs:27:9 | LL | 52 => 2, | ^^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:32:9 + --> $DIR/match_same_arms.rs:33:9 | LL | 2 => 2, | -^^^^^ @@ -67,13 +67,13 @@ LL | 2 => 2, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:31:9 + --> $DIR/match_same_arms.rs:32:9 | LL | 1 => 2, | ^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:34:9 + --> $DIR/match_same_arms.rs:35:9 | LL | 3 => 2, | -^^^^^ @@ -82,13 +82,13 @@ LL | 3 => 2, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:31:9 + --> $DIR/match_same_arms.rs:32:9 | LL | 1 => 2, | ^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:32:9 + --> $DIR/match_same_arms.rs:33:9 | LL | 2 => 2, | -^^^^^ @@ -97,13 +97,13 @@ LL | 2 => 2, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:34:9 + --> $DIR/match_same_arms.rs:35:9 | LL | 3 => 2, | ^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:51:17 + --> $DIR/match_same_arms.rs:52:17 | LL | CommandInfo::External { name, .. } => name.to_string(), | ----------------------------------^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | CommandInfo::External { name, .. } => name.to_string(), | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:50:17 + --> $DIR/match_same_arms.rs:51:17 | LL | CommandInfo::BuiltIn { name, .. } => name.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_same_arms2.rs b/tests/ui/match_same_arms2.rs index b1b9a6ae3e8ab..525a355f40355 100644 --- a/tests/ui/match_same_arms2.rs +++ b/tests/ui/match_same_arms2.rs @@ -4,7 +4,7 @@ clippy::diverging_sub_expression, clippy::uninlined_format_args )] - +//@no-rustfix fn bar(_: T) {} fn foo() -> bool { unimplemented!() diff --git a/tests/ui/match_same_arms_non_exhaustive.rs b/tests/ui/match_same_arms_non_exhaustive.rs index 07421173a3381..096858f3a67d5 100644 --- a/tests/ui/match_same_arms_non_exhaustive.rs +++ b/tests/ui/match_same_arms_non_exhaustive.rs @@ -1,7 +1,7 @@ #![feature(non_exhaustive_omitted_patterns_lint)] #![warn(clippy::match_same_arms)] #![no_main] - +//@no-rustfix use std::sync::atomic::Ordering; // #[non_exhaustive] enum pub fn f(x: Ordering) { diff --git a/tests/ui/match_single_binding.fixed b/tests/ui/match_single_binding.fixed index f59ff456bf298..3a3eee4c958b4 100644 --- a/tests/ui/match_single_binding.fixed +++ b/tests/ui/match_single_binding.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_single_binding)] #![allow( unused, diff --git a/tests/ui/match_single_binding.rs b/tests/ui/match_single_binding.rs index e293bc33c8a93..ff2f842ac39ee 100644 --- a/tests/ui/match_single_binding.rs +++ b/tests/ui/match_single_binding.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_single_binding)] #![allow( unused, diff --git a/tests/ui/match_single_binding.stderr b/tests/ui/match_single_binding.stderr index 8998786de7eaf..9d16af76c6af9 100644 --- a/tests/ui/match_single_binding.stderr +++ b/tests/ui/match_single_binding.stderr @@ -1,5 +1,5 @@ error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:34:5 + --> $DIR/match_single_binding.rs:33:5 | LL | / match (a, b, c) { LL | | (x, y, z) => { @@ -18,7 +18,7 @@ LL + } | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:40:5 + --> $DIR/match_single_binding.rs:39:5 | LL | / match (a, b, c) { LL | | (x, y, z) => println!("{} {} {}", x, y, z), @@ -32,7 +32,7 @@ LL + println!("{} {} {}", x, y, z); | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:57:5 + --> $DIR/match_single_binding.rs:56:5 | LL | / match a { LL | | _ => println!("whatever"), @@ -40,7 +40,7 @@ LL | | } | |_____^ help: consider using the match body instead: `println!("whatever");` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:61:5 + --> $DIR/match_single_binding.rs:60:5 | LL | / match a { LL | | _ => { @@ -59,7 +59,7 @@ LL + } | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:68:5 + --> $DIR/match_single_binding.rs:67:5 | LL | / match a { LL | | _ => { @@ -81,7 +81,7 @@ LL + } | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:78:5 + --> $DIR/match_single_binding.rs:77:5 | LL | / match p { LL | | Point { x, y } => println!("Coords: ({}, {})", x, y), @@ -95,7 +95,7 @@ LL + println!("Coords: ({}, {})", x, y); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:82:5 + --> $DIR/match_single_binding.rs:81:5 | LL | / match p { LL | | Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1), @@ -109,7 +109,7 @@ LL + println!("Coords: ({}, {})", x1, y1); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:87:5 + --> $DIR/match_single_binding.rs:86:5 | LL | / match x { LL | | ref r => println!("Got a reference to {}", r), @@ -123,7 +123,7 @@ LL + println!("Got a reference to {}", r); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:92:5 + --> $DIR/match_single_binding.rs:91:5 | LL | / match x { LL | | ref mut mr => println!("Got a mutable reference to {}", mr), @@ -137,7 +137,7 @@ LL + println!("Got a mutable reference to {}", mr); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:96:5 + --> $DIR/match_single_binding.rs:95:5 | LL | / let product = match coords() { LL | | Point { x, y } => x * y, @@ -151,7 +151,7 @@ LL + let product = x * y; | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:104:18 + --> $DIR/match_single_binding.rs:103:18 | LL | .map(|i| match i.unwrap() { | __________________^ @@ -168,7 +168,7 @@ LL ~ }) | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:130:5 + --> $DIR/match_single_binding.rs:129:5 | LL | / match x { LL | | // => @@ -177,7 +177,7 @@ LL | | } | |_____^ help: consider using the match body instead: `println!("Not an array index start")` error: this assignment could be simplified - --> $DIR/match_single_binding.rs:139:5 + --> $DIR/match_single_binding.rs:138:5 | LL | / val = match val.split_at(idx) { LL | | (pre, suf) => { @@ -197,7 +197,7 @@ LL ~ }; | error: this match could be replaced by its scrutinee and body - --> $DIR/match_single_binding.rs:152:16 + --> $DIR/match_single_binding.rs:151:16 | LL | let _ = || match side_effects() { | ________________^ @@ -214,7 +214,7 @@ LL ~ }; | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:158:5 + --> $DIR/match_single_binding.rs:157:5 | LL | / match r { LL | | x => match x { @@ -239,7 +239,7 @@ LL ~ }; | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:171:5 + --> $DIR/match_single_binding.rs:170:5 | LL | / match 1 { LL | | _ => (), @@ -247,7 +247,7 @@ LL | | } | |_____^ help: consider using the match body instead: `();` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:175:13 + --> $DIR/match_single_binding.rs:174:13 | LL | let a = match 1 { | _____________^ @@ -256,7 +256,7 @@ LL | | }; | |_____^ help: consider using the match body instead: `()` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:179:5 + --> $DIR/match_single_binding.rs:178:5 | LL | / match 1 { LL | | _ => side_effects(), @@ -264,7 +264,7 @@ LL | | } | |_____^ help: consider using the match body instead: `side_effects();` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:183:13 + --> $DIR/match_single_binding.rs:182:13 | LL | let b = match 1 { | _____________^ @@ -273,7 +273,7 @@ LL | | }; | |_____^ help: consider using the match body instead: `side_effects()` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:187:5 + --> $DIR/match_single_binding.rs:186:5 | LL | / match 1 { LL | | _ => println!("1"), @@ -281,7 +281,7 @@ LL | | } | |_____^ help: consider using the match body instead: `println!("1");` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:191:13 + --> $DIR/match_single_binding.rs:190:13 | LL | let c = match 1 { | _____________^ @@ -290,7 +290,7 @@ LL | | }; | |_____^ help: consider using the match body instead: `println!("1")` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:196:9 + --> $DIR/match_single_binding.rs:195:9 | LL | / match 1 { LL | | _ => (), @@ -298,7 +298,7 @@ LL | | }, | |_________^ help: consider using the match body instead: `()` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:199:9 + --> $DIR/match_single_binding.rs:198:9 | LL | / match 1 { LL | | _ => side_effects(), @@ -306,7 +306,7 @@ LL | | }, | |_________^ help: consider using the match body instead: `side_effects()` error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:202:9 + --> $DIR/match_single_binding.rs:201:9 | LL | / match 1 { LL | | _ => println!("1"), diff --git a/tests/ui/match_single_binding2.fixed b/tests/ui/match_single_binding2.fixed index adfb4ba91f743..5673aa78c76ae 100644 --- a/tests/ui/match_single_binding2.fixed +++ b/tests/ui/match_single_binding2.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_single_binding)] #![allow(unused_variables)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/match_single_binding2.rs b/tests/ui/match_single_binding2.rs index b5cfe3654a58d..575e7f5816b8b 100644 --- a/tests/ui/match_single_binding2.rs +++ b/tests/ui/match_single_binding2.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_single_binding)] #![allow(unused_variables)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/match_single_binding2.stderr b/tests/ui/match_single_binding2.stderr index e180b93e76d7b..17ef9c36767b8 100644 --- a/tests/ui/match_single_binding2.stderr +++ b/tests/ui/match_single_binding2.stderr @@ -1,5 +1,5 @@ error: this match could be written as a `let` statement - --> $DIR/match_single_binding2.rs:18:36 + --> $DIR/match_single_binding2.rs:17:36 | LL | Some((iter, _item)) => match iter.size_hint() { | ____________________________________^ @@ -17,7 +17,7 @@ LL ~ }, | error: this match could be written as a `let` statement - --> $DIR/match_single_binding2.rs:31:13 + --> $DIR/match_single_binding2.rs:30:13 | LL | / match get_tup() { LL | | (a, b) => println!("a {:?} and b {:?}", a, b), @@ -31,7 +31,7 @@ LL + println!("a {:?} and b {:?}", a, b) | error: this match could be replaced by its scrutinee and body - --> $DIR/match_single_binding2.rs:42:5 + --> $DIR/match_single_binding2.rs:41:5 | LL | / match side_effects() { LL | | _ => println!("Side effects"), @@ -45,7 +45,7 @@ LL + println!("Side effects"); | error: this match could be replaced by its scrutinee and body - --> $DIR/match_single_binding2.rs:49:5 + --> $DIR/match_single_binding2.rs:48:5 | LL | / match match x { LL | | 0 => 1, diff --git a/tests/ui/match_str_case_mismatch.fixed b/tests/ui/match_str_case_mismatch.fixed index cd53b1f06faa7..a608ab0c0cb05 100644 --- a/tests/ui/match_str_case_mismatch.fixed +++ b/tests/ui/match_str_case_mismatch.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_str_case_mismatch)] #![allow(dead_code)] diff --git a/tests/ui/match_str_case_mismatch.rs b/tests/ui/match_str_case_mismatch.rs index 6885305662a25..1e4269d1db5de 100644 --- a/tests/ui/match_str_case_mismatch.rs +++ b/tests/ui/match_str_case_mismatch.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_str_case_mismatch)] #![allow(dead_code)] diff --git a/tests/ui/match_str_case_mismatch.stderr b/tests/ui/match_str_case_mismatch.stderr index 197520a3d6081..3c946b30a90ec 100644 --- a/tests/ui/match_str_case_mismatch.stderr +++ b/tests/ui/match_str_case_mismatch.stderr @@ -1,5 +1,5 @@ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:113:9 + --> $DIR/match_str_case_mismatch.rs:112:9 | LL | "Bar" => {}, | ^^^^^ @@ -11,7 +11,7 @@ LL | "bar" => {}, | ~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:123:9 + --> $DIR/match_str_case_mismatch.rs:122:9 | LL | "~!@#$%^&*()-_=+Foo" => {}, | ^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | "~!@#$%^&*()-_=+foo" => {}, | ~~~~~~~~~~~~~~~~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:135:9 + --> $DIR/match_str_case_mismatch.rs:134:9 | LL | "Воды" => {}, | ^^^^^^ @@ -33,7 +33,7 @@ LL | "воды" => {}, | ~~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:146:9 + --> $DIR/match_str_case_mismatch.rs:145:9 | LL | "barDz" => {}, | ^^^^^^ @@ -44,7 +44,7 @@ LL | "bardz" => {}, | ~~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:156:9 + --> $DIR/match_str_case_mismatch.rs:155:9 | LL | "bARʁ" => {}, | ^^^^^^ @@ -55,7 +55,7 @@ LL | "BARʁ" => {}, | ~~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:166:9 + --> $DIR/match_str_case_mismatch.rs:165:9 | LL | "Bar" => {}, | ^^^^^ @@ -66,7 +66,7 @@ LL | "bar" => {}, | ~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:181:9 + --> $DIR/match_str_case_mismatch.rs:180:9 | LL | "bAR" => {}, | ^^^^^ diff --git a/tests/ui/match_wildcard_for_single_variants.fixed b/tests/ui/match_wildcard_for_single_variants.fixed index d2e6fef07594a..e5ea2fdde82fd 100644 --- a/tests/ui/match_wildcard_for_single_variants.fixed +++ b/tests/ui/match_wildcard_for_single_variants.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::match_wildcard_for_single_variants)] #![allow(dead_code)] diff --git a/tests/ui/match_wildcard_for_single_variants.rs b/tests/ui/match_wildcard_for_single_variants.rs index cff0c89606500..dbd7fbe160f02 100644 --- a/tests/ui/match_wildcard_for_single_variants.rs +++ b/tests/ui/match_wildcard_for_single_variants.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::match_wildcard_for_single_variants)] #![allow(dead_code)] diff --git a/tests/ui/match_wildcard_for_single_variants.stderr b/tests/ui/match_wildcard_for_single_variants.stderr index 40ff4fbd31606..dfb6e695aa999 100644 --- a/tests/ui/match_wildcard_for_single_variants.stderr +++ b/tests/ui/match_wildcard_for_single_variants.stderr @@ -1,5 +1,5 @@ error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:24:13 + --> $DIR/match_wildcard_for_single_variants.rs:22:13 | LL | _ => (), | ^ help: try: `Self::Rgb(..)` @@ -7,55 +7,55 @@ LL | _ => (), = note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:34:9 + --> $DIR/match_wildcard_for_single_variants.rs:32:9 | LL | _ => {}, | ^ help: try: `Foo::C` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:44:9 + --> $DIR/match_wildcard_for_single_variants.rs:42:9 | LL | _ => {}, | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:52:9 + --> $DIR/match_wildcard_for_single_variants.rs:50:9 | LL | _ => {}, | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:58:9 + --> $DIR/match_wildcard_for_single_variants.rs:56:9 | LL | _ => {}, | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:75:9 + --> $DIR/match_wildcard_for_single_variants.rs:73:9 | LL | &_ => (), | ^^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:84:9 + --> $DIR/match_wildcard_for_single_variants.rs:82:9 | LL | _ => (), | ^ help: try: `C::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:91:9 + --> $DIR/match_wildcard_for_single_variants.rs:89:9 | LL | _ => (), | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:126:13 + --> $DIR/match_wildcard_for_single_variants.rs:124:13 | LL | _ => (), | ^ help: try: `Enum::__Private` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:153:13 + --> $DIR/match_wildcard_for_single_variants.rs:151:13 | LL | _ => 2, | ^ help: try: `Foo::B` diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index d37e97b0a0608..453d0bcc57c53 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn( clippy::all, diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index 34e37f3dbbbdb..0c4e0f6032d8e 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn( clippy::all, diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index 58b57be750702..00f3ccbdbea6c 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -1,5 +1,5 @@ error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:16:13 + --> $DIR/mem_replace.rs:14:13 | LL | let _ = mem::replace(&mut an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` @@ -7,13 +7,13 @@ LL | let _ = mem::replace(&mut an_option, None); = note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:18:13 + --> $DIR/mem_replace.rs:16:13 | LL | let _ = mem::replace(an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:23:13 + --> $DIR/mem_replace.rs:21:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` @@ -21,127 +21,127 @@ LL | let _ = std::mem::replace(&mut s, String::default()); = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:26:13 + --> $DIR/mem_replace.rs:24:13 | LL | let _ = std::mem::replace(s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:27:13 + --> $DIR/mem_replace.rs:25:13 | LL | let _ = std::mem::replace(s, Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:30:13 + --> $DIR/mem_replace.rs:28:13 | LL | let _ = std::mem::replace(&mut v, Vec::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:31:13 + --> $DIR/mem_replace.rs:29:13 | LL | let _ = std::mem::replace(&mut v, Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:32:13 + --> $DIR/mem_replace.rs:30:13 | LL | let _ = std::mem::replace(&mut v, Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:33:13 + --> $DIR/mem_replace.rs:31:13 | LL | let _ = std::mem::replace(&mut v, vec![]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:36:13 + --> $DIR/mem_replace.rs:34:13 | LL | let _ = std::mem::replace(&mut hash_map, HashMap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_map)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:39:13 + --> $DIR/mem_replace.rs:37:13 | LL | let _ = std::mem::replace(&mut btree_map, BTreeMap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_map)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:42:13 + --> $DIR/mem_replace.rs:40:13 | LL | let _ = std::mem::replace(&mut vd, VecDeque::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut vd)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:45:13 + --> $DIR/mem_replace.rs:43:13 | LL | let _ = std::mem::replace(&mut hash_set, HashSet::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_set)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:48:13 + --> $DIR/mem_replace.rs:46:13 | LL | let _ = std::mem::replace(&mut btree_set, BTreeSet::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_set)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:51:13 + --> $DIR/mem_replace.rs:49:13 | LL | let _ = std::mem::replace(&mut list, LinkedList::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut list)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:54:13 + --> $DIR/mem_replace.rs:52:13 | LL | let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut binary_heap)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:57:13 + --> $DIR/mem_replace.rs:55:13 | LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:60:13 + --> $DIR/mem_replace.rs:58:13 | LL | let _ = std::mem::replace(&mut refstr, ""); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut refstr)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:63:13 + --> $DIR/mem_replace.rs:61:13 | LL | let _ = std::mem::replace(&mut slice, &[]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut slice)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:91:13 + --> $DIR/mem_replace.rs:89:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:121:13 + --> $DIR/mem_replace.rs:119:13 | LL | let _ = std::mem::replace(&mut f.0, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:122:13 + --> $DIR/mem_replace.rs:120:13 | LL | let _ = std::mem::replace(&mut *f, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:123:13 + --> $DIR/mem_replace.rs:121:13 | LL | let _ = std::mem::replace(&mut b.opt, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `b.opt.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> $DIR/mem_replace.rs:125:13 + --> $DIR/mem_replace.rs:123:13 | LL | let _ = std::mem::replace(&mut b.val, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)` diff --git a/tests/ui/methods_fixable.fixed b/tests/ui/methods_fixable.fixed index ce5d19a8b6e8e..bb06b5a480ff1 100644 --- a/tests/ui/methods_fixable.fixed +++ b/tests/ui/methods_fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::filter_next)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/methods_fixable.rs b/tests/ui/methods_fixable.rs index 0615817ec925d..11de924593ed2 100644 --- a/tests/ui/methods_fixable.rs +++ b/tests/ui/methods_fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::filter_next)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/methods_fixable.stderr b/tests/ui/methods_fixable.stderr index 6f45d100d2822..e4e626192ca2f 100644 --- a/tests/ui/methods_fixable.stderr +++ b/tests/ui/methods_fixable.stderr @@ -1,5 +1,5 @@ error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead - --> $DIR/methods_fixable.rs:11:13 + --> $DIR/methods_fixable.rs:9:13 | LL | let _ = v.iter().filter(|&x| *x < 0).next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `v.iter().find(|&x| *x < 0)` diff --git a/tests/ui/methods_unfixable.rs b/tests/ui/methods_unfixable.rs index 3d88ce4b6bbdc..e12b8136d2b9c 100644 --- a/tests/ui/methods_unfixable.rs +++ b/tests/ui/methods_unfixable.rs @@ -1,5 +1,5 @@ #![warn(clippy::filter_next)] - +//@no-rustfix fn main() { issue10029(); } diff --git a/tests/ui/mismatched_target_os_non_unix.fixed b/tests/ui/mismatched_target_os_non_unix.fixed index f58e9a429b623..de02b2bee31fc 100644 --- a/tests/ui/mismatched_target_os_non_unix.fixed +++ b/tests/ui/mismatched_target_os_non_unix.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::mismatched_target_os)] #![allow(unused)] diff --git a/tests/ui/mismatched_target_os_non_unix.rs b/tests/ui/mismatched_target_os_non_unix.rs index e00224f5ceb40..a960518751bfc 100644 --- a/tests/ui/mismatched_target_os_non_unix.rs +++ b/tests/ui/mismatched_target_os_non_unix.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::mismatched_target_os)] #![allow(unused)] diff --git a/tests/ui/mismatched_target_os_non_unix.stderr b/tests/ui/mismatched_target_os_non_unix.stderr index 5f1b090830464..3d41510a8563c 100644 --- a/tests/ui/mismatched_target_os_non_unix.stderr +++ b/tests/ui/mismatched_target_os_non_unix.stderr @@ -1,5 +1,5 @@ error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:6:1 + --> $DIR/mismatched_target_os_non_unix.rs:4:1 | LL | #[cfg(hermit)] | ^^^^^^------^^ @@ -9,7 +9,7 @@ LL | #[cfg(hermit)] = note: `-D clippy::mismatched-target-os` implied by `-D warnings` error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:9:1 + --> $DIR/mismatched_target_os_non_unix.rs:7:1 | LL | #[cfg(wasi)] | ^^^^^^----^^ @@ -17,7 +17,7 @@ LL | #[cfg(wasi)] | help: try: `target_os = "wasi"` error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:12:1 + --> $DIR/mismatched_target_os_non_unix.rs:10:1 | LL | #[cfg(none)] | ^^^^^^----^^ @@ -25,7 +25,7 @@ LL | #[cfg(none)] | help: try: `target_os = "none"` error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:16:1 + --> $DIR/mismatched_target_os_non_unix.rs:14:1 | LL | #[cfg(all(not(windows), wasi))] | ^^^^^^^^^^^^^^^^^^^^^^^^----^^^ diff --git a/tests/ui/mismatched_target_os_unix.fixed b/tests/ui/mismatched_target_os_unix.fixed index 330587a3c4c3e..b945c4d9619da 100644 --- a/tests/ui/mismatched_target_os_unix.fixed +++ b/tests/ui/mismatched_target_os_unix.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::mismatched_target_os)] #![allow(unused)] diff --git a/tests/ui/mismatched_target_os_unix.rs b/tests/ui/mismatched_target_os_unix.rs index 5a90019a2e4c3..34307facd6549 100644 --- a/tests/ui/mismatched_target_os_unix.rs +++ b/tests/ui/mismatched_target_os_unix.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::mismatched_target_os)] #![allow(unused)] diff --git a/tests/ui/mismatched_target_os_unix.stderr b/tests/ui/mismatched_target_os_unix.stderr index 9822c77c9dfea..8f4c60fc9ca6d 100644 --- a/tests/ui/mismatched_target_os_unix.stderr +++ b/tests/ui/mismatched_target_os_unix.stderr @@ -1,5 +1,5 @@ error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:6:1 + --> $DIR/mismatched_target_os_unix.rs:4:1 | LL | #[cfg(linux)] | ^^^^^^-----^^ @@ -10,7 +10,7 @@ LL | #[cfg(linux)] = note: `-D clippy::mismatched-target-os` implied by `-D warnings` error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:9:1 + --> $DIR/mismatched_target_os_unix.rs:7:1 | LL | #[cfg(freebsd)] | ^^^^^^-------^^ @@ -20,7 +20,7 @@ LL | #[cfg(freebsd)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:12:1 + --> $DIR/mismatched_target_os_unix.rs:10:1 | LL | #[cfg(dragonfly)] | ^^^^^^---------^^ @@ -30,7 +30,7 @@ LL | #[cfg(dragonfly)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:15:1 + --> $DIR/mismatched_target_os_unix.rs:13:1 | LL | #[cfg(openbsd)] | ^^^^^^-------^^ @@ -40,7 +40,7 @@ LL | #[cfg(openbsd)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:18:1 + --> $DIR/mismatched_target_os_unix.rs:16:1 | LL | #[cfg(netbsd)] | ^^^^^^------^^ @@ -50,7 +50,7 @@ LL | #[cfg(netbsd)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:21:1 + --> $DIR/mismatched_target_os_unix.rs:19:1 | LL | #[cfg(macos)] | ^^^^^^-----^^ @@ -60,7 +60,7 @@ LL | #[cfg(macos)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:24:1 + --> $DIR/mismatched_target_os_unix.rs:22:1 | LL | #[cfg(ios)] | ^^^^^^---^^ @@ -70,7 +70,7 @@ LL | #[cfg(ios)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:27:1 + --> $DIR/mismatched_target_os_unix.rs:25:1 | LL | #[cfg(android)] | ^^^^^^-------^^ @@ -80,7 +80,7 @@ LL | #[cfg(android)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:30:1 + --> $DIR/mismatched_target_os_unix.rs:28:1 | LL | #[cfg(emscripten)] | ^^^^^^----------^^ @@ -90,7 +90,7 @@ LL | #[cfg(emscripten)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:33:1 + --> $DIR/mismatched_target_os_unix.rs:31:1 | LL | #[cfg(fuchsia)] | ^^^^^^-------^^ @@ -100,7 +100,7 @@ LL | #[cfg(fuchsia)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:36:1 + --> $DIR/mismatched_target_os_unix.rs:34:1 | LL | #[cfg(haiku)] | ^^^^^^-----^^ @@ -110,7 +110,7 @@ LL | #[cfg(haiku)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:39:1 + --> $DIR/mismatched_target_os_unix.rs:37:1 | LL | #[cfg(illumos)] | ^^^^^^-------^^ @@ -120,7 +120,7 @@ LL | #[cfg(illumos)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:42:1 + --> $DIR/mismatched_target_os_unix.rs:40:1 | LL | #[cfg(l4re)] | ^^^^^^----^^ @@ -130,7 +130,7 @@ LL | #[cfg(l4re)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:45:1 + --> $DIR/mismatched_target_os_unix.rs:43:1 | LL | #[cfg(redox)] | ^^^^^^-----^^ @@ -140,7 +140,7 @@ LL | #[cfg(redox)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:48:1 + --> $DIR/mismatched_target_os_unix.rs:46:1 | LL | #[cfg(solaris)] | ^^^^^^-------^^ @@ -150,7 +150,7 @@ LL | #[cfg(solaris)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:51:1 + --> $DIR/mismatched_target_os_unix.rs:49:1 | LL | #[cfg(vxworks)] | ^^^^^^-------^^ @@ -160,7 +160,7 @@ LL | #[cfg(vxworks)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:55:1 + --> $DIR/mismatched_target_os_unix.rs:53:1 | LL | #[cfg(all(not(any(solaris, linux)), freebsd))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/misnamed_getters.fixed b/tests/ui/misnamed_getters.fixed new file mode 100644 index 0000000000000..fd7d127655872 --- /dev/null +++ b/tests/ui/misnamed_getters.fixed @@ -0,0 +1,124 @@ +#![allow(unused)] +#![warn(clippy::misnamed_getters)] + +struct A { + a: u8, + b: u8, + c: u8, +} + +impl A { + fn a(&self) -> &u8 { + &self.a + } + fn a_mut(&mut self) -> &mut u8 { + &mut self.a + } + + fn b(self) -> u8 { + self.b + } + + fn b_mut(&mut self) -> &mut u8 { + &mut self.b + } + + fn c(&self) -> &u8 { + &self.c + } + + fn c_mut(&mut self) -> &mut u8 { + &mut self.c + } +} + +union B { + a: u8, + b: u8, +} + +impl B { + unsafe fn a(&self) -> &u8 { + &self.a + } + unsafe fn a_mut(&mut self) -> &mut u8 { + &mut self.a + } + + unsafe fn b(self) -> u8 { + self.b + } + + unsafe fn b_mut(&mut self) -> &mut u8 { + &mut self.b + } + + unsafe fn c(&self) -> &u8 { + &self.b + } + + unsafe fn c_mut(&mut self) -> &mut u8 { + &mut self.a + } + + unsafe fn a_unchecked(&self) -> &u8 { + &self.a + } + unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { + &mut self.a + } + + unsafe fn b_unchecked(self) -> u8 { + self.b + } + + unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { + &mut self.b + } + + unsafe fn c_unchecked(&self) -> &u8 { + &self.b + } + + unsafe fn c_unchecked_mut(&mut self) -> &mut u8 { + &mut self.a + } +} + +struct D { + d: u8, + inner: A, +} + +impl core::ops::Deref for D { + type Target = A; + fn deref(&self) -> &A { + &self.inner + } +} + +impl core::ops::DerefMut for D { + fn deref_mut(&mut self) -> &mut A { + &mut self.inner + } +} + +impl D { + fn a(&self) -> &u8 { + &self.a + } + fn a_mut(&mut self) -> &mut u8 { + &mut self.a + } + + fn d(&self) -> &u8 { + &self.d + } + fn d_mut(&mut self) -> &mut u8 { + &mut self.d + } +} + +fn main() { + // test code goes here +} diff --git a/tests/ui/missing_spin_loop.fixed b/tests/ui/missing_spin_loop.fixed index a15298dc37b25..b6520d478be8b 100644 --- a/tests/ui/missing_spin_loop.fixed +++ b/tests/ui/missing_spin_loop.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::missing_spin_loop)] #![allow(clippy::bool_comparison)] #![allow(unused_braces)] diff --git a/tests/ui/missing_spin_loop.rs b/tests/ui/missing_spin_loop.rs index be74581ecd03b..7b115c66ade6e 100644 --- a/tests/ui/missing_spin_loop.rs +++ b/tests/ui/missing_spin_loop.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::missing_spin_loop)] #![allow(clippy::bool_comparison)] #![allow(unused_braces)] diff --git a/tests/ui/missing_spin_loop.stderr b/tests/ui/missing_spin_loop.stderr index 5795c2c219067..b525406bbf0ba 100644 --- a/tests/ui/missing_spin_loop.stderr +++ b/tests/ui/missing_spin_loop.stderr @@ -1,5 +1,5 @@ error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:11:37 + --> $DIR/missing_spin_loop.rs:10:37 | LL | while b.load(Ordering::Acquire) {} | ^^ help: try: `{ std::hint::spin_loop() }` @@ -7,31 +7,31 @@ LL | while b.load(Ordering::Acquire) {} = note: `-D clippy::missing-spin-loop` implied by `-D warnings` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:13:37 + --> $DIR/missing_spin_loop.rs:12:37 | LL | while !b.load(Ordering::SeqCst) {} | ^^ help: try: `{ std::hint::spin_loop() }` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:15:46 + --> $DIR/missing_spin_loop.rs:14:46 | LL | while b.load(Ordering::Acquire) == false {} | ^^ help: try: `{ std::hint::spin_loop() }` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:17:49 + --> $DIR/missing_spin_loop.rs:16:49 | LL | while { true == b.load(Ordering::Acquire) } {} | ^^ help: try: `{ std::hint::spin_loop() }` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:19:93 + --> $DIR/missing_spin_loop.rs:18:93 | LL | while b.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed) != Ok(true) {} | ^^ help: try: `{ std::hint::spin_loop() }` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:21:94 + --> $DIR/missing_spin_loop.rs:20:94 | LL | while Ok(false) != b.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) {} | ^^ help: try: `{ std::hint::spin_loop() }` diff --git a/tests/ui/missing_spin_loop_no_std.fixed b/tests/ui/missing_spin_loop_no_std.fixed index 960e5c05fb63d..497e0e243174e 100644 --- a/tests/ui/missing_spin_loop_no_std.fixed +++ b/tests/ui/missing_spin_loop_no_std.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::missing_spin_loop)] #![feature(lang_items, start, libc)] #![no_std] diff --git a/tests/ui/missing_spin_loop_no_std.rs b/tests/ui/missing_spin_loop_no_std.rs index e532ca62dc533..1c85a9c58d651 100644 --- a/tests/ui/missing_spin_loop_no_std.rs +++ b/tests/ui/missing_spin_loop_no_std.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::missing_spin_loop)] #![feature(lang_items, start, libc)] #![no_std] diff --git a/tests/ui/missing_spin_loop_no_std.stderr b/tests/ui/missing_spin_loop_no_std.stderr index 3322a7aae5f6a..33e5d32fe88d6 100644 --- a/tests/ui/missing_spin_loop_no_std.stderr +++ b/tests/ui/missing_spin_loop_no_std.stderr @@ -1,5 +1,5 @@ error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop_no_std.rs:13:37 + --> $DIR/missing_spin_loop_no_std.rs:12:37 | LL | while b.load(Ordering::Acquire) {} | ^^ help: try: `{ core::hint::spin_loop() }` diff --git a/tests/ui/mistyped_literal_suffix.fixed b/tests/ui/mistyped_literal_suffix.fixed index 9c2ffcb02ea11..384f34f65fc78 100644 --- a/tests/ui/mistyped_literal_suffix.fixed +++ b/tests/ui/mistyped_literal_suffix.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![allow( diff --git a/tests/ui/mistyped_literal_suffix.rs b/tests/ui/mistyped_literal_suffix.rs index a0a1e96a775d2..cc7105c4424a1 100644 --- a/tests/ui/mistyped_literal_suffix.rs +++ b/tests/ui/mistyped_literal_suffix.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![allow( diff --git a/tests/ui/mistyped_literal_suffix.stderr b/tests/ui/mistyped_literal_suffix.stderr index ef8e6a33d28f5..ecd73497a8e78 100644 --- a/tests/ui/mistyped_literal_suffix.stderr +++ b/tests/ui/mistyped_literal_suffix.stderr @@ -1,5 +1,5 @@ error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:17:18 + --> $DIR/mistyped_literal_suffix.rs:16:18 | LL | let fail14 = 2_32; | ^^^^ help: did you mean to write: `2_i32` @@ -7,91 +7,91 @@ LL | let fail14 = 2_32; = note: `#[deny(clippy::mistyped_literal_suffixes)]` on by default error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:18:18 + --> $DIR/mistyped_literal_suffix.rs:17:18 | LL | let fail15 = 4_64; | ^^^^ help: did you mean to write: `4_i64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:19:18 + --> $DIR/mistyped_literal_suffix.rs:18:18 | LL | let fail16 = 7_8; // | ^^^ help: did you mean to write: `7_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:20:18 + --> $DIR/mistyped_literal_suffix.rs:19:18 | LL | let fail17 = 23_16; // | ^^^^^ help: did you mean to write: `23_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:23:18 + --> $DIR/mistyped_literal_suffix.rs:22:18 | LL | let fail20 = 2__8; // | ^^^^ help: did you mean to write: `2_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:24:18 + --> $DIR/mistyped_literal_suffix.rs:23:18 | LL | let fail21 = 4___16; // | ^^^^^^ help: did you mean to write: `4_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:27:18 + --> $DIR/mistyped_literal_suffix.rs:26:18 | LL | let fail25 = 1E2_32; | ^^^^^^ help: did you mean to write: `1E2_f32` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:28:18 + --> $DIR/mistyped_literal_suffix.rs:27:18 | LL | let fail26 = 43E7_64; | ^^^^^^^ help: did you mean to write: `43E7_f64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:29:18 + --> $DIR/mistyped_literal_suffix.rs:28:18 | LL | let fail27 = 243E17_32; | ^^^^^^^^^ help: did you mean to write: `243E17_f32` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:30:18 + --> $DIR/mistyped_literal_suffix.rs:29:18 | LL | let fail28 = 241251235E723_64; | ^^^^^^^^^^^^^^^^ help: did you mean to write: `241_251_235E723_f64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:34:18 + --> $DIR/mistyped_literal_suffix.rs:33:18 | LL | let fail30 = 127_8; // should be i8 | ^^^^^ help: did you mean to write: `127_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:35:18 + --> $DIR/mistyped_literal_suffix.rs:34:18 | LL | let fail31 = 240_8; // should be u8 | ^^^^^ help: did you mean to write: `240_u8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:37:18 + --> $DIR/mistyped_literal_suffix.rs:36:18 | LL | let fail33 = 0x1234_16; | ^^^^^^^^^ help: did you mean to write: `0x1234_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:38:18 + --> $DIR/mistyped_literal_suffix.rs:37:18 | LL | let fail34 = 0xABCD_16; | ^^^^^^^^^ help: did you mean to write: `0xABCD_u16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:40:18 + --> $DIR/mistyped_literal_suffix.rs:39:18 | LL | let fail36 = 0xFFFF_FFFF_FFFF_FFFF_64; // u64 | ^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to write: `0xFFFF_FFFF_FFFF_FFFF_u64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:46:13 + --> $DIR/mistyped_literal_suffix.rs:45:13 | LL | let _ = 1.12345E1_32; | ^^^^^^^^^^^^ help: did you mean to write: `1.123_45E1_f32` diff --git a/tests/ui/must_use_candidates.fixed b/tests/ui/must_use_candidates.fixed index 3ca20c07d9baf..3ed705b29061e 100644 --- a/tests/ui/must_use_candidates.fixed +++ b/tests/ui/must_use_candidates.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(never_type)] #![allow( unused_mut, diff --git a/tests/ui/must_use_candidates.rs b/tests/ui/must_use_candidates.rs index dc4e0118ec720..ab8efea0ac7e2 100644 --- a/tests/ui/must_use_candidates.rs +++ b/tests/ui/must_use_candidates.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(never_type)] #![allow( unused_mut, diff --git a/tests/ui/must_use_candidates.stderr b/tests/ui/must_use_candidates.stderr index 5fb302ccbf14e..35da27d83a401 100644 --- a/tests/ui/must_use_candidates.stderr +++ b/tests/ui/must_use_candidates.stderr @@ -1,5 +1,5 @@ error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:17:1 + --> $DIR/must_use_candidates.rs:16:1 | LL | pub fn pure(i: u8) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8` @@ -7,25 +7,25 @@ LL | pub fn pure(i: u8) -> u8 { = note: `-D clippy::must-use-candidate` implied by `-D warnings` error: this method could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:22:5 + --> $DIR/must_use_candidates.rs:21:5 | LL | pub fn inherent_pure(&self) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8` error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:53:1 + --> $DIR/must_use_candidates.rs:52:1 | LL | pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool` error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:65:1 + --> $DIR/must_use_candidates.rs:64:1 | LL | pub fn rcd(_x: Rc) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn rcd(_x: Rc) -> bool` error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:73:1 + --> $DIR/must_use_candidates.rs:72:1 | LL | pub fn arcd(_x: Arc) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc) -> bool` diff --git a/tests/ui/must_use_unit.fixed b/tests/ui/must_use_unit.fixed index c460fd7c6b0d5..4ffade40cf0c5 100644 --- a/tests/ui/must_use_unit.fixed +++ b/tests/ui/must_use_unit.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::must_use_unit)] diff --git a/tests/ui/must_use_unit.rs b/tests/ui/must_use_unit.rs index fe95624f79960..6b928e37c417a 100644 --- a/tests/ui/must_use_unit.rs +++ b/tests/ui/must_use_unit.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::must_use_unit)] diff --git a/tests/ui/must_use_unit.stderr b/tests/ui/must_use_unit.stderr index 15e0906b66b5e..bb421abc663c8 100644 --- a/tests/ui/must_use_unit.stderr +++ b/tests/ui/must_use_unit.stderr @@ -1,5 +1,5 @@ error: this unit-returning function has a `#[must_use]` attribute - --> $DIR/must_use_unit.rs:11:1 + --> $DIR/must_use_unit.rs:10:1 | LL | #[must_use] | ----------- help: remove the attribute @@ -9,7 +9,7 @@ LL | pub fn must_use_default() {} = note: `-D clippy::must-use-unit` implied by `-D warnings` error: this unit-returning function has a `#[must_use]` attribute - --> $DIR/must_use_unit.rs:14:1 + --> $DIR/must_use_unit.rs:13:1 | LL | #[must_use] | ----------- help: remove the attribute @@ -17,7 +17,7 @@ LL | pub fn must_use_unit() -> () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this unit-returning function has a `#[must_use]` attribute - --> $DIR/must_use_unit.rs:17:1 + --> $DIR/must_use_unit.rs:16:1 | LL | #[must_use = "With note"] | ------------------------- help: remove the attribute diff --git a/tests/ui/mut_key.rs b/tests/ui/mut_key.rs index 15d68c08984fa..24cf2fbbf12ac 100644 --- a/tests/ui/mut_key.rs +++ b/tests/ui/mut_key.rs @@ -5,7 +5,7 @@ use std::rc::Rc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::Relaxed; use std::sync::Arc; - +//@no-rustfix struct Key(AtomicUsize); impl Clone for Key { diff --git a/tests/ui/mut_mutex_lock.fixed b/tests/ui/mut_mutex_lock.fixed index 433817a4e03da..bbedbb2bed23f 100644 --- a/tests/ui/mut_mutex_lock.fixed +++ b/tests/ui/mut_mutex_lock.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, unused_mut)] #![warn(clippy::mut_mutex_lock)] diff --git a/tests/ui/mut_mutex_lock.rs b/tests/ui/mut_mutex_lock.rs index 567a0b59e7030..74116100e82a7 100644 --- a/tests/ui/mut_mutex_lock.rs +++ b/tests/ui/mut_mutex_lock.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, unused_mut)] #![warn(clippy::mut_mutex_lock)] diff --git a/tests/ui/mut_mutex_lock.stderr b/tests/ui/mut_mutex_lock.stderr index 21c1b3486cacf..f7b371822de8f 100644 --- a/tests/ui/mut_mutex_lock.stderr +++ b/tests/ui/mut_mutex_lock.stderr @@ -1,5 +1,5 @@ error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference - --> $DIR/mut_mutex_lock.rs:11:33 + --> $DIR/mut_mutex_lock.rs:10:33 | LL | let mut value = value_mutex.lock().unwrap(); | ^^^^ help: change this to: `get_mut` diff --git a/tests/ui/mut_reference.rs b/tests/ui/mut_reference.rs index 00661c51a78f9..80edfb261e8ef 100644 --- a/tests/ui/mut_reference.rs +++ b/tests/ui/mut_reference.rs @@ -1,5 +1,5 @@ #![allow(unused_variables, dead_code)] - +//@no-rustfix fn takes_an_immutable_reference(a: &i32) {} fn takes_a_mutable_reference(a: &mut i32) {} diff --git a/tests/ui/needless_arbitrary_self_type.fixed b/tests/ui/needless_arbitrary_self_type.fixed index d7eb1a047ed3a..9da60c687d444 100644 --- a/tests/ui/needless_arbitrary_self_type.fixed +++ b/tests/ui/needless_arbitrary_self_type.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_arbitrary_self_type)] #![allow(unused_mut, clippy::needless_lifetimes)] diff --git a/tests/ui/needless_arbitrary_self_type.rs b/tests/ui/needless_arbitrary_self_type.rs index 85a2a957f29a1..fc4ec5cb0b3ca 100644 --- a/tests/ui/needless_arbitrary_self_type.rs +++ b/tests/ui/needless_arbitrary_self_type.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_arbitrary_self_type)] #![allow(unused_mut, clippy::needless_lifetimes)] diff --git a/tests/ui/needless_arbitrary_self_type.stderr b/tests/ui/needless_arbitrary_self_type.stderr index f4c645d35c8f1..c5b0b25c10b64 100644 --- a/tests/ui/needless_arbitrary_self_type.stderr +++ b/tests/ui/needless_arbitrary_self_type.stderr @@ -1,5 +1,5 @@ error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:12:16 + --> $DIR/needless_arbitrary_self_type.rs:10:16 | LL | pub fn bad(self: Self) { | ^^^^^^^^^^ help: consider to change this parameter to: `self` @@ -7,31 +7,31 @@ LL | pub fn bad(self: Self) { = note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:20:20 + --> $DIR/needless_arbitrary_self_type.rs:18:20 | LL | pub fn mut_bad(mut self: Self) { | ^^^^^^^^^^^^^^ help: consider to change this parameter to: `mut self` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:28:20 + --> $DIR/needless_arbitrary_self_type.rs:26:20 | LL | pub fn ref_bad(self: &Self) { | ^^^^^^^^^^^ help: consider to change this parameter to: `&self` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:36:38 + --> $DIR/needless_arbitrary_self_type.rs:34:38 | LL | pub fn ref_bad_with_lifetime<'a>(self: &'a Self) { | ^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'a self` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:44:24 + --> $DIR/needless_arbitrary_self_type.rs:42:24 | LL | pub fn mut_ref_bad(self: &mut Self) { | ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&mut self` error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:52:42 + --> $DIR/needless_arbitrary_self_type.rs:50:42 | LL | pub fn mut_ref_bad_with_lifetime<'a>(self: &'a mut Self) { | ^^^^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'a mut self` diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.fixed b/tests/ui/needless_arbitrary_self_type_unfixable.fixed new file mode 100644 index 0000000000000..df4949b977e95 --- /dev/null +++ b/tests/ui/needless_arbitrary_self_type_unfixable.fixed @@ -0,0 +1,46 @@ +//@aux-build:proc_macro_attr.rs:proc-macro + +#![warn(clippy::needless_arbitrary_self_type)] + +#[macro_use] +extern crate proc_macro_attr; + +mod issue_6089 { + // Check that we don't lint if the `self` parameter comes from expansion + + macro_rules! test_from_expansion { + () => { + trait T1 { + fn test(self: &Self); + } + + struct S1; + + impl T1 for S1 { + fn test(self: &Self) {} + } + }; + } + + test_from_expansion!(); + + // If only the lifetime name comes from expansion we will lint, but the suggestion will have + // placeholders and will not be applied automatically, as we can't reliably know the original name. + // This specific case happened with async_trait. + + trait T2 { + fn call_with_mut_self(&mut self); + } + + struct S2; + + // The method's signature will be expanded to: + // fn call_with_mut_self<'life0>(self: &'life0 mut Self) {} + #[rename_my_lifetimes] + impl T2 for S2 { + #[allow(clippy::needless_lifetimes)] + fn call_with_mut_self(&mut self) {} + } +} + +fn main() {} diff --git a/tests/ui/needless_bitwise_bool.fixed b/tests/ui/needless_bitwise_bool.fixed index 7543ab72ca214..201f8a4c19de5 100644 --- a/tests/ui/needless_bitwise_bool.fixed +++ b/tests/ui/needless_bitwise_bool.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_bitwise_bool)] fn returns_bool() -> bool { diff --git a/tests/ui/needless_bitwise_bool.rs b/tests/ui/needless_bitwise_bool.rs index 2cea701dce636..b0e5014b74b74 100644 --- a/tests/ui/needless_bitwise_bool.rs +++ b/tests/ui/needless_bitwise_bool.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_bitwise_bool)] fn returns_bool() -> bool { diff --git a/tests/ui/needless_bitwise_bool.stderr b/tests/ui/needless_bitwise_bool.stderr index 63c88ef63f52f..9752624902cce 100644 --- a/tests/ui/needless_bitwise_bool.stderr +++ b/tests/ui/needless_bitwise_bool.stderr @@ -1,5 +1,5 @@ error: use of bitwise operator instead of lazy operator between booleans - --> $DIR/needless_bitwise_bool.rs:24:8 + --> $DIR/needless_bitwise_bool.rs:22:8 | LL | if y & !x { | ^^^^^^ help: try: `y && !x` diff --git a/tests/ui/needless_bool/fixable.fixed b/tests/ui/needless_bool/fixable.fixed index 7d0e556528fa1..c9ea831f8b2a3 100644 --- a/tests/ui/needless_bool/fixable.fixed +++ b/tests/ui/needless_bool/fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_bool)] #![allow( unused, diff --git a/tests/ui/needless_bool/fixable.rs b/tests/ui/needless_bool/fixable.rs index 88bfe8af73373..b83d9c3f2096a 100644 --- a/tests/ui/needless_bool/fixable.rs +++ b/tests/ui/needless_bool/fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_bool)] #![allow( unused, diff --git a/tests/ui/needless_bool/fixable.stderr b/tests/ui/needless_bool/fixable.stderr index 1476aea439ff2..a2dfa2fd4827d 100644 --- a/tests/ui/needless_bool/fixable.stderr +++ b/tests/ui/needless_bool/fixable.stderr @@ -1,5 +1,5 @@ error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:42:5 + --> $DIR/fixable.rs:40:5 | LL | / if x { LL | | true @@ -11,7 +11,7 @@ LL | | }; = note: `-D clippy::needless-bool` implied by `-D warnings` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:47:5 + --> $DIR/fixable.rs:45:5 | LL | / if x { LL | | false @@ -21,7 +21,7 @@ LL | | }; | |_____^ help: you can reduce it to: `!x` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:52:5 + --> $DIR/fixable.rs:50:5 | LL | / if x && y { LL | | false @@ -31,7 +31,7 @@ LL | | }; | |_____^ help: you can reduce it to: `!(x && y)` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:60:5 + --> $DIR/fixable.rs:58:5 | LL | / if a == b { LL | | false @@ -41,7 +41,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a != b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:65:5 + --> $DIR/fixable.rs:63:5 | LL | / if a != b { LL | | false @@ -51,7 +51,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a == b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:70:5 + --> $DIR/fixable.rs:68:5 | LL | / if a < b { LL | | false @@ -61,7 +61,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a >= b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:75:5 + --> $DIR/fixable.rs:73:5 | LL | / if a <= b { LL | | false @@ -71,7 +71,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a > b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:80:5 + --> $DIR/fixable.rs:78:5 | LL | / if a > b { LL | | false @@ -81,7 +81,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a <= b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:85:5 + --> $DIR/fixable.rs:83:5 | LL | / if a >= b { LL | | false @@ -91,7 +91,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a < b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:113:5 + --> $DIR/fixable.rs:111:5 | LL | / if x { LL | | return true; @@ -101,7 +101,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return x` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:121:5 + --> $DIR/fixable.rs:119:5 | LL | / if x { LL | | return false; @@ -111,7 +111,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return !x` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:129:5 + --> $DIR/fixable.rs:127:5 | LL | / if x && y { LL | | return true; @@ -121,7 +121,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return x && y` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:137:5 + --> $DIR/fixable.rs:135:5 | LL | / if x && y { LL | | return false; @@ -131,7 +131,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return !(x && y)` error: equality checks against true are unnecessary - --> $DIR/fixable.rs:145:8 + --> $DIR/fixable.rs:143:8 | LL | if x == true {}; | ^^^^^^^^^ help: try simplifying it as shown: `x` @@ -139,25 +139,25 @@ LL | if x == true {}; = note: `-D clippy::bool-comparison` implied by `-D warnings` error: equality checks against false can be replaced by a negation - --> $DIR/fixable.rs:149:8 + --> $DIR/fixable.rs:147:8 | LL | if x == false {}; | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: equality checks against true are unnecessary - --> $DIR/fixable.rs:159:8 + --> $DIR/fixable.rs:157:8 | LL | if x == true {}; | ^^^^^^^^^ help: try simplifying it as shown: `x` error: equality checks against false can be replaced by a negation - --> $DIR/fixable.rs:160:8 + --> $DIR/fixable.rs:158:8 | LL | if x == false {}; | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:169:12 + --> $DIR/fixable.rs:167:12 | LL | } else if returns_bool() { | ____________^ @@ -168,7 +168,7 @@ LL | | }; | |_____^ help: you can reduce it to: `{ !returns_bool() }` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:182:5 + --> $DIR/fixable.rs:180:5 | LL | / if unsafe { no(4) } & 1 != 0 { LL | | true @@ -178,13 +178,13 @@ LL | | }; | |_____^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:187:30 + --> $DIR/fixable.rs:185:30 | LL | let _brackets_unneeded = if unsafe { no(4) } & 1 != 0 { true } else { false }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `unsafe { no(4) } & 1 != 0` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:190:9 + --> $DIR/fixable.rs:188:9 | LL | if unsafe { no(4) } & 1 != 0 { true } else { false } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)` diff --git a/tests/ui/needless_bool_assign.fixed b/tests/ui/needless_bool_assign.fixed index 3ed31d4d711fa..7b10fe78c6813 100644 --- a/tests/ui/needless_bool_assign.fixed +++ b/tests/ui/needless_bool_assign.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::needless_bool_assign)] diff --git a/tests/ui/needless_bool_assign.rs b/tests/ui/needless_bool_assign.rs index efaeb67fa45de..85c0a5777feea 100644 --- a/tests/ui/needless_bool_assign.rs +++ b/tests/ui/needless_bool_assign.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::needless_bool_assign)] diff --git a/tests/ui/needless_bool_assign.stderr b/tests/ui/needless_bool_assign.stderr index 601bbed5493b9..8e7ea615c7d74 100644 --- a/tests/ui/needless_bool_assign.stderr +++ b/tests/ui/needless_bool_assign.stderr @@ -1,5 +1,5 @@ error: this if-then-else expression assigns a bool literal - --> $DIR/needless_bool_assign.rs:15:5 + --> $DIR/needless_bool_assign.rs:13:5 | LL | / if random() && random() { LL | | a.field = true; @@ -11,7 +11,7 @@ LL | | } = note: `-D clippy::needless-bool-assign` implied by `-D warnings` error: this if-then-else expression assigns a bool literal - --> $DIR/needless_bool_assign.rs:20:5 + --> $DIR/needless_bool_assign.rs:18:5 | LL | / if random() && random() { LL | | a.field = false; @@ -21,7 +21,7 @@ LL | | } | |_____^ help: you can reduce it to: `a.field = !(random() && random());` error: this if-then-else expression assigns a bool literal - --> $DIR/needless_bool_assign.rs:34:5 + --> $DIR/needless_bool_assign.rs:32:5 | LL | / if random() { LL | | a.field = true; @@ -31,7 +31,7 @@ LL | | } | |_____^ help: you can reduce it to: `random(); a.field = true;` error: this `if` has identical blocks - --> $DIR/needless_bool_assign.rs:34:17 + --> $DIR/needless_bool_assign.rs:32:17 | LL | if random() { | _________________^ @@ -40,7 +40,7 @@ LL | | } else { | |_____^ | note: same as this - --> $DIR/needless_bool_assign.rs:36:12 + --> $DIR/needless_bool_assign.rs:34:12 | LL | } else { | ____________^ diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index 1dfbee150d789..ee67224b4a800 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![allow( unused, diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index 3c0d73f5f0253..1444f47d92099 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![allow( unused, diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index f85b4fb46a650..d26c317124b8d 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 - --> $DIR/needless_borrow.rs:16:15 + --> $DIR/needless_borrow.rs:15:15 | LL | let _ = x(&&a); // warn | ^^^ help: change this to: `&a` @@ -7,211 +7,211 @@ LL | let _ = x(&&a); // warn = note: `-D clippy::needless-borrow` implied by `-D warnings` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:20:13 + --> $DIR/needless_borrow.rs:19: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 - --> $DIR/needless_borrow.rs:32:13 + --> $DIR/needless_borrow.rs:31:13 | LL | &&a | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:34:15 + --> $DIR/needless_borrow.rs:33:15 | LL | 46 => &&a, | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:40:27 + --> $DIR/needless_borrow.rs:39:27 | LL | break &ref_a; | ^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:47:15 + --> $DIR/needless_borrow.rs:46:15 | LL | let _ = x(&&&a); | ^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:48:15 + --> $DIR/needless_borrow.rs:47:15 | LL | let _ = x(&mut &&a); | ^^^^^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:49:15 + --> $DIR/needless_borrow.rs:48: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 - --> $DIR/needless_borrow.rs:50:15 + --> $DIR/needless_borrow.rs:49: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 - --> $DIR/needless_borrow.rs:53:11 + --> $DIR/needless_borrow.rs:52:11 | LL | x(&b); | ^^ help: change this to: `b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:60:13 + --> $DIR/needless_borrow.rs:59:13 | LL | mut_ref(&mut x); | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:61:13 + --> $DIR/needless_borrow.rs:60: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 - --> $DIR/needless_borrow.rs:62:23 + --> $DIR/needless_borrow.rs:61: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 - --> $DIR/needless_borrow.rs:63:23 + --> $DIR/needless_borrow.rs:62: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 - --> $DIR/needless_borrow.rs:72:14 + --> $DIR/needless_borrow.rs:71:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:78:14 + --> $DIR/needless_borrow.rs:77:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:90:13 + --> $DIR/needless_borrow.rs:89:13 | LL | let _ = (&x).0; | ^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:92:22 + --> $DIR/needless_borrow.rs:91:22 | LL | let _ = unsafe { (&*x).0 }; | ^^^^^ help: change this to: `(*x)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:102:5 + --> $DIR/needless_borrow.rs:101:5 | LL | (&&()).foo(); | ^^^^^^ help: change this to: `(&())` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:111:5 + --> $DIR/needless_borrow.rs:110:5 | LL | (&&5).foo(); | ^^^^^ help: change this to: `(&5)` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:136:51 + --> $DIR/needless_borrow.rs:135:51 | LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); | ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:137:44 + --> $DIR/needless_borrow.rs:136:44 | LL | let _ = std::path::Path::new(".").join(&&"."); | ^^^^^ help: change this to: `"."` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:138:23 + --> $DIR/needless_borrow.rs:137:23 | LL | deref_target_is_x(&X); | ^^ help: change this to: `X` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:139:26 + --> $DIR/needless_borrow.rs:138:26 | LL | multiple_constraints(&[[""]]); | ^^^^^^^ help: change this to: `[[""]]` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:140:45 + --> $DIR/needless_borrow.rs:139:45 | LL | multiple_constraints_normalizes_to_same(&X, X); | ^^ help: change this to: `X` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:141:32 + --> $DIR/needless_borrow.rs:140:32 | LL | let _ = Some("").unwrap_or(&""); | ^^^ help: change this to: `""` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:142:33 + --> $DIR/needless_borrow.rs:141:33 | LL | let _ = std::fs::write("x", &"".to_string()); | ^^^^^^^^^^^^^^^ help: change this to: `"".to_string()` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:191:13 + --> $DIR/needless_borrow.rs:190:13 | LL | (&self.f)() | ^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:200:13 + --> $DIR/needless_borrow.rs:199:13 | LL | (&mut self.f)() | ^^^^^^^^^^^^^ help: change this to: `(self.f)` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:284:20 + --> $DIR/needless_borrow.rs:283:20 | LL | takes_iter(&mut x) | ^^^^^^ help: change this to: `x` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:298:55 + --> $DIR/needless_borrow.rs:297:55 | LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); | ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:336:37 + --> $DIR/needless_borrow.rs:335:37 | LL | let _ = std::fs::write("x", &arg); | ^^^^ help: change this to: `arg` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:337:37 + --> $DIR/needless_borrow.rs:336:37 | LL | let _ = std::fs::write("x", &loc); | ^^^^ help: change this to: `loc` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:355:15 + --> $DIR/needless_borrow.rs:354:15 | LL | debug(&x); | ^^ help: change this to: `x` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:364:15 + --> $DIR/needless_borrow.rs:363:15 | LL | use_x(&x); | ^^ help: change this to: `x` error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:458:13 + --> $DIR/needless_borrow.rs:457:13 | LL | foo(&a); | ^^ help: change this to: `a` diff --git a/tests/ui/needless_borrow_pat.fixed b/tests/ui/needless_borrow_pat.fixed new file mode 100644 index 0000000000000..a9091d784a7f8 --- /dev/null +++ b/tests/ui/needless_borrow_pat.fixed @@ -0,0 +1,150 @@ +// FIXME: run-rustfix waiting on multi-span suggestions + +#![warn(clippy::needless_borrow)] +#![allow(clippy::needless_borrowed_reference, clippy::explicit_auto_deref)] + +fn f1(_: &str) {} +macro_rules! m1 { + ($e:expr) => { + f1($e) + }; +} +macro_rules! m3 { + ($i:ident) => { + Some(ref $i) + }; +} +macro_rules! if_chain { + (if $e:expr; $($rest:tt)*) => { + if $e { + if_chain!($($rest)*) + } + }; + + (if let $p:pat = $e:expr; $($rest:tt)*) => { + if let $p = $e { + if_chain!($($rest)*) + } + }; + + (then $b:block) => { + $b + }; +} + +#[allow(dead_code)] +fn main() { + let x = String::new(); + + // Ok, reference to a String. + let _: &String = match Some(x.clone()) { + Some(ref x) => x, + None => return, + }; + + // Ok, reference to a &mut String + let _: &&mut String = match Some(&mut x.clone()) { + Some(ref x) => x, + None => return, + }; + + // Ok, the pattern is from a macro + let _: &String = match Some(&x) { + m3!(x) => x, + None => return, + }; + + // Err, reference to a &String + let _: &String = match Some(&x) { + Some(x) => x, + None => return, + }; + + // Err, reference to a &String. + let _: &String = match Some(&x) { + Some(x) => x, + None => return, + }; + + // Err, reference to a &String + let _: &String = match Some(&x) { + Some(x) => { + f1(x); + f1(x); + x + }, + None => return, + }; + + // Err, reference to a &String + match Some(&x) { + Some(x) => m1!(x), + None => return, + }; + + // Err, reference to a &String + let _ = |&x: &&String| { + let _: &String = x; + }; + + // Err, reference to a &String + let (y,) = (&x,); + let _: &String = y; + + let y = &&x; + // Ok, different y + let _: &String = *y; + + let x = (0, 0); + // Err, reference to a &u32. Don't suggest adding a reference to the field access. + let _: u32 = match Some(&x) { + Some(x) => x.0, + None => return, + }; + + enum E { + A(&'static u32), + B(&'static u32), + } + // Err, reference to &u32. + let _: &u32 = match E::A(&0) { + E::A(x) | E::B(x) => x, + }; + + // Err, reference to &String. + if_chain! { + if true; + if let Some(x) = Some(&String::new()); + then { + f1(x); + } + } +} + +// Err, reference to a &String +fn f2<'a>(&x: &&'a String) -> &'a String { + let _: &String = x; + x +} + +trait T1 { + // Err, reference to a &String + fn f(&x: &&String) { + let _: &String = x; + } +} + +struct S; +impl T1 for S { + // Err, reference to a &String + fn f(&x: &&String) { + let _: &String = x; + } +} + +// 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 59a38425b0680..5d2fd0950ee41 100644 --- a/tests/ui/needless_borrowed_ref.fixed +++ b/tests/ui/needless_borrowed_ref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_borrowed_reference)] #![allow( unused, diff --git a/tests/ui/needless_borrowed_ref.rs b/tests/ui/needless_borrowed_ref.rs index e48b19cb19db8..556fd3a35427c 100644 --- a/tests/ui/needless_borrowed_ref.rs +++ b/tests/ui/needless_borrowed_ref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_borrowed_reference)] #![allow( unused, diff --git a/tests/ui/needless_borrowed_ref.stderr b/tests/ui/needless_borrowed_ref.stderr index 35497a01ec220..553b068c6b43d 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 - --> $DIR/needless_borrowed_ref.rs:32:34 + --> $DIR/needless_borrowed_ref.rs:30:34 | LL | let _ = v.iter_mut().filter(|&ref a| a.is_empty()); | ^^^^^^ @@ -12,7 +12,7 @@ LL + let _ = v.iter_mut().filter(|a| a.is_empty()); | error: this pattern takes a reference on something that is being dereferenced - --> $DIR/needless_borrowed_ref.rs:36:17 + --> $DIR/needless_borrowed_ref.rs:34:17 | LL | if let Some(&ref v) = thingy {} | ^^^^^^ @@ -24,7 +24,7 @@ LL + if let Some(v) = thingy {} | error: this pattern takes a reference on something that is being dereferenced - --> $DIR/needless_borrowed_ref.rs:38:14 + --> $DIR/needless_borrowed_ref.rs:36:14 | LL | if let &[&ref a, ref b] = slice_of_refs {} | ^^^^^^ @@ -36,7 +36,7 @@ LL + if let &[a, ref b] = slice_of_refs {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:40:9 + --> $DIR/needless_borrowed_ref.rs:38:9 | LL | let &[ref a, ..] = &array; | ^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + let [a, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:41:9 + --> $DIR/needless_borrowed_ref.rs:39:9 | LL | let &[ref a, ref b, ..] = &array; | ^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + let [a, b, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:43:12 + --> $DIR/needless_borrowed_ref.rs:41:12 | LL | if let &[ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL + if let [a, b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:44:12 + --> $DIR/needless_borrowed_ref.rs:42:12 | LL | if let &[ref a, ref b] = &vec[..] {} | ^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL + if let [a, b] = &vec[..] {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:46:12 + --> $DIR/needless_borrowed_ref.rs:44:12 | LL | if let &[ref a, ref b, ..] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + if let [a, b, ..] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:47:12 + --> $DIR/needless_borrowed_ref.rs:45:12 | LL | if let &[ref a, .., ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + if let [a, .., b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:48:12 + --> $DIR/needless_borrowed_ref.rs:46:12 | LL | if let &[.., ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL + if let [.., a, b] = slice {} | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:50:12 + --> $DIR/needless_borrowed_ref.rs:48:12 | LL | if let &[ref a, _] = slice {} | ^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL + if let [a, _] = slice {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:52:12 + --> $DIR/needless_borrowed_ref.rs:50:12 | LL | if let &(ref a, ref b, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL + if let (a, b, c) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:53:12 + --> $DIR/needless_borrowed_ref.rs:51:12 | LL | if let &(ref a, _, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL + if let (a, _, c) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:54:12 + --> $DIR/needless_borrowed_ref.rs:52:12 | LL | if let &(ref a, ..) = &tuple {} | ^^^^^^^^^^^^ @@ -168,7 +168,7 @@ LL + if let (a, ..) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:56:12 + --> $DIR/needless_borrowed_ref.rs:54:12 | LL | if let &TupleStruct(ref a, ..) = &tuple_struct {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -180,7 +180,7 @@ LL + if let TupleStruct(a, ..) = &tuple_struct {} | error: dereferencing a struct pattern where every field's pattern takes a reference - --> $DIR/needless_borrowed_ref.rs:58:12 + --> $DIR/needless_borrowed_ref.rs:56:12 | LL | if let &Struct { | ____________^ @@ -199,7 +199,7 @@ LL ~ c: renamed, | error: dereferencing a struct pattern where every field's pattern takes a reference - --> $DIR/needless_borrowed_ref.rs:65:12 + --> $DIR/needless_borrowed_ref.rs:63:12 | LL | if let &Struct { ref a, b: _, .. } = &s {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_collect.fixed b/tests/ui/needless_collect.fixed index 0f0aaad17b453..bd83581bdd975 100644 --- a/tests/ui/needless_collect.fixed +++ b/tests/ui/needless_collect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::needless_if, clippy::suspicious_map, clippy::iter_count)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList}; diff --git a/tests/ui/needless_collect.rs b/tests/ui/needless_collect.rs index 4f48f24b17b84..6a81a767bbb67 100644 --- a/tests/ui/needless_collect.rs +++ b/tests/ui/needless_collect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::needless_if, clippy::suspicious_map, clippy::iter_count)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList}; diff --git a/tests/ui/needless_collect.stderr b/tests/ui/needless_collect.stderr index ad22a7b057e0f..c24568bba9c82 100644 --- a/tests/ui/needless_collect.stderr +++ b/tests/ui/needless_collect.stderr @@ -1,5 +1,5 @@ error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:11:29 + --> $DIR/needless_collect.rs:9:29 | LL | let len = sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` @@ -7,109 +7,109 @@ LL | let len = sample.iter().collect::>().len(); = note: `-D clippy::needless-collect` implied by `-D warnings` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:12:22 + --> $DIR/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 - --> $DIR/needless_collect.rs:15:28 + --> $DIR/needless_collect.rs:13:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:20:35 + --> $DIR/needless_collect.rs:18:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:21:35 + --> $DIR/needless_collect.rs:19:35 | LL | sample.iter().map(|x| (x, x)).collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:28:19 + --> $DIR/needless_collect.rs:26:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:29:19 + --> $DIR/needless_collect.rs:27:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:30:28 + --> $DIR/needless_collect.rs:28:28 | LL | sample.iter().cloned().collect::>().contains(&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == 1)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:31:19 + --> $DIR/needless_collect.rs:29:19 | LL | sample.iter().collect::>().contains(&&1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &1)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:34:19 + --> $DIR/needless_collect.rs:32:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:35:19 + --> $DIR/needless_collect.rs:33:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:40:27 + --> $DIR/needless_collect.rs:38:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:41:27 + --> $DIR/needless_collect.rs:39:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:63:27 + --> $DIR/needless_collect.rs:61:27 | LL | let _ = sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:64:27 + --> $DIR/needless_collect.rs:62:27 | LL | let _ = sample.iter().collect::>().contains(&&0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:68:40 + --> $DIR/needless_collect.rs:66:40 | LL | Vec::::new().extend((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:69:20 + --> $DIR/needless_collect.rs:67:20 | LL | foo((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:70:49 + --> $DIR/needless_collect.rs:68:49 | LL | bar((0..10).collect::>(), (0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:71:37 + --> $DIR/needless_collect.rs:69:37 | LL | baz((0..10), (), ('a'..='z').collect::>()) | ^^^^^^^^^^^^^^^^^^^^ help: remove this call diff --git a/tests/ui/needless_collect_indirect.rs b/tests/ui/needless_collect_indirect.rs index d3d856c2c659c..1c236a601b967 100644 --- a/tests/ui/needless_collect_indirect.rs +++ b/tests/ui/needless_collect_indirect.rs @@ -1,7 +1,7 @@ #![allow(clippy::uninlined_format_args, clippy::useless_vec)] #![allow(clippy::needless_if, clippy::uninlined_format_args)] #![warn(clippy::needless_collect)] - +//@no-rustfix use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque}; fn main() { diff --git a/tests/ui/needless_else.fixed b/tests/ui/needless_else.fixed index 06a16162790cc..240b79bae13c2 100644 --- a/tests/ui/needless_else.fixed +++ b/tests/ui/needless_else.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::needless_else)] #![allow(clippy::suspicious_else_formatting)] diff --git a/tests/ui/needless_else.rs b/tests/ui/needless_else.rs index 728032c47a66b..ad84da1705357 100644 --- a/tests/ui/needless_else.rs +++ b/tests/ui/needless_else.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::needless_else)] #![allow(clippy::suspicious_else_formatting)] diff --git a/tests/ui/needless_else.stderr b/tests/ui/needless_else.stderr index 49cd78501eac2..006e4d7d30fe2 100644 --- a/tests/ui/needless_else.stderr +++ b/tests/ui/needless_else.stderr @@ -1,5 +1,5 @@ error: this `else` branch is empty - --> $DIR/needless_else.rs:24:7 + --> $DIR/needless_else.rs:23:7 | LL | } else { | _______^ diff --git a/tests/ui/needless_for_each_fixable.fixed b/tests/ui/needless_for_each_fixable.fixed index 92572942bc0d4..8c0e7ba762786 100644 --- a/tests/ui/needless_for_each_fixable.fixed +++ b/tests/ui/needless_for_each_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::needless_for_each)] #![allow(unused)] #![allow( diff --git a/tests/ui/needless_for_each_fixable.rs b/tests/ui/needless_for_each_fixable.rs index 95acbdff8cc23..cdc903a636c99 100644 --- a/tests/ui/needless_for_each_fixable.rs +++ b/tests/ui/needless_for_each_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::needless_for_each)] #![allow(unused)] #![allow( diff --git a/tests/ui/needless_for_each_fixable.stderr b/tests/ui/needless_for_each_fixable.stderr index aebb762cc2283..08e995851d7a5 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` - --> $DIR/needless_for_each_fixable.rs:16:5 + --> $DIR/needless_for_each_fixable.rs:15:5 | LL | / v.iter().for_each(|elem| { LL | | acc += elem; @@ -15,7 +15,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:19:5 + --> $DIR/needless_for_each_fixable.rs:18:5 | LL | / v.into_iter().for_each(|elem| { LL | | acc += elem; @@ -30,7 +30,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:23:5 + --> $DIR/needless_for_each_fixable.rs:22:5 | LL | / [1, 2, 3].iter().for_each(|elem| { LL | | acc += elem; @@ -45,7 +45,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:28:5 + --> $DIR/needless_for_each_fixable.rs:27:5 | LL | / hash_map.iter().for_each(|(k, v)| { LL | | acc += k + v; @@ -60,7 +60,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:31:5 + --> $DIR/needless_for_each_fixable.rs:30:5 | LL | / hash_map.iter_mut().for_each(|(k, v)| { LL | | acc += *k + *v; @@ -75,7 +75,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:34:5 + --> $DIR/needless_for_each_fixable.rs:33:5 | LL | / hash_map.keys().for_each(|k| { LL | | acc += k; @@ -90,7 +90,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:37:5 + --> $DIR/needless_for_each_fixable.rs:36:5 | LL | / hash_map.values().for_each(|v| { LL | | acc += v; @@ -105,7 +105,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:44:5 + --> $DIR/needless_for_each_fixable.rs:43:5 | LL | / my_vec().iter().for_each(|elem| { LL | | acc += elem; diff --git a/tests/ui/needless_for_each_unfixable.rs b/tests/ui/needless_for_each_unfixable.rs index 282c72881d510..588d7cb070c70 100644 --- a/tests/ui/needless_for_each_unfixable.rs +++ b/tests/ui/needless_for_each_unfixable.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::needless_for_each)] #![allow(clippy::needless_return, clippy::uninlined_format_args)] diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index 7893ff31a6fdb..9c7f3d47121d0 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -1,5 +1,5 @@ error: needless use of `for_each` - --> $DIR/needless_for_each_unfixable.rs:7:5 + --> $DIR/needless_for_each_unfixable.rs:8:5 | LL | / v.iter().for_each(|v| { LL | | if *v == 10 { diff --git a/tests/ui/needless_if.fixed b/tests/ui/needless_if.fixed index 6001c9e93011a..35220e5b3c6e6 100644 --- a/tests/ui/needless_if.fixed +++ b/tests/ui/needless_if.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(let_chains)] #![allow( diff --git a/tests/ui/needless_if.rs b/tests/ui/needless_if.rs index c6be4766dd8a1..29d3bf77af89d 100644 --- a/tests/ui/needless_if.rs +++ b/tests/ui/needless_if.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(let_chains)] #![allow( diff --git a/tests/ui/needless_if.stderr b/tests/ui/needless_if.stderr index 14de400953bd6..bf131f2d7e4b4 100644 --- a/tests/ui/needless_if.stderr +++ b/tests/ui/needless_if.stderr @@ -1,5 +1,5 @@ error: this `if` branch is empty - --> $DIR/needless_if.rs:27:5 + --> $DIR/needless_if.rs:26:5 | LL | if (true) {} | ^^^^^^^^^^^^ help: you can remove it @@ -7,13 +7,13 @@ LL | if (true) {} = note: `-D clippy::needless-if` implied by `-D warnings` error: this `if` branch is empty - --> $DIR/needless_if.rs:29:5 + --> $DIR/needless_if.rs:28:5 | LL | if maybe_side_effect() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `maybe_side_effect();` error: this `if` branch is empty - --> $DIR/needless_if.rs:34:5 + --> $DIR/needless_if.rs:33:5 | LL | / if { LL | | return; @@ -28,7 +28,7 @@ LL + }); | error: this `if` branch is empty - --> $DIR/needless_if.rs:46:5 + --> $DIR/needless_if.rs:45:5 | LL | / if { LL | | if let true = true && true { true } else { false } @@ -44,19 +44,19 @@ LL + } && true); | error: this `if` branch is empty - --> $DIR/needless_if.rs:84:5 + --> $DIR/needless_if.rs:83:5 | LL | if { maybe_side_effect() } {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() });` error: this `if` branch is empty - --> $DIR/needless_if.rs:86:5 + --> $DIR/needless_if.rs:85:5 | LL | if { maybe_side_effect() } && true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() } && true);` error: this `if` branch is empty - --> $DIR/needless_if.rs:90:5 + --> $DIR/needless_if.rs:89:5 | LL | if true {} | ^^^^^^^^^^ help: you can remove it: `true;` diff --git a/tests/ui/needless_late_init.fixed b/tests/ui/needless_late_init.fixed index 933dd8bed2a26..0504bc2bd3705 100644 --- a/tests/ui/needless_late_init.fixed +++ b/tests/ui/needless_late_init.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(let_chains)] #![allow(unused)] diff --git a/tests/ui/needless_late_init.rs b/tests/ui/needless_late_init.rs index ba3a04e0825eb..7346a9ea3b50a 100644 --- a/tests/ui/needless_late_init.rs +++ b/tests/ui/needless_late_init.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(let_chains)] #![allow(unused)] diff --git a/tests/ui/needless_late_init.stderr b/tests/ui/needless_late_init.stderr index 78ba8e11c575c..eff782f8bf104 100644 --- a/tests/ui/needless_late_init.stderr +++ b/tests/ui/needless_late_init.stderr @@ -1,5 +1,5 @@ error: unneeded late initialization - --> $DIR/needless_late_init.rs:28:5 + --> $DIR/needless_late_init.rs:27:5 | LL | let a; | ^^^^^^ created here @@ -13,7 +13,7 @@ LL | let a = "zero"; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:31:5 + --> $DIR/needless_late_init.rs:30:5 | LL | let b; | ^^^^^^ created here @@ -27,7 +27,7 @@ LL | let b = 1; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:32:5 + --> $DIR/needless_late_init.rs:31:5 | LL | let c; | ^^^^^^ created here @@ -41,7 +41,7 @@ LL | let c = 2; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:36:5 + --> $DIR/needless_late_init.rs:35:5 | LL | let d: usize; | ^^^^^^^^^^^^^ created here @@ -54,7 +54,7 @@ LL | let d: usize = 1; | ~~~~~~~~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:39:5 + --> $DIR/needless_late_init.rs:38:5 | LL | let e; | ^^^^^^ created here @@ -67,7 +67,7 @@ LL | let e = format!("{}", d); | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:44:5 + --> $DIR/needless_late_init.rs:43:5 | LL | let a; | ^^^^^^ @@ -88,7 +88,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:53:5 + --> $DIR/needless_late_init.rs:52:5 | LL | let b; | ^^^^^^ @@ -109,7 +109,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:60:5 + --> $DIR/needless_late_init.rs:59:5 | LL | let d; | ^^^^^^ @@ -130,7 +130,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:68:5 + --> $DIR/needless_late_init.rs:67:5 | LL | let e; | ^^^^^^ @@ -151,7 +151,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:75:5 + --> $DIR/needless_late_init.rs:74:5 | LL | let f; | ^^^^^^ @@ -167,7 +167,7 @@ LL + 1 => "three", | error: unneeded late initialization - --> $DIR/needless_late_init.rs:81:5 + --> $DIR/needless_late_init.rs:80:5 | LL | let g: usize; | ^^^^^^^^^^^^^ @@ -187,7 +187,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:89:5 + --> $DIR/needless_late_init.rs:88:5 | LL | let x; | ^^^^^^ created here @@ -201,7 +201,7 @@ LL | let x = 1; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:93:5 + --> $DIR/needless_late_init.rs:92:5 | LL | let x; | ^^^^^^ created here @@ -215,7 +215,7 @@ LL | let x = SignificantDrop; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:97:5 + --> $DIR/needless_late_init.rs:96:5 | LL | let x; | ^^^^^^ created here @@ -229,7 +229,7 @@ LL | let x = SignificantDrop; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:116:5 + --> $DIR/needless_late_init.rs:115:5 | LL | let a; | ^^^^^^ @@ -250,7 +250,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:133:5 + --> $DIR/needless_late_init.rs:132:5 | LL | let a; | ^^^^^^ diff --git a/tests/ui/needless_lifetimes.fixed b/tests/ui/needless_lifetimes.fixed index 302a3f9edbecb..cde78c318ed78 100644 --- a/tests/ui/needless_lifetimes.fixed +++ b/tests/ui/needless_lifetimes.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::needless_lifetimes)] diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index b15477c92e814..eabfa48b4cf78 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::needless_lifetimes)] diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index 0da67b600a3f5..23b9cbe3f8589 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 - --> $DIR/needless_lifetimes.rs:18:23 + --> $DIR/needless_lifetimes.rs:17:23 | LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} | ^^ ^^ ^^ ^^ @@ -12,7 +12,7 @@ LL + fn distinct_lifetimes(_x: &u8, _y: &u8, _z: u8) {} | error: the following explicit lifetimes could be elided: 'a, 'b - --> $DIR/needless_lifetimes.rs:20:24 + --> $DIR/needless_lifetimes.rs:19:24 | LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} | ^^ ^^ ^^ ^^ @@ -24,7 +24,7 @@ LL + fn distinct_and_static(_x: &u8, _y: &u8, _z: &'static u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:30:15 + --> $DIR/needless_lifetimes.rs:29:15 | LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { | ^^ ^^ ^^ @@ -36,7 +36,7 @@ LL + fn in_and_out(x: &u8, _y: u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'b - --> $DIR/needless_lifetimes.rs:42:31 + --> $DIR/needless_lifetimes.rs:41:31 | LL | fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { | ^^ ^^ @@ -48,7 +48,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 - --> $DIR/needless_lifetimes.rs:49:27 + --> $DIR/needless_lifetimes.rs:48:27 | LL | fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 { | ^^ ^^ @@ -60,7 +60,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 - --> $DIR/needless_lifetimes.rs:66:26 + --> $DIR/needless_lifetimes.rs:65:26 | LL | fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { | ^^ ^^ @@ -72,7 +72,7 @@ LL + fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:73:22 + --> $DIR/needless_lifetimes.rs:72:22 | LL | fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> { | ^^ ^^ @@ -84,7 +84,7 @@ LL + fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:82:21 + --> $DIR/needless_lifetimes.rs:81:21 | LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { | ^^ ^^ ^^ @@ -96,7 +96,7 @@ LL + fn deep_reference_3(x: &u8, _y: u8) -> Result<&u8, ()> { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:87:28 + --> $DIR/needless_lifetimes.rs:86:28 | LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> | ^^ ^^ ^^ @@ -108,7 +108,7 @@ LL + fn where_clause_without_lt(x: &u8, _y: u8) -> Result<&u8, ()> | error: the following explicit lifetimes could be elided: 'a, 'b - --> $DIR/needless_lifetimes.rs:99:21 + --> $DIR/needless_lifetimes.rs:98:21 | LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} | ^^ ^^ ^^ ^^ @@ -120,7 +120,7 @@ LL + fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:123:15 + --> $DIR/needless_lifetimes.rs:122:15 | LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> | ^^ ^^ ^^ @@ -132,7 +132,7 @@ LL + fn fn_bound_2(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> | error: the following explicit lifetimes could be elided: 's - --> $DIR/needless_lifetimes.rs:153:21 + --> $DIR/needless_lifetimes.rs:152:21 | LL | fn self_and_out<'s>(&'s self) -> &'s u8 { | ^^ ^^ ^^ @@ -144,7 +144,7 @@ LL + fn self_and_out(&self) -> &u8 { | error: the following explicit lifetimes could be elided: 't - --> $DIR/needless_lifetimes.rs:160:30 + --> $DIR/needless_lifetimes.rs:159:30 | LL | fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { | ^^ ^^ @@ -156,7 +156,7 @@ LL + fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8 { | error: the following explicit lifetimes could be elided: 's - --> $DIR/needless_lifetimes.rs:167:26 + --> $DIR/needless_lifetimes.rs:166:26 | LL | fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 { | ^^ ^^ @@ -168,7 +168,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 - --> $DIR/needless_lifetimes.rs:171:29 + --> $DIR/needless_lifetimes.rs:170:29 | LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} | ^^ ^^ ^^ ^^ @@ -180,7 +180,7 @@ LL + fn distinct_self_and_in(&self, _x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:190:19 + --> $DIR/needless_lifetimes.rs:189:19 | LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { | ^^ ^^ ^^ @@ -192,7 +192,7 @@ LL + fn struct_with_lt(_foo: Foo<'_>) -> &str { | error: the following explicit lifetimes could be elided: 'b - --> $DIR/needless_lifetimes.rs:208:25 + --> $DIR/needless_lifetimes.rs:207:25 | LL | fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { | ^^ ^^ @@ -204,7 +204,7 @@ LL + fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:216:21 + --> $DIR/needless_lifetimes.rs:215:21 | LL | fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str { | ^^ ^^ @@ -216,7 +216,7 @@ LL + fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:231:22 + --> $DIR/needless_lifetimes.rs:230:22 | LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { | ^^ ^^ ^^ @@ -228,7 +228,7 @@ LL + fn trait_obj_elided2(_arg: &dyn Drop) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:237:18 + --> $DIR/needless_lifetimes.rs:236:18 | LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { | ^^ ^^ ^^ @@ -240,7 +240,7 @@ LL + fn alias_with_lt(_foo: FooAlias<'_>) -> &str { | error: the following explicit lifetimes could be elided: 'b - --> $DIR/needless_lifetimes.rs:255:24 + --> $DIR/needless_lifetimes.rs:254:24 | LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { | ^^ ^^ @@ -252,7 +252,7 @@ LL + fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:263:20 + --> $DIR/needless_lifetimes.rs:262:20 | LL | fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str { | ^^ ^^ @@ -264,7 +264,7 @@ LL + fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:267:30 + --> $DIR/needless_lifetimes.rs:266:30 | LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { | ^^ ^^ ^ @@ -276,7 +276,7 @@ LL + fn named_input_elided_output(_arg: &str) -> &str { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:275:19 + --> $DIR/needless_lifetimes.rs:274:19 | LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { | ^^ ^^ @@ -288,7 +288,7 @@ LL + fn trait_bound_ok>(_: &u8, _: T) { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:311:24 + --> $DIR/needless_lifetimes.rs:310:24 | LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { | ^^ ^^ ^^ @@ -300,7 +300,7 @@ LL + fn out_return_type_lts(e: &str) -> Cow<'_> { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:318:24 + --> $DIR/needless_lifetimes.rs:317:24 | LL | fn needless_lt<'a>(x: &'a u8) {} | ^^ ^^ @@ -312,7 +312,7 @@ LL + fn needless_lt(x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:322:24 + --> $DIR/needless_lifetimes.rs:321:24 | LL | fn needless_lt<'a>(_x: &'a u8) {} | ^^ ^^ @@ -324,7 +324,7 @@ LL + fn needless_lt(_x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:335:16 + --> $DIR/needless_lifetimes.rs:334:16 | LL | fn baz<'a>(&'a self) -> impl Foo + 'a { | ^^ ^^ ^^ @@ -336,7 +336,7 @@ LL + fn baz(&self) -> impl Foo + '_ { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:367:55 + --> $DIR/needless_lifetimes.rs:366:55 | LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -348,7 +348,7 @@ LL + fn impl_trait_elidable_nested_anonymous_lifetimes(i: &i32, f: impl Fn(& | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:376:26 + --> $DIR/needless_lifetimes.rs:375:26 | LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { | ^^ ^^ ^^ @@ -360,7 +360,7 @@ LL + fn generics_elidable &i32>(i: &i32, f: T) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:388:32 + --> $DIR/needless_lifetimes.rs:387:32 | LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 | ^^ ^^ ^^ @@ -372,7 +372,7 @@ LL + fn where_clause_elidadable(i: &i32, f: T) -> &i32 | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:403:28 + --> $DIR/needless_lifetimes.rs:402:28 | LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -384,7 +384,7 @@ LL + fn pointer_fn_elidable(i: &i32, f: fn(&i32) -> &i32) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:416:28 + --> $DIR/needless_lifetimes.rs:415:28 | LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { | ^^ ^^ @@ -396,7 +396,7 @@ LL + fn nested_fn_pointer_3(_: &i32) -> fn(fn(&i32) -> &i32) -> i32 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:419:28 + --> $DIR/needless_lifetimes.rs:418:28 | LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { | ^^ ^^ @@ -408,7 +408,7 @@ LL + fn nested_fn_pointer_4(_: &i32) -> impl Fn(fn(&i32)) { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:441:21 + --> $DIR/needless_lifetimes.rs:440:21 | LL | fn implicit<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -420,7 +420,7 @@ LL + fn implicit(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:444:25 + --> $DIR/needless_lifetimes.rs:443:25 | LL | fn implicit_mut<'a>(&'a mut self) -> &'a () { | ^^ ^^ ^^ @@ -432,7 +432,7 @@ LL + fn implicit_mut(&mut self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:455:31 + --> $DIR/needless_lifetimes.rs:454:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -444,7 +444,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:461:21 + --> $DIR/needless_lifetimes.rs:460:21 | LL | fn implicit<'a>(&'a self) -> &'a (); | ^^ ^^ ^^ @@ -456,7 +456,7 @@ LL + fn implicit(&self) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:462:30 + --> $DIR/needless_lifetimes.rs:461:30 | LL | fn implicit_provided<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -468,7 +468,7 @@ LL + fn implicit_provided(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:471:31 + --> $DIR/needless_lifetimes.rs:470:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a (); | ^^ ^^ ^^ @@ -480,7 +480,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:472:40 + --> $DIR/needless_lifetimes.rs:471:40 | LL | fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -492,7 +492,7 @@ LL + fn lifetime_elsewhere_provided(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:481:12 + --> $DIR/needless_lifetimes.rs:480:12 | LL | fn foo<'a>(x: &'a u8, y: &'_ u8) {} | ^^ ^^ @@ -504,7 +504,7 @@ LL + fn foo(x: &u8, y: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:483:12 + --> $DIR/needless_lifetimes.rs:482:12 | LL | fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {} | ^^ ^^ @@ -516,7 +516,7 @@ LL + fn bar(x: &u8, y: &'_ u8, z: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:490:18 + --> $DIR/needless_lifetimes.rs:489:18 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ @@ -528,7 +528,7 @@ LL + fn one_input(x: &u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:495:42 + --> $DIR/needless_lifetimes.rs:494:42 | LL | fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { | ^^ ^^ @@ -540,7 +540,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 - --> $DIR/needless_lifetimes.rs:511:22 + --> $DIR/needless_lifetimes.rs:510: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 d8a0400a4f0d5..a936eb463f964 100644 --- a/tests/ui/needless_match.fixed +++ b/tests/ui/needless_match.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::needless_match)] #![allow(clippy::manual_map)] #![allow(dead_code)] diff --git a/tests/ui/needless_match.rs b/tests/ui/needless_match.rs index 3de9bd6d7a1f0..b1dd6ff075d88 100644 --- a/tests/ui/needless_match.rs +++ b/tests/ui/needless_match.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::needless_match)] #![allow(clippy::manual_map)] #![allow(dead_code)] diff --git a/tests/ui/needless_match.stderr b/tests/ui/needless_match.stderr index 28e78441c2522..6ae2f38bf5009 100644 --- a/tests/ui/needless_match.stderr +++ b/tests/ui/needless_match.stderr @@ -1,5 +1,5 @@ error: this match expression is unnecessary - --> $DIR/needless_match.rs:16:18 + --> $DIR/needless_match.rs:15:18 | LL | let _: i32 = match i { | __________________^ @@ -13,7 +13,7 @@ LL | | }; = note: `-D clippy::needless-match` implied by `-D warnings` error: this match expression is unnecessary - --> $DIR/needless_match.rs:23:19 + --> $DIR/needless_match.rs:22:19 | LL | let _: &str = match s { | ___________________^ @@ -24,7 +24,7 @@ LL | | }; | |_____^ help: replace it with: `s` error: this match expression is unnecessary - --> $DIR/needless_match.rs:32:21 + --> $DIR/needless_match.rs:31:21 | LL | let _: Simple = match se { | _____________________^ @@ -36,7 +36,7 @@ LL | | }; | |_____^ help: replace it with: `se` error: this match expression is unnecessary - --> $DIR/needless_match.rs:54:26 + --> $DIR/needless_match.rs:53:26 | LL | let _: Option = match x { | __________________________^ @@ -46,7 +46,7 @@ LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> $DIR/needless_match.rs:70:31 + --> $DIR/needless_match.rs:69:31 | LL | let _: Result = match Ok(1) { | _______________________________^ @@ -56,7 +56,7 @@ LL | | }; | |_____^ help: replace it with: `Ok(1)` error: this match expression is unnecessary - --> $DIR/needless_match.rs:74:31 + --> $DIR/needless_match.rs:73:31 | LL | let _: Result = match func_ret_err(0_i32) { | _______________________________^ @@ -66,25 +66,25 @@ LL | | }; | |_____^ help: replace it with: `func_ret_err(0_i32)` error: this if-let expression is unnecessary - --> $DIR/needless_match.rs:87:13 + --> $DIR/needless_match.rs:86: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 - --> $DIR/needless_match.rs:122:31 + --> $DIR/needless_match.rs:121: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 - --> $DIR/needless_match.rs:123:31 + --> $DIR/needless_match.rs:122: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 - --> $DIR/needless_match.rs:130:21 + --> $DIR/needless_match.rs:129:21 | LL | let _: Simple = if let Simple::A = x { | _____________________^ @@ -97,7 +97,7 @@ LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> $DIR/needless_match.rs:169:26 + --> $DIR/needless_match.rs:168:26 | LL | let _: Complex = match ce { | __________________________^ @@ -110,7 +110,7 @@ LL | | }; | |_________^ help: replace it with: `ce` error: this match expression is unnecessary - --> $DIR/needless_match.rs:253:17 + --> $DIR/needless_match.rs:252:17 | LL | let _ = match e { | _________________^ @@ -120,7 +120,7 @@ LL | | }; | |_________^ help: replace it with: `e` error: this match expression is unnecessary - --> $DIR/needless_match.rs:259:17 + --> $DIR/needless_match.rs:258:17 | LL | let _ = match e { | _________________^ diff --git a/tests/ui/needless_option_as_deref.fixed b/tests/ui/needless_option_as_deref.fixed index ec981ad97e3d3..58f56eba0f539 100644 --- a/tests/ui/needless_option_as_deref.fixed +++ b/tests/ui/needless_option_as_deref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::needless_option_as_deref)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/needless_option_as_deref.rs b/tests/ui/needless_option_as_deref.rs index 6360874f62365..842e025f669b9 100644 --- a/tests/ui/needless_option_as_deref.rs +++ b/tests/ui/needless_option_as_deref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::needless_option_as_deref)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/needless_option_as_deref.stderr b/tests/ui/needless_option_as_deref.stderr index 4c0d502a20313..94be76a9a45ec 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 - --> $DIR/needless_option_as_deref.rs:9:29 + --> $DIR/needless_option_as_deref.rs:7:29 | LL | let _: Option<&usize> = Some(&1).as_deref(); | ^^^^^^^^^^^^^^^^^^^ help: try: `Some(&1)` @@ -7,13 +7,13 @@ LL | let _: Option<&usize> = Some(&1).as_deref(); = note: `-D clippy::needless-option-as-deref` implied by `-D warnings` error: derefed type is same as origin - --> $DIR/needless_option_as_deref.rs:10:33 + --> $DIR/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 - --> $DIR/needless_option_as_deref.rs:14:13 + --> $DIR/needless_option_as_deref.rs:12:13 | LL | let _ = x.as_deref_mut(); | ^^^^^^^^^^^^^^^^ help: try: `x` diff --git a/tests/ui/needless_option_take.fixed b/tests/ui/needless_option_take.fixed index bfc6d20d5a326..d732a2686cb9d 100644 --- a/tests/ui/needless_option_take.fixed +++ b/tests/ui/needless_option_take.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - fn main() { println!("Testing non erroneous option_take_on_temporary"); let mut option = Some(1); diff --git a/tests/ui/needless_option_take.rs b/tests/ui/needless_option_take.rs index 697eeab42074e..f947d874e064b 100644 --- a/tests/ui/needless_option_take.rs +++ b/tests/ui/needless_option_take.rs @@ -1,5 +1,3 @@ -//@run-rustfix - fn main() { println!("Testing non erroneous option_take_on_temporary"); let mut option = Some(1); diff --git a/tests/ui/needless_option_take.stderr b/tests/ui/needless_option_take.stderr index cb3bf015b369d..b6b50d6f2ff6e 100644 --- a/tests/ui/needless_option_take.stderr +++ b/tests/ui/needless_option_take.stderr @@ -1,5 +1,5 @@ error: called `Option::take()` on a temporary value - --> $DIR/needless_option_take.rs:14:5 + --> $DIR/needless_option_take.rs:12:5 | LL | x.as_ref().take(); | ^^^^^^^^^^^^^^^^^ help: try: `x.as_ref()` diff --git a/tests/ui/needless_parens_on_range_literals.fixed b/tests/ui/needless_parens_on_range_literals.fixed index 9b98f6ea7f799..b4d9e3297c491 100644 --- a/tests/ui/needless_parens_on_range_literals.fixed +++ b/tests/ui/needless_parens_on_range_literals.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 #![warn(clippy::needless_parens_on_range_literals)] diff --git a/tests/ui/needless_parens_on_range_literals.rs b/tests/ui/needless_parens_on_range_literals.rs index 088e7b2b98f0f..2f0e54f80d85a 100644 --- a/tests/ui/needless_parens_on_range_literals.rs +++ b/tests/ui/needless_parens_on_range_literals.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 #![warn(clippy::needless_parens_on_range_literals)] diff --git a/tests/ui/needless_parens_on_range_literals.stderr b/tests/ui/needless_parens_on_range_literals.stderr index 505f7ac916dda..0fe331ecc7546 100644 --- a/tests/ui/needless_parens_on_range_literals.stderr +++ b/tests/ui/needless_parens_on_range_literals.stderr @@ -1,5 +1,5 @@ error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:8:13 + --> $DIR/needless_parens_on_range_literals.rs:7:13 | LL | let _ = ('a')..=('z'); | ^^^^^ help: try: `'a'` @@ -7,31 +7,31 @@ LL | let _ = ('a')..=('z'); = note: `-D clippy::needless-parens-on-range-literals` implied by `-D warnings` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:8:21 + --> $DIR/needless_parens_on_range_literals.rs:7:21 | LL | let _ = ('a')..=('z'); | ^^^^^ help: try: `'z'` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:9:18 + --> $DIR/needless_parens_on_range_literals.rs:8:18 | LL | let _ = 'a'..('z'); | ^^^^^ help: try: `'z'` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:11:19 + --> $DIR/needless_parens_on_range_literals.rs:10:19 | LL | let _ = (1.)..(2.); | ^^^^ help: try: `2.` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:12:13 + --> $DIR/needless_parens_on_range_literals.rs:11:13 | LL | let _ = ('a')..; | ^^^^^ help: try: `'a'` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:13:15 + --> $DIR/needless_parens_on_range_literals.rs:12:15 | LL | let _ = ..('z'); | ^^^^^ help: try: `'z'` diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index ae7b018d0e256..13f62db3ecf67 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -1,6 +1,6 @@ #![allow(clippy::if_same_then_else, clippy::no_effect)] #![feature(lint_reasons)] - +//@no-rustfix use std::ptr::NonNull; fn foo(s: &mut Vec, b: &u32, x: &mut u32) { diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index d79ad86b1948c..ce4bc9286bef0 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -7,7 +7,7 @@ clippy::single_match, clippy::uninlined_format_args )] - +//@no-rustfix use std::borrow::Borrow; use std::collections::HashSet; use std::convert::AsRef; diff --git a/tests/ui/needless_pub_self.fixed b/tests/ui/needless_pub_self.fixed index 672b4c318a8da..b9eb9b1b0c14a 100644 --- a/tests/ui/needless_pub_self.fixed +++ b/tests/ui/needless_pub_self.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + //@aux-build:proc_macros.rs:proc-macro #![feature(custom_inner_attributes)] #![allow(unused)] diff --git a/tests/ui/needless_pub_self.rs b/tests/ui/needless_pub_self.rs index 5ac1edf8e9907..6f231aa75d877 100644 --- a/tests/ui/needless_pub_self.rs +++ b/tests/ui/needless_pub_self.rs @@ -1,4 +1,4 @@ -//@run-rustfix + //@aux-build:proc_macros.rs:proc-macro #![feature(custom_inner_attributes)] #![allow(unused)] diff --git a/tests/ui/needless_question_mark.fixed b/tests/ui/needless_question_mark.fixed index 679b73d404a65..07bd6b6f3c1e2 100644 --- a/tests/ui/needless_question_mark.fixed +++ b/tests/ui/needless_question_mark.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_question_mark)] #![allow( clippy::needless_return, diff --git a/tests/ui/needless_question_mark.rs b/tests/ui/needless_question_mark.rs index a993d3ec35d85..fbf8a12fd5044 100644 --- a/tests/ui/needless_question_mark.rs +++ b/tests/ui/needless_question_mark.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_question_mark)] #![allow( clippy::needless_return, diff --git a/tests/ui/needless_question_mark.stderr b/tests/ui/needless_question_mark.stderr index d1f89e326c67c..3e1d2c17c3013 100644 --- a/tests/ui/needless_question_mark.stderr +++ b/tests/ui/needless_question_mark.stderr @@ -1,5 +1,5 @@ error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:22:12 + --> $DIR/needless_question_mark.rs:20:12 | LL | return Some(to.magic?); | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` @@ -7,67 +7,67 @@ LL | return Some(to.magic?); = note: `-D clippy::needless-question-mark` implied by `-D warnings` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:30:12 + --> $DIR/needless_question_mark.rs:28:12 | LL | return Some(to.magic?) | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:35:5 + --> $DIR/needless_question_mark.rs:33:5 | LL | Some(to.magic?) | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:40:21 + --> $DIR/needless_question_mark.rs:38:21 | LL | to.and_then(|t| Some(t.magic?)) | ^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:49:9 + --> $DIR/needless_question_mark.rs:47:9 | LL | Some(t.magic?) | ^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:54:12 + --> $DIR/needless_question_mark.rs:52:12 | LL | return Ok(tr.magic?); | ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:61:12 + --> $DIR/needless_question_mark.rs:59:12 | LL | return Ok(tr.magic?) | ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:65:5 + --> $DIR/needless_question_mark.rs:63:5 | LL | Ok(tr.magic?) | ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:69:21 + --> $DIR/needless_question_mark.rs:67:21 | LL | tr.and_then(|t| Ok(t.magic?)) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:77:9 + --> $DIR/needless_question_mark.rs:75:9 | LL | Ok(t.magic?) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:84:16 + --> $DIR/needless_question_mark.rs:82:16 | LL | return Ok(t.magic?); | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:119:27 + --> $DIR/needless_question_mark.rs:117:27 | LL | || -> Option<_> { Some(Some($expr)?) }() | ^^^^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `Some($expr)` @@ -78,13 +78,13 @@ LL | let _x = some_and_qmark_in_macro!(x?); = note: this error originates in the macro `some_and_qmark_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:130:5 + --> $DIR/needless_question_mark.rs:128:5 | LL | Some(to.magic?) | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:138:5 + --> $DIR/needless_question_mark.rs:136:5 | LL | Ok(s.magic?) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `s.magic` diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs index a16ef5a5bca95..7457a93c5f559 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -4,7 +4,7 @@ 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]; const MAX_LEN: usize = 42; diff --git a/tests/ui/needless_range_loop2.rs b/tests/ui/needless_range_loop2.rs index 516d99a3532af..66cd15401f922 100644 --- a/tests/ui/needless_range_loop2.rs +++ b/tests/ui/needless_range_loop2.rs @@ -1,6 +1,6 @@ #![warn(clippy::needless_range_loop)] #![allow(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 b36912efbb2d4..4db375178b4f2 100644 --- a/tests/ui/needless_raw_string.fixed +++ b/tests/ui/needless_raw_string.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::needless_raw_strings)] #![feature(c_str_literals)] diff --git a/tests/ui/needless_raw_string.rs b/tests/ui/needless_raw_string.rs index 8f48e7dab2a6e..59c75fda41bef 100644 --- a/tests/ui/needless_raw_string.rs +++ b/tests/ui/needless_raw_string.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::needless_raw_strings)] #![feature(c_str_literals)] diff --git a/tests/ui/needless_raw_string.stderr b/tests/ui/needless_raw_string.stderr index cfb07b647d7c6..ddc36af2e724c 100644 --- a/tests/ui/needless_raw_string.stderr +++ b/tests/ui/needless_raw_string.stderr @@ -1,5 +1,5 @@ error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:7:5 + --> $DIR/needless_raw_string.rs:6:5 | LL | r#"aaa"#; | ^^^^^^^^ help: try: `"aaa"` @@ -7,7 +7,7 @@ LL | r#"aaa"#; = note: `-D clippy::needless-raw-strings` implied by `-D warnings` error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:10:5 + --> $DIR/needless_raw_string.rs:9:5 | LL | br#"aaa"#; | ^^^^^^^^^ help: try: `b"aaa"` diff --git a/tests/ui/needless_raw_string_hashes.fixed b/tests/ui/needless_raw_string_hashes.fixed index c8507c7271513..84902157ab4fc 100644 --- a/tests/ui/needless_raw_string_hashes.fixed +++ b/tests/ui/needless_raw_string_hashes.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::no_effect, unused)] #![warn(clippy::needless_raw_string_hashes)] #![feature(c_str_literals)] diff --git a/tests/ui/needless_raw_string_hashes.rs b/tests/ui/needless_raw_string_hashes.rs index 912fbde1679db..62abae8385926 100644 --- a/tests/ui/needless_raw_string_hashes.rs +++ b/tests/ui/needless_raw_string_hashes.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::no_effect, unused)] #![warn(clippy::needless_raw_string_hashes)] #![feature(c_str_literals)] diff --git a/tests/ui/needless_raw_string_hashes.stderr b/tests/ui/needless_raw_string_hashes.stderr index 30e6783a38e8b..9649d59a71fcd 100644 --- a/tests/ui/needless_raw_string_hashes.stderr +++ b/tests/ui/needless_raw_string_hashes.stderr @@ -1,5 +1,5 @@ error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:8:5 + --> $DIR/needless_raw_string_hashes.rs:7:5 | LL | r##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `r#"Hello "world"!"#` @@ -7,31 +7,31 @@ LL | r##"Hello "world"!"##; = note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings` error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:9:5 + --> $DIR/needless_raw_string_hashes.rs:8:5 | LL | r######" "### "## "# "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r####" "### "## "# "####` error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:10:5 + --> $DIR/needless_raw_string_hashes.rs:9:5 | LL | r######" "aa" "# "## "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r###" "aa" "# "## "###` error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:12:5 + --> $DIR/needless_raw_string_hashes.rs:11:5 | LL | br##"Hello "world"!"##; | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `br#"Hello "world"!"#` error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:13:5 + --> $DIR/needless_raw_string_hashes.rs:12:5 | LL | br######" "### "## "# "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `br####" "### "## "# "####` error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:14:5 + --> $DIR/needless_raw_string_hashes.rs:13:5 | LL | br######" "aa" "# "## "######; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `br###" "aa" "# "## "###` diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index 4dabf313963de..f9eb39d49382c 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lint_reasons)] #![feature(yeet_expr)] #![allow(unused)] diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index 542f562b31496..4dd2e22ea9fe6 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lint_reasons)] #![feature(yeet_expr)] #![allow(unused)] diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index 1d9d23d30083c..eea9a5ff9cf24 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -1,5 +1,5 @@ error: unneeded `return` statement - --> $DIR/needless_return.rs:28:5 + --> $DIR/needless_return.rs:26:5 | LL | return true; | ^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:32:5 + --> $DIR/needless_return.rs:30:5 | LL | return true; | ^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:37:5 + --> $DIR/needless_return.rs:35:5 | LL | return true;;; | ^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:42:5 + --> $DIR/needless_return.rs:40:5 | LL | return true;; ; ; | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:47:9 + --> $DIR/needless_return.rs:45:9 | LL | return true; | ^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:49:9 + --> $DIR/needless_return.rs:47:9 | LL | return false; | ^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL + false | error: unneeded `return` statement - --> $DIR/needless_return.rs:55:17 + --> $DIR/needless_return.rs:53:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:57:13 + --> $DIR/needless_return.rs:55:13 | LL | return true; | ^^^^^^^^^^^ @@ -95,7 +95,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:64:9 + --> $DIR/needless_return.rs:62:9 | LL | return true; | ^^^^^^^^^^^ @@ -107,7 +107,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:66:16 + --> $DIR/needless_return.rs:64:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:70:5 + --> $DIR/needless_return.rs:68:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -130,7 +130,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> $DIR/needless_return.rs:73:21 + --> $DIR/needless_return.rs:71:21 | LL | fn test_void_fun() { | _____________________^ @@ -145,7 +145,7 @@ LL + fn test_void_fun() { | error: unneeded `return` statement - --> $DIR/needless_return.rs:78:11 + --> $DIR/needless_return.rs:76:11 | LL | if b { | ___________^ @@ -160,7 +160,7 @@ LL + if b { | error: unneeded `return` statement - --> $DIR/needless_return.rs:80:13 + --> $DIR/needless_return.rs:78:13 | LL | } else { | _____________^ @@ -175,7 +175,7 @@ LL + } else { | error: unneeded `return` statement - --> $DIR/needless_return.rs:88:14 + --> $DIR/needless_return.rs:86:14 | LL | _ => return, | ^^^^^^ @@ -186,7 +186,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:96:24 + --> $DIR/needless_return.rs:94:24 | LL | let _ = 42; | ________________________^ @@ -201,7 +201,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> $DIR/needless_return.rs:99:14 + --> $DIR/needless_return.rs:97:14 | LL | _ => return, | ^^^^^^ @@ -212,7 +212,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:112:9 + --> $DIR/needless_return.rs:110:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -224,7 +224,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> $DIR/needless_return.rs:114:9 + --> $DIR/needless_return.rs:112:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -236,7 +236,7 @@ LL + String::new() | error: unneeded `return` statement - --> $DIR/needless_return.rs:136:32 + --> $DIR/needless_return.rs:134:32 | LL | bar.unwrap_or_else(|_| return) | ^^^^^^ @@ -247,7 +247,7 @@ LL | bar.unwrap_or_else(|_| {}) | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:140:21 + --> $DIR/needless_return.rs:138:21 | LL | let _ = || { | _____________________^ @@ -262,7 +262,7 @@ LL + let _ = || { | error: unneeded `return` statement - --> $DIR/needless_return.rs:143:20 + --> $DIR/needless_return.rs:141:20 | LL | let _ = || return; | ^^^^^^ @@ -273,7 +273,7 @@ LL | let _ = || {}; | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:149:32 + --> $DIR/needless_return.rs:147:32 | LL | res.unwrap_or_else(|_| return Foo) | ^^^^^^^^^^ @@ -284,7 +284,7 @@ LL | res.unwrap_or_else(|_| Foo) | ~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:158:5 + --> $DIR/needless_return.rs:156:5 | LL | return true; | ^^^^^^^^^^^ @@ -296,7 +296,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:162:5 + --> $DIR/needless_return.rs:160:5 | LL | return true; | ^^^^^^^^^^^ @@ -308,7 +308,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:167:9 + --> $DIR/needless_return.rs:165:9 | LL | return true; | ^^^^^^^^^^^ @@ -320,7 +320,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:169:9 + --> $DIR/needless_return.rs:167:9 | LL | return false; | ^^^^^^^^^^^^ @@ -332,7 +332,7 @@ LL + false | error: unneeded `return` statement - --> $DIR/needless_return.rs:175:17 + --> $DIR/needless_return.rs:173:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -343,7 +343,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:177:13 + --> $DIR/needless_return.rs:175:13 | LL | return true; | ^^^^^^^^^^^ @@ -355,7 +355,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:184:9 + --> $DIR/needless_return.rs:182:9 | LL | return true; | ^^^^^^^^^^^ @@ -367,7 +367,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:186:16 + --> $DIR/needless_return.rs:184:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -378,7 +378,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:190:5 + --> $DIR/needless_return.rs:188:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -390,7 +390,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> $DIR/needless_return.rs:193:33 + --> $DIR/needless_return.rs:191:33 | LL | async fn async_test_void_fun() { | _________________________________^ @@ -405,7 +405,7 @@ LL + async fn async_test_void_fun() { | error: unneeded `return` statement - --> $DIR/needless_return.rs:198:11 + --> $DIR/needless_return.rs:196:11 | LL | if b { | ___________^ @@ -420,7 +420,7 @@ LL + if b { | error: unneeded `return` statement - --> $DIR/needless_return.rs:200:13 + --> $DIR/needless_return.rs:198:13 | LL | } else { | _____________^ @@ -435,7 +435,7 @@ LL + } else { | error: unneeded `return` statement - --> $DIR/needless_return.rs:208:14 + --> $DIR/needless_return.rs:206:14 | LL | _ => return, | ^^^^^^ @@ -446,7 +446,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:221:9 + --> $DIR/needless_return.rs:219:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -458,7 +458,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> $DIR/needless_return.rs:223:9 + --> $DIR/needless_return.rs:221:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -470,7 +470,7 @@ LL + String::new() | error: unneeded `return` statement - --> $DIR/needless_return.rs:239:5 + --> $DIR/needless_return.rs:237:5 | LL | return format!("Hello {}", "world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -482,7 +482,7 @@ LL + format!("Hello {}", "world!") | error: unneeded `return` statement - --> $DIR/needless_return.rs:251:9 + --> $DIR/needless_return.rs:249:9 | LL | return true; | ^^^^^^^^^^^ @@ -496,7 +496,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:253:9 + --> $DIR/needless_return.rs:251:9 | LL | return false; | ^^^^^^^^^^^^ @@ -508,7 +508,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:260:13 + --> $DIR/needless_return.rs:258:13 | LL | return 10; | ^^^^^^^^^ @@ -523,7 +523,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:263:13 + --> $DIR/needless_return.rs:261:13 | LL | return 100; | ^^^^^^^^^^ @@ -536,7 +536,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:271:9 + --> $DIR/needless_return.rs:269:9 | LL | return 0; | ^^^^^^^^ @@ -548,7 +548,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:278:13 + --> $DIR/needless_return.rs:276:13 | LL | return *(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -563,7 +563,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:280:13 + --> $DIR/needless_return.rs:278:13 | LL | return !*(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -576,7 +576,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:287:20 + --> $DIR/needless_return.rs:285:20 | LL | let _ = 42; | ____________________^ @@ -593,7 +593,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> $DIR/needless_return.rs:294:20 + --> $DIR/needless_return.rs:292:20 | LL | let _ = 42; return; | ^^^^^^^ @@ -605,7 +605,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> $DIR/needless_return.rs:306:9 + --> $DIR/needless_return.rs:304:9 | LL | return Ok(format!("ok!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -617,7 +617,7 @@ LL + Ok(format!("ok!")) | error: unneeded `return` statement - --> $DIR/needless_return.rs:308:9 + --> $DIR/needless_return.rs:306:9 | LL | return Err(format!("err!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -629,7 +629,7 @@ LL + Err(format!("err!")) | error: unneeded `return` statement - --> $DIR/needless_return.rs:314:9 + --> $DIR/needless_return.rs:312:9 | LL | return if true { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -641,7 +641,7 @@ LL + if true { 1 } else { 2 } | error: unneeded `return` statement - --> $DIR/needless_return.rs:318:9 + --> $DIR/needless_return.rs:316:9 | LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_return_with_question_mark.fixed b/tests/ui/needless_return_with_question_mark.fixed index d6e47d07b0f80..45370fbab9592 100644 --- a/tests/ui/needless_return_with_question_mark.fixed +++ b/tests/ui/needless_return_with_question_mark.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow( clippy::needless_return, diff --git a/tests/ui/needless_return_with_question_mark.rs b/tests/ui/needless_return_with_question_mark.rs index 4fc04d363a9bf..e1f4148fc763b 100644 --- a/tests/ui/needless_return_with_question_mark.rs +++ b/tests/ui/needless_return_with_question_mark.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow( clippy::needless_return, diff --git a/tests/ui/needless_return_with_question_mark.stderr b/tests/ui/needless_return_with_question_mark.stderr index e1d91638d2c77..5cc20e9682bae 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 - --> $DIR/needless_return_with_question_mark.rs:28:5 + --> $DIR/needless_return_with_question_mark.rs:27:5 | LL | return Err(())?; | ^^^^^^^ help: remove it diff --git a/tests/ui/needless_splitn.fixed b/tests/ui/needless_splitn.fixed index 30a038312c876..efc47533e2337 100644 --- a/tests/ui/needless_splitn.fixed +++ b/tests/ui/needless_splitn.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 #![warn(clippy::needless_splitn)] diff --git a/tests/ui/needless_splitn.rs b/tests/ui/needless_splitn.rs index 1b0b9a5981a19..a4a3736eea2fe 100644 --- a/tests/ui/needless_splitn.rs +++ b/tests/ui/needless_splitn.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 #![warn(clippy::needless_splitn)] diff --git a/tests/ui/needless_splitn.stderr b/tests/ui/needless_splitn.stderr index 0005f758104a9..14c576e6457c8 100644 --- a/tests/ui/needless_splitn.stderr +++ b/tests/ui/needless_splitn.stderr @@ -1,5 +1,5 @@ error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:14:13 + --> $DIR/needless_splitn.rs:13:13 | LL | let _ = str.splitn(2, '=').next(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` @@ -7,73 +7,73 @@ LL | let _ = str.splitn(2, '=').next(); = note: `-D clippy::needless-splitn` implied by `-D warnings` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:15:13 + --> $DIR/needless_splitn.rs:14:13 | LL | let _ = str.splitn(2, '=').nth(0); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:18:18 + --> $DIR/needless_splitn.rs:17:18 | LL | let (_, _) = str.splitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:21:13 + --> $DIR/needless_splitn.rs:20:13 | LL | let _ = str.rsplitn(2, '=').next(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:22:13 + --> $DIR/needless_splitn.rs:21:13 | LL | let _ = str.rsplitn(2, '=').nth(0); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:25:18 + --> $DIR/needless_splitn.rs:24:18 | LL | let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:27:13 + --> $DIR/needless_splitn.rs:26:13 | LL | let _ = str.splitn(5, '=').next(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:28:13 + --> $DIR/needless_splitn.rs:27:13 | LL | let _ = str.splitn(5, '=').nth(3); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:34:13 + --> $DIR/needless_splitn.rs:33:13 | LL | let _ = s.splitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:35:13 + --> $DIR/needless_splitn.rs:34:13 | LL | let _ = s.splitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:36:13 + --> $DIR/needless_splitn.rs:35:13 | LL | let _ = s.rsplitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:37:13 + --> $DIR/needless_splitn.rs:36:13 | LL | let _ = s.rsplitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:45:13 + --> $DIR/needless_splitn.rs:44:13 | LL | let _ = "key=value".splitn(2, '=').nth(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split('=')` diff --git a/tests/ui/neg_multiply.fixed b/tests/ui/neg_multiply.fixed index e07e7c88d6848..52edea73afbb7 100644 --- a/tests/ui/neg_multiply.fixed +++ b/tests/ui/neg_multiply.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::neg_multiply)] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)] #![allow(unused)] diff --git a/tests/ui/neg_multiply.rs b/tests/ui/neg_multiply.rs index 2887af7b42187..23092a35e6064 100644 --- a/tests/ui/neg_multiply.rs +++ b/tests/ui/neg_multiply.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::neg_multiply)] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)] #![allow(unused)] diff --git a/tests/ui/neg_multiply.stderr b/tests/ui/neg_multiply.stderr index 388ef29eb8567..8b31bca0b7d4b 100644 --- a/tests/ui/neg_multiply.stderr +++ b/tests/ui/neg_multiply.stderr @@ -1,5 +1,5 @@ error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:29:5 + --> $DIR/neg_multiply.rs:28:5 | LL | x * -1; | ^^^^^^ help: consider using: `-x` @@ -7,43 +7,43 @@ LL | x * -1; = note: `-D clippy::neg-multiply` implied by `-D warnings` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:31:5 + --> $DIR/neg_multiply.rs:30:5 | LL | -1 * x; | ^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:33:11 + --> $DIR/neg_multiply.rs:32:11 | LL | 100 + x * -1; | ^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:35:5 + --> $DIR/neg_multiply.rs:34:5 | LL | (100 + x) * -1; | ^^^^^^^^^^^^^^ help: consider using: `-(100 + x)` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:37:5 + --> $DIR/neg_multiply.rs:36:5 | LL | -1 * 17; | ^^^^^^^ help: consider using: `-17` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:39:14 + --> $DIR/neg_multiply.rs:38:14 | LL | 0xcafe | 0xff00 * -1; | ^^^^^^^^^^^ help: consider using: `-0xff00` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:41:5 + --> $DIR/neg_multiply.rs:40:5 | LL | 3_usize as i32 * -1; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `-(3_usize as i32)` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:42:5 + --> $DIR/neg_multiply.rs:41:5 | LL | (3_usize as i32) * -1; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `-(3_usize as i32)` diff --git a/tests/ui/never_loop.rs b/tests/ui/never_loop.rs index eb179f30e75e2..22ff1c35b30f9 100644 --- a/tests/ui/never_loop.rs +++ b/tests/ui/never_loop.rs @@ -6,7 +6,7 @@ unused_variables, clippy::while_immutable_condition )] - +//@no-rustfix fn test1() { let mut x = 0; loop { diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed new file mode 100644 index 0000000000000..0c4283ad0c122 --- /dev/null +++ b/tests/ui/new_without_default.fixed @@ -0,0 +1,275 @@ +#![allow( + dead_code, + clippy::missing_safety_doc, + clippy::extra_unused_lifetimes, + clippy::extra_unused_type_parameters +)] +#![warn(clippy::new_without_default)] + +pub struct Foo; + +impl Default for Foo { + fn default() -> Self { + Self::new() + } +} + +impl Foo { + pub fn new() -> Foo { + Foo + } +} + +pub struct Bar; + +impl Default for Bar { + fn default() -> Self { + Self::new() + } +} + +impl Bar { + pub fn new() -> Self { + Bar + } +} + +pub struct Ok; + +impl Ok { + pub fn new() -> Self { + Ok + } +} + +impl Default for Ok { + fn default() -> Self { + Ok + } +} + +pub struct Params; + +impl Params { + pub fn new(_: u32) -> Self { + Params + } +} + +pub struct GenericsOk { + bar: T, +} + +impl Default for GenericsOk { + fn default() -> Self { + unimplemented!(); + } +} + +impl<'c, V> GenericsOk { + pub fn new() -> GenericsOk { + unimplemented!() + } +} + +pub struct LtOk<'a> { + foo: &'a bool, +} + +impl<'b> Default for LtOk<'b> { + fn default() -> Self { + unimplemented!(); + } +} + +impl<'c> LtOk<'c> { + pub fn new() -> LtOk<'c> { + unimplemented!() + } +} + +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> { + unimplemented!() + } + // FIXME: that suggestion is missing lifetimes +} + +struct Private; + +impl Private { + fn new() -> Private { + unimplemented!() + } // We don't lint private items +} + +struct PrivateStruct; + +impl PrivateStruct { + pub fn new() -> PrivateStruct { + unimplemented!() + } // We don't lint public items on private structs +} + +pub struct PrivateItem; + +impl PrivateItem { + fn new() -> PrivateItem { + unimplemented!() + } // We don't lint private items on public structs +} + +struct Const; + +impl Const { + pub const fn new() -> Const { + Const + } // const fns can't be implemented via Default +} + +pub struct IgnoreGenericNew; + +impl IgnoreGenericNew { + pub fn new() -> Self { + IgnoreGenericNew + } // the derived Default does not make sense here as the result depends on T +} + +pub trait TraitWithNew: Sized { + fn new() -> Self { + panic!() + } +} + +pub struct IgnoreUnsafeNew; + +impl IgnoreUnsafeNew { + pub unsafe fn new() -> Self { + IgnoreUnsafeNew + } +} + +#[derive(Default)] +pub struct OptionRefWrapper<'a, T>(Option<&'a T>); + +impl<'a, T> OptionRefWrapper<'a, T> { + pub fn new() -> Self { + OptionRefWrapper(None) + } +} + +pub struct Allow(Foo); + +impl Allow { + #[allow(clippy::new_without_default)] + pub fn new() -> Self { + unimplemented!() + } +} + +pub struct AllowDerive; + +impl AllowDerive { + #[allow(clippy::new_without_default)] + pub fn new() -> Self { + unimplemented!() + } +} + +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 { + NewNotEqualToDerive { foo: 1 } + } +} + +// see #6933 +pub struct FooGenerics(std::marker::PhantomData); +impl Default for FooGenerics { + fn default() -> Self { + Self::new() + } +} + +impl FooGenerics { + pub fn new() -> Self { + Self(Default::default()) + } +} + +pub struct BarGenerics(std::marker::PhantomData); +impl Default for BarGenerics { + fn default() -> Self { + Self::new() + } +} + +impl BarGenerics { + pub fn new() -> Self { + Self(Default::default()) + } +} + +pub mod issue7220 { + pub struct Foo { + _bar: *mut T, + } + + impl Default for Foo { + fn default() -> Self { + Self::new() + } + } + + impl Foo { + pub fn new() -> Self { + todo!() + } + } +} + +// see issue #8152 +// This should not create any lints +pub struct DocHidden; +impl DocHidden { + #[doc(hidden)] + pub fn new() -> Self { + DocHidden + } +} + +fn main() {} + +pub struct IgnoreConstGenericNew(usize); +impl IgnoreConstGenericNew { + pub fn new() -> Self { + Self(N) + } +} + +pub struct IgnoreLifetimeNew; +impl IgnoreLifetimeNew { + pub fn new<'a>() -> Self { + Self + } +} diff --git a/tests/ui/no_effect_return.rs b/tests/ui/no_effect_return.rs index 231dd063ad893..186d42134fd36 100644 --- a/tests/ui/no_effect_return.rs +++ b/tests/ui/no_effect_return.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(clippy::unused_unit, dead_code, unused)] #![no_main] diff --git a/tests/ui/no_effect_return.stderr b/tests/ui/no_effect_return.stderr index 779900e185908..2b55bcb881eec 100644 --- a/tests/ui/no_effect_return.stderr +++ b/tests/ui/no_effect_return.stderr @@ -1,5 +1,5 @@ error: statement with no effect - --> $DIR/no_effect_return.rs:8:9 + --> $DIR/no_effect_return.rs:9:9 | LL | 0u32; | -^^^^ @@ -9,7 +9,7 @@ LL | 0u32; = note: `-D clippy::no-effect` implied by `-D warnings` error: statement with no effect - --> $DIR/no_effect_return.rs:15:9 + --> $DIR/no_effect_return.rs:16:9 | LL | 0u32; | -^^^^ @@ -17,7 +17,7 @@ LL | 0u32; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:23:9 + --> $DIR/no_effect_return.rs:24:9 | LL | 0i32 as C; | -^^^^^^^^^ @@ -25,19 +25,19 @@ LL | 0i32 as C; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:31:9 + --> $DIR/no_effect_return.rs:32:9 | LL | 0u128; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect_return.rs:40:9 + --> $DIR/no_effect_return.rs:41:9 | LL | 0u16; | ^^^^^ error: statement with no effect - --> $DIR/no_effect_return.rs:47:9 + --> $DIR/no_effect_return.rs:48:9 | LL | [1u16]; | -^^^^^^ @@ -45,7 +45,7 @@ LL | [1u16]; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:54:9 + --> $DIR/no_effect_return.rs:55:9 | LL | ControlFlow::Break::<()>(()); | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL | ControlFlow::Break::<()>(()); | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:70:9 + --> $DIR/no_effect_return.rs:71:9 | LL | (); | -^^ @@ -61,7 +61,7 @@ LL | (); | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:78:9 + --> $DIR/no_effect_return.rs:79:9 | LL | (); | ^^^ diff --git a/tests/ui/no_mangle_with_rust_abi.rs b/tests/ui/no_mangle_with_rust_abi.rs index 818119f7be579..7ae9468230403 100644 --- a/tests/ui/no_mangle_with_rust_abi.rs +++ b/tests/ui/no_mangle_with_rust_abi.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(unused)] #![warn(clippy::no_mangle_with_rust_abi)] diff --git a/tests/ui/no_mangle_with_rust_abi.stderr b/tests/ui/no_mangle_with_rust_abi.stderr index da5d31d8f2d4c..9f5fc90dc12ba 100644 --- a/tests/ui/no_mangle_with_rust_abi.stderr +++ b/tests/ui/no_mangle_with_rust_abi.stderr @@ -1,5 +1,5 @@ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:5:1 + --> $DIR/no_mangle_with_rust_abi.rs:6:1 | LL | fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -15,7 +15,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 - --> $DIR/no_mangle_with_rust_abi.rs:8:1 + --> $DIR/no_mangle_with_rust_abi.rs:9:1 | LL | pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,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 - --> $DIR/no_mangle_with_rust_abi.rs:13:1 + --> $DIR/no_mangle_with_rust_abi.rs:14:1 | LL | pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,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 - --> $DIR/no_mangle_with_rust_abi.rs:18:1 + --> $DIR/no_mangle_with_rust_abi.rs:19:1 | LL | unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,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 - --> $DIR/no_mangle_with_rust_abi.rs:21:1 + --> $DIR/no_mangle_with_rust_abi.rs:22:1 | LL | / fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( LL | | arg_one: u32, diff --git a/tests/ui/non_minimal_cfg.fixed b/tests/ui/non_minimal_cfg.fixed index 430caafb33e12..2fcecab452b8d 100644 --- a/tests/ui/non_minimal_cfg.fixed +++ b/tests/ui/non_minimal_cfg.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #[cfg(windows)] diff --git a/tests/ui/non_minimal_cfg.rs b/tests/ui/non_minimal_cfg.rs index a38ce1c21d6e3..e3ce11b73336b 100644 --- a/tests/ui/non_minimal_cfg.rs +++ b/tests/ui/non_minimal_cfg.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #[cfg(all(windows))] diff --git a/tests/ui/non_minimal_cfg.stderr b/tests/ui/non_minimal_cfg.stderr index cdfd728aa6115..d0212e2302134 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 - --> $DIR/non_minimal_cfg.rs:5:7 + --> $DIR/non_minimal_cfg.rs:3:7 | LL | #[cfg(all(windows))] | ^^^^^^^^^^^^ help: try: `windows` @@ -7,19 +7,19 @@ LL | #[cfg(all(windows))] = note: `-D clippy::non-minimal-cfg` implied by `-D warnings` error: unneeded sub `cfg` when there is only one condition - --> $DIR/non_minimal_cfg.rs:8:7 + --> $DIR/non_minimal_cfg.rs:6:7 | LL | #[cfg(any(windows))] | ^^^^^^^^^^^^ help: try: `windows` error: unneeded sub `cfg` when there is only one condition - --> $DIR/non_minimal_cfg.rs:11:11 + --> $DIR/non_minimal_cfg.rs:9:11 | LL | #[cfg(all(any(unix), all(not(windows))))] | ^^^^^^^^^ help: try: `unix` error: unneeded sub `cfg` when there is only one condition - --> $DIR/non_minimal_cfg.rs:11:22 + --> $DIR/non_minimal_cfg.rs:9:22 | LL | #[cfg(all(any(unix), all(not(windows))))] | ^^^^^^^^^^^^^^^^^ help: try: `not(windows)` diff --git a/tests/ui/non_octal_unix_permissions.fixed b/tests/ui/non_octal_unix_permissions.fixed index 5d0da8dce6702..245d36cb734f6 100644 --- a/tests/ui/non_octal_unix_permissions.fixed +++ b/tests/ui/non_octal_unix_permissions.fixed @@ -1,5 +1,5 @@ //@ignore-target-windows -//@run-rustfix + #![warn(clippy::non_octal_unix_permissions)] use std::fs::{DirBuilder, File, OpenOptions, Permissions}; use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt}; diff --git a/tests/ui/non_octal_unix_permissions.rs b/tests/ui/non_octal_unix_permissions.rs index 04a3643050e69..d1559cba554bb 100644 --- a/tests/ui/non_octal_unix_permissions.rs +++ b/tests/ui/non_octal_unix_permissions.rs @@ -1,5 +1,5 @@ //@ignore-target-windows -//@run-rustfix + #![warn(clippy::non_octal_unix_permissions)] use std::fs::{DirBuilder, File, OpenOptions, Permissions}; use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt}; diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index e4aa0937b9779..9bb97bd50286b 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![feature(lint_reasons)] #![allow(unused, clippy::diverging_sub_expression, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index e2e4d6477c9f1..087e57867e6d1 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:12:13 + --> $DIR/nonminimal_bool.rs:13:13 | LL | let _ = !true; | ^^^^^ help: try: `false` @@ -7,43 +7,43 @@ LL | let _ = !true; = note: `-D clippy::nonminimal-bool` implied by `-D warnings` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:13:13 + --> $DIR/nonminimal_bool.rs:14:13 | LL | let _ = !false; | ^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:14:13 + --> $DIR/nonminimal_bool.rs:15:13 | LL | let _ = !!a; | ^^^ help: try: `a` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:15:13 + --> $DIR/nonminimal_bool.rs:16:13 | LL | let _ = false || a; | ^^^^^^^^^^ help: try: `a` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:19:13 + --> $DIR/nonminimal_bool.rs:20:13 | LL | let _ = !(!a && b); | ^^^^^^^^^^ help: try: `a || !b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:20:13 + --> $DIR/nonminimal_bool.rs:21:13 | LL | let _ = !(!a || b); | ^^^^^^^^^^ help: try: `a && !b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:21:13 + --> $DIR/nonminimal_bool.rs:22:13 | LL | let _ = !a && !(b && c); | ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:29:13 + --> $DIR/nonminimal_bool.rs:30:13 | LL | let _ = a == b && c == 5 && a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:30:13 + --> $DIR/nonminimal_bool.rs:31:13 | LL | let _ = a == b || c == 5 || a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL | let _ = a == b || c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:31:13 + --> $DIR/nonminimal_bool.rs:32:13 | LL | let _ = a == b && c == 5 && b == a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:32:13 + --> $DIR/nonminimal_bool.rs:33:13 | LL | let _ = a != b || !(a != b || c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +95,7 @@ LL | let _ = a != b || c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:33:13 + --> $DIR/nonminimal_bool.rs:34:13 | LL | let _ = a != b && !(a != b && c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | let _ = a != b && c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:63:8 + --> $DIR/nonminimal_bool.rs:64:8 | LL | if matches!(true, true) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(true, true)` diff --git a/tests/ui/nonminimal_bool_methods.fixed b/tests/ui/nonminimal_bool_methods.fixed index 294f2aa48f1c8..e27c0350d49e9 100644 --- a/tests/ui/nonminimal_bool_methods.fixed +++ b/tests/ui/nonminimal_bool_methods.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused, clippy::diverging_sub_expression, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] diff --git a/tests/ui/nonminimal_bool_methods.rs b/tests/ui/nonminimal_bool_methods.rs index a165368ab17dd..040a6e920a172 100644 --- a/tests/ui/nonminimal_bool_methods.rs +++ b/tests/ui/nonminimal_bool_methods.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused, clippy::diverging_sub_expression, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] diff --git a/tests/ui/nonminimal_bool_methods.stderr b/tests/ui/nonminimal_bool_methods.stderr index 21b84db858909..a2df889d62302 100644 --- a/tests/ui/nonminimal_bool_methods.stderr +++ b/tests/ui/nonminimal_bool_methods.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:9:13 + --> $DIR/nonminimal_bool_methods.rs:8:13 | LL | let _ = !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` @@ -7,73 +7,73 @@ LL | let _ = !a.is_some(); = note: `-D clippy::nonminimal-bool` implied by `-D warnings` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:11:13 + --> $DIR/nonminimal_bool_methods.rs:10:13 | LL | let _ = !a.is_none(); | ^^^^^^^^^^^^ help: try: `a.is_some()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:13:13 + --> $DIR/nonminimal_bool_methods.rs:12:13 | LL | let _ = !b.is_err(); | ^^^^^^^^^^^ help: try: `b.is_ok()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:15:13 + --> $DIR/nonminimal_bool_methods.rs:14:13 | LL | let _ = !b.is_ok(); | ^^^^^^^^^^ help: try: `b.is_err()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:17:13 + --> $DIR/nonminimal_bool_methods.rs:16:13 | LL | let _ = !(a.is_some() && !c); | ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() || c` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:18:13 + --> $DIR/nonminimal_bool_methods.rs:17:13 | LL | let _ = !(a.is_some() || !c); | ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() && c` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:19:26 + --> $DIR/nonminimal_bool_methods.rs:18:26 | LL | let _ = !(!c ^ c) || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:20:25 + --> $DIR/nonminimal_bool_methods.rs:19:25 | LL | let _ = (!c ^ c) || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:21:23 + --> $DIR/nonminimal_bool_methods.rs:20:23 | LL | let _ = !c ^ c || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:93:8 + --> $DIR/nonminimal_bool_methods.rs:92:8 | LL | if !res.is_ok() {} | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:94:8 + --> $DIR/nonminimal_bool_methods.rs:93:8 | LL | if !res.is_err() {} | ^^^^^^^^^^^^^ help: try: `res.is_ok()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:97:8 + --> $DIR/nonminimal_bool_methods.rs:96:8 | LL | if !res.is_some() {} | ^^^^^^^^^^^^^^ help: try: `res.is_none()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:98:8 + --> $DIR/nonminimal_bool_methods.rs:97:8 | LL | if !res.is_none() {} | ^^^^^^^^^^^^^^ help: try: `res.is_some()` diff --git a/tests/ui/numbered_fields.fixed b/tests/ui/numbered_fields.fixed index a52845e53a4c2..7f0a6f8e54477 100644 --- a/tests/ui/numbered_fields.fixed +++ b/tests/ui/numbered_fields.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::init_numbered_fields)] #![allow(unused_tuple_struct_fields)] diff --git a/tests/ui/numbered_fields.rs b/tests/ui/numbered_fields.rs index ca93f7dce59ac..38f3b36ec4d0e 100644 --- a/tests/ui/numbered_fields.rs +++ b/tests/ui/numbered_fields.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::init_numbered_fields)] #![allow(unused_tuple_struct_fields)] diff --git a/tests/ui/numbered_fields.stderr b/tests/ui/numbered_fields.stderr index 26f7ad9048b87..076c7aa0c6ac1 100644 --- a/tests/ui/numbered_fields.stderr +++ b/tests/ui/numbered_fields.stderr @@ -1,5 +1,5 @@ error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:19:13 + --> $DIR/numbered_fields.rs:18:13 | LL | let _ = TupleStruct { | _____________^ @@ -12,7 +12,7 @@ LL | | }; = note: `-D clippy::init-numbered-fields` implied by `-D warnings` error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:26:13 + --> $DIR/numbered_fields.rs:25:13 | LL | let _ = TupleStruct { | _____________^ diff --git a/tests/ui/obfuscated_if_else.fixed b/tests/ui/obfuscated_if_else.fixed index 9e4f97253f843..c5ee569800abd 100644 --- a/tests/ui/obfuscated_if_else.fixed +++ b/tests/ui/obfuscated_if_else.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::obfuscated_if_else)] fn main() { diff --git a/tests/ui/obfuscated_if_else.rs b/tests/ui/obfuscated_if_else.rs index c2351d64c1c55..2b60c855a555a 100644 --- a/tests/ui/obfuscated_if_else.rs +++ b/tests/ui/obfuscated_if_else.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::obfuscated_if_else)] fn main() { diff --git a/tests/ui/obfuscated_if_else.stderr b/tests/ui/obfuscated_if_else.stderr index e4180c288693f..1848151b1da25 100644 --- a/tests/ui/obfuscated_if_else.stderr +++ b/tests/ui/obfuscated_if_else.stderr @@ -1,5 +1,5 @@ error: use of `.then_some(..).unwrap_or(..)` can be written more clearly with `if .. else ..` - --> $DIR/obfuscated_if_else.rs:6:5 + --> $DIR/obfuscated_if_else.rs:4:5 | LL | true.then_some("a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` diff --git a/tests/ui/octal_escapes.rs b/tests/ui/octal_escapes.rs index 61ea96604577f..68fd3f2180d4e 100644 --- a/tests/ui/octal_escapes.rs +++ b/tests/ui/octal_escapes.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::octal_escapes)] fn main() { diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 63fdfe486e812..4245c32b5d201 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -1,5 +1,5 @@ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:4:17 + --> $DIR/octal_escapes.rs:5:17 | LL | let _bad1 = "/033[0m"; | ^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _bad1 = "/x0033[0m"; | ~~~~~~~~~~~ error: octal-looking escape in byte string literal - --> $DIR/octal_escapes.rs:5:17 + --> $DIR/octal_escapes.rs:6:17 | LL | let _bad2 = b"/033[0m"; | ^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _bad2 = b"/x0033[0m"; | ~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:6:17 + --> $DIR/octal_escapes.rs:7:17 | LL | let _bad3 = "///033[0m"; | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let _bad3 = "///x0033[0m"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:8:17 + --> $DIR/octal_escapes.rs:9:17 | LL | let _bad4 = "/01234567"; | ^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let _bad4 = "/x001234567"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:9:17 + --> $DIR/octal_escapes.rs:10:17 | LL | let _bad5 = "/0/03"; | ^^^^^^^ @@ -80,7 +80,7 @@ LL | let _bad5 = "/0/x003"; | ~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:10:17 + --> $DIR/octal_escapes.rs:11:17 | LL | let _bad6 = "Text-/055/077-MoreText"; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _bad6 = "Text-/x0055/x0077-MoreText"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:11:17 + --> $DIR/octal_escapes.rs:12:17 | LL | let _bad7 = "EvenMoreText-/01/02-ShortEscapes"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | let _bad7 = "EvenMoreText-/x001/x002-ShortEscapes"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:12:17 + --> $DIR/octal_escapes.rs:13:17 | LL | let _bad8 = "锈/01锈"; | ^^^^^^^^^ @@ -128,7 +128,7 @@ LL | let _bad8 = "锈/x001锈"; | ~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:13:17 + --> $DIR/octal_escapes.rs:14:17 | LL | let _bad9 = "锈/011锈"; | ^^^^^^^^^^ diff --git a/tests/ui/only_used_in_recursion.rs b/tests/ui/only_used_in_recursion.rs index f71e8ead5195e..871b3a79f3f6b 100644 --- a/tests/ui/only_used_in_recursion.rs +++ b/tests/ui/only_used_in_recursion.rs @@ -1,5 +1,5 @@ #![warn(clippy::only_used_in_recursion)] - +//@no-rustfix fn _simple(x: u32) -> u32 { x } diff --git a/tests/ui/only_used_in_recursion2.rs b/tests/ui/only_used_in_recursion2.rs index 45dd0553f58ac..587114b7cb8d9 100644 --- a/tests/ui/only_used_in_recursion2.rs +++ b/tests/ui/only_used_in_recursion2.rs @@ -1,5 +1,5 @@ #![warn(clippy::only_used_in_recursion)] - +//@no-rustfix fn _with_inner(flag: u32, a: u32, b: u32) -> usize { fn inner(flag: u32, a: u32) -> u32 { if flag == 0 { 0 } else { inner(flag, a) } diff --git a/tests/ui/op_ref.fixed b/tests/ui/op_ref.fixed new file mode 100644 index 0000000000000..ea7898e2b355d --- /dev/null +++ b/tests/ui/op_ref.fixed @@ -0,0 +1,94 @@ +#![allow(unused_variables, clippy::disallowed_names)] +#![warn(clippy::op_ref)] +use std::collections::HashSet; +use std::ops::{BitAnd, Mul}; + +fn main() { + let tracked_fds: HashSet = HashSet::new(); + let new_fds = HashSet::new(); + let unwanted = &tracked_fds - &new_fds; + + let foo = 5 - 6; + + let bar = String::new(); + let bar = "foo" == &bar; + + let a = "a".to_string(); + let b = "a"; + + if b < &a { + println!("OK"); + } + + struct X(i32); + impl BitAnd for X { + type Output = X; + fn bitand(self, rhs: X) -> X { + X(self.0 & rhs.0) + } + } + impl<'a> BitAnd<&'a X> for X { + type Output = X; + fn bitand(self, rhs: &'a X) -> X { + X(self.0 & rhs.0) + } + } + let x = X(1); + let y = X(2); + let z = x & &y; + + #[derive(Copy, Clone)] + struct Y(i32); + impl BitAnd for Y { + type Output = Y; + fn bitand(self, rhs: Y) -> Y { + Y(self.0 & rhs.0) + } + } + impl<'a> BitAnd<&'a Y> for Y { + type Output = Y; + fn bitand(self, rhs: &'a Y) -> Y { + Y(self.0 & rhs.0) + } + } + let x = Y(1); + let y = Y(2); + let z = x & y; +} + +#[derive(Clone, Copy)] +struct A(i32); +#[derive(Clone, Copy)] +struct B(i32); + +impl Mul<&A> for B { + type Output = i32; + fn mul(self, rhs: &A) -> Self::Output { + self.0 * rhs.0 + } +} +impl Mul for B { + type Output = i32; + fn mul(self, rhs: A) -> Self::Output { + // Should not lint because removing the reference would lead to unconditional recursion + self * &rhs + } +} +impl Mul<&A> for A { + type Output = i32; + fn mul(self, rhs: &A) -> Self::Output { + self.0 * rhs.0 + } +} +impl Mul for A { + type Output = i32; + fn mul(self, rhs: A) -> Self::Output { + let one = B(1); + let two = 2; + let three = 3; + let _ = one * self; + let _ = two + three; + // Removing the reference would lead to unconditional recursion + self * &rhs + } +} diff --git a/tests/ui/option_as_ref_deref.fixed b/tests/ui/option_as_ref_deref.fixed index 4d1a6a1ab98d1..c5a959ba566dc 100644 --- a/tests/ui/option_as_ref_deref.fixed +++ b/tests/ui/option_as_ref_deref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::redundant_clone, clippy::useless_vec)] #![warn(clippy::option_as_ref_deref)] diff --git a/tests/ui/option_as_ref_deref.rs b/tests/ui/option_as_ref_deref.rs index 66d5a1250360d..1aeedf211fe22 100644 --- a/tests/ui/option_as_ref_deref.rs +++ b/tests/ui/option_as_ref_deref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::redundant_clone, clippy::useless_vec)] #![warn(clippy::option_as_ref_deref)] diff --git a/tests/ui/option_as_ref_deref.stderr b/tests/ui/option_as_ref_deref.stderr index e471b56eea817..b5dc6a7f33189 100644 --- a/tests/ui/option_as_ref_deref.stderr +++ b/tests/ui/option_as_ref_deref.stderr @@ -1,5 +1,5 @@ error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead - --> $DIR/option_as_ref_deref.rs:13:13 + --> $DIR/option_as_ref_deref.rs:11:13 | LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.clone().as_deref()` @@ -7,7 +7,7 @@ LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); = note: `-D clippy::option-as-ref-deref` implied by `-D warnings` error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead - --> $DIR/option_as_ref_deref.rs:16:13 + --> $DIR/option_as_ref_deref.rs:14:13 | LL | let _ = opt.clone() | _____________^ @@ -17,97 +17,97 @@ LL | | ) | |_________^ help: try using as_deref instead: `opt.clone().as_deref()` error: called `.as_mut().map(DerefMut::deref_mut)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:22:13 + --> $DIR/option_as_ref_deref.rs:20:13 | LL | let _ = opt.as_mut().map(DerefMut::deref_mut); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:24:13 + --> $DIR/option_as_ref_deref.rs:22:13 | LL | let _ = opt.as_ref().map(String::as_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_ref().map(|x| x.as_str())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:25:13 + --> $DIR/option_as_ref_deref.rs:23:13 | LL | let _ = opt.as_ref().map(|x| x.as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_mut().map(String::as_mut_str)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:26:13 + --> $DIR/option_as_ref_deref.rs:24:13 | LL | let _ = opt.as_mut().map(String::as_mut_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` error: called `.as_mut().map(|x| x.as_mut_str())` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:27:13 + --> $DIR/option_as_ref_deref.rs:25:13 | LL | let _ = opt.as_mut().map(|x| x.as_mut_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` error: called `.as_ref().map(CString::as_c_str)` on an Option value. This can be done more directly by calling `Some(CString::new(vec![]).unwrap()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:28:13 + --> $DIR/option_as_ref_deref.rs:26:13 | LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(CString::new(vec![]).unwrap()).as_deref()` error: called `.as_ref().map(OsString::as_os_str)` on an Option value. This can be done more directly by calling `Some(OsString::new()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:29:13 + --> $DIR/option_as_ref_deref.rs:27:13 | LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(OsString::new()).as_deref()` error: called `.as_ref().map(PathBuf::as_path)` on an Option value. This can be done more directly by calling `Some(PathBuf::new()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:30:13 + --> $DIR/option_as_ref_deref.rs:28:13 | LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(PathBuf::new()).as_deref()` error: called `.as_ref().map(Vec::as_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:31:13 + --> $DIR/option_as_ref_deref.rs:29:13 | LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(Vec::<()>::new()).as_deref()` error: called `.as_mut().map(Vec::as_mut_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:32:13 + --> $DIR/option_as_ref_deref.rs:30:13 | LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `Some(Vec::<()>::new()).as_deref_mut()` error: called `.as_ref().map(|x| x.deref())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:34:13 + --> $DIR/option_as_ref_deref.rs:32:13 | LL | let _ = opt.as_ref().map(|x| x.deref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_mut().map(|x| x.deref_mut())` on an Option value. This can be done more directly by calling `opt.clone().as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:35:13 + --> $DIR/option_as_ref_deref.rs:33:13 | LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.clone().as_deref_mut()` error: called `.as_ref().map(|x| &**x)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:42:13 + --> $DIR/option_as_ref_deref.rs:40:13 | LL | let _ = opt.as_ref().map(|x| &**x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_mut().map(|x| &mut **x)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:43:13 + --> $DIR/option_as_ref_deref.rs:41:13 | LL | let _ = opt.as_mut().map(|x| &mut **x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` error: called `.as_ref().map(std::ops::Deref::deref)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:46:13 + --> $DIR/option_as_ref_deref.rs:44:13 | LL | let _ = opt.as_ref().map(std::ops::Deref::deref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:58:13 + --> $DIR/option_as_ref_deref.rs:56:13 | LL | let _ = opt.as_ref().map(String::as_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` diff --git a/tests/ui/option_filter_map.fixed b/tests/ui/option_filter_map.fixed index 93c250cfa735a..d4c04ff907b2a 100644 --- a/tests/ui/option_filter_map.fixed +++ b/tests/ui/option_filter_map.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_filter_map)] #![allow(clippy::map_flatten)] diff --git a/tests/ui/option_filter_map.rs b/tests/ui/option_filter_map.rs index 2c5f03250b987..99fb4723cab7a 100644 --- a/tests/ui/option_filter_map.rs +++ b/tests/ui/option_filter_map.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_filter_map)] #![allow(clippy::map_flatten)] diff --git a/tests/ui/option_filter_map.stderr b/tests/ui/option_filter_map.stderr index 4a030ac9ab045..e7da7c292871d 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` - --> $DIR/option_filter_map.rs:6:27 + --> $DIR/option_filter_map.rs:5:27 | LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` @@ -7,37 +7,37 @@ LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); = note: `-D clippy::option-filter-map` implied by `-D warnings` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:7:27 + --> $DIR/option_filter_map.rs:6: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` - --> $DIR/option_filter_map.rs:8:35 + --> $DIR/option_filter_map.rs:7: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` - --> $DIR/option_filter_map.rs:9:35 + --> $DIR/option_filter_map.rs:8: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` - --> $DIR/option_filter_map.rs:11:39 + --> $DIR/option_filter_map.rs:10: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` - --> $DIR/option_filter_map.rs:12:39 + --> $DIR/option_filter_map.rs:11: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` - --> $DIR/option_filter_map.rs:16:10 + --> $DIR/option_filter_map.rs:15:10 | LL | .filter(Option::is_some) | __________^ @@ -45,7 +45,7 @@ LL | | .map(Option::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:21:10 + --> $DIR/option_filter_map.rs:20: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 6fee3cce619c6..c3415a7df9e31 100644 --- a/tests/ui/option_if_let_else.fixed +++ b/tests/ui/option_if_let_else.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_if_let_else)] #![allow( unused_tuple_struct_fields, diff --git a/tests/ui/option_if_let_else.rs b/tests/ui/option_if_let_else.rs index 4b3cf948a1bed..86537f62057be 100644 --- a/tests/ui/option_if_let_else.rs +++ b/tests/ui/option_if_let_else.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_if_let_else)] #![allow( unused_tuple_struct_fields, diff --git a/tests/ui/option_if_let_else.stderr b/tests/ui/option_if_let_else.stderr index 350f0f07e136e..aa2da21740032 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 - --> $DIR/option_if_let_else.rs:13:5 + --> $DIR/option_if_let_else.rs:12:5 | LL | / if let Some(x) = string { LL | | (true, x) @@ -11,19 +11,19 @@ LL | | } = note: `-D clippy::option-if-let-else` implied by `-D warnings` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:31:13 + --> $DIR/option_if_let_else.rs:30: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 - --> $DIR/option_if_let_else.rs:32:13 + --> $DIR/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 - --> $DIR/option_if_let_else.rs:33:13 + --> $DIR/option_if_let_else.rs:32:13 | LL | let _ = if let Some(s) = &mut num { | _____________^ @@ -43,13 +43,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:39:13 + --> $DIR/option_if_let_else.rs:38: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 - --> $DIR/option_if_let_else.rs:40:13 + --> $DIR/option_if_let_else.rs:39:13 | LL | let _ = if let Some(mut s) = num { | _____________^ @@ -69,7 +69,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:46:13 + --> $DIR/option_if_let_else.rs:45:13 | LL | let _ = if let Some(ref mut s) = num { | _____________^ @@ -89,7 +89,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:55:5 + --> $DIR/option_if_let_else.rs:54:5 | LL | / if let Some(x) = arg { LL | | let y = x * x; @@ -108,7 +108,7 @@ LL + }) | error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:68:13 + --> $DIR/option_if_let_else.rs:67:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -120,7 +120,7 @@ LL | | }; | |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)` error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:77:13 + --> $DIR/option_if_let_else.rs:76:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -143,7 +143,7 @@ LL ~ }, |x| x * x * x * x); | error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:110:13 + --> $DIR/option_if_let_else.rs:109:13 | LL | / if let Some(idx) = s.find('.') { LL | | vec![s[..idx].to_string(), s[idx..].to_string()] @@ -153,7 +153,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 - --> $DIR/option_if_let_else.rs:121:5 + --> $DIR/option_if_let_else.rs:120:5 | LL | / if let Ok(binding) = variable { LL | | println!("Ok {binding}"); @@ -172,13 +172,13 @@ LL + }) | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:143:13 + --> $DIR/option_if_let_else.rs:142: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 - --> $DIR/option_if_let_else.rs:153:13 + --> $DIR/option_if_let_else.rs:152:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -200,13 +200,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:181:13 + --> $DIR/option_if_let_else.rs:180: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 - --> $DIR/option_if_let_else.rs:185:13 + --> $DIR/option_if_let_else.rs:184:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -226,7 +226,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:224:13 + --> $DIR/option_if_let_else.rs:223:13 | LL | let _ = match s { | _____________^ @@ -236,7 +236,7 @@ LL | | }; | |_____^ help: try: `s.map_or(1, |string| string.len())` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:228:13 + --> $DIR/option_if_let_else.rs:227:13 | LL | let _ = match Some(10) { | _____________^ @@ -246,7 +246,7 @@ LL | | }; | |_____^ help: try: `Some(10).map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:234:13 + --> $DIR/option_if_let_else.rs:233:13 | LL | let _ = match res { | _____________^ @@ -256,7 +256,7 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:238:13 + --> $DIR/option_if_let_else.rs:237:13 | LL | let _ = match res { | _____________^ @@ -266,13 +266,13 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:242:13 + --> $DIR/option_if_let_else.rs:241: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 - --> $DIR/option_if_let_else.rs:259:9 + --> $DIR/option_if_let_else.rs:258:9 | LL | / match initial { LL | | Some(value) => do_something(value), @@ -281,7 +281,7 @@ LL | | } | |_________^ help: try: `initial.as_ref().map_or({}, |value| do_something(value))` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:266:9 + --> $DIR/option_if_let_else.rs:265:9 | LL | / match initial { LL | | Some(value) => do_something2(value), diff --git a/tests/ui/option_map_or_none.fixed b/tests/ui/option_map_or_none.fixed index 501757647bfb8..5f0ef34d231ce 100644 --- a/tests/ui/option_map_or_none.fixed +++ b/tests/ui/option_map_or_none.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::bind_instead_of_map)] fn main() { diff --git a/tests/ui/option_map_or_none.rs b/tests/ui/option_map_or_none.rs index 4d8704e737da5..56b1f61212d03 100644 --- a/tests/ui/option_map_or_none.rs +++ b/tests/ui/option_map_or_none.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::bind_instead_of_map)] fn main() { diff --git a/tests/ui/option_map_or_none.stderr b/tests/ui/option_map_or_none.stderr index 7befcb890863a..76c4645534365 100644 --- a/tests/ui/option_map_or_none.stderr +++ b/tests/ui/option_map_or_none.stderr @@ -1,5 +1,5 @@ error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead - --> $DIR/option_map_or_none.rs:12:26 + --> $DIR/option_map_or_none.rs:10:26 | LL | let _: Option = opt.map_or(None, |x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| x + 1)` @@ -7,7 +7,7 @@ LL | let _: Option = opt.map_or(None, |x| Some(x + 1)); = note: `-D clippy::option-map-or-none` implied by `-D warnings` error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead - --> $DIR/option_map_or_none.rs:15:26 + --> $DIR/option_map_or_none.rs:13:26 | LL | let _: Option = opt.map_or(None, |x| { | __________________________^ @@ -16,13 +16,13 @@ LL | | }); | |_________________________^ help: try using `map` instead: `opt.map(|x| x + 1)` error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead - --> $DIR/option_map_or_none.rs:19:26 + --> $DIR/option_map_or_none.rs:17:26 | LL | let _: Option = opt.map_or(None, bar); | ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)` error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead - --> $DIR/option_map_or_none.rs:20:26 + --> $DIR/option_map_or_none.rs:18:26 | LL | let _: Option = opt.map_or(None, |x| { | __________________________^ @@ -42,7 +42,7 @@ LL ~ }); | error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead - --> $DIR/option_map_or_none.rs:27:26 + --> $DIR/option_map_or_none.rs:25:26 | LL | let _: Option = r.map_or(None, Some); | ^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `r.ok()` diff --git a/tests/ui/option_map_unit_fn_fixable.fixed b/tests/ui/option_map_unit_fn_fixable.fixed index 8f64451edf366..5dcc6464ff5f3 100644 --- a/tests/ui/option_map_unit_fn_fixable.fixed +++ b/tests/ui/option_map_unit_fn_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_map_unit_fn)] #![allow(unused)] #![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)] diff --git a/tests/ui/option_map_unit_fn_fixable.rs b/tests/ui/option_map_unit_fn_fixable.rs index 2bf7a8e0f7d45..5489545fe3d98 100644 --- a/tests/ui/option_map_unit_fn_fixable.rs +++ b/tests/ui/option_map_unit_fn_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_map_unit_fn)] #![allow(unused)] #![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)] diff --git a/tests/ui/option_map_unit_fn_fixable.stderr b/tests/ui/option_map_unit_fn_fixable.stderr index 5be5f10b0177a..38bcb5967f694 100644 --- a/tests/ui/option_map_unit_fn_fixable.stderr +++ b/tests/ui/option_map_unit_fn_fixable.stderr @@ -1,5 +1,5 @@ error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:38:5 + --> $DIR/option_map_unit_fn_fixable.rs:37:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -9,7 +9,7 @@ LL | x.field.map(do_nothing); = note: `-D clippy::option-map-unit-fn` implied by `-D warnings` error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:40:5 + --> $DIR/option_map_unit_fn_fixable.rs:39:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -17,7 +17,7 @@ LL | x.field.map(do_nothing); | help: try: `if let Some(x_field) = x.field { do_nothing(x_field) }` error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:42:5 + --> $DIR/option_map_unit_fn_fixable.rs:41:5 | LL | x.field.map(diverge); | ^^^^^^^^^^^^^^^^^^^^- @@ -25,7 +25,7 @@ LL | x.field.map(diverge); | help: try: `if let Some(x_field) = x.field { diverge(x_field) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:48:5 + --> $DIR/option_map_unit_fn_fixable.rs:47:5 | LL | x.field.map(|value| x.do_option_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -33,7 +33,7 @@ LL | x.field.map(|value| x.do_option_nothing(value + captured)); | help: try: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:50:5 + --> $DIR/option_map_unit_fn_fixable.rs:49:5 | LL | x.field.map(|value| { x.do_option_plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -41,7 +41,7 @@ LL | x.field.map(|value| { x.do_option_plus_one(value + captured); }); | help: try: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:53:5 + --> $DIR/option_map_unit_fn_fixable.rs:52:5 | LL | x.field.map(|value| do_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -49,7 +49,7 @@ LL | x.field.map(|value| do_nothing(value + captured)); | help: try: `if let Some(value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:55:5 + --> $DIR/option_map_unit_fn_fixable.rs:54:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -57,7 +57,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) }); | help: try: `if let Some(value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:57:5 + --> $DIR/option_map_unit_fn_fixable.rs:56:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -65,7 +65,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); }); | help: try: `if let Some(value) = x.field { do_nothing(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:59:5 + --> $DIR/option_map_unit_fn_fixable.rs:58:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -73,7 +73,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } }); | help: try: `if let Some(value) = x.field { do_nothing(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:62:5 + --> $DIR/option_map_unit_fn_fixable.rs:61:5 | LL | x.field.map(|value| diverge(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -81,7 +81,7 @@ LL | x.field.map(|value| diverge(value + captured)); | help: try: `if let Some(value) = x.field { diverge(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:64:5 + --> $DIR/option_map_unit_fn_fixable.rs:63:5 | LL | x.field.map(|value| { diverge(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -89,7 +89,7 @@ LL | x.field.map(|value| { diverge(value + captured) }); | help: try: `if let Some(value) = x.field { diverge(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:66:5 + --> $DIR/option_map_unit_fn_fixable.rs:65:5 | LL | x.field.map(|value| { diverge(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -97,7 +97,7 @@ LL | x.field.map(|value| { diverge(value + captured); }); | help: try: `if let Some(value) = x.field { diverge(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:68:5 + --> $DIR/option_map_unit_fn_fixable.rs:67:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -105,7 +105,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } }); | help: try: `if let Some(value) = x.field { diverge(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:73:5 + --> $DIR/option_map_unit_fn_fixable.rs:72:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -113,7 +113,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); }); | help: try: `if let Some(value) = x.field { let y = plus_one(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:75:5 + --> $DIR/option_map_unit_fn_fixable.rs:74:5 | LL | x.field.map(|value| { plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -121,7 +121,7 @@ LL | x.field.map(|value| { plus_one(value + captured); }); | help: try: `if let Some(value) = x.field { plus_one(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:77:5 + --> $DIR/option_map_unit_fn_fixable.rs:76:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -129,7 +129,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } }); | help: try: `if let Some(value) = x.field { plus_one(value + captured); }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:80:5 + --> $DIR/option_map_unit_fn_fixable.rs:79:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -137,7 +137,7 @@ LL | x.field.map(|ref value| { do_nothing(value + captured) }); | help: try: `if let Some(ref value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:82:5 + --> $DIR/option_map_unit_fn_fixable.rs:81:5 | LL | option().map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^^- @@ -145,7 +145,7 @@ LL | option().map(do_nothing); | help: try: `if let Some(a) = option() { do_nothing(a) }` error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` - --> $DIR/option_map_unit_fn_fixable.rs:84:5 + --> $DIR/option_map_unit_fn_fixable.rs:83:5 | LL | option().map(|value| println!("{:?}", value)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index 581f3ad45c7d7..e7ba54864ab0e 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::or_fun_call)] #![allow(dead_code)] #![allow( diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index 1f3987eb8917a..196632133d52a 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::or_fun_call)] #![allow(dead_code)] #![allow( diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 519f09165626c..5a904c2f490e8 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -1,5 +1,5 @@ error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:53:22 + --> $DIR/or_fun_call.rs:52:22 | LL | with_constructor.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(make)` @@ -7,7 +7,7 @@ LL | with_constructor.unwrap_or(make()); = note: `-D clippy::or-fun-call` implied by `-D warnings` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:56:14 + --> $DIR/or_fun_call.rs:55:14 | LL | with_new.unwrap_or(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` @@ -15,175 +15,175 @@ LL | with_new.unwrap_or(Vec::new()); = note: `-D clippy::unwrap-or-default` implied by `-D warnings` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:59:21 + --> $DIR/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: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:62:14 + --> $DIR/or_fun_call.rs:61:14 | LL | with_err.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| make())` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:65:19 + --> $DIR/or_fun_call.rs:64: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 - --> $DIR/or_fun_call.rs:68:24 + --> $DIR/or_fun_call.rs:67:24 | LL | with_default_trait.unwrap_or(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:71:23 + --> $DIR/or_fun_call.rs:70:23 | LL | with_default_type.unwrap_or(u64::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:74:18 + --> $DIR/or_fun_call.rs:73:18 | LL | self_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(::default)` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:77:18 + --> $DIR/or_fun_call.rs:76:18 | LL | real_default.unwrap_or(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:80:14 + --> $DIR/or_fun_call.rs:79:14 | LL | with_vec.unwrap_or(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:83:21 + --> $DIR/or_fun_call.rs:82:21 | LL | without_default.unwrap_or(Foo::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(Foo::new)` error: use of `or_insert` to construct default value - --> $DIR/or_fun_call.rs:86:19 + --> $DIR/or_fun_call.rs:85:19 | LL | map.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> $DIR/or_fun_call.rs:89:23 + --> $DIR/or_fun_call.rs:88:23 | LL | map_vec.entry(42).or_insert(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> $DIR/or_fun_call.rs:92:21 + --> $DIR/or_fun_call.rs:91:21 | LL | btree.entry(42).or_insert(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert` to construct default value - --> $DIR/or_fun_call.rs:95:25 + --> $DIR/or_fun_call.rs:94:25 | LL | btree_vec.entry(42).or_insert(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:98:21 + --> $DIR/or_fun_call.rs:97:21 | LL | let _ = stringy.unwrap_or(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:106:21 + --> $DIR/or_fun_call.rs:105:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:108:21 + --> $DIR/or_fun_call.rs:107:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` error: use of `or` followed by a function call - --> $DIR/or_fun_call.rs:132:35 + --> $DIR/or_fun_call.rs:131:35 | LL | let _ = Some("a".to_string()).or(Some("b".to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_else(|| Some("b".to_string()))` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:171:14 + --> $DIR/or_fun_call.rs:170:14 | LL | None.unwrap_or(ptr_to_ref(s)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| ptr_to_ref(s))` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:177:14 + --> $DIR/or_fun_call.rs:176:14 | LL | None.unwrap_or(unsafe { ptr_to_ref(s) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:179:14 + --> $DIR/or_fun_call.rs:178:14 | LL | None.unwrap_or( unsafe { ptr_to_ref(s) } ); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` error: use of `map_or` followed by a function call - --> $DIR/or_fun_call.rs:254:25 + --> $DIR/or_fun_call.rs:253:25 | LL | let _ = Some(4).map_or(g(), |v| v); | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(g, |v| v)` error: use of `map_or` followed by a function call - --> $DIR/or_fun_call.rs:255:25 + --> $DIR/or_fun_call.rs:254:25 | LL | let _ = Some(4).map_or(g(), f); | ^^^^^^^^^^^^^^ help: try: `map_or_else(g, f)` error: use of `unwrap_or_else` to construct default value - --> $DIR/or_fun_call.rs:286:18 + --> $DIR/or_fun_call.rs:285:18 | LL | with_new.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/or_fun_call.rs:289:28 + --> $DIR/or_fun_call.rs:288: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 - --> $DIR/or_fun_call.rs:292:27 + --> $DIR/or_fun_call.rs:291: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 - --> $DIR/or_fun_call.rs:295:22 + --> $DIR/or_fun_call.rs:294:22 | LL | real_default.unwrap_or_else(::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> $DIR/or_fun_call.rs:298:23 + --> $DIR/or_fun_call.rs:297:23 | LL | map.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `or_insert_with` to construct default value - --> $DIR/or_fun_call.rs:301:25 + --> $DIR/or_fun_call.rs:300:25 | LL | btree.entry(42).or_insert_with(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/or_fun_call.rs:304:25 + --> $DIR/or_fun_call.rs:303:25 | LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` diff --git a/tests/ui/or_then_unwrap.fixed b/tests/ui/or_then_unwrap.fixed index 773dfc3c5d148..c944786143521 100644 --- a/tests/ui/or_then_unwrap.fixed +++ b/tests/ui/or_then_unwrap.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::or_then_unwrap)] #![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui/or_then_unwrap.rs b/tests/ui/or_then_unwrap.rs index 5867e014878e2..10e43e1d18969 100644 --- a/tests/ui/or_then_unwrap.rs +++ b/tests/ui/or_then_unwrap.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::or_then_unwrap)] #![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui/or_then_unwrap.stderr b/tests/ui/or_then_unwrap.stderr index 2a1a52407dc37..4b47f538a6c4e 100644 --- a/tests/ui/or_then_unwrap.stderr +++ b/tests/ui/or_then_unwrap.stderr @@ -1,5 +1,5 @@ error: found `.or(Some(…)).unwrap()` - --> $DIR/or_then_unwrap.rs:24:20 + --> $DIR/or_then_unwrap.rs:22:20 | LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` @@ -7,13 +7,13 @@ LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint = note: `-D clippy::or-then-unwrap` implied by `-D warnings` error: found `.or(Ok(…)).unwrap()` - --> $DIR/or_then_unwrap.rs:27:20 + --> $DIR/or_then_unwrap.rs:25:20 | LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` error: found `.or(Some(…)).unwrap()` - --> $DIR/or_then_unwrap.rs:31:31 + --> $DIR/or_then_unwrap.rs:29: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/overly_complex_bool_expr.fixed b/tests/ui/overly_complex_bool_expr.fixed new file mode 100644 index 0000000000000..f143cf70fcfad --- /dev/null +++ b/tests/ui/overly_complex_bool_expr.fixed @@ -0,0 +1,34 @@ +#![feature(lint_reasons)] +#![allow(unused, clippy::diverging_sub_expression)] +#![warn(clippy::overly_complex_bool_expr)] + +fn main() { + let a: bool = unimplemented!(); + let b: bool = unimplemented!(); + let c: bool = unimplemented!(); + let d: bool = unimplemented!(); + let e: bool = unimplemented!(); + let _ = a; + let _ = !(a && b); + let _ = false; + // don't lint on cfgs + let _ = cfg!(you_shall_not_not_pass) && a; + let _ = a || !b || !c || !d || !e; + let _ = !(a && b || c); +} + +fn equality_stuff() { + let a: i32 = unimplemented!(); + let b: i32 = unimplemented!(); + let _ = false; + let _ = false; + let _ = false; + let _ = a > b && a == b; +} + +fn check_expect() { + let a: i32 = unimplemented!(); + let b: i32 = unimplemented!(); + #[expect(clippy::overly_complex_bool_expr)] + let _ = a < b && a >= b; +} diff --git a/tests/ui/partialeq_to_none.fixed b/tests/ui/partialeq_to_none.fixed index 95e184b1de6cb..87adbca394847 100644 --- a/tests/ui/partialeq_to_none.fixed +++ b/tests/ui/partialeq_to_none.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::partialeq_to_none)] #![allow(clippy::eq_op, clippy::needless_if)] diff --git a/tests/ui/partialeq_to_none.rs b/tests/ui/partialeq_to_none.rs index 4fa50dcc11b6e..b623e6a66268e 100644 --- a/tests/ui/partialeq_to_none.rs +++ b/tests/ui/partialeq_to_none.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::partialeq_to_none)] #![allow(clippy::eq_op, clippy::needless_if)] diff --git a/tests/ui/partialeq_to_none.stderr b/tests/ui/partialeq_to_none.stderr index 4f84862a22b8f..d06ab7aee558b 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` - --> $DIR/partialeq_to_none.rs:15:8 + --> $DIR/partialeq_to_none.rs:14:8 | LL | if f != None { "yay" } else { "nay" } | ^^^^^^^^^ help: use `Option::is_some()` instead: `f.is_some()` @@ -7,55 +7,55 @@ LL | if f != None { "yay" } else { "nay" } = note: `-D clippy::partialeq-to-none` implied by `-D warnings` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:45:13 + --> $DIR/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` - --> $DIR/partialeq_to_none.rs:46:13 + --> $DIR/partialeq_to_none.rs:45:13 | LL | let _ = x != None; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:47:13 + --> $DIR/partialeq_to_none.rs:46:13 | LL | let _ = None == x; | ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:48:13 + --> $DIR/partialeq_to_none.rs:47:13 | LL | let _ = None != x; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:50:8 + --> $DIR/partialeq_to_none.rs:49:8 | LL | if foobar() == None {} | ^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `foobar().is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:52:8 + --> $DIR/partialeq_to_none.rs:51:8 | LL | if bar().ok() != None {} | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `bar().ok().is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:54:13 + --> $DIR/partialeq_to_none.rs:53: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` - --> $DIR/partialeq_to_none.rs:56:13 + --> $DIR/partialeq_to_none.rs:55:13 | LL | let _ = { Some(0) } == None; | ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `{ Some(0) }.is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:58:13 + --> $DIR/partialeq_to_none.rs:57:13 | LL | let _ = { | _____________^ @@ -77,31 +77,31 @@ LL ~ }.is_some(); | error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:68:13 + --> $DIR/partialeq_to_none.rs:67:13 | LL | let _ = optref() == &&None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:69:13 + --> $DIR/partialeq_to_none.rs:68:13 | LL | let _ = &&None != optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:70:13 + --> $DIR/partialeq_to_none.rs:69:13 | LL | let _ = **optref() == None; | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:71:13 + --> $DIR/partialeq_to_none.rs:70:13 | LL | let _ = &None != *optref(); | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:74:13 + --> $DIR/partialeq_to_none.rs:73:13 | LL | let _ = None != *x; | ^^^^^^^^^^ help: use `Option::is_some()` instead: `(*x).is_some()` diff --git a/tests/ui/path_buf_push_overwrite.fixed b/tests/ui/path_buf_push_overwrite.fixed index 393fc6e1c6933..86e3e5bbdafda 100644 --- a/tests/ui/path_buf_push_overwrite.fixed +++ b/tests/ui/path_buf_push_overwrite.fixed @@ -1,4 +1,3 @@ -//@run-rustfix use std::path::PathBuf; #[warn(clippy::all, clippy::path_buf_push_overwrite)] diff --git a/tests/ui/path_buf_push_overwrite.rs b/tests/ui/path_buf_push_overwrite.rs index 18de6e0641268..460cc254e9420 100644 --- a/tests/ui/path_buf_push_overwrite.rs +++ b/tests/ui/path_buf_push_overwrite.rs @@ -1,4 +1,3 @@ -//@run-rustfix use std::path::PathBuf; #[warn(clippy::all, clippy::path_buf_push_overwrite)] diff --git a/tests/ui/path_buf_push_overwrite.stderr b/tests/ui/path_buf_push_overwrite.stderr index bb8dce2bbba4b..1922a6ab692ec 100644 --- a/tests/ui/path_buf_push_overwrite.stderr +++ b/tests/ui/path_buf_push_overwrite.stderr @@ -1,5 +1,5 @@ error: calling `push` with '/' or '/' (file system root) will overwrite the previous path definition - --> $DIR/path_buf_push_overwrite.rs:7:12 + --> $DIR/path_buf_push_overwrite.rs:6:12 | LL | x.push("/bar"); | ^^^^^^ help: try: `"bar"` diff --git a/tests/ui/patterns.fixed b/tests/ui/patterns.fixed index 714143e758694..d9e2e6ab16e9e 100644 --- a/tests/ui/patterns.fixed +++ b/tests/ui/patterns.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::all)] #![allow(unused)] diff --git a/tests/ui/patterns.rs b/tests/ui/patterns.rs index 153e264070173..a093604f037a4 100644 --- a/tests/ui/patterns.rs +++ b/tests/ui/patterns.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::all)] #![allow(unused)] diff --git a/tests/ui/patterns.stderr b/tests/ui/patterns.stderr index 276330d21c424..e2431cb300975 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` - --> $DIR/patterns.rs:15:9 + --> $DIR/patterns.rs:14:9 | LL | y @ _ => (), | ^^^^^ help: try: `y` @@ -7,13 +7,13 @@ LL | y @ _ => (), = note: `-D clippy::redundant-pattern` implied by `-D warnings` error: the `x @ _` pattern can be written as just `x` - --> $DIR/patterns.rs:30:9 + --> $DIR/patterns.rs:29:9 | LL | ref mut x @ _ => { | ^^^^^^^^^^^^^ help: try: `ref mut x` error: the `x @ _` pattern can be written as just `x` - --> $DIR/patterns.rs:38:9 + --> $DIR/patterns.rs:37:9 | LL | ref x @ _ => println!("vec: {:?}", x), | ^^^^^^^^^ help: try: `ref x` diff --git a/tests/ui/precedence.fixed b/tests/ui/precedence.fixed index af4d5636b6162..cc87de0d90f18 100644 --- a/tests/ui/precedence.fixed +++ b/tests/ui/precedence.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::precedence)] #![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)] #![allow(clippy::identity_op)] diff --git a/tests/ui/precedence.rs b/tests/ui/precedence.rs index e23ae9127866a..00c18d92b5fb6 100644 --- a/tests/ui/precedence.rs +++ b/tests/ui/precedence.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::precedence)] #![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)] #![allow(clippy::identity_op)] diff --git a/tests/ui/precedence.stderr b/tests/ui/precedence.stderr index 03d585b39750a..30f4607ad17af 100644 --- a/tests/ui/precedence.stderr +++ b/tests/ui/precedence.stderr @@ -1,5 +1,5 @@ error: operator precedence can trip the unwary - --> $DIR/precedence.rs:17:5 + --> $DIR/precedence.rs:16:5 | LL | 1 << 2 + 3; | ^^^^^^^^^^ help: consider parenthesizing your expression: `1 << (2 + 3)` @@ -7,67 +7,67 @@ LL | 1 << 2 + 3; = note: `-D clippy::precedence` implied by `-D warnings` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:18:5 + --> $DIR/precedence.rs:17:5 | LL | 1 + 2 << 3; | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:19:5 + --> $DIR/precedence.rs:18:5 | LL | 4 >> 1 + 1; | ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:20:5 + --> $DIR/precedence.rs:19:5 | LL | 1 + 3 >> 2; | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:21:5 + --> $DIR/precedence.rs:20:5 | LL | 1 ^ 1 - 1; | ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:22:5 + --> $DIR/precedence.rs:21:5 | LL | 3 | 2 - 1; | ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:23:5 + --> $DIR/precedence.rs:22:5 | LL | 3 & 5 - 2; | ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:24:5 + --> $DIR/precedence.rs:23:5 | LL | -1i32.abs(); | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1i32.abs())` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:25:5 + --> $DIR/precedence.rs:24:5 | LL | -1f32.abs(); | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1f32.abs())` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:52:13 + --> $DIR/precedence.rs:51:13 | LL | let _ = -1.0_f64.cos().cos(); | ^^^^^^^^^^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1.0_f64.cos().cos())` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:53:13 + --> $DIR/precedence.rs:52:13 | LL | let _ = -1.0_f64.cos().sin(); | ^^^^^^^^^^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1.0_f64.cos().sin())` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:54:13 + --> $DIR/precedence.rs:53:13 | LL | let _ = -1.0_f64.sin().cos(); | ^^^^^^^^^^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1.0_f64.sin().cos())` diff --git a/tests/ui/print_in_format_impl.rs b/tests/ui/print_in_format_impl.rs index 64e8868660980..deafcbfb8c366 100644 --- a/tests/ui/print_in_format_impl.rs +++ b/tests/ui/print_in_format_impl.rs @@ -1,7 +1,7 @@ #![allow(unused, clippy::print_literal, clippy::write_literal)] #![warn(clippy::print_in_format_impl)] use std::fmt::{Debug, Display, Error, Formatter}; - +//@no-rustfix macro_rules! indirect { () => {{ println!() }}; } diff --git a/tests/ui/print_literal.fixed b/tests/ui/print_literal.fixed new file mode 100644 index 0000000000000..48fe024ef63f7 --- /dev/null +++ b/tests/ui/print_literal.fixed @@ -0,0 +1,45 @@ +#![warn(clippy::print_literal)] +#![allow(clippy::uninlined_format_args)] + +fn main() { + // these should be fine + print!("Hello"); + println!("Hello"); + let world = "world"; + println!("Hello {}", world); + println!("Hello {world}", world = world); + println!("3 in hex is {:X}", 3); + println!("2 + 1 = {:.4}", 3); + println!("2 + 1 = {:5.4}", 3); + println!("Debug test {:?}", "hello, world"); + println!("{0:8} {1:>8}", "hello", "world"); + println!("{1:8} {0:>8}", "hello", "world"); + println!("{foo:8} {bar:>8}", foo = "hello", bar = "world"); + println!("{bar:8} {foo:>8}", foo = "hello", bar = "world"); + println!("{number:>width$}", number = 1, width = 6); + println!("{number:>0width$}", number = 1, width = 6); + println!("{} of {:b} people know binary, the other half doesn't", 1, 2); + println!("10 / 4 is {}", 2.5); + println!("2 + 1 = {}", 3); + println!("From expansion {}", stringify!(not a string literal)); + + // these should throw warnings + print!("Hello world"); + println!("Hello {} world", world); + println!("Hello world"); + println!("a literal {:.4}", 5); + + // positional args don't change the fact + // that we're using a literal -- this should + // throw a warning + println!("hello world"); + println!("world hello"); + + // named args shouldn't change anything either + println!("hello world"); + println!("world hello"); + + // The string literal from `file!()` has a callsite span that isn't marked as coming from an + // expansion + println!("file: {}", file!()); +} diff --git a/tests/ui/print_with_newline.fixed b/tests/ui/print_with_newline.fixed index 6098dea39911b..73e73984cdd2d 100644 --- a/tests/ui/print_with_newline.fixed +++ b/tests/ui/print_with_newline.fixed @@ -1,5 +1,4 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -//@run-rustfix #![allow(clippy::print_literal)] #![warn(clippy::print_with_newline)] diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs index d9c7acc274802..c3ea26ad74efe 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -1,5 +1,4 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// #![allow(clippy::print_literal)] #![warn(clippy::print_with_newline)] diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index b97711e777dd7..f3de601ed84cc 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 - --> $DIR/print_with_newline.rs:8:5 + --> $DIR/print_with_newline.rs:7:5 | LL | print!("Hello/n"); | ^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + println!("Hello"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:9:5 + --> $DIR/print_with_newline.rs:8:5 | LL | print!("Hello {}/n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + println!("Hello {}", "world"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:10:5 + --> $DIR/print_with_newline.rs:9:5 | LL | print!("Hello {} {}/n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + println!("Hello {} {}", "world", "#2"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:11:5 + --> $DIR/print_with_newline.rs:10:5 | LL | print!("{}/n", 1265); | ^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + println!("{}", 1265); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:12:5 + --> $DIR/print_with_newline.rs:11:5 | LL | print!("/n"); | ^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + println!(); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:31:5 + --> $DIR/print_with_newline.rs:30:5 | LL | print!("///n"); // should fail | ^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL + println!("//"); // should fail | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:38:5 + --> $DIR/print_with_newline.rs:37:5 | LL | / print!( LL | | " @@ -87,7 +87,7 @@ LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:42:5 + --> $DIR/print_with_newline.rs:41:5 | LL | / print!( LL | | r" @@ -102,7 +102,7 @@ LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:50:5 + --> $DIR/print_with_newline.rs:49:5 | LL | print!("//r/n"); // should fail | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/println_empty_string.fixed b/tests/ui/println_empty_string.fixed index abf951ae22d64..20811fc753234 100644 --- a/tests/ui/println_empty_string.fixed +++ b/tests/ui/println_empty_string.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::match_single_binding)] fn main() { diff --git a/tests/ui/println_empty_string.rs b/tests/ui/println_empty_string.rs index fd86e2543cc1d..47f7277dce790 100644 --- a/tests/ui/println_empty_string.rs +++ b/tests/ui/println_empty_string.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::match_single_binding)] fn main() { diff --git a/tests/ui/println_empty_string.stderr b/tests/ui/println_empty_string.stderr index 3cc8bb947bd35..eb740abc6b01e 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!` - --> $DIR/println_empty_string.rs:6:5 + --> $DIR/println_empty_string.rs:5:5 | LL | println!(""); | ^^^^^^^^^--^ @@ -9,7 +9,7 @@ LL | println!(""); = note: `-D clippy::println-empty-string` implied by `-D warnings` error: empty string literal in `println!` - --> $DIR/println_empty_string.rs:9:14 + --> $DIR/println_empty_string.rs:8:14 | LL | _ => println!(""), | ^^^^^^^^^--^ @@ -17,7 +17,7 @@ LL | _ => println!(""), | help: remove the empty string error: empty string literal in `eprintln!` - --> $DIR/println_empty_string.rs:13:5 + --> $DIR/println_empty_string.rs:12:5 | LL | eprintln!(""); | ^^^^^^^^^^--^ @@ -25,7 +25,7 @@ LL | eprintln!(""); | help: remove the empty string error: empty string literal in `eprintln!` - --> $DIR/println_empty_string.rs:16:14 + --> $DIR/println_empty_string.rs:15:14 | LL | _ => eprintln!(""), | ^^^^^^^^^^--^ diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index 08075c382a220..be02856b08896 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -7,7 +7,7 @@ clippy::needless_pass_by_ref_mut )] #![warn(clippy::ptr_arg)] - +//@no-rustfix use std::borrow::Cow; use std::path::{Path, PathBuf}; diff --git a/tests/ui/ptr_as_ptr.fixed b/tests/ui/ptr_as_ptr.fixed index 84babb974161d..9d9f80067c990 100644 --- a/tests/ui/ptr_as_ptr.fixed +++ b/tests/ui/ptr_as_ptr.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::ptr_as_ptr)] diff --git a/tests/ui/ptr_as_ptr.rs b/tests/ui/ptr_as_ptr.rs index 34fd76428b229..7fc4368250c3e 100644 --- a/tests/ui/ptr_as_ptr.rs +++ b/tests/ui/ptr_as_ptr.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::ptr_as_ptr)] diff --git a/tests/ui/ptr_as_ptr.stderr b/tests/ui/ptr_as_ptr.stderr index e64f3351505f9..9bd8f9b17d4dd 100644 --- a/tests/ui/ptr_as_ptr.stderr +++ b/tests/ui/ptr_as_ptr.stderr @@ -1,5 +1,5 @@ error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:19:33 + --> $DIR/ptr_as_ptr.rs:18:33 | LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::issue_11278_a::T) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `Box::into_raw(Box::new(o)).cast::>()` @@ -7,37 +7,37 @@ LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::i = note: `-D clippy::ptr-as-ptr` implied by `-D warnings` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:28:13 + --> $DIR/ptr_as_ptr.rs:27:13 | LL | let _ = ptr as *const i32; | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:29:13 + --> $DIR/ptr_as_ptr.rs:28:13 | LL | let _ = mut_ptr as *mut i32; | ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:34:17 + --> $DIR/ptr_as_ptr.rs:33:17 | LL | let _ = *ptr_ptr as *const i32; | ^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(*ptr_ptr).cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:47:25 + --> $DIR/ptr_as_ptr.rs:46:25 | LL | let _: *const i32 = ptr as *const _; | ^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:48:23 + --> $DIR/ptr_as_ptr.rs:47:23 | LL | let _: *mut i32 = mut_ptr as _; | ^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:51:21 + --> $DIR/ptr_as_ptr.rs:50:21 | LL | let _ = inline!($ptr as *const i32); | ^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `$ptr.cast::()` @@ -45,13 +45,13 @@ LL | let _ = inline!($ptr as *const i32); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:72:13 + --> $DIR/ptr_as_ptr.rs:71:13 | LL | let _ = ptr as *const i32; | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::()` error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:73:13 + --> $DIR/ptr_as_ptr.rs:72:13 | LL | let _ = mut_ptr as *mut i32; | ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::()` diff --git a/tests/ui/ptr_cast_constness.fixed b/tests/ui/ptr_cast_constness.fixed index 1ef1809d15305..74bfff8716a19 100644 --- a/tests/ui/ptr_cast_constness.fixed +++ b/tests/ui/ptr_cast_constness.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::ptr_cast_constness)] diff --git a/tests/ui/ptr_cast_constness.rs b/tests/ui/ptr_cast_constness.rs index 2c15cd429daf6..be8de3dcd087b 100644 --- a/tests/ui/ptr_cast_constness.rs +++ b/tests/ui/ptr_cast_constness.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::ptr_cast_constness)] diff --git a/tests/ui/ptr_cast_constness.stderr b/tests/ui/ptr_cast_constness.stderr index 0c3ff863685ba..76a5c7e016583 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 - --> $DIR/ptr_cast_constness.rs:11:41 + --> $DIR/ptr_cast_constness.rs:10:41 | LL | let _: &mut T = std::mem::transmute(p as *mut T); | ^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `p.cast_mut()` @@ -7,37 +7,37 @@ LL | let _: &mut T = std::mem::transmute(p as *mut T); = note: `-D clippy::ptr-cast-constness` implied by `-D warnings` error: `as` casting between raw pointers while changing only its constness - --> $DIR/ptr_cast_constness.rs:12:19 + --> $DIR/ptr_cast_constness.rs:11:19 | 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 - --> $DIR/ptr_cast_constness.rs:27:17 + --> $DIR/ptr_cast_constness.rs:26: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 - --> $DIR/ptr_cast_constness.rs:30:13 + --> $DIR/ptr_cast_constness.rs:29: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 - --> $DIR/ptr_cast_constness.rs:31:13 + --> $DIR/ptr_cast_constness.rs:30: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 - --> $DIR/ptr_cast_constness.rs:60:13 + --> $DIR/ptr_cast_constness.rs:59: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 - --> $DIR/ptr_cast_constness.rs:61:13 + --> $DIR/ptr_cast_constness.rs:60:13 | LL | let _ = mut_ptr as *const u32; | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()` diff --git a/tests/ui/ptr_eq.fixed b/tests/ui/ptr_eq.fixed index d5fa273d41f0b..3ae6df18c0a06 100644 --- a/tests/ui/ptr_eq.fixed +++ b/tests/ui/ptr_eq.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::ptr_eq)] macro_rules! mac { diff --git a/tests/ui/ptr_eq.rs b/tests/ui/ptr_eq.rs index e033366a4aab7..440d5d94a8313 100644 --- a/tests/ui/ptr_eq.rs +++ b/tests/ui/ptr_eq.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::ptr_eq)] macro_rules! mac { diff --git a/tests/ui/ptr_eq.stderr b/tests/ui/ptr_eq.stderr index 45d8c60382b59..3cdc30f970a25 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 - --> $DIR/ptr_eq.rs:20:13 + --> $DIR/ptr_eq.rs:19:13 | LL | let _ = a as *const _ as usize == b as *const _ as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` @@ -7,7 +7,7 @@ LL | let _ = a as *const _ as usize == b as *const _ as usize; = note: `-D clippy::ptr-eq` implied by `-D warnings` error: use `std::ptr::eq` when comparing raw pointers - --> $DIR/ptr_eq.rs:21:13 + --> $DIR/ptr_eq.rs:20:13 | LL | let _ = a as *const _ == b as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` diff --git a/tests/ui/ptr_offset_with_cast.fixed b/tests/ui/ptr_offset_with_cast.fixed index 6ffa401d76172..929512be63d48 100644 --- a/tests/ui/ptr_offset_with_cast.fixed +++ b/tests/ui/ptr_offset_with_cast.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::unnecessary_cast, clippy::useless_vec)] fn main() { diff --git a/tests/ui/ptr_offset_with_cast.rs b/tests/ui/ptr_offset_with_cast.rs index de1f86cb855c6..146bc27765ada 100644 --- a/tests/ui/ptr_offset_with_cast.rs +++ b/tests/ui/ptr_offset_with_cast.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::unnecessary_cast, clippy::useless_vec)] fn main() { diff --git a/tests/ui/ptr_offset_with_cast.stderr b/tests/ui/ptr_offset_with_cast.stderr index 3ba40593d6444..fd45224ca067f 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` - --> $DIR/ptr_offset_with_cast.rs:13:17 + --> $DIR/ptr_offset_with_cast.rs:12:17 | LL | let _ = ptr.offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)` @@ -7,7 +7,7 @@ LL | let _ = ptr.offset(offset_usize as isize); = note: `-D clippy::ptr-offset-with-cast` implied by `-D warnings` error: use of `wrapping_offset` with a `usize` casted to an `isize` - --> $DIR/ptr_offset_with_cast.rs:17:17 + --> $DIR/ptr_offset_with_cast.rs:16:17 | LL | let _ = ptr.wrapping_offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.wrapping_add(offset_usize)` diff --git a/tests/ui/pub_with_shorthand.fixed b/tests/ui/pub_with_shorthand.fixed index a774faa0a673b..f8b8d37120ade 100644 --- a/tests/ui/pub_with_shorthand.fixed +++ b/tests/ui/pub_with_shorthand.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + //@aux-build:proc_macros.rs:proc-macro #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] diff --git a/tests/ui/pub_with_shorthand.rs b/tests/ui/pub_with_shorthand.rs index 4a4bbc18728e9..baaed1edd5018 100644 --- a/tests/ui/pub_with_shorthand.rs +++ b/tests/ui/pub_with_shorthand.rs @@ -1,4 +1,4 @@ -//@run-rustfix + //@aux-build:proc_macros.rs:proc-macro #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] diff --git a/tests/ui/pub_without_shorthand.fixed b/tests/ui/pub_without_shorthand.fixed index fdb49ac4d9065..8730add27de35 100644 --- a/tests/ui/pub_without_shorthand.fixed +++ b/tests/ui/pub_without_shorthand.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + //@aux-build:proc_macros.rs:proc-macro #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] diff --git a/tests/ui/pub_without_shorthand.rs b/tests/ui/pub_without_shorthand.rs index 1f2ef7ece391e..2a0d8bce58299 100644 --- a/tests/ui/pub_without_shorthand.rs +++ b/tests/ui/pub_without_shorthand.rs @@ -1,4 +1,4 @@ -//@run-rustfix + //@aux-build:proc_macros.rs:proc-macro #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] diff --git a/tests/ui/question_mark.fixed b/tests/ui/question_mark.fixed index 20b9e42a7aab0..2ef006c141923 100644 --- a/tests/ui/question_mark.fixed +++ b/tests/ui/question_mark.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(try_blocks)] #![allow(unreachable_code)] #![allow(dead_code)] diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs index 8bdafd46e8fa9..c170669823f3f 100644 --- a/tests/ui/question_mark.rs +++ b/tests/ui/question_mark.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(try_blocks)] #![allow(unreachable_code)] #![allow(dead_code)] diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr index 62489c8c8c479..5dc62fadd8d65 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 - --> $DIR/question_mark.rs:8:5 + --> $DIR/question_mark.rs:7:5 | LL | / if a.is_none() { LL | | return None; @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::question-mark` implied by `-D warnings` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:53:9 + --> $DIR/question_mark.rs:52:9 | LL | / if (self.opt).is_none() { LL | | return None; @@ -17,7 +17,7 @@ LL | | } | |_________^ help: replace it with: `(self.opt)?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:57:9 + --> $DIR/question_mark.rs:56:9 | LL | / if self.opt.is_none() { LL | | return None @@ -25,7 +25,7 @@ LL | | } | |_________^ help: replace it with: `self.opt?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:61:17 + --> $DIR/question_mark.rs:60:17 | LL | let _ = if self.opt.is_none() { | _________________^ @@ -36,7 +36,7 @@ LL | | }; | |_________^ help: replace it with: `Some(self.opt?)` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:67:17 + --> $DIR/question_mark.rs:66:17 | LL | let _ = if let Some(x) = self.opt { | _________________^ @@ -47,7 +47,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:84:9 + --> $DIR/question_mark.rs:83:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -55,7 +55,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:92:9 + --> $DIR/question_mark.rs:91:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -63,7 +63,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:100:9 + --> $DIR/question_mark.rs:99:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -71,7 +71,7 @@ LL | | } | |_________^ help: replace it with: `self.opt.as_ref()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:107:26 + --> $DIR/question_mark.rs:106:26 | LL | let v: &Vec<_> = if let Some(ref v) = self.opt { | __________________________^ @@ -82,7 +82,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt.as_ref()?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:117:17 + --> $DIR/question_mark.rs:116:17 | LL | let v = if let Some(v) = self.opt { | _________________^ @@ -93,7 +93,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:132:5 + --> $DIR/question_mark.rs:131:5 | LL | / if f().is_none() { LL | | return None; @@ -101,13 +101,13 @@ LL | | } | |_____^ help: replace it with: `f()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:144:13 + --> $DIR/question_mark.rs:143: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 - --> $DIR/question_mark.rs:146:5 + --> $DIR/question_mark.rs:145:5 | LL | / if x.is_err() { LL | | return x; @@ -115,7 +115,7 @@ LL | | } | |_____^ help: replace it with: `x?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:214:5 + --> $DIR/question_mark.rs:213:5 | LL | / if let Err(err) = func_returning_result() { LL | | return Err(err); @@ -123,7 +123,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:221:5 + --> $DIR/question_mark.rs:220:5 | LL | / if let Err(err) = func_returning_result() { LL | | return Err(err); @@ -131,7 +131,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:298:13 + --> $DIR/question_mark.rs:297:13 | LL | / if a.is_none() { LL | | return None; diff --git a/tests/ui/range_contains.fixed b/tests/ui/range_contains.fixed index 47c5248118eac..ed248df374d16 100644 --- a/tests/ui/range_contains.fixed +++ b/tests/ui/range_contains.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_range_contains)] #![allow(unused)] #![allow(clippy::no_effect)] diff --git a/tests/ui/range_contains.rs b/tests/ui/range_contains.rs index a35315a649d85..c3188ec6d92be 100644 --- a/tests/ui/range_contains.rs +++ b/tests/ui/range_contains.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_range_contains)] #![allow(unused)] #![allow(clippy::no_effect)] diff --git a/tests/ui/range_contains.stderr b/tests/ui/range_contains.stderr index 1265db695bfb1..ea34023a46645 100644 --- a/tests/ui/range_contains.stderr +++ b/tests/ui/range_contains.stderr @@ -1,5 +1,5 @@ error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:15:5 + --> $DIR/range_contains.rs:13:5 | LL | x >= 8 && x < 12; | ^^^^^^^^^^^^^^^^ help: use: `(8..12).contains(&x)` @@ -7,121 +7,121 @@ LL | x >= 8 && x < 12; = note: `-D clippy::manual-range-contains` implied by `-D warnings` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:16:5 + --> $DIR/range_contains.rs:14:5 | LL | x < 42 && x >= 21; | ^^^^^^^^^^^^^^^^^ help: use: `(21..42).contains(&x)` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:17:5 + --> $DIR/range_contains.rs:15:5 | LL | 100 > x && 1 <= x; | ^^^^^^^^^^^^^^^^^ help: use: `(1..100).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:20:5 + --> $DIR/range_contains.rs:18:5 | LL | x >= 9 && x <= 99; | ^^^^^^^^^^^^^^^^^ help: use: `(9..=99).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:21:5 + --> $DIR/range_contains.rs:19:5 | LL | x <= 33 && x >= 1; | ^^^^^^^^^^^^^^^^^ help: use: `(1..=33).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:22:5 + --> $DIR/range_contains.rs:20:5 | LL | 999 >= x && 1 <= x; | ^^^^^^^^^^^^^^^^^^ help: use: `(1..=999).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:25:5 + --> $DIR/range_contains.rs:23:5 | LL | x < 8 || x >= 12; | ^^^^^^^^^^^^^^^^ help: use: `!(8..12).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:26:5 + --> $DIR/range_contains.rs:24:5 | LL | x >= 42 || x < 21; | ^^^^^^^^^^^^^^^^^ help: use: `!(21..42).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:27:5 + --> $DIR/range_contains.rs:25:5 | LL | 100 <= x || 1 > x; | ^^^^^^^^^^^^^^^^^ help: use: `!(1..100).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:30:5 + --> $DIR/range_contains.rs:28:5 | LL | x < 9 || x > 99; | ^^^^^^^^^^^^^^^ help: use: `!(9..=99).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:31:5 + --> $DIR/range_contains.rs:29:5 | LL | x > 33 || x < 1; | ^^^^^^^^^^^^^^^ help: use: `!(1..=33).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:32:5 + --> $DIR/range_contains.rs:30:5 | LL | 999 < x || 1 > x; | ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:47:5 + --> $DIR/range_contains.rs:45:5 | LL | y >= 0. && y < 1.; | ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:48:5 + --> $DIR/range_contains.rs:46:5 | LL | y < 0. || y > 1.; | ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:51:5 + --> $DIR/range_contains.rs:49:5 | LL | x >= -10 && x <= 10; | ^^^^^^^^^^^^^^^^^^^ help: use: `(-10..=10).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:53:5 + --> $DIR/range_contains.rs:51:5 | LL | y >= -3. && y <= 3.; | ^^^^^^^^^^^^^^^^^^^ help: use: `(-3. ..=3.).contains(&y)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:58:30 + --> $DIR/range_contains.rs:56:30 | LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&z)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:58:5 + --> $DIR/range_contains.rs:56:5 | LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:59:29 + --> $DIR/range_contains.rs:57:29 | LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10); | ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&z)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:59:5 + --> $DIR/range_contains.rs:57:5 | LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10); | ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&x)` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:78:5 + --> $DIR/range_contains.rs:76:5 | LL | x >= 8 && x < 35; | ^^^^^^^^^^^^^^^^ help: use: `(8..35).contains(&x)` diff --git a/tests/ui/range_plus_minus_one.fixed b/tests/ui/range_plus_minus_one.fixed index 79c133cb5e326..e701dde869338 100644 --- a/tests/ui/range_plus_minus_one.fixed +++ b/tests/ui/range_plus_minus_one.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_parens)] #![allow(clippy::iter_with_drain)] fn f() -> usize { diff --git a/tests/ui/range_plus_minus_one.rs b/tests/ui/range_plus_minus_one.rs index 689a6b7a17ce6..7057fa8e3f0d7 100644 --- a/tests/ui/range_plus_minus_one.rs +++ b/tests/ui/range_plus_minus_one.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_parens)] #![allow(clippy::iter_with_drain)] fn f() -> usize { diff --git a/tests/ui/range_plus_minus_one.stderr b/tests/ui/range_plus_minus_one.stderr index 0223696243b20..f92826fb75362 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 - --> $DIR/range_plus_minus_one.rs:31:14 + --> $DIR/range_plus_minus_one.rs:29:14 | LL | for _ in 0..3 + 1 {} | ^^^^^^^^ help: use: `0..=3` @@ -7,25 +7,25 @@ LL | for _ in 0..3 + 1 {} = note: `-D clippy::range-plus-one` implied by `-D warnings` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:34:14 + --> $DIR/range_plus_minus_one.rs:32:14 | LL | for _ in 0..1 + 5 {} | ^^^^^^^^ help: use: `0..=5` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:37:14 + --> $DIR/range_plus_minus_one.rs:35:14 | LL | for _ in 1..1 + 1 {} | ^^^^^^^^ help: use: `1..=1` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:43:14 + --> $DIR/range_plus_minus_one.rs:41:14 | LL | for _ in 0..(1 + f()) {} | ^^^^^^^^^^^^ help: use: `0..=f()` error: an exclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:47:13 + --> $DIR/range_plus_minus_one.rs:45:13 | LL | let _ = ..=11 - 1; | ^^^^^^^^^ help: use: `..11` @@ -33,25 +33,25 @@ LL | let _ = ..=11 - 1; = note: `-D clippy::range-minus-one` implied by `-D warnings` error: an exclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:48:13 + --> $DIR/range_plus_minus_one.rs:46:13 | LL | let _ = ..=(11 - 1); | ^^^^^^^^^^^ help: use: `..11` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:49:13 + --> $DIR/range_plus_minus_one.rs:47:13 | LL | let _ = (1..11 + 1); | ^^^^^^^^^^^ help: use: `(1..=11)` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:50:13 + --> $DIR/range_plus_minus_one.rs:48:13 | LL | let _ = (f() + 1)..(f() + 1); | ^^^^^^^^^^^^^^^^^^^^ help: use: `((f() + 1)..=f())` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:54:14 + --> $DIR/range_plus_minus_one.rs:52:14 | LL | for _ in 1..ONE + ONE {} | ^^^^^^^^^^^^ help: use: `1..=ONE` diff --git a/tests/ui/rc_buffer.fixed b/tests/ui/rc_buffer.fixed index 4cba292c1b73d..35ac95a76a914 100644 --- a/tests/ui/rc_buffer.fixed +++ b/tests/ui/rc_buffer.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::rc_buffer)] #![allow(dead_code, unused_imports)] diff --git a/tests/ui/rc_buffer.rs b/tests/ui/rc_buffer.rs index d8a9aa2786d44..e78fb5a6d9d83 100644 --- a/tests/ui/rc_buffer.rs +++ b/tests/ui/rc_buffer.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::rc_buffer)] #![allow(dead_code, unused_imports)] diff --git a/tests/ui/rc_buffer.stderr b/tests/ui/rc_buffer.stderr index 9ed028e3df41b..d78e39a010d8e 100644 --- a/tests/ui/rc_buffer.stderr +++ b/tests/ui/rc_buffer.stderr @@ -1,5 +1,5 @@ error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:12:11 + --> $DIR/rc_buffer.rs:11:11 | LL | bad1: Rc, | ^^^^^^^^^^ help: try: `Rc` @@ -7,43 +7,43 @@ LL | bad1: Rc, = note: `-D clippy::rc-buffer` implied by `-D warnings` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:13:11 + --> $DIR/rc_buffer.rs:12:11 | LL | bad2: Rc, | ^^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:14:11 + --> $DIR/rc_buffer.rs:13:11 | LL | bad3: Rc>, | ^^^^^^^^^^^ help: try: `Rc<[u8]>` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:15:11 + --> $DIR/rc_buffer.rs:14:11 | LL | bad4: Rc, | ^^^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:21:17 + --> $DIR/rc_buffer.rs:20:17 | LL | fn func_bad1(_: Rc) {} | ^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:22:17 + --> $DIR/rc_buffer.rs:21:17 | LL | fn func_bad2(_: Rc) {} | ^^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:23:17 + --> $DIR/rc_buffer.rs:22:17 | LL | fn func_bad3(_: Rc>) {} | ^^^^^^^^^^^ help: try: `Rc<[u8]>` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:24:17 + --> $DIR/rc_buffer.rs:23:17 | LL | fn func_bad4(_: Rc) {} | ^^^^^^^^^^^^ help: try: `Rc` diff --git a/tests/ui/rc_buffer_arc.fixed b/tests/ui/rc_buffer_arc.fixed index ac51ac9e4675b..0d01c7c476f75 100644 --- a/tests/ui/rc_buffer_arc.fixed +++ b/tests/ui/rc_buffer_arc.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::rc_buffer)] #![allow(dead_code, unused_imports)] diff --git a/tests/ui/rc_buffer_arc.rs b/tests/ui/rc_buffer_arc.rs index 21dc27bc5fa52..61ab16dc18292 100644 --- a/tests/ui/rc_buffer_arc.rs +++ b/tests/ui/rc_buffer_arc.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::rc_buffer)] #![allow(dead_code, unused_imports)] diff --git a/tests/ui/rc_buffer_arc.stderr b/tests/ui/rc_buffer_arc.stderr index 911feea73529d..70d4381151af5 100644 --- a/tests/ui/rc_buffer_arc.stderr +++ b/tests/ui/rc_buffer_arc.stderr @@ -1,5 +1,5 @@ error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:11:11 + --> $DIR/rc_buffer_arc.rs:10:11 | LL | bad1: Arc, | ^^^^^^^^^^^ help: try: `Arc` @@ -7,43 +7,43 @@ LL | bad1: Arc, = note: `-D clippy::rc-buffer` implied by `-D warnings` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:12:11 + --> $DIR/rc_buffer_arc.rs:11:11 | LL | bad2: Arc, | ^^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:13:11 + --> $DIR/rc_buffer_arc.rs:12:11 | LL | bad3: Arc>, | ^^^^^^^^^^^^ help: try: `Arc<[u8]>` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:14:11 + --> $DIR/rc_buffer_arc.rs:13:11 | LL | bad4: Arc, | ^^^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:20:17 + --> $DIR/rc_buffer_arc.rs:19:17 | LL | fn func_bad1(_: Arc) {} | ^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:21:17 + --> $DIR/rc_buffer_arc.rs:20:17 | LL | fn func_bad2(_: Arc) {} | ^^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:22:17 + --> $DIR/rc_buffer_arc.rs:21:17 | LL | fn func_bad3(_: Arc>) {} | ^^^^^^^^^^^^ help: try: `Arc<[u8]>` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:23:17 + --> $DIR/rc_buffer_arc.rs:22:17 | LL | fn func_bad4(_: Arc) {} | ^^^^^^^^^^^^^ help: try: `Arc` diff --git a/tests/ui/rc_clone_in_vec_init/arc.rs b/tests/ui/rc_clone_in_vec_init/arc.rs index 53fcbf3c49b46..9cb7f48e75b54 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.rs +++ b/tests/ui/rc_clone_in_vec_init/arc.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::rc_clone_in_vec_init)] #![allow(clippy::useless_vec)] use std::sync::{Arc, Mutex}; diff --git a/tests/ui/rc_clone_in_vec_init/arc.stderr b/tests/ui/rc_clone_in_vec_init/arc.stderr index a8fd28b84b3a6..3e82d4e57b757 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.stderr +++ b/tests/ui/rc_clone_in_vec_init/arc.stderr @@ -1,5 +1,5 @@ error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:8:13 + --> $DIR/arc.rs:9:13 | LL | let v = vec![Arc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:16:21 + --> $DIR/arc.rs:17:21 | LL | let v = vec![Arc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:22:13 + --> $DIR/arc.rs:23:13 | LL | let v = vec![ | _____________^ @@ -76,7 +76,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:31:14 + --> $DIR/arc.rs:32:14 | LL | let v1 = vec![ | ______________^ diff --git a/tests/ui/rc_clone_in_vec_init/rc.rs b/tests/ui/rc_clone_in_vec_init/rc.rs index 88ea39bf9083f..5b7ac062ddc94 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.rs +++ b/tests/ui/rc_clone_in_vec_init/rc.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::rc_clone_in_vec_init)] #![allow(clippy::useless_vec)] use std::rc::Rc; diff --git a/tests/ui/rc_clone_in_vec_init/rc.stderr b/tests/ui/rc_clone_in_vec_init/rc.stderr index eab464800ca97..278e497480483 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.stderr +++ b/tests/ui/rc_clone_in_vec_init/rc.stderr @@ -1,5 +1,5 @@ error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:9:13 + --> $DIR/rc.rs:10:13 | LL | let v = vec![Rc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:17:21 + --> $DIR/rc.rs:18:21 | LL | let v = vec![Rc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:23:13 + --> $DIR/rc.rs:24:13 | LL | let v = vec![ | _____________^ @@ -76,7 +76,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:32:14 + --> $DIR/rc.rs:33:14 | LL | let v1 = vec![ | ______________^ diff --git a/tests/ui/rc_clone_in_vec_init/weak.rs b/tests/ui/rc_clone_in_vec_init/weak.rs index 03142165057d2..386cccd88f6c2 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.rs +++ b/tests/ui/rc_clone_in_vec_init/weak.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::rc_clone_in_vec_init)] #![allow(clippy::useless_vec)] use std::rc::{Rc, Weak as UnSyncWeak}; diff --git a/tests/ui/rc_clone_in_vec_init/weak.stderr b/tests/ui/rc_clone_in_vec_init/weak.stderr index 1f7a849b18083..ffb78590a0c88 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.stderr +++ b/tests/ui/rc_clone_in_vec_init/weak.stderr @@ -1,5 +1,5 @@ error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:9:13 + --> $DIR/weak.rs:10:13 | LL | let v = vec![SyncWeak::::new(); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:10:14 + --> $DIR/weak.rs:11:14 | LL | let v2 = vec![UnSyncWeak::::new(); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:12:13 + --> $DIR/weak.rs:13:13 | LL | let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:13:13 + --> $DIR/weak.rs:14:13 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:21:21 + --> $DIR/weak.rs:22:21 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -115,7 +115,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:22:22 + --> $DIR/weak.rs:23:22 | LL | let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -138,7 +138,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:28:13 + --> $DIR/weak.rs:29:13 | LL | let v = vec![ | _____________^ @@ -168,7 +168,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:37:14 + --> $DIR/weak.rs:38:14 | LL | let v1 = vec![ | ______________^ diff --git a/tests/ui/read_line_without_trim.fixed b/tests/ui/read_line_without_trim.fixed index cb6aab84e49a8..03a99b17dcee6 100644 --- a/tests/ui/read_line_without_trim.fixed +++ b/tests/ui/read_line_without_trim.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::read_line_without_trim)] diff --git a/tests/ui/read_line_without_trim.rs b/tests/ui/read_line_without_trim.rs index bdc409a701065..65510aea0fd0a 100644 --- a/tests/ui/read_line_without_trim.rs +++ b/tests/ui/read_line_without_trim.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::read_line_without_trim)] diff --git a/tests/ui/read_line_without_trim.stderr b/tests/ui/read_line_without_trim.stderr index f3d7b60425fbb..a7751eb68d837 100644 --- a/tests/ui/read_line_without_trim.stderr +++ b/tests/ui/read_line_without_trim.stderr @@ -1,5 +1,5 @@ error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:14:25 + --> $DIR/read_line_without_trim.rs:12:25 | LL | let _x: i32 = input.parse().unwrap(); | ----- ^^^^^^^ @@ -7,14 +7,14 @@ 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 `.parse()` to fail - --> $DIR/read_line_without_trim.rs:13:5 + --> $DIR/read_line_without_trim.rs:11:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::read-line-without-trim` implied by `-D warnings` error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:18:20 + --> $DIR/read_line_without_trim.rs:16:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -22,13 +22,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 `.parse()` to fail - --> $DIR/read_line_without_trim.rs:17:5 + --> $DIR/read_line_without_trim.rs:15:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:22:20 + --> $DIR/read_line_without_trim.rs:20:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -36,13 +36,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 `.parse()` to fail - --> $DIR/read_line_without_trim.rs:21:5 + --> $DIR/read_line_without_trim.rs:19:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:26:20 + --> $DIR/read_line_without_trim.rs:24:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -50,13 +50,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 `.parse()` to fail - --> $DIR/read_line_without_trim.rs:25:5 + --> $DIR/read_line_without_trim.rs:23:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:30:20 + --> $DIR/read_line_without_trim.rs:28:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ 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 `.parse()` to fail - --> $DIR/read_line_without_trim.rs:29:5 + --> $DIR/read_line_without_trim.rs:27: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 ff2ad8644b49f..979955489b64e 100644 --- a/tests/ui/read_zero_byte_vec.rs +++ b/tests/ui/read_zero_byte_vec.rs @@ -7,7 +7,7 @@ use std::fs::File; use std::io; use std::io::prelude::*; - +//@no-rustfix extern crate futures; use futures::io::{AsyncRead, AsyncReadExt}; use tokio::io::{AsyncRead as TokioAsyncRead, AsyncReadExt as _, AsyncWrite as TokioAsyncWrite, AsyncWriteExt as _}; diff --git a/tests/ui/readonly_write_lock.fixed b/tests/ui/readonly_write_lock.fixed new file mode 100644 index 0000000000000..ae622a4100bf3 --- /dev/null +++ b/tests/ui/readonly_write_lock.fixed @@ -0,0 +1,42 @@ +#![warn(clippy::readonly_write_lock)] + +use std::sync::RwLock; + +fn mutate_i32(x: &mut i32) { + *x += 1; +} + +fn accept_i32(_: i32) {} + +fn main() { + let lock = RwLock::new(42); + let lock2 = RwLock::new(1234); + + { + let writer = lock.read().unwrap(); + dbg!(&writer); + } + + { + let writer = lock.read().unwrap(); + accept_i32(*writer); + } + + { + let mut writer = lock.write().unwrap(); + mutate_i32(&mut writer); + dbg!(&writer); + } + + { + let mut writer = lock.write().unwrap(); + *writer += 1; + } + + { + let mut writer1 = lock.write().unwrap(); + let mut writer2 = lock2.write().unwrap(); + *writer2 += 1; + *writer1 = *writer2; + } +} diff --git a/tests/ui/redundant_allocation_fixable.fixed b/tests/ui/redundant_allocation_fixable.fixed index b97863daf2263..61c989c67a1a4 100644 --- a/tests/ui/redundant_allocation_fixable.fixed +++ b/tests/ui/redundant_allocation_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all)] #![allow(clippy::boxed_local, clippy::needless_pass_by_value)] #![allow(clippy::disallowed_names, unused_variables, dead_code)] diff --git a/tests/ui/redundant_allocation_fixable.rs b/tests/ui/redundant_allocation_fixable.rs index bffb6f8c00020..3ad1e9a978df7 100644 --- a/tests/ui/redundant_allocation_fixable.rs +++ b/tests/ui/redundant_allocation_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all)] #![allow(clippy::boxed_local, clippy::needless_pass_by_value)] #![allow(clippy::disallowed_names, unused_variables, dead_code)] diff --git a/tests/ui/redundant_allocation_fixable.stderr b/tests/ui/redundant_allocation_fixable.stderr index 524ca5bf467dc..2e6e078b24b02 100644 --- a/tests/ui/redundant_allocation_fixable.stderr +++ b/tests/ui/redundant_allocation_fixable.stderr @@ -1,5 +1,5 @@ error: usage of `Box<&T>` - --> $DIR/redundant_allocation_fixable.rs:24:30 + --> $DIR/redundant_allocation_fixable.rs:23:30 | LL | pub fn box_test1(foo: Box<&T>) {} | ^^^^^^^ help: try: `&T` @@ -8,7 +8,7 @@ LL | pub fn box_test1(foo: Box<&T>) {} = note: `-D clippy::redundant-allocation` implied by `-D warnings` error: usage of `Box<&MyStruct>` - --> $DIR/redundant_allocation_fixable.rs:26:27 + --> $DIR/redundant_allocation_fixable.rs:25:27 | LL | pub fn box_test2(foo: Box<&MyStruct>) {} | ^^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -16,7 +16,7 @@ LL | pub fn box_test2(foo: Box<&MyStruct>) {} = note: `&MyStruct` is already a pointer, `Box<&MyStruct>` allocates a pointer on the heap error: usage of `Box<&MyEnum>` - --> $DIR/redundant_allocation_fixable.rs:28:27 + --> $DIR/redundant_allocation_fixable.rs:27:27 | LL | pub fn box_test3(foo: Box<&MyEnum>) {} | ^^^^^^^^^^^^ help: try: `&MyEnum` @@ -24,7 +24,7 @@ LL | pub fn box_test3(foo: Box<&MyEnum>) {} = note: `&MyEnum` is already a pointer, `Box<&MyEnum>` allocates a pointer on the heap error: usage of `Box>` - --> $DIR/redundant_allocation_fixable.rs:32:30 + --> $DIR/redundant_allocation_fixable.rs:31:30 | LL | pub fn box_test5(foo: Box>) {} | ^^^^^^^^^^^ help: try: `Box` @@ -32,7 +32,7 @@ LL | pub fn box_test5(foo: Box>) {} = note: `Box` is already on the heap, `Box>` makes an extra allocation error: usage of `Rc<&T>` - --> $DIR/redundant_allocation_fixable.rs:41:29 + --> $DIR/redundant_allocation_fixable.rs:40:29 | LL | pub fn rc_test1(foo: Rc<&T>) {} | ^^^^^^ help: try: `&T` @@ -40,7 +40,7 @@ LL | pub fn rc_test1(foo: Rc<&T>) {} = note: `&T` is already a pointer, `Rc<&T>` allocates a pointer on the heap error: usage of `Rc<&MyStruct>` - --> $DIR/redundant_allocation_fixable.rs:43:26 + --> $DIR/redundant_allocation_fixable.rs:42:26 | LL | pub fn rc_test2(foo: Rc<&MyStruct>) {} | ^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -48,7 +48,7 @@ LL | pub fn rc_test2(foo: Rc<&MyStruct>) {} = note: `&MyStruct` is already a pointer, `Rc<&MyStruct>` allocates a pointer on the heap error: usage of `Rc<&MyEnum>` - --> $DIR/redundant_allocation_fixable.rs:45:26 + --> $DIR/redundant_allocation_fixable.rs:44:26 | LL | pub fn rc_test3(foo: Rc<&MyEnum>) {} | ^^^^^^^^^^^ help: try: `&MyEnum` @@ -56,7 +56,7 @@ LL | pub fn rc_test3(foo: Rc<&MyEnum>) {} = note: `&MyEnum` is already a pointer, `Rc<&MyEnum>` allocates a pointer on the heap error: usage of `Rc>` - --> $DIR/redundant_allocation_fixable.rs:49:24 + --> $DIR/redundant_allocation_fixable.rs:48:24 | LL | pub fn rc_test6(a: Rc>) {} | ^^^^^^^^^^^^ help: try: `Rc` @@ -64,7 +64,7 @@ LL | pub fn rc_test6(a: Rc>) {} = note: `Rc` is already on the heap, `Rc>` makes an extra allocation error: usage of `Arc<&T>` - --> $DIR/redundant_allocation_fixable.rs:58:30 + --> $DIR/redundant_allocation_fixable.rs:57:30 | LL | pub fn arc_test1(foo: Arc<&T>) {} | ^^^^^^^ help: try: `&T` @@ -72,7 +72,7 @@ LL | pub fn arc_test1(foo: Arc<&T>) {} = note: `&T` is already a pointer, `Arc<&T>` allocates a pointer on the heap error: usage of `Arc<&MyStruct>` - --> $DIR/redundant_allocation_fixable.rs:60:27 + --> $DIR/redundant_allocation_fixable.rs:59:27 | LL | pub fn arc_test2(foo: Arc<&MyStruct>) {} | ^^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -80,7 +80,7 @@ LL | pub fn arc_test2(foo: Arc<&MyStruct>) {} = note: `&MyStruct` is already a pointer, `Arc<&MyStruct>` allocates a pointer on the heap error: usage of `Arc<&MyEnum>` - --> $DIR/redundant_allocation_fixable.rs:62:27 + --> $DIR/redundant_allocation_fixable.rs:61:27 | LL | pub fn arc_test3(foo: Arc<&MyEnum>) {} | ^^^^^^^^^^^^ help: try: `&MyEnum` @@ -88,7 +88,7 @@ LL | pub fn arc_test3(foo: Arc<&MyEnum>) {} = note: `&MyEnum` is already a pointer, `Arc<&MyEnum>` allocates a pointer on the heap error: usage of `Arc>` - --> $DIR/redundant_allocation_fixable.rs:66:25 + --> $DIR/redundant_allocation_fixable.rs:65:25 | LL | pub fn arc_test7(a: Arc>) {} | ^^^^^^^^^^^^^^ help: try: `Arc` diff --git a/tests/ui/redundant_async_block.fixed b/tests/ui/redundant_async_block.fixed index 328958491eebc..d492ea1be753a 100644 --- a/tests/ui/redundant_async_block.fixed +++ b/tests/ui/redundant_async_block.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::manual_async_fn)] #![warn(clippy::redundant_async_block)] diff --git a/tests/ui/redundant_async_block.rs b/tests/ui/redundant_async_block.rs index cd189b31555ca..dd96e14100682 100644 --- a/tests/ui/redundant_async_block.rs +++ b/tests/ui/redundant_async_block.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::manual_async_fn)] #![warn(clippy::redundant_async_block)] diff --git a/tests/ui/redundant_async_block.stderr b/tests/ui/redundant_async_block.stderr index f3dcb09b4440a..0ebd4d2cece7f 100644 --- a/tests/ui/redundant_async_block.stderr +++ b/tests/ui/redundant_async_block.stderr @@ -1,5 +1,5 @@ error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:15:13 + --> $DIR/redundant_async_block.rs:13:13 | LL | let x = async { f.await }; | ^^^^^^^^^^^^^^^^^ help: you can reduce it to: `f` @@ -7,49 +7,49 @@ LL | let x = async { f.await }; = note: `-D clippy::redundant-async-block` implied by `-D warnings` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:22:16 + --> $DIR/redundant_async_block.rs:20:16 | LL | let fut2 = async { fut1.await }; | ^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut1` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:26:16 + --> $DIR/redundant_async_block.rs:24:16 | LL | let fut2 = async move { fut1.await }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut1` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:29:15 + --> $DIR/redundant_async_block.rs:27:15 | LL | let fut = async { async { 42 }.await }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { 42 }` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:45:5 + --> $DIR/redundant_async_block.rs:43:5 | LL | async move { fut.await } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:58:5 + --> $DIR/redundant_async_block.rs:56:5 | LL | async move { fut.await } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:63:5 + --> $DIR/redundant_async_block.rs:61:5 | LL | async { f.await } | ^^^^^^^^^^^^^^^^^ help: you can reduce it to: `f` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:86:5 + --> $DIR/redundant_async_block.rs:84:5 | LL | async { async { f().await + 1 }.await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { f().await + 1 }` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:149:13 + --> $DIR/redundant_async_block.rs:147:13 | LL | async { async { 42 }.await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { 42 }` @@ -60,7 +60,7 @@ LL | mac!() = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:169:13 + --> $DIR/redundant_async_block.rs:167:13 | LL | async { async { $e }.await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { $e }` diff --git a/tests/ui/redundant_at_rest_pattern.fixed b/tests/ui/redundant_at_rest_pattern.fixed index 080cf13b5dac2..96e05fffd8d87 100644 --- a/tests/ui/redundant_at_rest_pattern.fixed +++ b/tests/ui/redundant_at_rest_pattern.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(irrefutable_let_patterns, unused)] #![warn(clippy::redundant_at_rest_pattern)] diff --git a/tests/ui/redundant_at_rest_pattern.rs b/tests/ui/redundant_at_rest_pattern.rs index a8a8028295640..c6d8ad5243df5 100644 --- a/tests/ui/redundant_at_rest_pattern.rs +++ b/tests/ui/redundant_at_rest_pattern.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(irrefutable_let_patterns, unused)] #![warn(clippy::redundant_at_rest_pattern)] diff --git a/tests/ui/redundant_at_rest_pattern.stderr b/tests/ui/redundant_at_rest_pattern.stderr index e2a4d9ffd57cb..008db304daf95 100644 --- a/tests/ui/redundant_at_rest_pattern.stderr +++ b/tests/ui/redundant_at_rest_pattern.stderr @@ -1,5 +1,5 @@ error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:10:12 + --> $DIR/redundant_at_rest_pattern.rs:9:12 | LL | if let [a @ ..] = [()] {} | ^^^^^^^^ help: this is better represented with just the binding: `a` @@ -7,31 +7,31 @@ LL | if let [a @ ..] = [()] {} = note: `-D clippy::redundant-at-rest-pattern` implied by `-D warnings` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:11:12 + --> $DIR/redundant_at_rest_pattern.rs:10:12 | LL | if let [ref a @ ..] = [()] {} | ^^^^^^^^^^^^ help: this is better represented with just the binding: `ref a` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:12:12 + --> $DIR/redundant_at_rest_pattern.rs:11:12 | LL | if let [mut a @ ..] = [()] {} | ^^^^^^^^^^^^ help: this is better represented with just the binding: `mut a` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:13:12 + --> $DIR/redundant_at_rest_pattern.rs:12:12 | LL | if let [ref mut a @ ..] = [()] {} | ^^^^^^^^^^^^^^^^ help: this is better represented with just the binding: `ref mut a` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:15:12 + --> $DIR/redundant_at_rest_pattern.rs:14:12 | LL | if let [a @ ..] = &*v {} | ^^^^^^^^ help: this is better represented with just the binding: `a` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:17:12 + --> $DIR/redundant_at_rest_pattern.rs:16:12 | LL | if let [a @ ..] = s {} | ^^^^^^^^ help: this is better represented with just the binding: `a` diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed index 5037c08ebd5f1..867f5b2101714 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -1,4 +1,3 @@ -//@run-rustfix // rustfix-only-machine-applicable #![feature(lint_reasons)] #![warn(clippy::redundant_clone)] diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs index 501898bf113c8..adcbd01e819ca 100644 --- a/tests/ui/redundant_clone.rs +++ b/tests/ui/redundant_clone.rs @@ -1,4 +1,3 @@ -//@run-rustfix // rustfix-only-machine-applicable #![feature(lint_reasons)] #![warn(clippy::redundant_clone)] diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index 8660c0e1f6a04..a1c09d2b3c79f 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -1,180 +1,180 @@ error: redundant clone - --> $DIR/redundant_clone.rs:16:42 + --> $DIR/redundant_clone.rs:15:42 | LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:16:14 + --> $DIR/redundant_clone.rs:15:14 | LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-clone` implied by `-D warnings` error: redundant clone - --> $DIR/redundant_clone.rs:19:15 + --> $DIR/redundant_clone.rs:18:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:19:14 + --> $DIR/redundant_clone.rs:18:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:22:15 + --> $DIR/redundant_clone.rs:21:15 | LL | let _s = s.to_string(); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:22:14 + --> $DIR/redundant_clone.rs:21:14 | LL | let _s = s.to_string(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:25:15 + --> $DIR/redundant_clone.rs:24:15 | LL | let _s = s.to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:25:14 + --> $DIR/redundant_clone.rs:24:14 | LL | let _s = s.to_owned(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:27:42 + --> $DIR/redundant_clone.rs:26:42 | LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:27:14 + --> $DIR/redundant_clone.rs:26:14 | LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:29:42 + --> $DIR/redundant_clone.rs:28:42 | LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:29:14 + --> $DIR/redundant_clone.rs:28:14 | LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:31:29 + --> $DIR/redundant_clone.rs:30:29 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:31:14 + --> $DIR/redundant_clone.rs:30:14 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:33:29 + --> $DIR/redundant_clone.rs:32:29 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:33:14 + --> $DIR/redundant_clone.rs:32:14 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:44:19 + --> $DIR/redundant_clone.rs:43:19 | LL | let _t = tup.0.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:44:14 + --> $DIR/redundant_clone.rs:43:14 | LL | let _t = tup.0.clone(); | ^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:76:25 + --> $DIR/redundant_clone.rs:75:25 | LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:76:24 + --> $DIR/redundant_clone.rs:75:24 | LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } | ^ error: redundant clone - --> $DIR/redundant_clone.rs:133:15 + --> $DIR/redundant_clone.rs:132:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:133:14 + --> $DIR/redundant_clone.rs:132:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:134:15 + --> $DIR/redundant_clone.rs:133:15 | LL | let _t = t.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:134:14 + --> $DIR/redundant_clone.rs:133:14 | LL | let _t = t.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:144:19 + --> $DIR/redundant_clone.rs:143:19 | LL | let _f = f.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:144:18 + --> $DIR/redundant_clone.rs:143:18 | LL | let _f = f.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:156:14 + --> $DIR/redundant_clone.rs:155:14 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^ help: remove this | note: cloned value is neither consumed nor mutated - --> $DIR/redundant_clone.rs:156:13 + --> $DIR/redundant_clone.rs:155:13 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:210:11 + --> $DIR/redundant_clone.rs:209:11 | LL | foo(&x.clone(), move || { | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:210:10 + --> $DIR/redundant_clone.rs:209:10 | LL | foo(&x.clone(), move || { | ^ diff --git a/tests/ui/redundant_closure_call_fixable.fixed b/tests/ui/redundant_closure_call_fixable.fixed index f3669a669ea1a..bf268d0b5832a 100644 --- a/tests/ui/redundant_closure_call_fixable.fixed +++ b/tests/ui/redundant_closure_call_fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(async_closure)] #![warn(clippy::redundant_closure_call)] #![allow(clippy::redundant_async_block)] diff --git a/tests/ui/redundant_closure_call_fixable.rs b/tests/ui/redundant_closure_call_fixable.rs index db8c7f80df48c..c8a91049d1975 100644 --- a/tests/ui/redundant_closure_call_fixable.rs +++ b/tests/ui/redundant_closure_call_fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(async_closure)] #![warn(clippy::redundant_closure_call)] #![allow(clippy::redundant_async_block)] diff --git a/tests/ui/redundant_closure_call_fixable.stderr b/tests/ui/redundant_closure_call_fixable.stderr index 618f5e071d6b2..a285420ea8f7d 100644 --- a/tests/ui/redundant_closure_call_fixable.stderr +++ b/tests/ui/redundant_closure_call_fixable.stderr @@ -1,5 +1,5 @@ error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:18:13 + --> $DIR/redundant_closure_call_fixable.rs:16:13 | LL | let a = (|| 42)(); | ^^^^^^^^^ help: try doing something like: `42` @@ -7,7 +7,7 @@ LL | let a = (|| 42)(); = note: `-D clippy::redundant-closure-call` implied by `-D warnings` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:19:13 + --> $DIR/redundant_closure_call_fixable.rs:17:13 | LL | let b = (async || { | _____________^ @@ -27,7 +27,7 @@ LL ~ }; | error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:24:13 + --> $DIR/redundant_closure_call_fixable.rs:22:13 | LL | let c = (|| { | _____________^ @@ -47,13 +47,13 @@ LL ~ }; | error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:29:13 + --> $DIR/redundant_closure_call_fixable.rs:27:13 | LL | let d = (async || something().await)(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `async { something().await }` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:38:13 + --> $DIR/redundant_closure_call_fixable.rs:36:13 | LL | (|| m!())() | ^^^^^^^^^^^ help: try doing something like: `m!()` @@ -64,7 +64,7 @@ LL | m2!(); = note: this error originates in the macro `m2` (in Nightly builds, run with -Z macro-backtrace for more info) error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:33:13 + --> $DIR/redundant_closure_call_fixable.rs:31:13 | LL | (|| 0)() | ^^^^^^^^ help: try doing something like: `0` @@ -75,49 +75,49 @@ LL | m2!(); = note: this error originates in the macro `m` which comes from the expansion of the macro `m2` (in Nightly builds, run with -Z macro-backtrace for more info) error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:46:16 + --> $DIR/redundant_closure_call_fixable.rs:44:16 | LL | assert_eq!((|| || 43)()(), 42); | ^^^^^^^^^^^^^^ help: try doing something like: `43` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:55:10 + --> $DIR/redundant_closure_call_fixable.rs:53:10 | LL | dbg!((|| 42)()); | ^^^^^^^^^ help: try doing something like: `42` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:58:13 + --> $DIR/redundant_closure_call_fixable.rs:56:13 | LL | let a = (|| || || 123)(); | ^^^^^^^^^^^^^^^^ help: try doing something like: `(|| || 123)` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:62:13 + --> $DIR/redundant_closure_call_fixable.rs:60:13 | LL | let a = (|| || || || async || 1)()()()()(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `async { 1 }` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:71:13 + --> $DIR/redundant_closure_call_fixable.rs:69:13 | LL | let a = (|| echo!(|| echo!(|| 1)))()()(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `1` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:73:13 + --> $DIR/redundant_closure_call_fixable.rs:71:13 | LL | let a = (|| echo!((|| 123)))()(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `123` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:86:11 + --> $DIR/redundant_closure_call_fixable.rs:84:11 | LL | bar()((|| || 42)()(), 5); | ^^^^^^^^^^^^^^ help: try doing something like: `42` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:87:9 + --> $DIR/redundant_closure_call_fixable.rs:85:9 | LL | foo((|| || 42)()(), 5); | ^^^^^^^^^^^^^^ help: try doing something like: `42` diff --git a/tests/ui/redundant_field_names.fixed b/tests/ui/redundant_field_names.fixed index d2a65399da658..bbe3b38e547bb 100644 --- a/tests/ui/redundant_field_names.fixed +++ b/tests/ui/redundant_field_names.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::redundant_field_names)] #![allow(clippy::extra_unused_type_parameters, clippy::no_effect, dead_code, unused_variables)] diff --git a/tests/ui/redundant_field_names.rs b/tests/ui/redundant_field_names.rs index 605ffd21e2f77..9afa191ce7c70 100644 --- a/tests/ui/redundant_field_names.rs +++ b/tests/ui/redundant_field_names.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::redundant_field_names)] #![allow(clippy::extra_unused_type_parameters, clippy::no_effect, dead_code, unused_variables)] diff --git a/tests/ui/redundant_field_names.stderr b/tests/ui/redundant_field_names.stderr index 00a72c50cf7d0..8bcf33007db6b 100644 --- a/tests/ui/redundant_field_names.stderr +++ b/tests/ui/redundant_field_names.stderr @@ -1,5 +1,5 @@ error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:35:9 + --> $DIR/redundant_field_names.rs:33:9 | LL | gender: gender, | ^^^^^^^^^^^^^^ help: replace it with: `gender` @@ -7,43 +7,43 @@ LL | gender: gender, = note: `-D clippy::redundant-field-names` implied by `-D warnings` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:36:9 + --> $DIR/redundant_field_names.rs:34:9 | LL | age: age, | ^^^^^^^^ help: replace it with: `age` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:57:25 + --> $DIR/redundant_field_names.rs:55:25 | LL | let _ = RangeFrom { start: start }; | ^^^^^^^^^^^^ help: replace it with: `start` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:58:23 + --> $DIR/redundant_field_names.rs:56:23 | LL | let _ = RangeTo { end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:59:21 + --> $DIR/redundant_field_names.rs:57:21 | LL | let _ = Range { start: start, end: end }; | ^^^^^^^^^^^^ help: replace it with: `start` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:59:35 + --> $DIR/redundant_field_names.rs:57:35 | LL | let _ = Range { start: start, end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:61:32 + --> $DIR/redundant_field_names.rs:59:32 | LL | let _ = RangeToInclusive { end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:83:25 + --> $DIR/redundant_field_names.rs:81:25 | LL | let _ = RangeFrom { start: start }; | ^^^^^^^^^^^^ help: replace it with: `start` diff --git a/tests/ui/redundant_guards.fixed b/tests/ui/redundant_guards.fixed index 49d7336ee3717..a3e8bd0890771 100644 --- a/tests/ui/redundant_guards.fixed +++ b/tests/ui/redundant_guards.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(if_let_guard)] #![allow(clippy::no_effect, unused)] diff --git a/tests/ui/redundant_guards.rs b/tests/ui/redundant_guards.rs index 87761010de2ce..dd16a15f5315d 100644 --- a/tests/ui/redundant_guards.rs +++ b/tests/ui/redundant_guards.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(if_let_guard)] #![allow(clippy::no_effect, unused)] diff --git a/tests/ui/redundant_guards.stderr b/tests/ui/redundant_guards.stderr index 5bdf43d23c533..5007723438263 100644 --- a/tests/ui/redundant_guards.stderr +++ b/tests/ui/redundant_guards.stderr @@ -1,5 +1,5 @@ error: redundant guard - --> $DIR/redundant_guards.rs:34:20 + --> $DIR/redundant_guards.rs:33:20 | LL | C(x, y) if let 1 = y => .., | ^^^^^^^^^ @@ -12,7 +12,7 @@ LL + C(x, 1) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:40:20 + --> $DIR/redundant_guards.rs:39:20 | LL | Some(x) if matches!(x, Some(1) if true) => .., | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | Some(Some(1)) if true => .., | ~~~~~~~ ~~~~~~~ error: redundant guard - --> $DIR/redundant_guards.rs:41:20 + --> $DIR/redundant_guards.rs:40:20 | LL | Some(x) if matches!(x, Some(1)) => { | ^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ LL + Some(Some(1)) => { | error: redundant guard - --> $DIR/redundant_guards.rs:45:20 + --> $DIR/redundant_guards.rs:44:20 | LL | Some(x) if let Some(1) = x => .., | ^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL + Some(Some(1)) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:46:20 + --> $DIR/redundant_guards.rs:45:20 | LL | Some(x) if x == Some(2) => .., | ^^^^^^^^^^^^ @@ -59,7 +59,7 @@ LL + Some(Some(2)) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:69:20 + --> $DIR/redundant_guards.rs:68:20 | LL | B { e } if matches!(e, Some(A(2))) => .., | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +71,7 @@ LL + B { e: Some(A(2)) } => .., | error: redundant guard - --> $DIR/redundant_guards.rs:106:20 + --> $DIR/redundant_guards.rs:105:20 | LL | E::A(y) if y == "not from an or pattern" => {}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL + E::A("not from an or pattern") => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:113:14 + --> $DIR/redundant_guards.rs:112:14 | LL | x if matches!(x, Some(0)) => .., | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_pattern_matching_drop_order.fixed b/tests/ui/redundant_pattern_matching_drop_order.fixed index d1134de5ab475..148eaa4b33a67 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.fixed +++ b/tests/ui/redundant_pattern_matching_drop_order.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - // Issue #5746 #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/tests/ui/redundant_pattern_matching_drop_order.rs b/tests/ui/redundant_pattern_matching_drop_order.rs index d144086e791a3..5bc06f3cc529c 100644 --- a/tests/ui/redundant_pattern_matching_drop_order.rs +++ b/tests/ui/redundant_pattern_matching_drop_order.rs @@ -1,5 +1,3 @@ -//@run-rustfix - // Issue #5746 #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/tests/ui/redundant_pattern_matching_drop_order.stderr b/tests/ui/redundant_pattern_matching_drop_order.stderr index 28f33f0c95d70..636d1a292aca2 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, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:17:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:15:12 | LL | if let Ok(_) = m.lock() {} | -------^^^^^----------- help: try: `if m.lock().is_ok()` @@ -9,7 +9,7 @@ LL | if let Ok(_) = m.lock() {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_drop_order.rs:18:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:16:12 | LL | if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {} | -------^^^^^^------------------------------------ help: try: `if Err::<(), _>(m.lock().unwrap().0).is_err()` @@ -18,7 +18,7 @@ LL | if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:21:16 + --> $DIR/redundant_pattern_matching_drop_order.rs:19:16 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()` @@ -27,7 +27,7 @@ LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:23:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:21:12 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) { | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()` @@ -36,31 +36,31 @@ LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) { = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:26:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:24:12 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_drop_order.rs:27:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:25:12 | LL | if let Err(_) = Err::, _>(()) {} | -------^^^^^^------------------------------------------ help: try: `if Err::, _>(()).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:29:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:27:12 | LL | if let Ok(_) = Ok::<_, ()>(String::new()) {} | -------^^^^^----------------------------- help: try: `if Ok::<_, ()>(String::new()).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_drop_order.rs:30:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:28:12 | LL | if let Err(_) = Err::<(), _>((String::new(), ())) {} | -------^^^^^^------------------------------------ help: try: `if Err::<(), _>((String::new(), ())).is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_drop_order.rs:33:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:31:12 | LL | if let Some(_) = Some(m.lock()) {} | -------^^^^^^^----------------- help: try: `if Some(m.lock()).is_some()` @@ -69,7 +69,7 @@ LL | if let Some(_) = Some(m.lock()) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_drop_order.rs:34:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:32:12 | LL | if let Some(_) = Some(m.lock().unwrap().0) {} | -------^^^^^^^---------------------------- help: try: `if Some(m.lock().unwrap().0).is_some()` @@ -78,7 +78,7 @@ LL | if let Some(_) = Some(m.lock().unwrap().0) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_drop_order.rs:37:16 + --> $DIR/redundant_pattern_matching_drop_order.rs:35:16 | LL | if let None = None::> {} | -------^^^^------------------------------------ help: try: `if None::>.is_none()` @@ -87,7 +87,7 @@ LL | if let None = None::> {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_drop_order.rs:39:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:37:12 | LL | if let None = None::> { | -------^^^^------------------------------------ help: try: `if None::>.is_none()` @@ -96,25 +96,25 @@ LL | if let None = None::> { = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_drop_order.rs:43:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:41:12 | LL | if let None = None::> {} | -------^^^^------------------------------------ help: try: `if None::>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_drop_order.rs:45:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:43:12 | LL | if let Some(_) = Some(String::new()) {} | -------^^^^^^^---------------------- help: try: `if Some(String::new()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_drop_order.rs:46:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:44:12 | LL | if let Some(_) = Some((String::new(), ())) {} | -------^^^^^^^---------------------------- help: try: `if Some((String::new(), ())).is_some()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_drop_order.rs:49:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:47:12 | LL | if let Ready(_) = Ready(m.lock()) {} | -------^^^^^^^^------------------ help: try: `if Ready(m.lock()).is_ready()` @@ -123,7 +123,7 @@ LL | if let Ready(_) = Ready(m.lock()) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_drop_order.rs:50:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:48:12 | LL | if let Ready(_) = Ready(m.lock().unwrap().0) {} | -------^^^^^^^^----------------------------- help: try: `if Ready(m.lock().unwrap().0).is_ready()` @@ -132,7 +132,7 @@ LL | if let Ready(_) = Ready(m.lock().unwrap().0) {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_drop_order.rs:53:16 + --> $DIR/redundant_pattern_matching_drop_order.rs:51:16 | LL | if let Pending = Pending::> {} | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` @@ -141,7 +141,7 @@ LL | if let Pending = Pending::> {} = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_drop_order.rs:55:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:53:12 | LL | if let Pending = Pending::> { | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` @@ -150,19 +150,19 @@ LL | if let Pending = Pending::> { = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_drop_order.rs:59:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:57:12 | LL | if let Pending = Pending::> {} | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_drop_order.rs:61:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:59:12 | LL | if let Ready(_) = Ready(String::new()) {} | -------^^^^^^^^----------------------- help: try: `if Ready(String::new()).is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_drop_order.rs:62:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:60:12 | LL | if let Ready(_) = Ready((String::new(), ())) {} | -------^^^^^^^^----------------------------- help: try: `if Ready((String::new(), ())).is_ready()` diff --git a/tests/ui/redundant_pattern_matching_ipaddr.fixed b/tests/ui/redundant_pattern_matching_ipaddr.fixed index 02f197aa26a33..70dd9fc250f77 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.fixed +++ b/tests/ui/redundant_pattern_matching_ipaddr.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all, clippy::redundant_pattern_matching)] #![allow(unused_must_use)] #![allow( diff --git a/tests/ui/redundant_pattern_matching_ipaddr.rs b/tests/ui/redundant_pattern_matching_ipaddr.rs index 5c1e1810f5506..6e2a2f7b6d244 100644 --- a/tests/ui/redundant_pattern_matching_ipaddr.rs +++ b/tests/ui/redundant_pattern_matching_ipaddr.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all, clippy::redundant_pattern_matching)] #![allow(unused_must_use)] #![allow( diff --git a/tests/ui/redundant_pattern_matching_ipaddr.stderr b/tests/ui/redundant_pattern_matching_ipaddr.stderr index bec8d30884d00..f5f5d268a621f 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, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:16:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:15:12 | LL | if let V4(_) = &ipaddr {} | -------^^^^^---------- help: try: `if ipaddr.is_ipv4()` @@ -7,31 +7,31 @@ LL | if let V4(_) = &ipaddr {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:18:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:17:12 | LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:20:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:19:12 | LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:22:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:21:15 | LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:24:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:23:15 | LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:34:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:33:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | V4(_) => true, @@ -40,7 +40,7 @@ LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:39:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:38:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | V4(_) => false, @@ -49,7 +49,7 @@ LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:44:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:43:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | V4(_) => false, @@ -58,7 +58,7 @@ LL | | }; | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:49:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:48:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | V4(_) => true, @@ -67,49 +67,49 @@ LL | | }; | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:54:20 + --> $DIR/redundant_pattern_matching_ipaddr.rs:53:20 | LL | let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) { | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:62:20 + --> $DIR/redundant_pattern_matching_ipaddr.rs:61:20 | LL | let _ = if let V4(_) = gen_ipaddr() { | -------^^^^^--------------- help: try: `if gen_ipaddr().is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:64:19 + --> $DIR/redundant_pattern_matching_ipaddr.rs:63:19 | LL | } else if let V6(_) = gen_ipaddr() { | -------^^^^^--------------- help: try: `if gen_ipaddr().is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:76:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:75:12 | LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:78:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:77:12 | LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | -------^^^^^-------------------------- help: try: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:80:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:79:15 | LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:82:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:81:15 | LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {} | ----------^^^^^-------------------------- help: try: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:84:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:83:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | V4(_) => true, @@ -118,7 +118,7 @@ LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:89:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:88:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | V4(_) => false, diff --git a/tests/ui/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed index d9fcd98c56e00..60f9fb6d493a8 100644 --- a/tests/ui/redundant_pattern_matching_option.fixed +++ b/tests/ui/redundant_pattern_matching_option.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs index cbd9494f15acf..94bbb569c2a8a 100644 --- a/tests/ui/redundant_pattern_matching_option.rs +++ b/tests/ui/redundant_pattern_matching_option.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr index b0e43924dbc9a..73b0353ce34fd 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, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:16:5 + --> $DIR/redundant_pattern_matching_option.rs:14:5 | LL | matches!(maybe_some, None if !boolean) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_some.is_none() && (!boolean)` @@ -7,55 +7,55 @@ LL | matches!(maybe_some, None if !boolean) = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:20:13 + --> $DIR/redundant_pattern_matching_option.rs:18:13 | LL | let _ = matches!(maybe_some, None if boolean || boolean2); // guard needs parentheses | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_some.is_none() && (boolean || boolean2)` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:29:12 + --> $DIR/redundant_pattern_matching_option.rs:27:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:31:12 + --> $DIR/redundant_pattern_matching_option.rs:29:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:33:12 + --> $DIR/redundant_pattern_matching_option.rs:31:12 | LL | if let Some(_) = Some(42) { | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:39:15 + --> $DIR/redundant_pattern_matching_option.rs:37:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:41:15 + --> $DIR/redundant_pattern_matching_option.rs:39:15 | LL | while let None = Some(42) {} | ----------^^^^----------- help: try: `while Some(42).is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:43:15 + --> $DIR/redundant_pattern_matching_option.rs:41:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:46:15 + --> $DIR/redundant_pattern_matching_option.rs:44:15 | LL | while let Some(_) = v.pop() { | ----------^^^^^^^---------- help: try: `while v.pop().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:54:5 + --> $DIR/redundant_pattern_matching_option.rs:52:5 | LL | / match Some(42) { LL | | Some(_) => true, @@ -64,7 +64,7 @@ LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:59:5 + --> $DIR/redundant_pattern_matching_option.rs:57:5 | LL | / match None::<()> { LL | | Some(_) => false, @@ -73,7 +73,7 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:64:13 + --> $DIR/redundant_pattern_matching_option.rs:62:13 | LL | let _ = match None::<()> { | _____________^ @@ -83,55 +83,55 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:70:20 + --> $DIR/redundant_pattern_matching_option.rs:68:20 | LL | let _ = if let Some(_) = opt { true } else { false }; | -------^^^^^^^------ help: try: `if opt.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:76:20 + --> $DIR/redundant_pattern_matching_option.rs:74:20 | LL | let _ = if let Some(_) = gen_opt() { | -------^^^^^^^------------ help: try: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:78:19 + --> $DIR/redundant_pattern_matching_option.rs:76:19 | LL | } else if let None = gen_opt() { | -------^^^^------------ help: try: `if gen_opt().is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:84:12 + --> $DIR/redundant_pattern_matching_option.rs:82:12 | LL | if let Some(..) = gen_opt() {} | -------^^^^^^^^------------ help: try: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:99:12 + --> $DIR/redundant_pattern_matching_option.rs:97:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:101:12 + --> $DIR/redundant_pattern_matching_option.rs:99:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:103:15 + --> $DIR/redundant_pattern_matching_option.rs:101:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:105:15 + --> $DIR/redundant_pattern_matching_option.rs:103:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:107:5 + --> $DIR/redundant_pattern_matching_option.rs:105:5 | LL | / match Some(42) { LL | | Some(_) => true, @@ -140,7 +140,7 @@ LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:112:5 + --> $DIR/redundant_pattern_matching_option.rs:110:5 | LL | / match None::<()> { LL | | Some(_) => false, @@ -149,19 +149,19 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:120:12 + --> $DIR/redundant_pattern_matching_option.rs:118:12 | LL | if let None = *(&None::<()>) {} | -------^^^^----------------- help: try: `if (&None::<()>).is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:121:12 + --> $DIR/redundant_pattern_matching_option.rs:119:12 | LL | if let None = *&None::<()> {} | -------^^^^--------------- help: try: `if (&None::<()>).is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:127:5 + --> $DIR/redundant_pattern_matching_option.rs:125:5 | LL | / match x { LL | | Some(_) => true, @@ -170,7 +170,7 @@ LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:132:5 + --> $DIR/redundant_pattern_matching_option.rs:130:5 | LL | / match x { LL | | None => true, @@ -179,7 +179,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:137:5 + --> $DIR/redundant_pattern_matching_option.rs:135:5 | LL | / match x { LL | | Some(_) => false, @@ -188,7 +188,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:142:5 + --> $DIR/redundant_pattern_matching_option.rs:140:5 | LL | / match x { LL | | None => false, @@ -197,13 +197,13 @@ LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:157:13 + --> $DIR/redundant_pattern_matching_option.rs:155:13 | LL | let _ = matches!(x, Some(_)); | ^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:159:13 + --> $DIR/redundant_pattern_matching_option.rs:157:13 | LL | let _ = matches!(x, None); | ^^^^^^^^^^^^^^^^^ help: try: `x.is_none()` diff --git a/tests/ui/redundant_pattern_matching_poll.fixed b/tests/ui/redundant_pattern_matching_poll.fixed index f739deaf58ea0..718c2f8ea3ddd 100644 --- a/tests/ui/redundant_pattern_matching_poll.fixed +++ b/tests/ui/redundant_pattern_matching_poll.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/tests/ui/redundant_pattern_matching_poll.rs b/tests/ui/redundant_pattern_matching_poll.rs index 88dde02b38b72..daa4761aff5e3 100644 --- a/tests/ui/redundant_pattern_matching_poll.rs +++ b/tests/ui/redundant_pattern_matching_poll.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/tests/ui/redundant_pattern_matching_poll.stderr b/tests/ui/redundant_pattern_matching_poll.stderr index 28d3606c4fb65..6c4603bcf3d83 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, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:17:12 + --> $DIR/redundant_pattern_matching_poll.rs:15:12 | LL | if let Pending = Pending::<()> {} | -------^^^^^^^---------------- help: try: `if Pending::<()>.is_pending()` @@ -7,37 +7,37 @@ LL | if let Pending = Pending::<()> {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:19:12 + --> $DIR/redundant_pattern_matching_poll.rs:17:12 | LL | if let Ready(_) = Ready(42) {} | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:21:12 + --> $DIR/redundant_pattern_matching_poll.rs:19:12 | LL | if let Ready(_) = Ready(42) { | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:27:15 + --> $DIR/redundant_pattern_matching_poll.rs:25:15 | LL | while let Ready(_) = Ready(42) {} | ----------^^^^^^^^------------ help: try: `while Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:29:15 + --> $DIR/redundant_pattern_matching_poll.rs:27:15 | LL | while let Pending = Ready(42) {} | ----------^^^^^^^------------ help: try: `while Ready(42).is_pending()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:31:15 + --> $DIR/redundant_pattern_matching_poll.rs:29:15 | LL | while let Pending = Pending::<()> {} | ----------^^^^^^^---------------- help: try: `while Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:37:5 + --> $DIR/redundant_pattern_matching_poll.rs:35:5 | LL | / match Ready(42) { LL | | Ready(_) => true, @@ -46,7 +46,7 @@ LL | | }; | |_____^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:42:5 + --> $DIR/redundant_pattern_matching_poll.rs:40:5 | LL | / match Pending::<()> { LL | | Ready(_) => false, @@ -55,7 +55,7 @@ LL | | }; | |_____^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:47:13 + --> $DIR/redundant_pattern_matching_poll.rs:45:13 | LL | let _ = match Pending::<()> { | _____________^ @@ -65,49 +65,49 @@ LL | | }; | |_____^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:53:20 + --> $DIR/redundant_pattern_matching_poll.rs:51:20 | LL | let _ = if let Ready(_) = poll { true } else { false }; | -------^^^^^^^^------- help: try: `if poll.is_ready()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:57:20 + --> $DIR/redundant_pattern_matching_poll.rs:55:20 | LL | let _ = if let Ready(_) = gen_poll() { | -------^^^^^^^^------------- help: try: `if gen_poll().is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:59:19 + --> $DIR/redundant_pattern_matching_poll.rs:57:19 | LL | } else if let Pending = gen_poll() { | -------^^^^^^^------------- help: try: `if gen_poll().is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:75:12 + --> $DIR/redundant_pattern_matching_poll.rs:73:12 | LL | if let Ready(_) = Ready(42) {} | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:77:12 + --> $DIR/redundant_pattern_matching_poll.rs:75:12 | LL | if let Pending = Pending::<()> {} | -------^^^^^^^---------------- help: try: `if Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:79:15 + --> $DIR/redundant_pattern_matching_poll.rs:77:15 | LL | while let Ready(_) = Ready(42) {} | ----------^^^^^^^^------------ help: try: `while Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:81:15 + --> $DIR/redundant_pattern_matching_poll.rs:79:15 | LL | while let Pending = Pending::<()> {} | ----------^^^^^^^---------------- help: try: `while Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:83:5 + --> $DIR/redundant_pattern_matching_poll.rs:81:5 | LL | / match Ready(42) { LL | | Ready(_) => true, @@ -116,7 +116,7 @@ LL | | }; | |_____^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:88:5 + --> $DIR/redundant_pattern_matching_poll.rs:86:5 | LL | / match Pending::<()> { LL | | Ready(_) => false, diff --git a/tests/ui/redundant_pattern_matching_result.fixed b/tests/ui/redundant_pattern_matching_result.fixed index 343e0d04340de..9571aaee74248 100644 --- a/tests/ui/redundant_pattern_matching_result.fixed +++ b/tests/ui/redundant_pattern_matching_result.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(deprecated, unused_must_use)] diff --git a/tests/ui/redundant_pattern_matching_result.rs b/tests/ui/redundant_pattern_matching_result.rs index 4d64eafe590c2..4fc65aa70b54a 100644 --- a/tests/ui/redundant_pattern_matching_result.rs +++ b/tests/ui/redundant_pattern_matching_result.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(deprecated, unused_must_use)] diff --git a/tests/ui/redundant_pattern_matching_result.stderr b/tests/ui/redundant_pattern_matching_result.stderr index 2b1ce9f54652b..4467e8e81073d 100644 --- a/tests/ui/redundant_pattern_matching_result.stderr +++ b/tests/ui/redundant_pattern_matching_result.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:16:12 + --> $DIR/redundant_pattern_matching_result.rs:15:12 | LL | if let Ok(_) = &result {} | -------^^^^^---------- help: try: `if result.is_ok()` @@ -7,31 +7,31 @@ LL | if let Ok(_) = &result {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:18:12 + --> $DIR/redundant_pattern_matching_result.rs:17:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try: `if Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:20:12 + --> $DIR/redundant_pattern_matching_result.rs:19:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:22:15 + --> $DIR/redundant_pattern_matching_result.rs:21:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:24:15 + --> $DIR/redundant_pattern_matching_result.rs:23:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:34:5 + --> $DIR/redundant_pattern_matching_result.rs:33:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -40,7 +40,7 @@ LL | | }; | |_____^ help: try: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:39:5 + --> $DIR/redundant_pattern_matching_result.rs:38:5 | LL | / match Ok::(42) { LL | | Ok(_) => false, @@ -49,7 +49,7 @@ LL | | }; | |_____^ help: try: `Ok::(42).is_err()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:44:5 + --> $DIR/redundant_pattern_matching_result.rs:43:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -58,7 +58,7 @@ LL | | }; | |_____^ help: try: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:49:5 + --> $DIR/redundant_pattern_matching_result.rs:48:5 | LL | / match Err::(42) { LL | | Ok(_) => true, @@ -67,73 +67,73 @@ LL | | }; | |_____^ help: try: `Err::(42).is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:54:20 + --> $DIR/redundant_pattern_matching_result.rs:53:20 | LL | let _ = if let Ok(_) = Ok::(4) { true } else { false }; | -------^^^^^--------------------- help: try: `if Ok::(4).is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:62:20 + --> $DIR/redundant_pattern_matching_result.rs:61:20 | LL | let _ = if let Ok(_) = gen_res() { | -------^^^^^------------ help: try: `if gen_res().is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:64:19 + --> $DIR/redundant_pattern_matching_result.rs:63:19 | LL | } else if let Err(_) = gen_res() { | -------^^^^^^------------ help: try: `if gen_res().is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:87:19 + --> $DIR/redundant_pattern_matching_result.rs:86:19 | LL | while let Some(_) = r#try!(result_opt()) {} | ----------^^^^^^^----------------------- help: try: `while r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:88:16 + --> $DIR/redundant_pattern_matching_result.rs:87:16 | LL | if let Some(_) = r#try!(result_opt()) {} | -------^^^^^^^----------------------- help: try: `if r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:94:12 + --> $DIR/redundant_pattern_matching_result.rs:93:12 | LL | if let Some(_) = m!() {} | -------^^^^^^^------- help: try: `if m!().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_result.rs:95:15 + --> $DIR/redundant_pattern_matching_result.rs:94:15 | LL | while let Some(_) = m!() {} | ----------^^^^^^^------- help: try: `while m!().is_some()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:113:12 + --> $DIR/redundant_pattern_matching_result.rs:112:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try: `if Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:115:12 + --> $DIR/redundant_pattern_matching_result.rs:114:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:117:15 + --> $DIR/redundant_pattern_matching_result.rs:116:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:119:15 + --> $DIR/redundant_pattern_matching_result.rs:118:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:121:5 + --> $DIR/redundant_pattern_matching_result.rs:120:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -142,7 +142,7 @@ LL | | }; | |_____^ help: try: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:126:5 + --> $DIR/redundant_pattern_matching_result.rs:125:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -151,7 +151,7 @@ LL | | }; | |_____^ help: try: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:136:5 + --> $DIR/redundant_pattern_matching_result.rs:135:5 | LL | / match x { LL | | Ok(_) => true, @@ -160,7 +160,7 @@ LL | | }; | |_____^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:141:5 + --> $DIR/redundant_pattern_matching_result.rs:140:5 | LL | / match x { LL | | Ok(_) => false, @@ -169,7 +169,7 @@ LL | | }; | |_____^ help: try: `x.is_err()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:146:5 + --> $DIR/redundant_pattern_matching_result.rs:145:5 | LL | / match x { LL | | Err(_) => true, @@ -178,7 +178,7 @@ LL | | }; | |_____^ help: try: `x.is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:151:5 + --> $DIR/redundant_pattern_matching_result.rs:150:5 | LL | / match x { LL | | Err(_) => false, @@ -187,13 +187,13 @@ LL | | }; | |_____^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:172:13 + --> $DIR/redundant_pattern_matching_result.rs:171:13 | LL | let _ = matches!(x, Ok(_)); | ^^^^^^^^^^^^^^^^^^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:174:13 + --> $DIR/redundant_pattern_matching_result.rs:173:13 | LL | let _ = matches!(x, Err(_)); | ^^^^^^^^^^^^^^^^^^^ help: try: `x.is_err()` diff --git a/tests/ui/redundant_pub_crate.fixed b/tests/ui/redundant_pub_crate.fixed index a1ed491bbc6e4..e1d845721a9c9 100644 --- a/tests/ui/redundant_pub_crate.fixed +++ b/tests/ui/redundant_pub_crate.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::redundant_pub_crate)] diff --git a/tests/ui/redundant_pub_crate.rs b/tests/ui/redundant_pub_crate.rs index 9accd297fc936..4d7f44892d0c5 100644 --- a/tests/ui/redundant_pub_crate.rs +++ b/tests/ui/redundant_pub_crate.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::redundant_pub_crate)] diff --git a/tests/ui/redundant_pub_crate.stderr b/tests/ui/redundant_pub_crate.stderr index 6fccdaa4e2037..f8c7d7a9e69e3 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 - --> $DIR/redundant_pub_crate.rs:7:5 + --> $DIR/redundant_pub_crate.rs:6:5 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -9,7 +9,7 @@ LL | pub(crate) fn g() {} // private due to m1 = note: `-D clippy::redundant-pub-crate` implied by `-D warnings` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:12:9 + --> $DIR/redundant_pub_crate.rs:11:9 | LL | pub(crate) fn g() {} // private due to m1_1 and m1 | ----------^^^^^ @@ -17,7 +17,7 @@ LL | pub(crate) fn g() {} // private due to m1_1 and m1 | help: consider using: `pub` error: pub(crate) module inside private module - --> $DIR/redundant_pub_crate.rs:16:5 + --> $DIR/redundant_pub_crate.rs:15:5 | LL | pub(crate) mod m1_2 { | ----------^^^^^^^^^ @@ -25,7 +25,7 @@ LL | pub(crate) mod m1_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:19:9 + --> $DIR/redundant_pub_crate.rs:18:9 | LL | pub(crate) fn g() {} // private due to m1_2 and m1 | ----------^^^^^ @@ -33,7 +33,7 @@ LL | pub(crate) fn g() {} // private due to m1_2 and m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:25:9 + --> $DIR/redundant_pub_crate.rs:24:9 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -41,7 +41,7 @@ LL | pub(crate) fn g() {} // private due to m1 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:32:5 + --> $DIR/redundant_pub_crate.rs:31:5 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -49,7 +49,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:37:9 + --> $DIR/redundant_pub_crate.rs:36:9 | LL | pub(crate) fn g() {} // private due to m2_1 | ----------^^^^^ @@ -57,7 +57,7 @@ LL | pub(crate) fn g() {} // private due to m2_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> $DIR/redundant_pub_crate.rs:41:5 + --> $DIR/redundant_pub_crate.rs:40:5 | LL | pub(crate) mod m2_2 { | ----------^^^^^^^^^ @@ -65,7 +65,7 @@ LL | pub(crate) mod m2_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:44:9 + --> $DIR/redundant_pub_crate.rs:43:9 | LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | ----------^^^^^ @@ -73,7 +73,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 - --> $DIR/redundant_pub_crate.rs:50:9 + --> $DIR/redundant_pub_crate.rs:49:9 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -81,7 +81,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m2 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:62:9 + --> $DIR/redundant_pub_crate.rs:61:9 | LL | pub(crate) fn g() {} // private due to m3_1 | ----------^^^^^ @@ -89,7 +89,7 @@ LL | pub(crate) fn g() {} // private due to m3_1 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:69:9 + --> $DIR/redundant_pub_crate.rs:68:9 | LL | pub(crate) fn g() {} // already crate visible due to m3_2 | ----------^^^^^ @@ -97,7 +97,7 @@ LL | pub(crate) fn g() {} // already crate visible due to m3_2 | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:82:5 + --> $DIR/redundant_pub_crate.rs:81:5 | LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | ----------^^^^^ @@ -105,7 +105,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 - --> $DIR/redundant_pub_crate.rs:87:9 + --> $DIR/redundant_pub_crate.rs:86:9 | LL | pub(crate) fn g() {} // private due to m4_1 | ----------^^^^^ @@ -113,7 +113,7 @@ LL | pub(crate) fn g() {} // private due to m4_1 | help: consider using: `pub` error: pub(crate) module inside private module - --> $DIR/redundant_pub_crate.rs:91:5 + --> $DIR/redundant_pub_crate.rs:90:5 | LL | pub(crate) mod m4_2 { | ----------^^^^^^^^^ @@ -121,7 +121,7 @@ LL | pub(crate) mod m4_2 { | help: consider using: `pub` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:94:9 + --> $DIR/redundant_pub_crate.rs:93:9 | LL | pub(crate) fn g() {} // private due to m4_2 | ----------^^^^^ diff --git a/tests/ui/redundant_slicing.fixed b/tests/ui/redundant_slicing.fixed index 56ddca71903e4..a4c035ba8407f 100644 --- a/tests/ui/redundant_slicing.fixed +++ b/tests/ui/redundant_slicing.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::deref_by_slicing)] #![warn(clippy::redundant_slicing)] diff --git a/tests/ui/redundant_slicing.rs b/tests/ui/redundant_slicing.rs index d67b6665e2604..67fe702acf547 100644 --- a/tests/ui/redundant_slicing.rs +++ b/tests/ui/redundant_slicing.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::deref_by_slicing)] #![warn(clippy::redundant_slicing)] diff --git a/tests/ui/redundant_slicing.stderr b/tests/ui/redundant_slicing.stderr index 82367143c07fa..e0db72765a8da 100644 --- a/tests/ui/redundant_slicing.stderr +++ b/tests/ui/redundant_slicing.stderr @@ -1,5 +1,5 @@ error: redundant slicing of the whole range - --> $DIR/redundant_slicing.rs:10:13 + --> $DIR/redundant_slicing.rs:8:13 | LL | let _ = &slice[..]; // Redundant slice | ^^^^^^^^^^ help: use the original value instead: `slice` @@ -7,13 +7,13 @@ LL | let _ = &slice[..]; // Redundant slice = note: `-D clippy::redundant-slicing` implied by `-D warnings` error: redundant slicing of the whole range - --> $DIR/redundant_slicing.rs:14:13 + --> $DIR/redundant_slicing.rs:12:13 | LL | let _ = &(&*v)[..]; // Outer borrow is redundant | ^^^^^^^^^^ help: use the original value instead: `(&*v)` error: redundant slicing of the whole range - --> $DIR/redundant_slicing.rs:31:13 + --> $DIR/redundant_slicing.rs:29:13 | LL | let _ = &m!(slice)[..]; | ^^^^^^^^^^^^^^ help: use the original value instead: `slice` diff --git a/tests/ui/redundant_static_lifetimes.fixed b/tests/ui/redundant_static_lifetimes.fixed index a83699ec68da7..9787bb635e709 100644 --- a/tests/ui/redundant_static_lifetimes.fixed +++ b/tests/ui/redundant_static_lifetimes.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #[derive(Debug)] diff --git a/tests/ui/redundant_static_lifetimes.rs b/tests/ui/redundant_static_lifetimes.rs index b165cbaa3aa16..b5a4827fa948e 100644 --- a/tests/ui/redundant_static_lifetimes.rs +++ b/tests/ui/redundant_static_lifetimes.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #[derive(Debug)] diff --git a/tests/ui/redundant_static_lifetimes.stderr b/tests/ui/redundant_static_lifetimes.stderr index a13e5eadf15dd..3e344fc67f92c 100644 --- a/tests/ui/redundant_static_lifetimes.stderr +++ b/tests/ui/redundant_static_lifetimes.stderr @@ -1,5 +1,5 @@ error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:8:17 + --> $DIR/redundant_static_lifetimes.rs:6:17 | LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removing 'static. | -^^^^^^^---- help: consider removing `'static`: `&str` @@ -7,103 +7,103 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removi = note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:12:21 + --> $DIR/redundant_static_lifetimes.rs:10:21 | LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:14:32 + --> $DIR/redundant_static_lifetimes.rs:12:32 | LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:14:47 + --> $DIR/redundant_static_lifetimes.rs:12:47 | LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:16:17 + --> $DIR/redundant_static_lifetimes.rs:14:17 | LL | const VAR_SIX: &'static u8 = &5; | -^^^^^^^--- help: consider removing `'static`: `&u8` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:18:20 + --> $DIR/redundant_static_lifetimes.rs:16:20 | LL | const VAR_HEIGHT: &'static Foo = &Foo {}; | -^^^^^^^---- help: consider removing `'static`: `&Foo` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:20:19 + --> $DIR/redundant_static_lifetimes.rs:18:19 | LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR: Consider removing 'static. | -^^^^^^^----- help: consider removing `'static`: `&[u8]` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:22:19 + --> $DIR/redundant_static_lifetimes.rs:20:19 | LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static. | -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:24:19 + --> $DIR/redundant_static_lifetimes.rs:22:19 | LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static. | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:26:25 + --> $DIR/redundant_static_lifetimes.rs:24:25 | LL | static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR: Consider removing 'static. | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:30:29 + --> $DIR/redundant_static_lifetimes.rs:28:29 | LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:32:25 + --> $DIR/redundant_static_lifetimes.rs:30:25 | LL | static STATIC_VAR_SIX: &'static u8 = &5; | -^^^^^^^--- help: consider removing `'static`: `&u8` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:34:28 + --> $DIR/redundant_static_lifetimes.rs:32:28 | LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {}; | -^^^^^^^---- help: consider removing `'static`: `&Foo` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:36:27 + --> $DIR/redundant_static_lifetimes.rs:34:27 | LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR: Consider removing 'static. | -^^^^^^^----- help: consider removing `'static`: `&[u8]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:38:27 + --> $DIR/redundant_static_lifetimes.rs:36:27 | LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static. | -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:40:27 + --> $DIR/redundant_static_lifetimes.rs:38:27 | LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static. | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:42:31 + --> $DIR/redundant_static_lifetimes.rs:40:31 | LL | static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0]; | -^^^^^^^---------- help: consider removing `'static`: `&mut [u32]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:71:16 + --> $DIR/redundant_static_lifetimes.rs:69:16 | LL | static V: &'static u8 = &17; | -^^^^^^^--- help: consider removing `'static`: `&u8` diff --git a/tests/ui/redundant_static_lifetimes_multiple.rs b/tests/ui/redundant_static_lifetimes_multiple.rs index b3f263a7d66d8..abaa146010c90 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.rs +++ b/tests/ui/redundant_static_lifetimes_multiple.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions // these are rustfixable, but run-rustfix tests cannot handle them const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static diff --git a/tests/ui/redundant_static_lifetimes_multiple.stderr b/tests/ui/redundant_static_lifetimes_multiple.stderr index 4e7500903f811..0ef9841e90620 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.stderr +++ b/tests/ui/redundant_static_lifetimes_multiple.stderr @@ -1,5 +1,5 @@ error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:3:18 + --> $DIR/redundant_static_lifetimes_multiple.rs:4:18 | LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` @@ -7,55 +7,55 @@ LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; = note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:3:30 + --> $DIR/redundant_static_lifetimes_multiple.rs:4:30 | LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:5:29 + --> $DIR/redundant_static_lifetimes_multiple.rs:6:29 | LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:5:39 + --> $DIR/redundant_static_lifetimes_multiple.rs:6:39 | LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:7:40 + --> $DIR/redundant_static_lifetimes_multiple.rs:8:40 | LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:7:55 + --> $DIR/redundant_static_lifetimes_multiple.rs:8:55 | LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:9:26 + --> $DIR/redundant_static_lifetimes_multiple.rs:10:26 | LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:9:38 + --> $DIR/redundant_static_lifetimes_multiple.rs:10:38 | LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:11:37 + --> $DIR/redundant_static_lifetimes_multiple.rs:12:37 | LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:11:47 + --> $DIR/redundant_static_lifetimes_multiple.rs:12:47 | LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^---- help: consider removing `'static`: `&str` diff --git a/tests/ui/ref_binding_to_reference.rs b/tests/ui/ref_binding_to_reference.rs index c8d0e56b197f4..b14ae6841e908 100644 --- a/tests/ui/ref_binding_to_reference.rs +++ b/tests/ui/ref_binding_to_reference.rs @@ -1,5 +1,5 @@ // FIXME: run-rustfix waiting on multi-span suggestions - +//@no-rustfix #![feature(lint_reasons)] #![warn(clippy::ref_binding_to_reference)] #![allow(clippy::needless_borrowed_reference, clippy::explicit_auto_deref)] diff --git a/tests/ui/ref_option_ref.rs b/tests/ui/ref_option_ref.rs index e487799e15220..9c766ca329215 100644 --- a/tests/ui/ref_option_ref.rs +++ b/tests/ui/ref_option_ref.rs @@ -1,6 +1,6 @@ #![allow(unused)] #![warn(clippy::ref_option_ref)] - +//@no-rustfix // This lint is not tagged as run-rustfix because automatically // changing the type of a variable would also means changing // all usages of this variable to match and This is not handled diff --git a/tests/ui/rename.fixed b/tests/ui/rename.fixed index e78b9e5c9c12e..0fd68eb92b1f2 100644 --- a/tests/ui/rename.fixed +++ b/tests/ui/rename.fixed @@ -2,8 +2,6 @@ // Use that command to update this file and do not edit by hand. // Manual edits will be overwritten. -//@run-rustfix - #![allow(clippy::almost_complete_range)] #![allow(clippy::disallowed_names)] #![allow(clippy::blocks_in_if_conditions)] diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index 2e6ef60cb7984..927937fba83a9 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -2,8 +2,6 @@ // Use that command to update this file and do not edit by hand. // Manual edits will be overwritten. -//@run-rustfix - #![allow(clippy::almost_complete_range)] #![allow(clippy::disallowed_names)] #![allow(clippy::blocks_in_if_conditions)] diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index 57e991e5695a1..2b26af16bad50 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,319 +7,319 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::unwrap_or_else_default` has been renamed to `clippy::unwrap_or_default` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::unwrap_or_else_default)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_or_default` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::cast_ref_to_mut` has been renamed to `invalid_reference_casting` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::cast_ref_to_mut)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_reference_casting` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::cmp_nan` has been renamed to `invalid_nan_comparisons` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::cmp_nan)] | ^^^^^^^^^^^^^^^ help: use the new name: `invalid_nan_comparisons` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:91:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:92:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> $DIR/rename.rs:93:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> $DIR/rename.rs:94:9 + --> $DIR/rename.rs:92:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks` - --> $DIR/rename.rs:95:9 + --> $DIR/rename.rs:93:9 | LL | #![warn(clippy::fn_null_check)] | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:96:9 + --> $DIR/rename.rs:94:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:97:9 + --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:98:9 + --> $DIR/rename.rs:96:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` - --> $DIR/rename.rs:99:9 + --> $DIR/rename.rs:97:9 | LL | #![warn(clippy::invalid_utf8_in_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:100:9 + --> $DIR/rename.rs:98:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:101:9 + --> $DIR/rename.rs:99:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:102:9 + --> $DIR/rename.rs:100:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:103:9 + --> $DIR/rename.rs:101:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:104:9 + --> $DIR/rename.rs:102:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops` - --> $DIR/rename.rs:105:9 + --> $DIR/rename.rs:103:9 | LL | #![warn(clippy::undropped_manually_drops)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:106:9 + --> $DIR/rename.rs:104:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:107:9 + --> $DIR/rename.rs:105:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` diff --git a/tests/ui/renamed_builtin_attr.fixed b/tests/ui/renamed_builtin_attr.fixed index 0334c1e1a29c5..bc055215708f0 100644 --- a/tests/ui/renamed_builtin_attr.fixed +++ b/tests/ui/renamed_builtin_attr.fixed @@ -1,4 +1,2 @@ -//@run-rustfix - #[clippy::cognitive_complexity = "1"] fn main() {} diff --git a/tests/ui/renamed_builtin_attr.rs b/tests/ui/renamed_builtin_attr.rs index d350370c2449d..fdb425363e817 100644 --- a/tests/ui/renamed_builtin_attr.rs +++ b/tests/ui/renamed_builtin_attr.rs @@ -1,4 +1,2 @@ -//@run-rustfix - #[clippy::cyclomatic_complexity = "1"] fn main() {} diff --git a/tests/ui/renamed_builtin_attr.stderr b/tests/ui/renamed_builtin_attr.stderr index 8804676248356..636d88fcd69c6 100644 --- a/tests/ui/renamed_builtin_attr.stderr +++ b/tests/ui/renamed_builtin_attr.stderr @@ -1,5 +1,5 @@ error: usage of deprecated attribute - --> $DIR/renamed_builtin_attr.rs:3:11 + --> $DIR/renamed_builtin_attr.rs:1:11 | LL | #[clippy::cyclomatic_complexity = "1"] | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `cognitive_complexity` diff --git a/tests/ui/repeat_once.fixed b/tests/ui/repeat_once.fixed index c517bfcc6aa93..72e97350a0c89 100644 --- a/tests/ui/repeat_once.fixed +++ b/tests/ui/repeat_once.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::repeat_once)] #[allow(unused, clippy::redundant_clone)] fn main() { diff --git a/tests/ui/repeat_once.rs b/tests/ui/repeat_once.rs index 9a30b47418ffd..7557c4d0bd417 100644 --- a/tests/ui/repeat_once.rs +++ b/tests/ui/repeat_once.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::repeat_once)] #[allow(unused, clippy::redundant_clone)] fn main() { diff --git a/tests/ui/repeat_once.stderr b/tests/ui/repeat_once.stderr index 915eea3bfc6b8..ae5258d4c2fbd 100644 --- a/tests/ui/repeat_once.stderr +++ b/tests/ui/repeat_once.stderr @@ -1,5 +1,5 @@ error: calling `repeat(1)` on slice - --> $DIR/repeat_once.rs:10:13 + --> $DIR/repeat_once.rs:9:13 | LL | let a = [1; 5].repeat(1); | ^^^^^^^^^^^^^^^^ help: consider using `.to_vec()` instead: `[1; 5].to_vec()` @@ -7,31 +7,31 @@ LL | let a = [1; 5].repeat(1); = note: `-D clippy::repeat-once` implied by `-D warnings` error: calling `repeat(1)` on slice - --> $DIR/repeat_once.rs:11:13 + --> $DIR/repeat_once.rs:10:13 | LL | let b = slice.repeat(1); | ^^^^^^^^^^^^^^^ help: consider using `.to_vec()` instead: `slice.to_vec()` error: calling `repeat(1)` on str - --> $DIR/repeat_once.rs:12:13 + --> $DIR/repeat_once.rs:11:13 | LL | let c = "hello".repeat(N); | ^^^^^^^^^^^^^^^^^ help: consider using `.to_string()` instead: `"hello".to_string()` error: calling `repeat(1)` on str - --> $DIR/repeat_once.rs:13:13 + --> $DIR/repeat_once.rs:12:13 | LL | let d = "hi".repeat(1); | ^^^^^^^^^^^^^^ help: consider using `.to_string()` instead: `"hi".to_string()` error: calling `repeat(1)` on str - --> $DIR/repeat_once.rs:14:13 + --> $DIR/repeat_once.rs:13:13 | LL | let e = s.repeat(1); | ^^^^^^^^^^^ help: consider using `.to_string()` instead: `s.to_string()` error: calling `repeat(1)` on a string literal - --> $DIR/repeat_once.rs:15:13 + --> $DIR/repeat_once.rs:14:13 | LL | let f = string.repeat(1); | ^^^^^^^^^^^^^^^^ help: consider using `.clone()` instead: `string.clone()` diff --git a/tests/ui/repl_uninit.rs b/tests/ui/repl_uninit.rs index 6c7e2b854dc14..f15b58e28de2e 100644 --- a/tests/ui/repl_uninit.rs +++ b/tests/ui/repl_uninit.rs @@ -1,6 +1,6 @@ #![allow(deprecated, invalid_value, clippy::uninit_assumed_init)] #![warn(clippy::mem_replace_with_uninit)] - +//@no-rustfix use std::mem; fn might_panic(x: X) -> X { diff --git a/tests/ui/result_map_or_into_option.fixed b/tests/ui/result_map_or_into_option.fixed index 6850eeb7a4cdb..fb2db6cf5ec03 100644 --- a/tests/ui/result_map_or_into_option.fixed +++ b/tests/ui/result_map_or_into_option.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::result_map_or_into_option)] fn main() { diff --git a/tests/ui/result_map_or_into_option.rs b/tests/ui/result_map_or_into_option.rs index 8e15181440782..06779a6992586 100644 --- a/tests/ui/result_map_or_into_option.rs +++ b/tests/ui/result_map_or_into_option.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::result_map_or_into_option)] fn main() { diff --git a/tests/ui/result_map_or_into_option.stderr b/tests/ui/result_map_or_into_option.stderr index febf32147d132..2b057042aee24 100644 --- a/tests/ui/result_map_or_into_option.stderr +++ b/tests/ui/result_map_or_into_option.stderr @@ -1,5 +1,5 @@ error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead - --> $DIR/result_map_or_into_option.rs:7:13 + --> $DIR/result_map_or_into_option.rs:5:13 | LL | let _ = opt.map_or(None, Some); | ^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()` diff --git a/tests/ui/result_map_unit_fn_fixable.fixed b/tests/ui/result_map_unit_fn_fixable.fixed index 0583d29277b35..3890f916b606e 100644 --- a/tests/ui/result_map_unit_fn_fixable.fixed +++ b/tests/ui/result_map_unit_fn_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::result_map_unit_fn)] #![allow(unused)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/result_map_unit_fn_fixable.rs b/tests/ui/result_map_unit_fn_fixable.rs index 7ad3bdd04bd6d..c3f5aca7bfbeb 100644 --- a/tests/ui/result_map_unit_fn_fixable.rs +++ b/tests/ui/result_map_unit_fn_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::result_map_unit_fn)] #![allow(unused)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/result_map_unit_fn_fixable.stderr b/tests/ui/result_map_unit_fn_fixable.stderr index ad941fa8bcc0b..5def0fe41733a 100644 --- a/tests/ui/result_map_unit_fn_fixable.stderr +++ b/tests/ui/result_map_unit_fn_fixable.stderr @@ -1,5 +1,5 @@ error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:35:5 + --> $DIR/result_map_unit_fn_fixable.rs:34:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -9,7 +9,7 @@ LL | x.field.map(do_nothing); = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:37:5 + --> $DIR/result_map_unit_fn_fixable.rs:36:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -17,7 +17,7 @@ LL | x.field.map(do_nothing); | help: try: `if let Ok(x_field) = x.field { do_nothing(x_field) }` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:39:5 + --> $DIR/result_map_unit_fn_fixable.rs:38:5 | LL | x.field.map(diverge); | ^^^^^^^^^^^^^^^^^^^^- @@ -25,7 +25,7 @@ LL | x.field.map(diverge); | help: try: `if let Ok(x_field) = x.field { diverge(x_field) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:45:5 + --> $DIR/result_map_unit_fn_fixable.rs:44:5 | LL | x.field.map(|value| x.do_result_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -33,7 +33,7 @@ LL | x.field.map(|value| x.do_result_nothing(value + captured)); | help: try: `if let Ok(value) = x.field { x.do_result_nothing(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:47:5 + --> $DIR/result_map_unit_fn_fixable.rs:46:5 | LL | x.field.map(|value| { x.do_result_plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -41,7 +41,7 @@ LL | x.field.map(|value| { x.do_result_plus_one(value + captured); }); | help: try: `if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:50:5 + --> $DIR/result_map_unit_fn_fixable.rs:49:5 | LL | x.field.map(|value| do_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -49,7 +49,7 @@ LL | x.field.map(|value| do_nothing(value + captured)); | help: try: `if let Ok(value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:52:5 + --> $DIR/result_map_unit_fn_fixable.rs:51:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -57,7 +57,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) }); | help: try: `if let Ok(value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:54:5 + --> $DIR/result_map_unit_fn_fixable.rs:53:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -65,7 +65,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); }); | help: try: `if let Ok(value) = x.field { do_nothing(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:56:5 + --> $DIR/result_map_unit_fn_fixable.rs:55:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -73,7 +73,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } }); | help: try: `if let Ok(value) = x.field { do_nothing(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:59:5 + --> $DIR/result_map_unit_fn_fixable.rs:58:5 | LL | x.field.map(|value| diverge(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -81,7 +81,7 @@ LL | x.field.map(|value| diverge(value + captured)); | help: try: `if let Ok(value) = x.field { diverge(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:61:5 + --> $DIR/result_map_unit_fn_fixable.rs:60:5 | LL | x.field.map(|value| { diverge(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -89,7 +89,7 @@ LL | x.field.map(|value| { diverge(value + captured) }); | help: try: `if let Ok(value) = x.field { diverge(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:63:5 + --> $DIR/result_map_unit_fn_fixable.rs:62:5 | LL | x.field.map(|value| { diverge(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -97,7 +97,7 @@ LL | x.field.map(|value| { diverge(value + captured); }); | help: try: `if let Ok(value) = x.field { diverge(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:65:5 + --> $DIR/result_map_unit_fn_fixable.rs:64:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -105,7 +105,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } }); | help: try: `if let Ok(value) = x.field { diverge(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:70:5 + --> $DIR/result_map_unit_fn_fixable.rs:69:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -113,7 +113,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); }); | help: try: `if let Ok(value) = x.field { let y = plus_one(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:72:5 + --> $DIR/result_map_unit_fn_fixable.rs:71:5 | LL | x.field.map(|value| { plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -121,7 +121,7 @@ LL | x.field.map(|value| { plus_one(value + captured); }); | help: try: `if let Ok(value) = x.field { plus_one(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:74:5 + --> $DIR/result_map_unit_fn_fixable.rs:73:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -129,7 +129,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } }); | help: try: `if let Ok(value) = x.field { plus_one(value + captured); }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:77:5 + --> $DIR/result_map_unit_fn_fixable.rs:76:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -137,7 +137,7 @@ LL | x.field.map(|ref value| { do_nothing(value + captured) }); | help: try: `if let Ok(ref value) = x.field { do_nothing(value + captured) }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:79:5 + --> $DIR/result_map_unit_fn_fixable.rs:78:5 | LL | x.field.map(|value| println!("{:?}", value)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- diff --git a/tests/ui/result_map_unit_fn_unfixable.rs b/tests/ui/result_map_unit_fn_unfixable.rs index b197c609d7bfc..ae853554d325e 100644 --- a/tests/ui/result_map_unit_fn_unfixable.rs +++ b/tests/ui/result_map_unit_fn_unfixable.rs @@ -1,7 +1,7 @@ #![warn(clippy::result_map_unit_fn)] #![feature(never_type)] #![allow(unused)] - +//@no-rustfix struct HasResult { field: Result, } diff --git a/tests/ui/reversed_empty_ranges_fixable.fixed b/tests/ui/reversed_empty_ranges_fixable.fixed index 30dfc977681ad..c8bf1b35085da 100644 --- a/tests/ui/reversed_empty_ranges_fixable.fixed +++ b/tests/ui/reversed_empty_ranges_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::reversed_empty_ranges)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/reversed_empty_ranges_fixable.rs b/tests/ui/reversed_empty_ranges_fixable.rs index 1837249eae1e4..6733c096420b8 100644 --- a/tests/ui/reversed_empty_ranges_fixable.rs +++ b/tests/ui/reversed_empty_ranges_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::reversed_empty_ranges)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/reversed_empty_ranges_fixable.stderr b/tests/ui/reversed_empty_ranges_fixable.stderr index c2495ea95f975..2d1bfe62c9236 100644 --- a/tests/ui/reversed_empty_ranges_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_fixable.stderr @@ -1,5 +1,5 @@ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:10:5 + --> $DIR/reversed_empty_ranges_fixable.rs:9:5 | LL | (42..=21).for_each(|x| println!("{}", x)); | ^^^^^^^^^ @@ -11,7 +11,7 @@ LL | (21..=42).rev().for_each(|x| println!("{}", x)); | ~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:11:13 + --> $DIR/reversed_empty_ranges_fixable.rs:10:13 | LL | let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); | ^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect:: $DIR/reversed_empty_ranges_fixable.rs:13:14 + --> $DIR/reversed_empty_ranges_fixable.rs:12:14 | LL | for _ in -21..=-42 {} | ^^^^^^^^^ @@ -33,7 +33,7 @@ LL | for _ in (-42..=-21).rev() {} | ~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:14:14 + --> $DIR/reversed_empty_ranges_fixable.rs:13:14 | LL | for _ in 42u32..21u32 {} | ^^^^^^^^^^^^ diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.fixed b/tests/ui/reversed_empty_ranges_loops_fixable.fixed index a74569599c79b..df5f2c441f41b 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.fixed +++ b/tests/ui/reversed_empty_ranges_loops_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::reversed_empty_ranges)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.rs b/tests/ui/reversed_empty_ranges_loops_fixable.rs index 42f9957dfbd01..92481be6cfc9b 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::reversed_empty_ranges)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/tests/ui/reversed_empty_ranges_loops_fixable.stderr index dfc52e64c7515..a135da488ffd3 100644 --- a/tests/ui/reversed_empty_ranges_loops_fixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_fixable.stderr @@ -1,5 +1,5 @@ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:8:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:7:14 | LL | for i in 10..0 { | ^^^^^ @@ -11,7 +11,7 @@ LL | for i in (0..10).rev() { | ~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:12:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:11:14 | LL | for i in 10..=0 { | ^^^^^^ @@ -22,7 +22,7 @@ LL | for i in (0..=10).rev() { | ~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:16:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:15:14 | LL | for i in MAX_LEN..0 { | ^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | for i in (0..MAX_LEN).rev() { | ~~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:35:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:34:14 | LL | for i in (10..0).map(|x| x * 2) { | ^^^^^^^ @@ -44,7 +44,7 @@ LL | for i in (0..10).rev().map(|x| x * 2) { | ~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:40:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:39:14 | LL | for i in 10..5 + 4 { | ^^^^^^^^^ @@ -55,7 +55,7 @@ LL | for i in (5 + 4..10).rev() { | ~~~~~~~~~~~~~~~~~ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:44:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:43:14 | LL | for i in (5 + 2)..(3 - 1) { | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/search_is_some.rs b/tests/ui/search_is_some.rs index 3cdbfaa162614..e8a0920b645d1 100644 --- a/tests/ui/search_is_some.rs +++ b/tests/ui/search_is_some.rs @@ -4,7 +4,7 @@ #![allow(dead_code)] extern crate option_helpers; use option_helpers::IteratorFalsePositives; - +//@no-rustfix #[rustfmt::skip] fn main() { let v = vec![3, 2, 1, 0, -1, -2, -3]; diff --git a/tests/ui/search_is_some_fixable_none.fixed b/tests/ui/search_is_some_fixable_none.fixed index 08fb87cb306e0..51636392f2bc0 100644 --- a/tests/ui/search_is_some_fixable_none.fixed +++ b/tests/ui/search_is_some_fixable_none.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] #![warn(clippy::search_is_some)] diff --git a/tests/ui/search_is_some_fixable_none.rs b/tests/ui/search_is_some_fixable_none.rs index ec3386933a61b..c7d773e18a321 100644 --- a/tests/ui/search_is_some_fixable_none.rs +++ b/tests/ui/search_is_some_fixable_none.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] #![warn(clippy::search_is_some)] diff --git a/tests/ui/search_is_some_fixable_none.stderr b/tests/ui/search_is_some_fixable_none.stderr index 933ce5cf42d2e..82b81f2906046 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` - --> $DIR/search_is_some_fixable_none.rs:10:13 + --> $DIR/search_is_some_fixable_none.rs:9:13 | LL | let _ = v.iter().find(|&x| *x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| *x < 0)` @@ -7,49 +7,49 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_none(); = note: `-D clippy::search-is-some` implied by `-D warnings` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:11:13 + --> $DIR/search_is_some_fixable_none.rs:10:13 | LL | let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(0..1).any(|x| **y == x)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:12:13 + --> $DIR/search_is_some_fixable_none.rs:11:13 | LL | let _ = (0..1).find(|x| *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(0..1).any(|x| x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:13:13 + --> $DIR/search_is_some_fixable_none.rs:12:13 | LL | let _ = v.iter().find(|x| **x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| *x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:14:13 + --> $DIR/search_is_some_fixable_none.rs:13:13 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(4..5).any(|x| x == 1 || x == 3 || x == 5)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:15:13 + --> $DIR/search_is_some_fixable_none.rs:14:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(1..3).any(|x| [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:16:13 + --> $DIR/search_is_some_fixable_none.rs:15:13 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(1..3).any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:17:13 + --> $DIR/search_is_some_fixable_none.rs:16:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(1..3).any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:18:13 + --> $DIR/search_is_some_fixable_none.rs:17:13 | LL | let _ = (1..3) | _____________^ @@ -58,91 +58,91 @@ LL | | .is_none(); | |__________________^ help: use `!_.any()` instead: `!(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 `position` - --> $DIR/search_is_some_fixable_none.rs:23:13 + --> $DIR/search_is_some_fixable_none.rs:22:13 | LL | let _ = v.iter().position(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some_fixable_none.rs:26:13 + --> $DIR/search_is_some_fixable_none.rs:25:13 | LL | let _ = v.iter().rposition(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:32:13 + --> $DIR/search_is_some_fixable_none.rs:31:13 | LL | let _ = "hello world".find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!"hello world".contains("world")` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:33:13 + --> $DIR/search_is_some_fixable_none.rs:32:13 | LL | let _ = "hello world".find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!"hello world".contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:34:13 + --> $DIR/search_is_some_fixable_none.rs:33:13 | LL | let _ = "hello world".find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!"hello world".contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:36:13 + --> $DIR/search_is_some_fixable_none.rs:35:13 | LL | let _ = s1.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1.contains("world")` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:37:13 + --> $DIR/search_is_some_fixable_none.rs:36:13 | LL | let _ = s1.find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1.contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:38:13 + --> $DIR/search_is_some_fixable_none.rs:37:13 | LL | let _ = s1.find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1.contains(&s2[2..])` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:40:13 + --> $DIR/search_is_some_fixable_none.rs:39:13 | LL | let _ = s1[2..].find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1[2..].contains("world")` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:41:13 + --> $DIR/search_is_some_fixable_none.rs:40:13 | LL | let _ = s1[2..].find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1[2..].contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:42:13 + --> $DIR/search_is_some_fixable_none.rs:41:13 | LL | let _ = s1[2..].find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1[2..].contains(&s2[2..])` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:58:25 + --> $DIR/search_is_some_fixable_none.rs:57:25 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!filter_hand.iter().any(|cc| c == &cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:74:30 + --> $DIR/search_is_some_fixable_none.rs:73:30 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!filter_hand.iter().any(|cc| c == cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:85:17 + --> $DIR/search_is_some_fixable_none.rs:84:17 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|v| v.foo == 1 && v.bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:88:17 + --> $DIR/search_is_some_fixable_none.rs:87:17 | LL | let _ = vfoo | _________________^ @@ -158,55 +158,55 @@ LL ~ .iter().any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2); | error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:96:17 + --> $DIR/search_is_some_fixable_none.rs:95:17 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|a| a[0] == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:102:17 + --> $DIR/search_is_some_fixable_none.rs:101:17 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|sub| sub[1..4].len() == 3)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:120:17 + --> $DIR/search_is_some_fixable_none.rs:119:17 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![ppx].iter().any(|ppp_x: &&u32| please(ppp_x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:121:17 + --> $DIR/search_is_some_fixable_none.rs:120:17 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![String::from("Hey hey")].iter().any(|s| s.len() == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:124:17 + --> $DIR/search_is_some_fixable_none.rs:123:17 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:125:17 + --> $DIR/search_is_some_fixable_none.rs:124:17 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x: &u32| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:128:17 + --> $DIR/search_is_some_fixable_none.rs:127:17 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:130:17 + --> $DIR/search_is_some_fixable_none.rs:129:17 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x: &u32| arg_no_deref(&x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:150:17 + --> $DIR/search_is_some_fixable_none.rs:149:17 | LL | let _ = vfoo | _________________^ @@ -222,61 +222,61 @@ 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` - --> $DIR/search_is_some_fixable_none.rs:166:17 + --> $DIR/search_is_some_fixable_none.rs:165:17 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|v| v.inner[0].bar == 2)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:171:17 + --> $DIR/search_is_some_fixable_none.rs:170:17 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|x| (**x)[0] == 9)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:184:17 + --> $DIR/search_is_some_fixable_none.rs:183:17 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|v| v.by_ref(&v.bar))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:188:17 + --> $DIR/search_is_some_fixable_none.rs:187:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:189:17 + --> $DIR/search_is_some_fixable_none.rs:188:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:208:17 + --> $DIR/search_is_some_fixable_none.rs:207:17 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|s| s[0].is_empty())` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:209:17 + --> $DIR/search_is_some_fixable_none.rs:208:17 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|s| test_string_1(&s[0]))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:218:17 + --> $DIR/search_is_some_fixable_none.rs:217:17 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|fp| fp.field.is_power_of_two())` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:219:17 + --> $DIR/search_is_some_fixable_none.rs:218:17 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|fp| test_u32_1(fp.field))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:220:17 + --> $DIR/search_is_some_fixable_none.rs:219:17 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|fp| test_u32_2(*fp.field))` diff --git a/tests/ui/search_is_some_fixable_some.fixed b/tests/ui/search_is_some_fixable_some.fixed index aa16f9da037d1..ae3cbc3c4da2a 100644 --- a/tests/ui/search_is_some_fixable_some.fixed +++ b/tests/ui/search_is_some_fixable_some.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] #![warn(clippy::search_is_some)] diff --git a/tests/ui/search_is_some_fixable_some.rs b/tests/ui/search_is_some_fixable_some.rs index aeb6f118bedeb..19a44803fd543 100644 --- a/tests/ui/search_is_some_fixable_some.rs +++ b/tests/ui/search_is_some_fixable_some.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] #![warn(clippy::search_is_some)] diff --git a/tests/ui/search_is_some_fixable_some.stderr b/tests/ui/search_is_some_fixable_some.stderr index c5c3c92c9182f..5466d0cb9f003 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` - --> $DIR/search_is_some_fixable_some.rs:10:22 + --> $DIR/search_is_some_fixable_some.rs:9:22 | LL | let _ = v.iter().find(|&x| *x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x < 0)` @@ -7,49 +7,49 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_some(); = note: `-D clippy::search-is-some` implied by `-D warnings` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:11:20 + --> $DIR/search_is_some_fixable_some.rs:10:20 | LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| **y == x)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:12:20 + --> $DIR/search_is_some_fixable_some.rs:11:20 | LL | let _ = (0..1).find(|x| *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:13:22 + --> $DIR/search_is_some_fixable_some.rs:12:22 | LL | let _ = v.iter().find(|x| **x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:14:20 + --> $DIR/search_is_some_fixable_some.rs:13:20 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| x == 1 || x == 3 || x == 5)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:15:20 + --> $DIR/search_is_some_fixable_some.rs:14:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:16:20 + --> $DIR/search_is_some_fixable_some.rs:15:20 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| x == 0 || [1, 2, 3].contains(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:17:20 + --> $DIR/search_is_some_fixable_some.rs:16:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| [1, 2, 3].contains(&x) || x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:19:10 + --> $DIR/search_is_some_fixable_some.rs:18:10 | LL | .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) | __________^ @@ -57,91 +57,91 @@ LL | | .is_some(); | |__________________^ help: use `any()` instead: `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 `position` - --> $DIR/search_is_some_fixable_some.rs:23:22 + --> $DIR/search_is_some_fixable_some.rs:22:22 | LL | let _ = v.iter().position(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)` error: called `is_some()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some_fixable_some.rs:26:22 + --> $DIR/search_is_some_fixable_some.rs:25:22 | LL | let _ = v.iter().rposition(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:31:27 + --> $DIR/search_is_some_fixable_some.rs:30:27 | LL | let _ = "hello world".find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:32:27 + --> $DIR/search_is_some_fixable_some.rs:31:27 | LL | let _ = "hello world".find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:33:27 + --> $DIR/search_is_some_fixable_some.rs:32:27 | LL | let _ = "hello world".find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:35:16 + --> $DIR/search_is_some_fixable_some.rs:34:16 | LL | let _ = s1.find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:36:16 + --> $DIR/search_is_some_fixable_some.rs:35:16 | LL | let _ = s1.find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:37:16 + --> $DIR/search_is_some_fixable_some.rs:36:16 | LL | let _ = s1.find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:39:21 + --> $DIR/search_is_some_fixable_some.rs:38:21 | LL | let _ = s1[2..].find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:40:21 + --> $DIR/search_is_some_fixable_some.rs:39:21 | LL | let _ = s1[2..].find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:41:21 + --> $DIR/search_is_some_fixable_some.rs:40:21 | LL | let _ = s1[2..].find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:57:44 + --> $DIR/search_is_some_fixable_some.rs:56:44 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|cc| c == &cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:73:49 + --> $DIR/search_is_some_fixable_some.rs:72:49 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|cc| c == cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:84:29 + --> $DIR/search_is_some_fixable_some.rs:83:29 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|v| v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:89:14 + --> $DIR/search_is_some_fixable_some.rs:88:14 | LL | .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) | ______________^ @@ -149,55 +149,55 @@ LL | | .is_some(); | |______________________^ help: use `any()` instead: `any(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:95:29 + --> $DIR/search_is_some_fixable_some.rs:94:29 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|a| a[0] == 42)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:101:29 + --> $DIR/search_is_some_fixable_some.rs:100:29 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|sub| sub[1..4].len() == 3)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:119:30 + --> $DIR/search_is_some_fixable_some.rs:118:30 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|ppp_x: &&u32| please(ppp_x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:120:50 + --> $DIR/search_is_some_fixable_some.rs:119:50 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|s| s.len() == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:123:26 + --> $DIR/search_is_some_fixable_some.rs:122:26 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:124:26 + --> $DIR/search_is_some_fixable_some.rs:123:26 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:127:26 + --> $DIR/search_is_some_fixable_some.rs:126:26 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:129:26 + --> $DIR/search_is_some_fixable_some.rs:128:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:151:14 + --> $DIR/search_is_some_fixable_some.rs:150:14 | LL | .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) | ______________^ @@ -205,85 +205,85 @@ LL | | .is_some(); | |______________________^ help: use `any()` instead: `any(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:165:29 + --> $DIR/search_is_some_fixable_some.rs:164:29 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|v| v.inner[0].bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:170:29 + --> $DIR/search_is_some_fixable_some.rs:169:29 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| (**x)[0] == 9)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:183:29 + --> $DIR/search_is_some_fixable_some.rs:182:29 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|v| v.by_ref(&v.bar))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:187:55 + --> $DIR/search_is_some_fixable_some.rs:186:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|(&x, y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:188:55 + --> $DIR/search_is_some_fixable_some.rs:187:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|(&x, y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:207:26 + --> $DIR/search_is_some_fixable_some.rs:206:26 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|s| s[0].is_empty())` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:208:26 + --> $DIR/search_is_some_fixable_some.rs:207:26 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|s| test_string_1(&s[0]))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:217:26 + --> $DIR/search_is_some_fixable_some.rs:216:26 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|fp| fp.field.is_power_of_two())` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:218:26 + --> $DIR/search_is_some_fixable_some.rs:217:26 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|fp| test_u32_1(fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:219:26 + --> $DIR/search_is_some_fixable_some.rs:218:26 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|fp| test_u32_2(*fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:234:18 + --> $DIR/search_is_some_fixable_some.rs:233:18 | LL | v.iter().find(|x: &&u32| func(x)).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| func(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:243:26 + --> $DIR/search_is_some_fixable_some.rs:242:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_impl(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| arg_no_deref_impl(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:246:26 + --> $DIR/search_is_some_fixable_some.rs:245:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_dyn(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| arg_no_deref_dyn(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:249:26 + --> $DIR/search_is_some_fixable_some.rs:248:26 | LL | let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| (*arg_no_deref_dyn)(&x))` diff --git a/tests/ui/seek_from_current.fixed b/tests/ui/seek_from_current.fixed index 34c33baf686d4..543f0c681393f 100644 --- a/tests/ui/seek_from_current.fixed +++ b/tests/ui/seek_from_current.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::seek_from_current)] use std::fs::File; diff --git a/tests/ui/seek_from_current.rs b/tests/ui/seek_from_current.rs index 22bcff1bc4054..4ed877f8ec211 100644 --- a/tests/ui/seek_from_current.rs +++ b/tests/ui/seek_from_current.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::seek_from_current)] use std::fs::File; diff --git a/tests/ui/seek_from_current.stderr b/tests/ui/seek_from_current.stderr index c079f36119292..2549a26b23c3d 100644 --- a/tests/ui/seek_from_current.stderr +++ b/tests/ui/seek_from_current.stderr @@ -1,5 +1,5 @@ error: using `SeekFrom::Current` to start from current position - --> $DIR/seek_from_current.rs:20:5 + --> $DIR/seek_from_current.rs:19:5 | LL | f.seek(SeekFrom::Current(0))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `f.stream_position()` diff --git a/tests/ui/seek_to_start_instead_of_rewind.fixed b/tests/ui/seek_to_start_instead_of_rewind.fixed index d8a6e6985d4a0..15cc8d54faab3 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 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::seek_to_start_instead_of_rewind)] diff --git a/tests/ui/seek_to_start_instead_of_rewind.rs b/tests/ui/seek_to_start_instead_of_rewind.rs index fc6a6433c2b09..197225ffbd5c9 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 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::seek_to_start_instead_of_rewind)] diff --git a/tests/ui/seek_to_start_instead_of_rewind.stderr b/tests/ui/seek_to_start_instead_of_rewind.stderr index 342ec00fe7295..47cddfe7ea694 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 - --> $DIR/seek_to_start_instead_of_rewind.rs:53:7 + --> $DIR/seek_to_start_instead_of_rewind.rs:52:7 | LL | t.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` @@ -7,13 +7,13 @@ LL | t.seek(SeekFrom::Start(0)); = note: `-D clippy::seek-to-start-instead-of-rewind` implied by `-D warnings` error: used `seek` to go to the start of the stream - --> $DIR/seek_to_start_instead_of_rewind.rs:58:7 + --> $DIR/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 - --> $DIR/seek_to_start_instead_of_rewind.rs:134:7 + --> $DIR/seek_to_start_instead_of_rewind.rs:133:7 | LL | f.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` diff --git a/tests/ui/semicolon_if_nothing_returned.fixed b/tests/ui/semicolon_if_nothing_returned.fixed index 653f4533b331f..bbcc0de27d115 100644 --- a/tests/ui/semicolon_if_nothing_returned.fixed +++ b/tests/ui/semicolon_if_nothing_returned.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::semicolon_if_nothing_returned)] #![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)] diff --git a/tests/ui/semicolon_if_nothing_returned.rs b/tests/ui/semicolon_if_nothing_returned.rs index 9db038219b4ae..fdc9c0c33f5a3 100644 --- a/tests/ui/semicolon_if_nothing_returned.rs +++ b/tests/ui/semicolon_if_nothing_returned.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::semicolon_if_nothing_returned)] #![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)] diff --git a/tests/ui/semicolon_if_nothing_returned.stderr b/tests/ui/semicolon_if_nothing_returned.stderr index 78813e7cc1c39..8d9a67585cf12 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 - --> $DIR/semicolon_if_nothing_returned.rs:9:5 + --> $DIR/semicolon_if_nothing_returned.rs:8:5 | LL | println!("Hello") | ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");` @@ -7,25 +7,25 @@ LL | println!("Hello") = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D warnings` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:13:5 + --> $DIR/semicolon_if_nothing_returned.rs:12:5 | LL | get_unit() | ^^^^^^^^^^ help: add a `;` here: `get_unit();` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:18:5 + --> $DIR/semicolon_if_nothing_returned.rs:17:5 | LL | y = x + 1 | ^^^^^^^^^ help: add a `;` here: `y = x + 1;` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:24:9 + --> $DIR/semicolon_if_nothing_returned.rs:23:9 | LL | hello() | ^^^^^^^ help: add a `;` here: `hello();` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:35:9 + --> $DIR/semicolon_if_nothing_returned.rs:34: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 ee359f60cbd7f..21681e71589e9 100644 --- a/tests/ui/semicolon_inside_block.fixed +++ b/tests/ui/semicolon_inside_block.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui/semicolon_inside_block.rs b/tests/ui/semicolon_inside_block.rs index e8516f79b20cd..3a81661cd16f5 100644 --- a/tests/ui/semicolon_inside_block.rs +++ b/tests/ui/semicolon_inside_block.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui/semicolon_inside_block.stderr b/tests/ui/semicolon_inside_block.stderr index 48d3690e2bdee..825c7142fdfa4 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 - --> $DIR/semicolon_inside_block.rs:39:5 + --> $DIR/semicolon_inside_block.rs:38:5 | LL | { unit_fn_block() }; | ^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + { unit_fn_block(); } | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:40:5 + --> $DIR/semicolon_inside_block.rs:39:5 | LL | unsafe { unit_fn_block() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + unsafe { unit_fn_block(); } | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:48:5 + --> $DIR/semicolon_inside_block.rs:47:5 | LL | / { LL | | unit_fn_block(); @@ -39,7 +39,7 @@ LL ~ } | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:61:5 + --> $DIR/semicolon_inside_block.rs:60:5 | LL | { m!(()) }; | ^^^^^^^^^^^ diff --git a/tests/ui/semicolon_outside_block.fixed b/tests/ui/semicolon_outside_block.fixed index 034c7f8c7c180..148e112e0bcb5 100644 --- a/tests/ui/semicolon_outside_block.fixed +++ b/tests/ui/semicolon_outside_block.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui/semicolon_outside_block.rs b/tests/ui/semicolon_outside_block.rs index 4dc956d8a4b51..c767201469ab6 100644 --- a/tests/ui/semicolon_outside_block.rs +++ b/tests/ui/semicolon_outside_block.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/tests/ui/semicolon_outside_block.stderr b/tests/ui/semicolon_outside_block.stderr index dcc102e60994a..53c6bbd825c18 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 - --> $DIR/semicolon_outside_block.rs:42:5 + --> $DIR/semicolon_outside_block.rs:41:5 | LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:43:5 + --> $DIR/semicolon_outside_block.rs:42:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:52:5 + --> $DIR/semicolon_outside_block.rs:51:5 | LL | / { LL | | unit_fn_block(); @@ -39,7 +39,7 @@ LL ~ }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:62:5 + --> $DIR/semicolon_outside_block.rs:61:5 | LL | { m!(()); } | ^^^^^^^^^^^ diff --git a/tests/ui/short_circuit_statement.fixed b/tests/ui/short_circuit_statement.fixed index 1737d50144198..a9930ef4dbb61 100644 --- a/tests/ui/short_circuit_statement.fixed +++ b/tests/ui/short_circuit_statement.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::short_circuit_statement)] #![allow(clippy::nonminimal_bool)] diff --git a/tests/ui/short_circuit_statement.rs b/tests/ui/short_circuit_statement.rs index ab93aa1ca5caa..71f7c7f2abf77 100644 --- a/tests/ui/short_circuit_statement.rs +++ b/tests/ui/short_circuit_statement.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::short_circuit_statement)] #![allow(clippy::nonminimal_bool)] diff --git a/tests/ui/short_circuit_statement.stderr b/tests/ui/short_circuit_statement.stderr index aa84ac3a7925f..1f7adea4a8b11 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 - --> $DIR/short_circuit_statement.rs:7:5 + --> $DIR/short_circuit_statement.rs:5:5 | LL | f() && g(); | ^^^^^^^^^^^ help: replace it with: `if f() { g(); }` @@ -7,13 +7,13 @@ LL | f() && g(); = note: `-D clippy::short-circuit-statement` implied by `-D warnings` error: boolean short circuit operator in statement may be clearer using an explicit test - --> $DIR/short_circuit_statement.rs:8:5 + --> $DIR/short_circuit_statement.rs:6: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 - --> $DIR/short_circuit_statement.rs:9:5 + --> $DIR/short_circuit_statement.rs:7:5 | LL | 1 == 2 || g(); | ^^^^^^^^^^^^^^ help: replace it with: `if 1 != 2 { g(); }` diff --git a/tests/ui/should_impl_trait/method_list_2.rs b/tests/ui/should_impl_trait/method_list_2.rs index 3efec1c52023b..27a66f2ed188f 100644 --- a/tests/ui/should_impl_trait/method_list_2.rs +++ b/tests/ui/should_impl_trait/method_list_2.rs @@ -10,7 +10,7 @@ clippy::missing_panics_doc, clippy::return_self_not_must_use )] - +//@no-rustfix use std::ops::Mul; use std::rc::{self, Rc}; use std::sync::{self, Arc}; diff --git a/tests/ui/significant_drop_in_scrutinee.fixed b/tests/ui/significant_drop_in_scrutinee.fixed deleted file mode 100644 index acc78d6bb0439..0000000000000 --- a/tests/ui/significant_drop_in_scrutinee.fixed +++ /dev/null @@ -1,627 +0,0 @@ -// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// //@run-rustfix -#![warn(clippy::significant_drop_in_scrutinee)] -#![allow(dead_code, unused_assignments)] -#![allow(clippy::match_single_binding, clippy::single_match, clippy::uninlined_format_args)] - -use std::num::ParseIntError; -use std::ops::Deref; -use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::RwLock; -use std::sync::{Mutex, MutexGuard}; - -struct State {} - -impl State { - fn foo(&self) -> bool { - true - } - - fn bar(&self) {} -} - -fn should_not_trigger_lint_with_mutex_guard_outside_match() { - let mutex = Mutex::new(State {}); - - // Should not trigger lint because the temporary should drop at the `;` on line before the match - let is_foo = mutex.lock().unwrap().foo(); - match is_foo { - true => { - mutex.lock().unwrap().bar(); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_with_mutex_guard_when_taking_ownership_in_match() { - let mutex = Mutex::new(State {}); - - // Should not trigger lint because the scrutinee is explicitly returning the MutexGuard, - // so its lifetime should not be surprising. - match mutex.lock() { - Ok(guard) => { - guard.foo(); - mutex.lock().unwrap().bar(); - }, - _ => {}, - }; -} - -fn should_trigger_lint_with_mutex_guard_in_match_scrutinee() { - let mutex = Mutex::new(State {}); - - // Should trigger lint because the lifetime of the temporary MutexGuard is surprising because it - // is preserved until the end of the match, but there is no clear indication that this is the - // case. - match mutex.lock().unwrap().foo() { - true => { - mutex.lock().unwrap().bar(); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_with_mutex_guard_in_match_scrutinee_when_lint_allowed() { - let mutex = Mutex::new(State {}); - - // Lint should not be triggered because it is "allowed" below. - #[allow(clippy::significant_drop_in_scrutinee)] - match mutex.lock().unwrap().foo() { - true => { - mutex.lock().unwrap().bar(); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_for_insignificant_drop() { - // Should not trigger lint because there are no temporaries whose drops have a significant - // side effect. - match 1u64.to_string().is_empty() { - true => { - println!("It was empty") - }, - false => { - println!("It was not empty") - }, - } -} - -struct StateWithMutex { - m: Mutex, -} - -struct MutexGuardWrapper<'a> { - mg: MutexGuard<'a, u64>, -} - -impl<'a> MutexGuardWrapper<'a> { - fn get_the_value(&self) -> u64 { - *self.mg.deref() - } -} - -struct MutexGuardWrapperWrapper<'a> { - mg: MutexGuardWrapper<'a>, -} - -impl<'a> MutexGuardWrapperWrapper<'a> { - fn get_the_value(&self) -> u64 { - *self.mg.mg.deref() - } -} - -impl StateWithMutex { - fn lock_m(&self) -> MutexGuardWrapper<'_> { - MutexGuardWrapper { - mg: self.m.lock().unwrap(), - } - } - - fn lock_m_m(&self) -> MutexGuardWrapperWrapper<'_> { - MutexGuardWrapperWrapper { - mg: MutexGuardWrapper { - mg: self.m.lock().unwrap(), - }, - } - } - - fn foo(&self) -> bool { - true - } - - fn bar(&self) {} -} - -fn should_trigger_lint_with_wrapped_mutex() { - let s = StateWithMutex { m: Mutex::new(1) }; - - // Should trigger lint because a temporary contains a type with a significant drop and its - // lifetime is not obvious. Additionally, it is not obvious from looking at the scrutinee that - // the temporary contains such a type, making it potentially even more surprising. - match s.lock_m().get_the_value() { - 1 => { - println!("Got 1. Is it still 1?"); - println!("{}", s.lock_m().get_the_value()); - }, - 2 => { - println!("Got 2. Is it still 2?"); - println!("{}", s.lock_m().get_the_value()); - }, - _ => {}, - } - println!("All done!"); -} - -fn should_trigger_lint_with_double_wrapped_mutex() { - let s = StateWithMutex { m: Mutex::new(1) }; - - // Should trigger lint because a temporary contains a type which further contains a type with a - // significant drop and its lifetime is not obvious. Additionally, it is not obvious from - // looking at the scrutinee that the temporary contains such a type, making it potentially even - // more surprising. - match s.lock_m_m().get_the_value() { - 1 => { - println!("Got 1. Is it still 1?"); - println!("{}", s.lock_m().get_the_value()); - }, - 2 => { - println!("Got 2. Is it still 2?"); - println!("{}", s.lock_m().get_the_value()); - }, - _ => {}, - } - println!("All done!"); -} - -struct Counter { - i: AtomicU64, -} - -#[clippy::has_significant_drop] -struct CounterWrapper<'a> { - counter: &'a Counter, -} - -impl<'a> CounterWrapper<'a> { - fn new(counter: &Counter) -> CounterWrapper { - counter.i.fetch_add(1, Ordering::Relaxed); - CounterWrapper { counter } - } -} - -impl<'a> Drop for CounterWrapper<'a> { - fn drop(&mut self) { - self.counter.i.fetch_sub(1, Ordering::Relaxed); - } -} - -impl Counter { - fn temp_increment(&self) -> Vec { - vec![CounterWrapper::new(self), CounterWrapper::new(self)] - } -} - -fn should_trigger_lint_for_vec() { - let counter = Counter { i: AtomicU64::new(0) }; - - // Should trigger lint because the temporary in the scrutinee returns a collection of types - // which have significant drops. The types with significant drops are also non-obvious when - // reading the expression in the scrutinee. - match counter.temp_increment().len() { - 2 => { - let current_count = counter.i.load(Ordering::Relaxed); - println!("Current count {}", current_count); - assert_eq!(current_count, 0); - }, - 1 => {}, - 3 => {}, - _ => {}, - }; -} - -struct StateWithField { - s: String, -} - -// Should trigger lint only on the type in the tuple which is created using a temporary -// with a significant drop. Additionally, this test ensures that the format of the tuple -// is preserved correctly in the suggestion. -fn should_trigger_lint_for_tuple_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - - { - match (mutex1.lock().unwrap().s.len(), true) { - (3, _) => { - println!("started"); - mutex1.lock().unwrap().s.len(); - println!("done"); - }, - (_, _) => {}, - }; - - match (true, mutex1.lock().unwrap().s.len(), true) { - (_, 3, _) => { - println!("started"); - mutex1.lock().unwrap().s.len(); - println!("done"); - }, - (_, _, _) => {}, - }; - - let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); - match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { - (3, _, 3) => { - println!("started"); - mutex1.lock().unwrap().s.len(); - mutex2.lock().unwrap().s.len(); - println!("done"); - }, - (_, _, _) => {}, - }; - - let mutex3 = Mutex::new(StateWithField { s: "three".to_owned() }); - match mutex3.lock().unwrap().s.as_str() { - "three" => { - println!("started"); - mutex1.lock().unwrap().s.len(); - mutex2.lock().unwrap().s.len(); - println!("done"); - }, - _ => {}, - }; - - match (true, mutex3.lock().unwrap().s.as_str()) { - (_, "three") => { - println!("started"); - mutex1.lock().unwrap().s.len(); - mutex2.lock().unwrap().s.len(); - println!("done"); - }, - (_, _) => {}, - }; - } -} - -// Should trigger lint when either side of a binary operation creates a temporary with a -// significant drop. -// To avoid potential unnecessary copies or creating references that would trigger the significant -// drop problem, the lint recommends moving the entire binary operation. -fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { - let mutex = Mutex::new(StateWithField { s: "state".to_owned() }); - - match mutex.lock().unwrap().s.len() > 1 { - true => { - mutex.lock().unwrap().s.len(); - }, - false => {}, - }; - - match 1 < mutex.lock().unwrap().s.len() { - true => { - mutex.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -// Should trigger lint when both sides of a binary operation creates a temporary with a -// significant drop. -// To avoid potential unnecessary copies or creating references that would trigger the significant -// drop problem, the lint recommends moving the entire binary operation. -fn should_trigger_lint_for_accessing_fields_in_mutex_in_both_sides_of_binary_op() { - let mutex1 = Mutex::new(StateWithField { s: "state".to_owned() }); - let mutex2 = Mutex::new(StateWithField { - s: "statewithfield".to_owned(), - }); - - match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { - true => { - println!( - "{} < {}", - mutex1.lock().unwrap().s.len(), - mutex2.lock().unwrap().s.len() - ); - }, - false => {}, - }; - - match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { - true => { - println!( - "{} >= {}", - mutex1.lock().unwrap().s.len(), - mutex2.lock().unwrap().s.len() - ); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_for_closure_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - - let get_mutex_guard = || mutex1.lock().unwrap().s.len(); - - // Should not trigger lint because the temporary with a significant drop will be dropped - // at the end of the closure, so the MutexGuard will be unlocked and not have a potentially - // surprising lifetime. - match get_mutex_guard() > 1 { - true => { - mutex1.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -fn should_trigger_lint_for_return_from_closure_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - - let get_mutex_guard = || mutex1.lock().unwrap(); - - // Should trigger lint because the temporary with a significant drop is returned from the - // closure but not used directly in any match arms, so it has a potentially surprising lifetime. - match get_mutex_guard().s.len() > 1 { - true => { - mutex1.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -fn should_trigger_lint_for_return_from_match_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); - - let i = 100; - - // Should trigger lint because the nested match within the scrutinee returns a temporary with a - // significant drop is but not used directly in any match arms, so it has a potentially - // surprising lifetime. - match match i { - 100 => mutex1.lock().unwrap(), - _ => mutex2.lock().unwrap(), - } - .s - .len() - > 1 - { - true => { - mutex1.lock().unwrap().s.len(); - }, - false => { - println!("nothing to do here"); - }, - }; -} - -fn should_trigger_lint_for_return_from_if_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); - - let i = 100; - - // Should trigger lint because the nested if-expression within the scrutinee returns a temporary - // with a significant drop is but not used directly in any match arms, so it has a potentially - // surprising lifetime. - match if i > 1 { - mutex1.lock().unwrap() - } else { - mutex2.lock().unwrap() - } - .s - .len() - > 1 - { - true => { - mutex1.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_for_if_in_scrutinee() { - let mutex = Mutex::new(StateWithField { s: "state".to_owned() }); - - let i = 100; - - // Should not trigger the lint because the temporary with a significant drop *is* dropped within - // the body of the if-expression nested within the match scrutinee, and therefore does not have - // a potentially surprising lifetime. - match if i > 1 { - mutex.lock().unwrap().s.len() > 1 - } else { - false - } { - true => { - mutex.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -struct StateWithBoxedMutexGuard { - u: Mutex, -} - -impl StateWithBoxedMutexGuard { - fn new() -> StateWithBoxedMutexGuard { - StateWithBoxedMutexGuard { u: Mutex::new(42) } - } - fn lock(&self) -> Box> { - Box::new(self.u.lock().unwrap()) - } -} - -fn should_trigger_lint_for_boxed_mutex_guard() { - let s = StateWithBoxedMutexGuard::new(); - - // Should trigger lint because a temporary Box holding a type with a significant drop in a match - // scrutinee may have a potentially surprising lifetime. - match s.lock().deref().deref() { - 0 | 1 => println!("Value was less than 2"), - _ => println!("Value is {}", s.lock().deref()), - }; -} - -struct StateStringWithBoxedMutexGuard { - s: Mutex, -} - -impl StateStringWithBoxedMutexGuard { - fn new() -> StateStringWithBoxedMutexGuard { - StateStringWithBoxedMutexGuard { - s: Mutex::new("A String".to_owned()), - } - } - fn lock(&self) -> Box> { - Box::new(self.s.lock().unwrap()) - } -} - -fn should_trigger_lint_for_boxed_mutex_guard_holding_string() { - let s = StateStringWithBoxedMutexGuard::new(); - - let matcher = String::from("A String"); - - // Should trigger lint because a temporary Box holding a type with a significant drop in a match - // scrutinee may have a potentially surprising lifetime. - match s.lock().deref().deref() { - matcher => println!("Value is {}", s.lock().deref()), - _ => println!("Value was not a match"), - }; -} - -struct StateWithIntField { - i: u64, -} - -// Should trigger lint when either side of an assign expression contains a temporary with a -// significant drop, because the temporary's lifetime will be extended to the end of the match. -// To avoid potential unnecessary copies or creating references that would trigger the significant -// drop problem, the lint recommends moving the entire binary operation. -fn should_trigger_lint_in_assign_expr() { - let mutex = Mutex::new(StateWithIntField { i: 10 }); - - let mut i = 100; - - match mutex.lock().unwrap().i = i { - _ => { - println!("{}", mutex.lock().unwrap().i); - }, - }; - - match i = mutex.lock().unwrap().i { - _ => { - println!("{}", mutex.lock().unwrap().i); - }, - }; - - match mutex.lock().unwrap().i += 1 { - _ => { - println!("{}", mutex.lock().unwrap().i); - }, - }; - - match i += mutex.lock().unwrap().i { - _ => { - println!("{}", mutex.lock().unwrap().i); - }, - }; -} - -#[derive(Debug)] -enum RecursiveEnum { - Foo(Option>), -} - -#[derive(Debug)] -enum GenericRecursiveEnum { - Foo(T, Option>>), -} - -fn should_not_cause_stack_overflow() { - // Test that when a type recursively contains itself, a stack overflow does not occur when - // checking sub-types for significant drops. - let f = RecursiveEnum::Foo(Some(Box::new(RecursiveEnum::Foo(None)))); - match f { - RecursiveEnum::Foo(Some(f)) => { - println!("{:?}", f) - }, - RecursiveEnum::Foo(f) => { - println!("{:?}", f) - }, - } - - let f = GenericRecursiveEnum::Foo(1u64, Some(Box::new(GenericRecursiveEnum::Foo(2u64, None)))); - match f { - GenericRecursiveEnum::Foo(i, Some(f)) => { - println!("{} {:?}", i, f) - }, - GenericRecursiveEnum::Foo(i, f) => { - println!("{} {:?}", i, f) - }, - } -} - -fn should_not_produce_lint_for_try_desugar() -> Result { - // TryDesugar (i.e. using `?` for a Result type) will turn into a match but is out of scope - // for this lint - let rwlock = RwLock::new("1".to_string()); - let result = rwlock.read().unwrap().parse::()?; - println!("{}", result); - rwlock.write().unwrap().push('2'); - Ok(result) -} - -struct ResultReturner { - s: String, -} - -impl ResultReturner { - fn to_number(&self) -> Result { - self.s.parse::() - } -} - -fn should_trigger_lint_for_non_ref_move_and_clone_suggestion() { - let rwlock = RwLock::::new(ResultReturner { s: "1".to_string() }); - match rwlock.read().unwrap().to_number() { - Ok(n) => println!("Converted to number: {}", n), - Err(e) => println!("Could not convert {} to number", e), - }; -} - -fn should_trigger_lint_for_read_write_lock_for_loop() { - // For-in loops desugar to match expressions and are prone to the type of deadlock this lint is - // designed to look for. - let rwlock = RwLock::>::new(vec!["1".to_string()]); - for s in rwlock.read().unwrap().iter() { - println!("{}", s); - } -} - -fn do_bar(mutex: &Mutex) { - mutex.lock().unwrap().bar(); -} - -fn should_trigger_lint_without_significant_drop_in_arm() { - let mutex = Mutex::new(State {}); - - // Should trigger lint because the lifetime of the temporary MutexGuard is surprising because it - // is preserved until the end of the match, but there is no clear indication that this is the - // case. - match mutex.lock().unwrap().foo() { - true => do_bar(&mutex), - false => {}, - }; -} - -fn should_not_trigger_on_significant_iterator_drop() { - let lines = std::io::stdin().lines(); - for line in lines { - println!("foo: {}", line.unwrap()); - } -} - -fn main() {} diff --git a/tests/ui/significant_drop_in_scrutinee.rs b/tests/ui/significant_drop_in_scrutinee.rs index 17df9f88fff70..0dcf4b804cf8b 100644 --- a/tests/ui/significant_drop_in_scrutinee.rs +++ b/tests/ui/significant_drop_in_scrutinee.rs @@ -1,5 +1,5 @@ // 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)] diff --git a/tests/ui/significant_drop_tightening.fixed b/tests/ui/significant_drop_tightening.fixed index 8065e9e5fbc92..ed05f6e0c8d35 100644 --- a/tests/ui/significant_drop_tightening.fixed +++ b/tests/ui/significant_drop_tightening.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::significant_drop_tightening)] use std::sync::Mutex; diff --git a/tests/ui/significant_drop_tightening.rs b/tests/ui/significant_drop_tightening.rs index 1620b76843a0b..e5f17278f0f6a 100644 --- a/tests/ui/significant_drop_tightening.rs +++ b/tests/ui/significant_drop_tightening.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::significant_drop_tightening)] use std::sync::Mutex; diff --git a/tests/ui/significant_drop_tightening.stderr b/tests/ui/significant_drop_tightening.stderr index b5cad88ad3ffe..ff6f5907ebd5f 100644 --- a/tests/ui/significant_drop_tightening.stderr +++ b/tests/ui/significant_drop_tightening.stderr @@ -1,5 +1,5 @@ error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:12:9 + --> $DIR/significant_drop_tightening.rs:10:9 | LL | pub fn complex_return_triggers_the_lint() -> i32 { | __________________________________________________- @@ -23,7 +23,7 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:106:13 + --> $DIR/significant_drop_tightening.rs:104:13 | LL | / { LL | | let mutex = Mutex::new(1i32); @@ -43,7 +43,7 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:127:13 + --> $DIR/significant_drop_tightening.rs:125:13 | LL | / { LL | | let mutex = Mutex::new(1i32); @@ -67,7 +67,7 @@ LL + | error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:133:17 + --> $DIR/significant_drop_tightening.rs:131:17 | LL | / { LL | | let mutex = Mutex::new(vec![1i32]); diff --git a/tests/ui/single_char_add_str.fixed b/tests/ui/single_char_add_str.fixed index cb301c8bc1529..eafd17f538744 100644 --- a/tests/ui/single_char_add_str.fixed +++ b/tests/ui/single_char_add_str.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_char_add_str)] #![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes)] diff --git a/tests/ui/single_char_add_str.rs b/tests/ui/single_char_add_str.rs index 99baf35ac2979..5326c7cf24c64 100644 --- a/tests/ui/single_char_add_str.rs +++ b/tests/ui/single_char_add_str.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_char_add_str)] #![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes)] diff --git a/tests/ui/single_char_add_str.stderr b/tests/ui/single_char_add_str.stderr index 3f93c18470eac..55d91583ad04d 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 - --> $DIR/single_char_add_str.rs:15:5 + --> $DIR/single_char_add_str.rs:14:5 | LL | string.push_str("R"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('R')` @@ -7,85 +7,85 @@ LL | string.push_str("R"); = note: `-D clippy::single-char-add-str` implied by `-D warnings` error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:16:5 + --> $DIR/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 - --> $DIR/single_char_add_str.rs:21:5 + --> $DIR/single_char_add_str.rs:20: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 - --> $DIR/single_char_add_str.rs:22:5 + --> $DIR/single_char_add_str.rs:21: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 - --> $DIR/single_char_add_str.rs:23:5 + --> $DIR/single_char_add_str.rs:22: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 string literal - --> $DIR/single_char_add_str.rs:25:5 + --> $DIR/single_char_add_str.rs:24: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 - --> $DIR/single_char_add_str.rs:30:5 + --> $DIR/single_char_add_str.rs:29: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 - --> $DIR/single_char_add_str.rs:31:5 + --> $DIR/single_char_add_str.rs:30: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 - --> $DIR/single_char_add_str.rs:36:5 + --> $DIR/single_char_add_str.rs:35: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 - --> $DIR/single_char_add_str.rs:37:5 + --> $DIR/single_char_add_str.rs:36: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 - --> $DIR/single_char_add_str.rs:39:5 + --> $DIR/single_char_add_str.rs:38: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 - --> $DIR/single_char_add_str.rs:41:5 + --> $DIR/single_char_add_str.rs:40: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 - --> $DIR/single_char_add_str.rs:42:5 + --> $DIR/single_char_add_str.rs:41: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 - --> $DIR/single_char_add_str.rs:43:5 + --> $DIR/single_char_add_str.rs:42: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 - --> $DIR/single_char_add_str.rs:45:5 + --> $DIR/single_char_add_str.rs:44: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_pattern.fixed b/tests/ui/single_char_pattern.fixed index 7ae62231acc0f..79e7eda40703b 100644 --- a/tests/ui/single_char_pattern.fixed +++ b/tests/ui/single_char_pattern.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes, unused_must_use)] use std::collections::HashSet; diff --git a/tests/ui/single_char_pattern.rs b/tests/ui/single_char_pattern.rs index 0604624e767be..81962c0a6e931 100644 --- a/tests/ui/single_char_pattern.rs +++ b/tests/ui/single_char_pattern.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes, unused_must_use)] use std::collections::HashSet; diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr index 5ae2450c22681..0d4c154af19c7 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 - --> $DIR/single_char_pattern.rs:9:13 + --> $DIR/single_char_pattern.rs:7:13 | LL | x.split("x"); | ^^^ help: try using a `char` instead: `'x'` @@ -7,229 +7,229 @@ LL | x.split("x"); = note: `-D clippy::single-char-pattern` implied by `-D warnings` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:15:13 + --> $DIR/single_char_pattern.rs:13:13 | LL | x.split("ß"); | ^^^ help: try using a `char` instead: `'ß'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:16:13 + --> $DIR/single_char_pattern.rs:14:13 | LL | x.split("ℝ"); | ^^^ help: try using a `char` instead: `'ℝ'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:17:13 + --> $DIR/single_char_pattern.rs:15:13 | LL | x.split("💣"); | ^^^^ help: try using a `char` instead: `'💣'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:20:23 + --> $DIR/single_char_pattern.rs:18:23 | LL | x.split_inclusive("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:21:16 + --> $DIR/single_char_pattern.rs:19:16 | LL | x.contains("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:22:19 + --> $DIR/single_char_pattern.rs:20:19 | LL | x.starts_with("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:23:17 + --> $DIR/single_char_pattern.rs:21:17 | LL | x.ends_with("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:24:12 + --> $DIR/single_char_pattern.rs:22:12 | LL | x.find("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:25:13 + --> $DIR/single_char_pattern.rs:23:13 | LL | x.rfind("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:26:14 + --> $DIR/single_char_pattern.rs:24:14 | LL | x.rsplit("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:27:24 + --> $DIR/single_char_pattern.rs:25:24 | LL | x.split_terminator("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:28:25 + --> $DIR/single_char_pattern.rs:26:25 | LL | x.rsplit_terminator("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:29:17 + --> $DIR/single_char_pattern.rs:27:17 | LL | x.splitn(2, "x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:30:18 + --> $DIR/single_char_pattern.rs:28:18 | LL | x.rsplitn(2, "x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:31:18 + --> $DIR/single_char_pattern.rs:29:18 | LL | x.split_once("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:32:19 + --> $DIR/single_char_pattern.rs:30:19 | LL | x.rsplit_once("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:33:15 + --> $DIR/single_char_pattern.rs:31:15 | LL | x.matches("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:34:16 + --> $DIR/single_char_pattern.rs:32:16 | LL | x.rmatches("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:35:21 + --> $DIR/single_char_pattern.rs:33:21 | LL | x.match_indices("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:36:22 + --> $DIR/single_char_pattern.rs:34:22 | LL | x.rmatch_indices("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:37:26 + --> $DIR/single_char_pattern.rs:35:26 | LL | x.trim_start_matches("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:38:24 + --> $DIR/single_char_pattern.rs:36:24 | LL | x.trim_end_matches("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:39:20 + --> $DIR/single_char_pattern.rs:37:20 | LL | x.strip_prefix("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:40:20 + --> $DIR/single_char_pattern.rs:38:20 | LL | x.strip_suffix("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:41:15 + --> $DIR/single_char_pattern.rs:39:15 | LL | x.replace("x", "y"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:42:16 + --> $DIR/single_char_pattern.rs:40:16 | LL | x.replacen("x", "y", 3); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:44:13 + --> $DIR/single_char_pattern.rs:42:13 | LL | x.split("/n"); | ^^^^ help: try using a `char` instead: `'/n'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:45:13 + --> $DIR/single_char_pattern.rs:43:13 | LL | x.split("'"); | ^^^ help: try using a `char` instead: `'/''` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:46:13 + --> $DIR/single_char_pattern.rs:44:13 | LL | x.split("/'"); | ^^^^ help: try using a `char` instead: `'/''` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:51:31 + --> $DIR/single_char_pattern.rs:49:31 | LL | x.replace(';', ",").split(","); // issue #2978 | ^^^ help: try using a `char` instead: `','` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:52:19 + --> $DIR/single_char_pattern.rs:50:19 | LL | x.starts_with("/x03"); // issue #2996 | ^^^^^^ help: try using a `char` instead: `'/x03'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:59:13 + --> $DIR/single_char_pattern.rs:57:13 | LL | x.split(r"a"); | ^^^^ help: try using a `char` instead: `'a'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:60:13 + --> $DIR/single_char_pattern.rs:58:13 | LL | x.split(r#"a"#); | ^^^^^^ help: try using a `char` instead: `'a'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:61:13 + --> $DIR/single_char_pattern.rs:59:13 | LL | x.split(r###"a"###); | ^^^^^^^^^^ help: try using a `char` instead: `'a'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:62:13 + --> $DIR/single_char_pattern.rs:60:13 | LL | x.split(r###"'"###); | ^^^^^^^^^^ help: try using a `char` instead: `'/''` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:63:13 + --> $DIR/single_char_pattern.rs:61:13 | LL | x.split(r###"#"###); | ^^^^^^^^^^ help: try using a `char` instead: `'#'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:65:13 + --> $DIR/single_char_pattern.rs:63:13 | LL | x.split(r#"/"#); | ^^^^^^ help: try using a `char` instead: `'//'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:66:13 + --> $DIR/single_char_pattern.rs:64:13 | LL | x.split(r"/"); | ^^^^ help: try using a `char` instead: `'//'` diff --git a/tests/ui/single_component_path_imports.fixed b/tests/ui/single_component_path_imports.fixed index b6b6b0288c52c..fdff336c281b8 100644 --- a/tests/ui/single_component_path_imports.fixed +++ b/tests/ui/single_component_path_imports.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] diff --git a/tests/ui/single_component_path_imports.rs b/tests/ui/single_component_path_imports.rs index a8c4d8990856e..2d72f122adf2b 100644 --- a/tests/ui/single_component_path_imports.rs +++ b/tests/ui/single_component_path_imports.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] diff --git a/tests/ui/single_component_path_imports.stderr b/tests/ui/single_component_path_imports.stderr index 853a2fe0e7bf8..0bff108f86ac4 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 - --> $DIR/single_component_path_imports.rs:7:1 + --> $DIR/single_component_path_imports.rs:6:1 | LL | use regex; | ^^^^^^^^^^ help: remove it entirely @@ -7,7 +7,7 @@ LL | use regex; = note: `-D clippy::single-component-path-imports` implied by `-D warnings` error: this import is redundant - --> $DIR/single_component_path_imports.rs:33:5 + --> $DIR/single_component_path_imports.rs:32:5 | LL | use regex; | ^^^^^^^^^^ help: remove it entirely diff --git a/tests/ui/single_component_path_imports_nested_first.rs b/tests/ui/single_component_path_imports_nested_first.rs index d6243c19f554b..f9dec47e64022 100644 --- a/tests/ui/single_component_path_imports_nested_first.rs +++ b/tests/ui/single_component_path_imports_nested_first.rs @@ -1,6 +1,6 @@ #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] - +//@no-rustfix use regex; use serde as edres; diff --git a/tests/ui/single_element_loop.fixed b/tests/ui/single_element_loop.fixed index 598f259415da5..a82eb6afcf5f3 100644 --- a/tests/ui/single_element_loop.fixed +++ b/tests/ui/single_element_loop.fixed @@ -1,4 +1,3 @@ -//@run-rustfix // Tests from for_loop.rs that don't have suggestions #![allow(clippy::single_range_in_vec_init)] diff --git a/tests/ui/single_element_loop.rs b/tests/ui/single_element_loop.rs index 3fc461735a499..a55ece6b0650c 100644 --- a/tests/ui/single_element_loop.rs +++ b/tests/ui/single_element_loop.rs @@ -1,4 +1,3 @@ -//@run-rustfix // Tests from for_loop.rs that don't have suggestions #![allow(clippy::single_range_in_vec_init)] diff --git a/tests/ui/single_element_loop.stderr b/tests/ui/single_element_loop.stderr index c40c6198945a0..1d89bf5538794 100644 --- a/tests/ui/single_element_loop.stderr +++ b/tests/ui/single_element_loop.stderr @@ -1,5 +1,5 @@ error: for loop over a single element - --> $DIR/single_element_loop.rs:9:5 + --> $DIR/single_element_loop.rs:8:5 | LL | / for item in &[item1] { LL | | dbg!(item); @@ -16,7 +16,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:13:5 + --> $DIR/single_element_loop.rs:12:5 | LL | / for item in [item1].iter() { LL | | dbg!(item); @@ -32,7 +32,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:17:5 + --> $DIR/single_element_loop.rs:16:5 | LL | / for item in &[0..5] { LL | | dbg!(item); @@ -48,7 +48,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:21:5 + --> $DIR/single_element_loop.rs:20:5 | LL | / for item in [0..5].iter_mut() { LL | | dbg!(item); @@ -64,7 +64,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:25:5 + --> $DIR/single_element_loop.rs:24:5 | LL | / for item in [0..5] { LL | | dbg!(item); @@ -80,7 +80,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:29:5 + --> $DIR/single_element_loop.rs:28:5 | LL | / for item in [0..5].into_iter() { LL | | dbg!(item); @@ -96,7 +96,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:48:5 + --> $DIR/single_element_loop.rs:47:5 | LL | / for _ in [42] { LL | | let _f = |n: u32| { diff --git a/tests/ui/single_match.fixed b/tests/ui/single_match.fixed index 163ba94aff802..0a49be2dc4f3e 100644 --- a/tests/ui/single_match.fixed +++ b/tests/ui/single_match.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_match)] #![allow( unused, diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs index 0dcdb125ffd8a..4e35d265acbf1 100644 --- a/tests/ui/single_match.rs +++ b/tests/ui/single_match.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_match)] #![allow( unused, diff --git a/tests/ui/single_match.stderr b/tests/ui/single_match.stderr index d35361599493e..76f7e78958985 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` - --> $DIR/single_match.rs:15:5 + --> $DIR/single_match.rs:14:5 | LL | / match x { LL | | Some(y) => { @@ -18,7 +18,7 @@ LL ~ }; | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:23:5 + --> $DIR/single_match.rs:22:5 | LL | / match x { LL | | // Note the missing block braces. @@ -30,7 +30,7 @@ LL | | } | |_____^ help: try: `if let Some(y) = x { println!("{:?}", y) }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match.rs:32:5 + --> $DIR/single_match.rs:31: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` - --> $DIR/single_match.rs:61:5 + --> $DIR/single_match.rs:60: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` - --> $DIR/single_match.rs:66:5 + --> $DIR/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` - --> $DIR/single_match.rs:73:5 + --> $DIR/single_match.rs:72: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` - --> $DIR/single_match.rs:94:5 + --> $DIR/single_match.rs:93: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` - --> $DIR/single_match.rs:107:5 + --> $DIR/single_match.rs:106: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` - --> $DIR/single_match.rs:113:5 + --> $DIR/single_match.rs:112: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` - --> $DIR/single_match.rs:118:5 + --> $DIR/single_match.rs:117: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` - --> $DIR/single_match.rs:124:5 + --> $DIR/single_match.rs:123: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` - --> $DIR/single_match.rs:141:5 + --> $DIR/single_match.rs:140: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` - --> $DIR/single_match.rs:149:5 + --> $DIR/single_match.rs:148: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` - --> $DIR/single_match.rs:171:5 + --> $DIR/single_match.rs:170: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` - --> $DIR/single_match.rs:177:5 + --> $DIR/single_match.rs:176: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` - --> $DIR/single_match.rs:183:5 + --> $DIR/single_match.rs:182: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` - --> $DIR/single_match.rs:255:5 + --> $DIR/single_match.rs:254: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` - --> $DIR/single_match.rs:263:5 + --> $DIR/single_match.rs:262:5 | LL | / match bar { LL | | #[rustfmt::skip] diff --git a/tests/ui/single_match_else.fixed b/tests/ui/single_match_else.fixed index fcc8f14803d31..e23c78aa484ff 100644 --- a/tests/ui/single_match_else.fixed +++ b/tests/ui/single_match_else.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![warn(clippy::single_match_else)] #![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs index 77afd58a08dc7..a33fb441668d4 100644 --- a/tests/ui/single_match_else.rs +++ b/tests/ui/single_match_else.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![warn(clippy::single_match_else)] #![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] diff --git a/tests/ui/single_match_else.stderr b/tests/ui/single_match_else.stderr index 5e7d4062efea0..e85d51de6a103 100644 --- a/tests/ui/single_match_else.stderr +++ b/tests/ui/single_match_else.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:17:13 + --> $DIR/single_match_else.rs:16:13 | LL | let _ = match ExprNode::Butterflies { | _____________^ @@ -21,7 +21,7 @@ LL ~ }; | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:82:5 + --> $DIR/single_match_else.rs:81:5 | LL | / match Some(1) { LL | | Some(a) => println!("${:?}", a), @@ -41,7 +41,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:91:5 + --> $DIR/single_match_else.rs:90:5 | LL | / match Some(1) { LL | | Some(a) => println!("${:?}", a), @@ -61,7 +61,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:101:5 + --> $DIR/single_match_else.rs:100:5 | LL | / match Result::::Ok(1) { LL | | Ok(a) => println!("${:?}", a), @@ -81,7 +81,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:110:5 + --> $DIR/single_match_else.rs:109:5 | LL | / match Cow::from("moo") { LL | | Cow::Owned(a) => println!("${:?}", a), @@ -101,7 +101,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:120:5 + --> $DIR/single_match_else.rs:119:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -124,7 +124,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:131:5 + --> $DIR/single_match_else.rs:130:5 | LL | / match bar { LL | | Some(v) => { @@ -148,7 +148,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:143:5 + --> $DIR/single_match_else.rs:142:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -172,7 +172,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> $DIR/single_match_else.rs:155:5 + --> $DIR/single_match_else.rs:154:5 | LL | / match bar { LL | | #[rustfmt::skip] diff --git a/tests/ui/single_range_in_vec_init.rs b/tests/ui/single_range_in_vec_init.rs index 833e1c43bfc0b..bf4e90837b29b 100644 --- a/tests/ui/single_range_in_vec_init.rs +++ b/tests/ui/single_range_in_vec_init.rs @@ -1,4 +1,5 @@ //@aux-build:proc_macros.rs:proc-macro +//@no-rustfix: overlapping suggestions #![allow(clippy::no_effect, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] #![feature(generic_arg_infer)] diff --git a/tests/ui/single_range_in_vec_init.stderr b/tests/ui/single_range_in_vec_init.stderr index 3e3d521f4a50e..1b347f4ae97f9 100644 --- a/tests/ui/single_range_in_vec_init.stderr +++ b/tests/ui/single_range_in_vec_init.stderr @@ -1,5 +1,5 @@ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:25:5 + --> $DIR/single_range_in_vec_init.rs:26:5 | LL | [0..200]; | ^^^^^^^^ @@ -15,7 +15,7 @@ LL | [0; 200]; | ~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:26:5 + --> $DIR/single_range_in_vec_init.rs:27:5 | LL | vec![0..200]; | ^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | vec![0; 200]; | ~~~~~~ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:27:5 + --> $DIR/single_range_in_vec_init.rs:28:5 | LL | [0u8..200]; | ^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | [0u8; 200]; | ~~~~~~~~ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:28:5 + --> $DIR/single_range_in_vec_init.rs:29:5 | LL | [0usize..200]; | ^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | [0usize; 200]; | ~~~~~~~~~~~ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:29:5 + --> $DIR/single_range_in_vec_init.rs:30:5 | LL | [0..200usize]; | ^^^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL | [0; 200usize]; | ~~~~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:30:5 + --> $DIR/single_range_in_vec_init.rs:31:5 | LL | vec![0u8..200]; | ^^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | vec![0u8; 200]; | ~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:31:5 + --> $DIR/single_range_in_vec_init.rs:32:5 | LL | vec![0usize..200]; | ^^^^^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ LL | vec![0usize; 200]; | ~~~~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:32:5 + --> $DIR/single_range_in_vec_init.rs:33:5 | LL | vec![0..200usize]; | ^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | vec![0; 200usize]; | ~~~~~~~~~~~ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:34:5 + --> $DIR/single_range_in_vec_init.rs:35:5 | LL | [0..200isize]; | ^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL | (0..200isize).collect::>(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:35:5 + --> $DIR/single_range_in_vec_init.rs:36:5 | LL | vec![0..200isize]; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/slow_vector_initialization.rs b/tests/ui/slow_vector_initialization.rs index cfb856861b8c6..b152a016d9a1f 100644 --- a/tests/ui/slow_vector_initialization.rs +++ b/tests/ui/slow_vector_initialization.rs @@ -1,5 +1,5 @@ use std::iter::repeat; - +//@no-rustfix fn main() { resize_vector(); extend_vector(); diff --git a/tests/ui/stable_sort_primitive.fixed b/tests/ui/stable_sort_primitive.fixed index 50c1fc71a3f9e..97f3a92238d20 100644 --- a/tests/ui/stable_sort_primitive.fixed +++ b/tests/ui/stable_sort_primitive.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::stable_sort_primitive)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/stable_sort_primitive.rs b/tests/ui/stable_sort_primitive.rs index bd1bb428f2bbe..26e3d8e74f715 100644 --- a/tests/ui/stable_sort_primitive.rs +++ b/tests/ui/stable_sort_primitive.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::stable_sort_primitive)] #![allow(clippy::useless_vec)] diff --git a/tests/ui/stable_sort_primitive.stderr b/tests/ui/stable_sort_primitive.stderr index aa5d7b7e49146..1432fdcff77ad 100644 --- a/tests/ui/stable_sort_primitive.stderr +++ b/tests/ui/stable_sort_primitive.stderr @@ -1,5 +1,5 @@ error: used `sort` on primitive type `i32` - --> $DIR/stable_sort_primitive.rs:8:5 + --> $DIR/stable_sort_primitive.rs:7:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -8,7 +8,7 @@ LL | vec.sort(); = note: `-D clippy::stable-sort-primitive` implied by `-D warnings` error: used `sort` on primitive type `bool` - --> $DIR/stable_sort_primitive.rs:10:5 + --> $DIR/stable_sort_primitive.rs:9:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -16,7 +16,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `char` - --> $DIR/stable_sort_primitive.rs:12:5 + --> $DIR/stable_sort_primitive.rs:11:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -24,7 +24,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `str` - --> $DIR/stable_sort_primitive.rs:14:5 + --> $DIR/stable_sort_primitive.rs:13:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -32,7 +32,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `tuple` - --> $DIR/stable_sort_primitive.rs:16:5 + --> $DIR/stable_sort_primitive.rs:15:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -40,7 +40,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `array` - --> $DIR/stable_sort_primitive.rs:18:5 + --> $DIR/stable_sort_primitive.rs:17:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -48,7 +48,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `i32` - --> $DIR/stable_sort_primitive.rs:20:5 + --> $DIR/stable_sort_primitive.rs:19:5 | LL | arr.sort(); | ^^^^^^^^^^ help: try: `arr.sort_unstable()` diff --git a/tests/ui/starts_ends_with.fixed b/tests/ui/starts_ends_with.fixed index b7237069dc5ce..4a66ca7ec91a1 100644 --- a/tests/ui/starts_ends_with.fixed +++ b/tests/ui/starts_ends_with.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_if, dead_code, unused_must_use)] fn main() {} diff --git a/tests/ui/starts_ends_with.rs b/tests/ui/starts_ends_with.rs index 658312e87e47f..16a68e02d66d3 100644 --- a/tests/ui/starts_ends_with.rs +++ b/tests/ui/starts_ends_with.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_if, dead_code, unused_must_use)] fn main() {} diff --git a/tests/ui/starts_ends_with.stderr b/tests/ui/starts_ends_with.stderr index 2dd9f53b8026a..1e26bee7aa177 100644 --- a/tests/ui/starts_ends_with.stderr +++ b/tests/ui/starts_ends_with.stderr @@ -1,5 +1,5 @@ error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:8:5 + --> $DIR/starts_ends_with.rs:7:5 | LL | "".chars().next() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with(' ')` @@ -7,31 +7,31 @@ LL | "".chars().next() == Some(' '); = note: `-D clippy::chars-next-cmp` implied by `-D warnings` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:9:5 + --> $DIR/starts_ends_with.rs:8:5 | LL | Some(' ') != "".chars().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with(' ')` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:12:5 + --> $DIR/starts_ends_with.rs:11:5 | LL | "".chars().next() == Some('/n'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with('/n')` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:13:5 + --> $DIR/starts_ends_with.rs:12:5 | LL | Some('/n') != "".chars().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with('/n')` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:18:8 + --> $DIR/starts_ends_with.rs:17:8 | LL | if s.chars().next().unwrap() == 'f' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.starts_with('f')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:22:8 + --> $DIR/starts_ends_with.rs:21:8 | LL | if s.chars().next_back().unwrap() == 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` @@ -39,61 +39,61 @@ LL | if s.chars().next_back().unwrap() == 'o' { = note: `-D clippy::chars-last-cmp` implied by `-D warnings` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:26:8 + --> $DIR/starts_ends_with.rs:25:8 | LL | if s.chars().last().unwrap() == 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:30:8 + --> $DIR/starts_ends_with.rs:29:8 | LL | if s.chars().next().unwrap() != 'f' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.starts_with('f')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:34:8 + --> $DIR/starts_ends_with.rs:33:8 | LL | if s.chars().next_back().unwrap() != 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:38:8 + --> $DIR/starts_ends_with.rs:37:8 | LL | if s.chars().last().unwrap() != '/n' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('/n')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:46:5 + --> $DIR/starts_ends_with.rs:45:5 | LL | "".chars().last() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:47:5 + --> $DIR/starts_ends_with.rs:46:5 | LL | Some(' ') != "".chars().last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:48:5 + --> $DIR/starts_ends_with.rs:47:5 | LL | "".chars().next_back() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:49:5 + --> $DIR/starts_ends_with.rs:48:5 | LL | Some(' ') != "".chars().next_back(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:52:5 + --> $DIR/starts_ends_with.rs:51:5 | LL | "".chars().last() == Some('/n'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with('/n')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:53:5 + --> $DIR/starts_ends_with.rs:52:5 | LL | Some('/n') != "".chars().last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with('/n')` diff --git a/tests/ui/string_add.rs b/tests/ui/string_add.rs index 6980242ae727b..0baeba95bf7b7 100644 --- a/tests/ui/string_add.rs +++ b/tests/ui/string_add.rs @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs:proc-macro - +//@no-rustfix extern crate proc_macros; use proc_macros::external; diff --git a/tests/ui/string_add_assign.fixed b/tests/ui/string_add_assign.fixed index 616c6daaf6605..31d84831d09ab 100644 --- a/tests/ui/string_add_assign.fixed +++ b/tests/ui/string_add_assign.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[allow(clippy::string_add, unused)] #[warn(clippy::string_add_assign)] fn main() { diff --git a/tests/ui/string_add_assign.rs b/tests/ui/string_add_assign.rs index e1f8859757c64..cdea91573cc75 100644 --- a/tests/ui/string_add_assign.rs +++ b/tests/ui/string_add_assign.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[allow(clippy::string_add, unused)] #[warn(clippy::string_add_assign)] fn main() { diff --git a/tests/ui/string_add_assign.stderr b/tests/ui/string_add_assign.stderr index 7676175c1b82f..d4b995519e379 100644 --- a/tests/ui/string_add_assign.stderr +++ b/tests/ui/string_add_assign.stderr @@ -1,5 +1,5 @@ error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead - --> $DIR/string_add_assign.rs:10:9 + --> $DIR/string_add_assign.rs:8:9 | LL | x = x + "."; | ^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | x = x + "."; = note: `-D clippy::string-add-assign` implied by `-D warnings` error: manual implementation of an assign operation - --> $DIR/string_add_assign.rs:10:9 + --> $DIR/string_add_assign.rs:8:9 | LL | x = x + "."; | ^^^^^^^^^^^ help: replace it with: `x += "."` @@ -15,7 +15,7 @@ LL | x = x + "."; = note: `-D clippy::assign-op-pattern` implied by `-D warnings` error: manual implementation of an assign operation - --> $DIR/string_add_assign.rs:19:5 + --> $DIR/string_add_assign.rs:17:5 | LL | x = x + 1; | ^^^^^^^^^ help: replace it with: `x += 1` diff --git a/tests/ui/string_extend.fixed b/tests/ui/string_extend.fixed index 65c9abff3d418..142cb6a349804 100644 --- a/tests/ui/string_extend.fixed +++ b/tests/ui/string_extend.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[derive(Copy, Clone)] struct HasChars; diff --git a/tests/ui/string_extend.rs b/tests/ui/string_extend.rs index 5f72ffe2fda76..41c0d29fae9ca 100644 --- a/tests/ui/string_extend.rs +++ b/tests/ui/string_extend.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[derive(Copy, Clone)] struct HasChars; diff --git a/tests/ui/string_extend.stderr b/tests/ui/string_extend.stderr index 34b43290147e2..49ff4516db1b6 100644 --- a/tests/ui/string_extend.stderr +++ b/tests/ui/string_extend.stderr @@ -1,5 +1,5 @@ error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:18:5 + --> $DIR/string_extend.rs:16:5 | LL | s.extend(abc.chars()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(abc)` @@ -7,19 +7,19 @@ LL | s.extend(abc.chars()); = note: `-D clippy::string-extend-chars` implied by `-D warnings` error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:21:5 + --> $DIR/string_extend.rs:19:5 | LL | s.extend("abc".chars()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str("abc")` error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:24:5 + --> $DIR/string_extend.rs:22:5 | LL | s.extend(def.chars()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(&def)` error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:34:5 + --> $DIR/string_extend.rs:32:5 | LL | s.extend(abc[0..2].chars()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(&abc[0..2])` diff --git a/tests/ui/string_from_utf8_as_bytes.fixed b/tests/ui/string_from_utf8_as_bytes.fixed index 9b315ae2b5585..6aa5a95c6f40f 100644 --- a/tests/ui/string_from_utf8_as_bytes.fixed +++ b/tests/ui/string_from_utf8_as_bytes.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::string_from_utf8_as_bytes)] fn main() { diff --git a/tests/ui/string_from_utf8_as_bytes.rs b/tests/ui/string_from_utf8_as_bytes.rs index 043dd2350829b..c8717f7950bd8 100644 --- a/tests/ui/string_from_utf8_as_bytes.rs +++ b/tests/ui/string_from_utf8_as_bytes.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::string_from_utf8_as_bytes)] fn main() { diff --git a/tests/ui/string_from_utf8_as_bytes.stderr b/tests/ui/string_from_utf8_as_bytes.stderr index bf5e5d33e8f9a..0fa4d59068f8e 100644 --- a/tests/ui/string_from_utf8_as_bytes.stderr +++ b/tests/ui/string_from_utf8_as_bytes.stderr @@ -1,5 +1,5 @@ error: calling a slice of `as_bytes()` with `from_utf8` should be not necessary - --> $DIR/string_from_utf8_as_bytes.rs:5:13 + --> $DIR/string_from_utf8_as_bytes.rs:4:13 | LL | let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(&"Hello World!"[6..11])` diff --git a/tests/ui/string_lit_as_bytes.fixed b/tests/ui/string_lit_as_bytes.fixed index 0edd81acc7afb..225d4e90c4e2c 100644 --- a/tests/ui/string_lit_as_bytes.fixed +++ b/tests/ui/string_lit_as_bytes.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:macro_rules.rs #![allow(clippy::needless_raw_string_hashes, dead_code, unused_variables)] diff --git a/tests/ui/string_lit_as_bytes.rs b/tests/ui/string_lit_as_bytes.rs index 2647f02f0e92c..3d116214ca424 100644 --- a/tests/ui/string_lit_as_bytes.rs +++ b/tests/ui/string_lit_as_bytes.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:macro_rules.rs #![allow(clippy::needless_raw_string_hashes, dead_code, unused_variables)] diff --git a/tests/ui/string_lit_as_bytes.stderr b/tests/ui/string_lit_as_bytes.stderr index 61b4e210e0fb9..985432e04c47d 100644 --- a/tests/ui/string_lit_as_bytes.stderr +++ b/tests/ui/string_lit_as_bytes.stderr @@ -1,5 +1,5 @@ error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:17:14 + --> $DIR/string_lit_as_bytes.rs:16:14 | LL | let bs = "hello there".as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"` @@ -7,25 +7,25 @@ LL | let bs = "hello there".as_bytes(); = note: `-D clippy::string-lit-as-bytes` implied by `-D warnings` error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:19:14 + --> $DIR/string_lit_as_bytes.rs:18:14 | LL | let bs = r###"raw string with 3# plus " ""###.as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with 3# plus " ""###` error: calling `into_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:21:14 + --> $DIR/string_lit_as_bytes.rs:20:14 | LL | let bs = "lit to string".to_string().into_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"lit to string".to_vec()` error: calling `into_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:22:14 + --> $DIR/string_lit_as_bytes.rs:21:14 | LL | let bs = "lit to owned".to_owned().into_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"lit to owned".to_vec()` error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:12:26 + --> $DIR/string_lit_as_bytes.rs:11:26 | LL | const B: &[u8] = $b.as_bytes(); | ^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"warning"` @@ -36,13 +36,13 @@ LL | b!("warning"); = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info) error: calling `as_bytes()` on `include_str!(..)` - --> $DIR/string_lit_as_bytes.rs:39:22 + --> $DIR/string_lit_as_bytes.rs:38:22 | LL | let includestr = include_str!("string_lit_as_bytes.rs").as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("string_lit_as_bytes.rs")` error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:41:13 + --> $DIR/string_lit_as_bytes.rs:40:13 | LL | let _ = "string with newline/t/n".as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline/t/n"` diff --git a/tests/ui/string_lit_chars_any.fixed b/tests/ui/string_lit_chars_any.fixed index d7ab9c3397a12..b9e91ccd1cf53 100644 --- a/tests/ui/string_lit_chars_any.fixed +++ b/tests/ui/string_lit_chars_any.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::string_lit_chars_any)] diff --git a/tests/ui/string_lit_chars_any.rs b/tests/ui/string_lit_chars_any.rs index 9408d7bb2390c..d0ce6780da3e5 100644 --- a/tests/ui/string_lit_chars_any.rs +++ b/tests/ui/string_lit_chars_any.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::string_lit_chars_any)] diff --git a/tests/ui/string_lit_chars_any.stderr b/tests/ui/string_lit_chars_any.stderr index ff951b73deddf..270728bb8415f 100644 --- a/tests/ui/string_lit_chars_any.stderr +++ b/tests/ui/string_lit_chars_any.stderr @@ -1,5 +1,5 @@ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> $DIR/string_lit_chars_any.rs:19:5 + --> $DIR/string_lit_chars_any.rs:18:5 | LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| x == c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> $DIR/string_lit_chars_any.rs:20:5 + --> $DIR/string_lit_chars_any.rs:19:5 | LL | r#"/.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> $DIR/string_lit_chars_any.rs:21:5 + --> $DIR/string_lit_chars_any.rs:20:5 | LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> $DIR/string_lit_chars_any.rs:22:5 + --> $DIR/string_lit_chars_any.rs:21:5 | LL | r#"/.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal - --> $DIR/string_lit_chars_any.rs:24:5 + --> $DIR/string_lit_chars_any.rs:23:5 | LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/strlen_on_c_strings.fixed b/tests/ui/strlen_on_c_strings.fixed index ef207e28cca37..8304e2afd8b6b 100644 --- a/tests/ui/strlen_on_c_strings.fixed +++ b/tests/ui/strlen_on_c_strings.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::strlen_on_c_strings)] #![allow(dead_code)] #![feature(rustc_private)] diff --git a/tests/ui/strlen_on_c_strings.rs b/tests/ui/strlen_on_c_strings.rs index 03ec5f79d092c..deba40a9ea5e6 100644 --- a/tests/ui/strlen_on_c_strings.rs +++ b/tests/ui/strlen_on_c_strings.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::strlen_on_c_strings)] #![allow(dead_code)] #![feature(rustc_private)] diff --git a/tests/ui/strlen_on_c_strings.stderr b/tests/ui/strlen_on_c_strings.stderr index fcd17f6894040..81881fbe3bd39 100644 --- a/tests/ui/strlen_on_c_strings.stderr +++ b/tests/ui/strlen_on_c_strings.stderr @@ -1,5 +1,5 @@ error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:15:13 + --> $DIR/strlen_on_c_strings.rs:13:13 | LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstring.as_bytes().len()` @@ -7,37 +7,37 @@ LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) }; = note: `-D clippy::strlen-on-c-strings` implied by `-D warnings` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:19:13 + --> $DIR/strlen_on_c_strings.rs:17:13 | LL | let _ = unsafe { libc::strlen(cstr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstr.to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:21:13 + --> $DIR/strlen_on_c_strings.rs:19:13 | LL | let _ = unsafe { strlen(cstr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstr.to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:24:22 + --> $DIR/strlen_on_c_strings.rs:22:22 | LL | let _ = unsafe { strlen((*pcstr).as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*pcstr).to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:29:22 + --> $DIR/strlen_on_c_strings.rs:27:22 | LL | let _ = unsafe { strlen(unsafe_identity(cstr).as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unsafe_identity(cstr).to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:30:13 + --> $DIR/strlen_on_c_strings.rs:28:13 | LL | let _ = unsafe { strlen(unsafe { unsafe_identity(cstr) }.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unsafe { unsafe_identity(cstr) }.to_bytes().len()` error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:33:22 + --> $DIR/strlen_on_c_strings.rs:31:22 | LL | let _ = unsafe { strlen(f(cstr).as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `f(cstr).to_bytes().len()` diff --git a/tests/ui/suspicious_command_arg_space.fixed b/tests/ui/suspicious_command_arg_space.fixed new file mode 100644 index 0000000000000..65f8c85d8d9ad --- /dev/null +++ b/tests/ui/suspicious_command_arg_space.fixed @@ -0,0 +1,10 @@ +fn main() { + // Things it should warn about: + std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); + std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); + + // Things it should not warn about: + std::process::Command::new("echo").arg("hello world").spawn().unwrap(); + std::process::Command::new("a").arg("--fmt=%a %b %c").spawn().unwrap(); + std::process::Command::new("b").arg("-ldflags=-s -w").spawn().unwrap(); +} diff --git a/tests/ui/suspicious_doc_comments.fixed b/tests/ui/suspicious_doc_comments.fixed index bffda1cc41296..614fc03571e53 100644 --- a/tests/ui/suspicious_doc_comments.fixed +++ b/tests/ui/suspicious_doc_comments.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] diff --git a/tests/ui/suspicious_doc_comments.rs b/tests/ui/suspicious_doc_comments.rs index cdd972ee30fbf..7dcba0fefc981 100644 --- a/tests/ui/suspicious_doc_comments.rs +++ b/tests/ui/suspicious_doc_comments.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] diff --git a/tests/ui/suspicious_doc_comments.stderr b/tests/ui/suspicious_doc_comments.stderr index 6c167df27873c..8d2a2bdf6e99d 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 - --> $DIR/suspicious_doc_comments.rs:6:1 + --> $DIR/suspicious_doc_comments.rs:5:1 | LL | ///! Fake module documentation. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | //! Fake module documentation. | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:10:5 + --> $DIR/suspicious_doc_comments.rs:9:5 | LL | ///! This module contains useful functions. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | //! This module contains useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:22:5 + --> $DIR/suspicious_doc_comments.rs:21:5 | LL | / /**! This module contains useful functions. LL | | */ @@ -35,7 +35,7 @@ LL + */ | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:36:5 + --> $DIR/suspicious_doc_comments.rs:35:5 | LL | / ///! This module LL | | ///! contains @@ -50,7 +50,7 @@ LL ~ //! useful functions. | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:44:5 + --> $DIR/suspicious_doc_comments.rs:43:5 | LL | / ///! a LL | | ///! b @@ -63,7 +63,7 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:52:5 + --> $DIR/suspicious_doc_comments.rs:51:5 | LL | ///! a | ^^^^^^ @@ -74,7 +74,7 @@ LL | //! a | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:58:5 + --> $DIR/suspicious_doc_comments.rs:57:5 | LL | / ///! a LL | | @@ -89,7 +89,7 @@ LL ~ //! b | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:70:5 + --> $DIR/suspicious_doc_comments.rs:69:5 | LL | ///! Very cool macro | ^^^^^^^^^^^^^^^^^^^^ @@ -100,7 +100,7 @@ LL | //! Very cool macro | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:77:5 + --> $DIR/suspicious_doc_comments.rs:76:5 | LL | ///! Huh. | ^^^^^^^^^ diff --git a/tests/ui/suspicious_doc_comments_unfixable.rs b/tests/ui/suspicious_doc_comments_unfixable.rs index ad98c7f4966ff..5f1980b43c40f 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.rs +++ b/tests/ui/suspicious_doc_comments_unfixable.rs @@ -1,6 +1,6 @@ #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] - +//@no-rustfix ///! a ///! b /// c diff --git a/tests/ui/suspicious_operation_groupings.fixed b/tests/ui/suspicious_operation_groupings.fixed index 0e37701ec48b8..9d9732307c85e 100644 --- a/tests/ui/suspicious_operation_groupings.fixed +++ b/tests/ui/suspicious_operation_groupings.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suspicious_operation_groupings)] #![allow(dead_code, unused_parens, clippy::eq_op)] diff --git a/tests/ui/suspicious_operation_groupings.rs b/tests/ui/suspicious_operation_groupings.rs index dd4f3b71c378f..201b8e657f4b3 100644 --- a/tests/ui/suspicious_operation_groupings.rs +++ b/tests/ui/suspicious_operation_groupings.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suspicious_operation_groupings)] #![allow(dead_code, unused_parens, clippy::eq_op)] diff --git a/tests/ui/suspicious_operation_groupings.stderr b/tests/ui/suspicious_operation_groupings.stderr index 29f229245fed3..baf9bc74b000e 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 - --> $DIR/suspicious_operation_groupings.rs:16:9 + --> $DIR/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` @@ -7,151 +7,151 @@ LL | self.x == other.y && self.y == other.y && self.z == other.z = note: `-D clippy::suspicious-operation-groupings` implied by `-D warnings` error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:29:20 + --> $DIR/suspicious_operation_groupings.rs:28: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 - --> $DIR/suspicious_operation_groupings.rs:77:33 + --> $DIR/suspicious_operation_groupings.rs:76: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 - --> $DIR/suspicious_operation_groupings.rs:82:19 + --> $DIR/suspicious_operation_groupings.rs:81: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 - --> $DIR/suspicious_operation_groupings.rs:82:19 + --> $DIR/suspicious_operation_groupings.rs:81: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 - --> $DIR/suspicious_operation_groupings.rs:87:19 + --> $DIR/suspicious_operation_groupings.rs:86: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 - --> $DIR/suspicious_operation_groupings.rs:92:19 + --> $DIR/suspicious_operation_groupings.rs:91: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 - --> $DIR/suspicious_operation_groupings.rs:97:5 + --> $DIR/suspicious_operation_groupings.rs:96: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 - --> $DIR/suspicious_operation_groupings.rs:102:33 + --> $DIR/suspicious_operation_groupings.rs:101: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 - --> $DIR/suspicious_operation_groupings.rs:115:20 + --> $DIR/suspicious_operation_groupings.rs:114: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 - --> $DIR/suspicious_operation_groupings.rs:120:34 + --> $DIR/suspicious_operation_groupings.rs:119: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 - --> $DIR/suspicious_operation_groupings.rs:125:38 + --> $DIR/suspicious_operation_groupings.rs:124: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 - --> $DIR/suspicious_operation_groupings.rs:130:39 + --> $DIR/suspicious_operation_groupings.rs:129: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 - --> $DIR/suspicious_operation_groupings.rs:135:42 + --> $DIR/suspicious_operation_groupings.rs:134: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 - --> $DIR/suspicious_operation_groupings.rs:135:42 + --> $DIR/suspicious_operation_groupings.rs:134: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 - --> $DIR/suspicious_operation_groupings.rs:140:40 + --> $DIR/suspicious_operation_groupings.rs:139: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 - --> $DIR/suspicious_operation_groupings.rs:145:40 + --> $DIR/suspicious_operation_groupings.rs:144: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 - --> $DIR/suspicious_operation_groupings.rs:150:20 + --> $DIR/suspicious_operation_groupings.rs:149: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 - --> $DIR/suspicious_operation_groupings.rs:155:35 + --> $DIR/suspicious_operation_groupings.rs:154: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 - --> $DIR/suspicious_operation_groupings.rs:160:29 + --> $DIR/suspicious_operation_groupings.rs:159: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 - --> $DIR/suspicious_operation_groupings.rs:165:17 + --> $DIR/suspicious_operation_groupings.rs:164: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 - --> $DIR/suspicious_operation_groupings.rs:174:77 + --> $DIR/suspicious_operation_groupings.rs:173: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 - --> $DIR/suspicious_operation_groupings.rs:188:25 + --> $DIR/suspicious_operation_groupings.rs:187: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 - --> $DIR/suspicious_operation_groupings.rs:194:23 + --> $DIR/suspicious_operation_groupings.rs:193: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 - --> $DIR/suspicious_operation_groupings.rs:201:48 + --> $DIR/suspicious_operation_groupings.rs:200: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 - --> $DIR/suspicious_operation_groupings.rs:206:27 + --> $DIR/suspicious_operation_groupings.rs:205:27 | LL | -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a }) | ^^^^^^^^^^^^^ help: did you mean: `-s1.b < -s2.b` diff --git a/tests/ui/suspicious_to_owned.rs b/tests/ui/suspicious_to_owned.rs index cba21bf4a93a1..bf228264e23d4 100644 --- a/tests/ui/suspicious_to_owned.rs +++ b/tests/ui/suspicious_to_owned.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::suspicious_to_owned)] #![warn(clippy::implicit_clone)] #![allow(clippy::redundant_clone)] diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index c4ec7aa88a2a3..1c2618e513c3d 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 the Cow<'_, str> contents to become owned - --> $DIR/suspicious_to_owned.rs:16:13 + --> $DIR/suspicious_to_owned.rs:17:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cause the Cow<'_, [char; 3]> contents to become owned - --> $DIR/suspicious_to_owned.rs:26:13 + --> $DIR/suspicious_to_owned.rs:27:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, Vec> itself and does not cause the Cow<'_, Vec> contents to become owned - --> $DIR/suspicious_to_owned.rs:36:13 + --> $DIR/suspicious_to_owned.rs:37:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned - --> $DIR/suspicious_to_owned.rs:46:13 + --> $DIR/suspicious_to_owned.rs:47:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type - --> $DIR/suspicious_to_owned.rs:60:13 + --> $DIR/suspicious_to_owned.rs:61:13 | LL | let _ = String::from(moo).to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::from(moo).clone()` @@ -68,7 +68,7 @@ LL | let _ = String::from(moo).to_owned(); = note: `-D clippy::implicit-clone` implied by `-D warnings` error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> $DIR/suspicious_to_owned.rs:61:13 + --> $DIR/suspicious_to_owned.rs:62:13 | LL | let _ = moos_vec.to_owned(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `moos_vec.clone()` diff --git a/tests/ui/suspicious_xor_used_as_pow.rs b/tests/ui/suspicious_xor_used_as_pow.rs index eb9fc63fb1d46..f7c44c9e6fa1e 100644 --- a/tests/ui/suspicious_xor_used_as_pow.rs +++ b/tests/ui/suspicious_xor_used_as_pow.rs @@ -1,7 +1,7 @@ #![allow(unused)] #![warn(clippy::suspicious_xor_used_as_pow)] #![allow(clippy::eq_op)] - +//@no-rustfix macro_rules! macro_test { () => { 13 diff --git a/tests/ui/swap.fixed b/tests/ui/swap.fixed index 7b74a83b6df90..888665a17ad16 100644 --- a/tests/ui/swap.fixed +++ b/tests/ui/swap.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: macro_rules.rs #![warn(clippy::all)] diff --git a/tests/ui/swap.rs b/tests/ui/swap.rs index 93855cd7b5c29..c9ad776292907 100644 --- a/tests/ui/swap.rs +++ b/tests/ui/swap.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: macro_rules.rs #![warn(clippy::all)] diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr index 1097b29bba022..a3b9c2b744c98 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 - --> $DIR/swap.rs:29:5 + --> $DIR/swap.rs:28:5 | LL | / let temp = bar.a; LL | | bar.a = bar.b; @@ -10,7 +10,7 @@ LL | | bar.b = temp; = note: `-D clippy::manual-swap` implied by `-D warnings` error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:41:5 + --> $DIR/swap.rs:40:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -18,7 +18,7 @@ LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:50:5 + --> $DIR/swap.rs:49:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -26,7 +26,7 @@ LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:69:5 + --> $DIR/swap.rs:68:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -34,7 +34,7 @@ LL | | foo[1] = temp; | |__________________^ help: try: `foo.swap(0, 1);` error: this looks like you are swapping `a` and `b` manually - --> $DIR/swap.rs:80:5 + --> $DIR/swap.rs:79:5 | LL | / a ^= b; LL | | b ^= a; @@ -42,7 +42,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 - --> $DIR/swap.rs:88:5 + --> $DIR/swap.rs:87:5 | LL | / bar.a ^= bar.b; LL | | bar.b ^= bar.a; @@ -50,7 +50,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 - --> $DIR/swap.rs:96:5 + --> $DIR/swap.rs:95:5 | LL | / foo[0] ^= foo[1]; LL | | foo[1] ^= foo[0]; @@ -58,7 +58,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 - --> $DIR/swap.rs:125:5 + --> $DIR/swap.rs:124:5 | LL | / let temp = foo[0][1]; LL | | foo[0][1] = bar[1][0]; @@ -68,7 +68,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 - --> $DIR/swap.rs:139:7 + --> $DIR/swap.rs:138:7 | LL | ; let t = a; | _______^ @@ -79,7 +79,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 - --> $DIR/swap.rs:148:7 + --> $DIR/swap.rs:147:7 | LL | ; let t = c.0; | _______^ @@ -90,7 +90,7 @@ LL | | a = t; = note: or maybe you should use `std::mem::replace`? error: this looks like you are swapping `b` and `a` manually - --> $DIR/swap.rs:174:5 + --> $DIR/swap.rs:173:5 | LL | / let t = b; LL | | b = a; @@ -100,7 +100,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` - --> $DIR/swap.rs:136:5 + --> $DIR/swap.rs:135:5 | LL | / a = b; LL | | b = a; @@ -110,7 +110,7 @@ LL | | b = a; = note: `-D clippy::almost-swapped` implied by `-D warnings` error: this looks like you are trying to swap `c.0` and `a` - --> $DIR/swap.rs:145:5 + --> $DIR/swap.rs:144:5 | LL | / c.0 = a; LL | | a = c.0; @@ -119,7 +119,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` - --> $DIR/swap.rs:152:5 + --> $DIR/swap.rs:151:5 | LL | / let a = b; LL | | let b = a; @@ -128,7 +128,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` - --> $DIR/swap.rs:157:5 + --> $DIR/swap.rs:156:5 | LL | / d = c; LL | | c = d; @@ -137,7 +137,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` - --> $DIR/swap.rs:161:5 + --> $DIR/swap.rs:160:5 | LL | / let a = b; LL | | b = a; @@ -146,7 +146,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 - --> $DIR/swap.rs:209:5 + --> $DIR/swap.rs:208:5 | LL | / let t = s.0.x; LL | | s.0.x = s.0.y; diff --git a/tests/ui/swap_ptr_to_ref.fixed b/tests/ui/swap_ptr_to_ref.fixed index 3bede3017a13c..599bb0e804430 100644 --- a/tests/ui/swap_ptr_to_ref.fixed +++ b/tests/ui/swap_ptr_to_ref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::swap_ptr_to_ref)] use core::ptr::addr_of_mut; diff --git a/tests/ui/swap_ptr_to_ref.rs b/tests/ui/swap_ptr_to_ref.rs index 726b09d37643a..3a8a8daefddc7 100644 --- a/tests/ui/swap_ptr_to_ref.rs +++ b/tests/ui/swap_ptr_to_ref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::swap_ptr_to_ref)] use core::ptr::addr_of_mut; diff --git a/tests/ui/swap_ptr_to_ref.stderr b/tests/ui/swap_ptr_to_ref.stderr index 401ce070869a2..a0f5160ee207b 100644 --- a/tests/ui/swap_ptr_to_ref.stderr +++ b/tests/ui/swap_ptr_to_ref.stderr @@ -1,5 +1,5 @@ error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref.rs:13:9 + --> $DIR/swap_ptr_to_ref.rs:11:9 | LL | core::mem::swap(&mut *y, &mut *z); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use ptr::swap: `core::ptr::swap(y, z)` @@ -7,19 +7,19 @@ LL | core::mem::swap(&mut *y, &mut *z); = note: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref.rs:14:9 + --> $DIR/swap_ptr_to_ref.rs:12:9 | LL | core::mem::swap(&mut *y, &mut x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use ptr::swap: `core::ptr::swap(y, &mut x)` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref.rs:15:9 + --> $DIR/swap_ptr_to_ref.rs:13:9 | LL | core::mem::swap(&mut x, &mut *y); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use ptr::swap: `core::ptr::swap(&mut x, y)` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref.rs:16:9 + --> $DIR/swap_ptr_to_ref.rs:14:9 | LL | core::mem::swap(&mut *addr_of_mut!(x), &mut *addr_of_mut!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use ptr::swap: `core::ptr::swap(addr_of_mut!(x), addr_of_mut!(x))` diff --git a/tests/ui/tabs_in_doc_comments.fixed b/tests/ui/tabs_in_doc_comments.fixed index 21020182c241b..26cc5c27e88cc 100644 --- a/tests/ui/tabs_in_doc_comments.fixed +++ b/tests/ui/tabs_in_doc_comments.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::tabs_in_doc_comments)] #[allow(dead_code)] diff --git a/tests/ui/tabs_in_doc_comments.rs b/tests/ui/tabs_in_doc_comments.rs index df704267dd25a..14b06966ecc1a 100644 --- a/tests/ui/tabs_in_doc_comments.rs +++ b/tests/ui/tabs_in_doc_comments.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::tabs_in_doc_comments)] #[allow(dead_code)] diff --git a/tests/ui/tabs_in_doc_comments.stderr b/tests/ui/tabs_in_doc_comments.stderr index 355f2e8057964..9da05fbec682a 100644 --- a/tests/ui/tabs_in_doc_comments.stderr +++ b/tests/ui/tabs_in_doc_comments.stderr @@ -1,5 +1,5 @@ error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:12:9 + --> $DIR/tabs_in_doc_comments.rs:10:9 | LL | /// - First String: | ^^^^ help: consider using four spaces per tab @@ -7,43 +7,43 @@ LL | /// - First String: = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:13:9 + --> $DIR/tabs_in_doc_comments.rs:11:9 | LL | /// - needs to be inside here | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:16:9 + --> $DIR/tabs_in_doc_comments.rs:14:9 | LL | /// - Second String: | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:17:9 + --> $DIR/tabs_in_doc_comments.rs:15:9 | LL | /// - needs to be inside here | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:8:5 + --> $DIR/tabs_in_doc_comments.rs:6:5 | LL | /// - first one | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:8:13 + --> $DIR/tabs_in_doc_comments.rs:6:13 | LL | /// - first one | ^^^^^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:9:5 + --> $DIR/tabs_in_doc_comments.rs:7:5 | LL | /// - second one | ^^^^ help: consider using four spaces per tab error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:9:14 + --> $DIR/tabs_in_doc_comments.rs:7:14 | LL | /// - second one | ^^^^ help: consider using four spaces per tab diff --git a/tests/ui/to_digit_is_some.fixed b/tests/ui/to_digit_is_some.fixed index dc9be66d48ab4..2ef4c05289fdd 100644 --- a/tests/ui/to_digit_is_some.fixed +++ b/tests/ui/to_digit_is_some.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::to_digit_is_some)] fn main() { diff --git a/tests/ui/to_digit_is_some.rs b/tests/ui/to_digit_is_some.rs index d2a09ac30de4e..54d9545809c52 100644 --- a/tests/ui/to_digit_is_some.rs +++ b/tests/ui/to_digit_is_some.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::to_digit_is_some)] fn main() { diff --git a/tests/ui/to_digit_is_some.stderr b/tests/ui/to_digit_is_some.stderr index c4718825dc26f..9ece2fce664e4 100644 --- a/tests/ui/to_digit_is_some.stderr +++ b/tests/ui/to_digit_is_some.stderr @@ -1,5 +1,5 @@ error: use of `.to_digit(..).is_some()` - --> $DIR/to_digit_is_some.rs:9:13 + --> $DIR/to_digit_is_some.rs:7:13 | LL | let _ = d.to_digit(8).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d.is_digit(8)` @@ -7,7 +7,7 @@ LL | let _ = d.to_digit(8).is_some(); = note: `-D clippy::to-digit-is-some` implied by `-D warnings` error: use of `.to_digit(..).is_some()` - --> $DIR/to_digit_is_some.rs:10:13 + --> $DIR/to_digit_is_some.rs:8:13 | LL | let _ = char::to_digit(c, 8).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `char::is_digit(c, 8)` diff --git a/tests/ui/to_string_in_format_args_incremental.fixed b/tests/ui/to_string_in_format_args_incremental.fixed index 9f75ad895cda8..1f78957963663 100644 --- a/tests/ui/to_string_in_format_args_incremental.fixed +++ b/tests/ui/to_string_in_format_args_incremental.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@compile-flags: -C incremental=target/debug/test/incr // see https://github.com/rust-lang/rust-clippy/issues/10969 diff --git a/tests/ui/to_string_in_format_args_incremental.rs b/tests/ui/to_string_in_format_args_incremental.rs index 67115f7c5a7b7..514febe8c92de 100644 --- a/tests/ui/to_string_in_format_args_incremental.rs +++ b/tests/ui/to_string_in_format_args_incremental.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@compile-flags: -C incremental=target/debug/test/incr // see https://github.com/rust-lang/rust-clippy/issues/10969 diff --git a/tests/ui/to_string_in_format_args_incremental.stderr b/tests/ui/to_string_in_format_args_incremental.stderr index a992c54291495..b817efdd4f766 100644 --- a/tests/ui/to_string_in_format_args_incremental.stderr +++ b/tests/ui/to_string_in_format_args_incremental.stderr @@ -1,5 +1,5 @@ error: `to_string` applied to a type that implements `Display` in `println!` args - --> $DIR/to_string_in_format_args_incremental.rs:8:21 + --> $DIR/to_string_in_format_args_incremental.rs:7:21 | LL | println!("{}", s.to_string()); | ^^^^^^^^^^^^ help: remove this diff --git a/tests/ui/toplevel_ref_arg.fixed b/tests/ui/toplevel_ref_arg.fixed index 9ad45c7a817b4..ccceb4684a122 100644 --- a/tests/ui/toplevel_ref_arg.fixed +++ b/tests/ui/toplevel_ref_arg.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::toplevel_ref_arg)] #![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)] diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs index 45ccc024cbdec..14c476199b33d 100644 --- a/tests/ui/toplevel_ref_arg.rs +++ b/tests/ui/toplevel_ref_arg.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![warn(clippy::toplevel_ref_arg)] #![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)] diff --git a/tests/ui/toplevel_ref_arg.stderr b/tests/ui/toplevel_ref_arg.stderr index 407c2d9fcd33b..84017669f4750 100644 --- a/tests/ui/toplevel_ref_arg.stderr +++ b/tests/ui/toplevel_ref_arg.stderr @@ -1,5 +1,5 @@ error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:15:9 + --> $DIR/toplevel_ref_arg.rs:14:9 | LL | let ref _x = 1; | ----^^^^^^----- help: try: `let _x = &1;` @@ -7,31 +7,31 @@ LL | let ref _x = 1; = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:17:9 + --> $DIR/toplevel_ref_arg.rs:16:9 | LL | let ref _y: (&_, u8) = (&1, 2); | ----^^^^^^--------------------- help: try: `let _y: &(&_, u8) = &(&1, 2);` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:19:9 + --> $DIR/toplevel_ref_arg.rs:18:9 | LL | let ref _z = 1 + 2; | ----^^^^^^--------- help: try: `let _z = &(1 + 2);` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:21:9 + --> $DIR/toplevel_ref_arg.rs:20:9 | LL | let ref mut _z = 1 + 2; | ----^^^^^^^^^^--------- help: try: `let _z = &mut (1 + 2);` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:26:9 + --> $DIR/toplevel_ref_arg.rs:25:9 | LL | let ref _x = vec![1, 2, 3]; | ----^^^^^^----------------- help: try: `let _x = &vec![1, 2, 3];` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:36:17 + --> $DIR/toplevel_ref_arg.rs:35:17 | LL | inline!(let ref _y = 42;); | ----^^^^^^------ help: try: `let _y = &42;` diff --git a/tests/ui/trailing_zeros.fixed b/tests/ui/trailing_zeros.fixed new file mode 100644 index 0000000000000..60db3c07ce90b --- /dev/null +++ b/tests/ui/trailing_zeros.fixed @@ -0,0 +1,10 @@ +#![allow(unused_parens)] +#![warn(clippy::verbose_bit_mask)] + +fn main() { + let x: i32 = 42; + let _ = x.trailing_zeros() >= 4; // suggest trailing_zeros + let _ = x.trailing_zeros() >= 5; // suggest trailing_zeros + let _ = x & 0b1_1010 == 0; // do not lint + let _ = x & 1 == 0; // do not lint +} diff --git a/tests/ui/trait_duplication_in_bounds.fixed b/tests/ui/trait_duplication_in_bounds.fixed index fdac0e4cb1e83..4fca29698e06b 100644 --- a/tests/ui/trait_duplication_in_bounds.fixed +++ b/tests/ui/trait_duplication_in_bounds.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::trait_duplication_in_bounds)] #![allow(unused)] diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs index a0300da555588..f67c8e35ed4cf 100644 --- a/tests/ui/trait_duplication_in_bounds.rs +++ b/tests/ui/trait_duplication_in_bounds.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::trait_duplication_in_bounds)] #![allow(unused)] diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr index 539b6114ca3ae..61a45538b65c1 100644 --- a/tests/ui/trait_duplication_in_bounds.stderr +++ b/tests/ui/trait_duplication_in_bounds.stderr @@ -1,59 +1,59 @@ error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:7:15 + --> $DIR/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 - --> $DIR/trait_duplication_in_bounds.rs:2:9 + --> $DIR/trait_duplication_in_bounds.rs:1:9 | LL | #![deny(clippy::trait_duplication_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: these where clauses contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:13:8 + --> $DIR/trait_duplication_in_bounds.rs:12:8 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:41:26 + --> $DIR/trait_duplication_in_bounds.rs:40:26 | LL | trait BadSelfTraitBound: Clone + Clone + Clone { | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these where clauses contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:48:15 + --> $DIR/trait_duplication_in_bounds.rs:47:15 | LL | Self: Clone + Clone + Clone; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:62:24 + --> $DIR/trait_duplication_in_bounds.rs:61:24 | LL | trait BadTraitBound { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these where clauses contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:69:12 + --> $DIR/trait_duplication_in_bounds.rs:68:12 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:102:19 + --> $DIR/trait_duplication_in_bounds.rs:101:19 | LL | fn bad_generic + GenericTrait + GenericTrait>(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `GenericTrait + GenericTrait` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:110:22 + --> $DIR/trait_duplication_in_bounds.rs:109:22 | LL | fn qualified_path(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::clone::Clone + foo::Clone` error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds.rs:118:33 + --> $DIR/trait_duplication_in_bounds.rs:117:33 | LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) { | ^^^^^^^^^^^^^^^^^ help: try: `Any + Send` diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index 1cbacf0feab54..9bd83d089af3e 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -1,5 +1,5 @@ #![allow(dead_code, clippy::borrow_as_ptr, clippy::needless_lifetimes)] - +//@no-rustfix extern crate core; use std::mem::transmute as my_transmute; diff --git a/tests/ui/transmute_float_to_int.fixed b/tests/ui/transmute_float_to_int.fixed new file mode 100644 index 0000000000000..37dbb9141da3a --- /dev/null +++ b/tests/ui/transmute_float_to_int.fixed @@ -0,0 +1,25 @@ +#![warn(clippy::transmute_float_to_int)] + +fn float_to_int() { + let _: u32 = unsafe { 1f32.to_bits() }; + let _: i32 = unsafe { 1f32.to_bits() as i32 }; + let _: u64 = unsafe { 1f64.to_bits() }; + let _: i64 = unsafe { 1f64.to_bits() as i64 }; + let _: u64 = unsafe { 1.0f64.to_bits() }; + let _: u64 = unsafe { (-1.0f64).to_bits() }; +} + +mod issue_5747 { + const VALUE32: i32 = unsafe { std::mem::transmute(1f32) }; + const VALUE64: u64 = unsafe { std::mem::transmute(1f64) }; + + const fn to_bits_32(v: f32) -> u32 { + unsafe { std::mem::transmute(v) } + } + + const fn to_bits_64(v: f64) -> i64 { + unsafe { std::mem::transmute(v) } + } +} + +fn main() {} diff --git a/tests/ui/transmute_int_to_non_zero.fixed b/tests/ui/transmute_int_to_non_zero.fixed new file mode 100644 index 0000000000000..b055a7c31c29b --- /dev/null +++ b/tests/ui/transmute_int_to_non_zero.fixed @@ -0,0 +1,41 @@ +#![warn(clippy::transmute_int_to_non_zero)] + +use core::num::*; + +fn main() { + let int_u8: u8 = 1; + let int_u16: u16 = 1; + let int_u32: u32 = 1; + let int_u64: u64 = 1; + let int_u128: u128 = 1; + + let int_i8: i8 = 1; + let int_i16: i16 = 1; + let int_i32: i32 = 1; + let int_i64: i64 = 1; + let int_i128: i128 = 1; + + let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; + let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; + let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) }; + let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) }; + let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) }; + + let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) }; + let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) }; + let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) }; + let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) }; + let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) }; + + let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; + let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; + let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) }; + let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) }; + let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) }; + + let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) }; + let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) }; + let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) }; + let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) }; + let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) }; +} diff --git a/tests/ui/transmute_ptr_to_ptr.fixed b/tests/ui/transmute_ptr_to_ptr.fixed new file mode 100644 index 0000000000000..5380c49b96a12 --- /dev/null +++ b/tests/ui/transmute_ptr_to_ptr.fixed @@ -0,0 +1,63 @@ +#![warn(clippy::transmute_ptr_to_ptr)] +#![allow(clippy::borrow_as_ptr)] + +// Make sure we can modify lifetimes, which is one of the recommended uses +// of transmute + +// Make sure we can do static lifetime transmutes +unsafe fn transmute_lifetime_to_static<'a, T>(t: &'a T) -> &'static T { + std::mem::transmute::<&'a T, &'static T>(t) +} + +// Make sure we can do non-static lifetime transmutes +unsafe fn transmute_lifetime<'a, 'b, T>(t: &'a T, u: &'b T) -> &'b T { + std::mem::transmute::<&'a T, &'b T>(t) +} + +struct LifetimeParam<'a> { + s: &'a str, +} + +struct GenericParam { + t: T, +} + +fn transmute_ptr_to_ptr() { + let ptr = &1u32 as *const u32; + let mut_ptr = &mut 1u32 as *mut u32; + unsafe { + // pointer-to-pointer transmutes; bad + let _: *const f32 = ptr as *const f32; + let _: *mut f32 = mut_ptr as *mut f32; + // ref-ref transmutes; bad + let _: &f32 = &*(&1u32 as *const u32 as *const f32); + let _: &f64 = &*(&1f32 as *const f32 as *const f64); + //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not + // the same type + let _: &mut f32 = &mut *(&mut 1u32 as *mut u32 as *mut f32); + let _: &GenericParam = &*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam); + } + + // these are recommendations for solving the above; if these lint we need to update + // those suggestions + let _ = ptr as *const f32; + let _ = mut_ptr as *mut f32; + let _ = unsafe { &*(&1u32 as *const u32 as *const f32) }; + let _ = unsafe { &mut *(&mut 1u32 as *mut u32 as *mut f32) }; + + // transmute internal lifetimes, should not lint + let s = "hello world".to_owned(); + let lp = LifetimeParam { s: &s }; + let _: &LifetimeParam<'static> = unsafe { std::mem::transmute(&lp) }; + let _: &GenericParam<&LifetimeParam<'static>> = unsafe { std::mem::transmute(&GenericParam { t: &lp }) }; +} + +// dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959) +const _: &() = { + struct Zst; + let zst = &Zst; + + unsafe { std::mem::transmute::<&'static Zst, &'static ()>(zst) } +}; + +fn main() {} diff --git a/tests/ui/transmute_ptr_to_ref.fixed b/tests/ui/transmute_ptr_to_ref.fixed index 215f0ac184225..acec14ccb6b82 100644 --- a/tests/ui/transmute_ptr_to_ref.fixed +++ b/tests/ui/transmute_ptr_to_ref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::transmute_ptr_to_ref)] #![allow(clippy::match_single_binding, clippy::unnecessary_cast)] diff --git a/tests/ui/transmute_ptr_to_ref.rs b/tests/ui/transmute_ptr_to_ref.rs index 3528e13790393..3376401e284b5 100644 --- a/tests/ui/transmute_ptr_to_ref.rs +++ b/tests/ui/transmute_ptr_to_ref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::transmute_ptr_to_ref)] #![allow(clippy::match_single_binding, clippy::unnecessary_cast)] diff --git a/tests/ui/transmute_ptr_to_ref.stderr b/tests/ui/transmute_ptr_to_ref.stderr index b3e6c09d2d7a1..c63b5524edb49 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`) - --> $DIR/transmute_ptr_to_ref.rs:7:17 + --> $DIR/transmute_ptr_to_ref.rs:5:17 | LL | let _: &T = std::mem::transmute(p); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*p` @@ -7,127 +7,127 @@ LL | let _: &T = std::mem::transmute(p); = note: `-D clippy::transmute-ptr-to-ref` implied by `-D warnings` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:10:21 + --> $DIR/transmute_ptr_to_ref.rs:8:21 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:13:17 + --> $DIR/transmute_ptr_to_ref.rs:11:17 | LL | let _: &T = std::mem::transmute(m); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*m` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:16:21 + --> $DIR/transmute_ptr_to_ref.rs:14:21 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:19:17 + --> $DIR/transmute_ptr_to_ref.rs:17:17 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:22:21 + --> $DIR/transmute_ptr_to_ref.rs:20:21 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:25:17 + --> $DIR/transmute_ptr_to_ref.rs:23:17 | 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>`) - --> $DIR/transmute_ptr_to_ref.rs:35:32 + --> $DIR/transmute_ptr_to_ref.rs:33: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>`) - --> $DIR/transmute_ptr_to_ref.rs:37:33 + --> $DIR/transmute_ptr_to_ref.rs:35: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`) - --> $DIR/transmute_ptr_to_ref.rs:41:14 + --> $DIR/transmute_ptr_to_ref.rs:39: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 (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:46:14 + --> $DIR/transmute_ptr_to_ref.rs:44:14 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:47:14 + --> $DIR/transmute_ptr_to_ref.rs:45:14 | LL | 1 => std::mem::transmute(y), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:48:14 + --> $DIR/transmute_ptr_to_ref.rs:46:14 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:49:14 + --> $DIR/transmute_ptr_to_ref.rs:47:14 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:57:19 + --> $DIR/transmute_ptr_to_ref.rs:55:19 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:58:19 + --> $DIR/transmute_ptr_to_ref.rs:56:19 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:60:14 + --> $DIR/transmute_ptr_to_ref.rs:58:14 | LL | 0 => std::mem::transmute(x), | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()` error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`) - --> $DIR/transmute_ptr_to_ref.rs:61:14 + --> $DIR/transmute_ptr_to_ref.rs:59:14 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:69:19 + --> $DIR/transmute_ptr_to_ref.rs:67:19 | LL | let _: &u32 = std::mem::transmute(a); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a` error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`) - --> $DIR/transmute_ptr_to_ref.rs:70:19 + --> $DIR/transmute_ptr_to_ref.rs:68:19 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:72:14 + --> $DIR/transmute_ptr_to_ref.rs:70:14 | 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`) - --> $DIR/transmute_ptr_to_ref.rs:73:14 + --> $DIR/transmute_ptr_to_ref.rs:71:14 | LL | _ => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &'b u32)` diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index 05aa86c479ad6..08b8e786611da 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::transmutes_expressible_as_ptr_casts)] // These two warnings currently cover the cases transmutes_expressible_as_ptr_casts // would otherwise be responsible for diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index 29fa6914cfd0b..92eb765e5f94e 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::transmutes_expressible_as_ptr_casts)] // These two warnings currently cover the cases transmutes_expressible_as_ptr_casts // would otherwise be responsible for diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 58f5162c78e78..846b982cdeaca 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 an integer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:18:39 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:17:39 | LL | let _ptr_i32_transmute = unsafe { transmute::(usize::MAX) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `usize::MAX as *const i32` @@ -7,7 +7,7 @@ LL | let _ptr_i32_transmute = unsafe { transmute::(usize: = note: `-D clippy::useless-transmute` implied by `-D warnings` error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:22:38 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:21:38 | LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as *const i8` @@ -15,13 +15,13 @@ LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` error: transmute from a pointer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:28:46 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:27:46 | LL | let _ptr_to_unsized_transmute = unsafe { transmute::<*const [i32], *const [u32]>(slice_ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice_ptr as *const [u32]` error: transmute from `*const i32` to `usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:34:50 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:33:50 | LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` @@ -29,37 +29,37 @@ LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, us = note: `-D clippy::transmutes-expressible-as-ptr-casts` implied by `-D warnings` error: transmute from a reference to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:40:41 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:39:41 | LL | let _array_ptr_transmute = unsafe { transmute::<&[i32; 4], *const [i32; 4]>(array_ref) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array_ref as *const [i32; 4]` error: transmute from `fn(usize) -> u8` to `*const usize` which could be expressed as a pointer cast instead - --> $DIR/transmutes_expressible_as_ptr_casts.rs:48:41 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:47: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 - --> $DIR/transmutes_expressible_as_ptr_casts.rs:52:49 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:51: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 - --> $DIR/transmutes_expressible_as_ptr_casts.rs:55:36 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:54: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 - --> $DIR/transmutes_expressible_as_ptr_casts.rs:66:14 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:65: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 - --> $DIR/transmutes_expressible_as_ptr_casts.rs:84:28 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:83:28 | LL | let _x: u8 = unsafe { *std::mem::transmute::(f) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(f as *const u8)` diff --git a/tests/ui/trim_split_whitespace.fixed b/tests/ui/trim_split_whitespace.fixed index 7909b319ddd5a..6d3daf798a675 100644 --- a/tests/ui/trim_split_whitespace.fixed +++ b/tests/ui/trim_split_whitespace.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::trim_split_whitespace)] #![allow(clippy::let_unit_value)] diff --git a/tests/ui/trim_split_whitespace.rs b/tests/ui/trim_split_whitespace.rs index 0cf58979fb207..b49d9e8b3fab8 100644 --- a/tests/ui/trim_split_whitespace.rs +++ b/tests/ui/trim_split_whitespace.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::trim_split_whitespace)] #![allow(clippy::let_unit_value)] diff --git a/tests/ui/trim_split_whitespace.stderr b/tests/ui/trim_split_whitespace.stderr index 5ae7849e27d2b..0379d79ae986e 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` - --> $DIR/trim_split_whitespace.rs:62:23 + --> $DIR/trim_split_whitespace.rs:61:23 | LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` @@ -7,43 +7,43 @@ LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint = note: `-D clippy::trim-split-whitespace` implied by `-D warnings` error: found call to `str::trim_start` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:63:23 + --> $DIR/trim_split_whitespace.rs:62: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` - --> $DIR/trim_split_whitespace.rs:64:23 + --> $DIR/trim_split_whitespace.rs:63: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` - --> $DIR/trim_split_whitespace.rs:67:37 + --> $DIR/trim_split_whitespace.rs:66: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` - --> $DIR/trim_split_whitespace.rs:68:37 + --> $DIR/trim_split_whitespace.rs:67: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` - --> $DIR/trim_split_whitespace.rs:69:37 + --> $DIR/trim_split_whitespace.rs:68: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` - --> $DIR/trim_split_whitespace.rs:76:15 + --> $DIR/trim_split_whitespace.rs:75:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` error: found call to `str::trim` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:84:15 + --> $DIR/trim_split_whitespace.rs:83:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` diff --git a/tests/ui/trivially_copy_pass_by_ref.rs b/tests/ui/trivially_copy_pass_by_ref.rs index 86f5cc937f445..3575e9f4f4cb8 100644 --- a/tests/ui/trivially_copy_pass_by_ref.rs +++ b/tests/ui/trivially_copy_pass_by_ref.rs @@ -8,7 +8,7 @@ clippy::uninlined_format_args, clippy::needless_pass_by_ref_mut )] - +//@no-rustfix #[derive(Copy, Clone)] struct Foo(u32); diff --git a/tests/ui/try_err.fixed b/tests/ui/try_err.fixed index 930489fab7646..060ef7b2a6d4c 100644 --- a/tests/ui/try_err.fixed +++ b/tests/ui/try_err.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![deny(clippy::try_err)] diff --git a/tests/ui/try_err.rs b/tests/ui/try_err.rs index f5baf3d8f744d..e3a58c91b2a3b 100644 --- a/tests/ui/try_err.rs +++ b/tests/ui/try_err.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![deny(clippy::try_err)] diff --git a/tests/ui/try_err.stderr b/tests/ui/try_err.stderr index 9968b383ebbc9..887889ffd111d 100644 --- a/tests/ui/try_err.stderr +++ b/tests/ui/try_err.stderr @@ -1,35 +1,35 @@ error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:23:9 + --> $DIR/try_err.rs:22:9 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err)` | note: the lint level is defined here - --> $DIR/try_err.rs:4:9 + --> $DIR/try_err.rs:3:9 | LL | #![deny(clippy::try_err)] | ^^^^^^^^^^^^^^^ error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:33:9 + --> $DIR/try_err.rs:32:9 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err.into())` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:53:17 + --> $DIR/try_err.rs:52:17 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err)` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:72:17 + --> $DIR/try_err.rs:71:17 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err.into())` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:92:23 + --> $DIR/try_err.rs:91:23 | LL | Err(_) => Err(1)?, | ^^^^^^^ help: try: `return Err(1)` @@ -37,7 +37,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 - --> $DIR/try_err.rs:99:23 + --> $DIR/try_err.rs:98:23 | LL | Err(_) => Err(inline!(1))?, | ^^^^^^^^^^^^^^^^ help: try: `return Err(inline!(1))` @@ -45,31 +45,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 - --> $DIR/try_err.rs:126:9 + --> $DIR/try_err.rs:125:9 | LL | Err(inline!(inline!(String::from("aasdfasdfasdfa"))))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Err(inline!(inline!(String::from("aasdfasdfasdfa"))))` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:133:9 + --> $DIR/try_err.rs:132:9 | LL | Err(io::ErrorKind::WriteZero)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:135:9 + --> $DIR/try_err.rs:134: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 - --> $DIR/try_err.rs:143:9 + --> $DIR/try_err.rs:142:9 | LL | Err(io::ErrorKind::NotFound)? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:152:16 + --> $DIR/try_err.rs:151:16 | LL | return Err(42)?; | ^^^^^^^^ help: try: `Err(42)` diff --git a/tests/ui/type_id_on_box.fixed b/tests/ui/type_id_on_box.fixed index 615d809c8975c..538c38b70e6b3 100644 --- a/tests/ui/type_id_on_box.fixed +++ b/tests/ui/type_id_on_box.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::type_id_on_box)] use std::any::{Any, TypeId}; diff --git a/tests/ui/type_id_on_box.rs b/tests/ui/type_id_on_box.rs index 74b6c74ae5f6f..f224d273bc236 100644 --- a/tests/ui/type_id_on_box.rs +++ b/tests/ui/type_id_on_box.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::type_id_on_box)] use std::any::{Any, TypeId}; diff --git a/tests/ui/type_id_on_box.stderr b/tests/ui/type_id_on_box.stderr index 1525328c0d03c..442f2c6b84770 100644 --- a/tests/ui/type_id_on_box.stderr +++ b/tests/ui/type_id_on_box.stderr @@ -1,5 +1,5 @@ error: calling `.type_id()` on a `Box` - --> $DIR/type_id_on_box.rs:26:13 + --> $DIR/type_id_on_box.rs:24:13 | LL | let _ = any_box.type_id(); | -------^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | let _ = any_box.type_id(); = note: `-D clippy::type-id-on-box` implied by `-D warnings` error: calling `.type_id()` on a `Box` - --> $DIR/type_id_on_box.rs:30:13 + --> $DIR/type_id_on_box.rs:28:13 | LL | let _ = any_box.type_id(); // 2 derefs are needed here to get to the `dyn Any` | -------^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | let _ = any_box.type_id(); // 2 derefs are needed here to get to the `d = note: if this is intentional, use `TypeId::of::>()` instead, which makes it more clear error: calling `.type_id()` on a `Box` - --> $DIR/type_id_on_box.rs:36:13 + --> $DIR/type_id_on_box.rs:34:13 | LL | let _ = b.type_id(); | -^^^^^^^^^^ diff --git a/tests/ui/types.fixed b/tests/ui/types.fixed index 4a2616a7a228e..6f1f55f0e62c8 100644 --- a/tests/ui/types.fixed +++ b/tests/ui/types.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code, unused_variables)] #![warn(clippy::cast_lossless)] diff --git a/tests/ui/types.rs b/tests/ui/types.rs index 5e0917907db75..960aee4600cae 100644 --- a/tests/ui/types.rs +++ b/tests/ui/types.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code, unused_variables)] #![warn(clippy::cast_lossless)] diff --git a/tests/ui/types.stderr b/tests/ui/types.stderr index 59c3e05a1aa3c..0d489f625204f 100644 --- a/tests/ui/types.stderr +++ b/tests/ui/types.stderr @@ -1,5 +1,5 @@ error: casting `i32` to `i64` may become silently lossy if you later change the type - --> $DIR/types.rs:14:22 + --> $DIR/types.rs:12:22 | LL | let c_i64: i64 = c as i64; | ^^^^^^^^ help: try: `i64::from(c)` diff --git a/tests/ui/unchecked_duration_subtraction.fixed b/tests/ui/unchecked_duration_subtraction.fixed index 757d159218472..a0c3330d1777a 100644 --- a/tests/ui/unchecked_duration_subtraction.fixed +++ b/tests/ui/unchecked_duration_subtraction.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unchecked_duration_subtraction)] use std::time::{Duration, Instant}; diff --git a/tests/ui/unchecked_duration_subtraction.rs b/tests/ui/unchecked_duration_subtraction.rs index da7faab6753ef..fff1d13720d98 100644 --- a/tests/ui/unchecked_duration_subtraction.rs +++ b/tests/ui/unchecked_duration_subtraction.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unchecked_duration_subtraction)] use std::time::{Duration, Instant}; diff --git a/tests/ui/unchecked_duration_subtraction.stderr b/tests/ui/unchecked_duration_subtraction.stderr index a2e0aa1d7c089..fa47f6ee80622 100644 --- a/tests/ui/unchecked_duration_subtraction.stderr +++ b/tests/ui/unchecked_duration_subtraction.stderr @@ -1,5 +1,5 @@ error: unchecked subtraction of a 'Duration' from an 'Instant' - --> $DIR/unchecked_duration_subtraction.rs:10:13 + --> $DIR/unchecked_duration_subtraction.rs:9:13 | LL | let _ = _first - second; | ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap()` @@ -7,19 +7,19 @@ LL | let _ = _first - second; = note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings` error: unchecked subtraction of a 'Duration' from an 'Instant' - --> $DIR/unchecked_duration_subtraction.rs:12:13 + --> $DIR/unchecked_duration_subtraction.rs:11:13 | LL | let _ = Instant::now() - Duration::from_secs(5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap()` error: unchecked subtraction of a 'Duration' from an 'Instant' - --> $DIR/unchecked_duration_subtraction.rs:14:13 + --> $DIR/unchecked_duration_subtraction.rs:13:13 | LL | let _ = _first - Duration::from_secs(5); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap()` error: unchecked subtraction of a 'Duration' from an 'Instant' - --> $DIR/unchecked_duration_subtraction.rs:16:13 + --> $DIR/unchecked_duration_subtraction.rs:15:13 | LL | let _ = Instant::now() - second; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap()` diff --git a/tests/ui/unicode.fixed b/tests/ui/unicode.fixed index 032040c4805c8..f9efb4ec34c6c 100644 --- a/tests/ui/unicode.fixed +++ b/tests/ui/unicode.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #[warn(clippy::invisible_characters)] diff --git a/tests/ui/unicode.rs b/tests/ui/unicode.rs index dd215bc604870..bba613e228ed7 100644 --- a/tests/ui/unicode.rs +++ b/tests/ui/unicode.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #[warn(clippy::invisible_characters)] diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index 21cc22a778bc5..74ee48cc2f977 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -1,5 +1,5 @@ error: invisible character detected - --> $DIR/unicode.rs:6:12 + --> $DIR/unicode.rs:5: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"` @@ -7,19 +7,19 @@ LL | print!("Here >​< is a ZWS, and ​another"); = note: `-D clippy::invisible-characters` implied by `-D warnings` error: invisible character detected - --> $DIR/unicode.rs:8:12 + --> $DIR/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 - --> $DIR/unicode.rs:10:12 + --> $DIR/unicode.rs:9: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"` error: non-NFC Unicode sequence detected - --> $DIR/unicode.rs:16:12 + --> $DIR/unicode.rs:15:12 | LL | print!("̀àh?"); | ^^^^^ help: consider replacing the string with: `"̀àh?"` @@ -27,37 +27,37 @@ LL | print!("̀àh?"); = note: `-D clippy::unicode-not-nfc` implied by `-D warnings` error: literal non-ASCII character detected - --> $DIR/unicode.rs:24:16 + --> $DIR/unicode.rs:23:16 | LL | print!("Üben!"); | ^^^^^^^ help: consider replacing the string with: `"/u{dc}ben!"` | note: the lint level is defined here - --> $DIR/unicode.rs:21:13 + --> $DIR/unicode.rs:20:13 | LL | #![deny(clippy::non_ascii_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: literal non-ASCII character detected - --> $DIR/unicode.rs:30:36 + --> $DIR/unicode.rs:29:36 | LL | const _EMPTY_BLOCK: char = '▱'; | ^^^ help: consider replacing the string with: `'/u{25b1}'` error: literal non-ASCII character detected - --> $DIR/unicode.rs:31:35 + --> $DIR/unicode.rs:30:35 | LL | const _FULL_BLOCK: char = '▰'; | ^^^ help: consider replacing the string with: `'/u{25b0}'` error: literal non-ASCII character detected - --> $DIR/unicode.rs:51:21 + --> $DIR/unicode.rs:50: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 - --> $DIR/unicode.rs:40:17 + --> $DIR/unicode.rs:39:17 | LL | #![deny(clippy::non_ascii_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args.fixed b/tests/ui/uninlined_format_args.fixed index a042731a9bf5f..91ad964565cdd 100644 --- a/tests/ui/uninlined_format_args.fixed +++ b/tests/ui/uninlined_format_args.fixed @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs:proc-macro -//@run-rustfix + #![warn(clippy::uninlined_format_args)] #![allow(named_arguments_used_positionally, unused)] #![allow( diff --git a/tests/ui/uninlined_format_args.rs b/tests/ui/uninlined_format_args.rs index d830b74d6072d..0fc4a93ce73fa 100644 --- a/tests/ui/uninlined_format_args.rs +++ b/tests/ui/uninlined_format_args.rs @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs:proc-macro -//@run-rustfix + #![warn(clippy::uninlined_format_args)] #![allow(named_arguments_used_positionally, unused)] #![allow( diff --git a/tests/ui/uninlined_format_args_panic.edition2018.fixed b/tests/ui/uninlined_format_args_panic.edition2018.fixed index 559050b3df62c..f0d570efdcee7 100644 --- a/tests/ui/uninlined_format_args_panic.edition2018.fixed +++ b/tests/ui/uninlined_format_args_panic.edition2018.fixed @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::uninlined_format_args)] diff --git a/tests/ui/uninlined_format_args_panic.edition2018.stderr b/tests/ui/uninlined_format_args_panic.edition2018.stderr index 2c8061259229a..55a3bd08b3192 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 - --> $DIR/uninlined_format_args_panic.rs:11:5 + --> $DIR/uninlined_format_args_panic.rs:10: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 3a753b49caf3e..7c0f28c457642 100644 --- a/tests/ui/uninlined_format_args_panic.edition2021.fixed +++ b/tests/ui/uninlined_format_args_panic.edition2021.fixed @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::uninlined_format_args)] diff --git a/tests/ui/uninlined_format_args_panic.edition2021.stderr b/tests/ui/uninlined_format_args_panic.edition2021.stderr index fc7b125080e76..00e7e8f0ff79a 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 - --> $DIR/uninlined_format_args_panic.rs:11:5 + --> $DIR/uninlined_format_args_panic.rs:10:5 | LL | println!("val='{}'", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + println!("val='{var}'"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:14:9 + --> $DIR/uninlined_format_args_panic.rs:13:9 | LL | panic!("p1 {}", var); | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + panic!("p1 {var}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:17:9 + --> $DIR/uninlined_format_args_panic.rs:16:9 | LL | panic!("p2 {0}", var); | ^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + panic!("p2 {var}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:20:9 + --> $DIR/uninlined_format_args_panic.rs:19:9 | LL | panic!("p3 {var}", var = var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + panic!("p3 {var}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:30:5 + --> $DIR/uninlined_format_args_panic.rs:29:5 | LL | assert!(var == 1, "p5 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + assert!(var == 1, "p5 {var}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:31:5 + --> $DIR/uninlined_format_args_panic.rs:30:5 | LL | debug_assert!(var == 1, "p6 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninlined_format_args_panic.rs b/tests/ui/uninlined_format_args_panic.rs index 83fbb9afd2a19..fa594d9a96f0f 100644 --- a/tests/ui/uninlined_format_args_panic.rs +++ b/tests/ui/uninlined_format_args_panic.rs @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::uninlined_format_args)] diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index fded8db5daf93..e834bb4bd7d7d 100644 --- a/tests/ui/unit_arg.rs +++ b/tests/ui/unit_arg.rs @@ -1,4 +1,5 @@ //@aux-build: proc_macros.rs:proc-macro +//@no-rustfix: overlapping suggestions #![warn(clippy::unit_arg)] #![allow(unused_must_use, unused_variables)] #![allow( diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index 74d4d2f4052f7..1de9d44bb0d6e 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 - --> $DIR/unit_arg.rs:62:5 + --> $DIR/unit_arg.rs:63:5 | LL | / foo({ LL | | 1; @@ -20,7 +20,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:65:5 + --> $DIR/unit_arg.rs:66:5 | LL | foo(foo(1)); | ^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:66:5 + --> $DIR/unit_arg.rs:67:5 | LL | / foo({ LL | | foo(1); @@ -54,7 +54,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:71:5 + --> $DIR/unit_arg.rs:72:5 | LL | / b.bar({ LL | | 1; @@ -74,7 +74,7 @@ LL ~ b.bar(()); | error: passing unit values to a function - --> $DIR/unit_arg.rs:74:5 + --> $DIR/unit_arg.rs:75:5 | LL | taking_multiple_units(foo(0), foo(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -87,7 +87,7 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> $DIR/unit_arg.rs:75:5 + --> $DIR/unit_arg.rs:76:5 | LL | / taking_multiple_units(foo(0), { LL | | foo(1); @@ -110,7 +110,7 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> $DIR/unit_arg.rs:79:5 + --> $DIR/unit_arg.rs:80:5 | LL | / taking_multiple_units( LL | | { @@ -146,7 +146,7 @@ LL ~ ); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:90:13 + --> $DIR/unit_arg.rs:91:13 | LL | None.or(Some(foo(2))); | ^^^^^^^^^^^^ @@ -160,7 +160,7 @@ LL ~ }); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:93:5 + --> $DIR/unit_arg.rs:94:5 | LL | foo(foo(())); | ^^^^^^^^^^^^ @@ -172,7 +172,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:130:5 + --> $DIR/unit_arg.rs:131:5 | LL | Some(foo(1)) | ^^^^^^^^^^^^ diff --git a/tests/ui/unit_arg_empty_blocks.fixed b/tests/ui/unit_arg_empty_blocks.fixed index 8c065115a74e7..a947ded7b1e72 100644 --- a/tests/ui/unit_arg_empty_blocks.fixed +++ b/tests/ui/unit_arg_empty_blocks.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unit_arg)] #![allow(unused_must_use, unused_variables)] #![allow(clippy::no_effect, clippy::uninlined_format_args)] diff --git a/tests/ui/unit_arg_empty_blocks.rs b/tests/ui/unit_arg_empty_blocks.rs index af166b56ff488..058c4f84a9e87 100644 --- a/tests/ui/unit_arg_empty_blocks.rs +++ b/tests/ui/unit_arg_empty_blocks.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unit_arg)] #![allow(unused_must_use, unused_variables)] #![allow(clippy::no_effect, clippy::uninlined_format_args)] diff --git a/tests/ui/unit_arg_empty_blocks.stderr b/tests/ui/unit_arg_empty_blocks.stderr index c697dfb1efa26..d35e931697d21 100644 --- a/tests/ui/unit_arg_empty_blocks.stderr +++ b/tests/ui/unit_arg_empty_blocks.stderr @@ -1,5 +1,5 @@ error: passing a unit value to a function - --> $DIR/unit_arg_empty_blocks.rs:17:5 + --> $DIR/unit_arg_empty_blocks.rs:16:5 | LL | foo({}); | ^^^^--^ @@ -9,7 +9,7 @@ LL | foo({}); = note: `-D clippy::unit-arg` implied by `-D warnings` error: passing a unit value to a function - --> $DIR/unit_arg_empty_blocks.rs:18:5 + --> $DIR/unit_arg_empty_blocks.rs:17:5 | LL | foo3({}, 2, 2); | ^^^^^--^^^^^^^ @@ -17,7 +17,7 @@ LL | foo3({}, 2, 2); | help: use a unit literal instead: `()` error: passing unit values to a function - --> $DIR/unit_arg_empty_blocks.rs:19:5 + --> $DIR/unit_arg_empty_blocks.rs:18:5 | LL | taking_two_units({}, foo(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,7 +29,7 @@ LL ~ taking_two_units((), ()); | error: passing unit values to a function - --> $DIR/unit_arg_empty_blocks.rs:20:5 + --> $DIR/unit_arg_empty_blocks.rs:19:5 | LL | taking_three_units({}, foo(0), foo(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unit_hash.fixed b/tests/ui/unit_hash.fixed new file mode 100644 index 0000000000000..18d39dc3fc531 --- /dev/null +++ b/tests/ui/unit_hash.fixed @@ -0,0 +1,28 @@ +#![warn(clippy::unit_hash)] +#![allow(clippy::let_unit_value)] + +use std::collections::hash_map::DefaultHasher; +use std::hash::Hash; + +enum Foo { + Empty, + WithValue(u8), +} + +fn do_nothing() {} + +fn main() { + let mut state = DefaultHasher::new(); + let my_enum = Foo::Empty; + + match my_enum { + Foo::Empty => 0_u8.hash(&mut state), + Foo::WithValue(x) => x.hash(&mut state), + } + + let res = (); + 0_u8.hash(&mut state); + + #[allow(clippy::unit_arg)] + 0_u8.hash(&mut state); +} diff --git a/tests/ui/unknown_clippy_lints.fixed b/tests/ui/unknown_clippy_lints.fixed index debc7e152e739..cba32ce6b772a 100644 --- a/tests/ui/unknown_clippy_lints.fixed +++ b/tests/ui/unknown_clippy_lints.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::pedantic)] // Should suggest lowercase #![allow(clippy::all)] diff --git a/tests/ui/unknown_clippy_lints.rs b/tests/ui/unknown_clippy_lints.rs index 16140fd107917..c15d541974f00 100644 --- a/tests/ui/unknown_clippy_lints.rs +++ b/tests/ui/unknown_clippy_lints.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::pedantic)] // Should suggest lowercase #![allow(clippy::All)] diff --git a/tests/ui/unknown_clippy_lints.stderr b/tests/ui/unknown_clippy_lints.stderr index 880673eef3e40..d478df8056b5e 100644 --- a/tests/ui/unknown_clippy_lints.stderr +++ b/tests/ui/unknown_clippy_lints.stderr @@ -1,5 +1,5 @@ error: unknown lint: `clippy::All` - --> $DIR/unknown_clippy_lints.rs:5:10 + --> $DIR/unknown_clippy_lints.rs:3:10 | LL | #![allow(clippy::All)] | ^^^^^^^^^^^ help: did you mean: `clippy::all` @@ -7,43 +7,43 @@ LL | #![allow(clippy::All)] = note: `-D unknown-lints` implied by `-D warnings` error: unknown lint: `clippy::CMP_OWNED` - --> $DIR/unknown_clippy_lints.rs:6:9 + --> $DIR/unknown_clippy_lints.rs:4:9 | LL | #![warn(clippy::CMP_OWNED)] | ^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::cmp_owned` error: unknown lint: `clippy::if_not_els` - --> $DIR/unknown_clippy_lints.rs:9:8 + --> $DIR/unknown_clippy_lints.rs:7:8 | LL | #[warn(clippy::if_not_els)] | ^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::if_not_else` error: unknown lint: `clippy::UNNecsaRy_cAst` - --> $DIR/unknown_clippy_lints.rs:10:8 + --> $DIR/unknown_clippy_lints.rs:8:8 | LL | #[warn(clippy::UNNecsaRy_cAst)] | ^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unnecessary_cast` error: unknown lint: `clippy::useles_transute` - --> $DIR/unknown_clippy_lints.rs:11:8 + --> $DIR/unknown_clippy_lints.rs:9:8 | LL | #[warn(clippy::useles_transute)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::useless_transmute` error: unknown lint: `clippy::dead_cod` - --> $DIR/unknown_clippy_lints.rs:13:8 + --> $DIR/unknown_clippy_lints.rs:11:8 | LL | #[warn(clippy::dead_cod)] | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::eq_op` error: unknown lint: `clippy::unused_colle` - --> $DIR/unknown_clippy_lints.rs:15:8 + --> $DIR/unknown_clippy_lints.rs:13:8 | LL | #[warn(clippy::unused_colle)] | ^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unused_self` error: unknown lint: `clippy::const_static_lifetim` - --> $DIR/unknown_clippy_lints.rs:17:8 + --> $DIR/unknown_clippy_lints.rs:15:8 | LL | #[warn(clippy::const_static_lifetim)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::redundant_static_lifetimes` diff --git a/tests/ui/unnecessary_box_returns.rs b/tests/ui/unnecessary_box_returns.rs index ce7cc2e97cb25..bbe52d3735464 100644 --- a/tests/ui/unnecessary_box_returns.rs +++ b/tests/ui/unnecessary_box_returns.rs @@ -1,5 +1,5 @@ #![warn(clippy::unnecessary_box_returns)] - +//@no-rustfix trait Bar { // lint fn baz(&self) -> Box; diff --git a/tests/ui/unnecessary_cast.fixed b/tests/ui/unnecessary_cast.fixed index 2bf02f1341425..18dd53bf2b42c 100644 --- a/tests/ui/unnecessary_cast.fixed +++ b/tests/ui/unnecessary_cast.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:extern_fake_libc.rs #![warn(clippy::unnecessary_cast)] #![allow( diff --git a/tests/ui/unnecessary_cast.rs b/tests/ui/unnecessary_cast.rs index 25b6b0f9b07ba..fcdd4c60ccd01 100644 --- a/tests/ui/unnecessary_cast.rs +++ b/tests/ui/unnecessary_cast.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:extern_fake_libc.rs #![warn(clippy::unnecessary_cast)] #![allow( diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr index 19411a01b67d3..69bbcdf740717 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`) - --> $DIR/unnecessary_cast.rs:19:5 + --> $DIR/unnecessary_cast.rs:18:5 | LL | ptr as *const T | ^^^^^^^^^^^^^^^ help: try: `ptr` @@ -7,235 +7,235 @@ LL | ptr as *const T = note: `-D clippy::unnecessary-cast` implied by `-D warnings` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:54:5 + --> $DIR/unnecessary_cast.rs:53:5 | LL | 1i32 as i32; | ^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:55:5 + --> $DIR/unnecessary_cast.rs:54:5 | LL | 1f32 as f32; | ^^^^^^^^^^^ help: try: `1_f32` error: casting to the same type is unnecessary (`bool` -> `bool`) - --> $DIR/unnecessary_cast.rs:56:5 + --> $DIR/unnecessary_cast.rs:55:5 | LL | false as bool; | ^^^^^^^^^^^^^ help: try: `false` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:59:5 + --> $DIR/unnecessary_cast.rs:58:5 | LL | -1_i32 as i32; | ^^^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:60:5 + --> $DIR/unnecessary_cast.rs:59:5 | LL | - 1_i32 as i32; | ^^^^^^^^^^^^^^ help: try: `- 1_i32` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:61:5 + --> $DIR/unnecessary_cast.rs:60:5 | LL | -1f32 as f32; | ^^^^^^^^^^^^ help: try: `-1_f32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:62:5 + --> $DIR/unnecessary_cast.rs:61:5 | LL | 1_i32 as i32; | ^^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:63:5 + --> $DIR/unnecessary_cast.rs:62: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`) - --> $DIR/unnecessary_cast.rs:65:22 + --> $DIR/unnecessary_cast.rs:64: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`) - --> $DIR/unnecessary_cast.rs:67:5 + --> $DIR/unnecessary_cast.rs:66: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`) - --> $DIR/unnecessary_cast.rs:69:5 + --> $DIR/unnecessary_cast.rs:68: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`) - --> $DIR/unnecessary_cast.rs:80:5 + --> $DIR/unnecessary_cast.rs:79: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`) - --> $DIR/unnecessary_cast.rs:81:5 + --> $DIR/unnecessary_cast.rs:80: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`) - --> $DIR/unnecessary_cast.rs:83:5 + --> $DIR/unnecessary_cast.rs:82: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`) - --> $DIR/unnecessary_cast.rs:118:5 + --> $DIR/unnecessary_cast.rs:117:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> $DIR/unnecessary_cast.rs:120:5 + --> $DIR/unnecessary_cast.rs:119:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting integer literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:156:9 + --> $DIR/unnecessary_cast.rs:155:9 | LL | 100 as f32; | ^^^^^^^^^^ help: try: `100_f32` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:157:9 + --> $DIR/unnecessary_cast.rs:156:9 | LL | 100 as f64; | ^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:158:9 + --> $DIR/unnecessary_cast.rs:157:9 | LL | 100_i32 as f64; | ^^^^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:159:17 + --> $DIR/unnecessary_cast.rs:158:17 | LL | let _ = -100 as f32; | ^^^^^^^^^^^ help: try: `-100_f32` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:160:17 + --> $DIR/unnecessary_cast.rs:159:17 | LL | let _ = -100 as f64; | ^^^^^^^^^^^ help: try: `-100_f64` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:161:17 + --> $DIR/unnecessary_cast.rs:160:17 | LL | let _ = -100_i32 as f64; | ^^^^^^^^^^^^^^^ help: try: `-100_f64` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:162:9 + --> $DIR/unnecessary_cast.rs:161:9 | LL | 100. as f32; | ^^^^^^^^^^^ help: try: `100_f32` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:163:9 + --> $DIR/unnecessary_cast.rs:162:9 | LL | 100. as f64; | ^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `u32` is unnecessary - --> $DIR/unnecessary_cast.rs:175:9 + --> $DIR/unnecessary_cast.rs:174:9 | LL | 1 as u32; | ^^^^^^^^ help: try: `1_u32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:176:9 + --> $DIR/unnecessary_cast.rs:175:9 | LL | 0x10 as i32; | ^^^^^^^^^^^ help: try: `0x10_i32` error: casting integer literal to `usize` is unnecessary - --> $DIR/unnecessary_cast.rs:177:9 + --> $DIR/unnecessary_cast.rs:176:9 | LL | 0b10 as usize; | ^^^^^^^^^^^^^ help: try: `0b10_usize` error: casting integer literal to `u16` is unnecessary - --> $DIR/unnecessary_cast.rs:178:9 + --> $DIR/unnecessary_cast.rs:177:9 | LL | 0o73 as u16; | ^^^^^^^^^^^ help: try: `0o73_u16` error: casting integer literal to `u32` is unnecessary - --> $DIR/unnecessary_cast.rs:179:9 + --> $DIR/unnecessary_cast.rs:178:9 | LL | 1_000_000_000 as u32; | ^^^^^^^^^^^^^^^^^^^^ help: try: `1_000_000_000_u32` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:181:9 + --> $DIR/unnecessary_cast.rs:180:9 | LL | 1.0 as f64; | ^^^^^^^^^^ help: try: `1.0_f64` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:182:9 + --> $DIR/unnecessary_cast.rs:181:9 | LL | 0.5 as f32; | ^^^^^^^^^^ help: try: `0.5_f32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:186:17 + --> $DIR/unnecessary_cast.rs:185:17 | LL | let _ = -1 as i32; | ^^^^^^^^^ help: try: `-1_i32` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:187:17 + --> $DIR/unnecessary_cast.rs:186:17 | LL | let _ = -1.0 as f32; | ^^^^^^^^^^^ help: try: `-1.0_f32` error: casting to the same type is unnecessary (`i32` -> `i32`) - --> $DIR/unnecessary_cast.rs:193:18 + --> $DIR/unnecessary_cast.rs:192:18 | LL | let _ = &(x as i32); | ^^^^^^^^^^ help: try: `{ x }` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:199:22 + --> $DIR/unnecessary_cast.rs:198:22 | LL | let _: i32 = -(1) as i32; | ^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i64` is unnecessary - --> $DIR/unnecessary_cast.rs:201:22 + --> $DIR/unnecessary_cast.rs:200:22 | LL | let _: i64 = -(1) as i64; | ^^^^^^^^^^^ help: try: `-1_i64` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:208:22 + --> $DIR/unnecessary_cast.rs:207:22 | LL | let _: f64 = (-8.0 as f64).exp(); | ^^^^^^^^^^^^^ help: try: `(-8.0_f64)` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:210:23 + --> $DIR/unnecessary_cast.rs:209: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`) - --> $DIR/unnecessary_cast.rs:218:20 + --> $DIR/unnecessary_cast.rs:217:20 | LL | let _num = foo() as f32; | ^^^^^^^^^^^^ help: try: `foo()` diff --git a/tests/ui/unnecessary_cast_unfixable.rs b/tests/ui/unnecessary_cast_unfixable.rs index 0e027f6042e6f..89a50314fbcbf 100644 --- a/tests/ui/unnecessary_cast_unfixable.rs +++ b/tests/ui/unnecessary_cast_unfixable.rs @@ -1,5 +1,5 @@ #![warn(clippy::unnecessary_cast)] - +//@no-rustfix fn main() { let _ = std::ptr::null() as *const u8; } diff --git a/tests/ui/unnecessary_clone.rs b/tests/ui/unnecessary_clone.rs index 7ceed3c75fd85..90dd65a1d42fb 100644 --- a/tests/ui/unnecessary_clone.rs +++ b/tests/ui/unnecessary_clone.rs @@ -2,7 +2,7 @@ #![warn(clippy::clone_on_ref_ptr)] #![allow(unused)] #![allow(clippy::redundant_clone, clippy::uninlined_format_args, clippy::unnecessary_wraps)] - +//@no-rustfix use std::cell::RefCell; use std::rc::{self, Rc}; use std::sync::{self, Arc}; diff --git a/tests/ui/unnecessary_fold.fixed b/tests/ui/unnecessary_fold.fixed index bd1d4a152aebc..c884d26eb6176 100644 --- a/tests/ui/unnecessary_fold.fixed +++ b/tests/ui/unnecessary_fold.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] /// Calls which should trigger the `UNNECESSARY_FOLD` lint diff --git a/tests/ui/unnecessary_fold.rs b/tests/ui/unnecessary_fold.rs index d27cc460c44af..2e6d6ba52eb91 100644 --- a/tests/ui/unnecessary_fold.rs +++ b/tests/ui/unnecessary_fold.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] /// Calls which should trigger the `UNNECESSARY_FOLD` lint diff --git a/tests/ui/unnecessary_fold.stderr b/tests/ui/unnecessary_fold.stderr index 98979f7477fbb..10920470c1ade 100644 --- a/tests/ui/unnecessary_fold.stderr +++ b/tests/ui/unnecessary_fold.stderr @@ -1,5 +1,5 @@ error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:8:20 + --> $DIR/unnecessary_fold.rs:6:20 | LL | let _ = (0..3).fold(false, |acc, x| acc || x > 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` @@ -7,85 +7,85 @@ LL | let _ = (0..3).fold(false, |acc, x| acc || x > 2); = note: `-D clippy::unnecessary-fold` implied by `-D warnings` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:10:20 + --> $DIR/unnecessary_fold.rs:8:20 | LL | let _ = (0..3).fold(true, |acc, x| acc && x > 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `all(|x| x > 2)` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:12:25 + --> $DIR/unnecessary_fold.rs:10:25 | LL | let _: i32 = (0..3).fold(0, |acc, x| acc + x); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `sum()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:14:25 + --> $DIR/unnecessary_fold.rs:12:25 | LL | let _: i32 = (0..3).fold(1, |acc, x| acc * x); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `product()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:19:41 + --> $DIR/unnecessary_fold.rs:17:41 | LL | let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:49:10 + --> $DIR/unnecessary_fold.rs:47:10 | LL | .fold(false, |acc, x| acc || x > 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:60:33 + --> $DIR/unnecessary_fold.rs:58:33 | LL | assert_eq!(map.values().fold(0, |x, y| x + y), 0); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:63:30 + --> $DIR/unnecessary_fold.rs:61:30 | LL | let _ = map.values().fold(0, |x, y| x + y); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:64:30 + --> $DIR/unnecessary_fold.rs:62:30 | LL | let _ = map.values().fold(1, |x, y| x * y); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:65:35 + --> $DIR/unnecessary_fold.rs:63:35 | LL | let _: i32 = map.values().fold(0, |x, y| x + y); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:66:35 + --> $DIR/unnecessary_fold.rs:64:35 | LL | let _: i32 = map.values().fold(1, |x, y| x * y); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:67:31 + --> $DIR/unnecessary_fold.rs:65:31 | LL | anything(map.values().fold(0, |x, y| x + y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:68:31 + --> $DIR/unnecessary_fold.rs:66:31 | LL | anything(map.values().fold(1, |x, y| x * y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product::()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:69:26 + --> $DIR/unnecessary_fold.rs:67:26 | LL | num(map.values().fold(0, |x, y| x + y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum()` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:70:26 + --> $DIR/unnecessary_fold.rs:68:26 | LL | num(map.values().fold(1, |x, y| x * y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product()` diff --git a/tests/ui/unnecessary_iter_cloned.fixed b/tests/ui/unnecessary_iter_cloned.fixed index a0f8dd1a200db..ad0e5fab029ee 100644 --- a/tests/ui/unnecessary_iter_cloned.fixed +++ b/tests/ui/unnecessary_iter_cloned.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_assignments)] #![warn(clippy::unnecessary_to_owned)] diff --git a/tests/ui/unnecessary_iter_cloned.rs b/tests/ui/unnecessary_iter_cloned.rs index 98f2dfe754915..d3d59c4c70f5c 100644 --- a/tests/ui/unnecessary_iter_cloned.rs +++ b/tests/ui/unnecessary_iter_cloned.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_assignments)] #![warn(clippy::unnecessary_to_owned)] diff --git a/tests/ui/unnecessary_iter_cloned.stderr b/tests/ui/unnecessary_iter_cloned.stderr index 8f151e620a25e..e9df5afa6b9f5 100644 --- a/tests/ui/unnecessary_iter_cloned.stderr +++ b/tests/ui/unnecessary_iter_cloned.stderr @@ -1,5 +1,5 @@ error: unnecessary use of `copied` - --> $DIR/unnecessary_iter_cloned.rs:31:22 + --> $DIR/unnecessary_iter_cloned.rs:29:22 | LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL + let other = match get_file_path(t) { | error: unnecessary use of `copied` - --> $DIR/unnecessary_iter_cloned.rs:46:22 + --> $DIR/unnecessary_iter_cloned.rs:44:22 | LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_join.fixed b/tests/ui/unnecessary_join.fixed index f13a5275e31b5..dab09be7ebd09 100644 --- a/tests/ui/unnecessary_join.fixed +++ b/tests/ui/unnecessary_join.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_join)] #![allow(clippy::uninlined_format_args, clippy::useless_vec)] diff --git a/tests/ui/unnecessary_join.rs b/tests/ui/unnecessary_join.rs index 6014d723a2f40..d042d9e5c2128 100644 --- a/tests/ui/unnecessary_join.rs +++ b/tests/ui/unnecessary_join.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_join)] #![allow(clippy::uninlined_format_args, clippy::useless_vec)] diff --git a/tests/ui/unnecessary_join.stderr b/tests/ui/unnecessary_join.stderr index e919a6d1d8aa3..80e5bc63a65e8 100644 --- a/tests/ui/unnecessary_join.stderr +++ b/tests/ui/unnecessary_join.stderr @@ -1,5 +1,5 @@ error: called `.collect::>().join("")` on an iterator - --> $DIR/unnecessary_join.rs:11:10 + --> $DIR/unnecessary_join.rs:10:10 | LL | .collect::>() | __________^ @@ -9,7 +9,7 @@ LL | | .join(""); = note: `-D clippy::unnecessary-join` implied by `-D warnings` error: called `.collect::>().join("")` on an iterator - --> $DIR/unnecessary_join.rs:20:10 + --> $DIR/unnecessary_join.rs:19:10 | LL | .collect::>() | __________^ diff --git a/tests/ui/unnecessary_lazy_eval.fixed b/tests/ui/unnecessary_lazy_eval.fixed index dca38034177b2..165406090a71e 100644 --- a/tests/ui/unnecessary_lazy_eval.fixed +++ b/tests/ui/unnecessary_lazy_eval.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![warn(clippy::unnecessary_lazy_evaluations)] #![allow(clippy::redundant_closure)] diff --git a/tests/ui/unnecessary_lazy_eval.rs b/tests/ui/unnecessary_lazy_eval.rs index 7fda719edc1b7..68af4200bbb7a 100644 --- a/tests/ui/unnecessary_lazy_eval.rs +++ b/tests/ui/unnecessary_lazy_eval.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: proc_macros.rs:proc-macro #![warn(clippy::unnecessary_lazy_evaluations)] #![allow(clippy::redundant_closure)] diff --git a/tests/ui/unnecessary_lazy_eval.stderr b/tests/ui/unnecessary_lazy_eval.stderr index 458eed1f359ad..2850a632fc774 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` - --> $DIR/unnecessary_lazy_eval.rs:69:13 + --> $DIR/unnecessary_lazy_eval.rs:68:13 | LL | let _ = opt.unwrap_or_else(|| 2); | ^^^^-------------------- @@ -9,7 +9,7 @@ LL | let _ = opt.unwrap_or_else(|| 2); = note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:70:13 + --> $DIR/unnecessary_lazy_eval.rs:69:13 | LL | let _ = opt.unwrap_or_else(|| astronomers_pi); | ^^^^--------------------------------- @@ -17,7 +17,7 @@ LL | let _ = opt.unwrap_or_else(|| astronomers_pi); | help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:71:13 + --> $DIR/unnecessary_lazy_eval.rs:70:13 | LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); | ^^^^------------------------------------- @@ -25,7 +25,7 @@ LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); | help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:73:13 + --> $DIR/unnecessary_lazy_eval.rs:72:13 | LL | let _ = opt.and_then(|_| ext_opt); | ^^^^--------------------- @@ -33,7 +33,7 @@ LL | let _ = opt.and_then(|_| ext_opt); | help: use `and(..)` instead: `and(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:74:13 + --> $DIR/unnecessary_lazy_eval.rs:73:13 | LL | let _ = opt.or_else(|| ext_opt); | ^^^^------------------- @@ -41,7 +41,7 @@ LL | let _ = opt.or_else(|| ext_opt); | help: use `or(..)` instead: `or(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:75:13 + --> $DIR/unnecessary_lazy_eval.rs:74:13 | LL | let _ = opt.or_else(|| None); | ^^^^---------------- @@ -49,7 +49,7 @@ LL | let _ = opt.or_else(|| None); | help: use `or(..)` instead: `or(None)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:76:13 + --> $DIR/unnecessary_lazy_eval.rs:75:13 | LL | let _ = opt.get_or_insert_with(|| 2); | ^^^^------------------------ @@ -57,7 +57,7 @@ LL | let _ = opt.get_or_insert_with(|| 2); | help: use `get_or_insert(..)` instead: `get_or_insert(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:77:13 + --> $DIR/unnecessary_lazy_eval.rs:76:13 | LL | let _ = opt.ok_or_else(|| 2); | ^^^^---------------- @@ -65,7 +65,7 @@ LL | let _ = opt.ok_or_else(|| 2); | help: use `ok_or(..)` instead: `ok_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:78:13 + --> $DIR/unnecessary_lazy_eval.rs:77:13 | LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); | ^^^^^^^^^^^^^^^^^------------------------------- @@ -73,7 +73,7 @@ LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); | help: use `unwrap_or(..)` instead: `unwrap_or(Some((1, 2)))` error: unnecessary closure used with `bool::then` - --> $DIR/unnecessary_lazy_eval.rs:79:13 + --> $DIR/unnecessary_lazy_eval.rs:78:13 | LL | let _ = cond.then(|| astronomers_pi); | ^^^^^----------------------- @@ -81,7 +81,7 @@ LL | let _ = cond.then(|| astronomers_pi); | help: use `then_some(..)` instead: `then_some(astronomers_pi)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:83:13 + --> $DIR/unnecessary_lazy_eval.rs:82:13 | LL | let _ = Some(1).unwrap_or_else(|| *r); | ^^^^^^^^--------------------- @@ -89,7 +89,7 @@ LL | let _ = Some(1).unwrap_or_else(|| *r); | help: use `unwrap_or(..)` instead: `unwrap_or(*r)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:85:13 + --> $DIR/unnecessary_lazy_eval.rs:84:13 | LL | let _ = Some(1).unwrap_or_else(|| *b); | ^^^^^^^^--------------------- @@ -97,7 +97,7 @@ LL | let _ = Some(1).unwrap_or_else(|| *b); | help: use `unwrap_or(..)` instead: `unwrap_or(*b)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:87:13 + --> $DIR/unnecessary_lazy_eval.rs:86:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r); | ^^^^^^^^^^^^^^^^^--------------------- @@ -105,7 +105,7 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r); | help: use `unwrap_or(..)` instead: `unwrap_or(&r)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:88:13 + --> $DIR/unnecessary_lazy_eval.rs:87:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b); | ^^^^^^^^^^^^^^^^^--------------------- @@ -113,7 +113,7 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b); | help: use `unwrap_or(..)` instead: `unwrap_or(&b)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:91:13 + --> $DIR/unnecessary_lazy_eval.rs:90:13 | LL | let _ = Some(10).unwrap_or_else(|| 2); | ^^^^^^^^^-------------------- @@ -121,7 +121,7 @@ LL | let _ = Some(10).unwrap_or_else(|| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:92:13 + --> $DIR/unnecessary_lazy_eval.rs:91:13 | LL | let _ = Some(10).and_then(|_| ext_opt); | ^^^^^^^^^--------------------- @@ -129,7 +129,7 @@ LL | let _ = Some(10).and_then(|_| ext_opt); | help: use `and(..)` instead: `and(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:93:28 + --> $DIR/unnecessary_lazy_eval.rs:92:28 | LL | let _: Option = None.or_else(|| ext_opt); | ^^^^^------------------- @@ -137,7 +137,7 @@ LL | let _: Option = None.or_else(|| ext_opt); | help: use `or(..)` instead: `or(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:94:13 + --> $DIR/unnecessary_lazy_eval.rs:93:13 | LL | let _ = None.get_or_insert_with(|| 2); | ^^^^^------------------------ @@ -145,7 +145,7 @@ LL | let _ = None.get_or_insert_with(|| 2); | help: use `get_or_insert(..)` instead: `get_or_insert(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:95:35 + --> $DIR/unnecessary_lazy_eval.rs:94:35 | LL | let _: Result = None.ok_or_else(|| 2); | ^^^^^---------------- @@ -153,7 +153,7 @@ LL | let _: Result = None.ok_or_else(|| 2); | help: use `ok_or(..)` instead: `ok_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:96:28 + --> $DIR/unnecessary_lazy_eval.rs:95:28 | LL | let _: Option = None.or_else(|| None); | ^^^^^---------------- @@ -161,7 +161,7 @@ LL | let _: Option = None.or_else(|| None); | help: use `or(..)` instead: `or(None)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:99:13 + --> $DIR/unnecessary_lazy_eval.rs:98:13 | LL | let _ = deep.0.unwrap_or_else(|| 2); | ^^^^^^^-------------------- @@ -169,7 +169,7 @@ LL | let _ = deep.0.unwrap_or_else(|| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:100:13 + --> $DIR/unnecessary_lazy_eval.rs:99:13 | LL | let _ = deep.0.and_then(|_| ext_opt); | ^^^^^^^--------------------- @@ -177,7 +177,7 @@ LL | let _ = deep.0.and_then(|_| ext_opt); | help: use `and(..)` instead: `and(ext_opt)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:101:13 + --> $DIR/unnecessary_lazy_eval.rs:100:13 | LL | let _ = deep.0.or_else(|| None); | ^^^^^^^---------------- @@ -185,7 +185,7 @@ LL | let _ = deep.0.or_else(|| None); | help: use `or(..)` instead: `or(None)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:102:13 + --> $DIR/unnecessary_lazy_eval.rs:101:13 | LL | let _ = deep.0.get_or_insert_with(|| 2); | ^^^^^^^------------------------ @@ -193,7 +193,7 @@ LL | let _ = deep.0.get_or_insert_with(|| 2); | help: use `get_or_insert(..)` instead: `get_or_insert(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:103:13 + --> $DIR/unnecessary_lazy_eval.rs:102:13 | LL | let _ = deep.0.ok_or_else(|| 2); | ^^^^^^^---------------- @@ -201,7 +201,7 @@ LL | let _ = deep.0.ok_or_else(|| 2); | help: use `ok_or(..)` instead: `ok_or(2)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:133:28 + --> $DIR/unnecessary_lazy_eval.rs:132:28 | LL | let _: Option = None.or_else(|| Some(3)); | ^^^^^------------------- @@ -209,7 +209,7 @@ LL | let _: Option = None.or_else(|| Some(3)); | help: use `or(..)` instead: `or(Some(3))` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:134:13 + --> $DIR/unnecessary_lazy_eval.rs:133:13 | LL | let _ = deep.0.or_else(|| Some(3)); | ^^^^^^^------------------- @@ -217,7 +217,7 @@ LL | let _ = deep.0.or_else(|| Some(3)); | help: use `or(..)` instead: `or(Some(3))` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:135:13 + --> $DIR/unnecessary_lazy_eval.rs:134:13 | LL | let _ = opt.or_else(|| Some(3)); | ^^^^------------------- @@ -225,7 +225,7 @@ LL | let _ = opt.or_else(|| Some(3)); | help: use `or(..)` instead: `or(Some(3))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:141:13 + --> $DIR/unnecessary_lazy_eval.rs:140:13 | LL | let _ = res2.unwrap_or_else(|_| 2); | ^^^^^--------------------- @@ -233,7 +233,7 @@ LL | let _ = res2.unwrap_or_else(|_| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:142:13 + --> $DIR/unnecessary_lazy_eval.rs:141:13 | LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); | ^^^^^---------------------------------- @@ -241,7 +241,7 @@ LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); | help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:143:13 + --> $DIR/unnecessary_lazy_eval.rs:142:13 | LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); | ^^^^^-------------------------------------- @@ -249,7 +249,7 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); | help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:165:35 + --> $DIR/unnecessary_lazy_eval.rs:164:35 | LL | let _: Result = res.and_then(|_| Err(2)); | ^^^^-------------------- @@ -257,7 +257,7 @@ LL | let _: Result = res.and_then(|_| Err(2)); | help: use `and(..)` instead: `and(Err(2))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:166:35 + --> $DIR/unnecessary_lazy_eval.rs:165:35 | LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); | ^^^^--------------------------------- @@ -265,7 +265,7 @@ LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); | help: use `and(..)` instead: `and(Err(astronomers_pi))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:167:35 + --> $DIR/unnecessary_lazy_eval.rs:166:35 | LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)); | ^^^^------------------------------------- @@ -273,7 +273,7 @@ LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)) | help: use `and(..)` instead: `and(Err(ext_str.some_field))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:169:35 + --> $DIR/unnecessary_lazy_eval.rs:168:35 | LL | let _: Result = res.or_else(|_| Ok(2)); | ^^^^------------------ @@ -281,7 +281,7 @@ LL | let _: Result = res.or_else(|_| Ok(2)); | help: use `or(..)` instead: `or(Ok(2))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:170:35 + --> $DIR/unnecessary_lazy_eval.rs:169:35 | LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); | ^^^^------------------------------- @@ -289,7 +289,7 @@ LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); | help: use `or(..)` instead: `or(Ok(astronomers_pi))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:171:35 + --> $DIR/unnecessary_lazy_eval.rs:170:35 | LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); | ^^^^----------------------------------- @@ -297,7 +297,7 @@ LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); | help: use `or(..)` instead: `or(Ok(ext_str.some_field))` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval.rs:172:35 + --> $DIR/unnecessary_lazy_eval.rs:171:35 | LL | let _: Result = res. | ___________________________________^ diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.rs b/tests/ui/unnecessary_lazy_eval_unfixable.rs index b4a1f81679ad9..d529cd3109cfe 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.rs +++ b/tests/ui/unnecessary_lazy_eval_unfixable.rs @@ -1,6 +1,6 @@ #![warn(clippy::unnecessary_lazy_evaluations)] #![allow(clippy::unnecessary_literal_unwrap)] - +//@no-rustfix struct Deep(Option); #[derive(Copy, Clone)] diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed index 72d52c62355c8..87df1f8cb08fb 100644 --- a/tests/ui/unnecessary_literal_unwrap.fixed +++ b/tests/ui/unnecessary_literal_unwrap.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_literal_unwrap)] #![allow(unreachable_code)] #![allow( diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs index 7d713ea205f3c..7bd8deea4d1b3 100644 --- a/tests/ui/unnecessary_literal_unwrap.rs +++ b/tests/ui/unnecessary_literal_unwrap.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_literal_unwrap)] #![allow(unreachable_code)] #![allow( diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr index 7f603d6ef5826..eae74f5695086 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 - --> $DIR/unnecessary_literal_unwrap.rs:12:16 + --> $DIR/unnecessary_literal_unwrap.rs:11:16 | LL | let _val = Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + let _val = 1; | error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:13:16 + --> $DIR/unnecessary_literal_unwrap.rs:12:16 | LL | let _val = Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:15:5 + --> $DIR/unnecessary_literal_unwrap.rs:14:5 | LL | Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + 1; | error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:16:5 + --> $DIR/unnecessary_literal_unwrap.rs:15:5 | LL | Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,13 +48,13 @@ LL + 1; | error: used `unwrap()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:21:16 + --> $DIR/unnecessary_literal_unwrap.rs:20:16 | LL | let _val = None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()` error: used `expect()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:22:16 + --> $DIR/unnecessary_literal_unwrap.rs:21:16 | LL | let _val = None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,13 +65,13 @@ LL | let _val = panic!("this always happens"); | ~~~~~~~ ~ error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:23:24 + --> $DIR/unnecessary_literal_unwrap.rs:22:24 | LL | let _val: String = None.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()` error: used `unwrap_or()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:24:21 + --> $DIR/unnecessary_literal_unwrap.rs:23:21 | LL | let _val: u16 = None.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:25:21 + --> $DIR/unnecessary_literal_unwrap.rs:24:21 | LL | let _val: u16 = None.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +95,7 @@ LL + let _val: u16 = 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:26:21 + --> $DIR/unnecessary_literal_unwrap.rs:25:21 | LL | let _val: u16 = None.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -107,7 +107,7 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:27:21 + --> $DIR/unnecessary_literal_unwrap.rs:26:21 | LL | let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -119,13 +119,13 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:29:5 + --> $DIR/unnecessary_literal_unwrap.rs:28:5 | LL | None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()` error: used `expect()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:30:5 + --> $DIR/unnecessary_literal_unwrap.rs:29:5 | LL | None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,13 +136,13 @@ LL | panic!("this always happens"); | ~~~~~~~ ~ error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:31:5 + --> $DIR/unnecessary_literal_unwrap.rs:30:5 | LL | None::.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()` error: used `unwrap_or()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:32:5 + --> $DIR/unnecessary_literal_unwrap.rs:31:5 | LL | None::.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:33:5 + --> $DIR/unnecessary_literal_unwrap.rs:32:5 | LL | None::.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +166,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:34:5 + --> $DIR/unnecessary_literal_unwrap.rs:33:5 | LL | None::.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -178,7 +178,7 @@ LL + { 234 }; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:35:5 + --> $DIR/unnecessary_literal_unwrap.rs:34:5 | LL | None::.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -190,7 +190,7 @@ LL + { 234 }; | error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:39:16 + --> $DIR/unnecessary_literal_unwrap.rs:38:16 | LL | let _val = Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -202,7 +202,7 @@ LL + let _val = 1; | error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:40:16 + --> $DIR/unnecessary_literal_unwrap.rs:39:16 | LL | let _val = Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -214,7 +214,7 @@ LL + let _val = 1; | error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:41:16 + --> $DIR/unnecessary_literal_unwrap.rs:40:16 | LL | let _val = Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL | let _val = panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:42:16 + --> $DIR/unnecessary_literal_unwrap.rs:41:16 | LL | let _val = Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -236,7 +236,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:44:5 + --> $DIR/unnecessary_literal_unwrap.rs:43:5 | LL | Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -248,7 +248,7 @@ LL + 1; | error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:45:5 + --> $DIR/unnecessary_literal_unwrap.rs:44:5 | LL | Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -260,7 +260,7 @@ LL + 1; | error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:46:5 + --> $DIR/unnecessary_literal_unwrap.rs:45:5 | LL | Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:47:5 + --> $DIR/unnecessary_literal_unwrap.rs:46:5 | LL | Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -282,7 +282,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:51:16 + --> $DIR/unnecessary_literal_unwrap.rs:50:16 | LL | let _val = Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -294,7 +294,7 @@ LL + let _val = 1; | error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:52:16 + --> $DIR/unnecessary_literal_unwrap.rs:51:16 | LL | let _val = Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -306,7 +306,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:53:16 + --> $DIR/unnecessary_literal_unwrap.rs:52:16 | LL | let _val = Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -317,7 +317,7 @@ LL | let _val = panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:54:16 + --> $DIR/unnecessary_literal_unwrap.rs:53:16 | LL | let _val = Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -328,7 +328,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:56:5 + --> $DIR/unnecessary_literal_unwrap.rs:55:5 | LL | Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -340,7 +340,7 @@ LL + 1; | error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:57:5 + --> $DIR/unnecessary_literal_unwrap.rs:56:5 | LL | Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -352,7 +352,7 @@ LL + 1; | error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:58:5 + --> $DIR/unnecessary_literal_unwrap.rs:57:5 | LL | Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -363,7 +363,7 @@ LL | panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:59:5 + --> $DIR/unnecessary_literal_unwrap.rs:58:5 | LL | Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -374,7 +374,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:63:16 + --> $DIR/unnecessary_literal_unwrap.rs:62:16 | LL | let _val = Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -386,7 +386,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:64:16 + --> $DIR/unnecessary_literal_unwrap.rs:63:16 | LL | let _val = Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -398,7 +398,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:65:16 + --> $DIR/unnecessary_literal_unwrap.rs:64:16 | LL | let _val = Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -410,7 +410,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:67:5 + --> $DIR/unnecessary_literal_unwrap.rs:66:5 | LL | Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -422,7 +422,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:68:5 + --> $DIR/unnecessary_literal_unwrap.rs:67:5 | LL | Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -434,7 +434,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:69:5 + --> $DIR/unnecessary_literal_unwrap.rs:68:5 | LL | Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -446,7 +446,7 @@ LL + 1; | error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:73:16 + --> $DIR/unnecessary_literal_unwrap.rs:72:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -458,7 +458,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:74:16 + --> $DIR/unnecessary_literal_unwrap.rs:73:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -470,7 +470,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:75:16 + --> $DIR/unnecessary_literal_unwrap.rs:74:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -482,7 +482,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:77:5 + --> $DIR/unnecessary_literal_unwrap.rs:76:5 | LL | Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -494,7 +494,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:78:5 + --> $DIR/unnecessary_literal_unwrap.rs:77:5 | LL | Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -506,7 +506,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:79:5 + --> $DIR/unnecessary_literal_unwrap.rs:78:5 | LL | Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -518,7 +518,7 @@ LL + 1; | error: used `unwrap_unchecked()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:93:22 + --> $DIR/unnecessary_literal_unwrap.rs:92:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -530,7 +530,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:94:22 + --> $DIR/unnecessary_literal_unwrap.rs:93:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -542,7 +542,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe | error: used `unwrap_unchecked()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:95:22 + --> $DIR/unnecessary_literal_unwrap.rs:94:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -554,7 +554,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_unchecked()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:96:22 + --> $DIR/unnecessary_literal_unwrap.rs:95:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -566,7 +566,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:97:22 + --> $DIR/unnecessary_literal_unwrap.rs:96:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -578,7 +578,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; | error: used `unwrap_unchecked()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:98:22 + --> $DIR/unnecessary_literal_unwrap.rs:97:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -590,7 +590,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_err_unchecked()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:99:22 + --> $DIR/unnecessary_literal_unwrap.rs:98: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 41300aceb4153..2671ecf678124 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.rs +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs @@ -1,7 +1,7 @@ #![warn(clippy::unnecessary_literal_unwrap)] #![allow(unreachable_code)] #![allow(clippy::unnecessary_lazy_evaluations, clippy::let_unit_value)] - +//@no-rustfix fn unwrap_option_some() { let val = Some(1); let _val2 = val.unwrap(); diff --git a/tests/ui/unnecessary_operation.fixed b/tests/ui/unnecessary_operation.fixed index fbd2d34591fc0..d0c0298ef4cd4 100644 --- a/tests/ui/unnecessary_operation.fixed +++ b/tests/ui/unnecessary_operation.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( clippy::deref_addrof, dead_code, diff --git a/tests/ui/unnecessary_operation.rs b/tests/ui/unnecessary_operation.rs index b45298a6dc462..e8e3a2d5657de 100644 --- a/tests/ui/unnecessary_operation.rs +++ b/tests/ui/unnecessary_operation.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( clippy::deref_addrof, dead_code, diff --git a/tests/ui/unnecessary_operation.stderr b/tests/ui/unnecessary_operation.stderr index a1d0d93998a6c..d71aa60d4cc1e 100644 --- a/tests/ui/unnecessary_operation.stderr +++ b/tests/ui/unnecessary_operation.stderr @@ -1,5 +1,5 @@ error: unnecessary operation - --> $DIR/unnecessary_operation.rs:56:5 + --> $DIR/unnecessary_operation.rs:54:5 | LL | Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` @@ -7,103 +7,103 @@ LL | Tuple(get_number()); = note: `-D clippy::unnecessary-operation` implied by `-D warnings` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:57:5 + --> $DIR/unnecessary_operation.rs:55:5 | LL | Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:58:5 + --> $DIR/unnecessary_operation.rs:56:5 | LL | Struct { ..get_struct() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_struct();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:59:5 + --> $DIR/unnecessary_operation.rs:57:5 | LL | Enum::Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:60:5 + --> $DIR/unnecessary_operation.rs:58:5 | LL | Enum::Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:61:5 + --> $DIR/unnecessary_operation.rs:59:5 | LL | 5 + get_number(); | ^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:62:5 + --> $DIR/unnecessary_operation.rs:60:5 | LL | *&get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:63:5 + --> $DIR/unnecessary_operation.rs:61:5 | LL | &get_number(); | ^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:64:5 + --> $DIR/unnecessary_operation.rs:62:5 | LL | (5, 6, get_number()); | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;6;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:65:5 + --> $DIR/unnecessary_operation.rs:63:5 | LL | get_number()..; | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:66:5 + --> $DIR/unnecessary_operation.rs:64:5 | LL | ..get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:67:5 + --> $DIR/unnecessary_operation.rs:65:5 | LL | 5..get_number(); | ^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:68:5 + --> $DIR/unnecessary_operation.rs:66:5 | LL | [42, get_number()]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:69:5 + --> $DIR/unnecessary_operation.rs:67:5 | LL | [42, 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:70:5 + --> $DIR/unnecessary_operation.rs:68:5 | LL | (42, get_number()).1; | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:71:5 + --> $DIR/unnecessary_operation.rs:69:5 | LL | [get_number(); 55]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:72:5 + --> $DIR/unnecessary_operation.rs:70:5 | LL | [42; 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42; 55].len() > get_usize());` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:73:5 + --> $DIR/unnecessary_operation.rs:71:5 | LL | / { LL | | get_number() @@ -111,7 +111,7 @@ LL | | }; | |______^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:76:5 + --> $DIR/unnecessary_operation.rs:74:5 | LL | / FooString { LL | | s: String::from("blah"), diff --git a/tests/ui/unnecessary_owned_empty_strings.fixed b/tests/ui/unnecessary_owned_empty_strings.fixed index af12fd1d63d01..75cd63db8a1ac 100644 --- a/tests/ui/unnecessary_owned_empty_strings.fixed +++ b/tests/ui/unnecessary_owned_empty_strings.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unnecessary_owned_empty_strings)] fn ref_str_argument(_value: &str) {} diff --git a/tests/ui/unnecessary_owned_empty_strings.rs b/tests/ui/unnecessary_owned_empty_strings.rs index a460b21af8c29..2edc0bd86d383 100644 --- a/tests/ui/unnecessary_owned_empty_strings.rs +++ b/tests/ui/unnecessary_owned_empty_strings.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unnecessary_owned_empty_strings)] fn ref_str_argument(_value: &str) {} diff --git a/tests/ui/unnecessary_owned_empty_strings.stderr b/tests/ui/unnecessary_owned_empty_strings.stderr index 1eb198a8675ea..2cfed265adf88 100644 --- a/tests/ui/unnecessary_owned_empty_strings.stderr +++ b/tests/ui/unnecessary_owned_empty_strings.stderr @@ -1,5 +1,5 @@ error: usage of `&String::new()` for a function expecting a `&str` argument - --> $DIR/unnecessary_owned_empty_strings.rs:12:22 + --> $DIR/unnecessary_owned_empty_strings.rs:10:22 | LL | ref_str_argument(&String::new()); | ^^^^^^^^^^^^^^ help: try: `""` @@ -7,7 +7,7 @@ LL | ref_str_argument(&String::new()); = note: `-D clippy::unnecessary-owned-empty-strings` implied by `-D warnings` error: usage of `&String::from("")` for a function expecting a `&str` argument - --> $DIR/unnecessary_owned_empty_strings.rs:16:22 + --> $DIR/unnecessary_owned_empty_strings.rs:14:22 | LL | ref_str_argument(&String::from("")); | ^^^^^^^^^^^^^^^^^ help: try: `""` diff --git a/tests/ui/unnecessary_self_imports.fixed b/tests/ui/unnecessary_self_imports.fixed index 7fc978d3ef7e7..c265dcd2414fa 100644 --- a/tests/ui/unnecessary_self_imports.fixed +++ b/tests/ui/unnecessary_self_imports.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_self_imports)] #![allow(unused_imports, dead_code)] diff --git a/tests/ui/unnecessary_self_imports.rs b/tests/ui/unnecessary_self_imports.rs index 02424bc12b00e..c3fcf7c951a17 100644 --- a/tests/ui/unnecessary_self_imports.rs +++ b/tests/ui/unnecessary_self_imports.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_self_imports)] #![allow(unused_imports, dead_code)] diff --git a/tests/ui/unnecessary_self_imports.stderr b/tests/ui/unnecessary_self_imports.stderr index db805eb3680be..412674a85ec7a 100644 --- a/tests/ui/unnecessary_self_imports.stderr +++ b/tests/ui/unnecessary_self_imports.stderr @@ -1,5 +1,5 @@ error: import ending with `::{self}` - --> $DIR/unnecessary_self_imports.rs:6:1 + --> $DIR/unnecessary_self_imports.rs:5:1 | LL | use std::fs::{self as alias}; | ^^^^^^^^^-------------------- @@ -10,7 +10,7 @@ LL | use std::fs::{self as alias}; = note: `-D clippy::unnecessary-self-imports` implied by `-D warnings` error: import ending with `::{self}` - --> $DIR/unnecessary_self_imports.rs:8:1 + --> $DIR/unnecessary_self_imports.rs:7:1 | LL | use std::rc::{self}; | ^^^^^^^^^----------- diff --git a/tests/ui/unnecessary_sort_by.fixed b/tests/ui/unnecessary_sort_by.fixed index 19380ad00dcd9..6b667e00c9781 100644 --- a/tests/ui/unnecessary_sort_by.fixed +++ b/tests/ui/unnecessary_sort_by.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::stable_sort_primitive, clippy::useless_vec)] use std::cell::Ref; diff --git a/tests/ui/unnecessary_sort_by.rs b/tests/ui/unnecessary_sort_by.rs index cea1b65b52031..0ff20fb9ef289 100644 --- a/tests/ui/unnecessary_sort_by.rs +++ b/tests/ui/unnecessary_sort_by.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::stable_sort_primitive, clippy::useless_vec)] use std::cell::Ref; diff --git a/tests/ui/unnecessary_sort_by.stderr b/tests/ui/unnecessary_sort_by.stderr index 89da5e7ea8b9b..55d681487b66f 100644 --- a/tests/ui/unnecessary_sort_by.stderr +++ b/tests/ui/unnecessary_sort_by.stderr @@ -1,5 +1,5 @@ error: use Vec::sort here instead - --> $DIR/unnecessary_sort_by.rs:14:5 + --> $DIR/unnecessary_sort_by.rs:12:5 | LL | vec.sort_by(|a, b| a.cmp(b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort()` @@ -7,67 +7,67 @@ LL | vec.sort_by(|a, b| a.cmp(b)); = note: `-D clippy::unnecessary-sort-by` implied by `-D warnings` error: use Vec::sort here instead - --> $DIR/unnecessary_sort_by.rs:15:5 + --> $DIR/unnecessary_sort_by.rs:13:5 | LL | vec.sort_unstable_by(|a, b| a.cmp(b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable()` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:16:5 + --> $DIR/unnecessary_sort_by.rs:14:5 | LL | vec.sort_by(|a, b| (a + 5).abs().cmp(&(b + 5).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (a + 5).abs())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:17:5 + --> $DIR/unnecessary_sort_by.rs:15:5 | LL | vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| id(-a))` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:20:5 + --> $DIR/unnecessary_sort_by.rs:18:5 | LL | vec.sort_by(|a, b| (b + 5).abs().cmp(&(a + 5).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|b| std::cmp::Reverse((b + 5).abs()))` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:21:5 + --> $DIR/unnecessary_sort_by.rs:19:5 | LL | vec.sort_unstable_by(|a, b| id(-b).cmp(&id(-a))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|b| std::cmp::Reverse(id(-b)))` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:31:5 + --> $DIR/unnecessary_sort_by.rs:29:5 | LL | vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (***a).abs())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:32:5 + --> $DIR/unnecessary_sort_by.rs:30:5 | LL | vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| (***a).abs())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:91:9 + --> $DIR/unnecessary_sort_by.rs:89:9 | LL | args.sort_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|a| a.name())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:92:9 + --> $DIR/unnecessary_sort_by.rs:90:9 | LL | args.sort_unstable_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|a| a.name())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:94:9 + --> $DIR/unnecessary_sort_by.rs:92:9 | LL | args.sort_by(|a, b| b.name().cmp(&a.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|b| std::cmp::Reverse(b.name()))` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:95:9 + --> $DIR/unnecessary_sort_by.rs:93:9 | LL | args.sort_unstable_by(|a, b| b.name().cmp(&a.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|b| std::cmp::Reverse(b.name()))` diff --git a/tests/ui/unnecessary_struct_initialization.fixed b/tests/ui/unnecessary_struct_initialization.fixed index eae1271d1aa72..b5dedef5f4c87 100644 --- a/tests/ui/unnecessary_struct_initialization.fixed +++ b/tests/ui/unnecessary_struct_initialization.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::incorrect_clone_impl_on_copy_type, unused)] #![warn(clippy::unnecessary_struct_initialization)] diff --git a/tests/ui/unnecessary_struct_initialization.rs b/tests/ui/unnecessary_struct_initialization.rs index 4abd560f84bec..2222c3ddf3708 100644 --- a/tests/ui/unnecessary_struct_initialization.rs +++ b/tests/ui/unnecessary_struct_initialization.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::incorrect_clone_impl_on_copy_type, unused)] #![warn(clippy::unnecessary_struct_initialization)] diff --git a/tests/ui/unnecessary_struct_initialization.stderr b/tests/ui/unnecessary_struct_initialization.stderr index ca497057702f6..5311415d166d2 100644 --- a/tests/ui/unnecessary_struct_initialization.stderr +++ b/tests/ui/unnecessary_struct_initialization.stderr @@ -1,5 +1,5 @@ error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:34:9 + --> $DIR/unnecessary_struct_initialization.rs:32:9 | LL | Self { ..*self } | ^^^^^^^^^^^^^^^^ help: replace with: `*self` @@ -7,25 +7,25 @@ LL | Self { ..*self } = note: `-D clippy::unnecessary-struct-initialization` implied by `-D warnings` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:41:17 + --> $DIR/unnecessary_struct_initialization.rs:39:17 | LL | let mut b = S { ..a }; | ^^^^^^^^^ help: replace with: `a` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:44:18 + --> $DIR/unnecessary_struct_initialization.rs:42:18 | LL | let c = &mut S { ..b }; | ^^^^^^^^^ help: replace with: `b` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:52:14 + --> $DIR/unnecessary_struct_initialization.rs:50:14 | LL | let g = &S { ..f }; | ^^^^^^^^^ help: replace with: `f` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:55:18 + --> $DIR/unnecessary_struct_initialization.rs:53:18 | LL | let h = &mut S { | __________________^ @@ -34,7 +34,7 @@ LL | | }; | |_____^ help: replace with: `*Box::new(S { f: String::from("foo") })` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:74:18 + --> $DIR/unnecessary_struct_initialization.rs:72:18 | LL | let p = &mut T { | __________________^ diff --git a/tests/ui/unnecessary_to_owned.fixed b/tests/ui/unnecessary_to_owned.fixed index cb7562351e8e4..7b662ca92d2ae 100644 --- a/tests/ui/unnecessary_to_owned.fixed +++ b/tests/ui/unnecessary_to_owned.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::needless_borrow, clippy::ptr_arg)] #![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)] diff --git a/tests/ui/unnecessary_to_owned.rs b/tests/ui/unnecessary_to_owned.rs index f82ddb2d25df1..d79778a6a2ed4 100644 --- a/tests/ui/unnecessary_to_owned.rs +++ b/tests/ui/unnecessary_to_owned.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::needless_borrow, clippy::ptr_arg)] #![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)] diff --git a/tests/ui/unnecessary_to_owned.stderr b/tests/ui/unnecessary_to_owned.stderr index 4918fe3559860..b5d009ae1dd5d 100644 --- a/tests/ui/unnecessary_to_owned.stderr +++ b/tests/ui/unnecessary_to_owned.stderr @@ -1,66 +1,66 @@ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:150:64 + --> $DIR/unnecessary_to_owned.rs:148: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 - --> $DIR/unnecessary_to_owned.rs:150:20 + --> $DIR/unnecessary_to_owned.rs:148:20 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-clone` implied by `-D warnings` error: redundant clone - --> $DIR/unnecessary_to_owned.rs:151:40 + --> $DIR/unnecessary_to_owned.rs:149:40 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:151:21 + --> $DIR/unnecessary_to_owned.rs:149:21 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:152:48 + --> $DIR/unnecessary_to_owned.rs:150:48 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:152:19 + --> $DIR/unnecessary_to_owned.rs:150:19 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:153:35 + --> $DIR/unnecessary_to_owned.rs:151:35 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:153:18 + --> $DIR/unnecessary_to_owned.rs:151:18 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:154:39 + --> $DIR/unnecessary_to_owned.rs:152:39 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/unnecessary_to_owned.rs:154:20 + --> $DIR/unnecessary_to_owned.rs:152:20 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^^^^^^^^^ error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:59:36 + --> $DIR/unnecessary_to_owned.rs:57:36 | LL | require_c_str(&Cow::from(c_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this @@ -68,415 +68,415 @@ LL | require_c_str(&Cow::from(c_str).into_owned()); = note: `-D clippy::unnecessary-to-owned` implied by `-D warnings` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:60:19 + --> $DIR/unnecessary_to_owned.rs:58:19 | LL | require_c_str(&c_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_os_string` - --> $DIR/unnecessary_to_owned.rs:62:20 + --> $DIR/unnecessary_to_owned.rs:60:20 | LL | require_os_str(&os_str.to_os_string()); | ^^^^^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:63:38 + --> $DIR/unnecessary_to_owned.rs:61:38 | LL | require_os_str(&Cow::from(os_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:64:20 + --> $DIR/unnecessary_to_owned.rs:62:20 | LL | require_os_str(&os_str.to_owned()); | ^^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_path_buf` - --> $DIR/unnecessary_to_owned.rs:66:18 + --> $DIR/unnecessary_to_owned.rs:64:18 | LL | require_path(&path.to_path_buf()); | ^^^^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:67:34 + --> $DIR/unnecessary_to_owned.rs:65:34 | LL | require_path(&Cow::from(path).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:68:18 + --> $DIR/unnecessary_to_owned.rs:66:18 | LL | require_path(&path.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:70:17 + --> $DIR/unnecessary_to_owned.rs:68:17 | LL | require_str(&s.to_string()); | ^^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:71:30 + --> $DIR/unnecessary_to_owned.rs:69:30 | LL | require_str(&Cow::from(s).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:72:17 + --> $DIR/unnecessary_to_owned.rs:70:17 | LL | require_str(&s.to_owned()); | ^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:73:17 + --> $DIR/unnecessary_to_owned.rs:71:17 | LL | require_str(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref.as_ref()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:75:19 + --> $DIR/unnecessary_to_owned.rs:73:19 | LL | require_slice(&slice.to_vec()); | ^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:76:36 + --> $DIR/unnecessary_to_owned.rs:74:36 | LL | require_slice(&Cow::from(slice).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:77:19 + --> $DIR/unnecessary_to_owned.rs:75:19 | LL | require_slice(&array.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `array.as_ref()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:78:19 + --> $DIR/unnecessary_to_owned.rs:76:19 | LL | require_slice(&array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref.as_ref()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:79:19 + --> $DIR/unnecessary_to_owned.rs:77:19 | LL | require_slice(&slice.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:82:42 + --> $DIR/unnecessary_to_owned.rs:80:42 | LL | require_x(&Cow::::Owned(x.clone()).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:85:25 + --> $DIR/unnecessary_to_owned.rs:83:25 | LL | require_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:86:26 + --> $DIR/unnecessary_to_owned.rs:84:26 | LL | require_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:87:24 + --> $DIR/unnecessary_to_owned.rs:85:24 | LL | require_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:88:23 + --> $DIR/unnecessary_to_owned.rs:86:23 | LL | require_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:89:25 + --> $DIR/unnecessary_to_owned.rs:87:25 | LL | require_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:91:30 + --> $DIR/unnecessary_to_owned.rs:89:30 | LL | require_impl_deref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:92:31 + --> $DIR/unnecessary_to_owned.rs:90:31 | LL | require_impl_deref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:93:29 + --> $DIR/unnecessary_to_owned.rs:91:29 | LL | require_impl_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:94:28 + --> $DIR/unnecessary_to_owned.rs:92:28 | LL | require_impl_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:95:30 + --> $DIR/unnecessary_to_owned.rs:93:30 | LL | require_impl_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:97:29 + --> $DIR/unnecessary_to_owned.rs:95:29 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:97:43 + --> $DIR/unnecessary_to_owned.rs:95:43 | LL | require_deref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:98:29 + --> $DIR/unnecessary_to_owned.rs:96:29 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:98:47 + --> $DIR/unnecessary_to_owned.rs:96:47 | LL | require_deref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:100:26 + --> $DIR/unnecessary_to_owned.rs:98:26 | LL | require_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:101:27 + --> $DIR/unnecessary_to_owned.rs:99:27 | LL | require_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:102:25 + --> $DIR/unnecessary_to_owned.rs:100:25 | LL | require_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:103:24 + --> $DIR/unnecessary_to_owned.rs:101:24 | LL | require_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:104:24 + --> $DIR/unnecessary_to_owned.rs:102:24 | LL | require_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:105:26 + --> $DIR/unnecessary_to_owned.rs:103:26 | LL | require_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:106:26 + --> $DIR/unnecessary_to_owned.rs:104:26 | LL | require_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:107:26 + --> $DIR/unnecessary_to_owned.rs:105:26 | LL | require_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:109:31 + --> $DIR/unnecessary_to_owned.rs:107:31 | LL | require_impl_as_ref_c_str(c_str.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `c_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:110:32 + --> $DIR/unnecessary_to_owned.rs:108:32 | LL | require_impl_as_ref_os_str(os_str.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `os_str` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:111:30 + --> $DIR/unnecessary_to_owned.rs:109:30 | LL | require_impl_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:112:29 + --> $DIR/unnecessary_to_owned.rs:110:29 | LL | require_impl_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:113:29 + --> $DIR/unnecessary_to_owned.rs:111:29 | LL | require_impl_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:114:31 + --> $DIR/unnecessary_to_owned.rs:112:31 | LL | require_impl_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:115:31 + --> $DIR/unnecessary_to_owned.rs:113:31 | LL | require_impl_as_ref_slice(array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:116:31 + --> $DIR/unnecessary_to_owned.rs:114:31 | LL | require_impl_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:118:30 + --> $DIR/unnecessary_to_owned.rs:116:30 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:118:44 + --> $DIR/unnecessary_to_owned.rs:116:44 | LL | require_as_ref_str_slice(s.to_owned(), array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:119:30 + --> $DIR/unnecessary_to_owned.rs:117:30 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:119:44 + --> $DIR/unnecessary_to_owned.rs:117:44 | LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:120:30 + --> $DIR/unnecessary_to_owned.rs:118:30 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:120:44 + --> $DIR/unnecessary_to_owned.rs:118:44 | LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:121:30 + --> $DIR/unnecessary_to_owned.rs:119:30 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:121:48 + --> $DIR/unnecessary_to_owned.rs:119:48 | LL | require_as_ref_slice_str(array.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:122:30 + --> $DIR/unnecessary_to_owned.rs:120:30 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:122:52 + --> $DIR/unnecessary_to_owned.rs:120:52 | LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:123:30 + --> $DIR/unnecessary_to_owned.rs:121:30 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:123:48 + --> $DIR/unnecessary_to_owned.rs:121:48 | LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:125:20 + --> $DIR/unnecessary_to_owned.rs:123:20 | LL | let _ = x.join(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:127:13 + --> $DIR/unnecessary_to_owned.rs:125:13 | LL | let _ = slice.to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:128:13 + --> $DIR/unnecessary_to_owned.rs:126:13 | LL | let _ = slice.to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:129:13 + --> $DIR/unnecessary_to_owned.rs:127:13 | LL | let _ = [std::path::PathBuf::new()][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:130:13 + --> $DIR/unnecessary_to_owned.rs:128:13 | LL | let _ = [std::path::PathBuf::new()][..].to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:132:13 + --> $DIR/unnecessary_to_owned.rs:130:13 | LL | let _ = IntoIterator::into_iter(slice.to_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:133:13 + --> $DIR/unnecessary_to_owned.rs:131:13 | LL | let _ = IntoIterator::into_iter(slice.to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:134:13 + --> $DIR/unnecessary_to_owned.rs:132:13 | LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:135:13 + --> $DIR/unnecessary_to_owned.rs:133:13 | LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:197:14 + --> $DIR/unnecessary_to_owned.rs:195:14 | LL | for t in file_types.to_vec() { | ^^^^^^^^^^^^^^^^^^^ @@ -492,25 +492,25 @@ LL + let path = match get_file_path(t) { | error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:220:14 + --> $DIR/unnecessary_to_owned.rs:218:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:225:14 + --> $DIR/unnecessary_to_owned.rs:223:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:272:24 + --> $DIR/unnecessary_to_owned.rs:270:24 | LL | Box::new(build(y.to_string())) | ^^^^^^^^^^^^^ help: use: `y` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:380:12 + --> $DIR/unnecessary_to_owned.rs:378:12 | LL | id("abc".to_string()) | ^^^^^^^^^^^^^^^^^ help: use: `"abc"` diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs index 63648ef5826f6..fa92143e980dd 100644 --- a/tests/ui/unnecessary_wraps.rs +++ b/tests/ui/unnecessary_wraps.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::unnecessary_wraps)] #![allow(clippy::no_effect)] #![allow(clippy::needless_return)] diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index a6a0b22cf689f..d29235165359d 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` - --> $DIR/unnecessary_wraps.rs:8:1 + --> $DIR/unnecessary_wraps.rs:9:1 | LL | / fn func1(a: bool, b: bool) -> Option { LL | | if a && b { @@ -27,7 +27,7 @@ LL ~ return 1337; | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:21:1 + --> $DIR/unnecessary_wraps.rs:22:1 | LL | / fn func2(a: bool, b: bool) -> Option { LL | | if a && b { @@ -49,7 +49,7 @@ LL ~ if a { 20 } else { 30 } | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:39:1 + --> $DIR/unnecessary_wraps.rs:40:1 | LL | / fn func5() -> Option { LL | | Some(1) @@ -66,7 +66,7 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Result` - --> $DIR/unnecessary_wraps.rs:49:1 + --> $DIR/unnecessary_wraps.rs:50:1 | LL | / fn func7() -> Result { LL | | Ok(1) @@ -83,7 +83,7 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:77:5 + --> $DIR/unnecessary_wraps.rs:78:5 | LL | / fn func12() -> Option { LL | | Some(1) @@ -100,7 +100,7 @@ LL | 1 | error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:104:1 + --> $DIR/unnecessary_wraps.rs:105:1 | LL | / fn issue_6640_1(a: bool, b: bool) -> Option<()> { LL | | if a && b { @@ -127,7 +127,7 @@ LL ~ return ; | error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:117:1 + --> $DIR/unnecessary_wraps.rs:118:1 | LL | / fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { LL | | if a && b { diff --git a/tests/ui/unneeded_wildcard_pattern.fixed b/tests/ui/unneeded_wildcard_pattern.fixed index 2eeba509e8338..b37d0ddb88d77 100644 --- a/tests/ui/unneeded_wildcard_pattern.fixed +++ b/tests/ui/unneeded_wildcard_pattern.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(stmt_expr_attributes)] #![deny(clippy::unneeded_wildcard_pattern)] diff --git a/tests/ui/unneeded_wildcard_pattern.rs b/tests/ui/unneeded_wildcard_pattern.rs index 5416cfaa5425f..ee3f9bae5cc58 100644 --- a/tests/ui/unneeded_wildcard_pattern.rs +++ b/tests/ui/unneeded_wildcard_pattern.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macros.rs:proc-macro #![feature(stmt_expr_attributes)] #![deny(clippy::unneeded_wildcard_pattern)] diff --git a/tests/ui/unneeded_wildcard_pattern.stderr b/tests/ui/unneeded_wildcard_pattern.stderr index ffbdc049506e0..f2880a8e68d38 100644 --- a/tests/ui/unneeded_wildcard_pattern.stderr +++ b/tests/ui/unneeded_wildcard_pattern.stderr @@ -1,89 +1,89 @@ error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:13:18 + --> $DIR/unneeded_wildcard_pattern.rs:12:18 | LL | if let (0, .., _) = t {}; | ^^^ help: remove it | note: the lint level is defined here - --> $DIR/unneeded_wildcard_pattern.rs:4:9 + --> $DIR/unneeded_wildcard_pattern.rs:3:9 | LL | #![deny(clippy::unneeded_wildcard_pattern)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:14:16 + --> $DIR/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 - --> $DIR/unneeded_wildcard_pattern.rs:15:13 + --> $DIR/unneeded_wildcard_pattern.rs:14:13 | LL | if let (_, .., 0) = t {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:16:15 + --> $DIR/unneeded_wildcard_pattern.rs:15:15 | LL | if let (.., _, 0) = t {}; | ^^^ help: remove it error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:17:16 + --> $DIR/unneeded_wildcard_pattern.rs:16:16 | LL | if let (0, _, _, ..) = t {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:18:18 + --> $DIR/unneeded_wildcard_pattern.rs:17:18 | LL | if let (0, .., _, _) = t {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:27:22 + --> $DIR/unneeded_wildcard_pattern.rs:26:22 | LL | if let (0, .., _, _,) = t {}; | ^^^^^^ help: remove them error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:34:19 + --> $DIR/unneeded_wildcard_pattern.rs:33:19 | LL | if let S(0, .., _) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:35:17 + --> $DIR/unneeded_wildcard_pattern.rs:34:17 | LL | if let S(0, _, ..) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:36:14 + --> $DIR/unneeded_wildcard_pattern.rs:35:14 | LL | if let S(_, .., 0) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:37:16 + --> $DIR/unneeded_wildcard_pattern.rs:36:16 | LL | if let S(.., _, 0) = s {}; | ^^^ help: remove it error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:38:17 + --> $DIR/unneeded_wildcard_pattern.rs:37:17 | LL | if let S(0, _, _, ..) = s {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:39:19 + --> $DIR/unneeded_wildcard_pattern.rs:38:19 | LL | if let S(0, .., _, _) = s {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:48:23 + --> $DIR/unneeded_wildcard_pattern.rs:47:23 | LL | if let S(0, .., _, _,) = s {}; | ^^^^^^ help: remove them diff --git a/tests/ui/unnested_or_patterns.fixed b/tests/ui/unnested_or_patterns.fixed index 738045595c0bc..53ec556d1008b 100644 --- a/tests/ui/unnested_or_patterns.fixed +++ b/tests/ui/unnested_or_patterns.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow( diff --git a/tests/ui/unnested_or_patterns.rs b/tests/ui/unnested_or_patterns.rs index 9e0e7b5def980..e5e378e922af2 100644 --- a/tests/ui/unnested_or_patterns.rs +++ b/tests/ui/unnested_or_patterns.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow( diff --git a/tests/ui/unnested_or_patterns.stderr b/tests/ui/unnested_or_patterns.stderr index b997e4ce85fb9..9e4f0d45d80a5 100644 --- a/tests/ui/unnested_or_patterns.stderr +++ b/tests/ui/unnested_or_patterns.stderr @@ -1,5 +1,5 @@ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:18:12 + --> $DIR/unnested_or_patterns.rs:16:12 | LL | if let box 0 | box 2 = Box::new(0) {} | ^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | if let box (0 | 2) = Box::new(0) {} | ~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:19:12 + --> $DIR/unnested_or_patterns.rs:17:12 | LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:21:12 + --> $DIR/unnested_or_patterns.rs:19:12 | LL | if let Some(1) | C0 | Some(2) = None {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | if let Some(1 | 2) | C0 = None {} | ~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:22:12 + --> $DIR/unnested_or_patterns.rs:20:12 | LL | if let &mut 0 | &mut 2 = &mut 0 {} | ^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | if let &mut (0 | 2) = &mut 0 {} | ~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:23:12 + --> $DIR/unnested_or_patterns.rs:21:12 | LL | if let x @ 0 | x @ 2 = 0 {} | ^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | if let x @ (0 | 2) = 0 {} | ~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:24:12 + --> $DIR/unnested_or_patterns.rs:22:12 | LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | if let (0, 1 | 2 | 3) = (0, 0) {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:25:12 + --> $DIR/unnested_or_patterns.rs:23:12 | LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | if let (1 | 2 | 3, 0) = (0, 0) {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:26:12 + --> $DIR/unnested_or_patterns.rs:24:12 | LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {} | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:27:12 + --> $DIR/unnested_or_patterns.rs:25:12 | LL | if let [0] | [1] = [0] {} | ^^^^^^^^^ @@ -99,7 +99,7 @@ LL | if let [0 | 1] = [0] {} | ~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:28:12 + --> $DIR/unnested_or_patterns.rs:26:12 | LL | if let [x, 0] | [x, 1] = [0, 1] {} | ^^^^^^^^^^^^^^^ @@ -110,7 +110,7 @@ LL | if let [x, 0 | 1] = [0, 1] {} | ~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:29:12 + --> $DIR/unnested_or_patterns.rs:27:12 | LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | if let [x, 0 | 1 | 2] = [0, 1] {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:30:12 + --> $DIR/unnested_or_patterns.rs:28:12 | LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {} | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:32:12 + --> $DIR/unnested_or_patterns.rs:30:12 | LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^ @@ -143,7 +143,7 @@ LL | if let TS(0 | 1, x) = TS(0, 0) {} | ~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:33:12 + --> $DIR/unnested_or_patterns.rs:31:12 | LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {} | ~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:34:12 + --> $DIR/unnested_or_patterns.rs:32:12 | LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +165,7 @@ LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} | ~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:39:12 + --> $DIR/unnested_or_patterns.rs:37:12 | LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -176,7 +176,7 @@ LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {} | ~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:50:12 + --> $DIR/unnested_or_patterns.rs:48:12 | LL | if let [1] | [53] = [0] {} | ^^^^^^^^^^ diff --git a/tests/ui/unnested_or_patterns2.fixed b/tests/ui/unnested_or_patterns2.fixed index 11dc34378758f..b2a4e83dadc33 100644 --- a/tests/ui/unnested_or_patterns2.fixed +++ b/tests/ui/unnested_or_patterns2.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow( diff --git a/tests/ui/unnested_or_patterns2.rs b/tests/ui/unnested_or_patterns2.rs index b255608274130..58435f8990d22 100644 --- a/tests/ui/unnested_or_patterns2.rs +++ b/tests/ui/unnested_or_patterns2.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow( diff --git a/tests/ui/unnested_or_patterns2.stderr b/tests/ui/unnested_or_patterns2.stderr index 76e890b3a2e3e..afb3100a552b2 100644 --- a/tests/ui/unnested_or_patterns2.stderr +++ b/tests/ui/unnested_or_patterns2.stderr @@ -1,5 +1,5 @@ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:14:12 + --> $DIR/unnested_or_patterns2.rs:12:12 | LL | if let Some(Some(0)) | Some(Some(1)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | if let Some(Some(0 | 1)) = None {} | ~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:15:12 + --> $DIR/unnested_or_patterns2.rs:13:12 | LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {} | ~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:16:12 + --> $DIR/unnested_or_patterns2.rs:14:12 | LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:17:12 + --> $DIR/unnested_or_patterns2.rs:15:12 | LL | if let Some(Some(0) | Some(1 | 2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {} | ~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:18:12 + --> $DIR/unnested_or_patterns2.rs:16:12 | LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | if let ((0 | 1 | 2,),) = ((0,),) {} | ~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:19:12 + --> $DIR/unnested_or_patterns2.rs:17:12 | LL | if let 0 | (1 | 2) = 0 {} | ^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | if let 0 | 1 | 2 = 0 {} | ~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:20:12 + --> $DIR/unnested_or_patterns2.rs:18:12 | LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:21:12 + --> $DIR/unnested_or_patterns2.rs:19:12 | LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unreadable_literal.fixed b/tests/ui/unreadable_literal.fixed index f5e87648a2319..6d8c719ee072c 100644 --- a/tests/ui/unreadable_literal.fixed +++ b/tests/ui/unreadable_literal.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unreadable_literal)] #![allow(unused_tuple_struct_fields)] diff --git a/tests/ui/unreadable_literal.rs b/tests/ui/unreadable_literal.rs index 426bdf7d7328b..42ca773c3516e 100644 --- a/tests/ui/unreadable_literal.rs +++ b/tests/ui/unreadable_literal.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unreadable_literal)] #![allow(unused_tuple_struct_fields)] diff --git a/tests/ui/unreadable_literal.stderr b/tests/ui/unreadable_literal.stderr index 450121b1c5a92..b75aa75a336d2 100644 --- a/tests/ui/unreadable_literal.stderr +++ b/tests/ui/unreadable_literal.stderr @@ -1,5 +1,5 @@ error: long literal lacking separators - --> $DIR/unreadable_literal.rs:34:17 + --> $DIR/unreadable_literal.rs:32:17 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` @@ -7,55 +7,55 @@ LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); = note: `-D clippy::unreadable-literal` implied by `-D warnings` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:34:31 + --> $DIR/unreadable_literal.rs:32:31 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^^^^^ help: consider: `0x1234_5678_usize` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:34:49 + --> $DIR/unreadable_literal.rs:32:49 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^ help: consider: `123_456_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:34:61 + --> $DIR/unreadable_literal.rs:32:61 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `1.234_567_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:36:20 + --> $DIR/unreadable_literal.rs:34:20 | LL | let _bad_sci = 1.123456e1; | ^^^^^^^^^^ help: consider: `1.123_456e1` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:38:18 + --> $DIR/unreadable_literal.rs:36:18 | LL | let _fail1 = 0xabcdef; | ^^^^^^^^ help: consider: `0x00ab_cdef` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:39:23 + --> $DIR/unreadable_literal.rs:37:23 | LL | let _fail2: u32 = 0xBAFEBAFE; | ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:40:18 + --> $DIR/unreadable_literal.rs:38:18 | LL | let _fail3 = 0xabcdeff; | ^^^^^^^^^ help: consider: `0x0abc_deff` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:41:24 + --> $DIR/unreadable_literal.rs:39:24 | LL | let _fail4: i128 = 0xabcabcabcabcabcabc; | ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:42:18 + --> $DIR/unreadable_literal.rs:40:18 | LL | let _fail5 = 1.100300400; | ^^^^^^^^^^^ help: consider: `1.100_300_400` diff --git a/tests/ui/unseparated_prefix_literals.fixed b/tests/ui/unseparated_prefix_literals.fixed index 1251208726703..2f275c62bef3c 100644 --- a/tests/ui/unseparated_prefix_literals.fixed +++ b/tests/ui/unseparated_prefix_literals.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macro_derive.rs:proc-macro #![warn(clippy::unseparated_literal_suffix)] diff --git a/tests/ui/unseparated_prefix_literals.rs b/tests/ui/unseparated_prefix_literals.rs index 0a3ffc4784b2d..f55160a1fc078 100644 --- a/tests/ui/unseparated_prefix_literals.rs +++ b/tests/ui/unseparated_prefix_literals.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macro_derive.rs:proc-macro #![warn(clippy::unseparated_literal_suffix)] diff --git a/tests/ui/unseparated_prefix_literals.stderr b/tests/ui/unseparated_prefix_literals.stderr index ab2f75e0c56de..a0c0be7a9d154 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 - --> $DIR/unseparated_prefix_literals.rs:24:18 + --> $DIR/unseparated_prefix_literals.rs:23:18 | LL | let _fail1 = 1234i32; | ^^^^^^^ help: add an underscore: `1234_i32` @@ -7,43 +7,43 @@ LL | let _fail1 = 1234i32; = note: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:25:18 + --> $DIR/unseparated_prefix_literals.rs:24:18 | LL | let _fail2 = 1234u32; | ^^^^^^^ help: add an underscore: `1234_u32` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:26:18 + --> $DIR/unseparated_prefix_literals.rs:25:18 | LL | let _fail3 = 1234isize; | ^^^^^^^^^ help: add an underscore: `1234_isize` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:27:18 + --> $DIR/unseparated_prefix_literals.rs:26:18 | LL | let _fail4 = 1234usize; | ^^^^^^^^^ help: add an underscore: `1234_usize` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:28:18 + --> $DIR/unseparated_prefix_literals.rs:27:18 | LL | let _fail5 = 0x123isize; | ^^^^^^^^^^ help: add an underscore: `0x123_isize` error: float type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:32:19 + --> $DIR/unseparated_prefix_literals.rs:31:19 | LL | let _failf1 = 1.5f32; | ^^^^^^ help: add an underscore: `1.5_f32` error: float type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:33:19 + --> $DIR/unseparated_prefix_literals.rs:32:19 | LL | let _failf2 = 1f32; | ^^^^ help: add an underscore: `1_f32` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:16:9 + --> $DIR/unseparated_prefix_literals.rs:15:9 | LL | 42usize | ^^^^^^^ help: add an underscore: `42_usize` @@ -54,7 +54,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 - --> $DIR/unseparated_prefix_literals.rs:41:16 + --> $DIR/unseparated_prefix_literals.rs:40:16 | LL | assert_eq!(4897u32, 32223); | ^^^^^^^ help: add an underscore: `4897_u32` diff --git a/tests/ui/unused_format_specs_unfixable.rs b/tests/ui/unused_format_specs_unfixable.rs index 78601a3483d34..c10cff1b55e6a 100644 --- a/tests/ui/unused_format_specs_unfixable.rs +++ b/tests/ui/unused_format_specs_unfixable.rs @@ -1,6 +1,6 @@ #![warn(clippy::unused_format_specs)] #![allow(unused)] - +//@no-rustfix macro_rules! format_args_from_macro { () => { format_args!("from macro") diff --git a/tests/ui/unused_rounding.fixed b/tests/ui/unused_rounding.fixed index f02b55502a060..02f970f42a420 100644 --- a/tests/ui/unused_rounding.fixed +++ b/tests/ui/unused_rounding.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unused_rounding)] fn main() { diff --git a/tests/ui/unused_rounding.rs b/tests/ui/unused_rounding.rs index c7bd4906d0b73..fd14c466f120a 100644 --- a/tests/ui/unused_rounding.rs +++ b/tests/ui/unused_rounding.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unused_rounding)] fn main() { diff --git a/tests/ui/unused_rounding.stderr b/tests/ui/unused_rounding.stderr index b867996fe5763..163f78982eef0 100644 --- a/tests/ui/unused_rounding.stderr +++ b/tests/ui/unused_rounding.stderr @@ -1,5 +1,5 @@ error: used the `ceil` method with a whole number float - --> $DIR/unused_rounding.rs:5:13 + --> $DIR/unused_rounding.rs:4:13 | LL | let _ = 1f32.ceil(); | ^^^^^^^^^^^ help: remove the `ceil` method call: `1f32` @@ -7,25 +7,25 @@ LL | let _ = 1f32.ceil(); = note: `-D clippy::unused-rounding` implied by `-D warnings` error: used the `floor` method with a whole number float - --> $DIR/unused_rounding.rs:6:13 + --> $DIR/unused_rounding.rs:5:13 | LL | let _ = 1.0f64.floor(); | ^^^^^^^^^^^^^^ help: remove the `floor` method call: `1.0f64` error: used the `round` method with a whole number float - --> $DIR/unused_rounding.rs:7:13 + --> $DIR/unused_rounding.rs:6:13 | LL | let _ = 1.00f32.round(); | ^^^^^^^^^^^^^^^ help: remove the `round` method call: `1.00f32` error: used the `round` method with a whole number float - --> $DIR/unused_rounding.rs:13:13 + --> $DIR/unused_rounding.rs:12:13 | LL | let _ = 3.0_f32.round(); | ^^^^^^^^^^^^^^^ help: remove the `round` method call: `3.0_f32` error: used the `round` method with a whole number float - --> $DIR/unused_rounding.rs:15:13 + --> $DIR/unused_rounding.rs:14:13 | LL | let _ = 3_3.0_0_f32.round(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `round` method call: `3_3.0_0_f32` diff --git a/tests/ui/unused_unit.fixed b/tests/ui/unused_unit.fixed index 7b8f7847dbf64..16da9a25b2aa8 100644 --- a/tests/ui/unused_unit.fixed +++ b/tests/ui/unused_unit.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + // The output for humans should just highlight the whole span without showing // the suggested replacement, but we also want to test that suggested diff --git a/tests/ui/unused_unit.rs b/tests/ui/unused_unit.rs index fdde1ecadf0bb..e374031436d5f 100644 --- a/tests/ui/unused_unit.rs +++ b/tests/ui/unused_unit.rs @@ -1,4 +1,4 @@ -//@run-rustfix + // The output for humans should just highlight the whole span without showing // the suggested replacement, but we also want to test that suggested diff --git a/tests/ui/unwrap_or.fixed b/tests/ui/unwrap_or.fixed new file mode 100644 index 0000000000000..cc0a4fa05beb7 --- /dev/null +++ b/tests/ui/unwrap_or.fixed @@ -0,0 +1,10 @@ +#![warn(clippy::all, clippy::or_fun_call)] +#![allow(clippy::unnecessary_literal_unwrap)] + +fn main() { + let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); +} + +fn new_lines() { + let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); +} diff --git a/tests/ui/unwrap_or_else_default.fixed b/tests/ui/unwrap_or_else_default.fixed index acdb96942ba1a..73d9990795860 100644 --- a/tests/ui/unwrap_or_else_default.fixed +++ b/tests/ui/unwrap_or_else_default.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unwrap_or_default)] #![allow(dead_code)] #![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui/unwrap_or_else_default.rs b/tests/ui/unwrap_or_else_default.rs index 55ccd00e1a2aa..afacedf17c63c 100644 --- a/tests/ui/unwrap_or_else_default.rs +++ b/tests/ui/unwrap_or_else_default.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unwrap_or_default)] #![allow(dead_code)] #![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] diff --git a/tests/ui/unwrap_or_else_default.stderr b/tests/ui/unwrap_or_else_default.stderr index af662c6def7e3..40023cf3b668d 100644 --- a/tests/ui/unwrap_or_else_default.stderr +++ b/tests/ui/unwrap_or_else_default.stderr @@ -1,5 +1,5 @@ error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:48:14 + --> $DIR/unwrap_or_else_default.rs:46:14 | LL | with_new.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` @@ -7,91 +7,91 @@ LL | with_new.unwrap_or_else(Vec::new); = note: `-D clippy::unwrap-or-default` implied by `-D warnings` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:62:23 + --> $DIR/unwrap_or_else_default.rs:60:23 | LL | with_real_default.unwrap_or_else(::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:65:24 + --> $DIR/unwrap_or_else_default.rs:63:24 | LL | with_default_trait.unwrap_or_else(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:68:23 + --> $DIR/unwrap_or_else_default.rs:66:23 | LL | with_default_type.unwrap_or_else(u64::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:71:23 + --> $DIR/unwrap_or_else_default.rs:69:23 | LL | with_default_type.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:74:18 + --> $DIR/unwrap_or_else_default.rs:72:18 | LL | empty_string.unwrap_or_else(|| "".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:78:12 + --> $DIR/unwrap_or_else_default.rs:76:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:81:12 + --> $DIR/unwrap_or_else_default.rs:79:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:84:12 + --> $DIR/unwrap_or_else_default.rs:82:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:87:12 + --> $DIR/unwrap_or_else_default.rs:85:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:90:12 + --> $DIR/unwrap_or_else_default.rs:88:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:93:12 + --> $DIR/unwrap_or_else_default.rs:91:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:96:12 + --> $DIR/unwrap_or_else_default.rs:94:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:99:12 + --> $DIR/unwrap_or_else_default.rs:97:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:115:12 + --> $DIR/unwrap_or_else_default.rs:113:12 | LL | option.unwrap_or_else(Vec::new).push(1); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `or_insert_with` to construct default value - --> $DIR/unwrap_or_else_default.rs:132:32 + --> $DIR/unwrap_or_else_default.rs:130:32 | LL | let _ = inner_map.entry(0).or_insert_with(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` diff --git a/tests/ui/upper_case_acronyms.fixed b/tests/ui/upper_case_acronyms.fixed new file mode 100644 index 0000000000000..f416e7f25ba78 --- /dev/null +++ b/tests/ui/upper_case_acronyms.fixed @@ -0,0 +1,50 @@ +#![warn(clippy::upper_case_acronyms)] + +struct HTTPResponse; // not linted by default, but with cfg option + +struct CString; // not linted + +enum Flags { + NS, // not linted + Cwr, + Ece, + Urg, + Ack, + Psh, + Rst, + Syn, + Fin, +} + +// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of +// `GccLlvmSomething` +struct GCCLLVMSomething; + +// public items must not be linted +pub struct NOWARNINGHERE; +pub struct ALSONoWarningHERE; + +// enum variants should not be linted if the num is pub +pub enum ParseError { + YDB(u8), + Utf8(std::string::FromUtf8Error), + Parse(T, String), +} + +// private, do lint here +enum ParseErrorPrivate { + Wasd(u8), + Utf8(std::string::FromUtf8Error), + Parse(T, String), +} + +// do lint here +struct Json; + +// do lint here +enum Yaml { + Num(u32), + Str(String), +} + +fn main() {} diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index 4179f21c51002..6427f955895aa 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macro_derive.rs:proc-macro #![warn(clippy::use_self)] diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 01a36def9e97f..ad39256f139f9 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macro_derive.rs:proc-macro #![warn(clippy::use_self)] diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index 48364c40c3b26..0e6ae5d451ba2 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -1,5 +1,5 @@ error: unnecessary structure name repetition - --> $DIR/use_self.rs:22:21 + --> $DIR/use_self.rs:21:21 | LL | fn new() -> Foo { | ^^^ help: use the applicable keyword: `Self` @@ -7,247 +7,247 @@ LL | fn new() -> Foo { = note: `-D clippy::use-self` implied by `-D warnings` error: unnecessary structure name repetition - --> $DIR/use_self.rs:23:13 + --> $DIR/use_self.rs:22:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:25:22 + --> $DIR/use_self.rs:24:22 | LL | fn test() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:26:13 + --> $DIR/use_self.rs:25:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:31:25 + --> $DIR/use_self.rs:30:25 | LL | fn default() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:32:13 + --> $DIR/use_self.rs:31:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:97:24 + --> $DIR/use_self.rs:96:24 | LL | fn bad(foos: &[Foo]) -> impl Iterator { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:97:55 + --> $DIR/use_self.rs:96:55 | LL | fn bad(foos: &[Foo]) -> impl Iterator { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:112:13 + --> $DIR/use_self.rs:111:13 | LL | TS(0) | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:147:29 + --> $DIR/use_self.rs:146:29 | LL | fn bar() -> Bar { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:148:21 + --> $DIR/use_self.rs:147:21 | LL | Bar { foo: Foo {} } | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:159:21 + --> $DIR/use_self.rs:158:21 | LL | fn baz() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:160:13 + --> $DIR/use_self.rs:159:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:177:21 + --> $DIR/use_self.rs:176:21 | LL | let _ = Enum::B(42); | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:178:21 + --> $DIR/use_self.rs:177:21 | LL | let _ = Enum::C { field: true }; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:179:21 + --> $DIR/use_self.rs:178:21 | LL | let _ = Enum::A; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:221:13 + --> $DIR/use_self.rs:220:13 | LL | nested::A::fun_1(); | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:222:13 + --> $DIR/use_self.rs:221:13 | LL | nested::A::A; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:224:13 + --> $DIR/use_self.rs:223:13 | LL | nested::A {}; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:243:13 + --> $DIR/use_self.rs:242:13 | LL | TestStruct::from_something() | ^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:257:25 + --> $DIR/use_self.rs:256:25 | LL | async fn g() -> S { | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:258:13 + --> $DIR/use_self.rs:257:13 | LL | S {} | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:262:16 + --> $DIR/use_self.rs:261:16 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:262:22 + --> $DIR/use_self.rs:261:22 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:285:29 + --> $DIR/use_self.rs:284:29 | LL | fn foo(value: T) -> Foo { | ^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:286:13 + --> $DIR/use_self.rs:285:13 | LL | Foo:: { value } | ^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:458:13 + --> $DIR/use_self.rs:457:13 | LL | A::new::(submod::B {}) | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:495:13 + --> $DIR/use_self.rs:494:13 | LL | S2::new() | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:532:17 + --> $DIR/use_self.rs:531:17 | LL | Foo::Bar => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:533:17 + --> $DIR/use_self.rs:532:17 | LL | Foo::Baz => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:539:20 + --> $DIR/use_self.rs:538:20 | LL | if let Foo::Bar = self { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:563:17 + --> $DIR/use_self.rs:562:17 | LL | Something::Num(n) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:564:17 + --> $DIR/use_self.rs:563:17 | LL | Something::TupleNums(n, _m) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:565:17 + --> $DIR/use_self.rs:564:17 | LL | Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:571:17 + --> $DIR/use_self.rs:570:17 | LL | crate::issue8845::Something::Num(n) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:572:17 + --> $DIR/use_self.rs:571:17 | LL | crate::issue8845::Something::TupleNums(n, _m) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:573:17 + --> $DIR/use_self.rs:572:17 | LL | crate::issue8845::Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:589:17 + --> $DIR/use_self.rs:588:17 | LL | let Foo(x) = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:594:17 + --> $DIR/use_self.rs:593:17 | LL | let crate::issue8845::Foo(x) = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:601:17 + --> $DIR/use_self.rs:600:17 | LL | let Bar { x, .. } = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:606:17 + --> $DIR/use_self.rs:605:17 | LL | let crate::issue8845::Bar { x, .. } = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:645:17 + --> $DIR/use_self.rs:644:17 | LL | E::A => {}, | ^ help: use the applicable keyword: `Self` diff --git a/tests/ui/use_self_trait.fixed b/tests/ui/use_self_trait.fixed index 20138a29fd1f1..2758ec7aca1fd 100644 --- a/tests/ui/use_self_trait.fixed +++ b/tests/ui/use_self_trait.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::use_self)] #![allow(dead_code)] #![allow(clippy::should_implement_trait, clippy::boxed_local)] diff --git a/tests/ui/use_self_trait.rs b/tests/ui/use_self_trait.rs index bf697b01a42f7..31031e8f50b24 100644 --- a/tests/ui/use_self_trait.rs +++ b/tests/ui/use_self_trait.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::use_self)] #![allow(dead_code)] #![allow(clippy::should_implement_trait, clippy::boxed_local)] diff --git a/tests/ui/use_self_trait.stderr b/tests/ui/use_self_trait.stderr index 6257f802dd80a..301d78e6c1ece 100644 --- a/tests/ui/use_self_trait.stderr +++ b/tests/ui/use_self_trait.stderr @@ -1,5 +1,5 @@ error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:21:18 + --> $DIR/use_self_trait.rs:19:18 | LL | fn refs(p1: &Bad) -> &Bad { | ^^^ help: use the applicable keyword: `Self` @@ -7,91 +7,91 @@ LL | fn refs(p1: &Bad) -> &Bad { = note: `-D clippy::use-self` implied by `-D warnings` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:21:27 + --> $DIR/use_self_trait.rs:19:27 | LL | fn refs(p1: &Bad) -> &Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:25:33 + --> $DIR/use_self_trait.rs:23:33 | LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:25:49 + --> $DIR/use_self_trait.rs:23:49 | LL | fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:29:26 + --> $DIR/use_self_trait.rs:27:26 | LL | fn mut_refs(p1: &mut Bad) -> &mut Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:29:39 + --> $DIR/use_self_trait.rs:27:39 | LL | fn mut_refs(p1: &mut Bad) -> &mut Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:33:24 + --> $DIR/use_self_trait.rs:31:24 | LL | fn nested(_p1: Box, _p2: (&u8, &Bad)) {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:33:42 + --> $DIR/use_self_trait.rs:31:42 | LL | fn nested(_p1: Box, _p2: (&u8, &Bad)) {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:35:16 + --> $DIR/use_self_trait.rs:33:16 | LL | fn vals(_: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:35:24 + --> $DIR/use_self_trait.rs:33:24 | LL | fn vals(_: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:36:9 + --> $DIR/use_self_trait.rs:34:9 | LL | Bad | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:41:19 + --> $DIR/use_self_trait.rs:39:19 | LL | type Output = Bad; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:43:23 + --> $DIR/use_self_trait.rs:41:23 | LL | fn mul(self, rhs: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:43:31 + --> $DIR/use_self_trait.rs:41:31 | LL | fn mul(self, rhs: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:50:9 + --> $DIR/use_self_trait.rs:48:9 | LL | Bad | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:147:13 + --> $DIR/use_self_trait.rs:145:13 | LL | std::fmt::Error // Should lint | ^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` diff --git a/tests/ui/useless_asref.fixed b/tests/ui/useless_asref.fixed index e42731f9bcf61..f6770558bd800 100644 --- a/tests/ui/useless_asref.fixed +++ b/tests/ui/useless_asref.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::useless_asref)] #![allow( clippy::explicit_auto_deref, diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs index 50c9990bb045d..0996218076b85 100644 --- a/tests/ui/useless_asref.rs +++ b/tests/ui/useless_asref.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::useless_asref)] #![allow( clippy::explicit_auto_deref, diff --git a/tests/ui/useless_asref.stderr b/tests/ui/useless_asref.stderr index c97851ac6ea43..163eb7b143743 100644 --- a/tests/ui/useless_asref.stderr +++ b/tests/ui/useless_asref.stderr @@ -1,71 +1,71 @@ error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:47:18 + --> $DIR/useless_asref.rs:46:18 | LL | foo_rstr(rstr.as_ref()); | ^^^^^^^^^^^^^ help: try: `rstr` | note: the lint level is defined here - --> $DIR/useless_asref.rs:2:9 + --> $DIR/useless_asref.rs:1:9 | LL | #![deny(clippy::useless_asref)] | ^^^^^^^^^^^^^^^^^^^^^ error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:49:20 + --> $DIR/useless_asref.rs:48:20 | LL | foo_rslice(rslice.as_ref()); | ^^^^^^^^^^^^^^^ help: try: `rslice` error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:53:21 + --> $DIR/useless_asref.rs:52:21 | LL | foo_mrslice(mrslice.as_mut()); | ^^^^^^^^^^^^^^^^ help: try: `mrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:55:20 + --> $DIR/useless_asref.rs:54:20 | LL | foo_rslice(mrslice.as_ref()); | ^^^^^^^^^^^^^^^^ help: try: `mrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:62:20 + --> $DIR/useless_asref.rs:61:20 | LL | foo_rslice(rrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^ help: try: `rrrrrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:64:18 + --> $DIR/useless_asref.rs:63:18 | LL | foo_rstr(rrrrrstr.as_ref()); | ^^^^^^^^^^^^^^^^^ help: try: `rrrrrstr` error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:69:21 + --> $DIR/useless_asref.rs:68:21 | LL | foo_mrslice(mrrrrrslice.as_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:71:20 + --> $DIR/useless_asref.rs:70:20 | LL | foo_rslice(mrrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:75:16 + --> $DIR/useless_asref.rs:74:16 | LL | foo_rrrrmr((&&&&MoreRef).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&&&&MoreRef)` error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:125:13 + --> $DIR/useless_asref.rs:124:13 | LL | foo_mrt(mrt.as_mut()); | ^^^^^^^^^^^^ help: try: `mrt` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:127:12 + --> $DIR/useless_asref.rs:126:12 | LL | foo_rt(mrt.as_ref()); | ^^^^^^^^^^^^ help: try: `mrt` diff --git a/tests/ui/useless_attribute.fixed b/tests/ui/useless_attribute.fixed index 8e77ec444b52e..475f3b34959e3 100644 --- a/tests/ui/useless_attribute.fixed +++ b/tests/ui/useless_attribute.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macro_derive.rs:proc-macro #![allow(unused)] diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index 27498d9bc132c..66bfcef51ef24 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:proc_macro_derive.rs:proc-macro #![allow(unused)] diff --git a/tests/ui/useless_attribute.stderr b/tests/ui/useless_attribute.stderr index a7ea0df22945a..8bb7b2d3d9ed1 100644 --- a/tests/ui/useless_attribute.stderr +++ b/tests/ui/useless_attribute.stderr @@ -1,5 +1,5 @@ error: useless lint attribute - --> $DIR/useless_attribute.rs:9:1 + --> $DIR/useless_attribute.rs:8:1 | LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]` @@ -7,13 +7,13 @@ LL | #[allow(dead_code)] = note: `-D clippy::useless-attribute` implied by `-D warnings` error: useless lint attribute - --> $DIR/useless_attribute.rs:10:1 + --> $DIR/useless_attribute.rs:9:1 | LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)` error: useless lint attribute - --> $DIR/useless_attribute.rs:21:5 + --> $DIR/useless_attribute.rs:20:5 | LL | #[allow(clippy::almost_swapped)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(clippy::almost_swapped)]` diff --git a/tests/ui/useless_conversion.fixed b/tests/ui/useless_conversion.fixed index 5d2c5b11658e2..d5a57ec61f7d5 100644 --- a/tests/ui/useless_conversion.fixed +++ b/tests/ui/useless_conversion.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::useless_conversion)] #![allow(clippy::needless_if, clippy::unnecessary_wraps)] diff --git a/tests/ui/useless_conversion.rs b/tests/ui/useless_conversion.rs index 03a3e3f95ba42..6730e6909c5a0 100644 --- a/tests/ui/useless_conversion.rs +++ b/tests/ui/useless_conversion.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::useless_conversion)] #![allow(clippy::needless_if, clippy::unnecessary_wraps)] diff --git a/tests/ui/useless_conversion.stderr b/tests/ui/useless_conversion.stderr index 4957f73a469a6..bf701b1e81ec7 100644 --- a/tests/ui/useless_conversion.stderr +++ b/tests/ui/useless_conversion.stderr @@ -1,179 +1,179 @@ error: useless conversion to the same type: `T` - --> $DIR/useless_conversion.rs:7:13 + --> $DIR/useless_conversion.rs:5:13 | LL | let _ = T::from(val); | ^^^^^^^^^^^^ help: consider removing `T::from()`: `val` | note: the lint level is defined here - --> $DIR/useless_conversion.rs:3:9 + --> $DIR/useless_conversion.rs:1:9 | LL | #![deny(clippy::useless_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: useless conversion to the same type: `T` - --> $DIR/useless_conversion.rs:8:5 + --> $DIR/useless_conversion.rs:6:5 | LL | val.into() | ^^^^^^^^^^ help: consider removing `.into()`: `val` error: useless conversion to the same type: `i32` - --> $DIR/useless_conversion.rs:20:22 + --> $DIR/useless_conversion.rs:18:22 | LL | let _: i32 = 0i32.into(); | ^^^^^^^^^^^ help: consider removing `.into()`: `0i32` error: useless conversion to the same type: `std::str::Lines<'_>` - --> $DIR/useless_conversion.rs:50:22 + --> $DIR/useless_conversion.rs:48:22 | LL | if Some("ok") == lines.into_iter().next() {} | ^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `lines` error: useless conversion to the same type: `std::str::Lines<'_>` - --> $DIR/useless_conversion.rs:55:21 + --> $DIR/useless_conversion.rs:53:21 | LL | let mut lines = text.lines().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()` error: useless conversion to the same type: `std::str::Lines<'_>` - --> $DIR/useless_conversion.rs:61:22 + --> $DIR/useless_conversion.rs:59:22 | LL | if Some("ok") == text.lines().into_iter().next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()` error: useless conversion to the same type: `std::ops::Range` - --> $DIR/useless_conversion.rs:67:13 + --> $DIR/useless_conversion.rs:65:13 | LL | let _ = NUMBERS.into_iter().next(); | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS` error: useless conversion to the same type: `std::ops::Range` - --> $DIR/useless_conversion.rs:72:17 + --> $DIR/useless_conversion.rs:70:17 | LL | let mut n = NUMBERS.into_iter(); | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:134:21 + --> $DIR/useless_conversion.rs:132:21 | LL | let _: String = "foo".to_string().into(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:135:21 + --> $DIR/useless_conversion.rs:133:21 | LL | let _: String = From::from("foo".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:136:13 + --> $DIR/useless_conversion.rs:134:13 | LL | let _ = String::from("foo".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:137:13 + --> $DIR/useless_conversion.rs:135:13 | LL | let _ = String::from(format!("A: {:04}", 123)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)` error: useless conversion to the same type: `std::str::Lines<'_>` - --> $DIR/useless_conversion.rs:138:13 + --> $DIR/useless_conversion.rs:136:13 | LL | let _ = "".lines().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()` error: useless conversion to the same type: `std::vec::IntoIter` - --> $DIR/useless_conversion.rs:139:13 + --> $DIR/useless_conversion.rs:137:13 | LL | let _ = vec![1, 2, 3].into_iter().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion.rs:140:21 + --> $DIR/useless_conversion.rs:138:21 | LL | let _: String = format!("Hello {}", "world").into(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")` error: useless conversion to the same type: `i32` - --> $DIR/useless_conversion.rs:145:13 + --> $DIR/useless_conversion.rs:143:13 | LL | let _ = i32::from(a + b) * 3; | ^^^^^^^^^^^^^^^^ help: consider removing `i32::from()`: `(a + b)` error: useless conversion to the same type: `Foo<'a'>` - --> $DIR/useless_conversion.rs:151:23 + --> $DIR/useless_conversion.rs:149:23 | LL | let _: Foo<'a'> = s2.into(); | ^^^^^^^^^ help: consider removing `.into()`: `s2` error: useless conversion to the same type: `Foo<'a'>` - --> $DIR/useless_conversion.rs:153:13 + --> $DIR/useless_conversion.rs:151:13 | LL | let _ = Foo::<'a'>::from(s3); | ^^^^^^^^^^^^^^^^^^^^ help: consider removing `Foo::<'a'>::from()`: `s3` error: useless conversion to the same type: `std::vec::IntoIter>` - --> $DIR/useless_conversion.rs:155:13 + --> $DIR/useless_conversion.rs:153:13 | LL | let _ = vec![s4, s4, s4].into_iter().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()` error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:171:7 + --> $DIR/useless_conversion.rs:169:7 | LL | b(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:161:13 + --> $DIR/useless_conversion.rs:159:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:172:7 + --> $DIR/useless_conversion.rs:170:7 | LL | c(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:162:18 + --> $DIR/useless_conversion.rs:160:18 | LL | fn c(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:173:7 + --> $DIR/useless_conversion.rs:171:7 | LL | d(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:165:12 + --> $DIR/useless_conversion.rs:163:12 | LL | T: IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:176:7 + --> $DIR/useless_conversion.rs:174:7 | LL | b(vec![1, 2].into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:161:13 + --> $DIR/useless_conversion.rs:159:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:177:7 + --> $DIR/useless_conversion.rs:175:7 | LL | b(vec![1, 2].into_iter().into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:161:13 + --> $DIR/useless_conversion.rs:159:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/vec.fixed b/tests/ui/vec.fixed index 7a7d0026f797b..3ff2acbe28f49 100644 --- a/tests/ui/vec.fixed +++ b/tests/ui/vec.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::useless_vec)] #![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args, unused)] diff --git a/tests/ui/vec.rs b/tests/ui/vec.rs index cbe7685b45339..2ab025f424ac6 100644 --- a/tests/ui/vec.rs +++ b/tests/ui/vec.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::useless_vec)] #![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args, unused)] diff --git a/tests/ui/vec.stderr b/tests/ui/vec.stderr index 8f6d2a1df8037..5cd6d9fa8c7e7 100644 --- a/tests/ui/vec.stderr +++ b/tests/ui/vec.stderr @@ -1,5 +1,5 @@ error: useless use of `vec!` - --> $DIR/vec.rs:31:14 + --> $DIR/vec.rs:30:14 | LL | on_slice(&vec![]); | ^^^^^^^ help: you can use a slice directly: `&[]` @@ -7,109 +7,109 @@ LL | on_slice(&vec![]); = note: `-D clippy::useless-vec` implied by `-D warnings` error: useless use of `vec!` - --> $DIR/vec.rs:33:18 + --> $DIR/vec.rs:32:18 | LL | on_mut_slice(&mut vec![]); | ^^^^^^^^^^^ help: you can use a slice directly: `&mut []` error: useless use of `vec!` - --> $DIR/vec.rs:35:14 + --> $DIR/vec.rs:34:14 | LL | on_slice(&vec![1, 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:37:18 + --> $DIR/vec.rs:36:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:39:14 + --> $DIR/vec.rs:38:14 | LL | on_slice(&vec![1, 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:41:18 + --> $DIR/vec.rs:40:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:43:14 + --> $DIR/vec.rs:42:14 | LL | on_slice(&vec!(1, 2)); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:45:18 + --> $DIR/vec.rs:44:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:47:14 + --> $DIR/vec.rs:46:14 | LL | on_slice(&vec![1; 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]` error: useless use of `vec!` - --> $DIR/vec.rs:49:18 + --> $DIR/vec.rs:48:18 | LL | on_mut_slice(&mut vec![1; 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1; 2]` error: useless use of `vec!` - --> $DIR/vec.rs:75:19 + --> $DIR/vec.rs:74:19 | LL | let _x: i32 = vec![1, 2, 3].iter().sum(); | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:78:17 + --> $DIR/vec.rs:77:17 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:84:22 + --> $DIR/vec.rs:83:22 | LL | let _x: &[i32] = &vec![1, 2, 3]; | ^^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:86:14 + --> $DIR/vec.rs:85:14 | LL | for _ in vec![1, 2, 3] {} | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:124:20 + --> $DIR/vec.rs:123:20 | LL | for _string in vec![repro!(true), repro!(null)] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]` error: useless use of `vec!` - --> $DIR/vec.rs:141:18 + --> $DIR/vec.rs:140:18 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:141:30 + --> $DIR/vec.rs:140:30 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1; 2]` error: useless use of `vec!` - --> $DIR/vec.rs:160:14 + --> $DIR/vec.rs:159:14 | LL | for a in vec![1, 2, 3] { | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:164:14 + --> $DIR/vec.rs:163:14 | LL | for a in vec![String::new(), String::new()] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]` diff --git a/tests/ui/vec_box_sized.fixed b/tests/ui/vec_box_sized.fixed index 0d0f710b558b8..4a5ef83856a41 100644 --- a/tests/ui/vec_box_sized.fixed +++ b/tests/ui/vec_box_sized.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] struct SizedStruct(i32); diff --git a/tests/ui/vec_box_sized.rs b/tests/ui/vec_box_sized.rs index fd3a7543ee1a9..ea020405a30f0 100644 --- a/tests/ui/vec_box_sized.rs +++ b/tests/ui/vec_box_sized.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] struct SizedStruct(i32); diff --git a/tests/ui/vec_box_sized.stderr b/tests/ui/vec_box_sized.stderr index c518267f04189..78e00f5661b41 100644 --- a/tests/ui/vec_box_sized.stderr +++ b/tests/ui/vec_box_sized.stderr @@ -1,5 +1,5 @@ error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:12:14 + --> $DIR/vec_box_sized.rs:10:14 | LL | const C: Vec> = Vec::new(); | ^^^^^^^^^^^^^ help: try: `Vec` @@ -7,31 +7,31 @@ LL | const C: Vec> = Vec::new(); = note: `-D clippy::vec-box` implied by `-D warnings` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:13:15 + --> $DIR/vec_box_sized.rs:11:15 | LL | static S: Vec> = Vec::new(); | ^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:16:21 + --> $DIR/vec_box_sized.rs:14:21 | LL | sized_type: Vec>, | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:19:14 + --> $DIR/vec_box_sized.rs:17:14 | LL | struct A(Vec>); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:20:18 + --> $DIR/vec_box_sized.rs:18:18 | LL | struct B(Vec>>); | ^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:48:23 + --> $DIR/vec_box_sized.rs:46:23 | LL | pub fn f() -> Vec> { | ^^^^^^^^^^^ help: try: `Vec` diff --git a/tests/ui/vec_init_then_push.rs b/tests/ui/vec_init_then_push.rs index 8dd098a5b5405..edca17eef14b1 100644 --- a/tests/ui/vec_init_then_push.rs +++ b/tests/ui/vec_init_then_push.rs @@ -1,6 +1,6 @@ #![allow(unused_variables)] #![warn(clippy::vec_init_then_push)] - +//@no-rustfix fn main() { let mut def_err: Vec = Default::default(); def_err.push(0); diff --git a/tests/ui/vec_resize_to_zero.fixed b/tests/ui/vec_resize_to_zero.fixed new file mode 100644 index 0000000000000..2c12c5a9a915f --- /dev/null +++ b/tests/ui/vec_resize_to_zero.fixed @@ -0,0 +1,19 @@ +#![warn(clippy::vec_resize_to_zero)] + +fn main() { + let mut v = vec![1, 2, 3, 4, 5]; + + // applicable here + v.clear(); + + // not applicable + v.resize(2, 5); + + let mut v = vec!["foo", "bar", "baz"]; + + // applicable here, but only implemented for integer literals for now + v.resize(0, "bar"); + + // not applicable + v.resize(2, "bar") +} diff --git a/tests/ui/while_let_loop.rs b/tests/ui/while_let_loop.rs index 5b8075731cb79..c563a142919d3 100644 --- a/tests/ui/while_let_loop.rs +++ b/tests/ui/while_let_loop.rs @@ -1,6 +1,6 @@ #![warn(clippy::while_let_loop)] #![allow(clippy::uninlined_format_args)] - +//@no-rustfix fn main() { let y = Some(true); loop { diff --git a/tests/ui/while_let_on_iterator.fixed b/tests/ui/while_let_on_iterator.fixed index 41a380ab8f6a4..d628d2227b719 100644 --- a/tests/ui/while_let_on_iterator.fixed +++ b/tests/ui/while_let_on_iterator.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::while_let_on_iterator)] #![allow(dead_code, unreachable_code, unused_mut)] #![allow( diff --git a/tests/ui/while_let_on_iterator.rs b/tests/ui/while_let_on_iterator.rs index 4c6433880b63e..525dbbaaab66f 100644 --- a/tests/ui/while_let_on_iterator.rs +++ b/tests/ui/while_let_on_iterator.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::while_let_on_iterator)] #![allow(dead_code, unreachable_code, unused_mut)] #![allow( diff --git a/tests/ui/while_let_on_iterator.stderr b/tests/ui/while_let_on_iterator.stderr index 3236765e1db0f..f8a66f2ad3e95 100644 --- a/tests/ui/while_let_on_iterator.stderr +++ b/tests/ui/while_let_on_iterator.stderr @@ -1,5 +1,5 @@ error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:16:5 + --> $DIR/while_let_on_iterator.rs:15:5 | LL | while let Option::Some(x) = iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` @@ -7,151 +7,151 @@ LL | while let Option::Some(x) = iter.next() { = note: `-D clippy::while-let-on-iterator` implied by `-D warnings` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:21:5 + --> $DIR/while_let_on_iterator.rs:20:5 | LL | while let Some(x) = iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:26:5 + --> $DIR/while_let_on_iterator.rs:25:5 | LL | while let Some(_) = iter.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in iter` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:102:9 + --> $DIR/while_let_on_iterator.rs:101:9 | LL | while let Some([..]) = it.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [..] in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:109:9 + --> $DIR/while_let_on_iterator.rs:108:9 | LL | while let Some([_x]) = it.next() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [_x] in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:122:9 + --> $DIR/while_let_on_iterator.rs:121:9 | LL | while let Some(x @ [_]) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x @ [_] in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:142:9 + --> $DIR/while_let_on_iterator.rs:141:9 | LL | while let Some(_) = y.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in y` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:199:9 + --> $DIR/while_let_on_iterator.rs:198:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:210:5 + --> $DIR/while_let_on_iterator.rs:209:5 | LL | while let Some(n) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for n in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:212:9 + --> $DIR/while_let_on_iterator.rs:211:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:221:9 + --> $DIR/while_let_on_iterator.rs:220:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:230:9 + --> $DIR/while_let_on_iterator.rs:229:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:247:9 + --> $DIR/while_let_on_iterator.rs:246:9 | LL | while let Some(m) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:262:13 + --> $DIR/while_let_on_iterator.rs:261:13 | LL | while let Some(i) = self.0.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for i in self.0.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:294:13 + --> $DIR/while_let_on_iterator.rs:293:13 | LL | while let Some(i) = self.0.0.0.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for i in self.0.0.0.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:323:5 + --> $DIR/while_let_on_iterator.rs:322:5 | LL | while let Some(n) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for n in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:335:9 + --> $DIR/while_let_on_iterator.rs:334:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:349:5 + --> $DIR/while_let_on_iterator.rs:348:5 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:360:5 + --> $DIR/while_let_on_iterator.rs:359:5 | LL | while let Some(x) = it.0.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.0.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:395:5 + --> $DIR/while_let_on_iterator.rs:394:5 | LL | while let Some(x) = s.x.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in s.x.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:402:5 + --> $DIR/while_let_on_iterator.rs:401:5 | LL | while let Some(x) = x[0].next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in x[0].by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:410:9 + --> $DIR/while_let_on_iterator.rs:409:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:420:9 + --> $DIR/while_let_on_iterator.rs:419:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:430:9 + --> $DIR/while_let_on_iterator.rs:429:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:440:9 + --> $DIR/while_let_on_iterator.rs:439:9 | LL | while let Some(x) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it` error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:450:5 + --> $DIR/while_let_on_iterator.rs:449:5 | LL | while let Some(..) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it` diff --git a/tests/ui/wildcard_enum_match_arm.fixed b/tests/ui/wildcard_enum_match_arm.fixed index ccb40acfbe1bb..1089415733a91 100644 --- a/tests/ui/wildcard_enum_match_arm.fixed +++ b/tests/ui/wildcard_enum_match_arm.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:non-exhaustive-enum.rs #![deny(clippy::wildcard_enum_match_arm)] #![allow(dead_code, unreachable_code, unused_variables)] diff --git a/tests/ui/wildcard_enum_match_arm.rs b/tests/ui/wildcard_enum_match_arm.rs index 3ce00b021a530..d9285c56f3efd 100644 --- a/tests/ui/wildcard_enum_match_arm.rs +++ b/tests/ui/wildcard_enum_match_arm.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:non-exhaustive-enum.rs #![deny(clippy::wildcard_enum_match_arm)] #![allow(dead_code, unreachable_code, unused_variables)] diff --git a/tests/ui/wildcard_enum_match_arm.stderr b/tests/ui/wildcard_enum_match_arm.stderr index 5b88ae4ab665e..7fbb16e69e4c5 100644 --- a/tests/ui/wildcard_enum_match_arm.stderr +++ b/tests/ui/wildcard_enum_match_arm.stderr @@ -1,41 +1,41 @@ error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:40:9 + --> $DIR/wildcard_enum_match_arm.rs:39:9 | LL | _ => eprintln!("Not red"), | ^ help: try: `Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan` | note: the lint level is defined here - --> $DIR/wildcard_enum_match_arm.rs:3:9 + --> $DIR/wildcard_enum_match_arm.rs:2:9 | LL | #![deny(clippy::wildcard_enum_match_arm)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:44:9 + --> $DIR/wildcard_enum_match_arm.rs:43:9 | LL | _not_red => eprintln!("Not red"), | ^^^^^^^^ help: try: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan` error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:48:9 + --> $DIR/wildcard_enum_match_arm.rs:47:9 | LL | not_red => format!("{:?}", not_red), | ^^^^^^^ help: try: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan` error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:64:9 + --> $DIR/wildcard_enum_match_arm.rs:63:9 | LL | _ => "No red", | ^ help: try: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan` error: wildcard matches known variants and will also match future added variants - --> $DIR/wildcard_enum_match_arm.rs:81:9 + --> $DIR/wildcard_enum_match_arm.rs:80:9 | LL | _ => {}, | ^ help: try: `ErrorKind::PermissionDenied | _` error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:99:13 + --> $DIR/wildcard_enum_match_arm.rs:98:13 | LL | _ => (), | ^ help: try: `Enum::B | Enum::__Private` diff --git a/tests/ui/wildcard_imports.fixed b/tests/ui/wildcard_imports.fixed index 67173f40654fe..2828f9d048efc 100644 --- a/tests/ui/wildcard_imports.fixed +++ b/tests/ui/wildcard_imports.fixed @@ -1,5 +1,5 @@ //@edition:2015 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs // the 2015 edition here is needed because edition 2018 changed the module system diff --git a/tests/ui/wildcard_imports.rs b/tests/ui/wildcard_imports.rs index 8223b69301813..cbe70e505d8cd 100644 --- a/tests/ui/wildcard_imports.rs +++ b/tests/ui/wildcard_imports.rs @@ -1,5 +1,5 @@ //@edition:2015 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs // the 2015 edition here is needed because edition 2018 changed the module system diff --git a/tests/ui/wildcard_imports_2021.edition2018.fixed b/tests/ui/wildcard_imports_2021.edition2018.fixed index 8a63375676eff..b27281fa25c56 100644 --- a/tests/ui/wildcard_imports_2021.edition2018.fixed +++ b/tests/ui/wildcard_imports_2021.edition2018.fixed @@ -1,7 +1,7 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs #![warn(clippy::wildcard_imports)] diff --git a/tests/ui/wildcard_imports_2021.edition2021.fixed b/tests/ui/wildcard_imports_2021.edition2021.fixed index 8a63375676eff..b27281fa25c56 100644 --- a/tests/ui/wildcard_imports_2021.edition2021.fixed +++ b/tests/ui/wildcard_imports_2021.edition2021.fixed @@ -1,7 +1,7 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs #![warn(clippy::wildcard_imports)] diff --git a/tests/ui/wildcard_imports_2021.rs b/tests/ui/wildcard_imports_2021.rs index 52cd2c82854fd..7dd2103eca7e7 100644 --- a/tests/ui/wildcard_imports_2021.rs +++ b/tests/ui/wildcard_imports_2021.rs @@ -1,7 +1,7 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs #![warn(clippy::wildcard_imports)] diff --git a/tests/ui/write_literal.fixed b/tests/ui/write_literal.fixed new file mode 100644 index 0000000000000..b6708453bdeb9 --- /dev/null +++ b/tests/ui/write_literal.fixed @@ -0,0 +1,45 @@ +#![warn(clippy::write_literal)] +#![allow(clippy::uninlined_format_args, unused_must_use)] + +use std::io::Write; + +fn main() { + let mut v = Vec::new(); + + // these should be fine + write!(v, "Hello"); + writeln!(v, "Hello"); + let world = "world"; + writeln!(v, "Hello {}", world); + writeln!(v, "Hello {world}", world = world); + writeln!(v, "3 in hex is {:X}", 3); + writeln!(v, "2 + 1 = {:.4}", 3); + writeln!(v, "2 + 1 = {:5.4}", 3); + writeln!(v, "Debug test {:?}", "hello, world"); + writeln!(v, "{0:8} {1:>8}", "hello", "world"); + writeln!(v, "{1:8} {0:>8}", "hello", "world"); + writeln!(v, "{foo:8} {bar:>8}", foo = "hello", bar = "world"); + writeln!(v, "{bar:8} {foo:>8}", foo = "hello", bar = "world"); + writeln!(v, "{number:>width$}", number = 1, width = 6); + writeln!(v, "{number:>0width$}", number = 1, width = 6); + writeln!(v, "{} of {:b} people know binary, the other half doesn't", 1, 2); + writeln!(v, "10 / 4 is {}", 2.5); + writeln!(v, "2 + 1 = {}", 3); + writeln!(v, "From expansion {}", stringify!(not a string literal)); + + // these should throw warnings + write!(v, "Hello world"); + writeln!(v, "Hello {} world", world); + writeln!(v, "Hello world"); + writeln!(v, "a literal {:.4}", 5); + + // positional args don't change the fact + // that we're using a literal -- this should + // throw a warning + writeln!(v, "hello world"); + writeln!(v, "world hello"); + + // named args shouldn't change anything either + writeln!(v, "hello world"); + writeln!(v, "world hello"); +} diff --git a/tests/ui/write_literal_2.rs b/tests/ui/write_literal_2.rs index 805127e275005..a250de30d5c42 100644 --- a/tests/ui/write_literal_2.rs +++ b/tests/ui/write_literal_2.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(unused_must_use)] #![warn(clippy::needless_raw_strings, clippy::write_literal)] diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index c30ec385b35ae..61cdf6112e0ef 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -1,5 +1,5 @@ error: unnecessary raw string literal - --> $DIR/write_literal_2.rs:10:24 + --> $DIR/write_literal_2.rs:11:24 | LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ help: try: `"{hello}"` @@ -7,7 +7,7 @@ LL | writeln!(v, r"{}", r"{hello}"); = note: `-D clippy::needless-raw-strings` implied by `-D warnings` error: literal with an empty format string - --> $DIR/write_literal_2.rs:9:23 + --> $DIR/write_literal_2.rs:10:23 | LL | writeln!(v, "{}", "{hello}"); | ^^^^^^^^^ @@ -20,7 +20,7 @@ LL + writeln!(v, "{{hello}}"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:10:24 + --> $DIR/write_literal_2.rs:11:24 | LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ @@ -32,7 +32,7 @@ LL + writeln!(v, r"{{hello}}"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:11:23 + --> $DIR/write_literal_2.rs:12:23 | LL | writeln!(v, "{}", '/''); | ^^^^ @@ -44,7 +44,7 @@ LL + writeln!(v, "'"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:12:23 + --> $DIR/write_literal_2.rs:13:23 | LL | writeln!(v, "{}", '"'); | ^^^ @@ -56,13 +56,13 @@ LL + writeln!(v, "/""); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:13:24 + --> $DIR/write_literal_2.rs:14:24 | LL | writeln!(v, r"{}", '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:14:24 + --> $DIR/write_literal_2.rs:15:24 | LL | writeln!(v, r"{}", '/''); | ^^^^ @@ -74,7 +74,7 @@ LL + writeln!(v, r"'"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:18:9 + --> $DIR/write_literal_2.rs:19:9 | LL | / "hello / LL | | world!" @@ -87,7 +87,7 @@ LL ~ world!" | error: literal with an empty format string - --> $DIR/write_literal_2.rs:25:9 + --> $DIR/write_literal_2.rs:26:9 | LL | "1", "2", "3", | ^^^ @@ -99,7 +99,7 @@ LL ~ {} // {}", "2", "3", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:25:14 + --> $DIR/write_literal_2.rs:26:14 | LL | "1", "2", "3", | ^^^ @@ -111,7 +111,7 @@ LL ~ "1", "3", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:25:19 + --> $DIR/write_literal_2.rs:26:19 | LL | "1", "2", "3", | ^^^ @@ -123,7 +123,7 @@ LL ~ "1", "2", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:27:23 + --> $DIR/write_literal_2.rs:28:23 | LL | writeln!(v, "{}", "//"); | ^^^^ @@ -135,7 +135,7 @@ LL + writeln!(v, "//"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:28:24 + --> $DIR/write_literal_2.rs:29:24 | LL | writeln!(v, r"{}", "//"); | ^^^^ @@ -147,7 +147,7 @@ LL + writeln!(v, r"/"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:29:26 + --> $DIR/write_literal_2.rs:30:26 | LL | writeln!(v, r#"{}"#, "//"); | ^^^^ @@ -159,7 +159,7 @@ LL + writeln!(v, r#"/"#); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:30:23 + --> $DIR/write_literal_2.rs:31:23 | LL | writeln!(v, "{}", r"/"); | ^^^^ @@ -171,7 +171,7 @@ LL + writeln!(v, "//"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:31:23 + --> $DIR/write_literal_2.rs:32:23 | LL | writeln!(v, "{}", "/r"); | ^^^^ @@ -183,13 +183,13 @@ LL + writeln!(v, "/r"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:32:28 + --> $DIR/write_literal_2.rs:33:28 | LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:32:33 + --> $DIR/write_literal_2.rs:33:33 | LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode | ^^^ diff --git a/tests/ui/write_with_newline.fixed b/tests/ui/write_with_newline.fixed index 0a10e526a2f56..f1daeb1324045 100644 --- a/tests/ui/write_with_newline.fixed +++ b/tests/ui/write_with_newline.fixed @@ -1,5 +1,4 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// //@run-rustfix #![allow(clippy::write_literal)] #![warn(clippy::write_with_newline)] @@ -50,7 +49,7 @@ fn main() { // Don't warn on CRLF (#4208) write!(v, "\r\n"); write!(v, "foo\r\n"); - writeln!(v, "\\r"); // warns + writeln!(v, "\\r"); write!(v, "foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/write_with_newline.rs b/tests/ui/write_with_newline.rs index 35bd9e7f3a077..f8f3002fed6ab 100644 --- a/tests/ui/write_with_newline.rs +++ b/tests/ui/write_with_newline.rs @@ -1,5 +1,4 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// #![allow(clippy::write_literal)] #![warn(clippy::write_with_newline)] diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index 03a18a4dc3f37..72c4bbff14b9b 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -1,5 +1,5 @@ error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:13:5 + --> $DIR/write_with_newline.rs:12:5 | LL | write!(v, "Hello/n"); | ^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + writeln!(v, "Hello"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:14:5 + --> $DIR/write_with_newline.rs:13:5 | LL | write!(v, "Hello {}/n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + writeln!(v, "Hello {}", "world"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:15:5 + --> $DIR/write_with_newline.rs:14:5 | LL | write!(v, "Hello {} {}/n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + writeln!(v, "Hello {} {}", "world", "#2"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:16:5 + --> $DIR/write_with_newline.rs:15:5 | LL | write!(v, "{}/n", 1265); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + writeln!(v, "{}", 1265); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:17:5 + --> $DIR/write_with_newline.rs:16:5 | LL | write!(v, "/n"); | ^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + writeln!(v); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:36:5 + --> $DIR/write_with_newline.rs:35:5 | LL | write!(v, "///n"); // should fail | ^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL + writeln!(v, "//"); // should fail | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:43:5 + --> $DIR/write_with_newline.rs:42:5 | LL | / write!( LL | | v, @@ -88,7 +88,7 @@ LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:48:5 + --> $DIR/write_with_newline.rs:47:5 | LL | / write!( LL | | v, @@ -104,7 +104,7 @@ LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:57:5 + --> $DIR/write_with_newline.rs:56:5 | LL | write!(v, "//r/n"); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/writeln_empty_string.fixed b/tests/ui/writeln_empty_string.fixed index 45dedd9ead6a8..f6a7481f6422c 100644 --- a/tests/ui/writeln_empty_string.fixed +++ b/tests/ui/writeln_empty_string.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_must_use)] #![warn(clippy::writeln_empty_string)] use std::io::Write; diff --git a/tests/ui/writeln_empty_string.rs b/tests/ui/writeln_empty_string.rs index 3b9f51a15d2f7..0297dba8c45d1 100644 --- a/tests/ui/writeln_empty_string.rs +++ b/tests/ui/writeln_empty_string.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_must_use)] #![warn(clippy::writeln_empty_string)] use std::io::Write; diff --git a/tests/ui/writeln_empty_string.stderr b/tests/ui/writeln_empty_string.stderr index 25e69ec48e7e2..93e1af5a4ec4f 100644 --- a/tests/ui/writeln_empty_string.stderr +++ b/tests/ui/writeln_empty_string.stderr @@ -1,5 +1,5 @@ error: empty string literal in `writeln!` - --> $DIR/writeln_empty_string.rs:11:5 + --> $DIR/writeln_empty_string.rs:9:5 | LL | writeln!(v, ""); | ^^^^^^^^^^----^ @@ -9,7 +9,7 @@ LL | writeln!(v, ""); = note: `-D clippy::writeln-empty-string` implied by `-D warnings` error: empty string literal in `writeln!` - --> $DIR/writeln_empty_string.rs:14:5 + --> $DIR/writeln_empty_string.rs:12:5 | LL | writeln!(suggestion, ""); | ^^^^^^^^^^^^^^^^^^^----^ diff --git a/tests/ui/zero_ptr.fixed b/tests/ui/zero_ptr.fixed index bed38ecafc7e9..5d99bc9b757de 100644 --- a/tests/ui/zero_ptr.fixed +++ b/tests/ui/zero_ptr.fixed @@ -1,4 +1,3 @@ -//@run-rustfix pub fn foo(_const: *const f32, _mut: *mut i64) {} fn main() { diff --git a/tests/ui/zero_ptr.rs b/tests/ui/zero_ptr.rs index b7b778915a8f4..09d321c7a18da 100644 --- a/tests/ui/zero_ptr.rs +++ b/tests/ui/zero_ptr.rs @@ -1,4 +1,3 @@ -//@run-rustfix pub fn foo(_const: *const f32, _mut: *mut i64) {} fn main() { diff --git a/tests/ui/zero_ptr.stderr b/tests/ui/zero_ptr.stderr index 4ee5e9a261686..21c2b8c1e3527 100644 --- a/tests/ui/zero_ptr.stderr +++ b/tests/ui/zero_ptr.stderr @@ -1,5 +1,5 @@ error: `0 as *const _` detected - --> $DIR/zero_ptr.rs:5:13 + --> $DIR/zero_ptr.rs:4:13 | LL | let _ = 0 as *const usize; | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::null::()` @@ -7,25 +7,25 @@ LL | let _ = 0 as *const usize; = note: `-D clippy::zero-ptr` implied by `-D warnings` error: `0 as *mut _` detected - --> $DIR/zero_ptr.rs:6:13 + --> $DIR/zero_ptr.rs:5:13 | LL | let _ = 0 as *mut f64; | ^^^^^^^^^^^^^ help: try: `std::ptr::null_mut::()` error: `0 as *const _` detected - --> $DIR/zero_ptr.rs:7:24 + --> $DIR/zero_ptr.rs:6:24 | LL | let _: *const u8 = 0 as *const _; | ^^^^^^^^^^^^^ help: try: `std::ptr::null()` error: `0 as *const _` detected - --> $DIR/zero_ptr.rs:10:9 + --> $DIR/zero_ptr.rs:9:9 | LL | foo(0 as *const _, 0 as *mut _); | ^^^^^^^^^^^^^ help: try: `std::ptr::null()` error: `0 as *mut _` detected - --> $DIR/zero_ptr.rs:10:24 + --> $DIR/zero_ptr.rs:9:24 | LL | foo(0 as *const _, 0 as *mut _); | ^^^^^^^^^^^ help: try: `std::ptr::null_mut()` diff --git a/tests/ui/zero_ptr_no_std.fixed b/tests/ui/zero_ptr_no_std.fixed index 7afd80ccaca61..4f4d19e883d1b 100644 --- a/tests/ui/zero_ptr_no_std.fixed +++ b/tests/ui/zero_ptr_no_std.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lang_items, start, libc)] #![no_std] #![deny(clippy::zero_ptr)] diff --git a/tests/ui/zero_ptr_no_std.rs b/tests/ui/zero_ptr_no_std.rs index 05a0587d22bcb..54954d8d13fe7 100644 --- a/tests/ui/zero_ptr_no_std.rs +++ b/tests/ui/zero_ptr_no_std.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lang_items, start, libc)] #![no_std] #![deny(clippy::zero_ptr)] diff --git a/tests/ui/zero_ptr_no_std.stderr b/tests/ui/zero_ptr_no_std.stderr index d92bb4a6528db..915b9c477ff4c 100644 --- a/tests/ui/zero_ptr_no_std.stderr +++ b/tests/ui/zero_ptr_no_std.stderr @@ -1,23 +1,23 @@ error: `0 as *const _` detected - --> $DIR/zero_ptr_no_std.rs:9:13 + --> $DIR/zero_ptr_no_std.rs:7:13 | LL | let _ = 0 as *const usize; | ^^^^^^^^^^^^^^^^^ help: try: `core::ptr::null::()` | note: the lint level is defined here - --> $DIR/zero_ptr_no_std.rs:5:9 + --> $DIR/zero_ptr_no_std.rs:3:9 | LL | #![deny(clippy::zero_ptr)] | ^^^^^^^^^^^^^^^^ error: `0 as *mut _` detected - --> $DIR/zero_ptr_no_std.rs:10:13 + --> $DIR/zero_ptr_no_std.rs:8:13 | LL | let _ = 0 as *mut f64; | ^^^^^^^^^^^^^ help: try: `core::ptr::null_mut::()` error: `0 as *const _` detected - --> $DIR/zero_ptr_no_std.rs:11:24 + --> $DIR/zero_ptr_no_std.rs:9:24 | LL | let _: *const u8 = 0 as *const _; | ^^^^^^^^^^^^^ help: try: `core::ptr::null()` From 00919a4f92dd8a03abb8415dee93ad69fd73356d Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 27 Jul 2023 13:23:04 +0000 Subject: [PATCH 09/79] Update ui test crate to auto-detect aux build crate kind --- Cargo.toml | 2 +- tests/compile-test.rs | 36 +++- .../collapsible_span_lint_calls.fixed | 1 - .../collapsible_span_lint_calls.stderr | 12 +- .../interning_defined_symbol.fixed | 1 - .../interning_defined_symbol.stderr | 10 +- .../ui-internal/invalid_msrv_attr_impl.fixed | 2 - .../ui-internal/invalid_msrv_attr_impl.stderr | 6 +- tests/ui-internal/outer_expn_data.fixed | 2 - tests/ui-internal/outer_expn_data.stderr | 4 +- tests/ui-internal/unnecessary_def_path.fixed | 1 - tests/ui-internal/unnecessary_def_path.stderr | 32 ++-- .../ui-internal/unnecessary_symbol_str.fixed | 1 - .../ui-internal/unnecessary_symbol_str.stderr | 12 +- .../ui-toml/absolute_paths/absolute_paths.rs | 2 +- .../excessive_nesting/excessive_nesting.rs | 2 +- .../conf_nonstandard_macro_braces.fixed | 2 +- .../conf_nonstandard_macro_braces.rs | 2 +- .../undocumented_unsafe_blocks.rs | 2 +- tests/ui/allow_attributes.fixed | 2 +- tests/ui/allow_attributes.rs | 2 +- tests/ui/allow_attributes_without_reason.rs | 2 +- tests/ui/almost_complete_range.fixed | 2 +- tests/ui/almost_complete_range.rs | 2 +- tests/ui/arc_with_non_send_sync.rs | 2 +- tests/ui/arithmetic_side_effects.rs | 2 +- tests/ui/as_conversions.rs | 2 +- tests/ui/borrow_deref_ref.fixed | 2 +- tests/ui/borrow_deref_ref.rs | 2 +- tests/ui/crashes/ice-10148.rs | 2 +- tests/ui/crashes/ice-3741.rs | 2 +- tests/ui/default_numeric_fallback_f64.fixed | 2 +- tests/ui/default_numeric_fallback_f64.rs | 2 +- tests/ui/default_numeric_fallback_i32.fixed | 2 +- tests/ui/default_numeric_fallback_i32.rs | 2 +- tests/ui/default_trait_access.fixed | 2 +- tests/ui/default_trait_access.rs | 2 +- tests/ui/deref_addrof.fixed | 2 +- tests/ui/deref_addrof.rs | 2 +- tests/ui/deref_addrof_macro.rs | 2 +- tests/ui/doc_unsafe.rs | 2 +- tests/ui/empty_line_after_doc_comments.rs | 2 +- tests/ui/empty_line_after_outer_attribute.rs | 2 +- tests/ui/empty_loop.rs | 2 +- tests/ui/equatable_if_let.fixed | 2 +- tests/ui/equatable_if_let.rs | 2 +- tests/ui/extra_unused_lifetimes.rs | 2 +- tests/ui/extra_unused_type_parameters.fixed | 2 +- tests/ui/extra_unused_type_parameters.rs | 2 +- tests/ui/field_reassign_with_default.rs | 4 +- tests/ui/filter_map_bool_then.fixed | 2 +- tests/ui/filter_map_bool_then.rs | 2 +- tests/ui/four_forward_slashes.fixed | 2 +- tests/ui/four_forward_slashes.rs | 2 +- tests/ui/implicit_hasher.rs | 2 +- tests/ui/implicit_hasher.stderr | 163 +++--------------- .../ui/inconsistent_struct_constructor.fixed | 2 +- tests/ui/inconsistent_struct_constructor.rs | 2 +- tests/ui/iter_skip_zero.fixed | 2 +- tests/ui/iter_skip_zero.rs | 2 +- tests/ui/large_enum_variant.rs | 2 +- tests/ui/let_underscore_untyped.rs | 2 +- tests/ui/let_with_type_underscore.rs | 2 +- tests/ui/macro_use_imports.fixed | 2 +- tests/ui/macro_use_imports.rs | 2 +- tests/ui/macro_use_imports.stderr | 12 +- tests/ui/macro_use_imports_expect.rs | 2 +- tests/ui/manual_float_methods.rs | 2 +- tests/ui/manual_rem_euclid.fixed | 2 +- tests/ui/manual_rem_euclid.rs | 2 +- tests/ui/manual_slice_size_calculation.fixed | 2 +- tests/ui/manual_slice_size_calculation.rs | 2 +- tests/ui/manual_try_fold.rs | 2 +- tests/ui/mem_replace_macro.rs | 2 +- tests/ui/min_ident_chars.rs | 2 +- .../ui/missing_const_for_fn/cant_be_const.rs | 2 +- tests/ui/missing_doc.rs | 2 +- tests/ui/missing_doc_impl.rs | 2 +- tests/ui/mistyped_literal_suffix.fixed | 2 +- tests/ui/mistyped_literal_suffix.rs | 2 +- tests/ui/multiple_unsafe_ops_per_block.rs | 2 +- tests/ui/must_use_unit.fixed | 2 +- tests/ui/must_use_unit.rs | 2 +- tests/ui/mut_mut.rs | 2 +- ...edless_arbitrary_self_type_unfixable.fixed | 2 +- .../needless_arbitrary_self_type_unfixable.rs | 2 +- tests/ui/needless_if.fixed | 2 +- tests/ui/needless_if.rs | 2 +- tests/ui/needless_late_init.fixed | 2 +- tests/ui/needless_late_init.rs | 2 +- tests/ui/needless_lifetimes.fixed | 2 +- tests/ui/needless_lifetimes.rs | 2 +- tests/ui/needless_pub_self.fixed | 2 +- tests/ui/needless_pub_self.rs | 2 +- .../needless_return_with_question_mark.fixed | 2 +- .../ui/needless_return_with_question_mark.rs | 2 +- tests/ui/option_env_unwrap.rs | 2 +- tests/ui/patterns.fixed | 2 +- tests/ui/patterns.rs | 2 +- tests/ui/ptr_as_ptr.fixed | 2 +- tests/ui/ptr_as_ptr.rs | 2 +- tests/ui/ptr_cast_constness.fixed | 2 +- tests/ui/ptr_cast_constness.rs | 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/redundant_at_rest_pattern.fixed | 2 +- tests/ui/redundant_at_rest_pattern.rs | 2 +- tests/ui/redundant_guards.fixed | 2 +- tests/ui/redundant_guards.rs | 2 +- tests/ui/redundant_locals.rs | 2 +- tests/ui/shadow.rs | 2 +- tests/ui/single_call_fn.rs | 2 +- tests/ui/single_match_else.fixed | 2 +- tests/ui/single_match_else.rs | 2 +- tests/ui/single_range_in_vec_init.rs | 2 +- tests/ui/string_add.rs | 2 +- tests/ui/string_lit_chars_any.fixed | 2 +- tests/ui/string_lit_chars_any.rs | 2 +- tests/ui/suspicious_else_formatting.rs | 2 +- tests/ui/toplevel_ref_arg.fixed | 2 +- tests/ui/toplevel_ref_arg.rs | 2 +- tests/ui/toplevel_ref_arg_non_rustfix.rs | 2 +- tests/ui/try_err.fixed | 2 +- tests/ui/try_err.rs | 2 +- tests/ui/tuple_array_conversions.rs | 2 +- tests/ui/undocumented_unsafe_blocks.rs | 2 +- tests/ui/uninlined_format_args.fixed | 2 +- tests/ui/uninlined_format_args.rs | 2 +- tests/ui/unit_arg.rs | 2 +- tests/ui/unnecessary_lazy_eval.fixed | 2 +- tests/ui/unnecessary_lazy_eval.rs | 2 +- tests/ui/unnecessary_unsafety_doc.rs | 2 +- tests/ui/unneeded_field_pattern.rs | 2 +- tests/ui/unneeded_wildcard_pattern.fixed | 2 +- tests/ui/unneeded_wildcard_pattern.rs | 2 +- tests/ui/unseparated_prefix_literals.fixed | 2 +- tests/ui/unseparated_prefix_literals.rs | 2 +- tests/ui/use_self.fixed | 2 +- tests/ui/use_self.rs | 2 +- tests/ui/used_underscore_binding.rs | 2 +- tests/ui/useless_attribute.fixed | 2 +- tests/ui/useless_attribute.rs | 2 +- 144 files changed, 228 insertions(+), 327 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e957cee3d4216..dcdd2161d7540 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ tempfile = { version = "3.2", optional = true } termize = "0.1" [dev-dependencies] -ui_test = "0.12" +ui_test = "0.13" tester = "0.9" regex = "1.5" toml = "0.7.3" diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 8f90aeb213936..7e283bf4a8b72 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -113,7 +113,7 @@ const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal"); fn base_config(test_dir: &str) -> (compiletest::Config, Args) { let args = Args::test(); let mut config = compiletest::Config { - mode: TestMode::Yolo, + mode: TestMode::Yolo { rustfix: true }, stderr_filters: vec![], stdout_filters: vec![], output_conflict_handling: if var_os("GITHUB_ACTION").is_none() @@ -124,7 +124,10 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) { OutputConflictHandling::Error("cargo uibless".into()) }, target: None, - out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap_or("target".into())).join("ui_test"), + out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap_or("target".into())) + .join("ui_test") + .canonicalize() + .unwrap(), ..compiletest::Config::rustc(Path::new("tests").join(test_dir)) }; let current_exe_path = env::current_exe().unwrap(); @@ -188,12 +191,18 @@ fn run_ui() { let test_filter = test_filter(); + let quiet = args.quiet; + compiletest::run_tests_generic( config, args, move |path, args| compiletest::default_file_filter(path, args) && test_filter(path), compiletest::default_per_file_config, - status_emitter::Text::verbose(), + if quiet { + status_emitter::Text::quiet() + } else { + status_emitter::Text::verbose() + }, ) .unwrap(); } @@ -208,13 +217,18 @@ fn run_internal_tests() { *err = "cargo uitest --features internal".into(); } let test_filter = test_filter(); + let quiet = args.quiet; compiletest::run_tests_generic( config, args, move |path, args| compiletest::default_file_filter(path, args) && test_filter(path), compiletest::default_per_file_config, - status_emitter::Text::verbose(), + if quiet { + status_emitter::Text::quiet() + } else { + status_emitter::Text::verbose() + }, ) .unwrap(); } @@ -236,6 +250,7 @@ fn run_ui_toml() { ); let test_filter = test_filter(); + let quiet = args.quiet; ui_test::run_tests_generic( config, @@ -249,7 +264,11 @@ fn run_ui_toml() { .push(("CLIPPY_CONF_DIR".into(), Some(path.parent().unwrap().into()))); Some(config) }, - status_emitter::Text::verbose(), + if quiet { + status_emitter::Text::quiet() + } else { + status_emitter::Text::verbose() + }, ) .unwrap(); } @@ -291,6 +310,7 @@ fn run_ui_cargo() { ); let test_filter = test_filter(); + let quiet = args.quiet; ui_test::run_tests_generic( config, @@ -301,7 +321,11 @@ fn run_ui_cargo() { config.out_dir = PathBuf::from("target/ui_test_cargo/").join(path.parent().unwrap()); Some(config) }, - status_emitter::Text::verbose(), + if quiet { + status_emitter::Text::quiet() + } else { + status_emitter::Text::verbose() + }, ) .unwrap(); } diff --git a/tests/ui-internal/collapsible_span_lint_calls.fixed b/tests/ui-internal/collapsible_span_lint_calls.fixed index 92c5d994c246d..918e33345a779 100644 --- a/tests/ui-internal/collapsible_span_lint_calls.fixed +++ b/tests/ui-internal/collapsible_span_lint_calls.fixed @@ -1,4 +1,3 @@ - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/tests/ui-internal/collapsible_span_lint_calls.stderr b/tests/ui-internal/collapsible_span_lint_calls.stderr index 0852fe65aafd0..dce2daad68a88 100644 --- a/tests/ui-internal/collapsible_span_lint_calls.stderr +++ b/tests/ui-internal/collapsible_span_lint_calls.stderr @@ -1,5 +1,5 @@ error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:36:9 + --> $DIR/collapsible_span_lint_calls.rs:35:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable); @@ -7,14 +7,14 @@ LL | | }); | |__________^ help: collapse into: `span_lint_and_sugg(cx, TEST_LINT, expr.span, lint_msg, help_msg, sugg.to_string(), Applicability::MachineApplicable)` | note: the lint level is defined here - --> $DIR/collapsible_span_lint_calls.rs:2:9 + --> $DIR/collapsible_span_lint_calls.rs:1:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::collapsible_span_lint_calls)]` implied by `#[deny(clippy::internal)]` error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:39:9 + --> $DIR/collapsible_span_lint_calls.rs:38:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.span_help(expr.span, help_msg); @@ -22,7 +22,7 @@ LL | | }); | |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg)` error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:42:9 + --> $DIR/collapsible_span_lint_calls.rs:41:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.help(help_msg); @@ -30,7 +30,7 @@ LL | | }); | |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg)` error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:45:9 + --> $DIR/collapsible_span_lint_calls.rs:44:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.span_note(expr.span, note_msg); @@ -38,7 +38,7 @@ LL | | }); | |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg)` error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:48:9 + --> $DIR/collapsible_span_lint_calls.rs:47:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.note(note_msg); diff --git a/tests/ui-internal/interning_defined_symbol.fixed b/tests/ui-internal/interning_defined_symbol.fixed index d6f2852c79d78..98591e15bec47 100644 --- a/tests/ui-internal/interning_defined_symbol.fixed +++ b/tests/ui-internal/interning_defined_symbol.fixed @@ -1,4 +1,3 @@ - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute, clippy::let_unit_value)] #![feature(rustc_private)] diff --git a/tests/ui-internal/interning_defined_symbol.stderr b/tests/ui-internal/interning_defined_symbol.stderr index 4e99636e6839d..b8d9721ee875d 100644 --- a/tests/ui-internal/interning_defined_symbol.stderr +++ b/tests/ui-internal/interning_defined_symbol.stderr @@ -1,30 +1,30 @@ error: interning a defined symbol - --> $DIR/interning_defined_symbol.rs:18:13 + --> $DIR/interning_defined_symbol.rs:17:13 | LL | let _ = Symbol::intern("f32"); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::f32` | note: the lint level is defined here - --> $DIR/interning_defined_symbol.rs:2:9 + --> $DIR/interning_defined_symbol.rs:1:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::interning_defined_symbol)]` implied by `#[deny(clippy::internal)]` error: interning a defined symbol - --> $DIR/interning_defined_symbol.rs:21:13 + --> $DIR/interning_defined_symbol.rs:20:13 | LL | let _ = sym!(f32); | ^^^^^^^^^ help: try: `rustc_span::sym::f32` error: interning a defined symbol - --> $DIR/interning_defined_symbol.rs:24:13 + --> $DIR/interning_defined_symbol.rs:23:13 | LL | let _ = Symbol::intern("proc-macro"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::proc_dash_macro` error: interning a defined symbol - --> $DIR/interning_defined_symbol.rs:27:13 + --> $DIR/interning_defined_symbol.rs:26:13 | LL | let _ = Symbol::intern("self"); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::symbol::kw::SelfLower` diff --git a/tests/ui-internal/invalid_msrv_attr_impl.fixed b/tests/ui-internal/invalid_msrv_attr_impl.fixed index fb323794fd511..928596d080913 100644 --- a/tests/ui-internal/invalid_msrv_attr_impl.fixed +++ b/tests/ui-internal/invalid_msrv_attr_impl.fixed @@ -1,5 +1,3 @@ - - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/tests/ui-internal/invalid_msrv_attr_impl.stderr b/tests/ui-internal/invalid_msrv_attr_impl.stderr index ddc06f0be1b3a..e97f6aea7e262 100644 --- a/tests/ui-internal/invalid_msrv_attr_impl.stderr +++ b/tests/ui-internal/invalid_msrv_attr_impl.stderr @@ -1,11 +1,11 @@ error: `extract_msrv_attr!` macro missing from `LateLintPass` implementation - --> $DIR/invalid_msrv_attr_impl.rs:30:1 + --> $DIR/invalid_msrv_attr_impl.rs:28:1 | LL | impl LateLintPass<'_> for Pass { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/invalid_msrv_attr_impl.rs:3:9 + --> $DIR/invalid_msrv_attr_impl.rs:1:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL + extract_msrv_attr!(LateContext); | error: `extract_msrv_attr!` macro missing from `EarlyLintPass` implementation - --> $DIR/invalid_msrv_attr_impl.rs:34:1 + --> $DIR/invalid_msrv_attr_impl.rs:32:1 | LL | impl EarlyLintPass for Pass { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-internal/outer_expn_data.fixed b/tests/ui-internal/outer_expn_data.fixed index 43f919cb35f1a..cef16cf6ca5bf 100644 --- a/tests/ui-internal/outer_expn_data.fixed +++ b/tests/ui-internal/outer_expn_data.fixed @@ -1,5 +1,3 @@ - - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/tests/ui-internal/outer_expn_data.stderr b/tests/ui-internal/outer_expn_data.stderr index afef696785e8b..e41ace4729d82 100644 --- a/tests/ui-internal/outer_expn_data.stderr +++ b/tests/ui-internal/outer_expn_data.stderr @@ -1,11 +1,11 @@ error: usage of `outer_expn().expn_data()` - --> $DIR/outer_expn_data.rs:25:34 + --> $DIR/outer_expn_data.rs:23:34 | LL | let _ = expr.span.ctxt().outer_expn().expn_data(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `outer_expn_data()` | note: the lint level is defined here - --> $DIR/outer_expn_data.rs:3:9 + --> $DIR/outer_expn_data.rs:1:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui-internal/unnecessary_def_path.fixed b/tests/ui-internal/unnecessary_def_path.fixed index ab2412683b6d0..3908411da827a 100644 --- a/tests/ui-internal/unnecessary_def_path.fixed +++ b/tests/ui-internal/unnecessary_def_path.fixed @@ -1,4 +1,3 @@ - //@aux-build:paths.rs #![deny(clippy::internal)] #![feature(rustc_private)] diff --git a/tests/ui-internal/unnecessary_def_path.stderr b/tests/ui-internal/unnecessary_def_path.stderr index 3ca29f099771b..dd963d24ced15 100644 --- a/tests/ui-internal/unnecessary_def_path.stderr +++ b/tests/ui-internal/unnecessary_def_path.stderr @@ -1,72 +1,72 @@ error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:37:13 + --> $DIR/unnecessary_def_path.rs:36:13 | LL | let _ = match_type(cx, ty, &OPTION); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Option)` | note: the lint level is defined here - --> $DIR/unnecessary_def_path.rs:3:9 + --> $DIR/unnecessary_def_path.rs:2:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::unnecessary_def_path)]` implied by `#[deny(clippy::internal)]` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:38:13 + --> $DIR/unnecessary_def_path.rs:37:13 | LL | let _ = match_type(cx, ty, RESULT); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:39:13 + --> $DIR/unnecessary_def_path.rs:38:13 | LL | let _ = match_type(cx, ty, &["core", "result", "Result"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:43:13 + --> $DIR/unnecessary_def_path.rs:42:13 | LL | let _ = clippy_utils::ty::match_type(cx, ty, rc_path); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Rc)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:45:13 + --> $DIR/unnecessary_def_path.rs:44:13 | LL | let _ = match_type(cx, ty, &paths::OPTION); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Option)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:46:13 + --> $DIR/unnecessary_def_path.rs:45:13 | LL | let _ = match_type(cx, ty, paths::RESULT); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:48:13 + --> $DIR/unnecessary_def_path.rs:47:13 | LL | let _ = match_type(cx, ty, &["alloc", "boxed", "Box"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_lang_item(cx, ty, LangItem::OwnedBox)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:49:13 + --> $DIR/unnecessary_def_path.rs:48:13 | LL | let _ = match_type(cx, ty, &["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit)` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:51:13 + --> $DIR/unnecessary_def_path.rs:50:13 | LL | let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:52:13 + --> $DIR/unnecessary_def_path.rs:51:13 | LL | let _ = match_def_path(cx, did, &["core", "option", "Option"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.is_diagnostic_item(sym::Option, did)` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:53:13 + --> $DIR/unnecessary_def_path.rs:52:13 | LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did)` @@ -74,25 +74,25 @@ LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]); = help: if this `DefId` came from a constructor expression or pattern then the parent `DefId` should be used instead error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:55:13 + --> $DIR/unnecessary_def_path.rs:54:13 | LL | let _ = match_trait_method(cx, expr, &["core", "convert", "AsRef"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_trait_method(cx, expr, sym::AsRef)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:57:13 + --> $DIR/unnecessary_def_path.rs:56:13 | LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_path_diagnostic_item(cx, expr, sym::Option)` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:58:13 + --> $DIR/unnecessary_def_path.rs:57:13 | LL | let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id))` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:59:13 + --> $DIR/unnecessary_def_path.rs:58:13 | LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option", "Some"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome)` diff --git a/tests/ui-internal/unnecessary_symbol_str.fixed b/tests/ui-internal/unnecessary_symbol_str.fixed index 5845f7f8d7cb5..eb79fdbc4b4c8 100644 --- a/tests/ui-internal/unnecessary_symbol_str.fixed +++ b/tests/ui-internal/unnecessary_symbol_str.fixed @@ -1,4 +1,3 @@ - #![feature(rustc_private)] #![deny(clippy::internal)] #![allow( diff --git a/tests/ui-internal/unnecessary_symbol_str.stderr b/tests/ui-internal/unnecessary_symbol_str.stderr index a1f507f331d26..8e2aa59539356 100644 --- a/tests/ui-internal/unnecessary_symbol_str.stderr +++ b/tests/ui-internal/unnecessary_symbol_str.stderr @@ -1,36 +1,36 @@ error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:16:5 + --> $DIR/unnecessary_symbol_str.rs:15:5 | LL | Symbol::intern("foo").as_str() == "clippy"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") == rustc_span::sym::clippy` | note: the lint level is defined here - --> $DIR/unnecessary_symbol_str.rs:3:9 + --> $DIR/unnecessary_symbol_str.rs:2:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::unnecessary_symbol_str)]` implied by `#[deny(clippy::internal)]` error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:17:5 + --> $DIR/unnecessary_symbol_str.rs:16:5 | LL | Symbol::intern("foo").to_string() == "self"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") == rustc_span::symbol::kw::SelfLower` error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:18:5 + --> $DIR/unnecessary_symbol_str.rs:17:5 | LL | Symbol::intern("foo").to_ident_string() != "Self"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") != rustc_span::symbol::kw::SelfUpper` error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:19:5 + --> $DIR/unnecessary_symbol_str.rs:18:5 | LL | &*Ident::empty().as_str() == "clippy"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::empty().name == rustc_span::sym::clippy` error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:20:5 + --> $DIR/unnecessary_symbol_str.rs:19:5 | LL | "clippy" == Ident::empty().to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::empty().name` diff --git a/tests/ui-toml/absolute_paths/absolute_paths.rs b/tests/ui-toml/absolute_paths/absolute_paths.rs index d4c250a8ff231..0e6a54452ee89 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths.rs +++ b/tests/ui-toml/absolute_paths/absolute_paths.rs @@ -1,4 +1,4 @@ -//@aux-build:../../ui/auxiliary/proc_macros.rs:proc-macro +//@aux-build:../../ui/auxiliary/proc_macros.rs //@aux-build:helper.rs //@revisions: allow_crates disallow_crates //@[allow_crates] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/allow_crates diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.rs b/tests/ui-toml/excessive_nesting/excessive_nesting.rs index c28220b973ec3..25f0d0d6230a7 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.rs +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![rustfmt::skip] #![feature(custom_inner_attributes)] #![allow(unused)] 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 f7484101760bc..673106f0b12d9 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 @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::nonstandard_macro_braces)] 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 4e01299f81e90..b9c69037be073 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 @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::nonstandard_macro_braces)] diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs index 33d63670958dc..c0976f0d6007b 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_unsafe.rs:proc-macro +//@aux-build:proc_macro_unsafe.rs #![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)] #![allow(deref_nullptr, clippy::let_unit_value, clippy::missing_safety_doc)] diff --git a/tests/ui/allow_attributes.fixed b/tests/ui/allow_attributes.fixed index 1351a1a4eb495..945ba83611c0d 100644 --- a/tests/ui/allow_attributes.fixed +++ b/tests/ui/allow_attributes.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::allow_attributes)] #![feature(lint_reasons)] diff --git a/tests/ui/allow_attributes.rs b/tests/ui/allow_attributes.rs index e14e24e52b532..8afa61c7002c5 100644 --- a/tests/ui/allow_attributes.rs +++ b/tests/ui/allow_attributes.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::allow_attributes)] #![feature(lint_reasons)] diff --git a/tests/ui/allow_attributes_without_reason.rs b/tests/ui/allow_attributes_without_reason.rs index d223d56422177..663c2eb2c3794 100644 --- a/tests/ui/allow_attributes_without_reason.rs +++ b/tests/ui/allow_attributes_without_reason.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(lint_reasons)] #![deny(clippy::allow_attributes_without_reason)] #![allow(unfulfilled_lint_expectations)] diff --git a/tests/ui/almost_complete_range.fixed b/tests/ui/almost_complete_range.fixed index b4de1b97336db..21caeb153e77d 100644 --- a/tests/ui/almost_complete_range.fixed +++ b/tests/ui/almost_complete_range.fixed @@ -1,5 +1,5 @@ //@edition:2018 -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(exclusive_range_pattern)] #![feature(stmt_expr_attributes)] diff --git a/tests/ui/almost_complete_range.rs b/tests/ui/almost_complete_range.rs index b0e8d69476e9c..556110a5c8aae 100644 --- a/tests/ui/almost_complete_range.rs +++ b/tests/ui/almost_complete_range.rs @@ -1,5 +1,5 @@ //@edition:2018 -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(exclusive_range_pattern)] #![feature(stmt_expr_attributes)] diff --git a/tests/ui/arc_with_non_send_sync.rs b/tests/ui/arc_with_non_send_sync.rs index 2940c27325526..d03a577c45447 100644 --- a/tests/ui/arc_with_non_send_sync.rs +++ b/tests/ui/arc_with_non_send_sync.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::arc_with_non_send_sync)] #![allow(unused_variables)] diff --git a/tests/ui/arithmetic_side_effects.rs b/tests/ui/arithmetic_side_effects.rs index 2ac2fa22086b8..8485b3eab71b4 100644 --- a/tests/ui/arithmetic_side_effects.rs +++ b/tests/ui/arithmetic_side_effects.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![allow( clippy::assign_op_pattern, diff --git a/tests/ui/as_conversions.rs b/tests/ui/as_conversions.rs index 69f1c541c4eed..192eb51ea99fc 100644 --- a/tests/ui/as_conversions.rs +++ b/tests/ui/as_conversions.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::as_conversions)] #![allow(clippy::borrow_as_ptr, unused)] diff --git a/tests/ui/borrow_deref_ref.fixed b/tests/ui/borrow_deref_ref.fixed index c7c22c7a0c9f1..ea5e983de3bdb 100644 --- a/tests/ui/borrow_deref_ref.fixed +++ b/tests/ui/borrow_deref_ref.fixed @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow(dead_code, unused_variables)] diff --git a/tests/ui/borrow_deref_ref.rs b/tests/ui/borrow_deref_ref.rs index 9e004ad7041fb..8c8905b150e62 100644 --- a/tests/ui/borrow_deref_ref.rs +++ b/tests/ui/borrow_deref_ref.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow(dead_code, unused_variables)] diff --git a/tests/ui/crashes/ice-10148.rs b/tests/ui/crashes/ice-10148.rs index 8060c8e3bf0df..d89d94edbcdb9 100644 --- a/tests/ui/crashes/ice-10148.rs +++ b/tests/ui/crashes/ice-10148.rs @@ -1,4 +1,4 @@ -//@aux-build:../auxiliary/proc_macros.rs:proc-macro +//@aux-build:../auxiliary/proc_macros.rs //@no-rustfix extern crate proc_macros; diff --git a/tests/ui/crashes/ice-3741.rs b/tests/ui/crashes/ice-3741.rs index 268c5ba0ad0f6..3106a2e721694 100644 --- a/tests/ui/crashes/ice-3741.rs +++ b/tests/ui/crashes/ice-3741.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_crash.rs:proc-macro +//@aux-build:proc_macro_crash.rs #![warn(clippy::suspicious_else_formatting)] diff --git a/tests/ui/default_numeric_fallback_f64.fixed b/tests/ui/default_numeric_fallback_f64.fixed index e1b242716f634..9072d23356343 100644 --- a/tests/ui/default_numeric_fallback_f64.fixed +++ b/tests/ui/default_numeric_fallback_f64.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::default_numeric_fallback)] #![allow( diff --git a/tests/ui/default_numeric_fallback_f64.rs b/tests/ui/default_numeric_fallback_f64.rs index 0e93088e1fa2b..256b94f6c0589 100644 --- a/tests/ui/default_numeric_fallback_f64.rs +++ b/tests/ui/default_numeric_fallback_f64.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::default_numeric_fallback)] #![allow( diff --git a/tests/ui/default_numeric_fallback_i32.fixed b/tests/ui/default_numeric_fallback_i32.fixed index d30403b9cc989..920cd9f8f7715 100644 --- a/tests/ui/default_numeric_fallback_i32.fixed +++ b/tests/ui/default_numeric_fallback_i32.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(lint_reasons)] #![warn(clippy::default_numeric_fallback)] diff --git a/tests/ui/default_numeric_fallback_i32.rs b/tests/ui/default_numeric_fallback_i32.rs index 4da9623d0f411..bdb7b5f47bca0 100644 --- a/tests/ui/default_numeric_fallback_i32.rs +++ b/tests/ui/default_numeric_fallback_i32.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(lint_reasons)] #![warn(clippy::default_numeric_fallback)] diff --git a/tests/ui/default_trait_access.fixed b/tests/ui/default_trait_access.fixed index 7f6e201444fcc..6f1e72c5a6c0c 100644 --- a/tests/ui/default_trait_access.fixed +++ b/tests/ui/default_trait_access.fixed @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![deny(clippy::default_trait_access)] #![allow(dead_code, unused_imports)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/default_trait_access.rs b/tests/ui/default_trait_access.rs index a0937118429c9..5528ca8b7936e 100644 --- a/tests/ui/default_trait_access.rs +++ b/tests/ui/default_trait_access.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![deny(clippy::default_trait_access)] #![allow(dead_code, unused_imports)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/deref_addrof.fixed b/tests/ui/deref_addrof.fixed index 30093da9b9a8c..aa1cf19b76f93 100644 --- a/tests/ui/deref_addrof.fixed +++ b/tests/ui/deref_addrof.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::return_self_not_must_use, clippy::useless_vec)] #![warn(clippy::deref_addrof)] diff --git a/tests/ui/deref_addrof.rs b/tests/ui/deref_addrof.rs index 3902bbd09757e..38796aef390e3 100644 --- a/tests/ui/deref_addrof.rs +++ b/tests/ui/deref_addrof.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::return_self_not_must_use, clippy::useless_vec)] #![warn(clippy::deref_addrof)] diff --git a/tests/ui/deref_addrof_macro.rs b/tests/ui/deref_addrof_macro.rs index ce4b94a73bd25..c7e60f3650603 100644 --- a/tests/ui/deref_addrof_macro.rs +++ b/tests/ui/deref_addrof_macro.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::deref_addrof)] diff --git a/tests/ui/doc_unsafe.rs b/tests/ui/doc_unsafe.rs index d21b046f167ef..0c8eac5ccffc3 100644 --- a/tests/ui/doc_unsafe.rs +++ b/tests/ui/doc_unsafe.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::let_unit_value)] diff --git a/tests/ui/empty_line_after_doc_comments.rs b/tests/ui/empty_line_after_doc_comments.rs index 83db2a07d334e..e843770f57854 100644 --- a/tests/ui/empty_line_after_doc_comments.rs +++ b/tests/ui/empty_line_after_doc_comments.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_attr.rs:proc-macro +//@aux-build:proc_macro_attr.rs #![warn(clippy::empty_line_after_doc_comments)] #![allow(clippy::assertions_on_constants)] #![feature(custom_inner_attributes)] diff --git a/tests/ui/empty_line_after_outer_attribute.rs b/tests/ui/empty_line_after_outer_attribute.rs index b2d7ddae42746..269e66ea0a816 100644 --- a/tests/ui/empty_line_after_outer_attribute.rs +++ b/tests/ui/empty_line_after_outer_attribute.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_attr.rs:proc-macro +//@aux-build:proc_macro_attr.rs #![warn(clippy::empty_line_after_outer_attr)] #![allow(clippy::assertions_on_constants)] #![feature(custom_inner_attributes)] diff --git a/tests/ui/empty_loop.rs b/tests/ui/empty_loop.rs index f1a55415c8d50..54e8fb4907c0f 100644 --- a/tests/ui/empty_loop.rs +++ b/tests/ui/empty_loop.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::empty_loop)] diff --git a/tests/ui/equatable_if_let.fixed b/tests/ui/equatable_if_let.fixed index 73094ad1e53f6..2b523e1e185c6 100644 --- a/tests/ui/equatable_if_let.fixed +++ b/tests/ui/equatable_if_let.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( unused_variables, diff --git a/tests/ui/equatable_if_let.rs b/tests/ui/equatable_if_let.rs index 460352734a313..f7e3bb2964da3 100644 --- a/tests/ui/equatable_if_let.rs +++ b/tests/ui/equatable_if_let.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( unused_variables, diff --git a/tests/ui/extra_unused_lifetimes.rs b/tests/ui/extra_unused_lifetimes.rs index 50abe89da893a..cdfaf8d3afea8 100644 --- a/tests/ui/extra_unused_lifetimes.rs +++ b/tests/ui/extra_unused_lifetimes.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![allow( unused, diff --git a/tests/ui/extra_unused_type_parameters.fixed b/tests/ui/extra_unused_type_parameters.fixed index 3de027d77e424..a4943344a11ef 100644 --- a/tests/ui/extra_unused_type_parameters.fixed +++ b/tests/ui/extra_unused_type_parameters.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused, clippy::needless_lifetimes)] #![warn(clippy::extra_unused_type_parameters)] diff --git a/tests/ui/extra_unused_type_parameters.rs b/tests/ui/extra_unused_type_parameters.rs index 14aa55d5314de..6d85b1ce9d4f3 100644 --- a/tests/ui/extra_unused_type_parameters.rs +++ b/tests/ui/extra_unused_type_parameters.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused, clippy::needless_lifetimes)] #![warn(clippy::extra_unused_type_parameters)] diff --git a/tests/ui/field_reassign_with_default.rs b/tests/ui/field_reassign_with_default.rs index d6df114b8d262..2045b1eebcd7f 100644 --- a/tests/ui/field_reassign_with_default.rs +++ b/tests/ui/field_reassign_with_default.rs @@ -1,5 +1,5 @@ -//@aux-build:proc_macro_derive.rs:proc-macro -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macro_derive.rs +//@aux-build:proc_macros.rs #![warn(clippy::field_reassign_with_default)] diff --git a/tests/ui/filter_map_bool_then.fixed b/tests/ui/filter_map_bool_then.fixed index 99188e07e45ee..6de870a928985 100644 --- a/tests/ui/filter_map_bool_then.fixed +++ b/tests/ui/filter_map_bool_then.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( clippy::clone_on_copy, clippy::map_identity, diff --git a/tests/ui/filter_map_bool_then.rs b/tests/ui/filter_map_bool_then.rs index 78b7daa1089ce..4108177e3a0e3 100644 --- a/tests/ui/filter_map_bool_then.rs +++ b/tests/ui/filter_map_bool_then.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( clippy::clone_on_copy, clippy::map_identity, diff --git a/tests/ui/four_forward_slashes.fixed b/tests/ui/four_forward_slashes.fixed index 67c07ccbed74a..6d31c543d7274 100644 --- a/tests/ui/four_forward_slashes.fixed +++ b/tests/ui/four_forward_slashes.fixed @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] #![warn(clippy::four_forward_slashes)] diff --git a/tests/ui/four_forward_slashes.rs b/tests/ui/four_forward_slashes.rs index c86a925e5e6d8..458b8de53e15b 100644 --- a/tests/ui/four_forward_slashes.rs +++ b/tests/ui/four_forward_slashes.rs @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] #![warn(clippy::four_forward_slashes)] diff --git a/tests/ui/implicit_hasher.rs b/tests/ui/implicit_hasher.rs index 5e7fa4faf27dd..f7cd541741b11 100644 --- a/tests/ui/implicit_hasher.rs +++ b/tests/ui/implicit_hasher.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs //@no-rustfix #![deny(clippy::implicit_hasher)] #![allow(unused)] diff --git a/tests/ui/implicit_hasher.stderr b/tests/ui/implicit_hasher.stderr index 83b46de2eb5e3..a27590288bc48 100644 --- a/tests/ui/implicit_hasher.stderr +++ b/tests/ui/implicit_hasher.stderr @@ -1,155 +1,40 @@ -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:18:35 +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:14:1 | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/implicit_hasher.rs:3:9 - | -LL | #![deny(clippy::implicit_hasher)] - | ^^^^^^^^^^^^^^^^^^^^^^^ -help: consider adding a type parameter - | -LL | impl Foo for HashMap { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:27:36 - | -LL | impl Foo for (HashMap,) { - | ^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for (HashMap,) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),)) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:32:19 - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for HashMap { - | +++++++++++++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: impl for `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:49:32 - | -LL | impl Foo for HashSet { - | ^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for HashSet { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | pub trait Foo: Sized { + | ^^^^^^^^^^^^^^^^^^^^^^^ -error: impl for `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:54:19 - | -LL | impl Foo for HashSet { - | ^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for HashSet { - | +++++++++++++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: parameter of type `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:71:23 +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:71:1 | LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: parameter of type `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:71:53 - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^ +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:74:1 | -help: consider adding a type parameter - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ +LL | pub mod gen { + | ^^^^^^^^^^^ -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:77:43 - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^ +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:92:1 | - = note: this error originates in the macro `__inline_mac_mod_gen` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider adding a type parameter - | -LL | impl Foo for HashMap { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | pub mod test_macro; + | ^^^^^^^^^^^^^^^^^^^ -error: parameter of type `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:83:31 - | -LL | pub fn bar(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^ +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:96:1 | - = note: this error originates in the macro `__inline_mac_mod_gen` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider adding a type parameter +LL | external! { + | ^^^^^^^^^ | -LL | pub fn bar(_map: &mut HashMap, _set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ + = note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info) -error: parameter of type `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:83:61 - | -LL | pub fn bar(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^ - | - = note: this error originates in the macro `__inline_mac_mod_gen` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider adding a type parameter - | -LL | pub fn bar(_map: &mut HashMap, _set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ - -error: parameter of type `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:101:35 +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:101:1 | LL | pub async fn election_vote(_data: HashMap) {} - | ^^^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | pub async fn election_vote(_data: HashMap) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 11 previous errors +error: aborting due to 6 previous errors diff --git a/tests/ui/inconsistent_struct_constructor.fixed b/tests/ui/inconsistent_struct_constructor.fixed index 3c33e9c5611bd..5778f8f526f86 100644 --- a/tests/ui/inconsistent_struct_constructor.fixed +++ b/tests/ui/inconsistent_struct_constructor.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::inconsistent_struct_constructor)] #![allow(clippy::redundant_field_names)] diff --git a/tests/ui/inconsistent_struct_constructor.rs b/tests/ui/inconsistent_struct_constructor.rs index a3360582f1a2d..9efaf0689342f 100644 --- a/tests/ui/inconsistent_struct_constructor.rs +++ b/tests/ui/inconsistent_struct_constructor.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::inconsistent_struct_constructor)] #![allow(clippy::redundant_field_names)] diff --git a/tests/ui/iter_skip_zero.fixed b/tests/ui/iter_skip_zero.fixed index f31c8634d4d75..62a83d5905b41 100644 --- a/tests/ui/iter_skip_zero.fixed +++ b/tests/ui/iter_skip_zero.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::useless_vec, unused)] #![warn(clippy::iter_skip_zero)] diff --git a/tests/ui/iter_skip_zero.rs b/tests/ui/iter_skip_zero.rs index 188ae547d8041..c96696dde65d4 100644 --- a/tests/ui/iter_skip_zero.rs +++ b/tests/ui/iter_skip_zero.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::useless_vec, unused)] #![warn(clippy::iter_skip_zero)] diff --git a/tests/ui/large_enum_variant.rs b/tests/ui/large_enum_variant.rs index 0aac6875346ec..f101bda76a895 100644 --- a/tests/ui/large_enum_variant.rs +++ b/tests/ui/large_enum_variant.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs //@no-rustfix #![allow(dead_code)] #![allow(unused_variables)] diff --git a/tests/ui/let_underscore_untyped.rs b/tests/ui/let_underscore_untyped.rs index 18630c27f4171..bd94a3ada18b9 100644 --- a/tests/ui/let_underscore_untyped.rs +++ b/tests/ui/let_underscore_untyped.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow(unused)] #![warn(clippy::let_underscore_untyped)] diff --git a/tests/ui/let_with_type_underscore.rs b/tests/ui/let_with_type_underscore.rs index 8214176cfd576..ae1a480bcfc55 100644 --- a/tests/ui/let_with_type_underscore.rs +++ b/tests/ui/let_with_type_underscore.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow(unused)] #![warn(clippy::let_with_type_underscore)] #![allow(clippy::let_unit_value, clippy::needless_late_init)] diff --git a/tests/ui/macro_use_imports.fixed b/tests/ui/macro_use_imports.fixed index 2d8ac229226bc..46c053b779e70 100644 --- a/tests/ui/macro_use_imports.fixed +++ b/tests/ui/macro_use_imports.fixed @@ -1,6 +1,6 @@ //@aux-build:macro_rules.rs //@aux-build:macro_use_helper.rs -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs //@ignore-32bit diff --git a/tests/ui/macro_use_imports.rs b/tests/ui/macro_use_imports.rs index 3ad81ef671947..47f5c9bf8845e 100644 --- a/tests/ui/macro_use_imports.rs +++ b/tests/ui/macro_use_imports.rs @@ -1,6 +1,6 @@ //@aux-build:macro_rules.rs //@aux-build:macro_use_helper.rs -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs //@ignore-32bit diff --git a/tests/ui/macro_use_imports.stderr b/tests/ui/macro_use_imports.stderr index 72ae0bea1fa9f..2259e5abf2f37 100644 --- a/tests/ui/macro_use_imports.stderr +++ b/tests/ui/macro_use_imports.stderr @@ -1,16 +1,16 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:23:5 + --> $DIR/macro_use_imports.rs:25:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` | = note: `-D clippy::macro-use-imports` implied by `-D warnings` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:19:5 + --> $DIR/macro_use_imports.rs:23:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};` error: `macro_use` attributes are no longer needed in the Rust 2018 edition --> $DIR/macro_use_imports.rs:21:5 @@ -19,10 +19,10 @@ LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:25:5 + --> $DIR/macro_use_imports.rs:19:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` error: aborting due to 4 previous errors diff --git a/tests/ui/macro_use_imports_expect.rs b/tests/ui/macro_use_imports_expect.rs index 3971aadbef853..b9677851b92de 100644 --- a/tests/ui/macro_use_imports_expect.rs +++ b/tests/ui/macro_use_imports_expect.rs @@ -1,6 +1,6 @@ //@aux-build:macro_rules.rs //@aux-build:macro_use_helper.rs -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs //@ignore-32bit #![feature(lint_reasons)] diff --git a/tests/ui/manual_float_methods.rs b/tests/ui/manual_float_methods.rs index 2a89a9e998239..f3e95d6807d33 100644 --- a/tests/ui/manual_float_methods.rs +++ b/tests/ui/manual_float_methods.rs @@ -1,5 +1,5 @@ //@no-rustfix: overlapping suggestions -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::needless_if, unused)] #![warn(clippy::manual_is_infinite, clippy::manual_is_finite)] #![feature(inline_const)] diff --git a/tests/ui/manual_rem_euclid.fixed b/tests/ui/manual_rem_euclid.fixed index f774f4cfcbd58..2d50865586d1f 100644 --- a/tests/ui/manual_rem_euclid.fixed +++ b/tests/ui/manual_rem_euclid.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::manual_rem_euclid)] #![allow(clippy::let_with_type_underscore)] diff --git a/tests/ui/manual_rem_euclid.rs b/tests/ui/manual_rem_euclid.rs index 9a64720698014..e405a2db47651 100644 --- a/tests/ui/manual_rem_euclid.rs +++ b/tests/ui/manual_rem_euclid.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::manual_rem_euclid)] #![allow(clippy::let_with_type_underscore)] diff --git a/tests/ui/manual_slice_size_calculation.fixed b/tests/ui/manual_slice_size_calculation.fixed index ec1ee79251d84..62b372f4b8d9c 100644 --- a/tests/ui/manual_slice_size_calculation.fixed +++ b/tests/ui/manual_slice_size_calculation.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::manual_slice_size_calculation)] diff --git a/tests/ui/manual_slice_size_calculation.rs b/tests/ui/manual_slice_size_calculation.rs index 404ba1268cc19..d59f5fd8b9427 100644 --- a/tests/ui/manual_slice_size_calculation.rs +++ b/tests/ui/manual_slice_size_calculation.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::manual_slice_size_calculation)] diff --git a/tests/ui/manual_try_fold.rs b/tests/ui/manual_try_fold.rs index 79d8a35e2b376..bddf03ac3f1fe 100644 --- a/tests/ui/manual_try_fold.rs +++ b/tests/ui/manual_try_fold.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::unnecessary_fold, unused)] #![warn(clippy::manual_try_fold)] #![feature(try_trait_v2)] diff --git a/tests/ui/mem_replace_macro.rs b/tests/ui/mem_replace_macro.rs index e53342f2ed368..132873858b7c5 100644 --- a/tests/ui/mem_replace_macro.rs +++ b/tests/ui/mem_replace_macro.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::mem_replace_with_default)] extern crate proc_macros; diff --git a/tests/ui/min_ident_chars.rs b/tests/ui/min_ident_chars.rs index 03784442e2c9e..030863ca0d304 100644 --- a/tests/ui/min_ident_chars.rs +++ b/tests/ui/min_ident_chars.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(irrefutable_let_patterns, nonstandard_style, unused)] #![warn(clippy::min_ident_chars)] diff --git a/tests/ui/missing_const_for_fn/cant_be_const.rs b/tests/ui/missing_const_for_fn/cant_be_const.rs index 06e0535247982..d026e009684a4 100644 --- a/tests/ui/missing_const_for_fn/cant_be_const.rs +++ b/tests/ui/missing_const_for_fn/cant_be_const.rs @@ -3,7 +3,7 @@ //! The .stderr output of this test should be empty. Otherwise it's a bug somewhere. //@aux-build:helper.rs -//@aux-build:../auxiliary/proc_macros.rs:proc-macro +//@aux-build:../auxiliary/proc_macros.rs #![warn(clippy::missing_const_for_fn)] #![feature(start)] diff --git a/tests/ui/missing_doc.rs b/tests/ui/missing_doc.rs index 83ebf09c8a3fc..9bfad3b96cffd 100644 --- a/tests/ui/missing_doc.rs +++ b/tests/ui/missing_doc.rs @@ -1,5 +1,5 @@ //@needs-asm-support -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::missing_docs_in_private_items)] // When denying at the crate level, be sure to not get random warnings from the diff --git a/tests/ui/missing_doc_impl.rs b/tests/ui/missing_doc_impl.rs index 2d45132f968eb..520ddbe16b829 100644 --- a/tests/ui/missing_doc_impl.rs +++ b/tests/ui/missing_doc_impl.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::missing_docs_in_private_items)] #![allow(dead_code)] diff --git a/tests/ui/mistyped_literal_suffix.fixed b/tests/ui/mistyped_literal_suffix.fixed index 384f34f65fc78..861764a2aeeb9 100644 --- a/tests/ui/mistyped_literal_suffix.fixed +++ b/tests/ui/mistyped_literal_suffix.fixed @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow( dead_code, diff --git a/tests/ui/mistyped_literal_suffix.rs b/tests/ui/mistyped_literal_suffix.rs index cc7105c4424a1..4a15c335fd893 100644 --- a/tests/ui/mistyped_literal_suffix.rs +++ b/tests/ui/mistyped_literal_suffix.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow( dead_code, diff --git a/tests/ui/multiple_unsafe_ops_per_block.rs b/tests/ui/multiple_unsafe_ops_per_block.rs index 23ad36bb47304..4ef6f0ca92f2d 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.rs +++ b/tests/ui/multiple_unsafe_ops_per_block.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![allow(deref_nullptr)] #![allow(clippy::unnecessary_operation)] diff --git a/tests/ui/must_use_unit.fixed b/tests/ui/must_use_unit.fixed index 4ffade40cf0c5..75f91e6682426 100644 --- a/tests/ui/must_use_unit.fixed +++ b/tests/ui/must_use_unit.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::must_use_unit)] #![allow(clippy::unused_unit)] diff --git a/tests/ui/must_use_unit.rs b/tests/ui/must_use_unit.rs index 6b928e37c417a..1305910ed0e5c 100644 --- a/tests/ui/must_use_unit.rs +++ b/tests/ui/must_use_unit.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::must_use_unit)] #![allow(clippy::unused_unit)] diff --git a/tests/ui/mut_mut.rs b/tests/ui/mut_mut.rs index fe7d53e8e9991..72a171119f3c5 100644 --- a/tests/ui/mut_mut.rs +++ b/tests/ui/mut_mut.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::mut_mut)] #![allow(unused)] #![allow( diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.fixed b/tests/ui/needless_arbitrary_self_type_unfixable.fixed index df4949b977e95..62a6e5932435d 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.fixed +++ b/tests/ui/needless_arbitrary_self_type_unfixable.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_attr.rs:proc-macro +//@aux-build:proc_macro_attr.rs #![warn(clippy::needless_arbitrary_self_type)] diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.rs b/tests/ui/needless_arbitrary_self_type_unfixable.rs index 876f16a3854d9..00871f9f450ca 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.rs +++ b/tests/ui/needless_arbitrary_self_type_unfixable.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_attr.rs:proc-macro +//@aux-build:proc_macro_attr.rs #![warn(clippy::needless_arbitrary_self_type)] diff --git a/tests/ui/needless_if.fixed b/tests/ui/needless_if.fixed index 35220e5b3c6e6..b84182c5756e5 100644 --- a/tests/ui/needless_if.fixed +++ b/tests/ui/needless_if.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(let_chains)] #![allow( clippy::blocks_in_if_conditions, diff --git a/tests/ui/needless_if.rs b/tests/ui/needless_if.rs index 29d3bf77af89d..6c6023c72dcf2 100644 --- a/tests/ui/needless_if.rs +++ b/tests/ui/needless_if.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(let_chains)] #![allow( clippy::blocks_in_if_conditions, diff --git a/tests/ui/needless_late_init.fixed b/tests/ui/needless_late_init.fixed index 0504bc2bd3705..9f45da04862c7 100644 --- a/tests/ui/needless_late_init.fixed +++ b/tests/ui/needless_late_init.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(let_chains)] #![allow(unused)] #![allow( diff --git a/tests/ui/needless_late_init.rs b/tests/ui/needless_late_init.rs index 7346a9ea3b50a..0dab0faad5611 100644 --- a/tests/ui/needless_late_init.rs +++ b/tests/ui/needless_late_init.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(let_chains)] #![allow(unused)] #![allow( diff --git a/tests/ui/needless_lifetimes.fixed b/tests/ui/needless_lifetimes.fixed index cde78c318ed78..d1787b35abd23 100644 --- a/tests/ui/needless_lifetimes.fixed +++ b/tests/ui/needless_lifetimes.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::needless_lifetimes)] #![allow( diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index eabfa48b4cf78..03d6f2013586c 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::needless_lifetimes)] #![allow( diff --git a/tests/ui/needless_pub_self.fixed b/tests/ui/needless_pub_self.fixed index b9eb9b1b0c14a..d9f7b92d09012 100644 --- a/tests/ui/needless_pub_self.fixed +++ b/tests/ui/needless_pub_self.fixed @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] #![warn(clippy::needless_pub_self)] diff --git a/tests/ui/needless_pub_self.rs b/tests/ui/needless_pub_self.rs index 6f231aa75d877..9f0ec76477e6e 100644 --- a/tests/ui/needless_pub_self.rs +++ b/tests/ui/needless_pub_self.rs @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] #![warn(clippy::needless_pub_self)] diff --git a/tests/ui/needless_return_with_question_mark.fixed b/tests/ui/needless_return_with_question_mark.fixed index 45370fbab9592..52d5418092148 100644 --- a/tests/ui/needless_return_with_question_mark.fixed +++ b/tests/ui/needless_return_with_question_mark.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( clippy::needless_return, clippy::no_effect, diff --git a/tests/ui/needless_return_with_question_mark.rs b/tests/ui/needless_return_with_question_mark.rs index e1f4148fc763b..d253cae4dc28e 100644 --- a/tests/ui/needless_return_with_question_mark.rs +++ b/tests/ui/needless_return_with_question_mark.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( clippy::needless_return, clippy::no_effect, diff --git a/tests/ui/option_env_unwrap.rs b/tests/ui/option_env_unwrap.rs index 61dbad939db40..f8d382340f2f4 100644 --- a/tests/ui/option_env_unwrap.rs +++ b/tests/ui/option_env_unwrap.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::option_env_unwrap)] #![allow(clippy::map_flatten)] diff --git a/tests/ui/patterns.fixed b/tests/ui/patterns.fixed index d9e2e6ab16e9e..332cba9715575 100644 --- a/tests/ui/patterns.fixed +++ b/tests/ui/patterns.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::all)] #![allow(unused)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/patterns.rs b/tests/ui/patterns.rs index a093604f037a4..45d907688e379 100644 --- a/tests/ui/patterns.rs +++ b/tests/ui/patterns.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::all)] #![allow(unused)] #![allow(clippy::uninlined_format_args)] diff --git a/tests/ui/ptr_as_ptr.fixed b/tests/ui/ptr_as_ptr.fixed index 9d9f80067c990..ca13b52ae3ba3 100644 --- a/tests/ui/ptr_as_ptr.fixed +++ b/tests/ui/ptr_as_ptr.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::ptr_as_ptr)] diff --git a/tests/ui/ptr_as_ptr.rs b/tests/ui/ptr_as_ptr.rs index 7fc4368250c3e..942c873444432 100644 --- a/tests/ui/ptr_as_ptr.rs +++ b/tests/ui/ptr_as_ptr.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::ptr_as_ptr)] diff --git a/tests/ui/ptr_cast_constness.fixed b/tests/ui/ptr_cast_constness.fixed index 74bfff8716a19..c410a660dc42f 100644 --- a/tests/ui/ptr_cast_constness.fixed +++ b/tests/ui/ptr_cast_constness.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::ptr_cast_constness)] #![allow(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast, unused)] diff --git a/tests/ui/ptr_cast_constness.rs b/tests/ui/ptr_cast_constness.rs index be8de3dcd087b..6025b857b8f4b 100644 --- a/tests/ui/ptr_cast_constness.rs +++ b/tests/ui/ptr_cast_constness.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::ptr_cast_constness)] #![allow(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast, unused)] diff --git a/tests/ui/pub_with_shorthand.fixed b/tests/ui/pub_with_shorthand.fixed index f8b8d37120ade..028209de06661 100644 --- a/tests/ui/pub_with_shorthand.fixed +++ b/tests/ui/pub_with_shorthand.fixed @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_with_shorthand)] diff --git a/tests/ui/pub_with_shorthand.rs b/tests/ui/pub_with_shorthand.rs index baaed1edd5018..8578e3e0c4347 100644 --- a/tests/ui/pub_with_shorthand.rs +++ b/tests/ui/pub_with_shorthand.rs @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_with_shorthand)] diff --git a/tests/ui/pub_without_shorthand.fixed b/tests/ui/pub_without_shorthand.fixed index 8730add27de35..715e86c176458 100644 --- a/tests/ui/pub_without_shorthand.fixed +++ b/tests/ui/pub_without_shorthand.fixed @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_without_shorthand)] diff --git a/tests/ui/pub_without_shorthand.rs b/tests/ui/pub_without_shorthand.rs index 2a0d8bce58299..ed2fd6f0f6174 100644 --- a/tests/ui/pub_without_shorthand.rs +++ b/tests/ui/pub_without_shorthand.rs @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_without_shorthand)] diff --git a/tests/ui/redundant_at_rest_pattern.fixed b/tests/ui/redundant_at_rest_pattern.fixed index 96e05fffd8d87..a7997637372e8 100644 --- a/tests/ui/redundant_at_rest_pattern.fixed +++ b/tests/ui/redundant_at_rest_pattern.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(irrefutable_let_patterns, unused)] #![warn(clippy::redundant_at_rest_pattern)] diff --git a/tests/ui/redundant_at_rest_pattern.rs b/tests/ui/redundant_at_rest_pattern.rs index c6d8ad5243df5..f103d1f1a1794 100644 --- a/tests/ui/redundant_at_rest_pattern.rs +++ b/tests/ui/redundant_at_rest_pattern.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(irrefutable_let_patterns, unused)] #![warn(clippy::redundant_at_rest_pattern)] diff --git a/tests/ui/redundant_guards.fixed b/tests/ui/redundant_guards.fixed index a3e8bd0890771..9a1ec3a4d36a6 100644 --- a/tests/ui/redundant_guards.fixed +++ b/tests/ui/redundant_guards.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(if_let_guard)] #![allow(clippy::no_effect, unused)] #![warn(clippy::redundant_guards)] diff --git a/tests/ui/redundant_guards.rs b/tests/ui/redundant_guards.rs index dd16a15f5315d..e2e0ee816c51b 100644 --- a/tests/ui/redundant_guards.rs +++ b/tests/ui/redundant_guards.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(if_let_guard)] #![allow(clippy::no_effect, unused)] #![warn(clippy::redundant_guards)] diff --git a/tests/ui/redundant_locals.rs b/tests/ui/redundant_locals.rs index 80af38f47b86d..c5d93e4365d90 100644 --- a/tests/ui/redundant_locals.rs +++ b/tests/ui/redundant_locals.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused, clippy::no_effect, clippy::needless_pass_by_ref_mut)] #![warn(clippy::redundant_locals)] diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs index 1b40a43d01962..258dba9dd831e 100644 --- a/tests/ui/shadow.rs +++ b/tests/ui/shadow.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)] #![allow( diff --git a/tests/ui/single_call_fn.rs b/tests/ui/single_call_fn.rs index 76e175014b877..d6493f234133d 100644 --- a/tests/ui/single_call_fn.rs +++ b/tests/ui/single_call_fn.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::redundant_closure_call, unused)] #![warn(clippy::single_call_fn)] #![no_main] diff --git a/tests/ui/single_match_else.fixed b/tests/ui/single_match_else.fixed index e23c78aa484ff..f3b1de3b44f90 100644 --- a/tests/ui/single_match_else.fixed +++ b/tests/ui/single_match_else.fixed @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::single_match_else)] #![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] extern crate proc_macros; diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs index a33fb441668d4..ddee2e42ec2a5 100644 --- a/tests/ui/single_match_else.rs +++ b/tests/ui/single_match_else.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::single_match_else)] #![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] 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 bf4e90837b29b..7887cfc61750f 100644 --- a/tests/ui/single_range_in_vec_init.rs +++ b/tests/ui/single_range_in_vec_init.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs //@no-rustfix: overlapping suggestions #![allow(clippy::no_effect, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] diff --git a/tests/ui/string_add.rs b/tests/ui/string_add.rs index 0baeba95bf7b7..c535f2ebbfcbe 100644 --- a/tests/ui/string_add.rs +++ b/tests/ui/string_add.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs //@no-rustfix extern crate proc_macros; use proc_macros::external; diff --git a/tests/ui/string_lit_chars_any.fixed b/tests/ui/string_lit_chars_any.fixed index b9e91ccd1cf53..03e20c16ee63c 100644 --- a/tests/ui/string_lit_chars_any.fixed +++ b/tests/ui/string_lit_chars_any.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::string_lit_chars_any)] diff --git a/tests/ui/string_lit_chars_any.rs b/tests/ui/string_lit_chars_any.rs index d0ce6780da3e5..12e6ffb6a9c47 100644 --- a/tests/ui/string_lit_chars_any.rs +++ b/tests/ui/string_lit_chars_any.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::string_lit_chars_any)] diff --git a/tests/ui/suspicious_else_formatting.rs b/tests/ui/suspicious_else_formatting.rs index 0473ccdc3f636..c0856427eaef7 100644 --- a/tests/ui/suspicious_else_formatting.rs +++ b/tests/ui/suspicious_else_formatting.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_suspicious_else_formatting.rs:proc-macro +//@aux-build:proc_macro_suspicious_else_formatting.rs #![warn(clippy::suspicious_else_formatting)] #![allow( diff --git a/tests/ui/toplevel_ref_arg.fixed b/tests/ui/toplevel_ref_arg.fixed index ccceb4684a122..ff5cd7abbb69e 100644 --- a/tests/ui/toplevel_ref_arg.fixed +++ b/tests/ui/toplevel_ref_arg.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::toplevel_ref_arg)] #![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)] diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs index 14c476199b33d..ab79b8959605f 100644 --- a/tests/ui/toplevel_ref_arg.rs +++ b/tests/ui/toplevel_ref_arg.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::toplevel_ref_arg)] #![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)] diff --git a/tests/ui/toplevel_ref_arg_non_rustfix.rs b/tests/ui/toplevel_ref_arg_non_rustfix.rs index 464762af82536..8aaf47b1bd0c5 100644 --- a/tests/ui/toplevel_ref_arg_non_rustfix.rs +++ b/tests/ui/toplevel_ref_arg_non_rustfix.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::toplevel_ref_arg)] #![allow(unused)] diff --git a/tests/ui/try_err.fixed b/tests/ui/try_err.fixed index 060ef7b2a6d4c..aae4f8ac47f82 100644 --- a/tests/ui/try_err.fixed +++ b/tests/ui/try_err.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![deny(clippy::try_err)] #![allow( diff --git a/tests/ui/try_err.rs b/tests/ui/try_err.rs index e3a58c91b2a3b..927eccf2d54c5 100644 --- a/tests/ui/try_err.rs +++ b/tests/ui/try_err.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![deny(clippy::try_err)] #![allow( diff --git a/tests/ui/tuple_array_conversions.rs b/tests/ui/tuple_array_conversions.rs index 569415acbceee..ed21ee668e3a0 100644 --- a/tests/ui/tuple_array_conversions.rs +++ b/tests/ui/tuple_array_conversions.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::no_effect, clippy::useless_vec, unused)] #![warn(clippy::tuple_array_conversions)] diff --git a/tests/ui/undocumented_unsafe_blocks.rs b/tests/ui/undocumented_unsafe_blocks.rs index a9cc429543563..f4e7f1943ae6d 100644 --- a/tests/ui/undocumented_unsafe_blocks.rs +++ b/tests/ui/undocumented_unsafe_blocks.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_unsafe.rs:proc-macro +//@aux-build:proc_macro_unsafe.rs #![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)] #![allow(clippy::let_unit_value, clippy::missing_safety_doc)] diff --git a/tests/ui/uninlined_format_args.fixed b/tests/ui/uninlined_format_args.fixed index 91ad964565cdd..3f5b0e52ece0a 100644 --- a/tests/ui/uninlined_format_args.fixed +++ b/tests/ui/uninlined_format_args.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::uninlined_format_args)] #![allow(named_arguments_used_positionally, unused)] diff --git a/tests/ui/uninlined_format_args.rs b/tests/ui/uninlined_format_args.rs index 0fc4a93ce73fa..b311aa4912cd7 100644 --- a/tests/ui/uninlined_format_args.rs +++ b/tests/ui/uninlined_format_args.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::uninlined_format_args)] #![allow(named_arguments_used_positionally, unused)] diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index e834bb4bd7d7d..2e1390621a6cd 100644 --- a/tests/ui/unit_arg.rs +++ b/tests/ui/unit_arg.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs //@no-rustfix: overlapping suggestions #![warn(clippy::unit_arg)] #![allow(unused_must_use, unused_variables)] diff --git a/tests/ui/unnecessary_lazy_eval.fixed b/tests/ui/unnecessary_lazy_eval.fixed index 165406090a71e..304e7b7fd7f6d 100644 --- a/tests/ui/unnecessary_lazy_eval.fixed +++ b/tests/ui/unnecessary_lazy_eval.fixed @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::unnecessary_lazy_evaluations)] #![allow(clippy::redundant_closure)] #![allow(clippy::bind_instead_of_map)] diff --git a/tests/ui/unnecessary_lazy_eval.rs b/tests/ui/unnecessary_lazy_eval.rs index 68af4200bbb7a..ddfa6bb3ef615 100644 --- a/tests/ui/unnecessary_lazy_eval.rs +++ b/tests/ui/unnecessary_lazy_eval.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::unnecessary_lazy_evaluations)] #![allow(clippy::redundant_closure)] #![allow(clippy::bind_instead_of_map)] diff --git a/tests/ui/unnecessary_unsafety_doc.rs b/tests/ui/unnecessary_unsafety_doc.rs index 2d55dc664a32d..373b18470f695 100644 --- a/tests/ui/unnecessary_unsafety_doc.rs +++ b/tests/ui/unnecessary_unsafety_doc.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::let_unit_value)] #![warn(clippy::unnecessary_safety_doc)] diff --git a/tests/ui/unneeded_field_pattern.rs b/tests/ui/unneeded_field_pattern.rs index 48ae1cf66405e..0dc21f4ce945d 100644 --- a/tests/ui/unneeded_field_pattern.rs +++ b/tests/ui/unneeded_field_pattern.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::unneeded_field_pattern)] #![allow(dead_code, unused)] diff --git a/tests/ui/unneeded_wildcard_pattern.fixed b/tests/ui/unneeded_wildcard_pattern.fixed index b37d0ddb88d77..cbf91ed4910ac 100644 --- a/tests/ui/unneeded_wildcard_pattern.fixed +++ b/tests/ui/unneeded_wildcard_pattern.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(stmt_expr_attributes)] #![deny(clippy::unneeded_wildcard_pattern)] #![allow(clippy::needless_if)] diff --git a/tests/ui/unneeded_wildcard_pattern.rs b/tests/ui/unneeded_wildcard_pattern.rs index ee3f9bae5cc58..10df2b93d5e07 100644 --- a/tests/ui/unneeded_wildcard_pattern.rs +++ b/tests/ui/unneeded_wildcard_pattern.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(stmt_expr_attributes)] #![deny(clippy::unneeded_wildcard_pattern)] #![allow(clippy::needless_if)] diff --git a/tests/ui/unseparated_prefix_literals.fixed b/tests/ui/unseparated_prefix_literals.fixed index 2f275c62bef3c..93f7f747b7cd5 100644 --- a/tests/ui/unseparated_prefix_literals.fixed +++ b/tests/ui/unseparated_prefix_literals.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::unseparated_literal_suffix)] #![allow(dead_code)] diff --git a/tests/ui/unseparated_prefix_literals.rs b/tests/ui/unseparated_prefix_literals.rs index f55160a1fc078..c960ff6b5dcce 100644 --- a/tests/ui/unseparated_prefix_literals.rs +++ b/tests/ui/unseparated_prefix_literals.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::unseparated_literal_suffix)] #![allow(dead_code)] diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index 6427f955895aa..787dd3ec7e680 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::use_self)] #![allow(dead_code, unreachable_code)] diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index ad39256f139f9..39e182faea677 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::use_self)] #![allow(dead_code, unreachable_code)] diff --git a/tests/ui/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs index 879e2e24ab341..c672eff1c2710 100644 --- a/tests/ui/used_underscore_binding.rs +++ b/tests/ui/used_underscore_binding.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![feature(rustc_private)] #![warn(clippy::all)] #![warn(clippy::used_underscore_binding)] diff --git a/tests/ui/useless_attribute.fixed b/tests/ui/useless_attribute.fixed index 475f3b34959e3..98a2bed0e81b5 100644 --- a/tests/ui/useless_attribute.fixed +++ b/tests/ui/useless_attribute.fixed @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![allow(unused)] #![warn(clippy::useless_attribute)] diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index 66bfcef51ef24..c5e324717b112 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![allow(unused)] #![warn(clippy::useless_attribute)] From 1088507a30e3f1ca263fc653c1b66a50d005e32d Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 7 Aug 2023 09:45:05 +0000 Subject: [PATCH 10/79] Canonicalize paths in a single location --- tests/compile-test.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 7e283bf4a8b72..af2e87715b45c 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -110,6 +110,12 @@ mod test_utils; // whether to run internal tests or not const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal"); +fn canonicalize(path: impl AsRef) -> PathBuf { + let path = path.as_ref(); + fs::create_dir_all(path).unwrap(); + fs::canonicalize(path).unwrap_or_else(|err| panic!("{} cannot be canonicalized: {err}", path.display())) +} + fn base_config(test_dir: &str) -> (compiletest::Config, Args) { let args = Args::test(); let mut config = compiletest::Config { @@ -124,10 +130,11 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) { OutputConflictHandling::Error("cargo uibless".into()) }, target: None, - out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap_or("target".into())) - .join("ui_test") - .canonicalize() - .unwrap(), + out_dir: canonicalize( + std::env::var_os("CARGO_TARGET_DIR") + .map_or_else(|| std::env::current_dir().unwrap().join("target"), PathBuf::from), + ) + .join("ui_test"), ..compiletest::Config::rustc(Path::new("tests").join(test_dir)) }; let current_exe_path = env::current_exe().unwrap(); @@ -178,7 +185,7 @@ fn run_ui() { let (config, args) = base_config("ui"); //config.rustfix_coverage = true; // use tests/clippy.toml - let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap()); + let _g = VarGuard::set("CARGO_MANIFEST_DIR", canonicalize("tests")); let _threads = VarGuard::set( "RUST_TEST_THREADS", // if RUST_TEST_THREADS is set, adhere to it, otherwise override it @@ -238,8 +245,7 @@ fn run_ui_toml() { config.stderr_filter( ®ex::escape( - &fs::canonicalize("tests") - .unwrap() + &canonicalize("tests") .parent() .unwrap() .display() @@ -298,8 +304,7 @@ fn run_ui_cargo() { config.stderr_filter( ®ex::escape( - &fs::canonicalize("tests") - .unwrap() + &canonicalize("tests") .parent() .unwrap() .display() @@ -318,7 +323,13 @@ fn run_ui_cargo() { |path, _args| test_filter(path) && path.ends_with("Cargo.toml"), |config, path| { let mut config = config.clone(); - config.out_dir = PathBuf::from("target/ui_test_cargo/").join(path.parent().unwrap()); + config.out_dir = canonicalize( + std::env::current_dir() + .unwrap() + .join("target") + .join("ui_test_cargo/") + .join(path.parent().unwrap()), + ); Some(config) }, if quiet { From 43f04e12add4dc15bbbb215467781ee3b2b228b8 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 8 Aug 2023 08:40:31 +0000 Subject: [PATCH 11/79] Bump ui_test crate --- Cargo.toml | 2 +- tests/compile-test.rs | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dcdd2161d7540..6730888f58a5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ tempfile = { version = "3.2", optional = true } termize = "0.1" [dev-dependencies] -ui_test = "0.13" +ui_test = "0.15" tester = "0.9" regex = "1.5" toml = "0.7.3" diff --git a/tests/compile-test.rs b/tests/compile-test.rs index af2e87715b45c..fd7839ba7f94f 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -201,9 +201,10 @@ fn run_ui() { let quiet = args.quiet; compiletest::run_tests_generic( - config, + vec![config], + std::thread::available_parallelism().unwrap(), args, - move |path, args| compiletest::default_file_filter(path, args) && test_filter(path), + move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path), compiletest::default_per_file_config, if quiet { status_emitter::Text::quiet() @@ -227,9 +228,10 @@ fn run_internal_tests() { let quiet = args.quiet; compiletest::run_tests_generic( - config, + vec![config], + std::thread::available_parallelism().unwrap(), args, - move |path, args| compiletest::default_file_filter(path, args) && test_filter(path), + move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path), compiletest::default_per_file_config, if quiet { status_emitter::Text::quiet() @@ -259,16 +261,15 @@ fn run_ui_toml() { let quiet = args.quiet; ui_test::run_tests_generic( - config, + vec![config], + std::thread::available_parallelism().unwrap(), args, - |path, args| compiletest::default_file_filter(path, args) && test_filter(path), - |config, path| { - let mut config = config.clone(); + |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path), + |config, path, _file_contents| { config .program .envs .push(("CLIPPY_CONF_DIR".into(), Some(path.parent().unwrap().into()))); - Some(config) }, if quiet { status_emitter::Text::quiet() @@ -318,11 +319,11 @@ fn run_ui_cargo() { let quiet = args.quiet; ui_test::run_tests_generic( - config, + vec![config], + std::thread::available_parallelism().unwrap(), args, - |path, _args| test_filter(path) && path.ends_with("Cargo.toml"), - |config, path| { - let mut config = config.clone(); + |path, _args, _config| test_filter(path) && path.ends_with("Cargo.toml"), + |config, path, _file_contents| { config.out_dir = canonicalize( std::env::current_dir() .unwrap() @@ -330,7 +331,6 @@ fn run_ui_cargo() { .join("ui_test_cargo/") .join(path.parent().unwrap()), ); - Some(config) }, if quiet { status_emitter::Text::quiet() From 665a61938dea5735a0ec2ce5fbc76fbba0fae679 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 10 Aug 2023 12:17:46 +0000 Subject: [PATCH 12/79] Bump ui_test --- Cargo.toml | 2 +- tests/compile-test.rs | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6730888f58a5c..1ab6d7e118f1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ tempfile = { version = "3.2", optional = true } termize = "0.1" [dev-dependencies] -ui_test = "0.15" +ui_test = "0.17.0" tester = "0.9" regex = "1.5" toml = "0.7.3" diff --git a/tests/compile-test.rs b/tests/compile-test.rs index fd7839ba7f94f..cb1c0941a30f1 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -117,7 +117,7 @@ fn canonicalize(path: impl AsRef) -> PathBuf { } fn base_config(test_dir: &str) -> (compiletest::Config, Args) { - let args = Args::test(); + let args = Args::test().unwrap(); let mut config = compiletest::Config { mode: TestMode::Yolo { rustfix: true }, stderr_filters: vec![], @@ -202,7 +202,6 @@ fn run_ui() { compiletest::run_tests_generic( vec![config], - std::thread::available_parallelism().unwrap(), args, move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path), compiletest::default_per_file_config, @@ -229,7 +228,6 @@ fn run_internal_tests() { compiletest::run_tests_generic( vec![config], - std::thread::available_parallelism().unwrap(), args, move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path), compiletest::default_per_file_config, @@ -262,7 +260,6 @@ fn run_ui_toml() { ui_test::run_tests_generic( vec![config], - std::thread::available_parallelism().unwrap(), args, |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path), |config, path, _file_contents| { @@ -320,7 +317,6 @@ fn run_ui_cargo() { ui_test::run_tests_generic( vec![config], - std::thread::available_parallelism().unwrap(), args, |path, _args, _config| test_filter(path) && path.ends_with("Cargo.toml"), |config, path, _file_contents| { From a7af8bc6ec032f54e3dbcd2a91469c34a6fef678 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 11 Aug 2023 15:22:06 +0000 Subject: [PATCH 13/79] Fix SPEEDTEST instructions --- book/src/development/speedtest.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/book/src/development/speedtest.md b/book/src/development/speedtest.md index 0db718e6ad674..4ea1c8e5c9c0a 100644 --- a/book/src/development/speedtest.md +++ b/book/src/development/speedtest.md @@ -9,16 +9,12 @@ accessed by the `SPEEDTEST` (and `SPEEDTEST_*`) environment variables. To do a simple speed test of a lint (e.g. `allow_attributes`), use this command. ```sh -$ SPEEDTEST=ui TESTNAME="allow_attributes" cargo uitest -- --nocapture +$ SPEEDTEST=ui TESTNAME="allow_attributes" cargo uitest ``` This will test all `ui` tests (`SPEEDTEST=ui`) whose names start with `allow_attributes`. By default, `SPEEDTEST` will iterate your test 1000 times. But you can change this with `SPEEDTEST_ITERATIONS`. ```sh -$ SPEEDTEST=toml SPEEDTEST_ITERATIONS=100 TESTNAME="semicolon_block" cargo uitest -- --nocapture +$ SPEEDTEST=toml SPEEDTEST_ITERATIONS=100 TESTNAME="semicolon_block" cargo uitest ``` - -> **WARNING**: Be sure to use `-- --nocapture` at the end of the command to see the average test time. If you don't -> use `-- --nocapture` (e.g. `SPEEDTEST=ui` `TESTNAME="let_underscore_untyped" cargo uitest -- --nocapture`), this -> will not show up. From cd8f12dd369262a167d79d19ee775d4bcb8b8a81 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 11 Aug 2023 15:22:23 +0000 Subject: [PATCH 14/79] Show correct measurements in SPEEDTEST --- tests/compile-test.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index e46f8bf6fabdf..78cb076ebca5f 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -349,7 +349,11 @@ fn main() { f(); sum += start.elapsed().as_millis(); } - println!("average {} time: {} millis.", speedtest.to_uppercase(), sum / 1000); + println!( + "average {} time: {} millis.", + speedtest.to_uppercase(), + sum / u128::from(iterations) + ); } else { run_ui(); run_ui_toml(); From 7a06d7ec51706222753048c6741962f60b7f14c5 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 1 Aug 2023 19:59:34 +0200 Subject: [PATCH 15/79] [new_without_default]: lifetimes are included in output The comment was likely obsolete. --- tests/ui/new_without_default.rs | 1 - tests/ui/new_without_default.stderr | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 7803418cb047d..7dbfa002d3fb7 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -84,7 +84,6 @@ impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { unimplemented!() } - // FIXME: that suggestion is missing lifetimes } struct Private; diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 583dd327d6a5d..7641035d2a6a5 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -51,7 +51,7 @@ LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> $DIR/new_without_default.rs:177:5 + --> $DIR/new_without_default.rs:176:5 | LL | / pub fn new() -> Self { LL | | NewNotEqualToDerive { foo: 1 } @@ -68,7 +68,7 @@ LL + } | error: you should consider adding a `Default` implementation for `FooGenerics` - --> $DIR/new_without_default.rs:185:5 + --> $DIR/new_without_default.rs:184:5 | LL | / pub fn new() -> Self { LL | | Self(Default::default()) @@ -85,7 +85,7 @@ LL + } | error: you should consider adding a `Default` implementation for `BarGenerics` - --> $DIR/new_without_default.rs:192:5 + --> $DIR/new_without_default.rs:191:5 | LL | / pub fn new() -> Self { LL | | Self(Default::default()) @@ -102,7 +102,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo` - --> $DIR/new_without_default.rs:203:9 + --> $DIR/new_without_default.rs:202:9 | LL | / pub fn new() -> Self { LL | | todo!() From 621e76d2528e0872926305686041f6a935028db8 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 31 Jul 2023 21:57:31 +0200 Subject: [PATCH 16/79] [new_without_default]: include `where` clauses in suggestion Fix #11267 --- clippy_lints/src/new_without_default.rs | 19 ++++++++++++++++--- tests/ui/new_without_default.rs | 18 ++++++++++++++++++ tests/ui/new_without_default.stderr | 22 +++++++++++++++++++++- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index cf7cd671dcabe..6900502e8e11e 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -130,6 +130,11 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { } let generics_sugg = snippet(cx, generics.span, ""); + let where_clause_sugg = if generics.has_where_clause_predicates { + format!("\n{}\n", snippet(cx, generics.where_clause_span, "")) + } else { + String::new() + }; let self_ty_fmt = self_ty.to_string(); let self_type_snip = snippet(cx, impl_self_ty.span, &self_ty_fmt); span_lint_hir_and_then( @@ -145,7 +150,11 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { cx, item.span, "try adding this", - &create_new_without_default_suggest_msg(&self_type_snip, &generics_sugg), + &create_new_without_default_suggest_msg( + &self_type_snip, + &generics_sugg, + &where_clause_sugg + ), Applicability::MaybeIncorrect, ); }, @@ -159,10 +168,14 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { } } -fn create_new_without_default_suggest_msg(self_type_snip: &str, generics_sugg: &str) -> String { +fn create_new_without_default_suggest_msg( + self_type_snip: &str, + generics_sugg: &str, + where_clause_sugg: &str, +) -> String { #[rustfmt::skip] format!( -"impl{generics_sugg} Default for {self_type_snip} {{ +"impl{generics_sugg} Default for {self_type_snip}{where_clause_sugg} {{ fn default() -> Self {{ Self::new() }} diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 7dbfa002d3fb7..bbd7a51d6b984 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -230,3 +230,21 @@ impl IgnoreLifetimeNew { Self } } + +// From issue #11267 + +pub struct MyStruct +where + K: std::hash::Hash + Eq + PartialEq, +{ + _kv: Option<(K, V)>, +} + +impl MyStruct +where + K: std::hash::Hash + Eq + PartialEq, +{ + pub fn new() -> Self { + Self { _kv: None } + } +} diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 7641035d2a6a5..61973abcde88c 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -120,5 +120,25 @@ LL + LL ~ impl Foo { | -error: aborting due to 7 previous errors +error: you should consider adding a `Default` implementation for `MyStruct` + --> $DIR/new_without_default.rs:247:5 + | +LL | / pub fn new() -> Self { +LL | | Self { _kv: None } +LL | | } + | |_____^ + | +help: try adding this + | +LL + impl Default for MyStruct +LL + where +LL + K: std::hash::Hash + Eq + PartialEq, +LL + { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } + | + +error: aborting due to 8 previous errors From f9b22e7b84df2bfef723fbb456349d1d5948d611 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 1 Aug 2023 20:28:10 +0200 Subject: [PATCH 17/79] [new_without_default]: make the suggestion machine-applicable Now that generics and lifetimes are output as expected, the lint should be applicable. --- clippy_lints/src/new_without_default.rs | 2 +- tests/ui/new_without_default.fixed | 28 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 6900502e8e11e..f7f9dccfbceb4 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { &generics_sugg, &where_clause_sugg ), - Applicability::MaybeIncorrect, + Applicability::MachineApplicable, ); }, ); diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed index 0c4283ad0c122..56359a4cbc3cf 100644 --- a/tests/ui/new_without_default.fixed +++ b/tests/ui/new_without_default.fixed @@ -102,7 +102,6 @@ impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { unimplemented!() } - // FIXME: that suggestion is missing lifetimes } struct Private; @@ -273,3 +272,30 @@ impl IgnoreLifetimeNew { Self } } + +// From issue #11267 + +pub struct MyStruct +where + K: std::hash::Hash + Eq + PartialEq, +{ + _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, +{ + pub fn new() -> Self { + Self { _kv: None } + } +} From d5dbee4aa0696374dcb99f7e13fa46721f759a8b Mon Sep 17 00:00:00 2001 From: unvalley Date: Sat, 12 Aug 2023 18:20:44 +0900 Subject: [PATCH 18/79] feat: update manual_retain to lint binary_heap_retain refactor: rename variable chore: reorder test: update naming for msrv --- clippy_lints/src/manual_retain.rs | 6 ++- clippy_utils/src/msrvs.rs | 2 +- clippy_utils/src/paths.rs | 1 + tests/ui/manual_retain.fixed | 39 ++++++++++++------ tests/ui/manual_retain.rs | 39 ++++++++++++------ tests/ui/manual_retain.stderr | 68 +++++++++++++++++++++---------- 6 files changed, 106 insertions(+), 49 deletions(-) diff --git a/clippy_lints/src/manual_retain.rs b/clippy_lints/src/manual_retain.rs index 5259066eb713c..1a69a48c582b0 100644 --- a/clippy_lints/src/manual_retain.rs +++ b/clippy_lints/src/manual_retain.rs @@ -12,13 +12,15 @@ use rustc_semver::RustcVersion; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::symbol::sym; -const ACCEPTABLE_METHODS: [&[&str]; 4] = [ +const ACCEPTABLE_METHODS: [&[&str]; 5] = [ + &paths::BINARYHEAP_ITER, &paths::HASHSET_ITER, &paths::BTREESET_ITER, &paths::SLICE_INTO, &paths::VEC_DEQUE_ITER, ]; -const ACCEPTABLE_TYPES: [(rustc_span::Symbol, Option); 6] = [ +const ACCEPTABLE_TYPES: [(rustc_span::Symbol, Option); 7] = [ + (sym::BinaryHeap, Some(msrvs::BINARY_HEAP_RETAIN)), (sym::BTreeSet, Some(msrvs::BTREE_SET_RETAIN)), (sym::BTreeMap, Some(msrvs::BTREE_MAP_RETAIN)), (sym::HashSet, Some(msrvs::HASH_SET_RETAIN)), diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index 3637476c40872..0faff05eb2319 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -20,7 +20,7 @@ macro_rules! msrv_aliases { // names may refer to stabilized feature flags or library items msrv_aliases! { 1,71,0 { TUPLE_ARRAY_CONVERSIONS } - 1,70,0 { OPTION_IS_SOME_AND } + 1,70,0 { OPTION_IS_SOME_AND, BINARY_HEAP_RETAIN } 1,68,0 { PATH_MAIN_SEPARATOR_STR } 1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS } 1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE } diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 914ea85ac2809..e72d063cfd9b4 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -15,6 +15,7 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [ ]; #[cfg(feature = "internal")] pub const DIAGNOSTIC_BUILDER: [&str; 3] = ["rustc_errors", "diagnostic_builder", "DiagnosticBuilder"]; +pub const BINARYHEAP_ITER: [&str; 5] = ["alloc", "collections", "binary_heap", "BinaryHeap", "iter"]; pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"]; pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"]; pub const BTREESET_ITER: [&str; 6] = ["alloc", "collections", "btree", "set", "BTreeSet", "iter"]; diff --git a/tests/ui/manual_retain.fixed b/tests/ui/manual_retain.fixed index 3afa2da6ab1db..c856a4dc67afe 100644 --- a/tests/ui/manual_retain.fixed +++ b/tests/ui/manual_retain.fixed @@ -17,22 +17,31 @@ fn main() { } fn binary_heap_retain() { - // NOTE: Do not lint now, because binary_heap_retain is nightly API. - // And we need to add a test case for msrv if we update this implementation. - // https://github.com/rust-lang/rust/issues/71503 - let mut heap = BinaryHeap::from([1, 2, 3]); - heap = heap.into_iter().filter(|x| x % 2 == 0).collect(); - heap = heap.iter().filter(|&x| x % 2 == 0).copied().collect(); - heap = heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); + let mut binary_heap = BinaryHeap::from([1, 2, 3]); + // Do lint. + binary_heap.retain(|x| x % 2 == 0); + binary_heap.retain(|x| x % 2 == 0); + binary_heap.retain(|x| x % 2 == 0); // Do not lint, because type conversion is performed - heap = heap.into_iter().filter(|x| x % 2 == 0).collect::>(); - heap = heap.iter().filter(|&x| x % 2 == 0).copied().collect::>(); - heap = heap.iter().filter(|&x| x % 2 == 0).cloned().collect::>(); + binary_heap = binary_heap + .into_iter() + .filter(|x| x % 2 == 0) + .collect::>(); + binary_heap = binary_heap + .iter() + .filter(|&x| x % 2 == 0) + .copied() + .collect::>(); + binary_heap = binary_heap + .iter() + .filter(|&x| x % 2 == 0) + .cloned() + .collect::>(); // Do not lint, because this expression is not assign. - let mut bar: BinaryHeap = heap.iter().filter(|&x| x % 2 == 0).copied().collect(); - let mut foobar: BinaryHeap = heap.into_iter().filter(|x| x % 2 == 0).collect(); + let mut bar: BinaryHeap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); + let mut foobar: BinaryHeap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); // Do not lint, because it is an assignment to a different variable. bar = foobar.iter().filter(|&x| x % 2 == 0).copied().collect(); @@ -209,6 +218,12 @@ fn vec_deque_retain() { bar = foobar.into_iter().filter(|x| x % 2 == 0).collect(); } +#[clippy::msrv = "1.70"] +fn _msrv_170() { + let mut binary_heap = BinaryHeap::from([1, 2, 3]); + binary_heap.retain(|x| x % 2 == 0); +} + #[clippy::msrv = "1.52"] fn _msrv_153() { let mut btree_map: BTreeMap = (0..8).map(|x| (x, x * 10)).collect(); diff --git a/tests/ui/manual_retain.rs b/tests/ui/manual_retain.rs index 43460da5eb0a8..7f92eede94e5b 100644 --- a/tests/ui/manual_retain.rs +++ b/tests/ui/manual_retain.rs @@ -17,22 +17,31 @@ fn main() { } fn binary_heap_retain() { - // NOTE: Do not lint now, because binary_heap_retain is nightly API. - // And we need to add a test case for msrv if we update this implementation. - // https://github.com/rust-lang/rust/issues/71503 - let mut heap = BinaryHeap::from([1, 2, 3]); - heap = heap.into_iter().filter(|x| x % 2 == 0).collect(); - heap = heap.iter().filter(|&x| x % 2 == 0).copied().collect(); - heap = heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); + let mut binary_heap = BinaryHeap::from([1, 2, 3]); + // Do lint. + binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); + binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); + binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); // Do not lint, because type conversion is performed - heap = heap.into_iter().filter(|x| x % 2 == 0).collect::>(); - heap = heap.iter().filter(|&x| x % 2 == 0).copied().collect::>(); - heap = heap.iter().filter(|&x| x % 2 == 0).cloned().collect::>(); + binary_heap = binary_heap + .into_iter() + .filter(|x| x % 2 == 0) + .collect::>(); + binary_heap = binary_heap + .iter() + .filter(|&x| x % 2 == 0) + .copied() + .collect::>(); + binary_heap = binary_heap + .iter() + .filter(|&x| x % 2 == 0) + .cloned() + .collect::>(); // Do not lint, because this expression is not assign. - let mut bar: BinaryHeap = heap.iter().filter(|&x| x % 2 == 0).copied().collect(); - let mut foobar: BinaryHeap = heap.into_iter().filter(|x| x % 2 == 0).collect(); + let mut bar: BinaryHeap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); + let mut foobar: BinaryHeap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); // Do not lint, because it is an assignment to a different variable. bar = foobar.iter().filter(|&x| x % 2 == 0).copied().collect(); @@ -215,6 +224,12 @@ fn vec_deque_retain() { bar = foobar.into_iter().filter(|x| x % 2 == 0).collect(); } +#[clippy::msrv = "1.70"] +fn _msrv_170() { + let mut binary_heap = BinaryHeap::from([1, 2, 3]); + binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); +} + #[clippy::msrv = "1.52"] fn _msrv_153() { let mut btree_map: BTreeMap = (0..8).map(|x| (x, x * 10)).collect(); diff --git a/tests/ui/manual_retain.stderr b/tests/ui/manual_retain.stderr index 8b5f9f3a30ea5..6b8ec4d68b24f 100644 --- a/tests/ui/manual_retain.stderr +++ b/tests/ui/manual_retain.stderr @@ -1,19 +1,37 @@ error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:45:5 + --> $DIR/manual_retain.rs:22:5 | -LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|k, _| k % 2 == 0)` +LL | binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` | = note: `-D clippy::manual-retain` implied by `-D warnings` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:46:5 + --> $DIR/manual_retain.rs:23:5 + | +LL | binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` + +error: this expression can be written more simply using `.retain()` + --> $DIR/manual_retain.rs:24:5 + | +LL | binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` + +error: this expression can be written more simply using `.retain()` + --> $DIR/manual_retain.rs:54:5 + | +LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|k, _| k % 2 == 0)` + +error: this expression can be written more simply using `.retain()` + --> $DIR/manual_retain.rs:55:5 | LL | btree_map = btree_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|_, &mut v| v % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:47:5 + --> $DIR/manual_retain.rs:56:5 | LL | / btree_map = btree_map LL | | .into_iter() @@ -22,37 +40,37 @@ LL | | .collect(); | |__________________^ help: consider calling `.retain()` instead: `btree_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:69:5 + --> $DIR/manual_retain.rs:78:5 | LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:70:5 + --> $DIR/manual_retain.rs:79:5 | LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:71:5 + --> $DIR/manual_retain.rs:80:5 | LL | btree_set = btree_set.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:101:5 + --> $DIR/manual_retain.rs:110:5 | LL | hash_map = hash_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|k, _| k % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:102:5 + --> $DIR/manual_retain.rs:111:5 | LL | hash_map = hash_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|_, &mut v| v % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:103:5 + --> $DIR/manual_retain.rs:112:5 | LL | / hash_map = hash_map LL | | .into_iter() @@ -61,64 +79,70 @@ LL | | .collect(); | |__________________^ help: consider calling `.retain()` instead: `hash_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:124:5 + --> $DIR/manual_retain.rs:133:5 | LL | hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:125:5 + --> $DIR/manual_retain.rs:134:5 | LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:126:5 + --> $DIR/manual_retain.rs:135:5 | LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:155:5 + --> $DIR/manual_retain.rs:164:5 | LL | s = s.chars().filter(|&c| c != 'o').to_owned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `s.retain(|c| c != 'o')` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:167:5 + --> $DIR/manual_retain.rs:176:5 | LL | vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:168:5 + --> $DIR/manual_retain.rs:177:5 | LL | vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:169:5 + --> $DIR/manual_retain.rs:178:5 | LL | vec = vec.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:191:5 + --> $DIR/manual_retain.rs:200:5 | LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:192:5 + --> $DIR/manual_retain.rs:201:5 | LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:193:5 + --> $DIR/manual_retain.rs:202:5 | LL | vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` -error: aborting due to 19 previous errors +error: this expression can be written more simply using `.retain()` + --> $DIR/manual_retain.rs:230:5 + | +LL | binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` + +error: aborting due to 23 previous errors From 3ac06a12a5c4f17f17d03594f234832010a3b861 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sun, 13 Aug 2023 13:16:38 +0000 Subject: [PATCH 19/79] Do not bless by default in ui tests --- .cargo/config.toml | 6 ++--- tests/compile-test.rs | 62 ++++++++++++++++--------------------------- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 40e841081260f..48a63e4856815 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,7 +1,7 @@ [alias] -uitest = "test --test compile-test -- --check" -uibless = "test --test compile-test" -bless = "test" +uitest = "test --test compile-test" +uibless = "test --test compile-test -- -- --bless" +bless = "test -- -- --bless" dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --" lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- " collect-metadata = "test --test dogfood --features internal -- run_metadata_collection_lint --ignored" diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 4e67cb3a74b88..b8731cfe78c81 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -1,4 +1,3 @@ -#![feature(test)] // compiletest_rs requires this attribute #![feature(lazy_cell)] #![feature(is_sorted)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] @@ -117,24 +116,32 @@ fn canonicalize(path: impl AsRef) -> PathBuf { } fn base_config(test_dir: &str) -> (compiletest::Config, Args) { - let args = Args::test().unwrap(); + let bless = var_os("RUSTC_BLESS").is_some_and(|v| v != "0") || env::args().any(|arg| arg == "--bless"); + + let args = Args { + filters: env::var("TESTNAME") + .map(|filters| filters.split(',').map(str::to_string).collect()) + .unwrap_or_default(), + quiet: false, + check: !bless, + threads: match std::env::var_os("RUST_TEST_THREADS") { + Some(n) => n.to_str().unwrap().parse().unwrap(), + None => std::thread::available_parallelism().unwrap(), + }, + skip: Vec::new(), + }; + let mut config = compiletest::Config { mode: TestMode::Yolo { rustfix: true }, stderr_filters: vec![], stdout_filters: vec![], - output_conflict_handling: if var_os("GITHUB_ACTION").is_none() - && (var_os("RUSTC_BLESS").is_some_and(|v| v != "0") || !args.check) - { + output_conflict_handling: if bless { OutputConflictHandling::Bless } else { OutputConflictHandling::Error("cargo uibless".into()) }, target: None, - out_dir: canonicalize( - std::env::var_os("CARGO_TARGET_DIR") - .map_or_else(|| std::env::current_dir().unwrap().join("target"), PathBuf::from), - ) - .join("ui_test"), + out_dir: canonicalize(std::env::var_os("CARGO_TARGET_DIR").unwrap_or_else(|| "target".into())).join("ui_test"), ..compiletest::Config::rustc(Path::new("tests").join(test_dir)) }; let current_exe_path = env::current_exe().unwrap(); @@ -172,38 +179,18 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) { (config, args) } -fn test_filter() -> Box bool> { - if let Ok(filters) = env::var("TESTNAME") { - let filters: Vec<_> = filters.split(',').map(ToString::to_string).collect(); - Box::new(move |path| filters.iter().any(|f| path.to_string_lossy().contains(f))) - } else { - Box::new(|_| true) - } -} - fn run_ui() { let (config, args) = base_config("ui"); - //config.rustfix_coverage = true; // use tests/clippy.toml let _g = VarGuard::set("CARGO_MANIFEST_DIR", canonicalize("tests")); - let _threads = VarGuard::set( - "RUST_TEST_THREADS", - // if RUST_TEST_THREADS is set, adhere to it, otherwise override it - env::var("RUST_TEST_THREADS").unwrap_or_else(|_| { - std::thread::available_parallelism() - .map_or(1, std::num::NonZeroUsize::get) - .to_string() - }), - ); - - let test_filter = test_filter(); + let _threads = VarGuard::set("RUST_TEST_THREADS", args.threads.to_string()); let quiet = args.quiet; compiletest::run_tests_generic( vec![config], args, - move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path), + compiletest::default_file_filter, compiletest::default_per_file_config, if quiet { status_emitter::Text::quiet() @@ -221,15 +208,14 @@ fn run_internal_tests() { } let (mut config, args) = base_config("ui-internal"); if let OutputConflictHandling::Error(err) = &mut config.output_conflict_handling { - *err = "cargo uitest --features internal".into(); + *err = "cargo uitest --features internal -- -- --bless".into(); } - let test_filter = test_filter(); let quiet = args.quiet; compiletest::run_tests_generic( vec![config], args, - move |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path), + compiletest::default_file_filter, compiletest::default_per_file_config, if quiet { status_emitter::Text::quiet() @@ -255,13 +241,12 @@ fn run_ui_toml() { "$$DIR", ); - let test_filter = test_filter(); let quiet = args.quiet; ui_test::run_tests_generic( vec![config], args, - |path, args, config| compiletest::default_file_filter(path, args, config) && test_filter(path), + compiletest::default_file_filter, |config, path, _file_contents| { config .program @@ -312,13 +297,12 @@ fn run_ui_cargo() { "$$DIR", ); - let test_filter = test_filter(); let quiet = args.quiet; ui_test::run_tests_generic( vec![config], args, - |path, _args, _config| test_filter(path) && path.ends_with("Cargo.toml"), + |path, args, _config| path.ends_with("Cargo.toml") && ui_test::default_filter_by_arg(path, args), |config, path, _file_contents| { config.out_dir = canonicalize( std::env::current_dir() From 1eff39ddb61ebeba58446894b8bb238840d5cc06 Mon Sep 17 00:00:00 2001 From: unvalley Date: Sun, 13 Aug 2023 22:52:06 +0900 Subject: [PATCH 20/79] fix: change msrv to 1.69 for binary heap --- tests/ui/manual_retain.fixed | 6 +++--- tests/ui/manual_retain.rs | 4 ++-- tests/ui/manual_retain.stderr | 8 +------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/ui/manual_retain.fixed b/tests/ui/manual_retain.fixed index c856a4dc67afe..4dea3e8bfe68a 100644 --- a/tests/ui/manual_retain.fixed +++ b/tests/ui/manual_retain.fixed @@ -218,10 +218,10 @@ fn vec_deque_retain() { bar = foobar.into_iter().filter(|x| x % 2 == 0).collect(); } -#[clippy::msrv = "1.70"] -fn _msrv_170() { +#[clippy::msrv = "1.69"] +fn _msrv_169() { let mut binary_heap = BinaryHeap::from([1, 2, 3]); - binary_heap.retain(|x| x % 2 == 0); + binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); } #[clippy::msrv = "1.52"] diff --git a/tests/ui/manual_retain.rs b/tests/ui/manual_retain.rs index 7f92eede94e5b..d839550f33a22 100644 --- a/tests/ui/manual_retain.rs +++ b/tests/ui/manual_retain.rs @@ -224,8 +224,8 @@ fn vec_deque_retain() { bar = foobar.into_iter().filter(|x| x % 2 == 0).collect(); } -#[clippy::msrv = "1.70"] -fn _msrv_170() { +#[clippy::msrv = "1.69"] +fn _msrv_169() { let mut binary_heap = BinaryHeap::from([1, 2, 3]); binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); } diff --git a/tests/ui/manual_retain.stderr b/tests/ui/manual_retain.stderr index 6b8ec4d68b24f..cc1b449d25ab1 100644 --- a/tests/ui/manual_retain.stderr +++ b/tests/ui/manual_retain.stderr @@ -138,11 +138,5 @@ error: this expression can be written more simply using `.retain()` LL | vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` -error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:230:5 - | -LL | binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` - -error: aborting due to 23 previous errors +error: aborting due to 22 previous errors From fc061890d6b1a2715d30e99e36ae4305f473c43c Mon Sep 17 00:00:00 2001 From: lengyijun Date: Thu, 3 Aug 2023 11:37:23 +0800 Subject: [PATCH 21/79] [`iter_overeager_cloned`]: detect .cloned().filter() and .cloned().find() Key idea: ``` // before iter.cloned().filter(|x| unimplemented!() ) // after iter.filter(|&x| unimplemented!() ).cloned() // before iter.cloned().filter( foo ) // after iter.filter(|&x| foo(x) ).cloned() ``` --- .../src/methods/iter_overeager_cloned.rs | 53 +++++++++++---- clippy_lints/src/methods/mod.rs | 24 +++++-- tests/ui/iter_overeager_cloned.fixed | 40 +++++++++-- tests/ui/iter_overeager_cloned.rs | 38 +++++++++-- tests/ui/iter_overeager_cloned.stderr | 66 ++++++++++++++++++- 5 files changed, 193 insertions(+), 28 deletions(-) diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index 9f7ec19aa598a..4b1ca0d9b9cfd 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{implements_trait, is_copy}; use rustc_errors::Applicability; -use rustc_hir::Expr; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::sym; @@ -10,12 +10,28 @@ use rustc_span::sym; use super::ITER_OVEREAGER_CLONED; use crate::redundant_clone::REDUNDANT_CLONE; +#[derive(Clone, Copy)] +pub(super) enum Op<'a> { + // rm `.cloned()` + // e.g. `count` + RmCloned, + + // later `.cloned()` + // and add `&` to the parameter of closure parameter + // e.g. `find` `filter` + FixClosure(&'a str, &'a Expr<'a>), + + // later `.cloned()` + // e.g. `skip` `take` + LaterCloned, +} + pub(super) fn check<'tcx>( cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, cloned_call: &'tcx Expr<'_>, cloned_recv: &'tcx Expr<'_>, - is_count: bool, + op: Op<'tcx>, needs_into_iter: bool, ) { let typeck = cx.typeck_results(); @@ -35,10 +51,9 @@ pub(super) fn check<'tcx>( return; } - let (lint, msg, trailing_clone) = if is_count { - (REDUNDANT_CLONE, "unneeded cloning of iterator items", "") - } else { - (ITER_OVEREAGER_CLONED, "unnecessarily eager cloning of iterator items", ".cloned()") + let (lint, msg, trailing_clone) = match op { + Op::RmCloned => (REDUNDANT_CLONE, "unneeded cloning of iterator items", ""), + Op::LaterCloned | Op::FixClosure(_, _) => (ITER_OVEREAGER_CLONED, "unnecessarily eager cloning of iterator items", ".cloned()"), }; span_lint_and_then( @@ -47,11 +62,27 @@ pub(super) fn check<'tcx>( expr.span, msg, |diag| { - let method_span = expr.span.with_lo(cloned_call.span.hi()); - if let Some(mut snip) = snippet_opt(cx, method_span) { - snip.push_str(trailing_clone); - let replace_span = expr.span.with_lo(cloned_recv.span.hi()); - diag.span_suggestion(replace_span, "try", snip, Applicability::MachineApplicable); + match op { + Op::RmCloned | Op::LaterCloned => { + let method_span = expr.span.with_lo(cloned_call.span.hi()); + if let Some(mut snip) = snippet_opt(cx, method_span) { + snip.push_str(trailing_clone); + let replace_span = expr.span.with_lo(cloned_recv.span.hi()); + diag.span_suggestion(replace_span, "try", snip, Applicability::MachineApplicable); + } + } + Op::FixClosure(name, predicate_expr) => { + if let Some(predicate) = snippet_opt(cx, predicate_expr.span) { + let new_closure = if let ExprKind::Closure(_) = predicate_expr.kind { + predicate.replacen('|', "|&", 1) + } else { + format!("|&x| {predicate}(x)") + }; + let snip = format!(".{name}({new_closure}).cloned()" ); + let replace_span = expr.span.with_lo(cloned_recv.span.hi()); + diag.span_suggestion(replace_span, "try", snip, Applicability::MachineApplicable); + } + } } } ); diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 42756b27d014d..729eda37af62d 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3919,7 +3919,7 @@ impl Methods { } }, ("count", []) if is_trait_method(cx, expr, sym::Iterator) => match method_call(recv) { - Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, true, false), + Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, iter_overeager_cloned::Op::RmCloned , false), Some((name2 @ ("into_iter" | "iter" | "iter_mut"), recv2, [], _, _)) => { iter_count::check(cx, expr, recv2, name2); }, @@ -3973,6 +3973,13 @@ impl Methods { string_extend_chars::check(cx, expr, recv, arg); extend_with_drain::check(cx, expr, recv, arg); }, + (name @ ( "filter" | "find" ) , [arg]) => { + if let Some(("cloned", recv2, [], _span2, _)) = method_call(recv) { + // if `arg` has side-effect, the semantic will change + iter_overeager_cloned::check(cx, expr, recv, recv2, + iter_overeager_cloned::Op::FixClosure(name, arg), false); + } + } ("filter_map", [arg]) => { unnecessary_filter_map::check(cx, expr, arg, name); filter_map_bool_then::check(cx, expr, arg, call_span); @@ -3987,7 +3994,7 @@ impl Methods { }, ("flatten", []) => match method_call(recv) { Some(("map", recv, [map_arg], map_span, _)) => map_flatten::check(cx, expr, recv, map_arg, map_span), - Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, true), + Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, iter_overeager_cloned::Op::LaterCloned , true), _ => {}, }, ("fold", [init, acc]) => { @@ -4021,7 +4028,8 @@ impl Methods { }, ("last", []) => { if let Some(("cloned", recv2, [], _span2, _)) = method_call(recv) { - iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); + iter_overeager_cloned::check(cx, expr, recv, recv2, + iter_overeager_cloned::Op::LaterCloned , false); } }, ("lock", []) => { @@ -4058,7 +4066,7 @@ impl Methods { ("next", []) => { if let Some((name2, recv2, args2, _, _)) = method_call(recv) { match (name2, args2) { - ("cloned", []) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, false), + ("cloned", []) => iter_overeager_cloned::check(cx, expr, recv, recv2, iter_overeager_cloned::Op::LaterCloned, false), ("filter", [arg]) => filter_next::check(cx, expr, recv2, arg), ("filter_map", [arg]) => filter_map_next::check(cx, expr, recv2, arg, &self.msrv), ("iter", []) => iter_next_slice::check(cx, expr, recv2), @@ -4071,7 +4079,7 @@ impl Methods { }, ("nth", [n_arg]) => match method_call(recv) { Some(("bytes", recv2, [], _, _)) => bytes_nth::check(cx, expr, recv2, n_arg), - Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, false, false), + Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, iter_overeager_cloned::Op::LaterCloned , false), Some(("iter", recv2, [], _, _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, false), Some(("iter_mut", recv2, [], _, _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, true), _ => iter_nth_zero::check(cx, expr, recv, n_arg), @@ -4126,7 +4134,8 @@ impl Methods { iter_skip_zero::check(cx, expr, arg); if let Some(("cloned", recv2, [], _span2, _)) = method_call(recv) { - iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); + iter_overeager_cloned::check(cx, expr, recv, recv2, + iter_overeager_cloned::Op::LaterCloned , false); } } ("sort", []) => { @@ -4152,7 +4161,8 @@ impl Methods { ("step_by", [arg]) => iterator_step_by_zero::check(cx, expr, arg), ("take", [_arg]) => { if let Some(("cloned", recv2, [], _span2, _)) = method_call(recv) { - iter_overeager_cloned::check(cx, expr, recv, recv2, false, false); + iter_overeager_cloned::check(cx, expr, recv, recv2, + iter_overeager_cloned::Op::LaterCloned, false); } }, ("take", []) => needless_option_take::check(cx, expr, recv), diff --git a/tests/ui/iter_overeager_cloned.fixed b/tests/ui/iter_overeager_cloned.fixed index ba26fe33d8925..9605b449b4095 100644 --- a/tests/ui/iter_overeager_cloned.fixed +++ b/tests/ui/iter_overeager_cloned.fixed @@ -20,8 +20,41 @@ fn main() { .iter() .flatten().cloned(); - // Not implemented yet - let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); + let _ = vec.iter().filter(|&x| x.starts_with('2')).cloned(); + + let _ = vec.iter().find(|&x| x == "2").cloned(); + + { + let f = |x: &String| x.starts_with('2'); + let _ = vec.iter().filter(|&x| f(x)).cloned(); + let _ = vec.iter().find(|&x| f(x)).cloned(); + } + + { + let vec: Vec<(String, String)> = vec![]; + let f = move |x: &(String, String)| x.0.starts_with('2'); + let _ = vec.iter().filter(|&x| f(x)).cloned(); + let _ = vec.iter().find(|&x| f(x)).cloned(); + } + + fn test_move<'a>( + iter: impl Iterator + 'a, + target: String, + ) -> impl Iterator + 'a { + iter.filter(move |&(&a, b)| a == 1 && b == &target).cloned() + } + + { + #[derive(Clone)] + struct S<'a> { + a: &'a u32, + b: String, + } + + fn bar<'a>(iter: impl Iterator> + 'a, target: String) -> impl Iterator> + 'a { + iter.filter(move |&S { a, b }| **a == 1 && b == &target).cloned() + } + } // Not implemented yet let _ = vec.iter().cloned().map(|x| x.len()); @@ -29,9 +62,6 @@ fn main() { // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); - // Not implemented yet - let _ = vec.iter().cloned().find(|x| x == "2"); - // Not implemented yet let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); diff --git a/tests/ui/iter_overeager_cloned.rs b/tests/ui/iter_overeager_cloned.rs index 2d3c4ea7c2015..8d75f039d44e4 100644 --- a/tests/ui/iter_overeager_cloned.rs +++ b/tests/ui/iter_overeager_cloned.rs @@ -21,18 +21,48 @@ fn main() { .cloned() .flatten(); - // Not implemented yet let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); + let _ = vec.iter().cloned().find(|x| x == "2"); + + { + let f = |x: &String| x.starts_with('2'); + let _ = vec.iter().cloned().filter(f); + let _ = vec.iter().cloned().find(f); + } + + { + let vec: Vec<(String, String)> = vec![]; + let f = move |x: &(String, String)| x.0.starts_with('2'); + let _ = vec.iter().cloned().filter(f); + let _ = vec.iter().cloned().find(f); + } + + fn test_move<'a>( + iter: impl Iterator + 'a, + target: String, + ) -> impl Iterator + 'a { + iter.cloned().filter(move |(&a, b)| a == 1 && b == &target) + } + + { + #[derive(Clone)] + struct S<'a> { + a: &'a u32, + b: String, + } + + fn bar<'a>(iter: impl Iterator> + 'a, target: String) -> impl Iterator> + 'a { + iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target) + } + } + // Not implemented yet let _ = vec.iter().cloned().map(|x| x.len()); // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); - // Not implemented yet - let _ = vec.iter().cloned().find(|x| x == "2"); - // Not implemented yet let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); diff --git a/tests/ui/iter_overeager_cloned.stderr b/tests/ui/iter_overeager_cloned.stderr index 2be2b7e07a468..bdbb04d7f0828 100644 --- a/tests/ui/iter_overeager_cloned.stderr +++ b/tests/ui/iter_overeager_cloned.stderr @@ -66,5 +66,69 @@ LL ~ .iter() LL ~ .flatten().cloned(); | -error: aborting due to 7 previous errors +error: unnecessarily eager cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:24:13 + | +LL | let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); + | ^^^^^^^^^^---------------------------------------- + | | + | help: try: `.filter(|&x| x.starts_with('2')).cloned()` + +error: unnecessarily eager cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:26:13 + | +LL | let _ = vec.iter().cloned().find(|x| x == "2"); + | ^^^^^^^^^^---------------------------- + | | + | help: try: `.find(|&x| x == "2").cloned()` + +error: unnecessarily eager cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:30:17 + | +LL | let _ = vec.iter().cloned().filter(f); + | ^^^^^^^^^^------------------- + | | + | help: try: `.filter(|&x| f(x)).cloned()` + +error: unnecessarily eager cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:31:17 + | +LL | let _ = vec.iter().cloned().find(f); + | ^^^^^^^^^^----------------- + | | + | help: try: `.find(|&x| f(x)).cloned()` + +error: unnecessarily eager cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:37:17 + | +LL | let _ = vec.iter().cloned().filter(f); + | ^^^^^^^^^^------------------- + | | + | help: try: `.filter(|&x| f(x)).cloned()` + +error: unnecessarily eager cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:38:17 + | +LL | let _ = vec.iter().cloned().find(f); + | ^^^^^^^^^^----------------- + | | + | help: try: `.find(|&x| f(x)).cloned()` + +error: unnecessarily eager cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:45:9 + | +LL | iter.cloned().filter(move |(&a, b)| a == 1 && b == &target) + | ^^^^------------------------------------------------------- + | | + | help: try: `.filter(move |&(&a, b)| a == 1 && b == &target).cloned()` + +error: unnecessarily eager cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:56:13 + | +LL | iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target) + | ^^^^------------------------------------------------------------ + | | + | help: try: `.filter(move |&S { a, b }| **a == 1 && b == &target).cloned()` + +error: aborting due to 15 previous errors From b8b3e078f99da9f07c0323eca895c2d4e431a4a4 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 13 Aug 2023 13:59:19 +0000 Subject: [PATCH 22/79] Remove constness from `ImplSource::Param` --- clippy_utils/src/qualify_min_const_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 4c695cb9b6e1f..139e31bc5286a 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -415,7 +415,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx> if !matches!( impl_src, - ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(ty::BoundConstness::ConstIfConst, _) + ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(_) ) { return false; } From 7c87e5c20d005afc0dd0c392a914490e7d4dc0dc Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Wed, 26 Apr 2023 20:53:51 +0200 Subject: [PATCH 23/79] Use `{Local}ModDefId` in many queries --- clippy_utils/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 171b7faf21960..b77a2f1d0cd05 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -83,7 +83,7 @@ use rustc_ast::Attribute; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::unhash::UnhashMap; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalModDefId, LOCAL_CRATE}; use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{walk_expr, FnKind, Visitor}; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; @@ -2370,11 +2370,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(); -fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool { +fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl Fn(&[Symbol]) -> bool) -> bool { let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default())); - let mut map: MutexGuard<'_, FxHashMap>> = cache.lock().unwrap(); + let mut map: MutexGuard<'_, FxHashMap>> = cache.lock().unwrap(); let value = map.entry(module); match value { Entry::Occupied(entry) => f(entry.get()), From 34348f72f40b070a1a5fe5eac829e41cbd5f98e1 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Mon, 3 Jul 2023 01:12:08 +0200 Subject: [PATCH 24/79] [`useless_conversion`]: make sure path points to fn-like item --- clippy_lints/src/useless_conversion.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 92b694d307600..3be4fb7cc32c7 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -150,9 +150,14 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { { if let Some(parent) = get_parent_expr(cx, e) { let parent_fn = match parent.kind { - ExprKind::Call(recv, args) if let ExprKind::Path(ref qpath) = recv.kind => { - cx.qpath_res(qpath, recv.hir_id).opt_def_id() - .map(|did| (did, args, MethodOrFunction::Function)) + ExprKind::Call(recv, args) + if let ExprKind::Path(ref qpath) = recv.kind + && let Some(did) = cx.qpath_res(qpath, recv.hir_id).opt_def_id() + // make sure that the path indeed points to a fn-like item, so that + // `fn_sig` does not ICE. (see #11065) + && cx.tcx.opt_def_kind(did).is_some_and(|k| k.is_fn_like()) => + { + Some((did, args, MethodOrFunction::Function)) } ExprKind::MethodCall(.., args, _) => { cx.typeck_results().type_dependent_def_id(parent.hir_id) From 2820d980cb3495768babdaeeabd8aa44c3f1aaa8 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Mon, 3 Jul 2023 01:19:09 +0200 Subject: [PATCH 25/79] [`useless_conversion`]: fix FP in macro and add test --- clippy_lints/src/useless_conversion.rs | 15 ++++++++++++++- tests/ui/crashes/ice-11065.rs | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/ui/crashes/ice-11065.rs diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 3be4fb7cc32c7..ec8af2b83626e 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -5,6 +5,7 @@ use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts}; use clippy_utils::{get_parent_expr, is_trait_method, is_ty_alias, match_def_path, path_to_local, paths}; use if_chain::if_chain; use rustc_errors::Applicability; +use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, MatchSource, Node, PatKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -101,6 +102,17 @@ fn into_iter_deep_call<'hir>(cx: &LateContext<'_>, mut expr: &'hir Expr<'hir>) - (expr, depth) } +/// Checks if the given `expr` is an argument of a macro invocation. +/// This is a slow-ish operation, so consider calling this late +/// to avoid slowing down the lint in the happy path when not emitting a warning +fn is_macro_argument(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + if let Some(parent) = get_parent_expr(cx, expr) { + parent.span.from_expansion() || is_macro_argument(cx, parent) + } else { + false + } +} + #[expect(clippy::too_many_lines)] impl<'tcx> LateLintPass<'tcx> for UselessConversion { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { @@ -155,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { && let Some(did) = cx.qpath_res(qpath, recv.hir_id).opt_def_id() // make sure that the path indeed points to a fn-like item, so that // `fn_sig` does not ICE. (see #11065) - && cx.tcx.opt_def_kind(did).is_some_and(|k| k.is_fn_like()) => + && cx.tcx.opt_def_kind(did).is_some_and(DefKind::is_fn_like) => { Some((did, args, MethodOrFunction::Function)) } @@ -173,6 +185,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { && let Some(&into_iter_param) = sig.inputs().get(kind.param_pos(arg_pos)) && let ty::Param(param) = into_iter_param.kind() && let Some(span) = into_iter_bound(cx, parent_fn_did, into_iter_did, param.index) + && !is_macro_argument(cx, e) { // Get the "innermost" `.into_iter()` call, e.g. given this expression: // `foo.into_iter().into_iter()` diff --git a/tests/ui/crashes/ice-11065.rs b/tests/ui/crashes/ice-11065.rs new file mode 100644 index 0000000000000..f5cf6b1cd77a2 --- /dev/null +++ b/tests/ui/crashes/ice-11065.rs @@ -0,0 +1,19 @@ +#![warn(clippy::useless_conversion)] + +use std::iter::FromIterator; +use std::option::IntoIter as OptionIter; + +fn eq(a: T, b: T) -> bool { + a == b +} + +macro_rules! tests { + ($($expr:expr, $ty:ty, ($($test:expr),*);)+) => (pub fn main() {$({ + const C: $ty = $expr; + assert!(eq(C($($test),*), $expr($($test),*))); + })+}) +} + +tests! { + FromIterator::from_iter, fn(OptionIter) -> Vec, (Some(5).into_iter()); +} From f47165c703c1f2819bb0f0aef1be1136457b2f9a Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Sun, 9 Jul 2023 22:32:58 +0200 Subject: [PATCH 26/79] find expansions more efficiently --- clippy_lints/src/useless_conversion.rs | 18 ++++++------------ tests/ui/useless_conversion.fixed | 14 ++++++++++++++ tests/ui/useless_conversion.rs | 14 ++++++++++++++ tests/ui/useless_conversion.stderr | 20 ++++++++++---------- 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index ec8af2b83626e..64dfe51b059ac 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -40,6 +40,7 @@ declare_clippy_lint! { #[derive(Default)] pub struct UselessConversion { try_desugar_arm: Vec, + expn_depth: u32, } impl_lint_pass!(UselessConversion => [USELESS_CONVERSION]); @@ -102,21 +103,11 @@ fn into_iter_deep_call<'hir>(cx: &LateContext<'_>, mut expr: &'hir Expr<'hir>) - (expr, depth) } -/// Checks if the given `expr` is an argument of a macro invocation. -/// This is a slow-ish operation, so consider calling this late -/// to avoid slowing down the lint in the happy path when not emitting a warning -fn is_macro_argument(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if let Some(parent) = get_parent_expr(cx, expr) { - parent.span.from_expansion() || is_macro_argument(cx, parent) - } else { - false - } -} - #[expect(clippy::too_many_lines)] impl<'tcx> LateLintPass<'tcx> for UselessConversion { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { + self.expn_depth += 1; return; } @@ -185,7 +176,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { && let Some(&into_iter_param) = sig.inputs().get(kind.param_pos(arg_pos)) && let ty::Param(param) = into_iter_param.kind() && let Some(span) = into_iter_bound(cx, parent_fn_did, into_iter_did, param.index) - && !is_macro_argument(cx, e) + && self.expn_depth == 0 { // Get the "innermost" `.into_iter()` call, e.g. given this expression: // `foo.into_iter().into_iter()` @@ -321,5 +312,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { if Some(&e.hir_id) == self.try_desugar_arm.last() { self.try_desugar_arm.pop(); } + if e.span.from_expansion() { + self.expn_depth -= 1; + } } } diff --git a/tests/ui/useless_conversion.fixed b/tests/ui/useless_conversion.fixed index d5a57ec61f7d5..5259195990592 100644 --- a/tests/ui/useless_conversion.fixed +++ b/tests/ui/useless_conversion.fixed @@ -153,6 +153,20 @@ fn main() { let _ = vec![s4, s4, s4].into_iter(); } +#[allow(dead_code)] +fn issue11065_fp() { + use std::option::IntoIter; + fn takes_into_iter(_: impl IntoIterator) {} + + macro_rules! x { + ($e:expr) => { + takes_into_iter($e); + let _: IntoIter = $e; // removing `.into_iter()` leads to a type error here + }; + } + x!(Some(5).into_iter()); +} + #[allow(dead_code)] fn explicit_into_iter_fn_arg() { fn a(_: T) {} diff --git a/tests/ui/useless_conversion.rs b/tests/ui/useless_conversion.rs index 6730e6909c5a0..befb2f9a5c32c 100644 --- a/tests/ui/useless_conversion.rs +++ b/tests/ui/useless_conversion.rs @@ -153,6 +153,20 @@ fn main() { let _ = vec![s4, s4, s4].into_iter().into_iter(); } +#[allow(dead_code)] +fn issue11065_fp() { + use std::option::IntoIter; + fn takes_into_iter(_: impl IntoIterator) {} + + macro_rules! x { + ($e:expr) => { + takes_into_iter($e); + let _: IntoIter = $e; // removing `.into_iter()` leads to a type error here + }; + } + x!(Some(5).into_iter()); +} + #[allow(dead_code)] fn explicit_into_iter_fn_arg() { fn a(_: T) {} diff --git a/tests/ui/useless_conversion.stderr b/tests/ui/useless_conversion.stderr index bf701b1e81ec7..28e7bb61098f7 100644 --- a/tests/ui/useless_conversion.stderr +++ b/tests/ui/useless_conversion.stderr @@ -119,61 +119,61 @@ LL | let _ = vec![s4, s4, s4].into_iter().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()` error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:169:7 + --> $DIR/useless_conversion.rs:183:7 | LL | b(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:159:13 + --> $DIR/useless_conversion.rs:173:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:170:7 + --> $DIR/useless_conversion.rs:184:7 | LL | c(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:160:18 + --> $DIR/useless_conversion.rs:174:18 | LL | fn c(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:171:7 + --> $DIR/useless_conversion.rs:185:7 | LL | d(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:163:12 + --> $DIR/useless_conversion.rs:177:12 | LL | T: IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:174:7 + --> $DIR/useless_conversion.rs:188:7 | LL | b(vec![1, 2].into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:159:13 + --> $DIR/useless_conversion.rs:173:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:175:7 + --> $DIR/useless_conversion.rs:189:7 | LL | b(vec![1, 2].into_iter().into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:159:13 + --> $DIR/useless_conversion.rs:173:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ From 77d10ac63dae6ef0a691d9acd63d65de9b9bf88e Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Mon, 14 Aug 2023 15:59:00 +0000 Subject: [PATCH 27/79] Use ui_test's Windows path backslash heuristic --- tests/compile-test.rs | 119 +++++++++------------ tests/ui/char_lit_as_u8_suggestions.stderr | 12 +-- tests/ui/crashes/ice-9405.stderr | 2 +- tests/ui/doc/doc-fixable.stderr | 4 +- tests/ui/eprint_with_newline.stderr | 32 +++--- tests/ui/explicit_write.stderr | 8 +- tests/ui/format.stderr | 4 +- tests/ui/manual_str_repeat.stderr | 4 +- tests/ui/octal_escapes.stderr | 72 ++++++------- tests/ui/path_buf_push_overwrite.stderr | 2 +- tests/ui/print_with_newline.stderr | 32 +++--- tests/ui/regex.stderr | 10 +- tests/ui/single_char_add_str.stderr | 22 ++-- tests/ui/single_char_pattern.stderr | 24 ++--- tests/ui/starts_ends_with.stderr | 20 ++-- tests/ui/string_lit_as_bytes.stderr | 4 +- tests/ui/string_lit_chars_any.stderr | 20 ++-- tests/ui/unicode.stderr | 14 +-- tests/ui/uninlined_format_args.stderr | 8 +- tests/ui/write_literal_2.stderr | 52 ++++----- tests/ui/write_with_newline.stderr | 32 +++--- 21 files changed, 237 insertions(+), 260 deletions(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index b8731cfe78c81..844e66728f253 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -4,12 +4,10 @@ #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(unused_extern_crates)] -use compiletest::{status_emitter, Args, CommandBuilder, OutputConflictHandling}; -use ui_test as compiletest; -use ui_test::Mode as TestMode; +use ui_test::{status_emitter, Args, CommandBuilder, Config, Match, Mode, OutputConflictHandling}; use std::collections::BTreeMap; -use std::env::{self, remove_var, set_var, var_os}; +use std::env::{self, set_var, var_os}; use std::ffi::{OsStr, OsString}; use std::fs; use std::path::{Path, PathBuf}; @@ -29,6 +27,8 @@ extern crate quote; extern crate syn; extern crate tokio; +mod test_utils; + /// All crates used in UI tests are listed here static TEST_DEPENDENCIES: &[&str] = &[ "clippy_lints", @@ -104,8 +104,6 @@ static EXTERN_FLAGS: LazyLock> = LazyLock::new(|| { .collect() }); -mod test_utils; - // whether to run internal tests or not const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal"); @@ -115,7 +113,7 @@ fn canonicalize(path: impl AsRef) -> PathBuf { fs::canonicalize(path).unwrap_or_else(|err| panic!("{} cannot be canonicalized: {err}", path.display())) } -fn base_config(test_dir: &str) -> (compiletest::Config, Args) { +fn base_config(test_dir: &str) -> (Config, Args) { let bless = var_os("RUSTC_BLESS").is_some_and(|v| v != "0") || env::args().any(|arg| arg == "--bless"); let args = Args { @@ -131,9 +129,9 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) { skip: Vec::new(), }; - let mut config = compiletest::Config { - mode: TestMode::Yolo { rustfix: true }, - stderr_filters: vec![], + let mut config = Config { + mode: Mode::Yolo { rustfix: true }, + stderr_filters: vec![(Match::PathBackslash, b"/")], stdout_filters: vec![], output_conflict_handling: if bless { OutputConflictHandling::Bless @@ -141,8 +139,8 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) { OutputConflictHandling::Error("cargo uibless".into()) }, target: None, - out_dir: canonicalize(std::env::var_os("CARGO_TARGET_DIR").unwrap_or_else(|| "target".into())).join("ui_test"), - ..compiletest::Config::rustc(Path::new("tests").join(test_dir)) + out_dir: canonicalize(var_os("CARGO_TARGET_DIR").unwrap_or_else(|| "target".into())).join("ui_test"), + ..Config::rustc(Path::new("tests").join(test_dir)) }; let current_exe_path = env::current_exe().unwrap(); let deps_path = current_exe_path.parent().unwrap(); @@ -167,10 +165,6 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) { config.program.args.push(dep.into()); } - // Normalize away slashes in windows paths. - config.stderr_filter(r"\\", "/"); - - //config.build_base = profile_path.join("test").join(test_dir); config.program.program = profile_path.join(if cfg!(windows) { "clippy-driver.exe" } else { @@ -180,18 +174,19 @@ fn base_config(test_dir: &str) -> (compiletest::Config, Args) { } fn run_ui() { - let (config, args) = base_config("ui"); - // use tests/clippy.toml - let _g = VarGuard::set("CARGO_MANIFEST_DIR", canonicalize("tests")); - let _threads = VarGuard::set("RUST_TEST_THREADS", args.threads.to_string()); + let (mut config, args) = base_config("ui"); + config + .program + .envs + .push(("CLIPPY_CONF_DIR".into(), Some(canonicalize("tests").into()))); let quiet = args.quiet; - compiletest::run_tests_generic( + ui_test::run_tests_generic( vec![config], args, - compiletest::default_file_filter, - compiletest::default_per_file_config, + ui_test::default_file_filter, + ui_test::default_per_file_config, if quiet { status_emitter::Text::quiet() } else { @@ -212,11 +207,11 @@ fn run_internal_tests() { } let quiet = args.quiet; - compiletest::run_tests_generic( + ui_test::run_tests_generic( vec![config], args, - compiletest::default_file_filter, - compiletest::default_per_file_config, + ui_test::default_file_filter, + ui_test::default_per_file_config, if quiet { status_emitter::Text::quiet() } else { @@ -229,24 +224,27 @@ fn run_internal_tests() { fn run_ui_toml() { let (mut config, args) = base_config("ui-toml"); - config.stderr_filter( - ®ex::escape( - &canonicalize("tests") - .parent() - .unwrap() - .display() - .to_string() - .replace('\\', "/"), + config.stderr_filters = vec![ + ( + Match::Exact( + canonicalize("tests") + .parent() + .unwrap() + .to_string_lossy() + .as_bytes() + .to_vec(), + ), + b"$DIR", ), - "$$DIR", - ); + (Match::Exact(b"\\".to_vec()), b"/"), + ]; let quiet = args.quiet; ui_test::run_tests_generic( vec![config], args, - compiletest::default_file_filter, + ui_test::default_file_filter, |config, path, _file_contents| { config .program @@ -285,17 +283,20 @@ fn run_ui_cargo() { }); config.edition = None; - config.stderr_filter( - ®ex::escape( - &canonicalize("tests") - .parent() - .unwrap() - .display() - .to_string() - .replace('\\', "/"), + config.stderr_filters = vec![ + ( + Match::Exact( + canonicalize("tests") + .parent() + .unwrap() + .to_string_lossy() + .as_bytes() + .to_vec(), + ), + b"$DIR", ), - "$$DIR", - ); + (Match::Exact(b"\\".to_vec()), b"/"), + ]; let quiet = args.quiet; @@ -410,27 +411,3 @@ fn ui_cargo_toml_metadata() { ); } } - -/// Restores an env var on drop -#[must_use] -struct VarGuard { - key: &'static str, - value: Option, -} - -impl VarGuard { - fn set(key: &'static str, val: impl AsRef) -> Self { - let value = var_os(key); - set_var(key, val); - Self { key, value } - } -} - -impl Drop for VarGuard { - fn drop(&mut self) { - match self.value.as_deref() { - None => remove_var(self.key), - Some(value) => set_var(self.key, value), - } - } -} diff --git a/tests/ui/char_lit_as_u8_suggestions.stderr b/tests/ui/char_lit_as_u8_suggestions.stderr index f7e7b878bb153..0542db5501a0c 100644 --- a/tests/ui/char_lit_as_u8_suggestions.stderr +++ b/tests/ui/char_lit_as_u8_suggestions.stderr @@ -10,24 +10,24 @@ LL | let _ = 'a' as u8; error: casting a character literal to `u8` truncates --> $DIR/char_lit_as_u8_suggestions.rs:5:13 | -LL | let _ = '/n' as u8; - | ^^^^^^^^^^ help: use a byte literal instead: `b'/n'` +LL | let _ = '\n' as u8; + | ^^^^^^^^^^ help: use a byte literal instead: `b'\n'` | = note: `char` is four bytes wide, but `u8` is a single byte error: casting a character literal to `u8` truncates --> $DIR/char_lit_as_u8_suggestions.rs:6:13 | -LL | let _ = '/0' as u8; - | ^^^^^^^^^^ help: use a byte literal instead: `b'/0'` +LL | let _ = '\0' as u8; + | ^^^^^^^^^^ help: use a byte literal instead: `b'\0'` | = note: `char` is four bytes wide, but `u8` is a single byte error: casting a character literal to `u8` truncates --> $DIR/char_lit_as_u8_suggestions.rs:7:13 | -LL | let _ = '/x01' as u8; - | ^^^^^^^^^^^^ help: use a byte literal instead: `b'/x01'` +LL | let _ = '\x01' as u8; + | ^^^^^^^^^^^^ help: use a byte literal instead: `b'\x01'` | = note: `char` is four bytes wide, but `u8` is a single byte diff --git a/tests/ui/crashes/ice-9405.stderr b/tests/ui/crashes/ice-9405.stderr index 9a6e410f21ea8..56649a2bdfcb5 100644 --- a/tests/ui/crashes/ice-9405.stderr +++ b/tests/ui/crashes/ice-9405.stderr @@ -1,7 +1,7 @@ warning: multiple lines skipped by escaped newline --> $DIR/ice-9405.rs:6:10 | -LL | "/ +LL | "\ | __________^ LL | | LL | | {}", diff --git a/tests/ui/doc/doc-fixable.stderr b/tests/ui/doc/doc-fixable.stderr index 94ef43afc08f3..dda764f8493bc 100644 --- a/tests/ui/doc/doc-fixable.stderr +++ b/tests/ui/doc/doc-fixable.stderr @@ -24,12 +24,12 @@ LL | /// The foo_bar function does _nothing_. See also `foo::bar`. (note the dot error: item in documentation is missing backticks --> $DIR/doc-fixable.rs:10:83 | -LL | /// Markdown is _weird_. I mean _really weird_. This /_ is ok. So is `_`. But not Foo::some_fun +LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun | ^^^^^^^^^^^^^ | help: try | -LL | /// Markdown is _weird_. I mean _really weird_. This /_ is ok. So is `_`. But not `Foo::some_fun` +LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not `Foo::some_fun` | ~~~~~~~~~~~~~~~ error: item in documentation is missing backticks diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr index 0a6bdf15df8ee..080f6c2a60542 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -1,74 +1,74 @@ error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:5:5 | -LL | eprint!("Hello/n"); +LL | eprint!("Hello\n"); | ^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-with-newline` implied by `-D warnings` help: use `eprintln!` instead | -LL - eprint!("Hello/n"); +LL - eprint!("Hello\n"); LL + eprintln!("Hello"); | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:6:5 | -LL | eprint!("Hello {}/n", "world"); +LL | eprint!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("Hello {}/n", "world"); +LL - eprint!("Hello {}\n", "world"); LL + eprintln!("Hello {}", "world"); | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:7:5 | -LL | eprint!("Hello {} {}/n", "world", "#2"); +LL | eprint!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("Hello {} {}/n", "world", "#2"); +LL - eprint!("Hello {} {}\n", "world", "#2"); LL + eprintln!("Hello {} {}", "world", "#2"); | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:8:5 | -LL | eprint!("{}/n", 1265); +LL | eprint!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("{}/n", 1265); +LL - eprint!("{}\n", 1265); LL + eprintln!("{}", 1265); | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:9:5 | -LL | eprint!("/n"); +LL | eprint!("\n"); | ^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("/n"); +LL - eprint!("\n"); LL + eprintln!(); | error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:28:5 | -LL | eprint!("///n"); // should fail +LL | eprint!("\\\n"); // should fail | ^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("///n"); // should fail -LL + eprintln!("//"); // should fail +LL - eprint!("\\\n"); // should fail +LL + eprintln!("\\"); // should fail | error: using `eprint!()` with a format string that ends in a single newline @@ -104,13 +104,13 @@ LL ~ error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:47:5 | -LL | eprint!("//r/n"); +LL | eprint!("\\r\n"); | ^^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("//r/n"); -LL + eprintln!("//r"); +LL - eprint!("\\r\n"); +LL + eprintln!("\\r"); | error: aborting due to 9 previous errors diff --git a/tests/ui/explicit_write.stderr b/tests/ui/explicit_write.stderr index fa7751d920d9a..230762c2db178 100644 --- a/tests/ui/explicit_write.stderr +++ b/tests/ui/explicit_write.stderr @@ -39,14 +39,14 @@ LL | std::io::stderr().write_fmt(format_args!("test")).unwrap(); error: use of `writeln!(stdout(), ...).unwrap()` --> $DIR/explicit_write.rs:31:9 | -LL | writeln!(std::io::stdout(), "test/ntest").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test/ntest")` +LL | writeln!(std::io::stdout(), "test\ntest").unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test\ntest")` error: use of `writeln!(stderr(), ...).unwrap()` --> $DIR/explicit_write.rs:32:9 | -LL | writeln!(std::io::stderr(), "test/ntest").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test/ntest")` +LL | writeln!(std::io::stderr(), "test\ntest").unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test\ntest")` error: use of `writeln!(stderr(), ...).unwrap()` --> $DIR/explicit_write.rs:35:9 diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr index f456c11924e5a..7019e2c867547 100644 --- a/tests/ui/format.stderr +++ b/tests/ui/format.stderr @@ -72,8 +72,8 @@ LL | let _ = Some(format!("{}", a + "bar")); error: useless use of `format!` --> $DIR/format.rs:78:22 | -LL | let _s: String = format!("{}", &*v.join("/n")); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()` +LL | let _s: String = format!("{}", &*v.join("\n")); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("\n")).to_string()` error: useless use of `format!` --> $DIR/format.rs:84:13 diff --git a/tests/ui/manual_str_repeat.stderr b/tests/ui/manual_str_repeat.stderr index e9067719cc666..b92835884d9c1 100644 --- a/tests/ui/manual_str_repeat.stderr +++ b/tests/ui/manual_str_repeat.stderr @@ -15,14 +15,14 @@ LL | let _: String = std::iter::repeat('x').take(10).collect(); error: manual implementation of `str::repeat` using iterators --> $DIR/manual_str_repeat.rs:9:21 | -LL | let _: String = std::iter::repeat('/'').take(10).collect(); +LL | let _: String = std::iter::repeat('\'').take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"'".repeat(10)` error: manual implementation of `str::repeat` using iterators --> $DIR/manual_str_repeat.rs:10:21 | LL | let _: String = std::iter::repeat('"').take(10).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"/"".repeat(10)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"\"".repeat(10)` error: manual implementation of `str::repeat` using iterators --> $DIR/manual_str_repeat.rs:14:13 diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 4245c32b5d201..078118eb7f204 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -1,146 +1,146 @@ error: octal-looking escape in string literal --> $DIR/octal_escapes.rs:5:17 | -LL | let _bad1 = "/033[0m"; +LL | let _bad1 = "\033[0m"; | ^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character = note: `-D clippy::octal-escapes` implied by `-D warnings` help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad1 = "/x1b[0m"; +LL | let _bad1 = "\x1b[0m"; | ~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad1 = "/x0033[0m"; +LL | let _bad1 = "\x0033[0m"; | ~~~~~~~~~~~ error: octal-looking escape in byte string literal --> $DIR/octal_escapes.rs:6:17 | -LL | let _bad2 = b"/033[0m"; +LL | let _bad2 = b"\033[0m"; | ^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null byte + = help: octal escapes are not supported, `\0` is always a null byte help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad2 = b"/x1b[0m"; +LL | let _bad2 = b"\x1b[0m"; | ~~~~~~~~~~ help: if the null byte is intended, disambiguate using | -LL | let _bad2 = b"/x0033[0m"; +LL | let _bad2 = b"\x0033[0m"; | ~~~~~~~~~~~~ error: octal-looking escape in string literal --> $DIR/octal_escapes.rs:7:17 | -LL | let _bad3 = "///033[0m"; +LL | let _bad3 = "\\\033[0m"; | ^^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad3 = "///x1b[0m"; +LL | let _bad3 = "\\\x1b[0m"; | ~~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad3 = "///x0033[0m"; +LL | let _bad3 = "\\\x0033[0m"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal --> $DIR/octal_escapes.rs:9:17 | -LL | let _bad4 = "/01234567"; +LL | let _bad4 = "\01234567"; | ^^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad4 = "/x0a34567"; +LL | let _bad4 = "\x0a34567"; | ~~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad4 = "/x001234567"; +LL | let _bad4 = "\x001234567"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal --> $DIR/octal_escapes.rs:10:17 | -LL | let _bad5 = "/0/03"; +LL | let _bad5 = "\0\03"; | ^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad5 = "/0/x03"; +LL | let _bad5 = "\0\x03"; | ~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad5 = "/0/x003"; +LL | let _bad5 = "\0\x003"; | ~~~~~~~~~ error: octal-looking escape in string literal --> $DIR/octal_escapes.rs:11:17 | -LL | let _bad6 = "Text-/055/077-MoreText"; +LL | let _bad6 = "Text-\055\077-MoreText"; | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad6 = "Text-/x2d/x3f-MoreText"; +LL | let _bad6 = "Text-\x2d\x3f-MoreText"; | ~~~~~~~~~~~~~~~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad6 = "Text-/x0055/x0077-MoreText"; +LL | let _bad6 = "Text-\x0055\x0077-MoreText"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal --> $DIR/octal_escapes.rs:12:17 | -LL | let _bad7 = "EvenMoreText-/01/02-ShortEscapes"; +LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad7 = "EvenMoreText-/x01/x02-ShortEscapes"; +LL | let _bad7 = "EvenMoreText-\x01\x02-ShortEscapes"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad7 = "EvenMoreText-/x001/x002-ShortEscapes"; +LL | let _bad7 = "EvenMoreText-\x001\x002-ShortEscapes"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal --> $DIR/octal_escapes.rs:13:17 | -LL | let _bad8 = "锈/01锈"; +LL | let _bad8 = "锈\01锈"; | ^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad8 = "锈/x01锈"; +LL | let _bad8 = "锈\x01锈"; | ~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad8 = "锈/x001锈"; +LL | let _bad8 = "锈\x001锈"; | ~~~~~~~~~~~ error: octal-looking escape in string literal --> $DIR/octal_escapes.rs:14:17 | -LL | let _bad9 = "锈/011锈"; +LL | let _bad9 = "锈\011锈"; | ^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad9 = "锈/x09锈"; +LL | let _bad9 = "锈\x09锈"; | ~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad9 = "锈/x0011锈"; +LL | let _bad9 = "锈\x0011锈"; | ~~~~~~~~~~~~ error: aborting due to 9 previous errors diff --git a/tests/ui/path_buf_push_overwrite.stderr b/tests/ui/path_buf_push_overwrite.stderr index 1922a6ab692ec..c94b321780497 100644 --- a/tests/ui/path_buf_push_overwrite.stderr +++ b/tests/ui/path_buf_push_overwrite.stderr @@ -1,4 +1,4 @@ -error: calling `push` with '/' or '/' (file system root) will overwrite the previous path definition +error: calling `push` with '/' or '\' (file system root) will overwrite the previous path definition --> $DIR/path_buf_push_overwrite.rs:6:12 | LL | x.push("/bar"); diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index f3de601ed84cc..7130edaa7f458 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -1,74 +1,74 @@ error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:7:5 | -LL | print!("Hello/n"); +LL | print!("Hello\n"); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-with-newline` implied by `-D warnings` help: use `println!` instead | -LL - print!("Hello/n"); +LL - print!("Hello\n"); LL + println!("Hello"); | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:8:5 | -LL | print!("Hello {}/n", "world"); +LL | print!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("Hello {}/n", "world"); +LL - print!("Hello {}\n", "world"); LL + println!("Hello {}", "world"); | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:9:5 | -LL | print!("Hello {} {}/n", "world", "#2"); +LL | print!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("Hello {} {}/n", "world", "#2"); +LL - print!("Hello {} {}\n", "world", "#2"); LL + println!("Hello {} {}", "world", "#2"); | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:10:5 | -LL | print!("{}/n", 1265); +LL | print!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("{}/n", 1265); +LL - print!("{}\n", 1265); LL + println!("{}", 1265); | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:11:5 | -LL | print!("/n"); +LL | print!("\n"); | ^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("/n"); +LL - print!("\n"); LL + println!(); | error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:30:5 | -LL | print!("///n"); // should fail +LL | print!("\\\n"); // should fail | ^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("///n"); // should fail -LL + println!("//"); // should fail +LL - print!("\\\n"); // should fail +LL + println!("\\"); // should fail | error: using `print!()` with a format string that ends in a single newline @@ -104,13 +104,13 @@ LL ~ error: using `print!()` with a format string that ends in a single newline --> $DIR/print_with_newline.rs:49:5 | -LL | print!("//r/n"); // should fail +LL | print!("\\r\n"); // should fail | ^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("//r/n"); // should fail -LL + println!("//r"); // should fail +LL - print!("\\r\n"); // should fail +LL + println!("\\r"); // should fail | error: aborting due to 9 previous errors diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index 21f1cb44460ef..4f758799f73c6 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -70,7 +70,7 @@ error: regex parse error: error: unclosed group --> $DIR/regex.rs:39:37 | -LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]); +LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ error: regex parse error: @@ -79,16 +79,16 @@ error: regex parse error: error: unclosed group --> $DIR/regex.rs:40:39 | -LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]); +LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ error: regex parse error: - /b/c + \b\c ^^ error: unrecognized escape sequence --> $DIR/regex.rs:47:42 | -LL | let escaped_string_span = Regex::new("//b//c"); +LL | let escaped_string_span = Regex::new("\\b\\c"); | ^^^^^^^^ | = help: consider using a raw string literal: `r".."` @@ -156,7 +156,7 @@ LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); error: trivial regex --> $DIR/regex.rs:70:40 | -LL | let trivial_backslash = Regex::new("a//.b"); +LL | let trivial_backslash = Regex::new("a\\.b"); | ^^^^^^^ | = help: consider using `str::contains` diff --git a/tests/ui/single_char_add_str.stderr b/tests/ui/single_char_add_str.stderr index 55d91583ad04d..cea9ba7235dea 100644 --- a/tests/ui/single_char_add_str.stderr +++ b/tests/ui/single_char_add_str.stderr @@ -10,19 +10,19 @@ error: calling `push_str()` using a single-character string literal --> $DIR/single_char_add_str.rs:15:5 | LL | string.push_str("'"); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/'')` + | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\'')` error: calling `push_str()` using a single-character string literal --> $DIR/single_char_add_str.rs:20:5 | -LL | string.push_str("/x52"); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/x52')` +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 --> $DIR/single_char_add_str.rs:21:5 | -LL | string.push_str("/u{0052}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/u{0052}')` +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 --> $DIR/single_char_add_str.rs:22:5 @@ -46,19 +46,19 @@ error: calling `insert_str()` using a single-character string literal --> $DIR/single_char_add_str.rs:30:5 | LL | string.insert_str(1, "'"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(1, '/'')` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(1, '\'')` error: calling `insert_str()` using a single-character string literal --> $DIR/single_char_add_str.rs:35:5 | -LL | string.insert_str(0, "/x52"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/x52')` +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 --> $DIR/single_char_add_str.rs:36:5 | -LL | string.insert_str(0, "/u{0052}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/u{0052}')` +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 --> $DIR/single_char_add_str.rs:38:5 @@ -82,7 +82,7 @@ error: calling `insert_str()` using a single-character string literal --> $DIR/single_char_add_str.rs:42:5 | LL | string.insert_str(Y, r##"'"##); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '/'')` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '\'')` error: calling `insert_str()` using a single-character string literal --> $DIR/single_char_add_str.rs:44:5 diff --git a/tests/ui/single_char_pattern.stderr b/tests/ui/single_char_pattern.stderr index 0d4c154af19c7..f11ab12edee93 100644 --- a/tests/ui/single_char_pattern.stderr +++ b/tests/ui/single_char_pattern.stderr @@ -165,20 +165,20 @@ LL | x.replacen("x", "y", 3); error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:42:13 | -LL | x.split("/n"); - | ^^^^ help: try using a `char` instead: `'/n'` +LL | x.split("\n"); + | ^^^^ help: try using a `char` instead: `'\n'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:43:13 | LL | x.split("'"); - | ^^^ help: try using a `char` instead: `'/''` + | ^^^ help: try using a `char` instead: `'\''` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:44:13 | -LL | x.split("/'"); - | ^^^^ help: try using a `char` instead: `'/''` +LL | x.split("\'"); + | ^^^^ help: try using a `char` instead: `'\''` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:49:31 @@ -189,8 +189,8 @@ LL | x.replace(';', ",").split(","); // issue #2978 error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:50:19 | -LL | x.starts_with("/x03"); // issue #2996 - | ^^^^^^ help: try using a `char` instead: `'/x03'` +LL | x.starts_with("\x03"); // issue #2996 + | ^^^^^^ help: try using a `char` instead: `'\x03'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:57:13 @@ -214,7 +214,7 @@ error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:60:13 | LL | x.split(r###"'"###); - | ^^^^^^^^^^ help: try using a `char` instead: `'/''` + | ^^^^^^^^^^ help: try using a `char` instead: `'\''` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:61:13 @@ -225,14 +225,14 @@ LL | x.split(r###"#"###); error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:63:13 | -LL | x.split(r#"/"#); - | ^^^^^^ help: try using a `char` instead: `'//'` +LL | x.split(r#"\"#); + | ^^^^^^ help: try using a `char` instead: `'\\'` error: single-character string constant used as pattern --> $DIR/single_char_pattern.rs:64:13 | -LL | x.split(r"/"); - | ^^^^ help: try using a `char` instead: `'//'` +LL | x.split(r"\"); + | ^^^^ help: try using a `char` instead: `'\\'` error: aborting due to 39 previous errors diff --git a/tests/ui/starts_ends_with.stderr b/tests/ui/starts_ends_with.stderr index 1e26bee7aa177..48d561bc4b8ec 100644 --- a/tests/ui/starts_ends_with.stderr +++ b/tests/ui/starts_ends_with.stderr @@ -15,14 +15,14 @@ LL | Some(' ') != "".chars().next(); error: you should use the `starts_with` method --> $DIR/starts_ends_with.rs:11:5 | -LL | "".chars().next() == Some('/n'); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with('/n')` +LL | "".chars().next() == Some('\n'); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with('\n')` error: you should use the `starts_with` method --> $DIR/starts_ends_with.rs:12:5 | -LL | Some('/n') != "".chars().next(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with('/n')` +LL | Some('\n') != "".chars().next(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with('\n')` error: you should use the `starts_with` method --> $DIR/starts_ends_with.rs:17:8 @@ -59,8 +59,8 @@ LL | if s.chars().next_back().unwrap() != 'o' { error: you should use the `ends_with` method --> $DIR/starts_ends_with.rs:37:8 | -LL | if s.chars().last().unwrap() != '/n' { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('/n')` +LL | if s.chars().last().unwrap() != '\n' { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('\n')` error: you should use the `ends_with` method --> $DIR/starts_ends_with.rs:45:5 @@ -89,14 +89,14 @@ LL | Some(' ') != "".chars().next_back(); error: you should use the `ends_with` method --> $DIR/starts_ends_with.rs:51:5 | -LL | "".chars().last() == Some('/n'); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with('/n')` +LL | "".chars().last() == Some('\n'); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with('\n')` error: you should use the `ends_with` method --> $DIR/starts_ends_with.rs:52:5 | -LL | Some('/n') != "".chars().last(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with('/n')` +LL | Some('\n') != "".chars().last(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with('\n')` error: aborting due to 16 previous errors diff --git a/tests/ui/string_lit_as_bytes.stderr b/tests/ui/string_lit_as_bytes.stderr index 985432e04c47d..73576f9f30000 100644 --- a/tests/ui/string_lit_as_bytes.stderr +++ b/tests/ui/string_lit_as_bytes.stderr @@ -44,8 +44,8 @@ LL | let includestr = include_str!("string_lit_as_bytes.rs").as_bytes(); error: calling `as_bytes()` on a string literal --> $DIR/string_lit_as_bytes.rs:40:13 | -LL | let _ = "string with newline/t/n".as_bytes(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline/t/n"` +LL | let _ = "string with newline\t\n".as_bytes(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline\t\n"` error: aborting due to 7 previous errors diff --git a/tests/ui/string_lit_chars_any.stderr b/tests/ui/string_lit_chars_any.stderr index 270728bb8415f..dac9a90b34181 100644 --- a/tests/ui/string_lit_chars_any.stderr +++ b/tests/ui/string_lit_chars_any.stderr @@ -1,57 +1,57 @@ error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> $DIR/string_lit_chars_any.rs:18:5 | -LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| x == c); +LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::string-lit-chars-any` implied by `-D warnings` help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> $DIR/string_lit_chars_any.rs:19:5 | -LL | r#"/.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); +LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> $DIR/string_lit_chars_any.rs:20:5 | -LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| c == x); +LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> $DIR/string_lit_chars_any.rs:21:5 | -LL | r#"/.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); +LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: usage of `.chars().any(...)` to check if a char matches any from a string literal --> $DIR/string_lit_chars_any.rs:23:5 | -LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); +LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 5 previous errors diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index 74ee48cc2f977..4f3bad6c03296 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -2,7 +2,7 @@ error: invisible character detected --> $DIR/unicode.rs:5: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"` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{200B}< is a ZWS, and \u{200B}another"` | = note: `-D clippy::invisible-characters` implied by `-D warnings` @@ -10,13 +10,13 @@ error: invisible character detected --> $DIR/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"` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{AD}< is a SHY, and \u{AD}another"` error: invisible character detected --> $DIR/unicode.rs:9: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"` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{2060}< is a WJ, and \u{2060}another"` error: non-NFC Unicode sequence detected --> $DIR/unicode.rs:15:12 @@ -30,7 +30,7 @@ error: literal non-ASCII character detected --> $DIR/unicode.rs:23:16 | LL | print!("Üben!"); - | ^^^^^^^ help: consider replacing the string with: `"/u{dc}ben!"` + | ^^^^^^^ help: consider replacing the string with: `"\u{dc}ben!"` | note: the lint level is defined here --> $DIR/unicode.rs:20:13 @@ -42,19 +42,19 @@ error: literal non-ASCII character detected --> $DIR/unicode.rs:29:36 | LL | const _EMPTY_BLOCK: char = '▱'; - | ^^^ help: consider replacing the string with: `'/u{25b1}'` + | ^^^ help: consider replacing the string with: `'\u{25b1}'` error: literal non-ASCII character detected --> $DIR/unicode.rs:30:35 | LL | const _FULL_BLOCK: char = '▰'; - | ^^^ help: consider replacing the string with: `'/u{25b0}'` + | ^^^ help: consider replacing the string with: `'\u{25b0}'` error: literal non-ASCII character detected --> $DIR/unicode.rs:50: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}"` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 --> $DIR/unicode.rs:39:17 diff --git a/tests/ui/uninlined_format_args.stderr b/tests/ui/uninlined_format_args.stderr index 44ca61f008c5f..c73c648738656 100644 --- a/tests/ui/uninlined_format_args.stderr +++ b/tests/ui/uninlined_format_args.stderr @@ -216,24 +216,24 @@ LL + println!("{val}"); error: variables can be used directly in the `format!` string --> $DIR/uninlined_format_args.rs:72:5 | -LL | println!("val='{/t }'", local_i32); +LL | println!("val='{\t }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: change this to | -LL - println!("val='{/t }'", local_i32); +LL - println!("val='{\t }'", local_i32); LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string --> $DIR/uninlined_format_args.rs:73:5 | -LL | println!("val='{/n }'", local_i32); +LL | println!("val='{\n }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: change this to | -LL - println!("val='{/n }'", local_i32); +LL - println!("val='{\n }'", local_i32); LL + println!("val='{local_i32}'"); | diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index 61cdf6112e0ef..b28bee56dc248 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -34,12 +34,12 @@ LL + writeln!(v, r"{{hello}}"); error: literal with an empty format string --> $DIR/write_literal_2.rs:12:23 | -LL | writeln!(v, "{}", '/''); +LL | writeln!(v, "{}", '\''); | ^^^^ | help: try | -LL - writeln!(v, "{}", '/''); +LL - writeln!(v, "{}", '\''); LL + writeln!(v, "'"); | @@ -52,7 +52,7 @@ LL | writeln!(v, "{}", '"'); help: try | LL - writeln!(v, "{}", '"'); -LL + writeln!(v, "/""); +LL + writeln!(v, "\""); | error: literal with an empty format string @@ -64,25 +64,25 @@ LL | writeln!(v, r"{}", '"'); error: literal with an empty format string --> $DIR/write_literal_2.rs:15:24 | -LL | writeln!(v, r"{}", '/''); +LL | writeln!(v, r"{}", '\''); | ^^^^ | help: try | -LL - writeln!(v, r"{}", '/''); +LL - writeln!(v, r"{}", '\''); LL + writeln!(v, r"'"); | error: literal with an empty format string --> $DIR/write_literal_2.rs:19:9 | -LL | / "hello / +LL | / "hello \ LL | | world!" | |_______________^ | help: try | -LL ~ "some hello / +LL ~ "some hello \ LL ~ world!" | @@ -94,8 +94,8 @@ LL | "1", "2", "3", | help: try | -LL ~ "some 1/ -LL ~ {} // {}", "2", "3", +LL ~ "some 1\ +LL ~ {} \\ {}", "2", "3", | error: literal with an empty format string @@ -106,7 +106,7 @@ LL | "1", "2", "3", | help: try | -LL ~ 2 // {}", +LL ~ 2 \\ {}", LL ~ "1", "3", | @@ -118,68 +118,68 @@ LL | "1", "2", "3", | help: try | -LL ~ {} // 3", +LL ~ {} \\ 3", LL ~ "1", "2", | error: literal with an empty format string --> $DIR/write_literal_2.rs:28:23 | -LL | writeln!(v, "{}", "//"); +LL | writeln!(v, "{}", "\\"); | ^^^^ | help: try | -LL - writeln!(v, "{}", "//"); -LL + writeln!(v, "//"); +LL - writeln!(v, "{}", "\\"); +LL + writeln!(v, "\\"); | error: literal with an empty format string --> $DIR/write_literal_2.rs:29:24 | -LL | writeln!(v, r"{}", "//"); +LL | writeln!(v, r"{}", "\\"); | ^^^^ | help: try | -LL - writeln!(v, r"{}", "//"); -LL + writeln!(v, r"/"); +LL - writeln!(v, r"{}", "\\"); +LL + writeln!(v, r"\"); | error: literal with an empty format string --> $DIR/write_literal_2.rs:30:26 | -LL | writeln!(v, r#"{}"#, "//"); +LL | writeln!(v, r#"{}"#, "\\"); | ^^^^ | help: try | -LL - writeln!(v, r#"{}"#, "//"); -LL + writeln!(v, r#"/"#); +LL - writeln!(v, r#"{}"#, "\\"); +LL + writeln!(v, r#"\"#); | error: literal with an empty format string --> $DIR/write_literal_2.rs:31:23 | -LL | writeln!(v, "{}", r"/"); +LL | writeln!(v, "{}", r"\"); | ^^^^ | help: try | -LL - writeln!(v, "{}", r"/"); -LL + writeln!(v, "//"); +LL - writeln!(v, "{}", r"\"); +LL + writeln!(v, "\\"); | error: literal with an empty format string --> $DIR/write_literal_2.rs:32:23 | -LL | writeln!(v, "{}", "/r"); +LL | writeln!(v, "{}", "\r"); | ^^^^ | help: try | -LL - writeln!(v, "{}", "/r"); -LL + writeln!(v, "/r"); +LL - writeln!(v, "{}", "\r"); +LL + writeln!(v, "\r"); | error: literal with an empty format string diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index 72c4bbff14b9b..cec236038eb02 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -1,74 +1,74 @@ error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:12:5 | -LL | write!(v, "Hello/n"); +LL | write!(v, "Hello\n"); | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::write-with-newline` implied by `-D warnings` help: use `writeln!` instead | -LL - write!(v, "Hello/n"); +LL - write!(v, "Hello\n"); LL + writeln!(v, "Hello"); | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:13:5 | -LL | write!(v, "Hello {}/n", "world"); +LL | write!(v, "Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "Hello {}/n", "world"); +LL - write!(v, "Hello {}\n", "world"); LL + writeln!(v, "Hello {}", "world"); | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:14:5 | -LL | write!(v, "Hello {} {}/n", "world", "#2"); +LL | write!(v, "Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "Hello {} {}/n", "world", "#2"); +LL - write!(v, "Hello {} {}\n", "world", "#2"); LL + writeln!(v, "Hello {} {}", "world", "#2"); | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:15:5 | -LL | write!(v, "{}/n", 1265); +LL | write!(v, "{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "{}/n", 1265); +LL - write!(v, "{}\n", 1265); LL + writeln!(v, "{}", 1265); | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:16:5 | -LL | write!(v, "/n"); +LL | write!(v, "\n"); | ^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "/n"); +LL - write!(v, "\n"); LL + writeln!(v); | error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:35:5 | -LL | write!(v, "///n"); // should fail +LL | write!(v, "\\\n"); // should fail | ^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "///n"); // should fail -LL + writeln!(v, "//"); // should fail +LL - write!(v, "\\\n"); // should fail +LL + writeln!(v, "\\"); // should fail | error: using `write!()` with a format string that ends in a single newline @@ -106,13 +106,13 @@ LL ~ v error: using `write!()` with a format string that ends in a single newline --> $DIR/write_with_newline.rs:56:5 | -LL | write!(v, "//r/n"); +LL | write!(v, "\\r\n"); | ^^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "//r/n"); -LL + writeln!(v, "//r"); +LL - write!(v, "\\r\n"); +LL + writeln!(v, "\\r"); | error: aborting due to 9 previous errors From 89fdc3e383c3ebe3a2cbddd7b49cbfe6a6cf0cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 14 Aug 2023 19:25:01 +0000 Subject: [PATCH 28/79] Move scrutinee `HirId` into `MatchSource::TryDesugar` --- clippy_lints/src/dereference.rs | 3 ++- clippy_lints/src/matches/mod.rs | 2 +- clippy_lints/src/matches/try_err.rs | 2 +- clippy_lints/src/methods/clone_on_copy.rs | 2 +- clippy_lints/src/methods/str_splitn.rs | 2 +- clippy_lints/src/needless_question_mark.rs | 2 +- clippy_lints/src/question_mark_used.rs | 2 +- clippy_lints/src/redundant_closure_call.rs | 2 +- clippy_lints/src/returns.rs | 2 +- clippy_lints/src/unit_types/unit_arg.rs | 2 +- clippy_lints/src/useless_conversion.rs | 2 +- clippy_utils/src/check_proc_macro.rs | 2 +- clippy_utils/src/lib.rs | 2 +- clippy_utils/src/visitors.rs | 2 +- 14 files changed, 15 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index bc011a6c354cb..58c2785500013 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -802,7 +802,8 @@ fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> boo match parent.kind { ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _, _) if child.hir_id == e.hir_id => true, - ExprKind::Field(_, _) | ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) => true, + ExprKind::Match(.., MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar) + | ExprKind::Field(_, _) => true, _ => false, } } else { diff --git a/clippy_lints/src/matches/mod.rs b/clippy_lints/src/matches/mod.rs index 6d16d18875408..930386a60aa02 100644 --- a/clippy_lints/src/matches/mod.rs +++ b/clippy_lints/src/matches/mod.rs @@ -1038,7 +1038,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { wild_in_or_pats::check(cx, arms); } - if source == MatchSource::TryDesugar { + if let MatchSource::TryDesugar(_) = source { try_err::check(cx, expr, ex); } diff --git a/clippy_lints/src/matches/try_err.rs b/clippy_lints/src/matches/try_err.rs index 99a748489b470..0fd6f533db0d5 100644 --- a/clippy_lints/src/matches/try_err.rs +++ b/clippy_lints/src/matches/try_err.rs @@ -80,7 +80,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine /// Finds function return type by examining return expressions in match arms. fn find_return_type<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx ExprKind<'_>) -> Option> { - if let ExprKind::Match(_, arms, MatchSource::TryDesugar) = expr { + if let ExprKind::Match(_, arms, MatchSource::TryDesugar(_)) = expr { for arm in *arms { if let ExprKind::Ret(Some(ret)) = arm.body.kind { return Some(cx.typeck_results().expr_ty(ret)); diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs index 7eb325ee7b5e7..eb4f003d38ae5 100644 --- a/clippy_lints/src/methods/clone_on_copy.rs +++ b/clippy_lints/src/methods/clone_on_copy.rs @@ -64,7 +64,7 @@ pub(super) fn check( ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _)) ), ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id => true, - ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) + ExprKind::Match(_, _, MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar) | ExprKind::Field(..) | ExprKind::Index(..) => true, _ => false, diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index 41986551da472..7016ad0a80f15 100644 --- a/clippy_lints/src/methods/str_splitn.rs +++ b/clippy_lints/src/methods/str_splitn.rs @@ -236,7 +236,7 @@ fn indirect_usage<'tcx>( !matches!( node, Node::Expr(Expr { - kind: ExprKind::Match(.., MatchSource::TryDesugar), + kind: ExprKind::Match(.., MatchSource::TryDesugar(_)), .. }) ) diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs index e2a7ba02a043c..7b0f7eaf1f063 100644 --- a/clippy_lints/src/needless_question_mark.rs +++ b/clippy_lints/src/needless_question_mark.rs @@ -122,7 +122,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { } else { return; }; - if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar) = &arg.kind; + if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar(_)) = &arg.kind; if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind; if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)) = &called.kind; if expr.span.ctxt() == inner_expr.span.ctxt(); diff --git a/clippy_lints/src/question_mark_used.rs b/clippy_lints/src/question_mark_used.rs index ff66b8a009531..d0de33e3c4f14 100644 --- a/clippy_lints/src/question_mark_used.rs +++ b/clippy_lints/src/question_mark_used.rs @@ -34,7 +34,7 @@ declare_lint_pass!(QuestionMarkUsed => [QUESTION_MARK_USED]); impl<'tcx> LateLintPass<'tcx> for QuestionMarkUsed { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if let ExprKind::Match(_, _, MatchSource::TryDesugar) = expr.kind { + if let ExprKind::Match(_, _, MatchSource::TryDesugar(_)) = expr.kind { if !span_is_local(expr.span) { return; } diff --git a/clippy_lints/src/redundant_closure_call.rs b/clippy_lints/src/redundant_closure_call.rs index 4e3efe97b8c61..fc49b58e0a777 100644 --- a/clippy_lints/src/redundant_closure_call.rs +++ b/clippy_lints/src/redundant_closure_call.rs @@ -52,7 +52,7 @@ impl ReturnVisitor { impl<'tcx> Visitor<'tcx> for ReturnVisitor { fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) { - if let hir::ExprKind::Ret(_) | hir::ExprKind::Match(.., hir::MatchSource::TryDesugar) = ex.kind { + if let hir::ExprKind::Ret(_) | hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_)) = ex.kind { self.found_return = true; } else { hir_visit::walk_expr(self, ex); diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 351bacf5691f3..d6b9a49d2fe05 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { if !in_external_macro(cx.sess(), stmt.span) && let StmtKind::Semi(expr) = stmt.kind && let ExprKind::Ret(Some(ret)) = expr.kind - && let ExprKind::Match(.., MatchSource::TryDesugar) = ret.kind + && let ExprKind::Match(.., MatchSource::TryDesugar(_)) = ret.kind // Ensure this is not the final stmt, otherwise removing it would cause a compile error && let OwnerNode::Item(item) = cx.tcx.hir().owner(cx.tcx.hir().get_parent_item(expr.hir_id)) && let ItemKind::Fn(_, _, body) = item.kind diff --git a/clippy_lints/src/unit_types/unit_arg.rs b/clippy_lints/src/unit_types/unit_arg.rs index dd120599c04e1..462b1aa8153e7 100644 --- a/clippy_lints/src/unit_types/unit_arg.rs +++ b/clippy_lints/src/unit_types/unit_arg.rs @@ -42,7 +42,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if cx.typeck_results().expr_ty(arg).is_unit() && !utils::is_unit_literal(arg) { !matches!( &arg.kind, - ExprKind::Match(.., MatchSource::TryDesugar) | ExprKind::Path(..) + ExprKind::Match(.., MatchSource::TryDesugar(_)) | ExprKind::Path(..) ) } else { false diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index 92b694d307600..bd4dc07a42bfa 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { } match e.kind { - ExprKind::Match(_, arms, MatchSource::TryDesugar) => { + ExprKind::Match(_, arms, MatchSource::TryDesugar(_)) => { let (ExprKind::Ret(Some(e)) | ExprKind::Break(_, Some(e))) = arms[0].body.kind else { return; }; diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs index 60fab1ec41aeb..6be8b8bb91696 100644 --- a/clippy_utils/src/check_proc_macro.rs +++ b/clippy_utils/src/check_proc_macro.rs @@ -149,7 +149,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { (Pat::Str("for"), Pat::Str("}")) }, ExprKind::Match(_, _, MatchSource::Normal) => (Pat::Str("match"), Pat::Str("}")), - ExprKind::Match(e, _, MatchSource::TryDesugar) => (expr_search_pat(tcx, e).0, Pat::Str("?")), + ExprKind::Match(e, _, MatchSource::TryDesugar(_)) => (expr_search_pat(tcx, e).0, Pat::Str("?")), ExprKind::Match(e, _, MatchSource::AwaitDesugar) | ExprKind::Yield(e, YieldSource::Await { .. }) => { (expr_search_pat(tcx, e).0, Pat::Str("await")) }, diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 171b7faf21960..09576d67b23be 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1765,7 +1765,7 @@ pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tc if let ExprKind::Match(_, arms, ref source) = expr.kind { // desugared from a `?` operator - if *source == MatchSource::TryDesugar { + if let MatchSource::TryDesugar(_) = *source { return Some(expr); } diff --git a/clippy_utils/src/visitors.rs b/clippy_utils/src/visitors.rs index f83988a6e325a..3b47a451345eb 100644 --- a/clippy_utils/src/visitors.rs +++ b/clippy_utils/src/visitors.rs @@ -161,7 +161,7 @@ pub fn for_each_expr_with_closures<'tcx, B, C: Continue>( /// returns `true` if expr contains match expr desugared from try fn contains_try(expr: &hir::Expr<'_>) -> bool { for_each_expr(expr, |e| { - if matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar)) { + if matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar(_))) { ControlFlow::Break(()) } else { ControlFlow::Continue(()) From d0a26f1c9c17ea4a6fda68235725d7ba8dbf16ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 14 Aug 2023 22:00:46 +0000 Subject: [PATCH 29/79] bless clippy test --- tests/ui/if_same_then_else2.rs | 2 +- tests/ui/if_same_then_else2.stderr | 21 +-------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/tests/ui/if_same_then_else2.rs b/tests/ui/if_same_then_else2.rs index 0b171f21d0cc4..c545434efe5b5 100644 --- a/tests/ui/if_same_then_else2.rs +++ b/tests/ui/if_same_then_else2.rs @@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> { }; if true { - //~^ ERROR: this `if` has identical blocks + // FIXME: should emit "this `if` has identical blocks" Ok("foo")?; } else { Ok("foo")?; diff --git a/tests/ui/if_same_then_else2.stderr b/tests/ui/if_same_then_else2.stderr index 56e5f3e45b22c..37fe787d1de3a 100644 --- a/tests/ui/if_same_then_else2.stderr +++ b/tests/ui/if_same_then_else2.stderr @@ -82,25 +82,6 @@ LL | | f32::NAN LL | | }; | |_____^ -error: this `if` has identical blocks - --> $DIR/if_same_then_else2.rs:100:13 - | -LL | if true { - | _____________^ -LL | | -LL | | Ok("foo")?; -LL | | } else { - | |_____^ - | -note: same as this - --> $DIR/if_same_then_else2.rs:103:12 - | -LL | } else { - | ____________^ -LL | | Ok("foo")?; -LL | | } - | |_____^ - error: this `if` has identical blocks --> $DIR/if_same_then_else2.rs:124:20 | @@ -122,5 +103,5 @@ LL | | return Ok(&foo[0..]); LL | | } | |_____^ -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors From aa8995e589c7f4a433ae6fe27b319ff9898b523a Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Tue, 15 Aug 2023 09:41:15 +0800 Subject: [PATCH 30/79] allow calling `to_owned` with borrowed value for [`implicit_clone`] --- clippy_lints/src/methods/implicit_clone.rs | 1 + tests/ui/implicit_clone.fixed | 2 +- tests/ui/implicit_clone.stderr | 8 +------- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/methods/implicit_clone.rs b/clippy_lints/src/methods/implicit_clone.rs index 043425300d8bc..e91ce64d8c8c8 100644 --- a/clippy_lints/src/methods/implicit_clone.rs +++ b/clippy_lints/src/methods/implicit_clone.rs @@ -17,6 +17,7 @@ pub fn check(cx: &LateContext<'_>, method_name: &str, expr: &hir::Expr<'_>, recv let return_type = cx.typeck_results().expr_ty(expr); let input_type = cx.typeck_results().expr_ty(recv); let (input_type, ref_count) = peel_mid_ty_refs(input_type); + if !(ref_count > 0 && is_diag_trait_item(cx, method_def_id, sym::ToOwned)); if let Some(ty_name) = input_type.ty_adt_def().map(|adt_def| cx.tcx.item_name(adt_def.did())); if return_type == input_type; if let Some(clone_trait) = cx.tcx.lang_items().clone_trait(); diff --git a/tests/ui/implicit_clone.fixed b/tests/ui/implicit_clone.fixed index 04644b111bffa..98556b4dd303b 100644 --- a/tests/ui/implicit_clone.fixed +++ b/tests/ui/implicit_clone.fixed @@ -67,7 +67,7 @@ fn main() { let vec_ref = &vec; let _ = return_owned_from_slice(vec_ref); - let _ = vec_ref.clone(); + let _ = vec_ref.to_owned(); let _ = vec_ref.clone(); // we expect no lint for this diff --git a/tests/ui/implicit_clone.stderr b/tests/ui/implicit_clone.stderr index 0f4124241907f..59f000c06e200 100644 --- a/tests/ui/implicit_clone.stderr +++ b/tests/ui/implicit_clone.stderr @@ -12,12 +12,6 @@ error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type LL | let _ = vec.to_vec(); | ^^^^^^^^^^^^ help: consider using: `vec.clone()` -error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:70:13 - | -LL | let _ = vec_ref.to_owned(); - | ^^^^^^^^^^^^^^^^^^ help: consider using: `vec_ref.clone()` - error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type --> $DIR/implicit_clone.rs:71:13 | @@ -72,5 +66,5 @@ error: implicitly cloning a `PathBuf` by calling `to_path_buf` on its dereferenc LL | let _ = pathbuf_ref.to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(**pathbuf_ref).clone()` -error: aborting due to 12 previous errors +error: aborting due to 11 previous errors From 97d31c8ae0b8505e3a25385da16562bbb6fa9c33 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 3 Apr 2023 17:32:09 +0200 Subject: [PATCH 31/79] New chapter: Defining Lints Co-authored-by: Nahua --- book/src/SUMMARY.md | 1 + book/src/development/defining_lints.md | 161 +++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 book/src/development/defining_lints.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 22fbdce75e8f8..f6378b1fb90f9 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -13,6 +13,7 @@ - [Development](development/README.md) - [Basics](development/basics.md) - [Adding Lints](development/adding_lints.md) + - [Defining Lints](development/defining_lints.md) - [Lint Passes](development/lint_passes.md) - [Type Checking](development/type_checking.md) - [Macro Expansions](development/macro_expansions.md) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md new file mode 100644 index 0000000000000..17e4c1a1181f7 --- /dev/null +++ b/book/src/development/defining_lints.md @@ -0,0 +1,161 @@ +# Define New Lints + +The first step in the journey of a new lint is the definition +and registration of the lint in Clippy's codebase. +We can use the Clippy dev tools to handle this step since setting up the +lint involves some boilerplate code. + +In our example, we're going to create a lint to detect functions named `foo` because it is a highly non-descriptive name for a function, so we want to trigger this and fix it early in the development process. + +## Lint name + +A good lint name is important, it is usually given by the issue you're fixing (in the **Lint name** field). If you're unsure if the name you chose fits the lint, you can check the [lint naming guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy team member will alert you in the PR process. + +If you're still unsure, you can ask on the [Zulip] or on the Github issue / PR. + +--- + +We'll name our example lint that detects functions named "foo" `foo_functions`. Check the [lint naming guidelines][lint_naming] to see why this name makes sense. + +## Add and Register the Lint + +Now that a name is chosen, we shall register `foo_functions` as a lint to the codebase. +There are two ways to register a lint. + +### Standalone + +If you believe that this new lint is a standalone lint (that doesn't belong to any specific [type](#lint-types) like `functions` or `loops`), you can run the following +command in your Clippy project: + +```sh +$ cargo dev new_lint --name=foo_functions --pass=late --category=pedantic +``` + +There are two things to note here: + +1. We set `--pass=late` in this command to do a late lint pass. The alternative +is an `early` lint pass. We will discuss this difference in a later chapter. + +2. If not provided, the `category` of this new lint will default to `nursery`. +See Clippy's [lint types](../lints.md) for more information on categories. + +The `cargo dev new_lint` command will create a new file: `clippy_lints/src/foo_functions.rs` +as well as [register the lint](#lint-registration). + +Overall, you should notice that the following files are modified or created: + +```sh +$ git status +On branch foo_functions +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: CHANGELOG.md + modified: clippy_lints/src/lib.register_lints.rs + modified: clippy_lints/src/lib.register_pedantic.rs + modified: clippy_lints/src/lib.rs + +Untracked files: + (use "git add ..." to include in what will be committed) + clippy_lints/src/foo_functions.rs + tests/ui/foo_functions.rs +``` + +### Specific Type + +If you believe that this new lint belongs to a specific type of lints, +you can run `cargo dev new_lint` with a `--type` option. + +Since our `foo_functions` lint is related to function calls, one could +argue that we should put it into a group of lints that detect some behaviors +of functions, we can put it in the `functions` group. + +Let's run the following command in your Clippy project: + +```sh +$ cargo dev new_lint --name=foo_functions --type=functions --category=pedantic +``` + +This command will create, among other things, a new file: +`clippy_lints/src/{type}/foo_functions.rs`. +In our case, the path will be `clippy_lints/src/functions/foo_functions.rs`. + +Notice how this command has a `--type` flag instead of `--pass`. Unlike a standalone +definition, this lint won't be registered in the traditional sense. Instead, you will +call your lint from within the type's lint pass, found in `clippy_lints/src/{type}/mod.rs`. + +A _type_ is just the name of a directory in `clippy_lints/src`, like `functions` in +the example command. Clippy groups together some lints that share common behaviors, +so if your lint falls into one, it would be best to add it to that type. +Read more about [lint types](#lint-types) below. + +Overall, you should notice that the following files are modified or created: + +```sh +$ git status +On branch foo_functions +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: CHANGELOG.md + modified: clippy_lints/src/declared_lints.rs + modified: clippy_lints/src/functions/mod.rs + +Untracked files: + (use "git add ..." to include in what will be committed) + clippy_lints/src/functions/foo_functions.rs + tests/ui/foo_functions.rs +``` + +## Lint registration + +If we run the `cargo dev new_lint` command for a new lint, +the lint will be automatically registered and there is nothing more to do. + +However, sometimes we might want to declare a new lint by hand. +In this case, we'd use `cargo dev update_lints` command afterwards. + +When a lint is manually declared, we might need to register the lint pass +manually in the `register_plugins` function in `clippy_lints/src/lib.rs`: + +```rust +store.register_late_pass(|| Box::new(foo_functions::FooFunctions)); +``` + +As you might have guessed, where there's something late, there is something early: +in Clippy there is a `register_early_pass` method as well. +More on early vs. late passes in a later chapter. + +Without a call to one of `register_early_pass` or `register_late_pass`, +the lint pass in question will not be run. + +## Lint types + +As of the writing of this documentation update, there are 12 categories (a.k.a. _types_) +of lints besides the numerous standalone lints living under `clippy_lints/src/`: + +- `cargo` +- `casts` +- `functions` +- `loops` +- `matches` +- `methods` +- `misc_early` +- `operators` +- `transmute` +- `types` +- `unit_types` +- `utils / internal` (Clippy internal lints) + +These categories group together lints that share some common behaviors. +For instance, as we have mentioned earlier, `functions` groups together lints +that deal with some aspects of function calls in Rust. + +For more information, feel free to compare the lint files under any category +with [All Clippy lints][all_lints] or +ask one of the maintainers. + +[all_lints]: https://rust-lang.github.io/rust-clippy/master/ +[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints +[clippy_team_members]: https://www.rust-lang.org/governance/teams/dev-tools#Clippy%20team +[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy \ No newline at end of file From c22906b37f81879f09c880154e815b0d522d21c2 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Tue, 4 Apr 2023 11:12:54 +0200 Subject: [PATCH 32/79] Fix CI formatting issues --- book/src/development/defining_lints.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 17e4c1a1181f7..62736433fbca7 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -5,17 +5,21 @@ and registration of the lint in Clippy's codebase. We can use the Clippy dev tools to handle this step since setting up the lint involves some boilerplate code. -In our example, we're going to create a lint to detect functions named `foo` because it is a highly non-descriptive name for a function, so we want to trigger this and fix it early in the development process. +In our example, we're going to create a lint to detect functions named `foo` because it is a highly non-descriptive +name for a function, so we want to trigger this and fix it early in the development process. ## Lint name -A good lint name is important, it is usually given by the issue you're fixing (in the **Lint name** field). If you're unsure if the name you chose fits the lint, you can check the [lint naming guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy team member will alert you in the PR process. +A good lint name is important, it is usually given by the issue you're fixing (in the **Lint name** field). If you're +unsure if the name you chose fits the lint, you can check the [lint naming guidelines][lint_naming]. Don't worry, if +the lint name doesn't fit, a Clippy team member will alert you in the PR process. If you're still unsure, you can ask on the [Zulip] or on the Github issue / PR. --- -We'll name our example lint that detects functions named "foo" `foo_functions`. Check the [lint naming guidelines][lint_naming] to see why this name makes sense. +We'll name our example lint that detects functions named "foo" `foo_functions`. Check the +[lint naming guidelines][lint_naming] to see why this name makes sense. ## Add and Register the Lint @@ -157,5 +161,4 @@ ask one of the maintainers. [all_lints]: https://rust-lang.github.io/rust-clippy/master/ [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints -[clippy_team_members]: https://www.rust-lang.org/governance/teams/dev-tools#Clippy%20team -[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy \ No newline at end of file +[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy From 735380b2cc3fd760934698c5f00e3faf1e5bea12 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 10 Apr 2023 21:42:00 +0200 Subject: [PATCH 33/79] Try to clear up confusion between `type` and `category`. --- book/src/development/defining_lints.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 62736433fbca7..5b669d33d1058 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -41,7 +41,6 @@ There are two things to note here: is an `early` lint pass. We will discuss this difference in a later chapter. 2. If not provided, the `category` of this new lint will default to `nursery`. -See Clippy's [lint types](../lints.md) for more information on categories. The `cargo dev new_lint` command will create a new file: `clippy_lints/src/foo_functions.rs` as well as [register the lint](#lint-registration). @@ -67,6 +66,8 @@ Untracked files: ### Specific Type +> **Note**: Lint types are listed in the ["Lint types"](#lint-types) section + If you believe that this new lint belongs to a specific type of lints, you can run `cargo dev new_lint` with a `--type` option. @@ -135,7 +136,7 @@ the lint pass in question will not be run. ## Lint types -As of the writing of this documentation update, there are 12 categories (a.k.a. _types_) +As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) of lints besides the numerous standalone lints living under `clippy_lints/src/`: - `cargo` From 74654362703de5d274e7fcc4e29ce7f6a114e566 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 17 Apr 2023 23:50:08 +0200 Subject: [PATCH 34/79] Improve briefness --- book/src/development/defining_lints.md | 90 ++++++++++++++++++-------- 1 file changed, 62 insertions(+), 28 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 5b669d33d1058..44806c0cb8519 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -10,12 +10,9 @@ name for a function, so we want to trigger this and fix it early in the developm ## Lint name -A good lint name is important, it is usually given by the issue you're fixing (in the **Lint name** field). If you're -unsure if the name you chose fits the lint, you can check the [lint naming guidelines][lint_naming]. Don't worry, if +A good lint name is important, make sure to check the [lint naming guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy team member will alert you in the PR process. -If you're still unsure, you can ask on the [Zulip] or on the Github issue / PR. - --- We'll name our example lint that detects functions named "foo" `foo_functions`. Check the @@ -32,7 +29,7 @@ If you believe that this new lint is a standalone lint (that doesn't belong to a command in your Clippy project: ```sh -$ cargo dev new_lint --name=foo_functions --pass=late --category=pedantic +$ cargo dev new_lint --name=lint_name --pass=late --category=pedantic ``` There are two things to note here: @@ -64,6 +61,7 @@ Untracked files: tests/ui/foo_functions.rs ``` + ### Specific Type > **Note**: Lint types are listed in the ["Lint types"](#lint-types) section @@ -112,29 +110,7 @@ Untracked files: tests/ui/foo_functions.rs ``` -## Lint registration - -If we run the `cargo dev new_lint` command for a new lint, -the lint will be automatically registered and there is nothing more to do. - -However, sometimes we might want to declare a new lint by hand. -In this case, we'd use `cargo dev update_lints` command afterwards. - -When a lint is manually declared, we might need to register the lint pass -manually in the `register_plugins` function in `clippy_lints/src/lib.rs`: - -```rust -store.register_late_pass(|| Box::new(foo_functions::FooFunctions)); -``` - -As you might have guessed, where there's something late, there is something early: -in Clippy there is a `register_early_pass` method as well. -More on early vs. late passes in a later chapter. - -Without a call to one of `register_early_pass` or `register_late_pass`, -the lint pass in question will not be run. - -## Lint types +#### Lint types As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) of lints besides the numerous standalone lints living under `clippy_lints/src/`: @@ -160,6 +136,64 @@ For more information, feel free to compare the lint files under any category with [All Clippy lints][all_lints] or ask one of the maintainers. +## The `define_clippy_lints` macro + +After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint. + +The macro looks something like this: + +```rust +declare_clippy_lint! { + /// ### What it does + /// + /// // Describe here what does the lint do. + /// + /// Triggers when detects... + /// + /// ### Why is this bad? + /// + /// // Describe why this pattern would be bad + /// + /// It can lead to... + /// + /// ### Example + /// ```rust + /// // example code where clippy issues a warning + /// ``` + /// Use instead: + /// ```rust + /// // example code which does not raise clippy warning + /// ``` + #[clippy::version = "1.70.0"] // <- In which version was this implemented, keep it up to date! + pub LINT_NAME, // <- The lint name IN_ALL_CAPS + pedantic, // <- The lint group + "default lint description" // <- A lint description, e.g. "A function has an unit return type." +} +``` + +## Lint registration + +If we run the `cargo dev new_lint` command for a new lint, +the lint will be automatically registered and there is nothing more to do. + +However, sometimes we might want to declare a new lint by hand. +In this case, we'd use `cargo dev update_lints` command afterwards. + +When a lint is manually declared, we might need to register the lint pass +manually in the `register_plugins` function in `clippy_lints/src/lib.rs`: + +```rust +store.register_late_pass(|| Box::new(foo_functions::FooFunctions)); +``` + +As you might have guessed, where there's something late, there is something early: +in Clippy there is a `register_early_pass` method as well. +More on early vs. late passes in a later chapter. + +Without a call to one of `register_early_pass` or `register_late_pass`, +the lint pass in question will not be run. + + [all_lints]: https://rust-lang.github.io/rust-clippy/master/ [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints [Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy From b91d676b60b23227698c9449bed561b6c759e4db Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 17 Apr 2023 23:51:59 +0200 Subject: [PATCH 35/79] Move "Lint types to the top" --- book/src/development/defining_lints.md | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 44806c0cb8519..e0dc21024596e 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -5,8 +5,33 @@ and registration of the lint in Clippy's codebase. We can use the Clippy dev tools to handle this step since setting up the lint involves some boilerplate code. -In our example, we're going to create a lint to detect functions named `foo` because it is a highly non-descriptive -name for a function, so we want to trigger this and fix it early in the development process. +#### Lint types + +A lint type is the category of items and expressions in which your lint focuses on. + +As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) +of lints besides the numerous standalone lints living under `clippy_lints/src/`: + +- `cargo` +- `casts` +- `functions` +- `loops` +- `matches` +- `methods` +- `misc_early` +- `operators` +- `transmute` +- `types` +- `unit_types` +- `utils / internal` (Clippy internal lints) + +These types group together lints that share some common behaviors. +For instance, `functions` groups together lints +that deal with some aspects of function calls in Rust. + +For more information, feel free to compare the lint files under any category +with [All Clippy lints][all_lints] or +ask one of the maintainers. ## Lint name @@ -110,31 +135,6 @@ Untracked files: tests/ui/foo_functions.rs ``` -#### Lint types - -As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) -of lints besides the numerous standalone lints living under `clippy_lints/src/`: - -- `cargo` -- `casts` -- `functions` -- `loops` -- `matches` -- `methods` -- `misc_early` -- `operators` -- `transmute` -- `types` -- `unit_types` -- `utils / internal` (Clippy internal lints) - -These categories group together lints that share some common behaviors. -For instance, as we have mentioned earlier, `functions` groups together lints -that deal with some aspects of function calls in Rust. - -For more information, feel free to compare the lint files under any category -with [All Clippy lints][all_lints] or -ask one of the maintainers. ## The `define_clippy_lints` macro From 6076cda3c5ba17c11965b0244422cfe9b06481e3 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Tue, 18 Apr 2023 18:43:48 +0200 Subject: [PATCH 36/79] Fix CI --- book/src/development/defining_lints.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index e0dc21024596e..14854233850c3 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -138,7 +138,8 @@ Untracked files: ## The `define_clippy_lints` macro -After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint. +After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file +if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint. The macro looks something like this: @@ -196,4 +197,3 @@ the lint pass in question will not be run. [all_lints]: https://rust-lang.github.io/rust-clippy/master/ [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints -[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy From 783c119768c14e1349c49c599410b7e0e60e0c4e Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Wed, 16 Aug 2023 14:36:09 +0200 Subject: [PATCH 37/79] Address review comments and formatting --- book/src/development/defining_lints.md | 94 ++++++++++++++------------ 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/book/src/development/defining_lints.md b/book/src/development/defining_lints.md index 14854233850c3..7c4aa5d45239f 100644 --- a/book/src/development/defining_lints.md +++ b/book/src/development/defining_lints.md @@ -2,15 +2,15 @@ The first step in the journey of a new lint is the definition and registration of the lint in Clippy's codebase. -We can use the Clippy dev tools to handle this step since setting up the +We can use the Clippy dev tools to handle this step since setting up the lint involves some boilerplate code. #### Lint types A lint type is the category of items and expressions in which your lint focuses on. -As of the writing of this documentation update, there are 12 groups (a.k.a. _types_) -of lints besides the numerous standalone lints living under `clippy_lints/src/`: +As of the writing of this documentation update, there are 12 _types_ of lints +besides the numerous standalone lints living under `clippy_lints/src/`: - `cargo` - `casts` @@ -25,33 +25,35 @@ of lints besides the numerous standalone lints living under `clippy_lints/src/`: - `unit_types` - `utils / internal` (Clippy internal lints) -These types group together lints that share some common behaviors. -For instance, `functions` groups together lints -that deal with some aspects of function calls in Rust. +These types group together lints that share some common behaviors. For instance, +`functions` groups together lints that deal with some aspects of functions in +Rust, like definitions, signatures and attributes. For more information, feel free to compare the lint files under any category -with [All Clippy lints][all_lints] or -ask one of the maintainers. +with [All Clippy lints][all_lints] or ask one of the maintainers. ## Lint name -A good lint name is important, make sure to check the [lint naming guidelines][lint_naming]. Don't worry, if -the lint name doesn't fit, a Clippy team member will alert you in the PR process. +A good lint name is important, make sure to check the [lint naming +guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy +team member will alert you in the PR process. --- -We'll name our example lint that detects functions named "foo" `foo_functions`. Check the -[lint naming guidelines][lint_naming] to see why this name makes sense. +We'll name our example lint that detects functions named "foo" `foo_functions`. +Check the [lint naming guidelines][lint_naming] to see why this name makes +sense. ## Add and Register the Lint -Now that a name is chosen, we shall register `foo_functions` as a lint to the codebase. -There are two ways to register a lint. +Now that a name is chosen, we shall register `foo_functions` as a lint to the +codebase. There are two ways to register a lint. ### Standalone -If you believe that this new lint is a standalone lint (that doesn't belong to any specific [type](#lint-types) like `functions` or `loops`), you can run the following -command in your Clippy project: +If you believe that this new lint is a standalone lint (that doesn't belong to +any specific [type](#lint-types) like `functions` or `loops`), you can run the +following command in your Clippy project: ```sh $ cargo dev new_lint --name=lint_name --pass=late --category=pedantic @@ -59,13 +61,16 @@ $ cargo dev new_lint --name=lint_name --pass=late --category=pedantic There are two things to note here: -1. We set `--pass=late` in this command to do a late lint pass. The alternative -is an `early` lint pass. We will discuss this difference in a later chapter. - -2. If not provided, the `category` of this new lint will default to `nursery`. +1. `--pass`: We set `--pass=late` in this command to do a late lint pass. The + alternative is an `early` lint pass. We will discuss this difference in a + later chapter. + +2. `--category`: If not provided, the `category` of this new lint will default + to `nursery`. -The `cargo dev new_lint` command will create a new file: `clippy_lints/src/foo_functions.rs` -as well as [register the lint](#lint-registration). +The `cargo dev new_lint` command will create a new file: +`clippy_lints/src/foo_functions.rs` as well as [register the +lint](#lint-registration). Overall, you should notice that the following files are modified or created: @@ -115,7 +120,6 @@ call your lint from within the type's lint pass, found in `clippy_lints/src/{typ A _type_ is just the name of a directory in `clippy_lints/src`, like `functions` in the example command. Clippy groups together some lints that share common behaviors, so if your lint falls into one, it would be best to add it to that type. -Read more about [lint types](#lint-types) below. Overall, you should notice that the following files are modified or created: @@ -138,24 +142,25 @@ Untracked files: ## The `define_clippy_lints` macro -After `cargo dev new_lint`, you should see a macro with the name `define_clippy_lints`. It will be in the same file -if you defined a standalone lint, and it will be in `mod.rs` if you defined a type-specific lint. +After `cargo dev new_lint`, you should see a macro with the name +`define_clippy_lints`. It will be in the same file if you defined a standalone +lint, and it will be in `mod.rs` if you defined a type-specific lint. The macro looks something like this: ```rust declare_clippy_lint! { - /// ### What it does + /// ### What it does + /// + /// // Describe here what does the lint do. + /// + /// Triggers when detects... /// - /// // Describe here what does the lint do. - /// - /// Triggers when detects... - /// /// ### Why is this bad? - /// - /// // Describe why this pattern would be bad - /// - /// It can lead to... + /// + /// // Describe why this pattern would be bad + /// + /// It can lead to... /// /// ### Example /// ```rust @@ -174,25 +179,26 @@ declare_clippy_lint! { ## Lint registration -If we run the `cargo dev new_lint` command for a new lint, -the lint will be automatically registered and there is nothing more to do. +If we run the `cargo dev new_lint` command for a new lint, the lint will be +automatically registered and there is nothing more to do. -However, sometimes we might want to declare a new lint by hand. -In this case, we'd use `cargo dev update_lints` command afterwards. +However, sometimes we might want to declare a new lint by hand. In this case, +we'd use `cargo dev update_lints` command afterwards. When a lint is manually declared, we might need to register the lint pass manually in the `register_plugins` function in `clippy_lints/src/lib.rs`: ```rust -store.register_late_pass(|| Box::new(foo_functions::FooFunctions)); +store.register_late_pass(|_| Box::new(foo_functions::FooFunctions)); ``` -As you might have guessed, where there's something late, there is something early: -in Clippy there is a `register_early_pass` method as well. -More on early vs. late passes in a later chapter. +As you might have guessed, where there's something late, there is something +early: in Clippy there is a `register_early_pass` method as well. More on early +vs. late passes in a later chapter. + -Without a call to one of `register_early_pass` or `register_late_pass`, -the lint pass in question will not be run. +Without a call to one of `register_early_pass` or `register_late_pass`, the lint +pass in question will not be run. [all_lints]: https://rust-lang.github.io/rust-clippy/master/ From 111f0229da738ad4374c56c216b08c7cc403a0ef Mon Sep 17 00:00:00 2001 From: blyxyas Date: Thu, 13 Apr 2023 21:57:47 +0200 Subject: [PATCH 38/79] Add "Method Checking" Co-authored-by: Nahua --- book/src/SUMMARY.md | 1 + book/src/development/method_checking.md | 93 +++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 book/src/development/method_checking.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index f6378b1fb90f9..daaefd06a97f3 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -16,6 +16,7 @@ - [Defining Lints](development/defining_lints.md) - [Lint Passes](development/lint_passes.md) - [Type Checking](development/type_checking.md) + - [Method Checking](development/method_checking.md) - [Macro Expansions](development/macro_expansions.md) - [Common Tools](development/common_tools_writing_lints.md) - [Infrastructure](development/infrastructure/README.md) diff --git a/book/src/development/method_checking.md b/book/src/development/method_checking.md new file mode 100644 index 0000000000000..604fcf193df6a --- /dev/null +++ b/book/src/development/method_checking.md @@ -0,0 +1,93 @@ +# Method Checking + +In some scenarios we might want to check for methods when developing +a lint. There are two kinds of questions that we might be curious about: + +- Invocation: Does an expression call a specific method? +- Definition: Does the type `Ty` of an expression define a method? + +## Checking if an `expr` is calling a specific method + +Suppose we have an `expr`, we can check whether it calls a specific +method, e.g. `our_fancy_method`, by performing a pattern match on +the [ExprKind] that we can access from `expr.kind`: + +```rust +use rustc_hir as hir; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_span::sym; + +impl<'tcx> LateLintPass<'tcx> for OurFancyMethodLint { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { + // Check our expr is calling a method with pattern matching + if let hir::ExprKind::MethodCall(path, _, [_self_arg, ..]) = &expr.kind + // Check if the name of this method is `our_fancy_method` + && path.ident.name == sym!(our_fancy_method) + // We can check the type of the self argument whenever necessary. + // (It's necessary if we want to check that method is specifically belonging to a specific trait, + // for example, a `map` method could belong to user-defined trait instead of to `Iterator`) + // See the "Type Checking" chapter of the Clippy book for more information. + { + println!("`expr` is a method call for `our_fancy_method`"); + } + } +} +``` + +Take a closer look at the `ExprKind` enum variant [MethodCall] for more +information on the pattern matching. +As mentioned in [Define Lints](define_lints.md#lint-types), +the `methods` lint type is full of pattern matching with `Methodcall` +in case the reader wishes to explore more. + +Additionally, we use the [`clippy_utils::sym!`][sym] macro to conveniently convert +an input `our_fancy_method` into a `Symbol` and compare that symbol to the [ident][Ident]'s name in the [PathSegment] +in the [MethodCall]. + +## Checking if a type defines a specific method + +While sometimes we want to check whether a method is being called or not, +other times we want to know if our type `Ty` defines a method. + +To check if our type defines a method called `our_fancy_method`, +we will utilize the [check_impl_item] method that is available +in our beloved [LateLintPass] (for more information, refer to the +["Lint Passes"](lint_passes.md) chapter in Clippy book). +This method provides us with an [ImplItem] struct, which represents +anything within an `impl` block. + +Let us take a look at how we might check for the implementation of +`our_fancy_method` on a type: + +```rust +use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::return_ty; +use rustc_hir::{ImplItem, ImplItemKind}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_span::symbol::sym; + +impl<'tcx> LateLintPass<'tcx> for MyTypeImpl { + fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { + // Check if item is a method/function + if let ImplItemKind::Fn(ref signature, _) = impl_item.kind + // Check the method is named `our_fancy_method` + && impl_item.ident.name == sym!(our_fancy_method) + // We can also check it has a parameter `self` + && signature.decl.implicit_self.has_implicit_self() + // We can go even further and even check if its return type is `String` + && is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::String) + { + println!("`our_fancy_method` is implemented!"); + } + } +} +``` + +[check_impl_item]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_impl_item +[ExprKind]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html +[Ident]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/struct.Ident.html +[ImplItem]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_hir/hir/struct.ImplItem.html +[LateLintPass]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html +[MethodCall]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html#variant.MethodCall +[PathSegment]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/struct.PathSegment.html +[sym]: https://doc.rust-lang.org/stable/nightly-rustc/clippy_utils/macro.sym.html From 9e4a2d7fcab0a32a8137f52e4b3a1442604ba61c Mon Sep 17 00:00:00 2001 From: blyxyas Date: Mon, 17 Apr 2023 23:08:44 +0200 Subject: [PATCH 39/79] Fixes based on reviews --- book/src/development/method_checking.md | 47 +++++++++++++------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/book/src/development/method_checking.md b/book/src/development/method_checking.md index 604fcf193df6a..c93af6f21d22d 100644 --- a/book/src/development/method_checking.md +++ b/book/src/development/method_checking.md @@ -4,56 +4,58 @@ In some scenarios we might want to check for methods when developing a lint. There are two kinds of questions that we might be curious about: - Invocation: Does an expression call a specific method? -- Definition: Does the type `Ty` of an expression define a method? +- Definition: Does an `impl` define a method? ## Checking if an `expr` is calling a specific method Suppose we have an `expr`, we can check whether it calls a specific method, e.g. `our_fancy_method`, by performing a pattern match on -the [ExprKind] that we can access from `expr.kind`: +the [`ExprKind`] that we can access from `expr.kind`: ```rust use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_span::sym; +use clippy_utils::is_trait_method; impl<'tcx> LateLintPass<'tcx> for OurFancyMethodLint { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { // Check our expr is calling a method with pattern matching - if let hir::ExprKind::MethodCall(path, _, [_self_arg, ..]) = &expr.kind + if let hir::ExprKind::MethodCall(path, _, [self_arg, ..]) = &expr.kind // Check if the name of this method is `our_fancy_method` && path.ident.name == sym!(our_fancy_method) // We can check the type of the self argument whenever necessary. - // (It's necessary if we want to check that method is specifically belonging to a specific trait, - // for example, a `map` method could belong to user-defined trait instead of to `Iterator`) - // See the "Type Checking" chapter of the Clippy book for more information. + // (It's necessary if we want to check that method is specifically belonging to a specific trait, + // for example, a `map` method could belong to user-defined trait instead of to `Iterator`) + // See the next section for more information. + && is_trait_method(cx, self_arg, sym::OurFancyTrait) { - println!("`expr` is a method call for `our_fancy_method`"); + println!("`expr` is a method call for `our_fancy_method`"); } } } ``` -Take a closer look at the `ExprKind` enum variant [MethodCall] for more +Take a closer look at the `ExprKind` enum variant [`MethodCall`] for more information on the pattern matching. As mentioned in [Define Lints](define_lints.md#lint-types), the `methods` lint type is full of pattern matching with `Methodcall` in case the reader wishes to explore more. Additionally, we use the [`clippy_utils::sym!`][sym] macro to conveniently convert -an input `our_fancy_method` into a `Symbol` and compare that symbol to the [ident][Ident]'s name in the [PathSegment] -in the [MethodCall]. +an input `our_fancy_method` into a `Symbol` and compare that symbol to the [`ident`][Ident]'s name in the [`PathSegment`] +in the [`MethodCall`]. -## Checking if a type defines a specific method +## Checking if a `impl` block implements a method While sometimes we want to check whether a method is being called or not, -other times we want to know if our type `Ty` defines a method. +other times we want to know if our `Ty` defines a method. -To check if our type defines a method called `our_fancy_method`, -we will utilize the [check_impl_item] method that is available -in our beloved [LateLintPass] (for more information, refer to the +To check if our `impl` block defines a method `our_fancy_method`, +we will utilize the [`check_impl_item`] method that is available +in our beloved [`LateLintPass`] (for more information, refer to the ["Lint Passes"](lint_passes.md) chapter in Clippy book). -This method provides us with an [ImplItem] struct, which represents +This method provides us with an [`ImplItem`] struct, which represents anything within an `impl` block. Let us take a look at how we might check for the implementation of @@ -65,7 +67,6 @@ use clippy_utils::return_ty; use rustc_hir::{ImplItem, ImplItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_span::symbol::sym; - impl<'tcx> LateLintPass<'tcx> for MyTypeImpl { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { // Check if item is a method/function @@ -83,11 +84,11 @@ impl<'tcx> LateLintPass<'tcx> for MyTypeImpl { } ``` -[check_impl_item]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_impl_item -[ExprKind]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html +[`check_impl_item`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_impl_item +[`ExprKind`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html [Ident]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/struct.Ident.html -[ImplItem]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_hir/hir/struct.ImplItem.html -[LateLintPass]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html -[MethodCall]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html#variant.MethodCall -[PathSegment]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/struct.PathSegment.html +[`ImplItem`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_hir/hir/struct.ImplItem.html +[`LateLintPass`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html +[`MethodCall`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html#variant.MethodCall +[`PathSegment`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/struct.PathSegment.html [sym]: https://doc.rust-lang.org/stable/nightly-rustc/clippy_utils/macro.sym.html From e8d79b86454ffd7c18ce65c98dda5df51633eedd Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Wed, 16 Aug 2023 14:44:26 +0200 Subject: [PATCH 40/79] Formatting --- book/src/development/method_checking.md | 31 ++++++++++++------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/book/src/development/method_checking.md b/book/src/development/method_checking.md index c93af6f21d22d..f061e6f5b3777 100644 --- a/book/src/development/method_checking.md +++ b/book/src/development/method_checking.md @@ -37,26 +37,24 @@ impl<'tcx> LateLintPass<'tcx> for OurFancyMethodLint { ``` Take a closer look at the `ExprKind` enum variant [`MethodCall`] for more -information on the pattern matching. -As mentioned in [Define Lints](define_lints.md#lint-types), -the `methods` lint type is full of pattern matching with `Methodcall` -in case the reader wishes to explore more. +information on the pattern matching. As mentioned in [Define +Lints](define_lints.md#lint-types), the `methods` lint type is full of pattern +matching with `MethodCall` in case the reader wishes to explore more. -Additionally, we use the [`clippy_utils::sym!`][sym] macro to conveniently convert -an input `our_fancy_method` into a `Symbol` and compare that symbol to the [`ident`][Ident]'s name in the [`PathSegment`] -in the [`MethodCall`]. +Additionally, we use the [`clippy_utils::sym!`][sym] macro to conveniently +convert an input `our_fancy_method` into a `Symbol` and compare that symbol to +the [`Ident`]'s name in the [`PathSegment`] in the [`MethodCall`]. ## Checking if a `impl` block implements a method -While sometimes we want to check whether a method is being called or not, -other times we want to know if our `Ty` defines a method. +While sometimes we want to check whether a method is being called or not, other +times we want to know if our `Ty` defines a method. -To check if our `impl` block defines a method `our_fancy_method`, -we will utilize the [`check_impl_item`] method that is available -in our beloved [`LateLintPass`] (for more information, refer to the -["Lint Passes"](lint_passes.md) chapter in Clippy book). -This method provides us with an [`ImplItem`] struct, which represents -anything within an `impl` block. +To check if our `impl` block defines a method `our_fancy_method`, we will +utilize the [`check_impl_item`] method that is available in our beloved +[`LateLintPass`] (for more information, refer to the ["Lint +Passes"](lint_passes.md) chapter in the Clippy book). This method provides us +with an [`ImplItem`] struct, which represents anything within an `impl` block. Let us take a look at how we might check for the implementation of `our_fancy_method` on a type: @@ -67,6 +65,7 @@ use clippy_utils::return_ty; use rustc_hir::{ImplItem, ImplItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_span::symbol::sym; + impl<'tcx> LateLintPass<'tcx> for MyTypeImpl { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { // Check if item is a method/function @@ -86,7 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for MyTypeImpl { [`check_impl_item`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html#method.check_impl_item [`ExprKind`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html -[Ident]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/struct.Ident.html +[`Ident`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/struct.Ident.html [`ImplItem`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_hir/hir/struct.ImplItem.html [`LateLintPass`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/trait.LateLintPass.html [`MethodCall`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/hir/enum.ExprKind.html#variant.MethodCall From 1dbc8dd0cf51ddff5a585d128f376d26ee619196 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Wed, 16 Aug 2023 14:54:47 +0200 Subject: [PATCH 41/79] Fix define_lints->defining_lints typo in link --- book/src/development/method_checking.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/development/method_checking.md b/book/src/development/method_checking.md index f061e6f5b3777..56d1be37519e9 100644 --- a/book/src/development/method_checking.md +++ b/book/src/development/method_checking.md @@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for OurFancyMethodLint { Take a closer look at the `ExprKind` enum variant [`MethodCall`] for more information on the pattern matching. As mentioned in [Define -Lints](define_lints.md#lint-types), the `methods` lint type is full of pattern +Lints](defining_lints.md#lint-types), the `methods` lint type is full of pattern matching with `MethodCall` in case the reader wishes to explore more. Additionally, we use the [`clippy_utils::sym!`][sym] macro to conveniently From 7e4621736224c07d80a43e771dd0e115676880f8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 17 Aug 2023 14:24:04 +0200 Subject: [PATCH 42/79] Add new regression test for `needless_pass_by_ref_mut` --- tests/ui/needless_pass_by_ref_mut.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index a20de47ab323c..ec87d44759756 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -221,6 +221,16 @@ async fn inner_async3(x: &mut i32, y: &mut u32) { .await; } +// Should not warn. +async fn async_vec(b: &mut Vec) { + b.append(&mut vec![]); +} + +// Should not warn. +async fn async_vec2(b: &mut Vec) { + b.push(true); +} + fn main() { let mut u = 0; let mut v = vec![0]; From 5875bd2b5f2b593d708459111bff42ba4535cebc Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 17 Aug 2023 17:45:17 +0200 Subject: [PATCH 43/79] Use `HirId` from `PlaceWithHirId` rather than using the one provided to the function --- clippy_lints/src/needless_pass_by_ref_mut.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index 6eb17d675e971..7b00eabf97b41 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -305,7 +305,7 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt<'tcx> { } } - fn borrow(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, id: HirId, borrow: ty::BorrowKind) { + fn borrow(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _id: HirId, borrow: ty::BorrowKind) { self.prev_bind = None; if let euv::Place { base: euv::PlaceBase::Local(vid), @@ -338,7 +338,7 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt<'tcx> { ], ), .. - }) = self.tcx.hir().get(id) + }) = self.tcx.hir().get(cmt.hir_id) { self.async_closures.insert(*def_id); } From d068043891de98a6263bbfe73f11958531b5d6f7 Mon Sep 17 00:00:00 2001 From: bors Date: Thu, 17 Aug 2023 14:41:46 +0000 Subject: [PATCH 44/79] Auto merge of #11070 - y21:issue11065, r=flip1995 [`useless_conversion`]: only lint on paths to fn items and fix FP in macro Fixes #11065 (which is actually two issues: an ICE and a false positive) It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616836099). It *also* makes sure that the expression is not part of a macro call (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616919639). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore) changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP) r? `@llogiq` (reviewed #10814, which introduced these issues) --- clippy_lints/src/useless_conversion.rs | 18 +++++++++++++++--- tests/ui/crashes/ice-11065.rs | 19 +++++++++++++++++++ tests/ui/useless_conversion.fixed | 14 ++++++++++++++ tests/ui/useless_conversion.rs | 14 ++++++++++++++ tests/ui/useless_conversion.stderr | 20 ++++++++++---------- 5 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 tests/ui/crashes/ice-11065.rs diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index bd4dc07a42bfa..5ac4f0aa46c10 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -5,6 +5,7 @@ use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts}; use clippy_utils::{get_parent_expr, is_trait_method, is_ty_alias, match_def_path, path_to_local, paths}; use if_chain::if_chain; use rustc_errors::Applicability; +use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, MatchSource, Node, PatKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -39,6 +40,7 @@ declare_clippy_lint! { #[derive(Default)] pub struct UselessConversion { try_desugar_arm: Vec, + expn_depth: u32, } impl_lint_pass!(UselessConversion => [USELESS_CONVERSION]); @@ -105,6 +107,7 @@ fn into_iter_deep_call<'hir>(cx: &LateContext<'_>, mut expr: &'hir Expr<'hir>) - impl<'tcx> LateLintPass<'tcx> for UselessConversion { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if e.span.from_expansion() { + self.expn_depth += 1; return; } @@ -150,9 +153,14 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { { if let Some(parent) = get_parent_expr(cx, e) { let parent_fn = match parent.kind { - ExprKind::Call(recv, args) if let ExprKind::Path(ref qpath) = recv.kind => { - cx.qpath_res(qpath, recv.hir_id).opt_def_id() - .map(|did| (did, args, MethodOrFunction::Function)) + ExprKind::Call(recv, args) + if let ExprKind::Path(ref qpath) = recv.kind + && let Some(did) = cx.qpath_res(qpath, recv.hir_id).opt_def_id() + // make sure that the path indeed points to a fn-like item, so that + // `fn_sig` does not ICE. (see #11065) + && cx.tcx.opt_def_kind(did).is_some_and(DefKind::is_fn_like) => + { + Some((did, args, MethodOrFunction::Function)) } ExprKind::MethodCall(.., args, _) => { cx.typeck_results().type_dependent_def_id(parent.hir_id) @@ -168,6 +176,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { && let Some(&into_iter_param) = sig.inputs().get(kind.param_pos(arg_pos)) && let ty::Param(param) = into_iter_param.kind() && let Some(span) = into_iter_bound(cx, parent_fn_did, into_iter_did, param.index) + && self.expn_depth == 0 { // Get the "innermost" `.into_iter()` call, e.g. given this expression: // `foo.into_iter().into_iter()` @@ -303,5 +312,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { if Some(&e.hir_id) == self.try_desugar_arm.last() { self.try_desugar_arm.pop(); } + if e.span.from_expansion() { + self.expn_depth -= 1; + } } } diff --git a/tests/ui/crashes/ice-11065.rs b/tests/ui/crashes/ice-11065.rs new file mode 100644 index 0000000000000..f5cf6b1cd77a2 --- /dev/null +++ b/tests/ui/crashes/ice-11065.rs @@ -0,0 +1,19 @@ +#![warn(clippy::useless_conversion)] + +use std::iter::FromIterator; +use std::option::IntoIter as OptionIter; + +fn eq(a: T, b: T) -> bool { + a == b +} + +macro_rules! tests { + ($($expr:expr, $ty:ty, ($($test:expr),*);)+) => (pub fn main() {$({ + const C: $ty = $expr; + assert!(eq(C($($test),*), $expr($($test),*))); + })+}) +} + +tests! { + FromIterator::from_iter, fn(OptionIter) -> Vec, (Some(5).into_iter()); +} diff --git a/tests/ui/useless_conversion.fixed b/tests/ui/useless_conversion.fixed index 5d2c5b11658e2..53d8a5a9ff18b 100644 --- a/tests/ui/useless_conversion.fixed +++ b/tests/ui/useless_conversion.fixed @@ -155,6 +155,20 @@ fn main() { let _ = vec![s4, s4, s4].into_iter(); } +#[allow(dead_code)] +fn issue11065_fp() { + use std::option::IntoIter; + fn takes_into_iter(_: impl IntoIterator) {} + + macro_rules! x { + ($e:expr) => { + takes_into_iter($e); + let _: IntoIter = $e; // removing `.into_iter()` leads to a type error here + }; + } + x!(Some(5).into_iter()); +} + #[allow(dead_code)] fn explicit_into_iter_fn_arg() { fn a(_: T) {} diff --git a/tests/ui/useless_conversion.rs b/tests/ui/useless_conversion.rs index 03a3e3f95ba42..51ba498733965 100644 --- a/tests/ui/useless_conversion.rs +++ b/tests/ui/useless_conversion.rs @@ -155,6 +155,20 @@ fn main() { let _ = vec![s4, s4, s4].into_iter().into_iter(); } +#[allow(dead_code)] +fn issue11065_fp() { + use std::option::IntoIter; + fn takes_into_iter(_: impl IntoIterator) {} + + macro_rules! x { + ($e:expr) => { + takes_into_iter($e); + let _: IntoIter = $e; // removing `.into_iter()` leads to a type error here + }; + } + x!(Some(5).into_iter()); +} + #[allow(dead_code)] fn explicit_into_iter_fn_arg() { fn a(_: T) {} diff --git a/tests/ui/useless_conversion.stderr b/tests/ui/useless_conversion.stderr index 4957f73a469a6..6f7dc01d2cd27 100644 --- a/tests/ui/useless_conversion.stderr +++ b/tests/ui/useless_conversion.stderr @@ -119,61 +119,61 @@ LL | let _ = vec![s4, s4, s4].into_iter().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()` error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:171:7 + --> $DIR/useless_conversion.rs:185:7 | LL | b(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:161:13 + --> $DIR/useless_conversion.rs:175:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:172:7 + --> $DIR/useless_conversion.rs:186:7 | LL | c(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:162:18 + --> $DIR/useless_conversion.rs:176:18 | LL | fn c(_: impl IntoIterator) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:173:7 + --> $DIR/useless_conversion.rs:187:7 | LL | d(vec![1, 2].into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:165:12 + --> $DIR/useless_conversion.rs:179:12 | LL | T: IntoIterator, | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:176:7 + --> $DIR/useless_conversion.rs:190:7 | LL | b(vec![1, 2].into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:161:13 + --> $DIR/useless_conversion.rs:175:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` - --> $DIR/useless_conversion.rs:177:7 + --> $DIR/useless_conversion.rs:191:7 | LL | b(vec![1, 2].into_iter().into_iter().into_iter()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` - --> $DIR/useless_conversion.rs:161:13 + --> $DIR/useless_conversion.rs:175:13 | LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ From 5638860ff8f3996522c6b632ca972177bc2df026 Mon Sep 17 00:00:00 2001 From: bors Date: Thu, 17 Aug 2023 15:55:23 +0000 Subject: [PATCH 45/79] Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r=Centri3 Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT Fixes https://github.com/rust-lang/rust-clippy/issues/11299. The problem was that the `async block`s are popping a closure which we didn't go into, making it miss the mutable access to the variables. cc `@Centri3` changelog: none --- clippy_lints/src/needless_pass_by_ref_mut.rs | 103 +++++++++++++++---- tests/ui/needless_pass_by_ref_mut.rs | 35 +++++++ tests/ui/needless_pass_by_ref_mut.stderr | 14 ++- 3 files changed, 129 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs index c634de960d137..7b00eabf97b41 100644 --- a/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -5,14 +5,16 @@ use clippy_utils::{get_parent_node, inherits_cfg, is_from_proc_macro, is_self}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_qpath, FnKind, Visitor}; -use rustc_hir::{Body, ExprKind, FnDecl, HirId, HirIdMap, HirIdSet, Impl, ItemKind, Mutability, Node, PatKind, QPath}; +use rustc_hir::{ + Body, Closure, Expr, ExprKind, FnDecl, HirId, HirIdMap, HirIdSet, Impl, ItemKind, Mutability, Node, PatKind, QPath, +}; use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::associated_body; use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, Ty, UpvarId, UpvarPath}; +use rustc_middle::ty::{self, Ty, TyCtxt, UpvarId, UpvarPath}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::kw; @@ -147,22 +149,36 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { // Collect variables mutably used and spans which will need dereferencings from the // function body. let MutablyUsedVariablesCtxt { mutably_used_vars, .. } = { - let mut ctx = MutablyUsedVariablesCtxt::default(); + let mut ctx = MutablyUsedVariablesCtxt { + mutably_used_vars: HirIdSet::default(), + prev_bind: None, + prev_move_to_closure: HirIdSet::default(), + aliases: HirIdMap::default(), + async_closures: FxHashSet::default(), + tcx: cx.tcx, + }; let infcx = cx.tcx.infer_ctxt().build(); euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); if is_async { - let closures = ctx.async_closures.clone(); - let hir = cx.tcx.hir(); - for closure in closures { - ctx.prev_bind = None; - ctx.prev_move_to_closure.clear(); - if let Some(body) = hir - .find_by_def_id(closure) - .and_then(associated_body) - .map(|(_, body_id)| hir.body(body_id)) - { - euv::ExprUseVisitor::new(&mut ctx, &infcx, closure, cx.param_env, cx.typeck_results()) - .consume_body(body); + let mut checked_closures = FxHashSet::default(); + while !ctx.async_closures.is_empty() { + let closures = ctx.async_closures.clone(); + ctx.async_closures.clear(); + let hir = cx.tcx.hir(); + for closure in closures { + if !checked_closures.insert(closure) { + continue; + } + ctx.prev_bind = None; + ctx.prev_move_to_closure.clear(); + if let Some(body) = hir + .find_by_def_id(closure) + .and_then(associated_body) + .map(|(_, body_id)| hir.body(body_id)) + { + euv::ExprUseVisitor::new(&mut ctx, &infcx, closure, cx.param_env, cx.typeck_results()) + .consume_body(body); + } } } } @@ -225,16 +241,16 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> { } } -#[derive(Default)] -struct MutablyUsedVariablesCtxt { +struct MutablyUsedVariablesCtxt<'tcx> { mutably_used_vars: HirIdSet, prev_bind: Option, prev_move_to_closure: HirIdSet, aliases: HirIdMap, async_closures: FxHashSet, + tcx: TyCtxt<'tcx>, } -impl MutablyUsedVariablesCtxt { +impl<'tcx> MutablyUsedVariablesCtxt<'tcx> { fn add_mutably_used_var(&mut self, mut used_id: HirId) { while let Some(id) = self.aliases.get(&used_id) { self.mutably_used_vars.insert(used_id); @@ -242,9 +258,27 @@ impl MutablyUsedVariablesCtxt { } self.mutably_used_vars.insert(used_id); } + + fn would_be_alias_cycle(&self, alias: HirId, mut target: HirId) -> bool { + while let Some(id) = self.aliases.get(&target) { + if *id == alias { + return true; + } + target = *id; + } + false + } + + fn add_alias(&mut self, alias: HirId, target: HirId) { + // This is to prevent alias loop. + if alias == target || self.would_be_alias_cycle(alias, target) { + return; + } + self.aliases.insert(alias, target); + } } -impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { +impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt<'tcx> { fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _id: HirId) { if let euv::Place { base: @@ -259,7 +293,7 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { { if let Some(bind_id) = self.prev_bind.take() { if bind_id != *vid { - self.aliases.insert(bind_id, *vid); + self.add_alias(bind_id, *vid); } } else if !self.prev_move_to_closure.contains(vid) && matches!(base_ty.ref_mutability(), Some(Mutability::Mut)) @@ -289,6 +323,25 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { { self.add_mutably_used_var(*vid); } + } else if borrow == ty::ImmBorrow { + // If there is an `async block`, it'll contain a call to a closure which we need to + // go into to ensure all "mutate" checks are found. + if let Node::Expr(Expr { + kind: + ExprKind::Call( + _, + [ + Expr { + kind: ExprKind::Closure(Closure { def_id, .. }), + .. + }, + ], + ), + .. + }) = self.tcx.hir().get(cmt.hir_id) + { + self.async_closures.insert(*def_id); + } } } @@ -296,7 +349,12 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { self.prev_bind = None; if let euv::Place { projections, - base: euv::PlaceBase::Local(vid), + base: + euv::PlaceBase::Local(vid) + | euv::PlaceBase::Upvar(UpvarId { + var_path: UpvarPath { hir_id: vid }, + .. + }), .. } = &cmt.place { @@ -329,8 +387,9 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt { // Seems like we are inside an async function. We need to store the closure `DefId` // to go through it afterwards. self.async_closures.insert(inner); - self.aliases.insert(cmt.hir_id, *vid); + self.add_alias(cmt.hir_id, *vid); self.prev_move_to_closure.insert(*vid); + self.prev_bind = None; } } } diff --git a/tests/ui/needless_pass_by_ref_mut.rs b/tests/ui/needless_pass_by_ref_mut.rs index ae7b018d0e256..ec87d44759756 100644 --- a/tests/ui/needless_pass_by_ref_mut.rs +++ b/tests/ui/needless_pass_by_ref_mut.rs @@ -196,6 +196,41 @@ mod foo { //~| NOTE: this is cfg-gated and may require further changes } +// Should not warn. +async fn inner_async(x: &mut i32, y: &mut u32) { + async { + *y += 1; + *x += 1; + } + .await; +} + +async fn inner_async2(x: &mut i32, y: &mut u32) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + async { + *x += 1; + } + .await; +} + +async fn inner_async3(x: &mut i32, y: &mut u32) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + async { + *y += 1; + } + .await; +} + +// Should not warn. +async fn async_vec(b: &mut Vec) { + b.append(&mut vec![]); +} + +// Should not warn. +async fn async_vec2(b: &mut Vec) { + b.push(true); +} + fn main() { let mut u = 0; let mut v = vec![0]; diff --git a/tests/ui/needless_pass_by_ref_mut.stderr b/tests/ui/needless_pass_by_ref_mut.stderr index 0d426ce32f9d5..2e06e7252d9ba 100644 --- a/tests/ui/needless_pass_by_ref_mut.stderr +++ b/tests/ui/needless_pass_by_ref_mut.stderr @@ -94,5 +94,17 @@ LL | fn cfg_warn(s: &mut u32) {} | = note: this is cfg-gated and may require further changes -error: aborting due to 15 previous errors +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:208:39 + | +LL | async fn inner_async2(x: &mut i32, y: &mut u32) { + | ^^^^^^^^ help: consider changing to: `&u32` + +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:216:26 + | +LL | async fn inner_async3(x: &mut i32, y: &mut u32) { + | ^^^^^^^^ help: consider changing to: `&i32` + +error: aborting due to 17 previous errors From ede43069cc927d0e2380de93aa37c4b30c1d15e0 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Thu, 17 Aug 2023 21:47:03 +0100 Subject: [PATCH 46/79] Remove use of `box_syntax` CONTRIBUTING.md` example `box_syntax` no longer exists. [`clippy_lints/src/lib.rs` now uses `Box::new`](https://github.com/rust-lang/rust-clippy/blob/d5298bea7fd0ce133506d156795e3dc7c68efc20/clippy_lints/src/lib.rs#L809C70-L809C70) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3df1328036948..04af1b98b556e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -148,7 +148,7 @@ pub mod else_if_without_else; pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) { // ... - store.register_early_pass(|| box else_if_without_else::ElseIfWithoutElse); + store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse)); // ... store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ From 41570c1ee71b36a5a5ea887a3aee07121d1aa0b6 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Fri, 18 Aug 2023 17:07:43 +0200 Subject: [PATCH 47/79] Update version attribute for 1.72 lints --- clippy_lints/src/casts/mod.rs | 2 +- clippy_lints/src/endian_bytes.rs | 6 +++--- clippy_lints/src/excessive_nesting.rs | 2 +- clippy_lints/src/large_stack_frames.rs | 2 +- clippy_lints/src/methods/mod.rs | 4 ++-- clippy_lints/src/needless_else.rs | 2 +- clippy_lints/src/redundant_type_annotations.rs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index d34de305f5dce..88ffbb55486bd 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -418,7 +418,7 @@ declare_clippy_lint! { /// let mut_ptr = ptr.cast_mut(); /// let ptr = mut_ptr.cast_const(); /// ``` - #[clippy::version = "1.71.0"] + #[clippy::version = "1.72.0"] pub PTR_CAST_CONSTNESS, pedantic, "casting using `as` from and to raw pointers to change constness when specialized methods apply" diff --git a/clippy_lints/src/endian_bytes.rs b/clippy_lints/src/endian_bytes.rs index dda14b4df533b..affd082212064 100644 --- a/clippy_lints/src/endian_bytes.rs +++ b/clippy_lints/src/endian_bytes.rs @@ -21,7 +21,7 @@ declare_clippy_lint! { /// let _x = 2i32.to_ne_bytes(); /// let _y = 2i64.to_ne_bytes(); /// ``` - #[clippy::version = "1.71.0"] + #[clippy::version = "1.72.0"] pub HOST_ENDIAN_BYTES, restriction, "disallows usage of the `to_ne_bytes` method" @@ -40,7 +40,7 @@ declare_clippy_lint! { /// let _x = 2i32.to_le_bytes(); /// let _y = 2i64.to_le_bytes(); /// ``` - #[clippy::version = "1.71.0"] + #[clippy::version = "1.72.0"] pub LITTLE_ENDIAN_BYTES, restriction, "disallows usage of the `to_le_bytes` method" @@ -59,7 +59,7 @@ declare_clippy_lint! { /// let _x = 2i32.to_be_bytes(); /// let _y = 2i64.to_be_bytes(); /// ``` - #[clippy::version = "1.71.0"] + #[clippy::version = "1.72.0"] pub BIG_ENDIAN_BYTES, restriction, "disallows usage of the `to_be_bytes` method" diff --git a/clippy_lints/src/excessive_nesting.rs b/clippy_lints/src/excessive_nesting.rs index 8911f1872c2cd..83480fc5eebed 100644 --- a/clippy_lints/src/excessive_nesting.rs +++ b/clippy_lints/src/excessive_nesting.rs @@ -56,7 +56,7 @@ declare_clippy_lint! { /// // lib.rs /// pub mod a; /// ``` - #[clippy::version = "1.70.0"] + #[clippy::version = "1.72.0"] pub EXCESSIVE_NESTING, complexity, "checks for blocks nested beyond a certain threshold" diff --git a/clippy_lints/src/large_stack_frames.rs b/clippy_lints/src/large_stack_frames.rs index 7aa1446d53d59..1d28d7dd0e7c5 100644 --- a/clippy_lints/src/large_stack_frames.rs +++ b/clippy_lints/src/large_stack_frames.rs @@ -72,7 +72,7 @@ declare_clippy_lint! { /// // ... /// } /// ``` - #[clippy::version = "1.71.0"] + #[clippy::version = "1.72.0"] pub LARGE_STACK_FRAMES, nursery, "checks for functions that allocate a lot of stack space" diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 729eda37af62d..3a8af0248d81e 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -301,7 +301,7 @@ declare_clippy_lint! { /// let val2 = 1; /// let val3 = 1; /// ``` - #[clippy::version = "1.69.0"] + #[clippy::version = "1.72.0"] pub UNNECESSARY_LITERAL_UNWRAP, complexity, "using `unwrap()` related calls on `Result` and `Option` constructors" @@ -3328,7 +3328,7 @@ declare_clippy_lint! { /// mem::take(v) /// } /// ``` - #[clippy::version = "1.71.0"] + #[clippy::version = "1.72.0"] pub DRAIN_COLLECT, perf, "calling `.drain(..).collect()` to move all elements into a new collection" diff --git a/clippy_lints/src/needless_else.rs b/clippy_lints/src/needless_else.rs index 03bab86c6d7c2..0c1fe881fc109 100644 --- a/clippy_lints/src/needless_else.rs +++ b/clippy_lints/src/needless_else.rs @@ -27,7 +27,7 @@ declare_clippy_lint! { /// println!("Check successful!"); /// } /// ``` - #[clippy::version = "1.71.0"] + #[clippy::version = "1.72.0"] pub NEEDLESS_ELSE, style, "empty else branch" diff --git a/clippy_lints/src/redundant_type_annotations.rs b/clippy_lints/src/redundant_type_annotations.rs index 3e963d7989280..1d4fdb43a0b90 100644 --- a/clippy_lints/src/redundant_type_annotations.rs +++ b/clippy_lints/src/redundant_type_annotations.rs @@ -31,7 +31,7 @@ declare_clippy_lint! { /// ```rust /// let foo = String::new(); /// ``` - #[clippy::version = "1.70.0"] + #[clippy::version = "1.72.0"] pub REDUNDANT_TYPE_ANNOTATIONS, restriction, "warns about needless / redundant type annotations." From 8f06b19b457e87fde9505c9777808dbc126afa5e Mon Sep 17 00:00:00 2001 From: xFrednet Date: Fri, 18 Aug 2023 17:08:59 +0200 Subject: [PATCH 48/79] Changelog for Rust 1.72 :beach_umbrella: --- CHANGELOG.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71671273c57b5..786df2ae9ab14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,18 +6,105 @@ document. ## Unreleased / Beta / In Rust Nightly -[435a8ad8...master](https://github.com/rust-lang/rust-clippy/compare/435a8ad8...master) +[37f4c172...master](https://github.com/rust-lang/rust-clippy/compare/37f4c172...master) + +## Rust 1.72 + +Current beta, released 2023-08-24 + +[View all 131 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-05-22T14%3A53%3A59Z..2023-07-01T22%3A57%3A20Z+base%3Amaster) + +### New Lints + +* [`manual_try_fold`] + [#11012](https://github.com/rust-lang/rust-clippy/pull/11012) +* [`tuple_array_conversions`] + [#11020](https://github.com/rust-lang/rust-clippy/pull/11020) +* [`redundant_at_rest_pattern`] + [#11013](https://github.com/rust-lang/rust-clippy/pull/11013) +* [`needless_pub_self`] + [#10967](https://github.com/rust-lang/rust-clippy/pull/10967) +* [`pub_with_shorthand`] + [#10967](https://github.com/rust-lang/rust-clippy/pull/10967) +* [`pub_without_shorthand`] + [#10967](https://github.com/rust-lang/rust-clippy/pull/10967) +* [`manual_range_patterns`] + [#10968](https://github.com/rust-lang/rust-clippy/pull/10968) +* [`needless_raw_string_hashes`] + [#10884](https://github.com/rust-lang/rust-clippy/pull/10884) +* [`needless_raw_strings`] + [#10884](https://github.com/rust-lang/rust-clippy/pull/10884) +* [`incorrect_clone_impl_on_copy_type`] + [#10925](https://github.com/rust-lang/rust-clippy/pull/10925) +* [`drain_collect`] + [#10835](https://github.com/rust-lang/rust-clippy/pull/10835) +* [`single_range_in_vec_init`] + [#10934](https://github.com/rust-lang/rust-clippy/pull/10934) +* [`unnecessary_literal_unwrap`] + [#10358](https://github.com/rust-lang/rust-clippy/pull/10358) +* [`large_stack_frames`] + [#10827](https://github.com/rust-lang/rust-clippy/pull/10827) +* [`min_ident_chars`] + [#10916](https://github.com/rust-lang/rust-clippy/pull/10916) +* [`needless_if`] + [#10921](https://github.com/rust-lang/rust-clippy/pull/10921) +* [`excessive_nesting`] + [#10672](https://github.com/rust-lang/rust-clippy/pull/10672) +* [`arc_with_non_send_sync`] + [#10898](https://github.com/rust-lang/rust-clippy/pull/10898) +* [`redundant_type_annotations`] + [#10570](https://github.com/rust-lang/rust-clippy/pull/10570) +* [`host_endian_bytes`] + [#10826](https://github.com/rust-lang/rust-clippy/pull/10826) +* [`little_endian_bytes`] + [#10826](https://github.com/rust-lang/rust-clippy/pull/10826) +* [`big_endian_bytes`] + [#10826](https://github.com/rust-lang/rust-clippy/pull/10826) +* [`ptr_cast_constness`] + [#10779](https://github.com/rust-lang/rust-clippy/pull/10779) +* [`needless_else`] + [#10810](https://github.com/rust-lang/rust-clippy/pull/10810) + +### Moves and Deprecations + +* Moved [`redundant_clone`] to `nursery` (Now allow-by-default) + [#10873](https://github.com/rust-lang/rust-clippy/pull/10873) + +### Enhancements + +* [`undocumented_unsafe_blocks`]: Added [`accept-comment-above-attributes`] configuration + [#10986](https://github.com/rust-lang/rust-clippy/pull/10986) +* [`undocumented_unsafe_blocks`]: Added [`accept-comment-above-statement`] configuration. + [#10886](https://github.com/rust-lang/rust-clippy/pull/10886) +* [`missing_panics_doc`]: No longer lints on `todo!()` + [#10976](https://github.com/rust-lang/rust-clippy/pull/10976) +* [`module_inception`]: Added `allow-private-module-inception` configuration. + [#10917](https://github.com/rust-lang/rust-clippy/pull/10917) +* Errors and warnings generated while parsing `clippy.toml` now point to the location in the TOML + file the error/warning occurred in. + [#10607](https://github.com/rust-lang/rust-clippy/pull/10607) + +### False Positive Fixes + +* [`excessive_precision`]: No longer lints overflowing literals + [#10952](https://github.com/rust-lang/rust-clippy/pull/10952) + +### Suggestion Fixes/Improvements + +* [`option_map_unwrap_or`]: The suggestion now considers the set [`msrv`] config value + [#11030](https://github.com/rust-lang/rust-clippy/pull/11030) + +### Documentation Improvements + +* [Clippy's lint list] now stores filter parameters in the URL, to allow easy sharing + [#10834](https://github.com/rust-lang/rust-clippy/pull/10834) ## Rust 1.71 Current stable, released 2023-07-13 - - -We're trying out a new shorter changelog format, that only contains significant changes. -You can check out the list of merged pull requests for a list of all changes. -If you have any feedback related to the new format, please share it in -[#10847](https://github.com/rust-lang/rust-clippy/issues/10847) +Note: Clippy will use a shorter changelog format from now on, if you want a detailed list of +all changes, please check out the list of merged pull requests. [View all 78 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-04-11T20%3A05%3A26Z..2023-05-20T13%3A48%3A17Z+base%3Amaster) @@ -4677,6 +4764,7 @@ Released 2018-09-13 [pull3665]: https://github.com/rust-lang/rust-clippy/pull/3665 [adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/book/src/development/adding_lints.md [`README.md`]: https://github.com/rust-lang/rust-clippy/blob/master/README.md +[Clippy's lint list]: https://rust-lang.github.io/rust-clippy/master/index.html From e52bd6f8505bd3e3ce120104e4c6ee4f17dc1d10 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Fri, 21 Jul 2023 11:23:31 +0200 Subject: [PATCH 49/79] new lint: `should_panic_without_expect` --- CHANGELOG.md | 1 + clippy_lints/src/attrs.rs | 74 ++++++++++++++++++++- clippy_lints/src/declared_lints.rs | 1 + clippy_utils/src/paths.rs | 2 + tests/ui/should_panic_without_expect.rs | 21 ++++++ tests/ui/should_panic_without_expect.stderr | 14 ++++ 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 tests/ui/should_panic_without_expect.rs create mode 100644 tests/ui/should_panic_without_expect.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 786df2ae9ab14..fe64283462d11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5329,6 +5329,7 @@ Released 2018-09-13 [`short_circuit_statement`]: https://rust-lang.github.io/rust-clippy/master/index.html#short_circuit_statement [`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq [`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait +[`should_panic_without_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_panic_without_expect [`significant_drop_in_scrutinee`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee [`significant_drop_tightening`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_tightening [`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 2a5be2756151a..a88f2b51c827e 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -6,7 +6,11 @@ use clippy_utils::macros::{is_panic, macro_backtrace}; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments}; use if_chain::if_chain; -use rustc_ast::{AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem}; +use rustc_ast::token::{Token, TokenKind}; +use rustc_ast::tokenstream::TokenTree; +use rustc_ast::{ + AttrArgs, AttrArgsEq, AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem, +}; use rustc_errors::Applicability; use rustc_hir::{ Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind, @@ -339,6 +343,41 @@ declare_clippy_lint! { "ensures that all `allow` and `expect` attributes have a reason" } +declare_clippy_lint! { + /// ### What it does + /// Checks for `#[should_panic]` attributes without specifying the expected panic message. + /// + /// ### Why is this bad? + /// The expected panic message should be specified to ensure that the test is actually + /// panicking with the expected message, and not another unrelated panic. + /// + /// ### Example + /// ```rust + /// fn random() -> i32 { 0 } + /// + /// #[should_panic] + /// #[test] + /// fn my_test() { + /// let _ = 1 / random(); + /// } + /// ``` + /// + /// Use instead: + /// ```rust + /// fn random() -> i32 { 0 } + /// + /// #[should_panic = "attempt to divide by zero"] + /// #[test] + /// fn my_test() { + /// let _ = 1 / random(); + /// } + /// ``` + #[clippy::version = "1.73.0"] + pub SHOULD_PANIC_WITHOUT_EXPECT, + pedantic, + "ensures that all `should_panic` attributes specify its expected panic message" +} + declare_clippy_lint! { /// ### What it does /// Checks for `any` and `all` combinators in `cfg` with only one condition. @@ -395,6 +434,7 @@ declare_lint_pass!(Attributes => [ DEPRECATED_SEMVER, USELESS_ATTRIBUTE, BLANKET_CLIPPY_RESTRICTION_LINTS, + SHOULD_PANIC_WITHOUT_EXPECT, ]); impl<'tcx> LateLintPass<'tcx> for Attributes { @@ -442,6 +482,9 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { } } } + if attr.has_name(sym::should_panic) { + check_should_panic_reason(cx, attr); + } } fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { @@ -550,6 +593,35 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option { None } +fn check_should_panic_reason(cx: &LateContext<'_>, attr: &Attribute) { + if let AttrKind::Normal(normal_attr) = &attr.kind { + if let AttrArgs::Eq(_, AttrArgsEq::Hir(_)) = &normal_attr.item.args { + // `#[should_panic = ".."]` found, good + return; + } + + if let AttrArgs::Delimited(args) = &normal_attr.item.args + && let mut tt_iter = args.tokens.trees() + && let Some(TokenTree::Token(Token { kind: TokenKind::Ident(sym::expected, _), .. }, _)) = tt_iter.next() + && let Some(TokenTree::Token(Token { kind: TokenKind::Eq, .. }, _)) = tt_iter.next() + && let Some(TokenTree::Token(Token { kind: TokenKind::Literal(_), .. }, _)) = tt_iter.next() + { + // `#[should_panic(expected = "..")]` found, good + return; + } + + span_lint_and_sugg( + cx, + SHOULD_PANIC_WITHOUT_EXPECT, + attr.span, + "#[should_panic] attribute without a reason", + "consider specifying the expected panic", + r#"#[should_panic(expected = /* panic message */)]"#.into(), + Applicability::HasPlaceholders, + ); + } +} + fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) { for lint in items { if let Some(lint_name) = extract_clippy_lint(lint) { diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index db114abfc869c..bab77f912691c 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -58,6 +58,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::attrs::MAYBE_MISUSED_CFG_INFO, crate::attrs::MISMATCHED_TARGET_OS_INFO, crate::attrs::NON_MINIMAL_CFG_INFO, + crate::attrs::SHOULD_PANIC_WITHOUT_EXPECT_INFO, crate::attrs::USELESS_ATTRIBUTE_INFO, crate::await_holding_invalid::AWAIT_HOLDING_INVALID_TYPE_INFO, crate::await_holding_invalid::AWAIT_HOLDING_LOCK_INFO, diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index e72d063cfd9b4..6d5754eee78ff 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -166,3 +166,5 @@ pub const DEBUG_STRUCT: [&str; 4] = ["core", "fmt", "builders", "DebugStruct"]; pub const ORD_CMP: [&str; 4] = ["core", "cmp", "Ord", "cmp"]; #[expect(clippy::invalid_paths)] // not sure why it thinks this, it works so pub const BOOL_THEN: [&str; 4] = ["core", "bool", "", "then"]; +#[allow(clippy::invalid_paths, reason = "internal lints do not always know about ::test")] +pub const TEST_DESC_AND_FN: [&str; 3] = ["test", "types", "TestDescAndFn"]; diff --git a/tests/ui/should_panic_without_expect.rs b/tests/ui/should_panic_without_expect.rs new file mode 100644 index 0000000000000..b554fdaf22495 --- /dev/null +++ b/tests/ui/should_panic_without_expect.rs @@ -0,0 +1,21 @@ +//@no-rustfix +#![deny(clippy::should_panic_without_expect)] + +#[test] +#[should_panic] +fn no_message() {} + +#[test] +#[should_panic] +#[cfg(not(test))] +fn no_message_cfg_false() {} + +#[test] +#[should_panic = "message"] +fn metastr() {} + +#[test] +#[should_panic(expected = "message")] +fn metalist() {} + +fn main() {} diff --git a/tests/ui/should_panic_without_expect.stderr b/tests/ui/should_panic_without_expect.stderr new file mode 100644 index 0000000000000..dfcef52a9f5f4 --- /dev/null +++ b/tests/ui/should_panic_without_expect.stderr @@ -0,0 +1,14 @@ +error: #[should_panic] attribute without a reason + --> $DIR/should_panic_without_expect.rs:5:1 + | +LL | #[should_panic] + | ^^^^^^^^^^^^^^^ help: consider specifying the expected panic: `#[should_panic(expected = /* panic message */)]` + | +note: the lint level is defined here + --> $DIR/should_panic_without_expect.rs:2:9 + | +LL | #![deny(clippy::should_panic_without_expect)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + From b4ab67fd4a7d541ad25c79ac0797c889a9ea6a03 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Sat, 19 Aug 2023 14:20:15 +0200 Subject: [PATCH 50/79] remove useless path --- clippy_utils/src/paths.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index 6d5754eee78ff..e72d063cfd9b4 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -166,5 +166,3 @@ pub const DEBUG_STRUCT: [&str; 4] = ["core", "fmt", "builders", "DebugStruct"]; pub const ORD_CMP: [&str; 4] = ["core", "cmp", "Ord", "cmp"]; #[expect(clippy::invalid_paths)] // not sure why it thinks this, it works so pub const BOOL_THEN: [&str; 4] = ["core", "bool", "", "then"]; -#[allow(clippy::invalid_paths, reason = "internal lints do not always know about ::test")] -pub const TEST_DESC_AND_FN: [&str; 3] = ["test", "types", "TestDescAndFn"]; From e440065a0f930b527925b61c3a6dd5f4207dd7b6 Mon Sep 17 00:00:00 2001 From: lengyijun Date: Sat, 5 Aug 2023 10:20:16 +0800 Subject: [PATCH 51/79] [`iter_overeager_cloned`]: detect .cloned().map() and .cloned().for_each() key idea: for `f` in `.map(f)` and `.for_each(f)`: 1. `f` must be a closure with one parameter 2. don't lint if mutable paramter in clsure `f`: `|mut x| ...` 3. don't lint if parameter is moved --- .../src/methods/iter_overeager_cloned.rs | 77 ++++++++++++++++++- clippy_lints/src/methods/mod.rs | 14 ++-- tests/ui/iter_overeager_cloned.fixed | 6 +- tests/ui/iter_overeager_cloned.rs | 2 - tests/ui/iter_overeager_cloned.stderr | 18 ++++- 5 files changed, 102 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/methods/iter_overeager_cloned.rs b/clippy_lints/src/methods/iter_overeager_cloned.rs index 4b1ca0d9b9cfd..ee405a3e30c3c 100644 --- a/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -1,14 +1,18 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{implements_trait, is_copy}; +use rustc_ast::BindingAnnotation; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; +use rustc_hir::{Body, Expr, ExprKind, HirId, HirIdSet, PatKind}; +use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_lint::LateContext; -use rustc_middle::ty; +use rustc_middle::mir::{FakeReadCause, Mutability}; +use rustc_middle::ty::{self, BorrowKind}; use rustc_span::sym; use super::ITER_OVEREAGER_CLONED; use crate::redundant_clone::REDUNDANT_CLONE; +use crate::rustc_trait_selection::infer::TyCtxtInferExt; #[derive(Clone, Copy)] pub(super) enum Op<'a> { @@ -16,6 +20,10 @@ pub(super) enum Op<'a> { // e.g. `count` RmCloned, + // rm `.cloned()` + // e.g. `map` `for_each` + NeedlessMove(&'a str, &'a Expr<'a>), + // later `.cloned()` // and add `&` to the parameter of closure parameter // e.g. `find` `filter` @@ -51,8 +59,46 @@ pub(super) fn check<'tcx>( return; } + if let Op::NeedlessMove(_, expr) = op { + let rustc_hir::ExprKind::Closure(closure) = expr.kind else { return } ; + let body @ Body { params: [p], .. } = cx.tcx.hir().body(closure.body) else { return }; + let mut delegate = MoveDelegate {used_move : HirIdSet::default()}; + let infcx = cx.tcx.infer_ctxt().build(); + + ExprUseVisitor::new( + &mut delegate, + &infcx, + closure.body.hir_id.owner.def_id, + cx.param_env, + cx.typeck_results(), + ) + .consume_body(body); + + let mut to_be_discarded = false; + + p.pat.walk(|it| { + if delegate.used_move.contains(&it.hir_id){ + to_be_discarded = true; + return false; + } + + match it.kind { + PatKind::Binding(BindingAnnotation(_, Mutability::Mut), _, _, _) + | PatKind::Ref(_, Mutability::Mut) => { + to_be_discarded = true; + false + } + _ => { true } + } + }); + + if to_be_discarded { + return; + } + } + let (lint, msg, trailing_clone) = match op { - Op::RmCloned => (REDUNDANT_CLONE, "unneeded cloning of iterator items", ""), + Op::RmCloned | Op::NeedlessMove(_, _) => (REDUNDANT_CLONE, "unneeded cloning of iterator items", ""), Op::LaterCloned | Op::FixClosure(_, _) => (ITER_OVEREAGER_CLONED, "unnecessarily eager cloning of iterator items", ".cloned()"), }; @@ -83,8 +129,33 @@ pub(super) fn check<'tcx>( diag.span_suggestion(replace_span, "try", snip, Applicability::MachineApplicable); } } + Op::NeedlessMove(_, _) => { + let method_span = expr.span.with_lo(cloned_call.span.hi()); + if let Some(snip) = snippet_opt(cx, method_span) { + let replace_span = expr.span.with_lo(cloned_recv.span.hi()); + diag.span_suggestion(replace_span, "try", snip, Applicability::MaybeIncorrect); + } + } } } ); } } + +struct MoveDelegate { + used_move: HirIdSet, +} + +impl<'tcx> Delegate<'tcx> for MoveDelegate { + fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, _: HirId) { + if let PlaceBase::Local(l) = place_with_id.place.base { + self.used_move.insert(l); + } + } + + fn borrow(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId, _: BorrowKind) {} + + fn mutate(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} + + fn fake_read(&mut self, _: &PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {} +} diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 3a8af0248d81e..5075137caa0cb 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -4001,9 +4001,11 @@ impl Methods { manual_try_fold::check(cx, expr, init, acc, call_span, &self.msrv); unnecessary_fold::check(cx, expr, init, acc, span); }, - ("for_each", [_]) => { - if let Some(("inspect", _, [_], span2, _)) = method_call(recv) { - inspect_for_each::check(cx, expr, span2); + ("for_each", [arg]) => { + match method_call(recv) { + Some(("inspect", _, [_], span2, _)) => inspect_for_each::check(cx, expr, span2), + Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, iter_overeager_cloned::Op::NeedlessMove(name, arg), false), + _ => {} } }, ("get", [arg]) => { @@ -4038,8 +4040,10 @@ impl Methods { (name @ ("map" | "map_err"), [m_arg]) => { if name == "map" { map_clone::check(cx, expr, recv, m_arg, &self.msrv); - if let Some((map_name @ ("iter" | "into_iter"), recv2, _, _, _)) = method_call(recv) { - iter_kv_map::check(cx, map_name, expr, recv2, m_arg); + match method_call(recv) { + Some((map_name @ ("iter" | "into_iter"), recv2, _, _, _)) => iter_kv_map::check(cx, map_name, expr, recv2, m_arg), + Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check(cx, expr, recv, recv2, iter_overeager_cloned::Op::NeedlessMove(name, m_arg), false), + _ => {} } } else { map_err_ignore::check(cx, expr, m_arg); diff --git a/tests/ui/iter_overeager_cloned.fixed b/tests/ui/iter_overeager_cloned.fixed index 9605b449b4095..9dd046fec1fee 100644 --- a/tests/ui/iter_overeager_cloned.fixed +++ b/tests/ui/iter_overeager_cloned.fixed @@ -56,14 +56,12 @@ fn main() { } } - // Not implemented yet - let _ = vec.iter().cloned().map(|x| x.len()); + let _ = vec.iter().map(|x| x.len()); // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); - // Not implemented yet - let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); + let _ = vec.iter().for_each(|x| assert!(!x.is_empty())); // Not implemented yet let _ = vec.iter().cloned().all(|x| x.len() == 1); diff --git a/tests/ui/iter_overeager_cloned.rs b/tests/ui/iter_overeager_cloned.rs index 8d75f039d44e4..3cab366955481 100644 --- a/tests/ui/iter_overeager_cloned.rs +++ b/tests/ui/iter_overeager_cloned.rs @@ -57,13 +57,11 @@ fn main() { } } - // Not implemented yet let _ = vec.iter().cloned().map(|x| x.len()); // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); - // Not implemented yet let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); // Not implemented yet diff --git a/tests/ui/iter_overeager_cloned.stderr b/tests/ui/iter_overeager_cloned.stderr index bdbb04d7f0828..4417a40a63b8b 100644 --- a/tests/ui/iter_overeager_cloned.stderr +++ b/tests/ui/iter_overeager_cloned.stderr @@ -130,5 +130,21 @@ LL | iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target | | | help: try: `.filter(move |&S { a, b }| **a == 1 && b == &target).cloned()` -error: aborting due to 15 previous errors +error: unneeded cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:60:13 + | +LL | let _ = vec.iter().cloned().map(|x| x.len()); + | ^^^^^^^^^^-------------------------- + | | + | help: try: `.map(|x| x.len())` + +error: unneeded cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:65:13 + | +LL | let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); + | ^^^^^^^^^^---------------------------------------------- + | | + | help: try: `.for_each(|x| assert!(!x.is_empty()))` + +error: aborting due to 17 previous errors From 8f2d47ea72fdc754697b381441fb49953bf37b58 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sat, 19 Aug 2023 18:06:46 +0000 Subject: [PATCH 52/79] Check that the suggested method exists in unwrap_or_default --- clippy_lints/src/methods/or_fun_call.rs | 19 ++++++++++++++-- tests/ui/unwrap_or_else_default.fixed | 30 +++++++++++++++++++++++++ tests/ui/unwrap_or_else_default.rs | 30 +++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 8b2f57160af48..942f3bd79a618 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -65,11 +65,26 @@ pub(super) fn check<'tcx>( }; let sugg = match (name, call_expr.is_some()) { - ("unwrap_or", true) | ("unwrap_or_else", false) => "unwrap_or_default", - ("or_insert", true) | ("or_insert_with", false) => "or_default", + ("unwrap_or", true) | ("unwrap_or_else", false) => sym!(unwrap_or_default), + ("or_insert", true) | ("or_insert_with", false) => sym!(or_default), _ => return false, }; + let receiver_ty = cx.typeck_results().expr_ty_adjusted(receiver).peel_refs(); + let has_suggested_method = receiver_ty.ty_adt_def().is_some_and(|adt_def| { + cx.tcx + .inherent_impls(adt_def.did()) + .iter() + .flat_map(|impl_id| cx.tcx.associated_items(impl_id).filter_by_name_unhygienic(sugg)) + .any(|assoc| { + assoc.fn_has_self_parameter + && cx.tcx.fn_sig(assoc.def_id).skip_binder().inputs().skip_binder().len() == 1 + }) + }); + if !has_suggested_method { + return false; + } + // needs to target Default::default in particular or be *::new and have a Default impl // available if (is_new(fun) && output_type_implements_default(fun)) diff --git a/tests/ui/unwrap_or_else_default.fixed b/tests/ui/unwrap_or_else_default.fixed index 73d9990795860..8d5d34175c525 100644 --- a/tests/ui/unwrap_or_else_default.fixed +++ b/tests/ui/unwrap_or_else_default.fixed @@ -130,4 +130,34 @@ fn method_call_with_deref() { let _ = inner_map.entry(0).or_default(); } +fn missing_suggested_method() { + #[derive(Copy, Clone)] + struct S(T); + + impl S { + fn or_insert_with(&mut self, default: impl FnOnce() -> T) -> &mut T { + &mut self.0 + } + + fn or_insert(&mut self, default: T) -> &mut T { + &mut self.0 + } + + fn unwrap_or_else(self, default: impl FnOnce() -> T) -> T { + self.0 + } + + fn unwrap_or(self, default: T) -> T { + self.0 + } + } + + // Don't lint when or_default/unwrap_or_default do not exist on the type + let mut s = S(1); + s.or_insert_with(Default::default); + s.or_insert(Default::default()); + s.unwrap_or_else(Default::default); + s.unwrap_or(Default::default()); +} + fn main() {} diff --git a/tests/ui/unwrap_or_else_default.rs b/tests/ui/unwrap_or_else_default.rs index afacedf17c63c..adbcb4b446591 100644 --- a/tests/ui/unwrap_or_else_default.rs +++ b/tests/ui/unwrap_or_else_default.rs @@ -130,4 +130,34 @@ fn method_call_with_deref() { let _ = inner_map.entry(0).or_insert_with(Default::default); } +fn missing_suggested_method() { + #[derive(Copy, Clone)] + struct S(T); + + impl S { + fn or_insert_with(&mut self, default: impl FnOnce() -> T) -> &mut T { + &mut self.0 + } + + fn or_insert(&mut self, default: T) -> &mut T { + &mut self.0 + } + + fn unwrap_or_else(self, default: impl FnOnce() -> T) -> T { + self.0 + } + + fn unwrap_or(self, default: T) -> T { + self.0 + } + } + + // Don't lint when or_default/unwrap_or_default do not exist on the type + let mut s = S(1); + s.or_insert_with(Default::default); + s.or_insert(Default::default()); + s.unwrap_or_else(Default::default); + s.unwrap_or(Default::default()); +} + fn main() {} From 50f7f8e0f84cd646b7272103cd70f4a337bd589a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 19 Aug 2023 13:10:25 +0200 Subject: [PATCH 53/79] give some unwind-related terminators a more clear name --- clippy_utils/src/qualify_min_const_fn.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index 139e31bc5286a..43523faa23612 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -291,8 +291,8 @@ fn check_terminator<'tcx>( | TerminatorKind::FalseUnwind { .. } | TerminatorKind::Goto { .. } | TerminatorKind::Return - | TerminatorKind::Resume - | TerminatorKind::Terminate + | TerminatorKind::UnwindResume + | TerminatorKind::UnwindTerminate | TerminatorKind::Unreachable => Ok(()), TerminatorKind::Drop { place, .. } => { if !is_ty_const_destruct(tcx, place.ty(&body.local_decls, tcx).ty, body) { From 7fbf808a5056f63da5d2ae86ebeb32fb21f45b50 Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Mon, 21 Aug 2023 18:50:53 +0200 Subject: [PATCH 54/79] Added new lint: `reserve_after_initialization` --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/lib.rs | 2 + .../src/reserve_after_initialization.rs | 242 ++++++++++++++++++ tests/ui/reserve_after_initialization.fixed | 5 + tests/ui/reserve_after_initialization.rs | 6 + tests/ui/reserve_after_initialization.stderr | 11 + 7 files changed, 268 insertions(+) create mode 100644 clippy_lints/src/reserve_after_initialization.rs create mode 100644 tests/ui/reserve_after_initialization.fixed create mode 100644 tests/ui/reserve_after_initialization.rs create mode 100644 tests/ui/reserve_after_initialization.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index fe64283462d11..4e33cb7b45707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5299,6 +5299,7 @@ Released 2018-09-13 [`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro [`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once [`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts +[`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 [`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used [`result_large_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index bab77f912691c..1be9720fbbf8d 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -579,6 +579,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::reference::DEREF_ADDROF_INFO, crate::regex::INVALID_REGEX_INFO, crate::regex::TRIVIAL_REGEX_INFO, + crate::reserve_after_initialization::RESERVE_AFTER_INITIALIZATION_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 358004cf460b1..791fb96453d03 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -285,6 +285,7 @@ mod ref_option_ref; mod ref_patterns; mod reference; mod regex; +mod reserve_after_initialization; mod return_self_not_must_use; mod returns; mod same_name_method; @@ -1095,6 +1096,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: }); store.register_late_pass(|_| Box::new(redundant_locals::RedundantLocals)); store.register_late_pass(|_| Box::new(ignored_unit_patterns::IgnoredUnitPatterns)); + store.register_late_pass(|_| Box::new(reserve_after_initialization::ReserveAfterInitialization::default())); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs new file mode 100644 index 0000000000000..073f810048c13 --- /dev/null +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -0,0 +1,242 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher::{get_vec_init_kind, VecInitKind}; +use clippy_utils::source::snippet; +use clippy_utils::visitors::for_each_local_use_after_expr; +use clippy_utils::{get_parent_expr, path_to_local_id}; +use core::ops::ControlFlow; +use rustc_ast::LitKind; +use rustc_errors::Applicability; +use rustc_hir::def::Res; +use rustc_hir::{ + BindingAnnotation, Block, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp, +}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_middle::lint::in_external_macro; +use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::{Span, Symbol}; + +declare_clippy_lint! { + /// ### What it does + /// Informs the user about a more concise way to create a vector with a known capacity. + /// + /// ### Why is this bad? + /// The `Vec::with_capacity` constructor is easier to understand. + /// + /// ### Example + /// ```rust + /// { + /// let mut v = vec![]; + /// v.reserve(space_hint); + /// v + /// } + /// ``` + /// Use instead: + /// ```rust + /// Vec::with_capacity(space_hint) + /// ``` + #[clippy::version = "1.73.0"] + pub RESERVE_AFTER_INITIALIZATION, + complexity, + "`reserve` called immediatly after `Vec` creation" +} +impl_lint_pass!(ReserveAfterInitialization => [RESERVE_AFTER_INITIALIZATION]); + +/*impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'_>) { + if let ExprKind::Assign(left, right, _) = expr.kind + && let ExprKind::Path(QPath::Resolved(None, path)) = left.kind + && let [name] = &path.segments + && let Res::Local(id) = path.res + && let Some(init) = get_vec_init_kind(cx, right) + && !matches!(init, VecInitKind::WithExprCapacity(_)) { + span_lint_and_help( + cx, + RESERVE_AFTER_INITIALIZATION, + expr.span, + "`reserve` called just after the initialisation of the vector", + None, + "use `Vec::with_capacity(space_hint)` instead" + ); + } + } + + /*fn check_block(&mut self, cx: &LateContext<'_>, block: &'_ rustc_hir::Block<'_>) { + span_lint_and_help( + cx, + RESERVE_AFTER_INITIALIZATION, + block.span, + "`reserve` called just after the initialisation of the vector", + None, + "use `Vec::with_capacity(space_hint)` instead" + ); + }*/ +}*/ + +#[derive(Default)] +pub struct ReserveAfterInitialization { + searcher: Option, +} + +struct VecReserveSearcher { + local_id: HirId, + lhs_is_let: bool, + let_ty_span: Option, + name: Symbol, + err_span: Span, + last_reserve_expr: HirId, + space_hint: usize, +} +impl VecReserveSearcher { + fn display_err(&self, cx: &LateContext<'_>) { + if self.space_hint == 0 { + return; + } + + let mut needs_mut = false; + let _res = for_each_local_use_after_expr(cx, self.local_id, self.last_reserve_expr, |e| { + let Some(parent) = get_parent_expr(cx, e) else { + return ControlFlow::Continue(()); + }; + let adjusted_ty = cx.typeck_results().expr_ty_adjusted(e); + let adjusted_mut = adjusted_ty.ref_mutability().unwrap_or(Mutability::Not); + needs_mut |= adjusted_mut == Mutability::Mut; + match parent.kind { + ExprKind::AddrOf(_, Mutability::Mut, _) => { + needs_mut = true; + return ControlFlow::Break(true); + }, + ExprKind::Unary(UnOp::Deref, _) | ExprKind::Index(..) if !needs_mut => { + let mut last_place = parent; + while let Some(parent) = get_parent_expr(cx, last_place) { + if matches!(parent.kind, ExprKind::Unary(UnOp::Deref, _) | ExprKind::Field(..)) + || matches!(parent.kind, ExprKind::Index(e, _, _) if e.hir_id == last_place.hir_id) + { + last_place = parent; + } else { + break; + } + } + needs_mut |= cx.typeck_results().expr_ty_adjusted(last_place).ref_mutability() + == Some(Mutability::Mut) + || get_parent_expr(cx, last_place) + .map_or(false, |e| matches!(e.kind, ExprKind::AddrOf(_, Mutability::Mut, _))); + }, + ExprKind::MethodCall(_, recv, ..) + if recv.hir_id == e.hir_id + && adjusted_mut == Mutability::Mut + && !adjusted_ty.peel_refs().is_slice() => + { + // No need to set `needs_mut` to true. The receiver will be either explicitly borrowed, or it will + // be implicitly borrowed via an adjustment. Both of these cases are already handled by this point. + return ControlFlow::Break(true); + }, + ExprKind::Assign(lhs, ..) if e.hir_id == lhs.hir_id => { + needs_mut = true; + return ControlFlow::Break(false); + }, + _ => (), + } + ControlFlow::Continue(()) + }); + + let mut s = if self.lhs_is_let { + String::from("let ") + } else { + String::new() + }; + if needs_mut { + s.push_str("mut "); + } + s.push_str(self.name.as_str()); + if let Some(span) = self.let_ty_span { + s.push_str(": "); + s.push_str(&snippet(cx, span, "_")); + } + s.push_str(format!(" = Vec::with_capacity({});", self.space_hint).as_str()); + + span_lint_and_sugg( + cx, + RESERVE_AFTER_INITIALIZATION, + self.err_span, + "calls to `reverse` immediately after creation", + "consider using `Vec::with_capacity(space_hint)`", + s, + Applicability::HasPlaceholders, + ); + } +} + +impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { + fn check_block(&mut self, _: &LateContext<'tcx>, _: &'tcx Block<'tcx>) { + self.searcher = None; + } + + fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { + if let Some(init_expr) = local.init + && let PatKind::Binding(BindingAnnotation::MUT, id, name, None) = local.pat.kind + && !in_external_macro(cx.sess(), local.span) + && let Some(init) = get_vec_init_kind(cx, init_expr) + && !matches!(init, VecInitKind::WithExprCapacity(_)) + { + self.searcher = Some(VecReserveSearcher { + local_id: id, + lhs_is_let: true, + name: name.name, + let_ty_span: local.ty.map(|ty| ty.span), + err_span: local.span, + last_reserve_expr: init_expr.hir_id, + space_hint: 0 + }); + } + } + + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { + if self.searcher.is_none() + && let ExprKind::Assign(left, right, _) = expr.kind + && let ExprKind::Path(QPath::Resolved(None, path)) = left.kind + && let [name] = &path.segments + && let Res::Local(id) = path.res + && !in_external_macro(cx.sess(), expr.span) + && let Some(init) = get_vec_init_kind(cx, right) + && !matches!(init, VecInitKind::WithExprCapacity(_)) + { + self.searcher = Some(VecReserveSearcher { + local_id: id, + lhs_is_let: false, + let_ty_span: None, + name: name.ident.name, + err_span: expr.span, + last_reserve_expr: expr.hir_id, + space_hint: 0 + }); + } + } + + 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 + && let ExprKind::MethodCall(name, self_arg, other_args, _) = expr.kind + && other_args.len() == 1 + && let ExprKind::Lit(lit) = other_args[0].kind + && let LitKind::Int(space_hint, _) = lit.node + && path_to_local_id(self_arg, searcher.local_id) + && name.ident.as_str() == "reserve" + { + self.searcher = Some(VecReserveSearcher { + err_span: searcher.err_span.to(stmt.span), + last_reserve_expr: expr.hir_id, + space_hint: space_hint as usize, + .. searcher + }); + } else { + searcher.display_err(cx); + } + } + } + + fn check_block_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx Block<'tcx>) { + if let Some(searcher) = self.searcher.take() { + searcher.display_err(cx); + } + } +} diff --git a/tests/ui/reserve_after_initialization.fixed b/tests/ui/reserve_after_initialization.fixed new file mode 100644 index 0000000000000..fe1f7ff174e50 --- /dev/null +++ b/tests/ui/reserve_after_initialization.fixed @@ -0,0 +1,5 @@ +#![warn(clippy::reserve_after_initialization)] + +fn main() { + let v: Vec = Vec::with_capacity(10); +} diff --git a/tests/ui/reserve_after_initialization.rs b/tests/ui/reserve_after_initialization.rs new file mode 100644 index 0000000000000..469b951b1c429 --- /dev/null +++ b/tests/ui/reserve_after_initialization.rs @@ -0,0 +1,6 @@ +#![warn(clippy::reserve_after_initialization)] + +fn main() { + let mut v: Vec = vec![]; + v.reserve(10); +} diff --git a/tests/ui/reserve_after_initialization.stderr b/tests/ui/reserve_after_initialization.stderr new file mode 100644 index 0000000000000..da8c7d693f0b4 --- /dev/null +++ b/tests/ui/reserve_after_initialization.stderr @@ -0,0 +1,11 @@ +error: calls to `reverse` immediately after creation + --> $DIR/reserve_after_initialization.rs:4:5 + | +LL | / let mut v: Vec = vec![]; +LL | | v.reserve(10); + | |__________________^ help: consider using `Vec::with_capacity(space_hint)`: `let v: Vec = Vec::with_capacity(10);` + | + = note: `-D clippy::reserve-after-initialization` implied by `-D warnings` + +error: aborting due to previous error + From e33a17e33c0201f8fe00a17e875fe8f8b7210ce5 Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Mon, 21 Aug 2023 19:05:59 +0200 Subject: [PATCH 55/79] Changed Box --- clippy_lints/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 791fb96453d03..f50019f3cf766 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1096,7 +1096,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: }); store.register_late_pass(|_| Box::new(redundant_locals::RedundantLocals)); store.register_late_pass(|_| Box::new(ignored_unit_patterns::IgnoredUnitPatterns)); - store.register_late_pass(|_| Box::new(reserve_after_initialization::ReserveAfterInitialization::default())); + store.register_late_pass(|_| Box::::default()); // add lints here, do not remove this comment, it's used in `new_lint` } From 073149a7ef483b8feddacc865e935d6019272e14 Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Mon, 21 Aug 2023 19:21:02 +0200 Subject: [PATCH 56/79] Changed documentation example and removed comments --- .../src/reserve_after_initialization.rs | 40 ++----------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index 073f810048c13..6a2bbd0af8528 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -24,15 +24,12 @@ declare_clippy_lint! { /// /// ### Example /// ```rust - /// { - /// let mut v = vec![]; - /// v.reserve(space_hint); - /// v - /// } + /// let mut v: Vec = vec![]; + /// v.reserve(10); /// ``` /// Use instead: /// ```rust - /// Vec::with_capacity(space_hint) + /// let mut v: Vec = Vec::with_capacity(10); /// ``` #[clippy::version = "1.73.0"] pub RESERVE_AFTER_INITIALIZATION, @@ -41,37 +38,6 @@ declare_clippy_lint! { } impl_lint_pass!(ReserveAfterInitialization => [RESERVE_AFTER_INITIALIZATION]); -/*impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'_>) { - if let ExprKind::Assign(left, right, _) = expr.kind - && let ExprKind::Path(QPath::Resolved(None, path)) = left.kind - && let [name] = &path.segments - && let Res::Local(id) = path.res - && let Some(init) = get_vec_init_kind(cx, right) - && !matches!(init, VecInitKind::WithExprCapacity(_)) { - span_lint_and_help( - cx, - RESERVE_AFTER_INITIALIZATION, - expr.span, - "`reserve` called just after the initialisation of the vector", - None, - "use `Vec::with_capacity(space_hint)` instead" - ); - } - } - - /*fn check_block(&mut self, cx: &LateContext<'_>, block: &'_ rustc_hir::Block<'_>) { - span_lint_and_help( - cx, - RESERVE_AFTER_INITIALIZATION, - block.span, - "`reserve` called just after the initialisation of the vector", - None, - "use `Vec::with_capacity(space_hint)` instead" - ); - }*/ -}*/ - #[derive(Default)] pub struct ReserveAfterInitialization { searcher: Option, From a1bf23f0a394788aec496e5440d8520d2807caec Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Mon, 21 Aug 2023 22:22:48 +0200 Subject: [PATCH 57/79] Added more use cases --- .../src/reserve_after_initialization.rs | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index 6a2bbd0af8528..f9454bd7540b0 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -50,11 +50,11 @@ struct VecReserveSearcher { name: Symbol, err_span: Span, last_reserve_expr: HirId, - space_hint: usize, + space_hint: Option, } impl VecReserveSearcher { fn display_err(&self, cx: &LateContext<'_>) { - if self.space_hint == 0 { + if self.space_hint == Some(0) { return; } @@ -118,7 +118,16 @@ impl VecReserveSearcher { s.push_str(": "); s.push_str(&snippet(cx, span, "_")); } - s.push_str(format!(" = Vec::with_capacity({});", self.space_hint).as_str()); + s.push_str( + format!( + " = Vec::with_capacity({});", + match self.space_hint { + None => "..".to_string(), + Some(hint) => hint.to_string(), + } + ) + .as_str(), + ); span_lint_and_sugg( cx, @@ -151,7 +160,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { let_ty_span: local.ty.map(|ty| ty.span), err_span: local.span, last_reserve_expr: init_expr.hir_id, - space_hint: 0 + space_hint: Some(0) }); } } @@ -173,7 +182,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { name: name.ident.name, err_span: expr.span, last_reserve_expr: expr.hir_id, - space_hint: 0 + space_hint: Some(0) }); } } @@ -183,17 +192,25 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind && let ExprKind::MethodCall(name, self_arg, other_args, _) = expr.kind && other_args.len() == 1 - && let ExprKind::Lit(lit) = other_args[0].kind - && let LitKind::Int(space_hint, _) = lit.node && path_to_local_id(self_arg, searcher.local_id) && name.ident.as_str() == "reserve" { - self.searcher = Some(VecReserveSearcher { - err_span: searcher.err_span.to(stmt.span), - last_reserve_expr: expr.hir_id, - space_hint: space_hint as usize, - .. searcher - }); + if let ExprKind::Lit(lit) = other_args[0].kind + && let LitKind::Int(space_hint, _) = lit.node { + self.searcher = Some(VecReserveSearcher { + err_span: searcher.err_span.to(stmt.span), + last_reserve_expr: expr.hir_id, + space_hint: Some(space_hint as usize), // the expression is an int, so we'll display the good amount as a hint + .. searcher + }); + } else { + self.searcher = Some(VecReserveSearcher { + err_span: searcher.err_span.to(stmt.span), + last_reserve_expr: expr.hir_id, + space_hint: None, // the expression isn't an int, so we'll display ".." as hint + .. searcher + }); + } } else { searcher.display_err(cx); } From b0bd6219c8f62ea97bbc6d5580f9b847758fb195 Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Mon, 21 Aug 2023 23:36:15 +0200 Subject: [PATCH 58/79] Simplified code and added tests --- .../src/reserve_after_initialization.rs | 138 ++++-------------- tests/ui/reserve_after_initialization.fixed | 14 +- tests/ui/reserve_after_initialization.rs | 17 ++- tests/ui/reserve_after_initialization.stderr | 17 ++- 4 files changed, 66 insertions(+), 120 deletions(-) diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index f9454bd7540b0..d530d5758b1f5 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -1,19 +1,15 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::higher::{get_vec_init_kind, VecInitKind}; +use clippy_utils::path_to_local_id; use clippy_utils::source::snippet; -use clippy_utils::visitors::for_each_local_use_after_expr; -use clippy_utils::{get_parent_expr, path_to_local_id}; -use core::ops::ControlFlow; -use rustc_ast::LitKind; +//use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def::Res; -use rustc_hir::{ - BindingAnnotation, Block, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp, -}; +use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Local, PatKind, QPath, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_span::{Span, Symbol}; +use rustc_span::Span; declare_clippy_lint! { /// ### What it does @@ -45,89 +41,17 @@ pub struct ReserveAfterInitialization { struct VecReserveSearcher { local_id: HirId, - lhs_is_let: bool, - let_ty_span: Option, - name: Symbol, err_span: Span, - last_reserve_expr: HirId, - space_hint: Option, + init_part: String, + space_hint: String, } impl VecReserveSearcher { fn display_err(&self, cx: &LateContext<'_>) { - if self.space_hint == Some(0) { + if self.space_hint.is_empty() { return; } - let mut needs_mut = false; - let _res = for_each_local_use_after_expr(cx, self.local_id, self.last_reserve_expr, |e| { - let Some(parent) = get_parent_expr(cx, e) else { - return ControlFlow::Continue(()); - }; - let adjusted_ty = cx.typeck_results().expr_ty_adjusted(e); - let adjusted_mut = adjusted_ty.ref_mutability().unwrap_or(Mutability::Not); - needs_mut |= adjusted_mut == Mutability::Mut; - match parent.kind { - ExprKind::AddrOf(_, Mutability::Mut, _) => { - needs_mut = true; - return ControlFlow::Break(true); - }, - ExprKind::Unary(UnOp::Deref, _) | ExprKind::Index(..) if !needs_mut => { - let mut last_place = parent; - while let Some(parent) = get_parent_expr(cx, last_place) { - if matches!(parent.kind, ExprKind::Unary(UnOp::Deref, _) | ExprKind::Field(..)) - || matches!(parent.kind, ExprKind::Index(e, _, _) if e.hir_id == last_place.hir_id) - { - last_place = parent; - } else { - break; - } - } - needs_mut |= cx.typeck_results().expr_ty_adjusted(last_place).ref_mutability() - == Some(Mutability::Mut) - || get_parent_expr(cx, last_place) - .map_or(false, |e| matches!(e.kind, ExprKind::AddrOf(_, Mutability::Mut, _))); - }, - ExprKind::MethodCall(_, recv, ..) - if recv.hir_id == e.hir_id - && adjusted_mut == Mutability::Mut - && !adjusted_ty.peel_refs().is_slice() => - { - // No need to set `needs_mut` to true. The receiver will be either explicitly borrowed, or it will - // be implicitly borrowed via an adjustment. Both of these cases are already handled by this point. - return ControlFlow::Break(true); - }, - ExprKind::Assign(lhs, ..) if e.hir_id == lhs.hir_id => { - needs_mut = true; - return ControlFlow::Break(false); - }, - _ => (), - } - ControlFlow::Continue(()) - }); - - let mut s = if self.lhs_is_let { - String::from("let ") - } else { - String::new() - }; - if needs_mut { - s.push_str("mut "); - } - s.push_str(self.name.as_str()); - if let Some(span) = self.let_ty_span { - s.push_str(": "); - s.push_str(&snippet(cx, span, "_")); - } - s.push_str( - format!( - " = Vec::with_capacity({});", - match self.space_hint { - None => "..".to_string(), - Some(hint) => hint.to_string(), - } - ) - .as_str(), - ); + let s = format!("{} = Vec::with_capacity({});", self.init_part, self.space_hint); span_lint_and_sugg( cx, @@ -148,19 +72,22 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { if let Some(init_expr) = local.init - && let PatKind::Binding(BindingAnnotation::MUT, id, name, None) = local.pat.kind + && let PatKind::Binding(BindingAnnotation::MUT, id, _name, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) && let Some(init) = get_vec_init_kind(cx, init_expr) && !matches!(init, VecInitKind::WithExprCapacity(_)) + && !matches!(init, VecInitKind::WithConstCapacity(_)) { self.searcher = Some(VecReserveSearcher { local_id: id, - lhs_is_let: true, - name: name.name, - let_ty_span: local.ty.map(|ty| ty.span), err_span: local.span, - last_reserve_expr: init_expr.hir_id, - space_hint: Some(0) + init_part: format!("let {}: {}", + snippet(cx, local.pat.span, ""), + match local.ty { + Some(type_inference) => snippet(cx, type_inference.span, "").to_string(), + None => String::new() + }), + space_hint: String::new() }); } } @@ -169,20 +96,18 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { if self.searcher.is_none() && let ExprKind::Assign(left, right, _) = expr.kind && let ExprKind::Path(QPath::Resolved(None, path)) = left.kind - && let [name] = &path.segments + && let [_name] = &path.segments && let Res::Local(id) = path.res && !in_external_macro(cx.sess(), expr.span) && let Some(init) = get_vec_init_kind(cx, right) && !matches!(init, VecInitKind::WithExprCapacity(_)) + && !matches!(init, VecInitKind::WithConstCapacity(_)) { self.searcher = Some(VecReserveSearcher { local_id: id, - lhs_is_let: false, - let_ty_span: None, - name: name.ident.name, err_span: expr.span, - last_reserve_expr: expr.hir_id, - space_hint: Some(0) + init_part: snippet(cx, left.span, "").to_string(), + space_hint: String::new() }); } } @@ -195,22 +120,11 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { && path_to_local_id(self_arg, searcher.local_id) && name.ident.as_str() == "reserve" { - if let ExprKind::Lit(lit) = other_args[0].kind - && let LitKind::Int(space_hint, _) = lit.node { - self.searcher = Some(VecReserveSearcher { - err_span: searcher.err_span.to(stmt.span), - last_reserve_expr: expr.hir_id, - space_hint: Some(space_hint as usize), // the expression is an int, so we'll display the good amount as a hint - .. searcher - }); - } else { - self.searcher = Some(VecReserveSearcher { - err_span: searcher.err_span.to(stmt.span), - last_reserve_expr: expr.hir_id, - space_hint: None, // the expression isn't an int, so we'll display ".." as hint - .. searcher - }); - } + self.searcher = Some(VecReserveSearcher { + err_span: searcher.err_span.to(stmt.span), + space_hint: snippet(cx, other_args[0].span, "").to_string(), + .. searcher + }); } else { searcher.display_err(cx); } diff --git a/tests/ui/reserve_after_initialization.fixed b/tests/ui/reserve_after_initialization.fixed index fe1f7ff174e50..e7dd8f6b14fbb 100644 --- a/tests/ui/reserve_after_initialization.fixed +++ b/tests/ui/reserve_after_initialization.fixed @@ -1,5 +1,17 @@ #![warn(clippy::reserve_after_initialization)] fn main() { - let v: Vec = Vec::with_capacity(10); + // Should lint + let mut v1: Vec = Vec::with_capacity(10); + + // Should lint + let capacity = 10; + let mut v2: Vec = Vec::with_capacity(capacity); + + // Shouldn't lint + let mut v3 = vec![1]; + v3.reserve(10); + + // Shouldn't lint + let mut v4: Vec = Vec::with_capacity(10); } diff --git a/tests/ui/reserve_after_initialization.rs b/tests/ui/reserve_after_initialization.rs index 469b951b1c429..07f9377dbfe20 100644 --- a/tests/ui/reserve_after_initialization.rs +++ b/tests/ui/reserve_after_initialization.rs @@ -1,6 +1,19 @@ #![warn(clippy::reserve_after_initialization)] fn main() { - let mut v: Vec = vec![]; - v.reserve(10); + // Should lint + let mut v1: Vec = vec![]; + v1.reserve(10); + + // Should lint + let capacity = 10; + let mut v2: Vec = vec![]; + v2.reserve(capacity); + + // Shouldn't lint + let mut v3 = vec![1]; + v3.reserve(10); + + // Shouldn't lint + let mut v4: Vec = Vec::with_capacity(10); } diff --git a/tests/ui/reserve_after_initialization.stderr b/tests/ui/reserve_after_initialization.stderr index da8c7d693f0b4..ab2753cdd6005 100644 --- a/tests/ui/reserve_after_initialization.stderr +++ b/tests/ui/reserve_after_initialization.stderr @@ -1,11 +1,18 @@ error: calls to `reverse` immediately after creation - --> $DIR/reserve_after_initialization.rs:4:5 + --> $DIR/reserve_after_initialization.rs:5:5 | -LL | / let mut v: Vec = vec![]; -LL | | v.reserve(10); - | |__________________^ help: consider using `Vec::with_capacity(space_hint)`: `let v: Vec = Vec::with_capacity(10);` +LL | / let mut v1: Vec = vec![]; +LL | | v1.reserve(10); + | |___________________^ help: consider using `Vec::with_capacity(space_hint)`: `let mut v1: Vec = Vec::with_capacity(10);` | = note: `-D clippy::reserve-after-initialization` implied by `-D warnings` -error: aborting due to previous error +error: calls to `reverse` immediately after creation + --> $DIR/reserve_after_initialization.rs:10:5 + | +LL | / let mut v2: Vec = vec![]; +LL | | v2.reserve(capacity); + | |_________________________^ help: consider using `Vec::with_capacity(space_hint)`: `let mut v2: Vec = Vec::with_capacity(capacity);` + +error: aborting due to 2 previous errors From e35eb91a337431b5894aa6755d0d8317b9aa2cca Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Tue, 22 Aug 2023 13:15:05 +0400 Subject: [PATCH 59/79] Fix tuple_array_conversions lint on nightly --- clippy_lints/src/tuple_array_conversions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/tuple_array_conversions.rs b/clippy_lints/src/tuple_array_conversions.rs index 78ad52d8a8794..c12519d723c08 100644 --- a/clippy_lints/src/tuple_array_conversions.rs +++ b/clippy_lints/src/tuple_array_conversions.rs @@ -189,8 +189,8 @@ fn all_bindings_are_for_conv<'tcx>( tys.len() == elements.len() && tys.iter().chain(final_tys.iter().copied()).all_equal() }, (ToType::Tuple, ty::Array(ty, len)) => { - len.eval_target_usize(cx.tcx, cx.param_env) as usize == elements.len() - && final_tys.iter().chain(once(ty)).all_equal() + let Some(len) = len.try_eval_target_usize(cx.tcx, cx.param_env) else { return false }; + len as usize == elements.len() && final_tys.iter().chain(once(ty)).all_equal() }, _ => false, } From 9c96605b20229d08a11f693412494cccc42f1ed0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 28 Jul 2023 15:24:40 +0200 Subject: [PATCH 60/79] Manually add annotations for ui tests --- tests/ui/crashes/auxiliary/ice-7868-aux.rs | 2 + tests/ui/trivially_copy_pass_by_ref.rs | 19 ++++++- tests/ui/trivially_copy_pass_by_ref.stderr | 60 +++++++++++----------- 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/tests/ui/crashes/auxiliary/ice-7868-aux.rs b/tests/ui/crashes/auxiliary/ice-7868-aux.rs index bee29894b63d5..882b66d676938 100644 --- a/tests/ui/crashes/auxiliary/ice-7868-aux.rs +++ b/tests/ui/crashes/auxiliary/ice-7868-aux.rs @@ -1,3 +1,5 @@ fn zero() { unsafe { 0 }; + //~^ ERROR: unsafe block missing a safety comment + //~| NOTE: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` } diff --git a/tests/ui/trivially_copy_pass_by_ref.rs b/tests/ui/trivially_copy_pass_by_ref.rs index 3575e9f4f4cb8..043a7b63af3cc 100644 --- a/tests/ui/trivially_copy_pass_by_ref.rs +++ b/tests/ui/trivially_copy_pass_by_ref.rs @@ -1,5 +1,5 @@ //@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)" -//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)" +//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: 8 byte)" #![deny(clippy::trivially_copy_pass_by_ref)] #![allow( clippy::disallowed_names, @@ -50,6 +50,8 @@ fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> { } fn bad(x: &u32, y: &Foo, z: &Baz) {} +//~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by +//~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by impl Foo { fn good(self, a: &mut u32, b: u32, c: &Bar) {} @@ -57,10 +59,18 @@ impl Foo { fn good2(&mut self) {} fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by fn bad2(x: &u32, y: &Foo, z: &Baz) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by fn bad_issue7518(self, other: &Self) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if } impl AsRef for Foo { @@ -73,10 +83,14 @@ impl Bar { fn good(&self, a: &mut u32, b: u32, c: &Bar) {} fn bad2(x: &u32, y: &Foo, z: &Baz) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if } trait MyTrait { fn trait_method(&self, _foo: &Foo); + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if } pub trait MyTrait2 { @@ -109,11 +123,13 @@ mod issue5876 { #[inline(never)] fn foo_never(x: &i32) { + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by println!("{}", x); } #[inline] fn foo(x: &i32) { + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by println!("{}", x); } } @@ -141,6 +157,7 @@ async fn _async_explicit<'a>(x: &'a u32) -> &'a u32 { } fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 { + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by y } diff --git a/tests/ui/trivially_copy_pass_by_ref.stderr b/tests/ui/trivially_copy_pass_by_ref.stderr index 2af668537f5c3..903c240bfcaba 100644 --- a/tests/ui/trivially_copy_pass_by_ref.stderr +++ b/tests/ui/trivially_copy_pass_by_ref.stderr @@ -22,92 +22,92 @@ error: this argument (N byte) is passed by reference, but would be more efficien 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) - --> $DIR/trivially_copy_pass_by_ref.rs:59:12 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61: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) - --> $DIR/trivially_copy_pass_by_ref.rs:59:22 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61: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) - --> $DIR/trivially_copy_pass_by_ref.rs:59:31 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61: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) - --> $DIR/trivially_copy_pass_by_ref.rs:59:40 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61: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) - --> $DIR/trivially_copy_pass_by_ref.rs:61:16 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:67: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) - --> $DIR/trivially_copy_pass_by_ref.rs:61:25 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:67: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) - --> $DIR/trivially_copy_pass_by_ref.rs:61:34 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:67: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) - --> $DIR/trivially_copy_pass_by_ref.rs:63:35 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:72: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) - --> $DIR/trivially_copy_pass_by_ref.rs:75:16 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:85: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) - --> $DIR/trivially_copy_pass_by_ref.rs:75:25 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:85: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) - --> $DIR/trivially_copy_pass_by_ref.rs:75:34 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:85: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) - --> $DIR/trivially_copy_pass_by_ref.rs:79:34 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:92:34 | 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) - --> $DIR/trivially_copy_pass_by_ref.rs:111:21 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:125: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) - --> $DIR/trivially_copy_pass_by_ref.rs:116:15 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:131: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) - --> $DIR/trivially_copy_pass_by_ref.rs:143:37 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:159:37 | LL | fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 { | ^^^^^^^ help: consider passing by value instead: `u32` From 3a31c0557889cb8242764ef8568fa870685199f9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 28 Jul 2023 20:40:44 +0200 Subject: [PATCH 61/79] Remove/move comments to prevent weird rustfmt wrapping --- tests/ui/bytecount.rs | 24 +- tests/ui/bytecount.stderr | 12 +- tests/ui/cast.rs | 81 ++++-- tests/ui/cast.stderr | 82 +++--- tests/ui/char_lit_as_u8.rs | 3 +- tests/ui/char_lit_as_u8.stderr | 4 +- .../ui/checked_unwrap/complex_conditionals.rs | 60 ++-- .../complex_conditionals.stderr | 86 +++--- .../complex_conditionals_nested.rs | 6 +- .../complex_conditionals_nested.stderr | 9 +- .../ui/checked_unwrap/simple_conditionals.rs | 75 +++-- .../checked_unwrap/simple_conditionals.stderr | 79 ++--- tests/ui/collection_is_never_read.rs | 40 +-- tests/ui/collection_is_never_read.stderr | 40 +-- tests/ui/disallowed_script_idents.rs | 12 +- tests/ui/disallowed_script_idents.stderr | 8 +- tests/ui/eprint_with_newline.fixed | 14 +- tests/ui/eprint_with_newline.rs | 14 +- tests/ui/eprint_with_newline.stderr | 14 +- tests/ui/indexing_slicing_index.rs | 42 ++- tests/ui/indexing_slicing_index.stderr | 26 +- tests/ui/indexing_slicing_slice.rs | 6 +- tests/ui/indexing_slicing_slice.stderr | 12 +- tests/ui/infinite_iter.rs | 59 ++-- tests/ui/infinite_iter.stderr | 56 ++-- tests/ui/missing_inline.rs | 18 +- tests/ui/missing_inline.stderr | 24 +- tests/ui/modulo_one.rs | 15 +- tests/ui/modulo_one.stderr | 24 +- tests/ui/mut_range_bound.rs | 16 +- tests/ui/mut_range_bound.stderr | 10 +- tests/ui/needless_continue.rs | 12 +- tests/ui/needless_continue.stderr | 16 +- tests/ui/out_of_bounds_indexing/issue-3102.rs | 4 +- .../out_of_bounds_indexing/issue-3102.stderr | 4 +- tests/ui/print_with_newline.fixed | 17 +- tests/ui/print_with_newline.rs | 17 +- tests/ui/print_with_newline.stderr | 20 +- tests/ui/trailing_zeros.fixed | 4 +- tests/ui/trailing_zeros.rs | 4 +- tests/ui/trailing_zeros.stderr | 4 +- tests/ui/transmute_undefined_repr.rs | 274 +++++++++++------- tests/ui/transmute_undefined_repr.stderr | 48 +-- tests/ui/trivially_copy_pass_by_ref.stderr | 6 +- tests/ui/write_literal_2.rs | 6 +- tests/ui/write_literal_2.stderr | 8 +- tests/ui/write_with_newline.fixed | 14 +- tests/ui/write_with_newline.rs | 14 +- tests/ui/write_with_newline.stderr | 14 +- 49 files changed, 850 insertions(+), 607 deletions(-) diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index 10a1d904bf6c7..ba1ef6e49168e 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -6,23 +6,31 @@ fn main() { let x = vec![0_u8; 16]; - let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count + // naive byte count + let _ = x.iter().filter(|&&a| a == 0).count(); - let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count + // naive byte count + let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); - let _ = x.iter().filter(|a| **a > 0).count(); // not an equality count, OK. + // not an equality count, OK. + let _ = x.iter().filter(|a| **a > 0).count(); - let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count(); // not a slice + // not a slice + let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count(); let b = 0; - let _ = x.iter().filter(|_| b > 0).count(); // woah there + // woah there + let _ = x.iter().filter(|_| b > 0).count(); - let _ = x.iter().filter(|_a| b == b + 1).count(); // nothing to see here, move along + // nothing to see here, move along + let _ = x.iter().filter(|_a| b == b + 1).count(); - let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count + // naive byte count + let _ = x.iter().filter(|a| b + 1 == **a).count(); let y = vec![0_u16; 3]; - let _ = y.iter().filter(|&&a| a == 0).count(); // naive count, but not bytes + // naive count, but not bytes + let _ = y.iter().filter(|&&a| a == 0).count(); } diff --git a/tests/ui/bytecount.stderr b/tests/ui/bytecount.stderr index 2b7dc2ac08748..680b7b2bda8b9 100644 --- a/tests/ui/bytecount.stderr +++ b/tests/ui/bytecount.stderr @@ -1,7 +1,7 @@ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:9:13 + --> $DIR/bytecount.rs:10:13 | -LL | let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count +LL | let _ = x.iter().filter(|&&a| a == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, 0)` | note: the lint level is defined here @@ -11,15 +11,15 @@ LL | #[deny(clippy::naive_bytecount)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:11:13 + --> $DIR/bytecount.rs:13:13 | -LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count +LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count((&x[..]), 0)` error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:23:13 + --> $DIR/bytecount.rs:30:13 | -LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count +LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, b + 1)` error: aborting due to 3 previous errors diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index d5ebe67c4e9fa..d2cfa41611844 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -43,14 +43,22 @@ fn main() { 1u32 as i32; 1u64 as i64; 1usize as isize; - 1usize as i8; // should not wrap, usize is never 8 bits - 1usize as i16; // wraps on 16 bit ptr size - 1usize as i32; // wraps on 32 bit ptr size - 1usize as i64; // wraps on 64 bit ptr size - 1u8 as isize; // should not wrap, isize is never 8 bits - 1u16 as isize; // wraps on 16 bit ptr size - 1u32 as isize; // wraps on 32 bit ptr size - 1u64 as isize; // wraps on 64 bit ptr size + // should not wrap, usize is never 8 bits + 1usize as i8; + // wraps on 16 bit ptr size + 1usize as i16; + // wraps on 32 bit ptr size + 1usize as i32; + // wraps on 64 bit ptr size + 1usize as i64; + // should not wrap, isize is never 8 bits + 1u8 as isize; + // wraps on 16 bit ptr size + 1u16 as isize; + // wraps on 32 bit ptr size + 1u32 as isize; + // wraps on 64 bit ptr size + 1u64 as isize; // Test clippy::cast_sign_loss 1i32 as u32; -1i32 as u32; @@ -122,7 +130,8 @@ fn main() { let _ = s as i32; // Test for signed min - (-99999999999i64).min(1) as i8; // should be linted because signed + // should be linted because signed + (-99999999999i64).min(1) as i8; // Test for various operations that remove enough bits for the result to fit (999999u64 & 1) as u8; @@ -134,7 +143,8 @@ fn main() { x.min(1) }) as u8; 999999u64.clamp(0, 255) as u8; - 999999u64.clamp(0, 256) as u8; // should still be linted + // should still be linted + 999999u64.clamp(0, 256) as u8; #[derive(Clone, Copy)] enum E1 { @@ -144,7 +154,8 @@ fn main() { } impl E1 { fn test(self) { - let _ = self as u8; // Don't lint. `0..=2` fits in u8 + // Don't lint. `0..=2` fits in u8 + let _ = self as u8; } } @@ -157,8 +168,10 @@ fn main() { fn test(self) { let _ = self as u8; let _ = Self::B as u8; - let _ = self as i16; // Don't lint. `255..=256` fits in i16 - let _ = Self::A as u8; // Don't lint. + // Don't lint. `255..=256` fits in i16 + let _ = self as i16; + // Don't lint. + let _ = Self::A as u8; } } @@ -170,7 +183,8 @@ fn main() { } impl E3 { fn test(self) { - let _ = self as i8; // Don't lint. `-1..=50` fits in i8 + // Don't lint. `-1..=50` fits in i8 + let _ = self as i8; } } @@ -181,7 +195,8 @@ fn main() { } impl E4 { fn test(self) { - let _ = self as i8; // Don't lint. `-128..=-127` fits in i8 + // Don't lint. `-128..=-127` fits in i8 + let _ = self as i8; } } @@ -194,8 +209,10 @@ fn main() { fn test(self) { let _ = self as i8; let _ = Self::A as i8; - let _ = self as i16; // Don't lint. `-129..=127` fits in i16 - let _ = Self::B as u8; // Don't lint. + // Don't lint. `-129..=127` fits in i16 + let _ = self as i16; + // Don't lint. + let _ = Self::B as u8; } } @@ -208,9 +225,12 @@ fn main() { impl E6 { fn test(self) { let _ = self as i16; - let _ = Self::A as u16; // Don't lint. `2^16-1` fits in u16 - let _ = self as u32; // Don't lint. `2^16-1..=2^16` fits in u32 - let _ = Self::A as u16; // Don't lint. + // Don't lint. `2^16-1` fits in u16 + let _ = Self::A as u16; + // Don't lint. `2^16-1..=2^16` fits in u32 + let _ = self as u32; + // Don't lint. + let _ = Self::A as u16; } } @@ -223,8 +243,10 @@ fn main() { impl E7 { fn test(self) { let _ = self as usize; - let _ = Self::A as usize; // Don't lint. - let _ = self as u64; // Don't lint. `2^32-1..=2^32` fits in u64 + // Don't lint. + let _ = Self::A as usize; + // Don't lint. `2^32-1..=2^32` fits in u64 + let _ = self as u64; } } @@ -238,7 +260,8 @@ fn main() { } impl E8 { fn test(self) { - let _ = self as i128; // Don't lint. `-(2^127)..=2^127-1` fits it i128 + // Don't lint. `-(2^127)..=2^127-1` fits it i128 + let _ = self as i128; } } @@ -250,8 +273,10 @@ fn main() { } impl E9 { fn test(self) { - let _ = Self::A as u8; // Don't lint. - let _ = self as u128; // Don't lint. `0..=2^128-1` fits in u128 + // Don't lint. + let _ = Self::A as u8; + // Don't lint. `0..=2^128-1` fits in u128 + let _ = self as u128; } } @@ -264,8 +289,10 @@ fn main() { impl E10 { fn test(self) { let _ = self as u16; - let _ = Self::B as u32; // Don't lint. - let _ = self as u64; // Don't lint. + // Don't lint. + let _ = Self::B as u32; + // Don't lint. + let _ = self as u64; } } } diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index ff2a4294512b5..f0630743aa75c 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -216,133 +216,133 @@ LL | 1usize as isize; | ^^^^^^^^^^^^^^^ error: casting `usize` to `i8` may truncate the value - --> $DIR/cast.rs:46:5 + --> $DIR/cast.rs:47:5 | -LL | 1usize as i8; // should not wrap, usize is never 8 bits +LL | 1usize as i8; | ^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from(1usize); // should not wrap, usize is never 8 bits +LL | i8::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may truncate the value - --> $DIR/cast.rs:47:5 + --> $DIR/cast.rs:49:5 | -LL | 1usize as i16; // wraps on 16 bit ptr size +LL | 1usize as i16; | ^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i16::try_from(1usize); // wraps on 16 bit ptr size +LL | i16::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:47:5 + --> $DIR/cast.rs:49:5 | -LL | 1usize as i16; // wraps on 16 bit ptr size +LL | 1usize as i16; | ^^^^^^^^^^^^^ | = note: `usize` and `isize` may be as small as 16 bits on some platforms = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:48:5 + --> $DIR/cast.rs:51:5 | -LL | 1usize as i32; // wraps on 32 bit ptr size +LL | 1usize as i32; | ^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i32::try_from(1usize); // wraps on 32 bit ptr size +LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:48:5 + --> $DIR/cast.rs:51:5 | -LL | 1usize as i32; // wraps on 32 bit ptr size +LL | 1usize as i32; | ^^^^^^^^^^^^^ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:49:5 + --> $DIR/cast.rs:53:5 | -LL | 1usize as i64; // wraps on 64 bit ptr size +LL | 1usize as i64; | ^^^^^^^^^^^^^ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:57:5 | -LL | 1u16 as isize; // wraps on 16 bit ptr size +LL | 1u16 as isize; | ^^^^^^^^^^^^^ | = note: `usize` and `isize` may be as small as 16 bits on some platforms = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:52:5 + --> $DIR/cast.rs:59:5 | -LL | 1u32 as isize; // wraps on 32 bit ptr size +LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:53:5 + --> $DIR/cast.rs:61:5 | -LL | 1u64 as isize; // wraps on 64 bit ptr size +LL | 1u64 as isize; | ^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | isize::try_from(1u64); // wraps on 64 bit ptr size +LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:53:5 + --> $DIR/cast.rs:61:5 | -LL | 1u64 as isize; // wraps on 64 bit ptr size +LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:56:5 + --> $DIR/cast.rs:64:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> $DIR/cast.rs:58:5 + --> $DIR/cast.rs:66:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> $DIR/cast.rs:125:5 + --> $DIR/cast.rs:134:5 | -LL | (-99999999999i64).min(1) as i8; // should be linted because signed +LL | (-99999999999i64).min(1) as i8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from((-99999999999i64).min(1)); // should be linted because signed +LL | i8::try_from((-99999999999i64).min(1)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> $DIR/cast.rs:137:5 + --> $DIR/cast.rs:147:5 | -LL | 999999u64.clamp(0, 256) as u8; // should still be linted +LL | 999999u64.clamp(0, 256) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted +LL | u8::try_from(999999u64.clamp(0, 256)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E2` to `u8` may truncate the value - --> $DIR/cast.rs:158:21 + --> $DIR/cast.rs:169:21 | LL | let _ = self as u8; | ^^^^^^^^^^ @@ -354,7 +354,7 @@ LL | let _ = u8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E2::B` to `u8` will truncate the value - --> $DIR/cast.rs:159:21 + --> $DIR/cast.rs:170:21 | LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ @@ -362,7 +362,7 @@ LL | let _ = Self::B as u8; = note: `-D clippy::cast-enum-truncation` implied by `-D warnings` error: casting `main::E5` to `i8` may truncate the value - --> $DIR/cast.rs:195:21 + --> $DIR/cast.rs:210:21 | LL | let _ = self as i8; | ^^^^^^^^^^ @@ -374,13 +374,13 @@ LL | let _ = i8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E5::A` to `i8` will truncate the value - --> $DIR/cast.rs:196:21 + --> $DIR/cast.rs:211:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> $DIR/cast.rs:210:21 + --> $DIR/cast.rs:227:21 | LL | let _ = self as i16; | ^^^^^^^^^^^ @@ -392,7 +392,7 @@ LL | let _ = i16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:225:21 + --> $DIR/cast.rs:245:21 | LL | let _ = self as usize; | ^^^^^^^^^^^^^ @@ -404,7 +404,7 @@ LL | let _ = usize::try_from(self); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E10` to `u16` may truncate the value - --> $DIR/cast.rs:266:21 + --> $DIR/cast.rs:291:21 | LL | let _ = self as u16; | ^^^^^^^^^^^ @@ -416,7 +416,7 @@ LL | let _ = u16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:274:13 + --> $DIR/cast.rs:301:13 | LL | let c = (q >> 16) as u8; | ^^^^^^^^^^^^^^^ @@ -428,7 +428,7 @@ LL | let c = u8::try_from(q >> 16); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:277:13 + --> $DIR/cast.rs:304:13 | LL | let c = (q / 1000) as u8; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/char_lit_as_u8.rs b/tests/ui/char_lit_as_u8.rs index 0a53a3d6490a3..e724c456b8883 100644 --- a/tests/ui/char_lit_as_u8.rs +++ b/tests/ui/char_lit_as_u8.rs @@ -1,5 +1,6 @@ #![warn(clippy::char_lit_as_u8)] fn main() { - let _ = '❤' as u8; // no suggestion, since a byte literal won't work. + // no suggestion, since a byte literal won't work. + let _ = '❤' as u8; } diff --git a/tests/ui/char_lit_as_u8.stderr b/tests/ui/char_lit_as_u8.stderr index 39fc9d6dda674..da3e5c5e52b16 100644 --- a/tests/ui/char_lit_as_u8.stderr +++ b/tests/ui/char_lit_as_u8.stderr @@ -1,7 +1,7 @@ error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8.rs:4:13 + --> $DIR/char_lit_as_u8.rs:5:13 | -LL | let _ = '❤' as u8; // no suggestion, since a byte literal won't work. +LL | let _ = '❤' as u8; | ^^^^^^^^^ | = note: `char` is four bytes wide, but `u8` is a single byte diff --git a/tests/ui/checked_unwrap/complex_conditionals.rs b/tests/ui/checked_unwrap/complex_conditionals.rs index 16e54a7d969ef..9e618350b1982 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.rs +++ b/tests/ui/checked_unwrap/complex_conditionals.rs @@ -9,10 +9,14 @@ fn test_complex_conditions() { let x: Result<(), ()> = Ok(()); let y: Result<(), ()> = Ok(()); if x.is_ok() && y.is_err() { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic - y.unwrap(); // will panic - y.unwrap_err(); // unnecessary + // unnecessary + x.unwrap(); + // will panic + x.unwrap_err(); + // will panic + y.unwrap(); + // unnecessary + y.unwrap_err(); } else { // not statically determinable whether any of the following will always succeed or always fail: x.unwrap(); @@ -26,19 +30,29 @@ fn test_complex_conditions() { x.unwrap(); y.unwrap(); } else { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary - y.unwrap(); // will panic - y.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + // unnecessary + x.unwrap_err(); + // will panic + y.unwrap(); + // unnecessary + y.unwrap_err(); } let z: Result<(), ()> = Ok(()); if x.is_ok() && !(y.is_ok() || z.is_err()) { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic - y.unwrap(); // will panic - y.unwrap_err(); // unnecessary - z.unwrap(); // unnecessary - z.unwrap_err(); // will panic + // unnecessary + x.unwrap(); + // will panic + x.unwrap_err(); + // will panic + y.unwrap(); + // unnecessary + y.unwrap_err(); + // unnecessary + z.unwrap(); + // will panic + z.unwrap_err(); } if x.is_ok() || !(y.is_ok() && z.is_err()) { // not statically determinable whether any of the following will always succeed or always fail: @@ -46,12 +60,18 @@ fn test_complex_conditions() { y.unwrap(); z.unwrap(); } else { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary - y.unwrap(); // unnecessary - y.unwrap_err(); // will panic - z.unwrap(); // will panic - z.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + // unnecessary + x.unwrap_err(); + // unnecessary + y.unwrap(); + // will panic + y.unwrap_err(); + // will panic + z.unwrap(); + // unnecessary + z.unwrap_err(); } } diff --git a/tests/ui/checked_unwrap/complex_conditionals.stderr b/tests/ui/checked_unwrap/complex_conditionals.stderr index c395c5ba06f2e..f342815ac76ba 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals.stderr @@ -1,9 +1,10 @@ error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:12:9 + --> $DIR/complex_conditionals.rs:13:9 | LL | if x.is_ok() && y.is_err() { | --------- the check is happening here -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` @@ -14,12 +15,12 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:13:9 + --> $DIR/complex_conditionals.rs:15:9 | LL | if x.is_ok() && y.is_err() { | --------- because of this check -LL | x.unwrap(); // unnecessary -LL | x.unwrap_err(); // will panic +... +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ | note: the lint level is defined here @@ -29,180 +30,181 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:14:9 + --> $DIR/complex_conditionals.rs:17:9 | LL | if x.is_ok() && y.is_err() { | ---------- because of this check ... -LL | y.unwrap(); // will panic +LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:15:9 + --> $DIR/complex_conditionals.rs:19:9 | LL | if x.is_ok() && y.is_err() { | ---------- the check is happening here ... -LL | y.unwrap_err(); // unnecessary +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:29:9 + --> $DIR/complex_conditionals.rs:34:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:30:9 + --> $DIR/complex_conditionals.rs:36:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here ... -LL | x.unwrap_err(); // unnecessary +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:31:9 + --> $DIR/complex_conditionals.rs:38:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check ... -LL | y.unwrap(); // will panic +LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:32:9 + --> $DIR/complex_conditionals.rs:40:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here ... -LL | y.unwrap_err(); // unnecessary +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:36:9 + --> $DIR/complex_conditionals.rs:45:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:37:9 + --> $DIR/complex_conditionals.rs:47:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check -LL | x.unwrap(); // unnecessary -LL | x.unwrap_err(); // will panic +... +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:38:9 + --> $DIR/complex_conditionals.rs:49:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check ... -LL | y.unwrap(); // will panic +LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:39:9 + --> $DIR/complex_conditionals.rs:51:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here ... -LL | y.unwrap_err(); // unnecessary +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: called `unwrap` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:40:9 + --> $DIR/complex_conditionals.rs:53:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- the check is happening here ... -LL | z.unwrap(); // unnecessary +LL | z.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:41:9 + --> $DIR/complex_conditionals.rs:55:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- because of this check ... -LL | z.unwrap_err(); // will panic +LL | z.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:49:9 + --> $DIR/complex_conditionals.rs:64:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:50:9 + --> $DIR/complex_conditionals.rs:66:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here ... -LL | x.unwrap_err(); // unnecessary +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: called `unwrap` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:51:9 + --> $DIR/complex_conditionals.rs:68:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here ... -LL | y.unwrap(); // unnecessary +LL | y.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:52:9 + --> $DIR/complex_conditionals.rs:70:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check ... -LL | y.unwrap_err(); // will panic +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:53:9 + --> $DIR/complex_conditionals.rs:72:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- because of this check ... -LL | z.unwrap(); // will panic +LL | z.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:54:9 + --> $DIR/complex_conditionals.rs:74:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- the check is happening here ... -LL | z.unwrap_err(); // unnecessary +LL | z.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.rs b/tests/ui/checked_unwrap/complex_conditionals_nested.rs index e390cfab58d94..1ee8d16565b5c 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.rs +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.rs @@ -9,9 +9,11 @@ fn test_nested() { fn nested() { let x = Some(()); if x.is_some() { - x.unwrap(); // unnecessary + // unnecessary + x.unwrap(); } else { - x.unwrap(); // will panic + // will panic + x.unwrap(); } } } diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr index 049a69d93bfe9..bf7c6750ccfda 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr @@ -1,9 +1,10 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/complex_conditionals_nested.rs:12:13 + --> $DIR/complex_conditionals_nested.rs:13:13 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here @@ -13,12 +14,12 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals_nested.rs:14:13 + --> $DIR/complex_conditionals_nested.rs:16:13 | LL | if x.is_some() { | ----------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 15a246fce6403..12522ae5ba12c 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -10,7 +10,8 @@ macro_rules! m { ($a:expr) => { if $a.is_some() { - $a.unwrap(); // unnecessary + // unnecessary + $a.unwrap(); } }; } @@ -42,37 +43,56 @@ macro_rules! checks_some { fn main() { let x = Some(()); if x.is_some() { - x.unwrap(); // unnecessary - x.expect("an error message"); // unnecessary + // unnecessary + x.unwrap(); + // unnecessary + x.expect("an error message"); } else { - x.unwrap(); // will panic - x.expect("an error message"); // will panic + // will panic + x.unwrap(); + // will panic + x.expect("an error message"); } if x.is_none() { - x.unwrap(); // will panic + // will panic + x.unwrap(); } else { - x.unwrap(); // unnecessary + // unnecessary + x.unwrap(); } m!(x); - checks_in_param!(x.is_some(), x.unwrap()); // ok - checks_unwrap!(x, x.unwrap()); // ok - checks_some!(x.is_some(), x); // ok + // ok + checks_in_param!(x.is_some(), x.unwrap()); + // ok + checks_unwrap!(x, x.unwrap()); + // ok + checks_some!(x.is_some(), x); let mut x: Result<(), ()> = Ok(()); if x.is_ok() { - x.unwrap(); // unnecessary - x.expect("an error message"); // unnecessary - x.unwrap_err(); // will panic + // unnecessary + x.unwrap(); + // unnecessary + x.expect("an error message"); + // will panic + x.unwrap_err(); } else { - x.unwrap(); // will panic - x.expect("an error message"); // will panic - x.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + // will panic + x.expect("an error message"); + // unnecessary + x.unwrap_err(); } if x.is_err() { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + // unnecessary + x.unwrap_err(); } else { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic + // unnecessary + x.unwrap(); + // will panic + x.unwrap_err(); } if x.is_ok() { x = Err(()); @@ -88,20 +108,25 @@ fn main() { x.unwrap_err(); } - assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern + // ok, it's a common test pattern + assert!(x.is_ok(), "{:?}", x.unwrap_err()); } fn check_expect() { let x = Some(()); if x.is_some() { #[expect(clippy::unnecessary_unwrap)] - x.unwrap(); // unnecessary + // unnecessary + x.unwrap(); #[expect(clippy::unnecessary_unwrap)] - x.expect("an error message"); // unnecessary + // unnecessary + x.expect("an error message"); } else { #[expect(clippy::panicking_unwrap)] - x.unwrap(); // will panic + // will panic + x.unwrap(); #[expect(clippy::panicking_unwrap)] - x.expect("an error message"); // will panic + // will panic + x.expect("an error message"); } } diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index dae7c88126268..0c5a64979241f 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -1,9 +1,10 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:45:9 + --> $DIR/simple_conditionals.rs:47:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here @@ -13,21 +14,21 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:46:9 + --> $DIR/simple_conditionals.rs:49:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` -LL | x.unwrap(); // unnecessary -LL | x.expect("an error message"); // unnecessary +... +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:48:9 + --> $DIR/simple_conditionals.rs:52:9 | LL | if x.is_some() { | ----------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here @@ -37,37 +38,39 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:49:9 + --> $DIR/simple_conditionals.rs:54:9 | LL | if x.is_some() { | ----------- because of this check ... -LL | x.expect("an error message"); // will panic +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:52:9 + --> $DIR/simple_conditionals.rs:58:9 | LL | if x.is_none() { | ----------- because of this check -LL | x.unwrap(); // will panic +LL | // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_none` - --> $DIR/simple_conditionals.rs:54:9 + --> $DIR/simple_conditionals.rs:61:9 | LL | if x.is_none() { | -------------- help: try: `if let Some(..) = x` ... -LL | x.unwrap(); // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:13:13 + --> $DIR/simple_conditionals.rs:14:13 | LL | if $a.is_some() { | --------------- help: try: `if let Some(..) = x` -LL | $a.unwrap(); // unnecessary +LL | // unnecessary +LL | $a.unwrap(); | ^^^^^^^^^^^ ... LL | m!(x); @@ -76,91 +79,93 @@ LL | m!(x); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:62:9 + --> $DIR/simple_conditionals.rs:73:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:63:9 + --> $DIR/simple_conditionals.rs:75:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` -LL | x.unwrap(); // unnecessary -LL | x.expect("an error message"); // unnecessary +... +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:64:9 + --> $DIR/simple_conditionals.rs:77:9 | LL | if x.is_ok() { | --------- because of this check ... -LL | x.unwrap_err(); // will panic +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:66:9 + --> $DIR/simple_conditionals.rs:80:9 | LL | if x.is_ok() { | --------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:67:9 + --> $DIR/simple_conditionals.rs:82:9 | LL | if x.is_ok() { | --------- because of this check ... -LL | x.expect("an error message"); // will panic +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:68:9 + --> $DIR/simple_conditionals.rs:84:9 | LL | if x.is_ok() { | ------------ help: try: `if let Err(..) = x` ... -LL | x.unwrap_err(); // unnecessary +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:71:9 + --> $DIR/simple_conditionals.rs:88:9 | LL | if x.is_err() { | ---------- because of this check -LL | x.unwrap(); // will panic +LL | // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:72:9 + --> $DIR/simple_conditionals.rs:90:9 | LL | if x.is_err() { | ------------- help: try: `if let Err(..) = x` -LL | x.unwrap(); // will panic -LL | x.unwrap_err(); // unnecessary +... +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:74:9 + --> $DIR/simple_conditionals.rs:93:9 | LL | if x.is_err() { | ------------- help: try: `if let Ok(..) = x` ... -LL | x.unwrap(); // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:75:9 + --> $DIR/simple_conditionals.rs:95:9 | LL | if x.is_err() { | ---------- because of this check ... -LL | x.unwrap_err(); // will panic +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: aborting due to 17 previous errors diff --git a/tests/ui/collection_is_never_read.rs b/tests/ui/collection_is_never_read.rs index e02c1c57230ad..f7ba68fd8948e 100644 --- a/tests/ui/collection_is_never_read.rs +++ b/tests/ui/collection_is_never_read.rs @@ -18,7 +18,7 @@ fn no_access_at_all() { fn write_without_read() { // The main use case for `collection_is_never_read`. - let mut x = HashMap::new(); // WARNING + let mut x = HashMap::new(); x.insert(1, 2); } @@ -57,7 +57,7 @@ fn read_in_closure() { } fn write_in_closure() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; let _ = || { x.push(4); }; @@ -72,12 +72,12 @@ fn read_in_format() { fn shadowing_1() { let x = HashMap::::new(); // Ok let _ = x.len(); - let mut x = HashMap::new(); // WARNING + let mut x = HashMap::new(); x.insert(1, 2); } fn shadowing_2() { - let mut x = HashMap::new(); // WARNING + let mut x = HashMap::new(); x.insert(1, 2); let x = HashMap::::new(); // Ok let _ = x.len(); @@ -85,26 +85,26 @@ fn shadowing_2() { #[allow(clippy::let_unit_value)] fn fake_read_1() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; x.reverse(); let _: () = x.clear(); } fn fake_read_2() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; x.reverse(); println!("{:?}", x.push(5)); } fn assignment() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; let y = vec![4, 5, 6]; // Ok x = y; } #[allow(clippy::self_assignment)] fn self_assignment() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; x = x; } @@ -121,7 +121,7 @@ fn method_argument_but_not_target() { } fn insert_is_not_a_read() { - let mut x = HashSet::new(); // WARNING + let mut x = HashSet::new(); x.insert(5); } @@ -135,7 +135,7 @@ fn insert_is_a_read() { fn not_read_if_return_value_not_used() { // `is_empty` does not modify the set, so it's a query. But since the return value is not used, the // lint does not consider it a read here. - let x = vec![1, 2, 3]; // WARNING + let x = vec![1, 2, 3]; x.is_empty(); } @@ -170,34 +170,34 @@ fn function_argument() { } fn supported_types() { - let mut x = std::collections::BTreeMap::new(); // WARNING + let mut x = std::collections::BTreeMap::new(); x.insert(true, 1); - let mut x = std::collections::BTreeSet::new(); // WARNING + let mut x = std::collections::BTreeSet::new(); x.insert(1); - let mut x = std::collections::BinaryHeap::new(); // WARNING + let mut x = std::collections::BinaryHeap::new(); x.push(1); - let mut x = std::collections::HashMap::new(); // WARNING + let mut x = std::collections::HashMap::new(); x.insert(1, 2); - let mut x = std::collections::HashSet::new(); // WARNING + let mut x = std::collections::HashSet::new(); x.insert(1); - let mut x = std::collections::LinkedList::new(); // WARNING + let mut x = std::collections::LinkedList::new(); x.push_front(1); - let mut x = Some(true); // WARNING + let mut x = Some(true); x.insert(false); - let mut x = String::from("hello"); // WARNING + let mut x = String::from("hello"); x.push('!'); - let mut x = Vec::new(); // WARNING + let mut x = Vec::new(); x.clear(); x.push(1); - let mut x = std::collections::VecDeque::new(); // WARNING + let mut x = std::collections::VecDeque::new(); x.push_front(1); } diff --git a/tests/ui/collection_is_never_read.stderr b/tests/ui/collection_is_never_read.stderr index 982cb445534a2..32ba6b9bc2738 100644 --- a/tests/ui/collection_is_never_read.stderr +++ b/tests/ui/collection_is_never_read.stderr @@ -1,7 +1,7 @@ error: collection is never read --> $DIR/collection_is_never_read.rs:21:5 | -LL | let mut x = HashMap::new(); // WARNING +LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::collection-is-never-read` implied by `-D warnings` @@ -9,115 +9,115 @@ LL | let mut x = HashMap::new(); // WARNING error: collection is never read --> $DIR/collection_is_never_read.rs:60:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:75:5 | -LL | let mut x = HashMap::new(); // WARNING +LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:80:5 | -LL | let mut x = HashMap::new(); // WARNING +LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:88:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:94:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:100:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:107:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:124:5 | -LL | let mut x = HashSet::new(); // WARNING +LL | let mut x = HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:138:5 | -LL | let x = vec![1, 2, 3]; // WARNING +LL | let x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:173:5 | -LL | let mut x = std::collections::BTreeMap::new(); // WARNING +LL | let mut x = std::collections::BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:176:5 | -LL | let mut x = std::collections::BTreeSet::new(); // WARNING +LL | let mut x = std::collections::BTreeSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:179:5 | -LL | let mut x = std::collections::BinaryHeap::new(); // WARNING +LL | let mut x = std::collections::BinaryHeap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:182:5 | -LL | let mut x = std::collections::HashMap::new(); // WARNING +LL | let mut x = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:185:5 | -LL | let mut x = std::collections::HashSet::new(); // WARNING +LL | let mut x = std::collections::HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:188:5 | -LL | let mut x = std::collections::LinkedList::new(); // WARNING +LL | let mut x = std::collections::LinkedList::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:191:5 | -LL | let mut x = Some(true); // WARNING +LL | let mut x = Some(true); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:194:5 | -LL | let mut x = String::from("hello"); // WARNING +LL | let mut x = String::from("hello"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:197:5 | -LL | let mut x = Vec::new(); // WARNING +LL | let mut x = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read --> $DIR/collection_is_never_read.rs:201:5 | -LL | let mut x = std::collections::VecDeque::new(); // WARNING +LL | let mut x = std::collections::VecDeque::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 20 previous errors diff --git a/tests/ui/disallowed_script_idents.rs b/tests/ui/disallowed_script_idents.rs index cfdda35971fb6..6fc6f9988ebe4 100644 --- a/tests/ui/disallowed_script_idents.rs +++ b/tests/ui/disallowed_script_idents.rs @@ -2,9 +2,13 @@ #![allow(dead_code)] fn main() { - let counter = 10; // OK, latin is allowed. - let zähler = 10; // OK, it's still latin. + // OK, latin is allowed. + let counter = 10; + // OK, it's still latin. + let zähler = 10; - let счётчик = 10; // Cyrillic is not allowed by default. - let カウンタ = 10; // Same for japanese. + // Cyrillic is not allowed by default. + let счётчик = 10; + // Same for japanese. + let カウンタ = 10; } diff --git a/tests/ui/disallowed_script_idents.stderr b/tests/ui/disallowed_script_idents.stderr index cc84dc1d43c59..7b91d8c426b27 100644 --- a/tests/ui/disallowed_script_idents.stderr +++ b/tests/ui/disallowed_script_idents.stderr @@ -1,7 +1,7 @@ error: identifier `счётчик` has a Unicode script that is not allowed by configuration: Cyrillic - --> $DIR/disallowed_script_idents.rs:8:9 + --> $DIR/disallowed_script_idents.rs:11:9 | -LL | let счётчик = 10; // Cyrillic is not allowed by default. +LL | let счётчик = 10; | ^^^^^^^ | note: the lint level is defined here @@ -11,9 +11,9 @@ LL | #![deny(clippy::disallowed_script_idents)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: identifier `カウンタ` has a Unicode script that is not allowed by configuration: Katakana - --> $DIR/disallowed_script_idents.rs:9:9 + --> $DIR/disallowed_script_idents.rs:13:9 | -LL | let カウンタ = 10; // Same for japanese. +LL | let カウンタ = 10; | ^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/eprint_with_newline.fixed b/tests/ui/eprint_with_newline.fixed index c63a657142026..d0349e68622a6 100644 --- a/tests/ui/eprint_with_newline.fixed +++ b/tests/ui/eprint_with_newline.fixed @@ -20,16 +20,20 @@ fn main() { eprint!("\n\n"); eprint!("like eof\n\n"); eprint!("Hello {} {}\n\n", "world", "#2"); - eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - eprintln!("\nbla\n\n"); // #3126 + // #3126 + eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + eprintln!("\nbla\n\n"); // Escaping - eprint!("\\n"); // #3514 - eprintln!("\\"); // should fail + // #3514 + eprint!("\\n"); + eprintln!("\\"); eprint!("\\\\n"); // Raw strings - eprint!(r"\n"); // #3778 + // #3778 + eprint!(r"\n"); // Literal newlines should also fail eprintln!( diff --git a/tests/ui/eprint_with_newline.rs b/tests/ui/eprint_with_newline.rs index 8389806c838e1..9446d5d651a17 100644 --- a/tests/ui/eprint_with_newline.rs +++ b/tests/ui/eprint_with_newline.rs @@ -20,16 +20,20 @@ fn main() { eprint!("\n\n"); eprint!("like eof\n\n"); eprint!("Hello {} {}\n\n", "world", "#2"); - eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - eprintln!("\nbla\n\n"); // #3126 + // #3126 + eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + eprintln!("\nbla\n\n"); // Escaping - eprint!("\\n"); // #3514 - eprint!("\\\n"); // should fail + // #3514 + eprint!("\\n"); + eprint!("\\\n"); eprint!("\\\\n"); // Raw strings - eprint!(r"\n"); // #3778 + // #3778 + eprint!(r"\n"); // Literal newlines should also fail eprint!( diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr index 080f6c2a60542..e92b1ba672fe7 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -60,19 +60,19 @@ LL + eprintln!(); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:28:5 + --> $DIR/eprint_with_newline.rs:31:5 | -LL | eprint!("\\\n"); // should fail +LL | eprint!("\\\n"); | ^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("\\\n"); // should fail -LL + eprintln!("\\"); // should fail +LL - eprint!("\\\n"); +LL + eprintln!("\\"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:35:5 + --> $DIR/eprint_with_newline.rs:39:5 | LL | / eprint!( LL | | " @@ -87,7 +87,7 @@ LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:39:5 + --> $DIR/eprint_with_newline.rs:43:5 | LL | / eprint!( LL | | r" @@ -102,7 +102,7 @@ LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:47:5 + --> $DIR/eprint_with_newline.rs:51:5 | LL | eprint!("\\r\n"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index 16f9e47e8532c..f7f7ea4103534 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -25,29 +25,43 @@ fn main() { let x = [1, 2, 3, 4]; let index: usize = 1; x[index]; - x[4]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - x[1 << 3]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[4]; + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[1 << 3]; - x[0]; // Ok, should not produce stderr. - x[3]; // Ok, should not produce stderr. - x[const { idx() }]; // Ok, should not produce stderr. - x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - const { &ARR[idx()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. - const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. + // Ok, should not produce stderr. + x[0]; + // Ok, should not produce stderr. + x[3]; + // Ok, should not produce stderr. + x[const { idx() }]; + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[const { idx4() }]; + // This should be linted, since `suppress-restriction-lint-in-const` default is false. + const { &ARR[idx()] }; + // This should be linted, since `suppress-restriction-lint-in-const` default is false. + const { &ARR[idx4()] }; let y = &x; - y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021 - y[4]; // Ok, rustc will handle references too. + // Ok, referencing shouldn't affect this lint. See the issue 6021 + y[0]; + // Ok, rustc will handle references too. + y[4]; let v = vec![0; 5]; v[0]; v[10]; v[1 << 3]; - const N: usize = 15; // Out of bounds - const M: usize = 3; // In bounds - x[N]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - x[M]; // Ok, should not produce stderr. + // Out of bounds + const N: usize = 15; + // In bounds + const M: usize = 3; + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[N]; + // Ok, should not produce stderr. + x[M]; v[N]; v[M]; } diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index f4357c1d592d0..1db2eb1397cde 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -18,15 +18,15 @@ LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. = note: the suggestion might not be applicable in constant blocks error[E0080]: evaluation of `main::{constant#3}` failed - --> $DIR/indexing_slicing_index.rs:36:14 + --> $DIR/indexing_slicing_index.rs:44:14 | -LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 note: erroneous constant used - --> $DIR/indexing_slicing_index.rs:36:5 + --> $DIR/indexing_slicing_index.rs:44:5 | -LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^^^^^^^^^^^^ error: indexing may panic @@ -38,25 +38,25 @@ LL | x[index]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:35:14 + --> $DIR/indexing_slicing_index.rs:42:14 | -LL | const { &ARR[idx()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx()] }; | ^^^^^^^^^^ | = help: consider using `.get(n)` or `.get_mut(n)` instead = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:36:14 + --> $DIR/indexing_slicing_index.rs:44:14 | -LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ | = help: consider using `.get(n)` or `.get_mut(n)` instead = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:43:5 + --> $DIR/indexing_slicing_index.rs:53:5 | LL | v[0]; | ^^^^ @@ -64,7 +64,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:44:5 + --> $DIR/indexing_slicing_index.rs:54:5 | LL | v[10]; | ^^^^^ @@ -72,7 +72,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:45:5 + --> $DIR/indexing_slicing_index.rs:55:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -80,7 +80,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:51:5 + --> $DIR/indexing_slicing_index.rs:65:5 | LL | v[N]; | ^^^^ @@ -88,7 +88,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:52:5 + --> $DIR/indexing_slicing_index.rs:66:5 | LL | v[M]; | ^^^^ diff --git a/tests/ui/indexing_slicing_slice.rs b/tests/ui/indexing_slicing_slice.rs index 939b6ac36bde8..ea111a48b29fe 100644 --- a/tests/ui/indexing_slicing_slice.rs +++ b/tests/ui/indexing_slicing_slice.rs @@ -12,8 +12,8 @@ fn main() { &x[index..]; &x[..index]; &x[index_from..index_to]; - &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. - &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. + &x[index_from..][..index_to]; + &x[5..][..10]; &x[0..][..3]; &x[1..][..5]; @@ -29,7 +29,7 @@ fn main() { let v = vec![0; 5]; &v[10..100]; - &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. + &x[10..][..100]; &v[10..]; &v[..100]; diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr index dc54bd41365d3..6a75d57453797 100644 --- a/tests/ui/indexing_slicing_slice.stderr +++ b/tests/ui/indexing_slicing_slice.stderr @@ -26,7 +26,7 @@ LL | &x[index_from..index_to]; error: slicing may panic --> $DIR/indexing_slicing_slice.rs:15:6 | -LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. +LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using `.get(..n)`or `.get_mut(..n)` instead @@ -34,7 +34,7 @@ LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from. error: slicing may panic --> $DIR/indexing_slicing_slice.rs:15:6 | -LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. +LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^ | = help: consider using `.get(n..)` or .get_mut(n..)` instead @@ -42,7 +42,7 @@ LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from. error: slicing may panic --> $DIR/indexing_slicing_slice.rs:16:6 | -LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. +LL | &x[5..][..10]; | ^^^^^^^^^^^^ | = help: consider using `.get(..n)`or `.get_mut(..n)` instead @@ -50,7 +50,7 @@ LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and ano error: range is out of bounds --> $DIR/indexing_slicing_slice.rs:16:8 | -LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. +LL | &x[5..][..10]; | ^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` @@ -94,7 +94,7 @@ LL | &v[10..100]; error: slicing may panic --> $DIR/indexing_slicing_slice.rs:32:6 | -LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. +LL | &x[10..][..100]; | ^^^^^^^^^^^^^^ | = help: consider using `.get(..n)`or `.get_mut(..n)` instead @@ -102,7 +102,7 @@ LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [. error: range is out of bounds --> $DIR/indexing_slicing_slice.rs:32:8 | -LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. +LL | &x[10..][..100]; | ^^ error: slicing may panic diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs index 622644f675d35..7821dd44812df 100644 --- a/tests/ui/infinite_iter.rs +++ b/tests/ui/infinite_iter.rs @@ -8,42 +8,60 @@ fn square_is_lower_64(x: &u32) -> bool { #[allow(clippy::maybe_infinite_iter)] #[deny(clippy::infinite_iter)] fn infinite_iters() { - repeat(0_u8).collect::>(); // infinite iter - (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter - (0..8_u64).chain(0..).max(); // infinite iter + repeat(0_u8).collect::>(); + // infinite iter + (0..8_u32).take_while(square_is_lower_64).cycle().count(); + // infinite iter + (0..8_u64).chain(0..).max(); + // infinite iter (0_usize..) .chain([0usize, 1, 2].iter().cloned()) .skip_while(|x| *x != 42) - .min(); // infinite iter + .min(); + // infinite iter (0..8_u32) .rev() .cycle() .map(|x| x + 1_u32) - .for_each(|x| println!("{}", x)); // infinite iter - (0..3_u32).flat_map(|x| x..).sum::(); // infinite iter - (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter - (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter - (0..42_u64).by_ref().last(); // not an infinite, because ranges are double-ended - (0..).next(); // iterator is not exhausted + .for_each(|x| println!("{}", x)); + // infinite iter + (0..3_u32).flat_map(|x| x..).sum::(); + // infinite iter + (0_usize..).flat_map(|x| 0..x).product::(); + // infinite iter + (0_u64..).filter(|x| x % 2 == 0).last(); + // not an infinite, because ranges are double-ended + (0..42_u64).by_ref().last(); + // iterator is not exhausted + (0..).next(); } #[deny(clippy::maybe_infinite_iter)] fn potential_infinite_iters() { - (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter - repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter + // maybe infinite iter + (0..).zip((0..).take_while(square_is_lower_64)).count(); + // maybe infinite iter + repeat(42).take_while(|x| *x == 42).chain(0..42).max(); + // maybe infinite iter (1..) .scan(0, |state, x| { *state += x; Some(*state) }) - .min(); // maybe infinite iter - (0..).find(|x| *x == 24); // maybe infinite iter - (0..).position(|x| x == 24); // maybe infinite iter - (0..).any(|x| x == 24); // maybe infinite iter - (0..).all(|x| x == 24); // maybe infinite iter + .min(); + // maybe infinite iter + (0..).find(|x| *x == 24); + // maybe infinite iter + (0..).position(|x| x == 24); + // maybe infinite iter + (0..).any(|x| x == 24); + // maybe infinite iter + (0..).all(|x| x == 24); - (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); // not infinite - repeat(42).take_while(|x| *x == 42).next(); // iterator is not exhausted + // not infinite + (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); + // iterator is not exhausted + repeat(42).take_while(|x| *x == 42).next(); } fn main() { @@ -62,7 +80,8 @@ mod finite_collect { } fn check_collect() { - let _: HashSet = (0..).collect(); // Infinite iter + // Infinite iter + let _: HashSet = (0..).collect(); // Some data structures don't collect infinitely, such as `ArrayVec` let _: C = (0..).collect(); diff --git a/tests/ui/infinite_iter.stderr b/tests/ui/infinite_iter.stderr index b911163f715e7..39d2fcc71aa69 100644 --- a/tests/ui/infinite_iter.stderr +++ b/tests/ui/infinite_iter.stderr @@ -1,7 +1,7 @@ error: infinite iteration detected --> $DIR/infinite_iter.rs:11:5 | -LL | repeat(0_u8).collect::>(); // infinite iter +LL | repeat(0_u8).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here @@ -11,96 +11,96 @@ LL | #[deny(clippy::infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:12:5 + --> $DIR/infinite_iter.rs:13:5 | -LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter +LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:13:5 + --> $DIR/infinite_iter.rs:15:5 | -LL | (0..8_u64).chain(0..).max(); // infinite iter +LL | (0..8_u64).chain(0..).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:18:5 + --> $DIR/infinite_iter.rs:22:5 | LL | / (0..8_u32) LL | | .rev() LL | | .cycle() LL | | .map(|x| x + 1_u32) -LL | | .for_each(|x| println!("{}", x)); // infinite iter +LL | | .for_each(|x| println!("{}", x)); | |________________________________________^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:24:5 + --> $DIR/infinite_iter.rs:30:5 | -LL | (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter +LL | (0_usize..).flat_map(|x| 0..x).product::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:25:5 + --> $DIR/infinite_iter.rs:32:5 | -LL | (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter +LL | (0_u64..).filter(|x| x % 2 == 0).last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:32:5 + --> $DIR/infinite_iter.rs:42:5 | -LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter +LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/infinite_iter.rs:30:8 + --> $DIR/infinite_iter.rs:39:8 | LL | #[deny(clippy::maybe_infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:33:5 + --> $DIR/infinite_iter.rs:44:5 | -LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter +LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:34:5 + --> $DIR/infinite_iter.rs:46:5 | LL | / (1..) LL | | .scan(0, |state, x| { LL | | *state += x; LL | | Some(*state) LL | | }) -LL | | .min(); // maybe infinite iter +LL | | .min(); | |______________^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:40:5 + --> $DIR/infinite_iter.rs:53:5 | -LL | (0..).find(|x| *x == 24); // maybe infinite iter +LL | (0..).find(|x| *x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:41:5 + --> $DIR/infinite_iter.rs:55:5 | -LL | (0..).position(|x| x == 24); // maybe infinite iter +LL | (0..).position(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:42:5 + --> $DIR/infinite_iter.rs:57:5 | -LL | (0..).any(|x| x == 24); // maybe infinite iter +LL | (0..).any(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:43:5 + --> $DIR/infinite_iter.rs:59:5 | -LL | (0..).all(|x| x == 24); // maybe infinite iter +LL | (0..).all(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:65:31 + --> $DIR/infinite_iter.rs:84:31 | -LL | let _: HashSet = (0..).collect(); // Infinite iter +LL | let _: HashSet = (0..).collect(); | ^^^^^^^^^^^^^^^ | = note: `#[deny(clippy::infinite_iter)]` on by default diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index 07f8e3888c998..c5cf97d3cd655 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -16,7 +16,8 @@ mod module {} // ok pub mod pub_module {} // ok fn foo() {} -pub fn pub_foo() {} // missing #[inline] +// missing #[inline] +pub fn pub_foo() {} #[inline] pub fn pub_foo_inline() {} // ok #[inline(always)] @@ -32,7 +33,8 @@ trait Bar { pub trait PubBar { fn PubBar_a(); // ok - fn PubBar_b() {} // missing #[inline] + // missing #[inline] + fn PubBar_b() {} #[inline] fn PubBar_c() {} // ok } @@ -46,9 +48,12 @@ impl PubBar for Foo { // all of these need inline because PubFoo is exported impl PubBar for PubFoo { - fn PubBar_a() {} // missing #[inline] - fn PubBar_b() {} // missing #[inline] - fn PubBar_c() {} // missing #[inline] + // missing #[inline] + fn PubBar_a() {} + // missing #[inline] + fn PubBar_b() {} + // missing #[inline] + fn PubBar_c() {} } // do not need inline because Foo is not exported @@ -58,7 +63,8 @@ impl Foo { // need inline because PubFoo is exported impl PubFoo { - pub fn PubFooImpl() {} // missing #[inline] + // missing #[inline] + pub fn PubFooImpl() {} } // do not lint this since users cannot control the external code diff --git a/tests/ui/missing_inline.stderr b/tests/ui/missing_inline.stderr index 40b92b7647bf7..73f876c1d1a31 100644 --- a/tests/ui/missing_inline.stderr +++ b/tests/ui/missing_inline.stderr @@ -1,39 +1,39 @@ error: missing `#[inline]` for a function - --> $DIR/missing_inline.rs:19:1 + --> $DIR/missing_inline.rs:20:1 | -LL | pub fn pub_foo() {} // missing #[inline] +LL | pub fn pub_foo() {} | ^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` error: missing `#[inline]` for a default trait method - --> $DIR/missing_inline.rs:35:5 + --> $DIR/missing_inline.rs:37:5 | -LL | fn PubBar_b() {} // missing #[inline] +LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:49:5 + --> $DIR/missing_inline.rs:52:5 | -LL | fn PubBar_a() {} // missing #[inline] +LL | fn PubBar_a() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:50:5 + --> $DIR/missing_inline.rs:54:5 | -LL | fn PubBar_b() {} // missing #[inline] +LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:51:5 + --> $DIR/missing_inline.rs:56:5 | -LL | fn PubBar_c() {} // missing #[inline] +LL | fn PubBar_c() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:61:5 + --> $DIR/missing_inline.rs:67:5 | -LL | pub fn PubFooImpl() {} // missing #[inline] +LL | pub fn PubFooImpl() {} | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs index adff08e5d1e8b..656b0b5cedcc2 100644 --- a/tests/ui/modulo_one.rs +++ b/tests/ui/modulo_one.rs @@ -8,16 +8,21 @@ fn main() { 10 % 1; 10 % -1; 10 % 2; - i32::MIN % (-1); // also caught by rustc + // also caught by rustc + i32::MIN % (-1); const ONE: u32 = 1 * 1; const NEG_ONE: i64 = 1 - 2; const INT_MIN: i64 = i64::MIN; 2 % ONE; - 5 % STATIC_ONE; // NOT caught by lint + // NOT caught by lint + 5 % STATIC_ONE; 2 % NEG_ONE; - 5 % STATIC_NEG_ONE; // NOT caught by lint - INT_MIN % NEG_ONE; // also caught by rustc - INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc + // NOT caught by lint + 5 % STATIC_NEG_ONE; + // also caught by rustc + INT_MIN % NEG_ONE; + // ONLY caught by rustc + INT_MIN % STATIC_NEG_ONE; } diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index 83a76f81d4e78..0793e6386930b 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -1,21 +1,21 @@ error: this operation will panic at runtime - --> $DIR/modulo_one.rs:11:5 + --> $DIR/modulo_one.rs:12:5 | -LL | i32::MIN % (-1); // also caught by rustc +LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ attempt to compute `i32::MIN % -1_i32`, which would overflow | = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime - --> $DIR/modulo_one.rs:21:5 + --> $DIR/modulo_one.rs:25:5 | -LL | INT_MIN % NEG_ONE; // also caught by rustc +LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: this operation will panic at runtime - --> $DIR/modulo_one.rs:22:5 + --> $DIR/modulo_one.rs:27:5 | -LL | INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc +LL | INT_MIN % STATIC_NEG_ONE; | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: any number modulo 1 will be 0 @@ -33,27 +33,27 @@ LL | 10 % -1; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:11:5 + --> $DIR/modulo_one.rs:12:5 | -LL | i32::MIN % (-1); // also caught by rustc +LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ error: any number modulo 1 will be 0 - --> $DIR/modulo_one.rs:17:5 + --> $DIR/modulo_one.rs:18:5 | LL | 2 % ONE; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:19:5 + --> $DIR/modulo_one.rs:21:5 | LL | 2 % NEG_ONE; | ^^^^^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:21:5 + --> $DIR/modulo_one.rs:25:5 | -LL | INT_MIN % NEG_ONE; // also caught by rustc +LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ error: aborting due to 9 previous errors diff --git a/tests/ui/mut_range_bound.rs b/tests/ui/mut_range_bound.rs index 7fdeb27ed988f..2c0d71ef0dd15 100644 --- a/tests/ui/mut_range_bound.rs +++ b/tests/ui/mut_range_bound.rs @@ -6,14 +6,14 @@ fn mut_range_bound_upper() { let mut m = 4; for i in 0..m { m = 5; - } // warning + } } fn mut_range_bound_lower() { let mut m = 4; for i in m..10 { m *= 2; - } // warning + } } fn mut_range_bound_both() { @@ -22,7 +22,7 @@ fn mut_range_bound_both() { for i in m..n { m = 5; n = 7; - } // warning (1 for each mutated bound) + } } fn mut_range_bound_no_mutation() { @@ -35,7 +35,7 @@ fn mut_range_bound_no_mutation() { fn mut_borrow_range_bound() { let mut m = 4; for i in 0..m { - let n = &mut m; // warning + let n = &mut m; *n += 1; } } @@ -43,7 +43,7 @@ fn mut_borrow_range_bound() { fn immut_borrow_range_bound() { let mut m = 4; for i in 0..m { - let n = &m; // should be no warning? + let n = &m; } } @@ -67,7 +67,8 @@ fn mut_range_bound_break() { fn mut_range_bound_no_immediate_break() { let mut m = 4; for i in 0..m { - m = 2; // warning because it is not immediately followed by break + // warning because it is not immediately followed by break + m = 2; if m == 4 { break; } @@ -76,7 +77,8 @@ fn mut_range_bound_no_immediate_break() { let mut n = 3; for i in n..10 { if n == 4 { - n = 1; // FIXME: warning because it is not immediately followed by break + // FIXME: warning because it is not immediately followed by break + n = 1; let _ = 2; break; } diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr index b679b7a0aaf82..6183135fc9c13 100644 --- a/tests/ui/mut_range_bound.stderr +++ b/tests/ui/mut_range_bound.stderr @@ -34,23 +34,23 @@ LL | n = 7; error: attempt to mutate range bound within loop --> $DIR/mut_range_bound.rs:38:22 | -LL | let n = &mut m; // warning +LL | let n = &mut m; | ^ | = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:70:9 + --> $DIR/mut_range_bound.rs:71:9 | -LL | m = 2; // warning because it is not immediately followed by break +LL | m = 2; | ^ | = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:79:13 + --> $DIR/mut_range_bound.rs:81:13 | -LL | n = 1; // FIXME: warning because it is not immediately followed by break +LL | n = 1; | ^ | = note: the range of the loop is unchanged diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index c891c9de3aeca..12e6c7deb9c20 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -55,21 +55,21 @@ fn main() { fn simple_loop() { loop { - continue; // should lint here + continue; } } fn simple_loop2() { loop { println!("bleh"); - continue; // should lint here + continue; } } #[rustfmt::skip] fn simple_loop3() { loop { - continue // should lint here + continue } } @@ -77,7 +77,7 @@ fn simple_loop3() { fn simple_loop4() { loop { println!("bleh"); - continue // should lint here + continue } } @@ -128,13 +128,13 @@ mod issue_2329 { if condition() { println!("bar-3"); } else { - continue 'inner; // should lint here + continue 'inner; } println!("bar-4"); update_condition(); if condition() { - continue; // should lint here + continue; } else { println!("bar-5"); } diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index d99989b54fc25..7f9f644643f97 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -57,7 +57,7 @@ LL | | } error: this `continue` expression is redundant --> $DIR/needless_continue.rs:58:9 | -LL | continue; // should lint here +LL | continue; | ^^^^^^^^^ | = help: consider dropping the `continue` expression @@ -65,7 +65,7 @@ LL | continue; // should lint here error: this `continue` expression is redundant --> $DIR/needless_continue.rs:65:9 | -LL | continue; // should lint here +LL | continue; | ^^^^^^^^^ | = help: consider dropping the `continue` expression @@ -73,7 +73,7 @@ LL | continue; // should lint here error: this `continue` expression is redundant --> $DIR/needless_continue.rs:72:9 | -LL | continue // should lint here +LL | continue | ^^^^^^^^ | = help: consider dropping the `continue` expression @@ -81,7 +81,7 @@ LL | continue // should lint here error: this `continue` expression is redundant --> $DIR/needless_continue.rs:80:9 | -LL | continue // should lint here +LL | continue | ^^^^^^^^ | = help: consider dropping the `continue` expression @@ -91,7 +91,7 @@ error: this `else` block is redundant | LL | } else { | ________________________^ -LL | | continue 'inner; // should lint here +LL | | continue 'inner; LL | | } | |_________________^ | @@ -102,7 +102,7 @@ LL | | } println!("bar-4"); update_condition(); if condition() { - continue; // should lint here + continue; } else { println!("bar-5"); } @@ -113,7 +113,7 @@ error: there is no need for an explicit `else` block for this `if` expression --> $DIR/needless_continue.rs:136:17 | LL | / if condition() { -LL | | continue; // should lint here +LL | | continue; LL | | } else { LL | | println!("bar-5"); LL | | } @@ -121,7 +121,7 @@ LL | | } | = help: consider dropping the `else` clause if condition() { - continue; // should lint here + continue; } { println!("bar-5"); diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs index edd2123d48a55..a5605cc14d484 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ b/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -6,6 +6,6 @@ fn main() { // issue 3102 let num = 1; - &x[num..10]; // should trigger out of bounds error - &x[10..num]; // should trigger out of bounds error + &x[num..10]; + &x[10..num]; } diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/tests/ui/out_of_bounds_indexing/issue-3102.stderr index 516c1df40be0a..8a09688a90ceb 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.stderr +++ b/tests/ui/out_of_bounds_indexing/issue-3102.stderr @@ -1,7 +1,7 @@ error: range is out of bounds --> $DIR/issue-3102.rs:9:13 | -LL | &x[num..10]; // should trigger out of bounds error +LL | &x[num..10]; | ^^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` @@ -9,7 +9,7 @@ LL | &x[num..10]; // should trigger out of bounds error error: range is out of bounds --> $DIR/issue-3102.rs:10:8 | -LL | &x[10..num]; // should trigger out of bounds error +LL | &x[10..num]; | ^^ error: aborting due to 2 previous errors diff --git a/tests/ui/print_with_newline.fixed b/tests/ui/print_with_newline.fixed index 73e73984cdd2d..c9c3b925aa699 100644 --- a/tests/ui/print_with_newline.fixed +++ b/tests/ui/print_with_newline.fixed @@ -22,16 +22,20 @@ fn main() { print!("\n\n"); print!("like eof\n\n"); print!("Hello {} {}\n\n", "world", "#2"); - println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - println!("\nbla\n\n"); // #3126 + // #3126 + println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + println!("\nbla\n\n"); // Escaping - print!("\\n"); // #3514 - println!("\\"); // should fail + // #3514 + print!("\\n"); + println!("\\"); print!("\\\\n"); // Raw strings - print!(r"\n"); // #3778 + // #3778 + print!(r"\n"); // Literal newlines should also fail println!( @@ -44,7 +48,8 @@ fn main() { // Don't warn on CRLF (#4208) print!("\r\n"); print!("foo\r\n"); - println!("\\r"); // should fail + // should fail + println!("\\r"); print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs index c3ea26ad74efe..aaddbcd4be824 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -22,16 +22,20 @@ fn main() { print!("\n\n"); print!("like eof\n\n"); print!("Hello {} {}\n\n", "world", "#2"); - println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - println!("\nbla\n\n"); // #3126 + // #3126 + println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + println!("\nbla\n\n"); // Escaping - print!("\\n"); // #3514 - print!("\\\n"); // should fail + // #3514 + print!("\\n"); + print!("\\\n"); print!("\\\\n"); // Raw strings - print!(r"\n"); // #3778 + // #3778 + print!(r"\n"); // Literal newlines should also fail print!( @@ -46,7 +50,8 @@ fn main() { // Don't warn on CRLF (#4208) print!("\r\n"); print!("foo\r\n"); - print!("\\r\n"); // should fail + // should fail + print!("\\r\n"); print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index 7130edaa7f458..16cec220f8346 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -60,19 +60,19 @@ LL + println!(); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:30:5 + --> $DIR/print_with_newline.rs:33:5 | -LL | print!("\\\n"); // should fail +LL | print!("\\\n"); | ^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("\\\n"); // should fail -LL + println!("\\"); // should fail +LL - print!("\\\n"); +LL + println!("\\"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:37:5 + --> $DIR/print_with_newline.rs:41:5 | LL | / print!( LL | | " @@ -87,7 +87,7 @@ LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:41:5 + --> $DIR/print_with_newline.rs:45:5 | LL | / print!( LL | | r" @@ -102,15 +102,15 @@ LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:49:5 + --> $DIR/print_with_newline.rs:54:5 | -LL | print!("\\r\n"); // should fail +LL | print!("\\r\n"); | ^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("\\r\n"); // should fail -LL + println!("\\r"); // should fail +LL - print!("\\r\n"); +LL + println!("\\r"); | error: aborting due to 9 previous errors diff --git a/tests/ui/trailing_zeros.fixed b/tests/ui/trailing_zeros.fixed index 60db3c07ce90b..8aceb76ddd851 100644 --- a/tests/ui/trailing_zeros.fixed +++ b/tests/ui/trailing_zeros.fixed @@ -3,8 +3,8 @@ fn main() { let x: i32 = 42; - let _ = x.trailing_zeros() >= 4; // suggest trailing_zeros - let _ = x.trailing_zeros() >= 5; // suggest trailing_zeros + let _ = x.trailing_zeros() >= 4; + let _ = x.trailing_zeros() >= 5; let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint } diff --git a/tests/ui/trailing_zeros.rs b/tests/ui/trailing_zeros.rs index fbdc977b769a4..888f0587fe348 100644 --- a/tests/ui/trailing_zeros.rs +++ b/tests/ui/trailing_zeros.rs @@ -3,8 +3,8 @@ fn main() { let x: i32 = 42; - let _ = (x & 0b1111 == 0); // suggest trailing_zeros - let _ = x & 0b1_1111 == 0; // suggest trailing_zeros + let _ = (x & 0b1111 == 0); + let _ = x & 0b1_1111 == 0; let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint } diff --git a/tests/ui/trailing_zeros.stderr b/tests/ui/trailing_zeros.stderr index 798551118309e..7c44f139c0952 100644 --- a/tests/ui/trailing_zeros.stderr +++ b/tests/ui/trailing_zeros.stderr @@ -1,7 +1,7 @@ error: bit mask could be simplified with a call to `trailing_zeros` --> $DIR/trailing_zeros.rs:6:13 | -LL | let _ = (x & 0b1111 == 0); // suggest trailing_zeros +LL | let _ = (x & 0b1111 == 0); | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 4` | = note: `-D clippy::verbose-bit-mask` implied by `-D warnings` @@ -9,7 +9,7 @@ LL | let _ = (x & 0b1111 == 0); // suggest trailing_zeros error: bit mask could be simplified with a call to `trailing_zeros` --> $DIR/trailing_zeros.rs:7:13 | -LL | let _ = x & 0b1_1111 == 0; // suggest trailing_zeros +LL | let _ = x & 0b1_1111 == 0; | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5` error: aborting due to 2 previous errors diff --git a/tests/ui/transmute_undefined_repr.rs b/tests/ui/transmute_undefined_repr.rs index 5aad0b44270a3..6afb1915e7e58 100644 --- a/tests/ui/transmute_undefined_repr.rs +++ b/tests/ui/transmute_undefined_repr.rs @@ -25,102 +25,160 @@ fn main() { let _: Ty = transmute(value::()); let _: Ty = transmute(value::()); - let _: Ty2C = transmute(value::>()); // Lint, Ty2 is unordered - let _: Ty2 = transmute(value::>()); // Lint, Ty2 is unordered + // Lint, Ty2 is unordered + let _: Ty2C = transmute(value::>()); + // Lint, Ty2 is unordered + let _: Ty2 = transmute(value::>()); - let _: Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same - let _: Ty> = transmute(value::>()); // Ok, Ty2 types are the same + // Ok, Ty2 types are the same + let _: Ty2 = transmute(value::>>()); + // Ok, Ty2 types are the same + let _: Ty> = transmute(value::>()); - let _: Ty2 = transmute(value::>>()); // Lint, different Ty2 instances - let _: Ty> = transmute(value::>()); // Lint, different Ty2 instances + // Lint, different Ty2 instances + let _: Ty2 = transmute(value::>>()); + // Lint, different Ty2 instances + let _: Ty> = transmute(value::>()); let _: Ty<&()> = transmute(value::<&()>()); let _: &() = transmute(value::>()); - let _: &Ty2 = transmute(value::>>()); // Lint, different Ty2 instances - let _: Ty<&Ty2> = transmute(value::<&Ty2>()); // Lint, different Ty2 instances + // Lint, different Ty2 instances + let _: &Ty2 = transmute(value::>>()); + // Lint, different Ty2 instances + let _: Ty<&Ty2> = transmute(value::<&Ty2>()); - let _: Ty = transmute(value::<&Ty2>()); // Ok, pointer to usize conversion - let _: &Ty2 = transmute(value::>()); // Ok, pointer to usize conversion + // Ok, pointer to usize conversion + let _: Ty = transmute(value::<&Ty2>()); + // Ok, pointer to usize conversion + let _: &Ty2 = transmute(value::>()); - let _: Ty<[u8; 8]> = transmute(value::>()); // Ok, transmute to byte array - let _: Ty2 = transmute(value::>()); // Ok, transmute from byte array + // Ok, transmute to byte array + let _: Ty<[u8; 8]> = transmute(value::>()); + // Ok, transmute from byte array + let _: Ty2 = transmute(value::>()); // issue #8417 - let _: Ty2C, ()> = transmute(value::>()); // Ok, Ty2 types are the same - let _: Ty2 = transmute(value::, ()>>()); // Ok, Ty2 types are the same - - let _: &'static mut Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same - let _: Box> = transmute(value::<&'static mut Ty2>()); // Ok, Ty2 types are the same - let _: *mut Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same - let _: Box> = transmute(value::<*mut Ty2>()); // Ok, Ty2 types are the same - - let _: &'static mut Ty2 = transmute(value::>>()); // Lint, different Ty2 instances - let _: Box> = transmute(value::<&'static mut Ty2>()); // Lint, different Ty2 instances - - let _: *const () = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const ()>()); // Ok, reverse type erasure - - let _: *const c_void = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const c_void>()); // Ok, reverse type erasure + // Ok, Ty2 types are the same + let _: Ty2C, ()> = transmute(value::>()); + // Ok, Ty2 types are the same + let _: Ty2 = transmute(value::, ()>>()); + + // Ok, Ty2 types are the same + let _: &'static mut Ty2 = transmute(value::>>()); + // Ok, Ty2 types are the same + let _: Box> = transmute(value::<&'static mut Ty2>()); + // Ok, Ty2 types are the same + let _: *mut Ty2 = transmute(value::>>()); + // Ok, Ty2 types are the same + let _: Box> = transmute(value::<*mut Ty2>()); + + // Lint, different Ty2 instances + let _: &'static mut Ty2 = transmute(value::>>()); + // Lint, different Ty2 instances + let _: Box> = transmute(value::<&'static mut Ty2>()); + + // Ok, type erasure + let _: *const () = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const ()>()); + + // Ok, type erasure + let _: *const c_void = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const c_void>()); enum Erase {} - let _: *const Erase = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const Erase>()); // Ok, reverse type erasure + // Ok, type erasure + let _: *const Erase = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const Erase>()); struct Erase2( [u8; 0], core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, ); - let _: *const Erase2 = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const Erase2>()); // Ok, reverse type erasure - - let _: *const () = transmute(value::<&&[u8]>()); // Ok, type erasure - let _: &&[u8] = transmute(value::<*const ()>()); // Ok, reverse type erasure - - let _: *mut c_void = transmute(value::<&mut &[u8]>()); // Ok, type erasure - let _: &mut &[u8] = transmute(value::<*mut c_void>()); // Ok, reverse type erasure - - let _: [u8; size_of::<&[u8]>()] = transmute(value::<&[u8]>()); // Ok, transmute to byte array - let _: &[u8] = transmute(value::<[u8; size_of::<&[u8]>()]>()); // Ok, transmute from byte array - - let _: [usize; 2] = transmute(value::<&[u8]>()); // Ok, transmute to int array - let _: &[u8] = transmute(value::<[usize; 2]>()); // Ok, transmute from int array - - let _: *const [u8] = transmute(value::>()); // Ok - let _: Box<[u8]> = transmute(value::<*mut [u8]>()); // Ok - - let _: Ty2 = transmute(value::<(Ty2,)>()); // Ok - let _: (Ty2,) = transmute(value::>()); // Ok - - let _: Ty2 = transmute(value::<(Ty2, ())>()); // Ok - let _: (Ty2, ()) = transmute(value::>()); // Ok - - let _: Ty2 = transmute(value::<((), Ty2)>()); // Ok - let _: ((), Ty2) = transmute(value::>()); // Ok - - let _: (usize, usize) = transmute(value::<&[u8]>()); // Ok - let _: &[u8] = transmute(value::<(usize, usize)>()); // Ok + // Ok, type erasure + let _: *const Erase2 = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const Erase2>()); + + // Ok, type erasure + let _: *const () = transmute(value::<&&[u8]>()); + // Ok, reverse type erasure + let _: &&[u8] = transmute(value::<*const ()>()); + + // Ok, type erasure + let _: *mut c_void = transmute(value::<&mut &[u8]>()); + // Ok, reverse type erasure + let _: &mut &[u8] = transmute(value::<*mut c_void>()); + + // Ok, transmute to byte array + let _: [u8; size_of::<&[u8]>()] = transmute(value::<&[u8]>()); + // Ok, transmute from byte array + let _: &[u8] = transmute(value::<[u8; size_of::<&[u8]>()]>()); + + // Ok, transmute to int array + let _: [usize; 2] = transmute(value::<&[u8]>()); + // Ok, transmute from int array + let _: &[u8] = transmute(value::<[usize; 2]>()); + + // Ok + let _: *const [u8] = transmute(value::>()); + // Ok + let _: Box<[u8]> = transmute(value::<*mut [u8]>()); + + // Ok + let _: Ty2 = transmute(value::<(Ty2,)>()); + // Ok + let _: (Ty2,) = transmute(value::>()); + + // Ok + let _: Ty2 = transmute(value::<(Ty2, ())>()); + // Ok + let _: (Ty2, ()) = transmute(value::>()); + + // Ok + let _: Ty2 = transmute(value::<((), Ty2)>()); + // Ok + let _: ((), Ty2) = transmute(value::>()); + + // Ok + let _: (usize, usize) = transmute(value::<&[u8]>()); + // Ok + let _: &[u8] = transmute(value::<(usize, usize)>()); trait Trait {} - let _: (isize, isize) = transmute(value::<&dyn Trait>()); // Ok - let _: &dyn Trait = transmute(value::<(isize, isize)>()); // Ok - - let _: MaybeUninit> = transmute(value::>()); // Ok - let _: Ty2 = transmute(value::>>()); // Ok - - let _: Ty<&[u32]> = transmute::<&[u32], _>(value::<&Vec>()); // Ok - - let _: *const Ty2 = transmute(value::<*const Ty2C, u32>>()); // Ok - let _: *const Ty2C, u32> = transmute(value::<*const Ty2>()); // Ok - let _: *const Ty2 = transmute(value::<*const Ty2C<(), Ty2>>()); // Ok - let _: *const Ty2C<(), Ty2> = transmute(value::<*const Ty2>()); // Ok - - let _: *const Ty2 = transmute(value::<*const Ty2C>>()); // Err - let _: *const Ty2C> = transmute(value::<*const Ty2>()); // Err - - let _: NonNull = transmute(value::>()); // Ok - let _: NonNull<(String, String)> = transmute(value::>()); // Ok + // Ok + let _: (isize, isize) = transmute(value::<&dyn Trait>()); + let _: &dyn Trait = transmute(value::<(isize, isize)>()); + + // Ok + let _: MaybeUninit> = transmute(value::>()); + // Ok + let _: Ty2 = transmute(value::>>()); + + // Ok + let _: Ty<&[u32]> = transmute::<&[u32], _>(value::<&Vec>()); + + // Ok + let _: *const Ty2 = transmute(value::<*const Ty2C, u32>>()); + // Ok + let _: *const Ty2C, u32> = transmute(value::<*const Ty2>()); + // Ok + let _: *const Ty2 = transmute(value::<*const Ty2C<(), Ty2>>()); + // Ok + let _: *const Ty2C<(), Ty2> = transmute(value::<*const Ty2>()); + + // Err + let _: *const Ty2 = transmute(value::<*const Ty2C>>()); + // Err + let _: *const Ty2C> = transmute(value::<*const Ty2>()); + + // Ok + let _: NonNull = transmute(value::>()); + // Ok + let _: NonNull<(String, String)> = transmute(value::>()); } } @@ -129,28 +187,44 @@ fn _with_generics() { return; } unsafe { - let _: &u32 = transmute(value::<&T>()); // Ok - let _: &T = transmute(value::<&u32>()); // Ok - - let _: Vec = transmute(value::>()); // Ok - let _: Vec = transmute(value::>()); // Ok - - let _: Ty<&u32> = transmute(value::<&T>()); // Ok - let _: Ty<&T> = transmute(value::<&u32>()); // Ok - - let _: Vec = transmute(value::>()); // Ok - let _: Vec = transmute(value::>()); // Ok - - let _: &Ty2 = transmute(value::<&Ty2>()); // Ok - let _: &Ty2 = transmute(value::<&Ty2>()); // Ok - - let _: Vec> = transmute(value::>>()); // Ok - let _: Vec> = transmute(value::>>()); // Ok - - let _: Vec> = transmute(value::>>()); // Err - let _: Vec> = transmute(value::>>()); // Err - - let _: *const u32 = transmute(value::>()); // Ok - let _: Box = transmute(value::<*const u32>()); // Ok + // Ok + let _: &u32 = transmute(value::<&T>()); + // Ok + let _: &T = transmute(value::<&u32>()); + + // Ok + let _: Vec = transmute(value::>()); + // Ok + let _: Vec = transmute(value::>()); + + // Ok + let _: Ty<&u32> = transmute(value::<&T>()); + // Ok + let _: Ty<&T> = transmute(value::<&u32>()); + + // Ok + let _: Vec = transmute(value::>()); + // Ok + let _: Vec = transmute(value::>()); + + // Ok + let _: &Ty2 = transmute(value::<&Ty2>()); + // Ok + let _: &Ty2 = transmute(value::<&Ty2>()); + + // Ok + let _: Vec> = transmute(value::>>()); + // Ok + let _: Vec> = transmute(value::>>()); + + // Err + let _: Vec> = transmute(value::>>()); + // Err + let _: Vec> = transmute(value::>>()); + + // Ok + let _: *const u32 = transmute(value::>()); + // Ok + let _: Box = transmute(value::<*const u32>()); } } diff --git a/tests/ui/transmute_undefined_repr.stderr b/tests/ui/transmute_undefined_repr.stderr index e50a773290e17..220bcb5b528dc 100644 --- a/tests/ui/transmute_undefined_repr.stderr +++ b/tests/ui/transmute_undefined_repr.stderr @@ -1,93 +1,93 @@ error: transmute from `Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:28:33 + --> $DIR/transmute_undefined_repr.rs:29:33 | -LL | let _: Ty2C = transmute(value::>()); // Lint, Ty2 is unordered +LL | let _: Ty2C = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::transmute-undefined-repr` implied by `-D warnings` error: transmute into `Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:29:32 + --> $DIR/transmute_undefined_repr.rs:31:32 | -LL | let _: Ty2 = transmute(value::>()); // Lint, Ty2 is unordered +LL | let _: Ty2 = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `Ty>` to `Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:34:32 + --> $DIR/transmute_undefined_repr.rs:39:32 | -LL | let _: Ty2 = transmute(value::>>()); // Lint, different Ty2 instances +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 - --> $DIR/transmute_undefined_repr.rs:35:36 + --> $DIR/transmute_undefined_repr.rs:41:36 | -LL | let _: Ty> = transmute(value::>()); // Lint, different Ty2 instances +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 - --> $DIR/transmute_undefined_repr.rs:40:33 + --> $DIR/transmute_undefined_repr.rs:47:33 | -LL | let _: &Ty2 = transmute(value::>>()); // Lint, different Ty2 instances +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 - --> $DIR/transmute_undefined_repr.rs:41:37 + --> $DIR/transmute_undefined_repr.rs:49:37 | -LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); // Lint, different Ty2 instances +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 - --> $DIR/transmute_undefined_repr.rs:58:45 + --> $DIR/transmute_undefined_repr.rs:77:45 | -LL | let _: &'static mut Ty2 = transmute(value::>>()); // Lint, different Ty2 instances +LL | let _: &'static mut Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `&mut Ty2` to `std::boxed::Box>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:59:37 + --> $DIR/transmute_undefined_repr.rs:79:37 | -LL | let _: Box> = transmute(value::<&'static mut Ty2>()); // Lint, different Ty2 instances +LL | let _: Box> = transmute(value::<&'static mut Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute into `*const Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:119:39 + --> $DIR/transmute_undefined_repr.rs:174:39 | -LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); // Err +LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the contained type `Ty2` has an undefined layout error: transmute from `*const Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:120:50 + --> $DIR/transmute_undefined_repr.rs:176:50 | -LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); // Err +LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = 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 - --> $DIR/transmute_undefined_repr.rs:150:35 + --> $DIR/transmute_undefined_repr.rs:221:35 | -LL | let _: Vec> = transmute(value::>>()); // Err +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 - --> $DIR/transmute_undefined_repr.rs:151:35 + --> $DIR/transmute_undefined_repr.rs:223:35 | -LL | let _: Vec> = transmute(value::>>()); // Err +LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Vec`) may have different layouts diff --git a/tests/ui/trivially_copy_pass_by_ref.stderr b/tests/ui/trivially_copy_pass_by_ref.stderr index 903c240bfcaba..c9585e519883c 100644 --- a/tests/ui/trivially_copy_pass_by_ref.stderr +++ b/tests/ui/trivially_copy_pass_by_ref.stderr @@ -1,4 +1,4 @@ -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> $DIR/trivially_copy_pass_by_ref.rs:52:11 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} @@ -10,13 +10,13 @@ note: the lint level is defined here LL | #![deny(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) +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> $DIR/trivially_copy_pass_by_ref.rs:52: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) +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> $DIR/trivially_copy_pass_by_ref.rs:52:29 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} diff --git a/tests/ui/write_literal_2.rs b/tests/ui/write_literal_2.rs index a250de30d5c42..c71a4cb6f7a7f 100644 --- a/tests/ui/write_literal_2.rs +++ b/tests/ui/write_literal_2.rs @@ -30,6 +30,8 @@ fn main() { writeln!(v, r#"{}"#, "\\"); writeln!(v, "{}", r"\"); writeln!(v, "{}", "\r"); - writeln!(v, r#"{}{}"#, '#', '"'); // hard mode - writeln!(v, r"{}", "\r"); // should not lint + // hard mode + writeln!(v, r#"{}{}"#, '#', '"'); + // should not lint + writeln!(v, r"{}", "\r"); } diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index b28bee56dc248..c78a92f56eeff 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -183,15 +183,15 @@ LL + writeln!(v, "\r"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:33:28 + --> $DIR/write_literal_2.rs:34:28 | -LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode +LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:33:33 + --> $DIR/write_literal_2.rs:34:33 | -LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode +LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ error: aborting due to 18 previous errors diff --git a/tests/ui/write_with_newline.fixed b/tests/ui/write_with_newline.fixed index f1daeb1324045..c0e6c2a826405 100644 --- a/tests/ui/write_with_newline.fixed +++ b/tests/ui/write_with_newline.fixed @@ -27,16 +27,20 @@ fn main() { write!(v, "\n\n"); write!(v, "like eof\n\n"); write!(v, "Hello {} {}\n\n", "world", "#2"); - writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - writeln!(v, "\nbla\n\n"); // #3126 + // #3126 + writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + writeln!(v, "\nbla\n\n"); // Escaping - write!(v, "\\n"); // #3514 - writeln!(v, "\\"); // should fail + // #3514 + write!(v, "\\n"); + writeln!(v, "\\"); write!(v, "\\\\n"); // Raw strings - write!(v, r"\n"); // #3778 + // #3778 + write!(v, r"\n"); // Literal newlines should also fail writeln!( diff --git a/tests/ui/write_with_newline.rs b/tests/ui/write_with_newline.rs index f8f3002fed6ab..bacafdc8ad4ea 100644 --- a/tests/ui/write_with_newline.rs +++ b/tests/ui/write_with_newline.rs @@ -27,16 +27,20 @@ fn main() { write!(v, "\n\n"); write!(v, "like eof\n\n"); write!(v, "Hello {} {}\n\n", "world", "#2"); - writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - writeln!(v, "\nbla\n\n"); // #3126 + // #3126 + writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + writeln!(v, "\nbla\n\n"); // Escaping - write!(v, "\\n"); // #3514 - write!(v, "\\\n"); // should fail + // #3514 + write!(v, "\\n"); + write!(v, "\\\n"); write!(v, "\\\\n"); // Raw strings - write!(v, r"\n"); // #3778 + // #3778 + write!(v, r"\n"); // Literal newlines should also fail write!( diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index cec236038eb02..4ab6919b6b214 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -60,19 +60,19 @@ LL + writeln!(v); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:35:5 + --> $DIR/write_with_newline.rs:38:5 | -LL | write!(v, "\\\n"); // should fail +LL | write!(v, "\\\n"); | ^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "\\\n"); // should fail -LL + writeln!(v, "\\"); // should fail +LL - write!(v, "\\\n"); +LL + writeln!(v, "\\"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:42:5 + --> $DIR/write_with_newline.rs:46:5 | LL | / write!( LL | | v, @@ -88,7 +88,7 @@ LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:47:5 + --> $DIR/write_with_newline.rs:51:5 | LL | / write!( LL | | v, @@ -104,7 +104,7 @@ LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:56:5 + --> $DIR/write_with_newline.rs:60:5 | LL | write!(v, "\\r\n"); | ^^^^^^^^^^^^^^^^^^ From a05d3a41377f72eb87d7789e96575bd0e445397c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 28 Jul 2023 21:35:48 +0200 Subject: [PATCH 62/79] Automatic generation of error annotations for ui tests --- tests/ui/absurd-extreme-comparisons.rs | 19 ++ tests/ui/absurd-extreme-comparisons.stderr | 34 +-- tests/ui/approx_const.rs | 23 ++ tests/ui/approx_const.stderr | 44 ++-- tests/ui/as_ptr_cast_mut.rs | 3 + tests/ui/as_ptr_cast_mut.stderr | 2 +- tests/ui/asm_syntax.rs | 5 + tests/ui/asm_syntax.stderr | 8 +- tests/ui/assertions_on_constants.rs | 9 + tests/ui/assertions_on_constants.stderr | 16 +- tests/ui/assign_ops2.rs | 12 ++ tests/ui/assign_ops2.stderr | 18 +- tests/ui/attrs.rs | 5 + tests/ui/attrs.stderr | 4 +- tests/ui/await_holding_lock.rs | 13 ++ tests/ui/await_holding_lock.stderr | 63 +++--- tests/ui/await_holding_refcell_ref.rs | 6 + tests/ui/await_holding_refcell_ref.stderr | 28 +-- tests/ui/bit_masks.rs | 20 ++ tests/ui/bit_masks.stderr | 30 +-- tests/ui/blanket_clippy_restriction_lints.rs | 3 + .../blanket_clippy_restriction_lints.stderr | 4 +- tests/ui/blocks_in_if_conditions_closure.rs | 3 + .../ui/blocks_in_if_conditions_closure.stderr | 5 +- tests/ui/borrow_box.rs | 10 + tests/ui/borrow_box.stderr | 18 +- tests/ui/borrow_deref_ref_unfixable.rs | 2 + tests/ui/box_collection.rs | 9 + tests/ui/box_collection.stderr | 16 +- tests/ui/boxed_local.rs | 5 + tests/ui/boxed_local.stderr | 6 +- .../branches_sharing_code/shared_at_bottom.rs | 12 ++ .../shared_at_bottom.stderr | 32 ++- .../ui/branches_sharing_code/shared_at_top.rs | 7 + .../shared_at_top.stderr | 21 +- .../shared_at_top_and_bottom.rs | 5 + .../shared_at_top_and_bottom.stderr | 23 +- .../branches_sharing_code/valid_if_blocks.rs | 5 + .../valid_if_blocks.stderr | 22 +- tests/ui/bytecount.rs | 3 + tests/ui/bytecount.stderr | 4 +- tests/ui/cast.rs | 57 +++++ tests/ui/cast.stderr | 100 ++++----- tests/ui/cast_alignment.rs | 5 + tests/ui/cast_alignment.stderr | 6 +- tests/ui/cast_enum_constructor.rs | 3 + tests/ui/cast_enum_constructor.stderr | 2 +- tests/ui/cast_nan_to_int.rs | 12 ++ tests/ui/cast_nan_to_int.stderr | 10 +- tests/ui/cast_size.rs | 20 ++ tests/ui/cast_size.stderr | 34 +-- tests/ui/cast_size_32bit.rs | 21 ++ tests/ui/cast_slice_different_sizes.rs | 15 ++ tests/ui/cast_slice_different_sizes.stderr | 36 ++-- tests/ui/cfg_features.fixed | 5 + tests/ui/cfg_features.rs | 5 + tests/ui/cfg_features.stderr | 6 +- tests/ui/char_lit_as_u8.rs | 2 + .../ui/checked_unwrap/complex_conditionals.rs | 20 ++ .../complex_conditionals.stderr | 38 ++-- .../complex_conditionals_nested.rs | 2 + .../complex_conditionals_nested.stderr | 2 +- .../ui/checked_unwrap/simple_conditionals.rs | 16 ++ .../checked_unwrap/simple_conditionals.stderr | 30 +-- tests/ui/cmp_null.rs | 3 + tests/ui/cmp_null.stderr | 2 +- tests/ui/cmp_owned/without_suggestion.rs | 4 + tests/ui/cmp_owned/without_suggestion.stderr | 4 +- tests/ui/cognitive_complexity.rs | 20 ++ tests/ui/cognitive_complexity.stderr | 38 ++-- tests/ui/cognitive_complexity_attr_used.rs | 1 + tests/ui/collapsible_match.rs | 12 ++ tests/ui/collapsible_match.stderr | 64 +++--- tests/ui/collapsible_match2.rs | 4 + tests/ui/collapsible_match2.stderr | 24 ++- tests/ui/collection_is_never_read.rs | 21 ++ tests/ui/collection_is_never_read.stderr | 38 ++-- tests/ui/comparison_chain.rs | 7 + tests/ui/comparison_chain.stderr | 34 +-- tests/ui/const_comparisons.rs | 44 ++++ tests/ui/const_comparisons.stderr | 60 +++--- tests/ui/copy_iterator.rs | 2 + tests/ui/copy_iterator.stderr | 4 +- tests/ui/crashes/ice-10912.rs | 6 +- tests/ui/crashes/ice-10912.stderr | 4 +- tests/ui/crashes/ice-2774.fixed | 2 + tests/ui/crashes/ice-2774.rs | 2 + tests/ui/crashes/ice-360.rs | 3 + tests/ui/crashes/ice-360.stderr | 10 +- tests/ui/crashes/ice-3717.fixed | 1 + tests/ui/crashes/ice-3717.rs | 1 + tests/ui/crashes/ice-3891.rs | 1 + tests/ui/crashes/ice-3969.rs | 6 + tests/ui/crashes/ice-3969.stderr | 8 +- tests/ui/crashes/ice-5835.fixed | 2 + tests/ui/crashes/ice-5835.rs | 2 + tests/ui/crashes/ice-5872.fixed | 2 + tests/ui/crashes/ice-5872.rs | 2 + tests/ui/crashes/ice-6254.rs | 2 + tests/ui/crashes/ice-7169.fixed | 2 + tests/ui/crashes/ice-7169.rs | 2 + tests/ui/crashes/ice-7869.rs | 1 + tests/ui/crashes/ice-7869.stderr | 1 + tests/ui/crashes/ice-8250.fixed | 2 + tests/ui/crashes/ice-8250.rs | 2 + tests/ui/crashes/ice-8821.fixed | 2 + tests/ui/crashes/ice-8821.rs | 2 + tests/ui/crashes/ice-8850.fixed | 4 + tests/ui/crashes/ice-8850.rs | 4 + tests/ui/crashes/ice-8850.stderr | 4 +- tests/ui/crashes/ice-9041.rs | 2 + tests/ui/crashes/ice-9445.rs | 2 + tests/ui/crashes/ice-9463.rs | 4 + tests/ui/crashes/ice-9463.stderr | 4 +- .../needless_lifetimes_impl_trait.fixed | 1 + .../crashes/needless_lifetimes_impl_trait.rs | 1 + .../needless_pass_by_value-w-late-bound.fixed | 1 + .../needless_pass_by_value-w-late-bound.rs | 1 + tests/ui/crate_level_checks/no_std_swap.rs | 2 + .../ui/crate_level_checks/no_std_swap.stderr | 2 + .../crate_level_checks/std_main_recursion.rs | 1 + tests/ui/dbg_macro.rs | 19 ++ tests/ui/dbg_macro.stderr | 34 +-- tests/ui/debug_assert_with_mut_call.rs | 29 +++ tests/ui/debug_assert_with_mut_call.stderr | 54 ++--- tests/ui/def_id_nocore.rs | 1 + tests/ui/default_union_representation.rs | 4 + tests/ui/default_union_representation.stderr | 10 +- tests/ui/deprecated_old.rs | 4 + tests/ui/deprecated_old.stderr | 4 +- tests/ui/deref_addrof_double_trigger.rs | 4 + tests/ui/deref_addrof_double_trigger.stderr | 4 +- tests/ui/derive.rs | 5 + tests/ui/derive.stderr | 26 ++- tests/ui/derive_ord_xor_partial_ord.rs | 4 + tests/ui/derive_ord_xor_partial_ord.stderr | 16 +- tests/ui/derived_hash_with_manual_eq.rs | 2 + tests/ui/derived_hash_with_manual_eq.stderr | 6 +- tests/ui/disallowed_names.rs | 15 ++ tests/ui/disallowed_names.stderr | 26 +-- tests/ui/disallowed_script_idents.rs | 2 + tests/ui/disallowed_script_idents.stderr | 2 +- tests/ui/diverging_sub_expression.rs | 12 ++ tests/ui/diverging_sub_expression.stderr | 20 +- tests/ui/doc/unbalanced_ticks.rs | 8 + tests/ui/doc/unbalanced_ticks.stderr | 15 +- tests/ui/doc_errors.rs | 8 + tests/ui/doc_errors.stderr | 12 +- tests/ui/doc_link_with_quotes.rs | 2 + tests/ui/double_must_use.rs | 4 + tests/ui/double_must_use.stderr | 6 +- tests/ui/double_neg.rs | 2 + tests/ui/double_parens.rs | 7 + tests/ui/double_parens.stderr | 10 +- tests/ui/drop_non_drop.rs | 2 + tests/ui/drop_non_drop.stderr | 4 +- tests/ui/duplicate_underscore_argument.rs | 2 + tests/ui/empty_enum.rs | 1 + tests/ui/empty_loop_no_std.rs | 2 + tests/ui/empty_loop_no_std.stderr | 2 +- tests/ui/enum_clike_unportable_variant.rs | 10 + tests/ui/enum_variants.rs | 15 ++ tests/ui/enum_variants.stderr | 44 ++-- tests/ui/eprint_with_newline.fixed | 10 + tests/ui/eprint_with_newline.rs | 10 + tests/ui/eprint_with_newline.stderr | 20 +- tests/ui/eq_op.rs | 31 +++ tests/ui/eq_op.stderr | 56 ++--- tests/ui/eq_op_macros.rs | 8 + tests/ui/eq_op_macros.stderr | 14 +- tests/ui/erasing_op.rs | 6 + tests/ui/erasing_op.stderr | 8 +- tests/ui/error_impl_error.rs | 4 + tests/ui/error_impl_error.stderr | 12 +- tests/ui/exit1.rs | 2 + tests/ui/exit2.rs | 2 + tests/ui/expect.rs | 3 + tests/ui/expect.stderr | 4 +- tests/ui/expect_tool_lint_rfc_2383.rs | 7 + tests/ui/expect_tool_lint_rfc_2383.stderr | 10 +- tests/ui/explicit_counter_loop.rs | 11 + tests/ui/explicit_counter_loop.stderr | 16 +- .../extra_unused_type_parameters_unfixable.rs | 3 + ...ra_unused_type_parameters_unfixable.stderr | 4 +- tests/ui/fallible_impl_from.rs | 4 + tests/ui/fallible_impl_from.stderr | 21 +- tests/ui/filetype_is_file.rs | 3 + tests/ui/filetype_is_file.stderr | 4 +- tests/ui/filter_map_next.rs | 2 + tests/ui/filter_map_next.stderr | 4 +- tests/ui/float_arithmetic.rs | 18 ++ tests/ui/float_arithmetic.stderr | 32 +-- tests/ui/float_cmp.rs | 12 ++ tests/ui/float_cmp.stderr | 10 +- tests/ui/float_cmp_const.rs | 16 ++ tests/ui/float_cmp_const.stderr | 14 +- tests/ui/float_equality_without_abs.rs | 12 ++ tests/ui/float_equality_without_abs.stderr | 20 +- tests/ui/fn_address_comparisons.rs | 3 + tests/ui/fn_address_comparisons.stderr | 2 +- tests/ui/fn_params_excessive_bools.rs | 7 + tests/ui/fn_params_excessive_bools.stderr | 14 +- tests/ui/fn_to_numeric_cast.rs | 25 +++ tests/ui/fn_to_numeric_cast.stderr | 44 ++-- tests/ui/fn_to_numeric_cast_32bit.rs | 25 +++ tests/ui/fn_to_numeric_cast_any.rs | 18 ++ tests/ui/fn_to_numeric_cast_any.stderr | 32 +-- tests/ui/for_kv_map.fixed | 6 + tests/ui/for_kv_map.rs | 6 + tests/ui/for_kv_map.stderr | 8 +- tests/ui/forget_non_drop.rs | 2 + tests/ui/forget_non_drop.stderr | 4 +- tests/ui/format_args_unfixable.rs | 18 ++ tests/ui/format_args_unfixable.stderr | 36 ++-- tests/ui/format_collect.rs | 3 + tests/ui/format_collect.stderr | 13 +- tests/ui/format_push_string.rs | 5 + tests/ui/format_push_string.stderr | 11 +- tests/ui/formatting.rs | 12 ++ tests/ui/formatting.stderr | 10 +- tests/ui/from_over_into_unfixable.rs | 4 + tests/ui/from_over_into_unfixable.stderr | 6 +- tests/ui/from_raw_with_void_ptr.rs | 5 + tests/ui/from_raw_with_void_ptr.stderr | 16 +- tests/ui/from_str_radix_10.fixed | 9 + tests/ui/from_str_radix_10.rs | 9 + tests/ui/from_str_radix_10.stderr | 14 +- tests/ui/functions.rs | 18 ++ tests/ui/functions.stderr | 32 +-- tests/ui/functions_maxlines.rs | 2 + tests/ui/functions_maxlines.stderr | 4 +- tests/ui/future_not_send.rs | 8 + tests/ui/future_not_send.stderr | 39 ++-- tests/ui/if_let_mutex.rs | 3 + tests/ui/if_let_mutex.stderr | 7 +- tests/ui/if_not_else.rs | 2 + tests/ui/if_not_else.stderr | 4 +- tests/ui/if_then_some_else_none.rs | 5 + tests/ui/if_then_some_else_none.stderr | 11 +- tests/ui/impl.rs | 4 + tests/ui/impl.stderr | 13 +- tests/ui/impl_trait_in_params.rs | 3 + tests/ui/impl_trait_in_params.stderr | 2 +- ...partial_ord_impl_on_ord_type_fully_qual.rs | 3 + ...ial_ord_impl_on_ord_type_fully_qual.stderr | 5 +- .../if_let_slice_binding.fixed | 10 + .../if_let_slice_binding.rs | 10 + .../if_let_slice_binding.stderr | 18 +- .../slice_indexing_in_macro.fixed | 1 + .../slice_indexing_in_macro.rs | 1 + tests/ui/indexing_slicing_index.rs | 10 + tests/ui/indexing_slicing_index.stderr | 24 +-- tests/ui/indexing_slicing_slice.rs | 17 ++ tests/ui/indexing_slicing_slice.stderr | 30 +-- tests/ui/infinite_iter.rs | 15 ++ tests/ui/infinite_iter.stderr | 30 +-- tests/ui/infinite_loop.rs | 24 +++ tests/ui/infinite_loop.stderr | 22 +- tests/ui/inherent_to_string.rs | 2 + tests/ui/inherent_to_string.stderr | 4 +- tests/ui/inspect_for_each.rs | 1 + tests/ui/inspect_for_each.stderr | 1 + tests/ui/integer_division.rs | 3 + tests/ui/integer_division.stderr | 4 +- tests/ui/invalid_upcast_comparisons.rs | 28 +++ tests/ui/invalid_upcast_comparisons.stderr | 52 ++--- tests/ui/issue-7447.rs | 3 + tests/ui/issue-7447.stderr | 2 +- tests/ui/issue_4266.rs | 4 + tests/ui/issue_4266.stderr | 4 +- tests/ui/items_after_statement.rs | 3 + tests/ui/items_after_statement.stderr | 7 +- tests/ui/iter_not_returning_iterator.rs | 4 + tests/ui/iter_not_returning_iterator.stderr | 4 +- tests/ui/iter_skip_next_unfixable.rs | 3 + tests/ui/iter_skip_next_unfixable.stderr | 8 +- tests/ui/iterator_step_by_zero.rs | 8 + tests/ui/iterator_step_by_zero.stderr | 12 +- tests/ui/large_futures.fixed | 8 + tests/ui/large_futures.rs | 8 + tests/ui/large_futures.stderr | 16 +- tests/ui/large_stack_arrays.rs | 7 + tests/ui/large_stack_arrays.stderr | 12 +- tests/ui/large_stack_frames.rs | 6 + tests/ui/large_stack_frames.stderr | 12 +- tests/ui/len_without_is_empty.rs | 16 ++ tests/ui/len_without_is_empty.stderr | 40 ++-- tests/ui/let_and_return.fixed | 5 + tests/ui/let_and_return.rs | 5 + tests/ui/let_and_return.stderr | 6 +- tests/ui/let_if_seq.rs | 7 + tests/ui/let_if_seq.stderr | 17 +- tests/ui/let_underscore_future.rs | 5 + tests/ui/let_underscore_future.stderr | 6 +- tests/ui/let_underscore_lock.rs | 4 + tests/ui/let_underscore_lock.stderr | 6 +- tests/ui/let_underscore_must_use.rs | 12 ++ tests/ui/let_underscore_must_use.stderr | 22 +- tests/ui/linkedlist.rs | 9 + tests/ui/linkedlist.stderr | 16 +- tests/ui/literals.rs | 26 +++ tests/ui/literals.stderr | 38 ++-- tests/ui/manual_clamp.fixed | 36 ++++ tests/ui/manual_clamp.rs | 70 +++++++ tests/ui/manual_clamp.stderr | 145 +++++++------ tests/ui/manual_find.rs | 4 + tests/ui/manual_find.stderr | 12 +- tests/ui/manual_flatten.rs | 9 + tests/ui/manual_flatten.stderr | 45 ++-- tests/ui/manual_let_else.rs | 26 +++ tests/ui/manual_let_else.stderr | 75 ++++--- tests/ui/manual_let_else_match.rs | 10 + tests/ui/manual_let_else_match.stderr | 26 ++- tests/ui/manual_memcpy/with_loop_counters.rs | 12 ++ .../manual_memcpy/with_loop_counters.stderr | 32 ++- .../ui/manual_memcpy/without_loop_counters.rs | 14 ++ .../without_loop_counters.stderr | 38 ++-- tests/ui/manual_non_exhaustive_enum.rs | 2 + tests/ui/manual_non_exhaustive_enum.stderr | 8 +- tests/ui/manual_non_exhaustive_struct.rs | 4 + tests/ui/manual_non_exhaustive_struct.stderr | 16 +- tests/ui/manual_strip.rs | 8 + tests/ui/manual_strip.stderr | 32 +-- tests/ui/many_single_char_names.rs | 6 + tests/ui/many_single_char_names.stderr | 7 +- tests/ui/map_err.rs | 1 + tests/ui/map_flatten.rs | 5 + tests/ui/map_flatten.stderr | 21 +- tests/ui/match_bool.rs | 10 + tests/ui/match_bool.stderr | 27 ++- tests/ui/match_on_vec_items.rs | 9 + tests/ui/match_on_vec_items.stderr | 14 +- tests/ui/match_overlapping_arm.rs | 8 + tests/ui/match_overlapping_arm.stderr | 30 +-- tests/ui/match_same_arms_non_exhaustive.rs | 2 + .../ui/match_same_arms_non_exhaustive.stderr | 6 +- tests/ui/match_wild_err_arm.rs | 8 + tests/ui/match_wild_err_arm.stderr | 6 +- tests/ui/mem_forget.rs | 8 + tests/ui/mem_forget.stderr | 6 +- tests/ui/methods_unfixable.rs | 1 + tests/ui/min_max.rs | 14 ++ tests/ui/min_max.stderr | 24 +-- tests/ui/min_rust_version_attr.rs | 6 + tests/ui/min_rust_version_attr.stderr | 10 +- tests/ui/min_rust_version_invalid_attr.rs | 5 + tests/ui/min_rust_version_invalid_attr.stderr | 14 +- tests/ui/mismatching_type_param_order.rs | 10 + tests/ui/mismatching_type_param_order.stderr | 16 +- tests/ui/misnamed_getters.fixed | 19 ++ tests/ui/misnamed_getters.rs | 19 ++ tests/ui/misnamed_getters.stderr | 53 +++-- tests/ui/missing_assert_message.rs | 16 ++ tests/ui/missing_assert_message.stderr | 30 +-- .../ui/missing_const_for_fn/could_be_const.rs | 12 ++ .../could_be_const.stderr | 32 ++- tests/ui/missing_doc_crate_missing.rs | 2 + tests/ui/missing_doc_crate_missing.stderr | 2 + tests/ui/missing_fields_in_debug.rs | 3 + tests/ui/missing_fields_in_debug.stderr | 20 +- tests/ui/missing_inline.rs | 7 + tests/ui/missing_inline.stderr | 10 +- tests/ui/missing_trait_methods.rs | 2 + tests/ui/missing_trait_methods.stderr | 2 +- tests/ui/mixed_read_write_in_expression.rs | 4 + .../ui/mixed_read_write_in_expression.stderr | 12 +- tests/ui/module_inception.rs | 5 + tests/ui/module_inception.stderr | 11 +- tests/ui/module_name_repetitions.rs | 6 + tests/ui/module_name_repetitions.stderr | 8 +- tests/ui/modulo_arithmetic_float.rs | 20 ++ tests/ui/modulo_arithmetic_float.stderr | 18 +- tests/ui/modulo_arithmetic_integral.rs | 34 +++ tests/ui/modulo_arithmetic_integral.stderr | 32 +-- tests/ui/modulo_arithmetic_integral_const.rs | 34 +++ .../modulo_arithmetic_integral_const.stderr | 32 +-- tests/ui/modulo_one.rs | 11 + tests/ui/modulo_one.stderr | 16 +- tests/ui/multi_assignments.rs | 7 + tests/ui/multi_assignments.stderr | 10 +- tests/ui/mut_from_ref.rs | 6 + tests/ui/mut_from_ref.stderr | 20 +- tests/ui/mut_key.rs | 20 ++ tests/ui/mut_key.stderr | 30 +-- tests/ui/mut_range_bound.rs | 14 ++ tests/ui/mut_range_bound.stderr | 12 +- tests/ui/mut_reference.rs | 6 + tests/ui/mut_reference.stderr | 6 +- tests/ui/mutex_atomic.rs | 9 + tests/ui/mutex_atomic.stderr | 12 +- tests/ui/needless_borrow_pat.fixed | 13 ++ tests/ui/needless_borrow_pat.rs | 13 ++ tests/ui/needless_borrow_pat.stderr | 26 ++- tests/ui/needless_collect_indirect.rs | 17 ++ tests/ui/needless_collect_indirect.stderr | 65 ++++-- tests/ui/needless_continue.rs | 8 + tests/ui/needless_continue.stderr | 22 +- tests/ui/needless_doc_main.rs | 11 +- tests/ui/needless_doc_main.stderr | 6 +- tests/ui/needless_for_each_unfixable.rs | 2 + tests/ui/needless_for_each_unfixable.stderr | 8 +- tests/ui/needless_pass_by_value.rs | 23 ++ tests/ui/needless_pass_by_value.stderr | 50 ++--- tests/ui/needless_range_loop.rs | 15 ++ tests/ui/needless_range_loop.stderr | 26 +-- tests/ui/needless_range_loop2.rs | 9 + tests/ui/needless_range_loop2.stderr | 14 +- tests/ui/needless_update.rs | 2 + tests/ui/neg_cmp_op_on_partial_ord.rs | 5 + tests/ui/neg_cmp_op_on_partial_ord.stderr | 6 +- tests/ui/never_loop.rs | 16 ++ tests/ui/never_loop.stderr | 57 ++--- tests/ui/new_ret_no_self.rs | 13 ++ tests/ui/new_ret_no_self.stderr | 33 ++- tests/ui/new_without_default.fixed | 8 + tests/ui/new_without_default.rs | 8 + tests/ui/new_without_default.stderr | 22 +- tests/ui/no_effect.rs | 31 +++ tests/ui/no_effect.stderr | 56 ++--- tests/ui/no_effect_replace.rs | 9 + tests/ui/no_effect_replace.stderr | 14 +- tests/ui/no_effect_return.rs | 10 + tests/ui/no_effect_return.stderr | 16 +- tests/ui/no_mangle_with_rust_abi.rs | 6 + tests/ui/no_mangle_with_rust_abi.stderr | 9 +- tests/ui/non_minimal_cfg2.rs | 2 + tests/ui/non_send_fields_in_send_ty.rs | 12 ++ tests/ui/non_send_fields_in_send_ty.stderr | 48 ++--- tests/ui/nonminimal_bool.rs | 14 ++ tests/ui/nonminimal_bool.stderr | 24 +-- tests/ui/octal_escapes.rs | 9 + tests/ui/octal_escapes.stderr | 16 +- tests/ui/ok_expect.rs | 5 + tests/ui/ok_expect.stderr | 8 +- tests/ui/only_used_in_recursion.rs | 16 ++ tests/ui/only_used_in_recursion.stderr | 62 +++--- tests/ui/only_used_in_recursion2.rs | 5 + tests/ui/only_used_in_recursion2.stderr | 18 +- tests/ui/op_ref.fixed | 5 + tests/ui/op_ref.rs | 5 + tests/ui/op_ref.stderr | 6 +- tests/ui/open_options.rs | 8 + tests/ui/open_options.stderr | 12 +- tests/ui/option_option.rs | 12 ++ tests/ui/option_option.stderr | 22 +- tests/ui/out_of_bounds_indexing/issue-3102.rs | 3 + .../out_of_bounds_indexing/issue-3102.stderr | 2 +- tests/ui/out_of_bounds_indexing/simple.rs | 7 + tests/ui/out_of_bounds_indexing/simple.stderr | 10 +- tests/ui/overflow_check_conditional.rs | 9 + tests/ui/overflow_check_conditional.stderr | 14 +- tests/ui/overly_complex_bool_expr.fixed | 5 + tests/ui/overly_complex_bool_expr.rs | 5 + tests/ui/overly_complex_bool_expr.stderr | 16 +- tests/ui/panic_in_result_fn.rs | 2 + tests/ui/panic_in_result_fn.stderr | 8 +- tests/ui/panic_in_result_fn_assertions.rs | 3 + tests/ui/panic_in_result_fn_assertions.stderr | 13 +- tests/ui/panicking_macros.rs | 20 ++ tests/ui/panicking_macros.stderr | 30 +-- tests/ui/partial_pub_fields.rs | 4 + tests/ui/partial_pub_fields.stderr | 6 +- tests/ui/partialeq_ne_impl.rs | 2 + tests/ui/partialeq_ne_impl.stderr | 2 + tests/ui/pattern_type_mismatch/mutability.rs | 2 + .../pattern_type_mismatch/mutability.stderr | 2 +- .../pattern_alternatives.rs | 3 + .../pattern_alternatives.stderr | 4 +- .../pattern_type_mismatch/pattern_structs.rs | 8 + .../pattern_structs.stderr | 14 +- .../pattern_type_mismatch/pattern_tuples.rs | 10 + .../pattern_tuples.stderr | 18 +- tests/ui/pattern_type_mismatch/syntax.rs | 8 + tests/ui/pattern_type_mismatch/syntax.stderr | 16 +- tests/ui/permissions_set_readonly_false.rs | 2 + tests/ui/print.rs | 10 + tests/ui/print.stderr | 14 +- tests/ui/print_in_format_impl.rs | 8 + tests/ui/print_in_format_impl.stderr | 12 +- tests/ui/print_literal.fixed | 13 ++ tests/ui/print_literal.rs | 13 ++ tests/ui/print_literal.stderr | 22 +- tests/ui/print_stderr.rs | 3 + tests/ui/print_stderr.stderr | 2 +- tests/ui/print_with_newline.fixed | 10 + tests/ui/print_with_newline.rs | 10 + tests/ui/print_with_newline.stderr | 20 +- tests/ui/proc_macro.rs | 1 + tests/ui/ptr_arg.rs | 24 +++ tests/ui/ptr_arg.stderr | 51 +++-- tests/ui/pub_use.rs | 1 + tests/ui/question_mark_used.rs | 1 + tests/ui/range.rs | 2 + tests/ui/rc_clone_in_vec_init/arc.rs | 8 + tests/ui/rc_clone_in_vec_init/arc.stderr | 14 +- tests/ui/rc_clone_in_vec_init/rc.rs | 8 + tests/ui/rc_clone_in_vec_init/rc.stderr | 14 +- tests/ui/rc_clone_in_vec_init/weak.rs | 16 ++ tests/ui/rc_clone_in_vec_init/weak.stderr | 22 +- tests/ui/rc_mutex.rs | 4 + tests/ui/rc_mutex.stderr | 6 +- tests/ui/read_zero_byte_vec.rs | 11 + tests/ui/read_zero_byte_vec.stderr | 18 +- tests/ui/readonly_write_lock.fixed | 3 + tests/ui/readonly_write_lock.rs | 3 + tests/ui/readonly_write_lock.stderr | 2 +- tests/ui/recursive_format_impl.rs | 11 + tests/ui/recursive_format_impl.stderr | 18 +- tests/ui/redundant_allocation.rs | 40 ++++ tests/ui/redundant_allocation.stderr | 38 ++-- tests/ui/redundant_closure_call_early.rs | 3 + tests/ui/redundant_closure_call_early.stderr | 2 +- tests/ui/redundant_closure_call_late.rs | 4 + tests/ui/redundant_closure_call_late.stderr | 4 +- tests/ui/redundant_else.rs | 7 + tests/ui/redundant_else.stderr | 19 +- .../ui/redundant_static_lifetimes_multiple.rs | 11 + ...redundant_static_lifetimes_multiple.stderr | 16 +- tests/ui/redundant_type_annotations.rs | 18 ++ tests/ui/redundant_type_annotations.stderr | 32 +-- tests/ui/ref_binding_to_reference.rs | 8 + tests/ui/ref_binding_to_reference.stderr | 17 +- tests/ui/ref_option_ref.rs | 12 ++ tests/ui/ref_option_ref.stderr | 20 +- tests/ui/ref_patterns.rs | 3 + tests/ui/ref_patterns.stderr | 4 +- tests/ui/regex.rs | 19 ++ tests/ui/regex.stderr | 46 ++-- tests/ui/repl_uninit.rs | 5 + tests/ui/repl_uninit.stderr | 6 +- tests/ui/rest_pat_in_fully_bound_structs.rs | 5 +- .../ui/rest_pat_in_fully_bound_structs.stderr | 6 +- tests/ui/result_large_err.rs | 12 ++ tests/ui/result_large_err.stderr | 22 +- tests/ui/result_map_unit_fn_unfixable.rs | 7 + tests/ui/result_map_unit_fn_unfixable.stderr | 11 +- tests/ui/result_unit_error.rs | 5 + tests/ui/result_unit_error.stderr | 8 +- tests/ui/return_self_not_must_use.rs | 3 + tests/ui/return_self_not_must_use.stderr | 6 +- .../reversed_empty_ranges_loops_unfixable.rs | 3 + ...versed_empty_ranges_loops_unfixable.stderr | 2 +- tests/ui/reversed_empty_ranges_unfixable.rs | 4 + .../ui/reversed_empty_ranges_unfixable.stderr | 4 +- tests/ui/same_item_push.rs | 5 + tests/ui/same_item_push.stderr | 8 +- tests/ui/same_name_method.rs | 5 + tests/ui/same_name_method.stderr | 18 +- tests/ui/self_assignment.rs | 12 ++ tests/ui/self_assignment.stderr | 20 +- tests/ui/self_named_constructors.rs | 2 + tests/ui/self_named_constructors.stderr | 2 + tests/ui/serde.rs | 2 + tests/ui/serde.stderr | 5 +- tests/ui/should_impl_trait/method_list_1.rs | 15 ++ .../ui/should_impl_trait/method_list_1.stderr | 43 ++-- tests/ui/should_impl_trait/method_list_2.rs | 17 ++ .../ui/should_impl_trait/method_list_2.stderr | 47 +++-- tests/ui/significant_drop_in_scrutinee.rs | 52 +++++ tests/ui/significant_drop_in_scrutinee.stderr | 85 ++++---- tests/ui/similar_names.rs | 7 + tests/ui/similar_names.stderr | 22 +- tests/ui/single_char_lifetime_names.rs | 5 + tests/ui/single_char_lifetime_names.stderr | 6 +- ...gle_component_path_imports_nested_first.rs | 4 + ...component_path_imports_nested_first.stderr | 4 +- .../size_of_in_element_count/expressions.rs | 4 + .../expressions.stderr | 6 +- .../ui/size_of_in_element_count/functions.rs | 21 ++ .../size_of_in_element_count/functions.stderr | 40 ++-- tests/ui/size_of_ref.rs | 3 + tests/ui/size_of_ref.stderr | 4 +- tests/ui/slow_vector_initialization.rs | 15 ++ tests/ui/slow_vector_initialization.stderr | 24 +-- tests/ui/std_instead_of_core.rs | 12 ++ tests/ui/std_instead_of_core.stderr | 22 +- tests/ui/str_to_string.rs | 2 + tests/ui/str_to_string.stderr | 2 +- tests/ui/string_slice.rs | 4 + tests/ui/string_slice.stderr | 4 +- tests/ui/string_to_string.rs | 1 + tests/ui/struct_excessive_bools.rs | 2 + tests/ui/struct_excessive_bools.stderr | 4 +- tests/ui/suspicious_arithmetic_impl.rs | 11 + tests/ui/suspicious_arithmetic_impl.stderr | 16 +- tests/ui/suspicious_command_arg_space.fixed | 3 + tests/ui/suspicious_command_arg_space.rs | 3 + tests/ui/suspicious_command_arg_space.stderr | 2 +- tests/ui/suspicious_doc_comments_unfixable.rs | 3 + .../suspicious_doc_comments_unfixable.stderr | 8 +- tests/ui/suspicious_map.rs | 2 + tests/ui/suspicious_map.stderr | 2 +- tests/ui/suspicious_splitn.rs | 18 ++ tests/ui/suspicious_splitn.stderr | 16 +- tests/ui/suspicious_to_owned.rs | 8 + tests/ui/suspicious_to_owned.stderr | 10 +- tests/ui/suspicious_unary_op_formatting.rs | 4 + .../ui/suspicious_unary_op_formatting.stderr | 6 +- tests/ui/suspicious_xor_used_as_pow.rs | 7 + tests/ui/suspicious_xor_used_as_pow.stderr | 10 +- tests/ui/swap_ptr_to_ref_unfixable.rs | 4 + tests/ui/swap_ptr_to_ref_unfixable.stderr | 4 +- tests/ui/temporary_assignment.rs | 5 + tests/ui/temporary_assignment.stderr | 7 +- tests/ui/tests_outside_test_module.rs | 2 + tests/ui/trailing_empty_array.rs | 11 + tests/ui/trailing_empty_array.stderr | 30 ++- tests/ui/trailing_zeros.fixed | 3 + tests/ui/trailing_zeros.rs | 3 + tests/ui/trailing_zeros.stderr | 2 +- .../trait_duplication_in_bounds_unfixable.rs | 8 + ...ait_duplication_in_bounds_unfixable.stderr | 12 +- tests/ui/transmute.rs | 45 ++++ tests/ui/transmute.stderr | 74 +++---- tests/ui/transmute_64bit.rs | 3 + tests/ui/transmute_64bit.stderr | 2 +- tests/ui/transmute_collection.rs | 19 ++ tests/ui/transmute_collection.stderr | 34 +-- tests/ui/transmute_float_to_int.fixed | 7 + tests/ui/transmute_float_to_int.rs | 7 + tests/ui/transmute_float_to_int.stderr | 10 +- tests/ui/transmute_int_to_non_zero.fixed | 11 + tests/ui/transmute_int_to_non_zero.rs | 11 + tests/ui/transmute_int_to_non_zero.stderr | 18 +- tests/ui/transmute_null_to_fn.rs | 3 + tests/ui/transmute_null_to_fn.stderr | 4 +- tests/ui/transmute_ptr_to_ptr.fixed | 7 + tests/ui/transmute_ptr_to_ptr.rs | 7 + tests/ui/transmute_ptr_to_ptr.stderr | 10 +- tests/ui/transmute_undefined_repr.rs | 23 ++ tests/ui/transmute_undefined_repr.stderr | 22 +- tests/ui/transmuting_null.rs | 4 + tests/ui/transmuting_null.stderr | 4 +- tests/ui/type_complexity.rs | 16 ++ tests/ui/type_complexity.stderr | 28 +-- tests/ui/type_repetition_in_bounds.rs | 5 + tests/ui/type_repetition_in_bounds.stderr | 8 +- tests/ui/uninit.rs | 4 + tests/ui/uninit.stderr | 4 +- tests/ui/uninit_vec.rs | 11 + tests/ui/uninit_vec.stderr | 38 ++-- tests/ui/unit_cmp.rs | 7 + tests/ui/unit_cmp.stderr | 21 +- tests/ui/unit_hash.fixed | 6 + tests/ui/unit_hash.rs | 6 + tests/ui/unit_hash.stderr | 4 +- tests/ui/unit_return_expecting_ord.rs | 4 + tests/ui/unit_return_expecting_ord.stderr | 10 +- tests/ui/unknown_attribute.rs | 1 + tests/ui/unnecessary_box_returns.rs | 4 + tests/ui/unnecessary_box_returns.stderr | 6 +- tests/ui/unnecessary_cast_unfixable.rs | 3 + tests/ui/unnecessary_cast_unfixable.stderr | 2 +- tests/ui/unnecessary_clone.rs | 11 + tests/ui/unnecessary_clone.stderr | 16 +- tests/ui/unnecessary_filter_map.rs | 5 + tests/ui/unnecessary_filter_map.stderr | 10 +- tests/ui/unnecessary_find_map.rs | 5 + tests/ui/unnecessary_find_map.stderr | 10 +- tests/ui/unnecessary_lazy_eval_unfixable.rs | 4 + .../ui/unnecessary_lazy_eval_unfixable.stderr | 4 +- .../unnecessary_literal_unwrap_unfixable.rs | 52 +++++ ...nnecessary_literal_unwrap_unfixable.stderr | 198 +++++++++--------- tests/ui/unnecessary_safety_comment.rs | 8 + tests/ui/unnecessary_safety_comment.stderr | 32 +-- tests/ui/unnecessary_wraps.rs | 8 + tests/ui/unnecessary_wraps.stderr | 24 ++- tests/ui/unsafe_derive_deserialize.rs | 4 + tests/ui/unsafe_derive_deserialize.stderr | 6 +- tests/ui/unsafe_removed_from_name.rs | 6 + tests/ui/unsafe_removed_from_name.stderr | 8 +- tests/ui/unused_async.rs | 4 + tests/ui/unused_async.stderr | 11 +- tests/ui/unused_format_specs_unfixable.rs | 5 + tests/ui/unused_format_specs_unfixable.stderr | 6 +- tests/ui/unused_io_amount.rs | 20 ++ tests/ui/unused_io_amount.stderr | 39 ++-- tests/ui/unused_peekable.rs | 8 + tests/ui/unused_peekable.stderr | 14 +- tests/ui/unused_self.rs | 9 + tests/ui/unused_self.stderr | 16 +- tests/ui/unwrap.rs | 3 + tests/ui/unwrap.stderr | 4 +- tests/ui/unwrap_expect_used.rs | 6 + tests/ui/unwrap_expect_used.stderr | 10 +- tests/ui/unwrap_in_result.rs | 2 + tests/ui/unwrap_in_result.stderr | 12 +- tests/ui/unwrap_or.fixed | 3 + tests/ui/unwrap_or.rs | 3 + tests/ui/unwrap_or.stderr | 2 +- tests/ui/upper_case_acronyms.fixed | 12 ++ tests/ui/upper_case_acronyms.rs | 12 ++ tests/ui/upper_case_acronyms.stderr | 20 +- tests/ui/useless_conversion_try.rs | 9 + tests/ui/useless_conversion_try.stderr | 16 +- tests/ui/vec_init_then_push.rs | 9 + tests/ui/vec_init_then_push.stderr | 25 ++- tests/ui/vec_resize_to_zero.fixed | 1 + tests/ui/vec_resize_to_zero.rs | 1 + tests/ui/verbose_file_reads.rs | 2 + tests/ui/verbose_file_reads.stderr | 2 +- tests/ui/vtable_address_comparisons.rs | 8 + tests/ui/vtable_address_comparisons.stderr | 14 +- tests/ui/while_let_loop.rs | 6 + tests/ui/while_let_loop.stderr | 21 +- tests/ui/wild_in_or_pats.rs | 4 + tests/ui/wild_in_or_pats.stderr | 6 +- tests/ui/write_literal.fixed | 13 ++ tests/ui/write_literal.rs | 13 ++ tests/ui/write_literal.stderr | 22 +- tests/ui/write_literal_2.rs | 22 +- tests/ui/write_literal_2.stderr | 53 ++--- tests/ui/write_with_newline.fixed | 10 + tests/ui/write_with_newline.rs | 10 + tests/ui/write_with_newline.stderr | 20 +- tests/ui/wrong_self_convention.rs | 24 +++ tests/ui/wrong_self_convention.stderr | 46 ++-- tests/ui/wrong_self_convention2.rs | 2 + tests/ui/wrong_self_convention2.stderr | 2 +- tests/ui/wrong_self_conventions_mut.rs | 2 + tests/ui/wrong_self_conventions_mut.stderr | 2 +- tests/ui/zero_div_zero.rs | 4 + tests/ui/zero_div_zero.stderr | 6 +- tests/ui/zero_offset.rs | 9 + tests/ui/zero_offset.stderr | 14 +- tests/ui/zero_sized_btreemap_values.rs | 14 +- tests/ui/zero_sized_btreemap_values.stderr | 24 +-- tests/ui/zero_sized_hashmap_values.rs | 14 +- tests/ui/zero_sized_hashmap_values.stderr | 24 +-- 729 files changed, 6743 insertions(+), 2780 deletions(-) diff --git a/tests/ui/absurd-extreme-comparisons.rs b/tests/ui/absurd-extreme-comparisons.rs index f682b280c1b80..60f2ba4abcff3 100644 --- a/tests/ui/absurd-extreme-comparisons.rs +++ b/tests/ui/absurd-extreme-comparisons.rs @@ -12,27 +12,46 @@ fn main() { const Z: u32 = 0; let u: u32 = 42; u <= 0; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u <= Z; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u < Z; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con Z >= u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con Z > u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u > u32::MAX; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u >= u32::MAX; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u32::MAX < u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u32::MAX <= u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con 1-1 > u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u >= !0; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u <= 12 - 2*6; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con let i: i8 = 0; i < -127 - 1; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con i8::MAX >= i; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con 3-7 < i32::MIN; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con let b = false; b >= true; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con false > b; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u > 0; // ok // this is handled by clippy::unit_cmp () < {}; + //~^ ERROR: <-comparison of unit values detected. This will always be false + //~| NOTE: `#[deny(clippy::unit_cmp)]` on by default } use std::cmp::{Ordering, PartialEq, PartialOrd}; diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index 21cb11fa1bb84..a7843e2b349e2 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -8,7 +8,7 @@ LL | u <= 0; = note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings` error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:15:5 + --> $DIR/absurd-extreme-comparisons.rs:16:5 | LL | u <= Z; | ^^^^^^ @@ -16,7 +16,7 @@ LL | u <= Z; = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == Z` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:16:5 + --> $DIR/absurd-extreme-comparisons.rs:18:5 | LL | u < Z; | ^^^^^ @@ -24,7 +24,7 @@ LL | u < Z; = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:17:5 + --> $DIR/absurd-extreme-comparisons.rs:20:5 | LL | Z >= u; | ^^^^^^ @@ -32,7 +32,7 @@ LL | Z >= u; = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `Z == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:18:5 + --> $DIR/absurd-extreme-comparisons.rs:22:5 | LL | Z > u; | ^^^^^ @@ -40,7 +40,7 @@ LL | Z > u; = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:19:5 + --> $DIR/absurd-extreme-comparisons.rs:24:5 | LL | u > u32::MAX; | ^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | u > u32::MAX; = help: because `u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:20:5 + --> $DIR/absurd-extreme-comparisons.rs:26:5 | LL | u >= u32::MAX; | ^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | u >= u32::MAX; = help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == u32::MAX` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:21:5 + --> $DIR/absurd-extreme-comparisons.rs:28:5 | LL | u32::MAX < u; | ^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | u32::MAX < u; = help: because `u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:22:5 + --> $DIR/absurd-extreme-comparisons.rs:30:5 | LL | u32::MAX <= u; | ^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | u32::MAX <= u; = help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u32::MAX == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:23:5 + --> $DIR/absurd-extreme-comparisons.rs:32:5 | LL | 1-1 > u; | ^^^^^^^ @@ -80,7 +80,7 @@ LL | 1-1 > u; = help: because `1-1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:24:5 + --> $DIR/absurd-extreme-comparisons.rs:34:5 | LL | u >= !0; | ^^^^^^^ @@ -88,7 +88,7 @@ LL | u >= !0; = help: because `!0` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == !0` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:25:5 + --> $DIR/absurd-extreme-comparisons.rs:36:5 | LL | u <= 12 - 2*6; | ^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | u <= 12 - 2*6; = help: because `12 - 2*6` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 12 - 2*6` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:27:5 + --> $DIR/absurd-extreme-comparisons.rs:39:5 | LL | i < -127 - 1; | ^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | i < -127 - 1; = help: because `-127 - 1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:28:5 + --> $DIR/absurd-extreme-comparisons.rs:41:5 | LL | i8::MAX >= i; | ^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | i8::MAX >= i; = help: because `i8::MAX` is the maximum value for this type, this comparison is always true error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:29:5 + --> $DIR/absurd-extreme-comparisons.rs:43:5 | LL | 3-7 < i32::MIN; | ^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | 3-7 < i32::MIN; = help: because `i32::MIN` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:31:5 + --> $DIR/absurd-extreme-comparisons.rs:46:5 | LL | b >= true; | ^^^^^^^^^ @@ -128,7 +128,7 @@ LL | b >= true; = help: because `true` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `b == true` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:32:5 + --> $DIR/absurd-extreme-comparisons.rs:48:5 | LL | false > b; | ^^^^^^^^^ @@ -136,7 +136,7 @@ LL | false > b; = help: because `false` is the minimum value for this type, this comparison is always false error: <-comparison of unit values detected. This will always be false - --> $DIR/absurd-extreme-comparisons.rs:35:5 + --> $DIR/absurd-extreme-comparisons.rs:52:5 | LL | () < {}; | ^^^^^^^ diff --git a/tests/ui/approx_const.rs b/tests/ui/approx_const.rs index ccdbd34f7ec7b..2c3e0978c528e 100644 --- a/tests/ui/approx_const.rs +++ b/tests/ui/approx_const.rs @@ -2,63 +2,86 @@ #[allow(clippy::similar_names)] fn main() { let my_e = 2.7182; + //~^ ERROR: approximate value of `f{32, 64}::consts::E` found let almost_e = 2.718; + //~^ ERROR: approximate value of `f{32, 64}::consts::E` found let no_e = 2.71; let my_1_frac_pi = 0.3183; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_PI` found let no_1_frac_pi = 0.31; let my_frac_1_sqrt_2 = 0.70710678; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found let almost_frac_1_sqrt_2 = 0.70711; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found let my_frac_1_sqrt_2 = 0.707; let my_frac_2_pi = 0.63661977; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_2_PI` found let no_frac_2_pi = 0.636; let my_frac_2_sq_pi = 1.128379; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found let no_frac_2_sq_pi = 1.128; let my_frac_pi_2 = 1.57079632679; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_2` found let no_frac_pi_2 = 1.5705; let my_frac_pi_3 = 1.04719755119; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_3` found let no_frac_pi_3 = 1.047; let my_frac_pi_4 = 0.785398163397; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_4` found let no_frac_pi_4 = 0.785; let my_frac_pi_6 = 0.523598775598; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_6` found let no_frac_pi_6 = 0.523; let my_frac_pi_8 = 0.3926990816987; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_8` found let no_frac_pi_8 = 0.392; let my_ln_10 = 2.302585092994046; + //~^ ERROR: approximate value of `f{32, 64}::consts::LN_10` found let no_ln_10 = 2.303; let my_ln_2 = 0.6931471805599453; + //~^ ERROR: approximate value of `f{32, 64}::consts::LN_2` found let no_ln_2 = 0.693; let my_log10_e = 0.4342944819032518; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_E` found let no_log10_e = 0.434; let my_log2_e = 1.4426950408889634; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_E` found let no_log2_e = 1.442; let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found let no_log2_10 = 3.321; let log10_2 = 0.301029995663981; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_2` found let no_log10_2 = 0.301; let my_pi = 3.1415; + //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found let almost_pi = 3.14; + //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found let no_pi = 3.15; let my_sq2 = 1.4142; + //~^ ERROR: approximate value of `f{32, 64}::consts::SQRT_2` found let no_sq2 = 1.414; let my_tau = 6.2832; + //~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found let almost_tau = 6.28; + //~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found let no_tau = 6.3; } diff --git a/tests/ui/approx_const.stderr b/tests/ui/approx_const.stderr index 0932a2eec520f..28d2d317155bb 100644 --- a/tests/ui/approx_const.stderr +++ b/tests/ui/approx_const.stderr @@ -8,7 +8,7 @@ LL | let my_e = 2.7182; = note: `-D clippy::approx-constant` implied by `-D warnings` error: approximate value of `f{32, 64}::consts::E` found - --> $DIR/approx_const.rs:5:20 + --> $DIR/approx_const.rs:6:20 | LL | let almost_e = 2.718; | ^^^^^ @@ -16,7 +16,7 @@ LL | let almost_e = 2.718; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_1_PI` found - --> $DIR/approx_const.rs:8:24 + --> $DIR/approx_const.rs:10:24 | LL | let my_1_frac_pi = 0.3183; | ^^^^^^ @@ -24,7 +24,7 @@ LL | let my_1_frac_pi = 0.3183; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found - --> $DIR/approx_const.rs:11:28 + --> $DIR/approx_const.rs:14:28 | LL | let my_frac_1_sqrt_2 = 0.70710678; | ^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let my_frac_1_sqrt_2 = 0.70710678; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found - --> $DIR/approx_const.rs:12:32 + --> $DIR/approx_const.rs:16:32 | LL | let almost_frac_1_sqrt_2 = 0.70711; | ^^^^^^^ @@ -40,7 +40,7 @@ LL | let almost_frac_1_sqrt_2 = 0.70711; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_2_PI` found - --> $DIR/approx_const.rs:15:24 + --> $DIR/approx_const.rs:20:24 | LL | let my_frac_2_pi = 0.63661977; | ^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let my_frac_2_pi = 0.63661977; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found - --> $DIR/approx_const.rs:18:27 + --> $DIR/approx_const.rs:24:27 | LL | let my_frac_2_sq_pi = 1.128379; | ^^^^^^^^ @@ -56,7 +56,7 @@ LL | let my_frac_2_sq_pi = 1.128379; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_2` found - --> $DIR/approx_const.rs:21:24 + --> $DIR/approx_const.rs:28:24 | LL | let my_frac_pi_2 = 1.57079632679; | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let my_frac_pi_2 = 1.57079632679; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_3` found - --> $DIR/approx_const.rs:24:24 + --> $DIR/approx_const.rs:32:24 | LL | let my_frac_pi_3 = 1.04719755119; | ^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | let my_frac_pi_3 = 1.04719755119; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_4` found - --> $DIR/approx_const.rs:27:24 + --> $DIR/approx_const.rs:36:24 | LL | let my_frac_pi_4 = 0.785398163397; | ^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | let my_frac_pi_4 = 0.785398163397; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_6` found - --> $DIR/approx_const.rs:30:24 + --> $DIR/approx_const.rs:40:24 | LL | let my_frac_pi_6 = 0.523598775598; | ^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | let my_frac_pi_6 = 0.523598775598; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_8` found - --> $DIR/approx_const.rs:33:24 + --> $DIR/approx_const.rs:44:24 | LL | let my_frac_pi_8 = 0.3926990816987; | ^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let my_frac_pi_8 = 0.3926990816987; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LN_10` found - --> $DIR/approx_const.rs:36:20 + --> $DIR/approx_const.rs:48:20 | LL | let my_ln_10 = 2.302585092994046; | ^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | let my_ln_10 = 2.302585092994046; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LN_2` found - --> $DIR/approx_const.rs:39:19 + --> $DIR/approx_const.rs:52:19 | LL | let my_ln_2 = 0.6931471805599453; | ^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | let my_ln_2 = 0.6931471805599453; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG10_E` found - --> $DIR/approx_const.rs:42:22 + --> $DIR/approx_const.rs:56:22 | LL | let my_log10_e = 0.4342944819032518; | ^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | let my_log10_e = 0.4342944819032518; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_E` found - --> $DIR/approx_const.rs:45:21 + --> $DIR/approx_const.rs:60:21 | LL | let my_log2_e = 1.4426950408889634; | ^^^^^^^^^^^^^^^^^^ @@ -128,7 +128,7 @@ LL | let my_log2_e = 1.4426950408889634; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/approx_const.rs:48:19 + --> $DIR/approx_const.rs:64:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG10_2` found - --> $DIR/approx_const.rs:51:19 + --> $DIR/approx_const.rs:68:19 | LL | let log10_2 = 0.301029995663981; | ^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | let log10_2 = 0.301029995663981; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::PI` found - --> $DIR/approx_const.rs:54:17 + --> $DIR/approx_const.rs:72:17 | LL | let my_pi = 3.1415; | ^^^^^^ @@ -152,7 +152,7 @@ LL | let my_pi = 3.1415; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::PI` found - --> $DIR/approx_const.rs:55:21 + --> $DIR/approx_const.rs:74:21 | LL | let almost_pi = 3.14; | ^^^^ @@ -160,7 +160,7 @@ LL | let almost_pi = 3.14; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::SQRT_2` found - --> $DIR/approx_const.rs:58:18 + --> $DIR/approx_const.rs:78:18 | LL | let my_sq2 = 1.4142; | ^^^^^^ @@ -168,7 +168,7 @@ LL | let my_sq2 = 1.4142; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::TAU` found - --> $DIR/approx_const.rs:61:18 + --> $DIR/approx_const.rs:82:18 | LL | let my_tau = 6.2832; | ^^^^^^ @@ -176,7 +176,7 @@ LL | let my_tau = 6.2832; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::TAU` found - --> $DIR/approx_const.rs:62:22 + --> $DIR/approx_const.rs:84:22 | LL | let almost_tau = 6.28; | ^^^^ diff --git a/tests/ui/as_ptr_cast_mut.rs b/tests/ui/as_ptr_cast_mut.rs index 74dad7a493577..297a53b1bbfb4 100644 --- a/tests/ui/as_ptr_cast_mut.rs +++ b/tests/ui/as_ptr_cast_mut.rs @@ -20,7 +20,10 @@ impl Covariant { fn main() { let mut string = String::new(); let _ = string.as_ptr() as *mut u8; + //~^ ERROR: casting the result of `as_ptr` to *mut u8 + //~| NOTE: `-D clippy::as-ptr-cast-mut` implied by `-D warnings` let _: *mut i8 = string.as_ptr() as *mut _; + //~^ ERROR: casting the result of `as_ptr` to *mut i8 let _ = string.as_ptr() as *const i8; let _ = string.as_mut_ptr(); let _ = string.as_mut_ptr() as *mut u8; diff --git a/tests/ui/as_ptr_cast_mut.stderr b/tests/ui/as_ptr_cast_mut.stderr index 9255f4e048b26..1cd57dd6d1653 100644 --- a/tests/ui/as_ptr_cast_mut.stderr +++ b/tests/ui/as_ptr_cast_mut.stderr @@ -7,7 +7,7 @@ LL | let _ = string.as_ptr() as *mut u8; = note: `-D clippy::as-ptr-cast-mut` implied by `-D warnings` error: casting the result of `as_ptr` to *mut i8 - --> $DIR/as_ptr_cast_mut.rs:23:22 + --> $DIR/as_ptr_cast_mut.rs:25:22 | LL | let _: *mut i8 = string.as_ptr() as *mut _; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()` diff --git a/tests/ui/asm_syntax.rs b/tests/ui/asm_syntax.rs index af02e202b17bb..0a7eb86bc03f3 100644 --- a/tests/ui/asm_syntax.rs +++ b/tests/ui/asm_syntax.rs @@ -6,8 +6,11 @@ mod warn_intel { pub(super) unsafe fn use_asm() { use std::arch::asm; asm!(""); + //~^ ERROR: Intel x86 assembly syntax used asm!("", options()); + //~^ ERROR: Intel x86 assembly syntax used asm!("", options(nostack)); + //~^ ERROR: Intel x86 assembly syntax used asm!("", options(att_syntax)); asm!("", options(nostack, att_syntax)); } @@ -21,7 +24,9 @@ mod warn_att { asm!("", options()); asm!("", options(nostack)); asm!("", options(att_syntax)); + //~^ ERROR: AT&T x86 assembly syntax used asm!("", options(nostack, att_syntax)); + //~^ ERROR: AT&T x86 assembly syntax used } } diff --git a/tests/ui/asm_syntax.stderr b/tests/ui/asm_syntax.stderr index 9c7c3ba7d87e6..8ee3c97ae2c6c 100644 --- a/tests/ui/asm_syntax.stderr +++ b/tests/ui/asm_syntax.stderr @@ -8,7 +8,7 @@ LL | asm!(""); = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings` error: Intel x86 assembly syntax used - --> $DIR/asm_syntax.rs:9:9 + --> $DIR/asm_syntax.rs:10:9 | LL | asm!("", options()); | ^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | asm!("", options()); = help: use AT&T x86 assembly syntax error: Intel x86 assembly syntax used - --> $DIR/asm_syntax.rs:10:9 + --> $DIR/asm_syntax.rs:12:9 | LL | asm!("", options(nostack)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | asm!("", options(nostack)); = help: use AT&T x86 assembly syntax error: AT&T x86 assembly syntax used - --> $DIR/asm_syntax.rs:23:9 + --> $DIR/asm_syntax.rs:26:9 | LL | asm!("", options(att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | asm!("", options(att_syntax)); = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings` error: AT&T x86 assembly syntax used - --> $DIR/asm_syntax.rs:24:9 + --> $DIR/asm_syntax.rs:28:9 | LL | asm!("", options(nostack, att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/assertions_on_constants.rs b/tests/ui/assertions_on_constants.rs index 7bea9563d47d3..10809a6d247a2 100644 --- a/tests/ui/assertions_on_constants.rs +++ b/tests/ui/assertions_on_constants.rs @@ -8,21 +8,30 @@ macro_rules! assert_const { } fn main() { assert!(true); + //~^ ERROR: `assert!(true)` will be optimized out by the compiler assert!(false); + //~^ ERROR: `assert!(false)` should probably be replaced assert!(true, "true message"); + //~^ ERROR: `assert!(true)` will be optimized out by the compiler assert!(false, "false message"); + //~^ ERROR: `assert!(false, ..)` should probably be replaced let msg = "panic message"; assert!(false, "{}", msg.to_uppercase()); + //~^ ERROR: `assert!(false, ..)` should probably be replaced const B: bool = true; assert!(B); + //~^ ERROR: `assert!(true)` will be optimized out by the compiler const C: bool = false; assert!(C); + //~^ ERROR: `assert!(false)` should probably be replaced assert!(C, "C message"); + //~^ ERROR: `assert!(false, ..)` should probably be replaced debug_assert!(true); + //~^ ERROR: `debug_assert!(true)` will be optimized out by the compiler // Don't lint this, since there is no better way for expressing "Only panic in debug mode". debug_assert!(false); // #3948 assert_const!(3); diff --git a/tests/ui/assertions_on_constants.stderr b/tests/ui/assertions_on_constants.stderr index 29fe009035f16..fc1c7671ffc72 100644 --- a/tests/ui/assertions_on_constants.stderr +++ b/tests/ui/assertions_on_constants.stderr @@ -8,7 +8,7 @@ LL | assert!(true); = note: `-D clippy::assertions-on-constants` implied by `-D warnings` error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:11:5 + --> $DIR/assertions_on_constants.rs:12:5 | LL | assert!(false); | ^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | assert!(false); = help: use `panic!()` or `unreachable!()` error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:12:5 + --> $DIR/assertions_on_constants.rs:14:5 | LL | assert!(true, "true message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | assert!(true, "true message"); = help: remove it error: `assert!(false, ..)` should probably be replaced - --> $DIR/assertions_on_constants.rs:13:5 + --> $DIR/assertions_on_constants.rs:16:5 | LL | assert!(false, "false message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | assert!(false, "false message"); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(false, ..)` should probably be replaced - --> $DIR/assertions_on_constants.rs:16:5 + --> $DIR/assertions_on_constants.rs:20:5 | LL | assert!(false, "{}", msg.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | assert!(false, "{}", msg.to_uppercase()); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:19:5 + --> $DIR/assertions_on_constants.rs:24:5 | LL | assert!(B); | ^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | assert!(B); = help: remove it error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:22:5 + --> $DIR/assertions_on_constants.rs:28:5 | LL | assert!(C); | ^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | assert!(C); = help: use `panic!()` or `unreachable!()` error: `assert!(false, ..)` should probably be replaced - --> $DIR/assertions_on_constants.rs:23:5 + --> $DIR/assertions_on_constants.rs:30:5 | LL | assert!(C, "C message"); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | assert!(C, "C message"); = help: use `panic!(..)` or `unreachable!(..)` error: `debug_assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:25:5 + --> $DIR/assertions_on_constants.rs:33:5 | LL | debug_assert!(true); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/assign_ops2.rs b/tests/ui/assign_ops2.rs index 2be333df09902..a53556425849b 100644 --- a/tests/ui/assign_ops2.rs +++ b/tests/ui/assign_ops2.rs @@ -6,14 +6,24 @@ fn main() { let mut a = 5; a += a + 1; + //~^ ERROR: variable appears on both sides of an assignment operation + //~| NOTE: `-D clippy::misrefactored-assign-op` implied by `-D warnings` a += 1 + a; + //~^ ERROR: variable appears on both sides of an assignment operation a -= a - 1; + //~^ ERROR: variable appears on both sides of an assignment operation a *= a * 99; + //~^ ERROR: variable appears on both sides of an assignment operation a *= 42 * a; + //~^ ERROR: variable appears on both sides of an assignment operation a /= a / 2; + //~^ ERROR: variable appears on both sides of an assignment operation a %= a % 5; + //~^ ERROR: variable appears on both sides of an assignment operation a &= a & 1; + //~^ ERROR: variable appears on both sides of an assignment operation a *= a * a; + //~^ ERROR: variable appears on both sides of an assignment operation a = a * a * a; a = a * 42 * a; a = a * 2 + a; @@ -51,6 +61,8 @@ fn cow_add_assign() { // this can be linted buf = buf + cows.clone(); + //~^ ERROR: manual implementation of an assign operation + //~| NOTE: `-D clippy::assign-op-pattern` implied by `-D warnings` // this should not as cow Add is not commutative buf = cows + buf; diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr index e5ff3ff3a477a..b392d1c690bb6 100644 --- a/tests/ui/assign_ops2.stderr +++ b/tests/ui/assign_ops2.stderr @@ -15,7 +15,7 @@ LL | a = a + a + 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:9:5 + --> $DIR/assign_ops2.rs:11:5 | LL | a += 1 + a; | ^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | a = a + 1 + a; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:10:5 + --> $DIR/assign_ops2.rs:13:5 | LL | a -= a - 1; | ^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | a = a - (a - 1); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:11:5 + --> $DIR/assign_ops2.rs:15:5 | LL | a *= a * 99; | ^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | a = a * a * 99; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:12:5 + --> $DIR/assign_ops2.rs:17:5 | LL | a *= 42 * a; | ^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL | a = a * 42 * a; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:13:5 + --> $DIR/assign_ops2.rs:19:5 | LL | a /= a / 2; | ^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | a = a / (a / 2); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:14:5 + --> $DIR/assign_ops2.rs:21:5 | LL | a %= a % 5; | ^^^^^^^^^^ @@ -105,7 +105,7 @@ LL | a = a % (a % 5); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:15:5 + --> $DIR/assign_ops2.rs:23:5 | LL | a &= a & 1; | ^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | a = a & a & 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:16:5 + --> $DIR/assign_ops2.rs:25:5 | LL | a *= a * a; | ^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | a = a * a * a; | ~~~~~~~~~~~~~ error: manual implementation of an assign operation - --> $DIR/assign_ops2.rs:53:5 + --> $DIR/assign_ops2.rs:63:5 | LL | buf = buf + cows.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()` diff --git a/tests/ui/attrs.rs b/tests/ui/attrs.rs index 8df6e19421ec5..05ee48d17b1ef 100644 --- a/tests/ui/attrs.rs +++ b/tests/ui/attrs.rs @@ -3,6 +3,8 @@ #![allow(clippy::missing_docs_in_private_items, clippy::panic, clippy::unreachable)] #[inline(always)] +//~^ ERROR: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a b +//~| NOTE: `-D clippy::inline-always` implied by `-D warnings` fn test_attr_lint() { assert!(true) } @@ -23,9 +25,12 @@ fn empty_and_false_positive_stmt() { } #[deprecated(since = "forever")] +//~^ ERROR: the since field must contain a semver-compliant version +//~| NOTE: `-D clippy::deprecated-semver` implied by `-D warnings` pub const SOME_CONST: u8 = 42; #[deprecated(since = "1")] +//~^ ERROR: the since field must contain a semver-compliant version pub const ANOTHER_CONST: u8 = 23; #[deprecated(since = "0.1.1")] diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr index df4e9e20b649c..0139717f54861 100644 --- a/tests/ui/attrs.stderr +++ b/tests/ui/attrs.stderr @@ -7,7 +7,7 @@ LL | #[inline(always)] = note: `-D clippy::inline-always` implied by `-D warnings` error: the since field must contain a semver-compliant version - --> $DIR/attrs.rs:25:14 + --> $DIR/attrs.rs:27:14 | LL | #[deprecated(since = "forever")] | ^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | #[deprecated(since = "forever")] = note: `-D clippy::deprecated-semver` implied by `-D warnings` error: the since field must contain a semver-compliant version - --> $DIR/attrs.rs:28:14 + --> $DIR/attrs.rs:32:14 | LL | #[deprecated(since = "1")] | ^^^^^^^^^^^ diff --git a/tests/ui/await_holding_lock.rs b/tests/ui/await_holding_lock.rs index 57e5b55045b95..27b57b6481368 100644 --- a/tests/ui/await_holding_lock.rs +++ b/tests/ui/await_holding_lock.rs @@ -7,6 +7,7 @@ mod std_mutex { pub async fn bad(x: &Mutex) -> u32 { let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -22,11 +23,13 @@ mod std_mutex { pub async fn bad_rw(x: &RwLock) -> u32 { let guard = x.read().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } pub async fn bad_rw_write(x: &RwLock) -> u32 { let mut guard = x.write().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -48,6 +51,7 @@ mod std_mutex { let first = baz().await; let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point let second = baz().await; @@ -61,6 +65,7 @@ mod std_mutex { let second = { let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await }; @@ -73,6 +78,7 @@ mod std_mutex { pub fn block_bad(x: &Mutex) -> impl std::future::Future + '_ { async move { let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } } @@ -85,6 +91,7 @@ mod parking_lot_mutex { pub async fn bad(x: &Mutex) -> u32 { let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -100,11 +107,13 @@ mod parking_lot_mutex { pub async fn bad_rw(x: &RwLock) -> u32 { let guard = x.read(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } pub async fn bad_rw_write(x: &RwLock) -> u32 { let mut guard = x.write(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -126,6 +135,7 @@ mod parking_lot_mutex { let first = baz().await; let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point let second = baz().await; @@ -139,6 +149,7 @@ mod parking_lot_mutex { let second = { let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await }; @@ -151,6 +162,7 @@ mod parking_lot_mutex { pub fn block_bad(x: &Mutex) -> impl std::future::Future + '_ { async move { let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } } @@ -171,6 +183,7 @@ async fn no_await(x: std::sync::Mutex) { // `*guard += 1` is removed it is picked up. async fn dropped_before_await(x: std::sync::Mutex) { let mut guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point *guard += 1; drop(guard); baz().await; diff --git a/tests/ui/await_holding_lock.stderr b/tests/ui/await_holding_lock.stderr index 81a2d05243839..d360c757158b0 100644 --- a/tests/ui/await_holding_lock.stderr +++ b/tests/ui/await_holding_lock.stderr @@ -9,195 +9,206 @@ note: these are all the `await` points this lock is held through --> $DIR/await_holding_lock.rs:9:9 | LL | / let guard = x.lock().unwrap(); +LL | | LL | | baz().await LL | | } | |_____^ = note: `-D clippy::await-holding-lock` implied by `-D warnings` error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:24:13 + --> $DIR/await_holding_lock.rs:25:13 | LL | let guard = x.read().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:24:9 + --> $DIR/await_holding_lock.rs:25:9 | LL | / let guard = x.read().unwrap(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:29:13 + --> $DIR/await_holding_lock.rs:31:13 | LL | let mut guard = x.write().unwrap(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:29:9 + --> $DIR/await_holding_lock.rs:31:9 | LL | / let mut guard = x.write().unwrap(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:50:13 + --> $DIR/await_holding_lock.rs:53:13 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:50:9 + --> $DIR/await_holding_lock.rs:53:9 | LL | / let guard = x.lock().unwrap(); LL | | -LL | | let second = baz().await; LL | | +LL | | let second = baz().await; ... | LL | | first + second + third LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:63:17 + --> $DIR/await_holding_lock.rs:67:17 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:63:13 + --> $DIR/await_holding_lock.rs:67:13 | LL | / let guard = x.lock().unwrap(); +LL | | LL | | baz().await LL | | }; | |_________^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:75:17 + --> $DIR/await_holding_lock.rs:80:17 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:75:13 + --> $DIR/await_holding_lock.rs:80:13 | LL | / let guard = x.lock().unwrap(); +LL | | LL | | baz().await LL | | } | |_________^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:87:13 + --> $DIR/await_holding_lock.rs:93:13 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:87:9 + --> $DIR/await_holding_lock.rs:93:9 | LL | / let guard = x.lock(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:102:13 + --> $DIR/await_holding_lock.rs:109:13 | LL | let guard = x.read(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:102:9 + --> $DIR/await_holding_lock.rs:109:9 | LL | / let guard = x.read(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:107:13 + --> $DIR/await_holding_lock.rs:115:13 | LL | let mut guard = x.write(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:107:9 + --> $DIR/await_holding_lock.rs:115:9 | LL | / let mut guard = x.write(); +LL | | LL | | baz().await LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:128:13 + --> $DIR/await_holding_lock.rs:137:13 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:128:9 + --> $DIR/await_holding_lock.rs:137:9 | LL | / let guard = x.lock(); LL | | -LL | | let second = baz().await; LL | | +LL | | let second = baz().await; ... | LL | | first + second + third LL | | } | |_____^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:141:17 + --> $DIR/await_holding_lock.rs:151:17 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:141:13 + --> $DIR/await_holding_lock.rs:151:13 | LL | / let guard = x.lock(); +LL | | LL | | baz().await LL | | }; | |_________^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:153:17 + --> $DIR/await_holding_lock.rs:164:17 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:153:13 + --> $DIR/await_holding_lock.rs:164:13 | LL | / let guard = x.lock(); +LL | | LL | | baz().await LL | | } | |_________^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:173:9 + --> $DIR/await_holding_lock.rs:185:9 | LL | let mut guard = x.lock().unwrap(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:173:5 + --> $DIR/await_holding_lock.rs:185:5 | LL | / let mut guard = x.lock().unwrap(); +LL | | LL | | *guard += 1; LL | | drop(guard); LL | | baz().await; diff --git a/tests/ui/await_holding_refcell_ref.rs b/tests/ui/await_holding_refcell_ref.rs index 23b7095de3a39..5bd26c6283627 100644 --- a/tests/ui/await_holding_refcell_ref.rs +++ b/tests/ui/await_holding_refcell_ref.rs @@ -4,11 +4,13 @@ use std::cell::RefCell; async fn bad(x: &RefCell) -> u32 { let b = x.borrow(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await } async fn bad_mut(x: &RefCell) -> u32 { let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await } @@ -30,6 +32,7 @@ async fn also_bad(x: &RefCell) -> u32 { let first = baz().await; let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point let second = baz().await; @@ -42,6 +45,7 @@ async fn less_bad(x: &RefCell) -> u32 { let first = baz().await; let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point let second = baz().await; @@ -57,6 +61,7 @@ async fn not_good(x: &RefCell) -> u32 { let second = { let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await }; @@ -69,6 +74,7 @@ async fn not_good(x: &RefCell) -> u32 { fn block_bad(x: &RefCell) -> impl std::future::Future + '_ { async move { let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await } } diff --git a/tests/ui/await_holding_refcell_ref.stderr b/tests/ui/await_holding_refcell_ref.stderr index 25c15ab80602e..266f8f39028a5 100644 --- a/tests/ui/await_holding_refcell_ref.stderr +++ b/tests/ui/await_holding_refcell_ref.stderr @@ -9,90 +9,94 @@ note: these are all the `await` points this reference is held through --> $DIR/await_holding_refcell_ref.rs:6:5 | LL | / let b = x.borrow(); +LL | | LL | | baz().await LL | | } | |_^ = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings` error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:11:9 + --> $DIR/await_holding_refcell_ref.rs:12:9 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:11:5 + --> $DIR/await_holding_refcell_ref.rs:12:5 | LL | / let b = x.borrow_mut(); +LL | | LL | | baz().await LL | | } | |_^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:32:9 + --> $DIR/await_holding_refcell_ref.rs:34:9 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:32:5 + --> $DIR/await_holding_refcell_ref.rs:34:5 | LL | / let b = x.borrow_mut(); LL | | -LL | | let second = baz().await; LL | | +LL | | let second = baz().await; ... | LL | | first + second + third LL | | } | |_^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:44:9 + --> $DIR/await_holding_refcell_ref.rs:47:9 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:44:5 + --> $DIR/await_holding_refcell_ref.rs:47:5 | LL | / let b = x.borrow_mut(); LL | | -LL | | let second = baz().await; LL | | +LL | | let second = baz().await; ... | LL | | first + second + third LL | | } | |_^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:59:13 + --> $DIR/await_holding_refcell_ref.rs:63:13 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:59:9 + --> $DIR/await_holding_refcell_ref.rs:63:9 | LL | / let b = x.borrow_mut(); +LL | | LL | | baz().await LL | | }; | |_____^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:71:13 + --> $DIR/await_holding_refcell_ref.rs:76:13 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:71:9 + --> $DIR/await_holding_refcell_ref.rs:76:9 | LL | / let b = x.borrow_mut(); +LL | | LL | | baz().await LL | | } | |_____^ diff --git a/tests/ui/bit_masks.rs b/tests/ui/bit_masks.rs index cfb493fb52afb..8e1d066c25e49 100644 --- a/tests/ui/bit_masks.rs +++ b/tests/ui/bit_masks.rs @@ -12,19 +12,27 @@ fn main() { let x = 5; x & 0 == 0; + //~^ ERROR: &-masking with zero + //~| NOTE: `-D clippy::bad-bit-mask` implied by `-D warnings` + //~| ERROR: this operation will always return zero. This is likely not the intended ou + //~| NOTE: `#[deny(clippy::erasing_op)]` on by default x & 1 == 1; //ok, distinguishes bit 0 x & 1 == 0; //ok, compared with zero x & 2 == 1; + //~^ ERROR: incompatible bit mask: `_ & 2` can never be equal to `1` 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; + //~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2` x & 1 > 1; + //~^ ERROR: incompatible bit mask: `_ & 1` will never be higher than `1` 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; + //~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1` x | 2 <= 2; // ok (if a bit silly), equals x <= 2 x & 192 == 128; // ok, tests for bit 7 and not bit 6 @@ -32,15 +40,22 @@ fn main() { // this also now works with constants x & THREE_BITS == 8; + //~^ ERROR: incompatible bit mask: `_ & 7` can never be equal to `8` x | EVEN_MORE_REDIRECTION < 7; + //~^ ERROR: incompatible bit mask: `_ | 7` will never be lower than `7` 0 & x == 0; + //~^ ERROR: &-masking with zero + //~| ERROR: this operation will always return zero. This is likely not the intended ou 1 | x > 1; // and should now also match uncommon usage 1 < 2 | x; + //~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1` 2 == 3 | x; + //~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2` 1 == x & 2; + //~^ ERROR: incompatible bit mask: `_ & 2` can never be equal to `1` x | 1 > 2; // no error, because we allowed ineffective bit masks ineffective(); @@ -52,9 +67,14 @@ fn ineffective() { let x = 5; x | 1 > 3; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared d + //~| NOTE: `-D clippy::ineffective-bit-mask` implied by `-D warnings` x | 1 < 4; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared d x | 1 <= 3; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared d x | 1 >= 8; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared d x | 1 > 2; // not an error (yet), better written as x >= 2 x | 1 >= 7; // not an error (yet), better written as x >= 6 diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr index dc5ad6dfbdff9..d0cb3a263fca8 100644 --- a/tests/ui/bit_masks.stderr +++ b/tests/ui/bit_masks.stderr @@ -15,73 +15,73 @@ LL | x & 0 == 0; = note: `#[deny(clippy::erasing_op)]` on by default error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> $DIR/bit_masks.rs:17:5 + --> $DIR/bit_masks.rs:21:5 | LL | x & 2 == 1; | ^^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> $DIR/bit_masks.rs:21:5 + --> $DIR/bit_masks.rs:26:5 | LL | x | 3 == 2; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 1` will never be higher than `1` - --> $DIR/bit_masks.rs:23:5 + --> $DIR/bit_masks.rs:29:5 | LL | x & 1 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> $DIR/bit_masks.rs:27:5 + --> $DIR/bit_masks.rs:34:5 | LL | x | 2 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ & 7` can never be equal to `8` - --> $DIR/bit_masks.rs:34:5 + --> $DIR/bit_masks.rs:42:5 | LL | x & THREE_BITS == 8; | ^^^^^^^^^^^^^^^^^^^ error: incompatible bit mask: `_ | 7` will never be lower than `7` - --> $DIR/bit_masks.rs:35:5 + --> $DIR/bit_masks.rs:44:5 | LL | x | EVEN_MORE_REDIRECTION < 7; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: &-masking with zero - --> $DIR/bit_masks.rs:37:5 + --> $DIR/bit_masks.rs:47:5 | LL | 0 & x == 0; | ^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/bit_masks.rs:37:5 + --> $DIR/bit_masks.rs:47:5 | LL | 0 & x == 0; | ^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> $DIR/bit_masks.rs:41:5 + --> $DIR/bit_masks.rs:53:5 | LL | 1 < 2 | x; | ^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> $DIR/bit_masks.rs:42:5 + --> $DIR/bit_masks.rs:55:5 | LL | 2 == 3 | x; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> $DIR/bit_masks.rs:43:5 + --> $DIR/bit_masks.rs:57:5 | LL | 1 == x & 2; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> $DIR/bit_masks.rs:54:5 + --> $DIR/bit_masks.rs:69:5 | LL | x | 1 > 3; | ^^^^^^^^^ @@ -89,19 +89,19 @@ LL | x | 1 > 3; = note: `-D clippy::ineffective-bit-mask` implied by `-D warnings` error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly - --> $DIR/bit_masks.rs:55:5 + --> $DIR/bit_masks.rs:72:5 | LL | x | 1 < 4; | ^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> $DIR/bit_masks.rs:56:5 + --> $DIR/bit_masks.rs:74:5 | LL | x | 1 <= 3; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly - --> $DIR/bit_masks.rs:57:5 + --> $DIR/bit_masks.rs:76:5 | LL | x | 1 >= 8; | ^^^^^^^^^^ diff --git a/tests/ui/blanket_clippy_restriction_lints.rs b/tests/ui/blanket_clippy_restriction_lints.rs index e1ff25c54cfcb..2bfaadf8df94e 100644 --- a/tests/ui/blanket_clippy_restriction_lints.rs +++ b/tests/ui/blanket_clippy_restriction_lints.rs @@ -4,7 +4,10 @@ //! Test that the whole restriction group is not enabled #![warn(clippy::restriction)] +//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group #![deny(clippy::restriction)] +//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group #![forbid(clippy::restriction)] +//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group fn main() {} diff --git a/tests/ui/blanket_clippy_restriction_lints.stderr b/tests/ui/blanket_clippy_restriction_lints.stderr index 2bf89ab69a40c..0f92fbebae99f 100644 --- a/tests/ui/blanket_clippy_restriction_lints.stderr +++ b/tests/ui/blanket_clippy_restriction_lints.stderr @@ -13,7 +13,7 @@ LL | #![warn(clippy::restriction)] = help: enable the restriction lints you need individually error: `clippy::restriction` is not meant to be enabled as a group - --> $DIR/blanket_clippy_restriction_lints.rs:7:9 + --> $DIR/blanket_clippy_restriction_lints.rs:8:9 | LL | #![deny(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | #![deny(clippy::restriction)] = help: enable the restriction lints you need individually error: `clippy::restriction` is not meant to be enabled as a group - --> $DIR/blanket_clippy_restriction_lints.rs:8:11 + --> $DIR/blanket_clippy_restriction_lints.rs:10:11 | LL | #![forbid(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/blocks_in_if_conditions_closure.rs b/tests/ui/blocks_in_if_conditions_closure.rs index d6d085d7fd14f..539f2df15bd85 100644 --- a/tests/ui/blocks_in_if_conditions_closure.rs +++ b/tests/ui/blocks_in_if_conditions_closure.rs @@ -21,6 +21,8 @@ fn pred_test() { && sky == "blue" && predicate( |x| { + //~^ ERROR: in an `if` condition, avoid complex blocks or closures with blocks + //~| NOTE: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` let target = 3; x == target }, @@ -30,6 +32,7 @@ fn pred_test() { if predicate( |x| { + //~^ ERROR: in an `if` condition, avoid complex blocks or closures with blocks; in let target = 3; x == target }, diff --git a/tests/ui/blocks_in_if_conditions_closure.stderr b/tests/ui/blocks_in_if_conditions_closure.stderr index 5ac02e7504e8a..34ebe5b6d1446 100644 --- a/tests/ui/blocks_in_if_conditions_closure.stderr +++ b/tests/ui/blocks_in_if_conditions_closure.stderr @@ -3,6 +3,8 @@ error: in an `if` condition, avoid complex blocks or closures with blocks; inste | LL | |x| { | _________________^ +LL | | +LL | | LL | | let target = 3; LL | | x == target LL | | }, @@ -11,10 +13,11 @@ LL | | }, = note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` - --> $DIR/blocks_in_if_conditions_closure.rs:32:13 + --> $DIR/blocks_in_if_conditions_closure.rs:34:13 | LL | |x| { | _____________^ +LL | | LL | | let target = 3; LL | | x == target LL | | }, diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index 1c0fd470ddb04..e9994aac8454a 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -23,14 +23,17 @@ pub fn test1(foo: &mut Box) { pub fn test2() { let foo: &Box; + //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` } struct Test3<'a> { foo: &'a Box, + //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` } trait Test4 { fn test4(a: &Box); + //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` } impl<'a> Test4 for Test3<'a> { @@ -97,17 +100,24 @@ pub fn test13(boxed_slice: &mut Box<[i32]>) { // The suggestion should include proper parentheses to avoid a syntax error. pub fn test14(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test15(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test16<'a>(_display: &'a Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test17(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test18(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test19<'a>(_display: &'a Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` // This exists only to check what happens when parentheses are already present. // Even though the current implementation doesn't put extra parentheses, // it's fine that unnecessary parentheses appear in the future for some reason. pub fn test20(_display: &Box<(dyn Display + Send)>) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` fn main() { test1(&mut Box::new(false)); diff --git a/tests/ui/borrow_box.stderr b/tests/ui/borrow_box.stderr index 6f498d2338d99..a9773958a3778 100644 --- a/tests/ui/borrow_box.stderr +++ b/tests/ui/borrow_box.stderr @@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)] | ^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:29:10 + --> $DIR/borrow_box.rs:30:10 | LL | foo: &'a Box, | ^^^^^^^^^^^^^ help: try: `&'a bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:33:17 + --> $DIR/borrow_box.rs:35:17 | LL | fn test4(a: &Box); | ^^^^^^^^^^ help: try: `&bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:99:25 + --> $DIR/borrow_box.rs:102:25 | LL | pub fn test14(_display: &Box) {} | ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:100:25 + --> $DIR/borrow_box.rs:104:25 | LL | pub fn test15(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:101:29 + --> $DIR/borrow_box.rs:106:29 | LL | pub fn test16<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:103:25 + --> $DIR/borrow_box.rs:109:25 | LL | pub fn test17(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:104:25 + --> $DIR/borrow_box.rs:111:25 | LL | pub fn test18(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:105:29 + --> $DIR/borrow_box.rs:113:29 | LL | pub fn test19<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:110:25 + --> $DIR/borrow_box.rs:119:25 | LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` diff --git a/tests/ui/borrow_deref_ref_unfixable.rs b/tests/ui/borrow_deref_ref_unfixable.rs index 5e7a8d514b546..be98873395978 100644 --- a/tests/ui/borrow_deref_ref_unfixable.rs +++ b/tests/ui/borrow_deref_ref_unfixable.rs @@ -7,5 +7,7 @@ mod should_lint { fn two_helps() { let s = &String::new(); let x: &str = &*s; + //~^ ERROR: deref on an immutable reference + //~| NOTE: `-D clippy::borrow-deref-ref` implied by `-D warnings` } } diff --git a/tests/ui/box_collection.rs b/tests/ui/box_collection.rs index 4c9947b9ae724..499625ea9c31a 100644 --- a/tests/ui/box_collection.rs +++ b/tests/ui/box_collection.rs @@ -19,6 +19,7 @@ fn test_macro() { } fn test1(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Vec<..>` fn test2(foo: Box)>) { // pass if #31 is fixed @@ -26,20 +27,28 @@ fn test2(foo: Box)>) { } fn test3(foo: Box) {} +//~^ ERROR: you seem to be trying to use `Box`. Consider using just `String` fn test4(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `HashMap< fn test5(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `HashSet< fn test6(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `VecDequ fn test7(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Linke fn test8(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `BTreeMa fn test9(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `BTreeSe fn test10(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Binar fn test_local_not_linted() { let _: Box>; diff --git a/tests/ui/box_collection.stderr b/tests/ui/box_collection.stderr index 40b6f9be61d59..7734271267534 100644 --- a/tests/ui/box_collection.stderr +++ b/tests/ui/box_collection.stderr @@ -8,7 +8,7 @@ LL | fn test1(foo: Box>) {} = note: `-D clippy::box-collection` implied by `-D warnings` error: you seem to be trying to use `Box`. Consider using just `String` - --> $DIR/box_collection.rs:28:15 + --> $DIR/box_collection.rs:29:15 | LL | fn test3(foo: Box) {} | ^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn test3(foo: Box) {} = help: `String` is already on the heap, `Box` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `HashMap<..>` - --> $DIR/box_collection.rs:30:15 + --> $DIR/box_collection.rs:32:15 | LL | fn test4(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn test4(foo: Box>) {} = help: `HashMap<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `HashSet<..>` - --> $DIR/box_collection.rs:32:15 + --> $DIR/box_collection.rs:35:15 | LL | fn test5(foo: Box>) {} | ^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | fn test5(foo: Box>) {} = help: `HashSet<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `VecDeque<..>` - --> $DIR/box_collection.rs:34:15 + --> $DIR/box_collection.rs:38:15 | LL | fn test6(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | fn test6(foo: Box>) {} = help: `VecDeque<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `LinkedList<..>` - --> $DIR/box_collection.rs:36:15 + --> $DIR/box_collection.rs:41:15 | LL | fn test7(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | fn test7(foo: Box>) {} = help: `LinkedList<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `BTreeMap<..>` - --> $DIR/box_collection.rs:38:15 + --> $DIR/box_collection.rs:44:15 | LL | fn test8(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | fn test8(foo: Box>) {} = help: `BTreeMap<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `BTreeSet<..>` - --> $DIR/box_collection.rs:40:15 + --> $DIR/box_collection.rs:47:15 | LL | fn test9(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | fn test9(foo: Box>) {} = help: `BTreeSet<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `BinaryHeap<..>` - --> $DIR/box_collection.rs:42:16 + --> $DIR/box_collection.rs:50:16 | LL | fn test10(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/boxed_local.rs b/tests/ui/boxed_local.rs index 79b6d33fc77ca..e888154c46def 100644 --- a/tests/ui/boxed_local.rs +++ b/tests/ui/boxed_local.rs @@ -38,6 +38,8 @@ fn warn_call() { } fn warn_arg(x: Box) { + //~^ ERROR: local variable doesn't need to be boxed here + //~| NOTE: `-D clippy::boxed-local` implied by `-D warnings` x.foo(); } @@ -119,6 +121,7 @@ pub struct PeekableSeekable { } pub fn new(_needs_name: Box>) -> () {} +//~^ ERROR: local variable doesn't need to be boxed here /// Regression for #916, #1123 /// @@ -183,6 +186,7 @@ mod issue4804 { // warn on `x: Box` fn default_impl_x(self: Box, x: Box) -> u32 { + //~^ ERROR: local variable doesn't need to be boxed here 4 } } @@ -190,6 +194,7 @@ mod issue4804 { trait WarnTrait { // warn on `x: Box` fn foo(x: Box) {} + //~^ ERROR: local variable doesn't need to be boxed here } } diff --git a/tests/ui/boxed_local.stderr b/tests/ui/boxed_local.stderr index 10d78fbc0abb5..11868605d9693 100644 --- a/tests/ui/boxed_local.stderr +++ b/tests/ui/boxed_local.stderr @@ -7,19 +7,19 @@ LL | fn warn_arg(x: Box) { = note: `-D clippy::boxed-local` implied by `-D warnings` error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:121:12 + --> $DIR/boxed_local.rs:123:12 | LL | pub fn new(_needs_name: Box>) -> () {} | ^^^^^^^^^^^ error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:185:44 + --> $DIR/boxed_local.rs:188:44 | LL | fn default_impl_x(self: Box, x: Box) -> u32 { | ^ error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:192:16 + --> $DIR/boxed_local.rs:196:16 | LL | fn foo(x: Box) {} | ^ diff --git a/tests/ui/branches_sharing_code/shared_at_bottom.rs b/tests/ui/branches_sharing_code/shared_at_bottom.rs index e2ce3f6ff28a5..d102efa7a5880 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.rs +++ b/tests/ui/branches_sharing_code/shared_at_bottom.rs @@ -29,6 +29,8 @@ fn simple_examples() { // The rest is self contained and moveable => Only lint the rest let result = false; + //~^ ERROR: all if blocks contain the same code at the end + //~| NOTE: the end suggestion probably needs some adjustments to use the expressio println!("Block end!"); result }; @@ -47,6 +49,7 @@ fn simple_examples() { } else { println!("This is also eq with the else block"); println!("Same end of block"); + //~^ ERROR: all if blocks contain the same code at the end } // Use of outer scope value @@ -64,6 +67,7 @@ fn simple_examples() { println!("I'm a local because I use the value `z`: `{}`", z); println!( + //~^ ERROR: all if blocks contain the same code at the end "I'm moveable because I know: `outer_scope_value`: '{}'", outer_scope_value ); @@ -76,6 +80,7 @@ fn simple_examples() { println!("Hello World"); } else { println!("Hello World"); + //~^ ERROR: all if blocks contain the same code at the end } } } @@ -92,6 +97,7 @@ fn simple_but_suggestion_is_invalid() { println!("{}", later_used_value); } else { let later_used_value = "A string value"; + //~^ ERROR: all if blocks contain the same code at the end println!("{}", later_used_value); // I'm expecting a note about this } @@ -105,6 +111,7 @@ fn simple_but_suggestion_is_invalid() { println!("Separator print statement"); let simple_examples = "I now identify as a &str :)"; + //~^ ERROR: all if blocks contain the same code at the end println!("This is the new simple_example: {}", simple_examples); } simple_examples(); @@ -170,6 +177,8 @@ fn added_note_for_expression_use() -> u32 { } else { let _ = 6; x << 2 + //~^ ERROR: all if blocks contain the same code at the end + //~| NOTE: the end suggestion probably needs some adjustments to use the expressio }; if x == 9 { @@ -177,6 +186,8 @@ fn added_note_for_expression_use() -> u32 { } else { let _ = 17; x * 4 + //~^ ERROR: all if blocks contain the same code at the end + //~| NOTE: the end suggestion probably needs some adjustments to use the expressio } } @@ -189,6 +200,7 @@ fn test_suggestion_with_weird_formatting() { // The error message still looks weird tbh but this is the best I can do // for weird formatting if x == 17 { b = 1; a = 0x99; } else { a = 0x99; } + //~^ ERROR: all if blocks contain the same code at the end } fn fp_test() { diff --git a/tests/ui/branches_sharing_code/shared_at_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_bottom.stderr index b9b113dc0c6a0..d00717befc103 100644 --- a/tests/ui/branches_sharing_code/shared_at_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_bottom.stderr @@ -2,6 +2,8 @@ error: all if blocks contain the same code at the end --> $DIR/shared_at_bottom.rs:31:5 | LL | / let result = false; +LL | | +LL | | LL | | println!("Block end!"); LL | | result LL | | }; @@ -17,14 +19,17 @@ help: consider moving these statements after the if | LL ~ } LL + let result = false; +LL + +LL + LL + println!("Block end!"); LL ~ result; | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:49:5 + --> $DIR/shared_at_bottom.rs:51:5 | LL | / println!("Same end of block"); +LL | | LL | | } | |_____^ | @@ -35,9 +40,10 @@ LL + println!("Same end of block"); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:66:5 + --> $DIR/shared_at_bottom.rs:69:5 | LL | / println!( +LL | | LL | | "I'm moveable because I know: `outer_scope_value`: '{}'", LL | | outer_scope_value LL | | ); @@ -48,15 +54,17 @@ help: consider moving these statements after the if | LL ~ } LL + println!( +LL + LL + "I'm moveable because I know: `outer_scope_value`: '{}'", LL + outer_scope_value LL + ); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:78:9 + --> $DIR/shared_at_bottom.rs:82:9 | LL | / println!("Hello World"); +LL | | LL | | } | |_________^ | @@ -67,9 +75,10 @@ LL + println!("Hello World"); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:94:5 + --> $DIR/shared_at_bottom.rs:99:5 | LL | / let later_used_value = "A string value"; +LL | | LL | | println!("{}", later_used_value); LL | | // I'm expecting a note about this LL | | } @@ -80,13 +89,15 @@ help: consider moving these statements after the if | LL ~ } LL + let later_used_value = "A string value"; +LL + LL + println!("{}", later_used_value); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:107:5 + --> $DIR/shared_at_bottom.rs:113:5 | LL | / let simple_examples = "I now identify as a &str :)"; +LL | | LL | | println!("This is the new simple_example: {}", simple_examples); LL | | } | |_____^ @@ -96,13 +107,16 @@ help: consider moving these statements after the if | LL ~ } LL + let simple_examples = "I now identify as a &str :)"; +LL + LL + println!("This is the new simple_example: {}", simple_examples); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:172:5 + --> $DIR/shared_at_bottom.rs:179:5 | LL | / x << 2 +LL | | +LL | | LL | | }; | |_____^ | @@ -114,9 +128,11 @@ LL ~ x << 2; | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:179:5 + --> $DIR/shared_at_bottom.rs:188:5 | LL | / x * 4 +LL | | +LL | | LL | | } | |_____^ | @@ -128,7 +144,7 @@ LL + x * 4 | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:191:44 + --> $DIR/shared_at_bottom.rs:202:44 | LL | if x == 17 { b = 1; a = 0x99; } else { a = 0x99; } | ^^^^^^^^^^^ diff --git a/tests/ui/branches_sharing_code/shared_at_top.rs b/tests/ui/branches_sharing_code/shared_at_top.rs index ac206ac8741e9..44f8b2eabce3b 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.rs +++ b/tests/ui/branches_sharing_code/shared_at_top.rs @@ -9,6 +9,7 @@ fn simple_examples() { // Simple if true { + //~^ ERROR: all if blocks contain the same code at the start println!("Hello World!"); println!("I'm branch nr: 1"); } else { @@ -18,6 +19,7 @@ fn simple_examples() { // Else if if x == 0 { + //~^ ERROR: all if blocks contain the same code at the start let y = 9; println!("The value y was set to: `{}`", y); let _z = y; @@ -39,6 +41,7 @@ fn simple_examples() { // Return a value let _ = if x == 7 { + //~^ ERROR: all if blocks contain the same code at the start let y = 16; println!("What can I say except: \"you're welcome?\""); let _ = y; @@ -57,6 +60,7 @@ fn simple_but_suggestion_is_invalid() { // Can't be automatically moved because used_value_name is getting used again let used_value_name = 19; if x == 10 { + //~^ ERROR: all if blocks contain the same code at the start let used_value_name = "Different type"; println!("Str: {}", used_value_name); let _ = 1; @@ -71,6 +75,7 @@ fn simple_but_suggestion_is_invalid() { let can_be_overridden = 8; let _ = can_be_overridden; if x == 11 { + //~^ ERROR: all if blocks contain the same code at the start let can_be_overridden = "Move me"; println!("I'm also moveable"); let _ = 111; @@ -87,6 +92,7 @@ fn check_if_same_than_else_mask() { #[allow(clippy::if_same_then_else)] if x == 2020 { + //~^ ERROR: all if blocks contain the same code at the start println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); println!("Because `IF_SAME_THEN_ELSE` is allowed here"); } else { @@ -95,6 +101,7 @@ fn check_if_same_than_else_mask() { } if x == 2019 { + //~^ ERROR: this `if` has identical blocks println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); } else { println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); diff --git a/tests/ui/branches_sharing_code/shared_at_top.stderr b/tests/ui/branches_sharing_code/shared_at_top.stderr index 3e3242a75d303..9d4d42fb689e4 100644 --- a/tests/ui/branches_sharing_code/shared_at_top.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top.stderr @@ -2,6 +2,7 @@ error: all if blocks contain the same code at the start --> $DIR/shared_at_top.rs:11:5 | LL | / if true { +LL | | LL | | println!("Hello World!"); | |_________________________________^ | @@ -17,9 +18,10 @@ LL + if true { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:20:5 + --> $DIR/shared_at_top.rs:21:5 | LL | / if x == 0 { +LL | | LL | | let y = 9; LL | | println!("The value y was set to: `{}`", y); LL | | let _z = y; @@ -35,9 +37,10 @@ LL + if x == 0 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:41:5 + --> $DIR/shared_at_top.rs:43:5 | LL | / let _ = if x == 7 { +LL | | LL | | let y = 16; | |___________________^ | @@ -48,9 +51,10 @@ LL + let _ = if x == 7 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:59:5 + --> $DIR/shared_at_top.rs:62:5 | LL | / if x == 10 { +LL | | LL | | let used_value_name = "Different type"; LL | | println!("Str: {}", used_value_name); | |_____________________________________________^ @@ -64,9 +68,10 @@ LL + if x == 10 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:73:5 + --> $DIR/shared_at_top.rs:77:5 | LL | / if x == 11 { +LL | | LL | | let can_be_overridden = "Move me"; LL | | println!("I'm also moveable"); | |______________________________________^ @@ -80,9 +85,10 @@ LL + if x == 11 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:89:5 + --> $DIR/shared_at_top.rs:94:5 | LL | / if x == 2020 { +LL | | LL | | println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); LL | | println!("Because `IF_SAME_THEN_ELSE` is allowed here"); | |________________________________________________________________^ @@ -95,16 +101,17 @@ LL + if x == 2020 { | error: this `if` has identical blocks - --> $DIR/shared_at_top.rs:97:18 + --> $DIR/shared_at_top.rs:103:18 | LL | if x == 2019 { | __________________^ +LL | | LL | | println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); LL | | } else { | |_____^ | note: same as this - --> $DIR/shared_at_top.rs:99:12 + --> $DIR/shared_at_top.rs:106:12 | LL | } else { | ____________^ diff --git a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs index eb0b937e22089..36620ee1a9bf0 100644 --- a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs +++ b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs @@ -15,6 +15,7 @@ fn overlapping_eq_regions() { // Overlap with separator if x == 7 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let t = 7; let _overlap_start = t * 2; let _overlap_end = 2 * t; @@ -31,6 +32,7 @@ fn overlapping_eq_regions() { // Overlap with separator if x == 99 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let r = 7; let _overlap_start = r; let _overlap_middle = r * r; @@ -60,6 +62,7 @@ fn complexer_example() { let x = 8; let y = 9; if (x > 7 && y < 13) || (x + y) % 2 == 1 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let a = 0xcafe; let b = 0xffff00ff; let e_id = gen_id(a, b); @@ -93,6 +96,7 @@ fn added_note_for_expression_use() -> u32 { let x = 9; let _ = if x == 7 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let _ = 19; let _splitter = 6; @@ -105,6 +109,7 @@ fn added_note_for_expression_use() -> u32 { }; if x == 9 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let _ = 17; let _splitter = 6; diff --git a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr index ccd697a421551..74495fca8ab75 100644 --- a/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr +++ b/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr @@ -2,13 +2,14 @@ error: all if blocks contain the same code at both the start and the end --> $DIR/shared_at_top_and_bottom.rs:17:5 | LL | / if x == 7 { +LL | | LL | | let t = 7; LL | | let _overlap_start = t * 2; LL | | let _overlap_end = 2 * t; | |_________________________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:29:5 + --> $DIR/shared_at_top_and_bottom.rs:30:5 | LL | / let _u = 9; LL | | } @@ -32,16 +33,17 @@ LL + let _u = 9; | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:33:5 + --> $DIR/shared_at_top_and_bottom.rs:34:5 | LL | / if x == 99 { +LL | | LL | | let r = 7; LL | | let _overlap_start = r; LL | | let _overlap_middle = r * r; | |____________________________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:44:5 + --> $DIR/shared_at_top_and_bottom.rs:46:5 | LL | / let _overlap_end = r * r * r; LL | | let z = "end"; @@ -63,16 +65,17 @@ LL + let z = "end"; | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:62:5 + --> $DIR/shared_at_top_and_bottom.rs:64:5 | LL | / if (x > 7 && y < 13) || (x + y) % 2 == 1 { +LL | | LL | | let a = 0xcafe; LL | | let b = 0xffff00ff; LL | | let e_id = gen_id(a, b); | |________________________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:82:5 + --> $DIR/shared_at_top_and_bottom.rs:85:5 | LL | / let pack = DataPack { LL | | id: e_id, @@ -102,14 +105,15 @@ LL + process_data(pack); | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:95:5 + --> $DIR/shared_at_top_and_bottom.rs:98:5 | LL | / let _ = if x == 7 { +LL | | LL | | let _ = 19; | |___________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:104:5 + --> $DIR/shared_at_top_and_bottom.rs:108:5 | LL | / x << 2 LL | | }; @@ -127,14 +131,15 @@ LL ~ x << 2; | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:107:5 + --> $DIR/shared_at_top_and_bottom.rs:111:5 | LL | / if x == 9 { +LL | | LL | | let _ = 17; | |___________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:116:5 + --> $DIR/shared_at_top_and_bottom.rs:121:5 | LL | / x * 4 LL | | } diff --git a/tests/ui/branches_sharing_code/valid_if_blocks.rs b/tests/ui/branches_sharing_code/valid_if_blocks.rs index 5780ea0893777..2aeacb89c0cb6 100644 --- a/tests/ui/branches_sharing_code/valid_if_blocks.rs +++ b/tests/ui/branches_sharing_code/valid_if_blocks.rs @@ -107,6 +107,7 @@ fn valid_examples() { // Let's test empty blocks if false { + //~^ ERROR: this `if` has identical blocks } else { } } @@ -118,6 +119,7 @@ fn trigger_other_lint() { // Same block if x == 0 { + //~^ ERROR: this `if` has identical blocks let u = 19; println!("How are u today?"); let _ = "This is a string"; @@ -129,12 +131,14 @@ fn trigger_other_lint() { // Only same expression let _ = if x == 6 { 7 } else { 7 }; + //~^ ERROR: this `if` has identical blocks // Same in else if block let _ = if x == 67 { println!("Well I'm the most important block"); "I'm a pretty string" } else if x == 68 { + //~^ ERROR: this `if` has identical blocks println!("I'm a doppelgänger"); // Don't listen to my clone below @@ -149,6 +153,7 @@ fn trigger_other_lint() { if x == 0 { println!("I'm single"); } else if x == 68 { + //~^ ERROR: this `if` has identical blocks println!("I'm a doppelgänger"); // Don't listen to my clone below } else { diff --git a/tests/ui/branches_sharing_code/valid_if_blocks.stderr b/tests/ui/branches_sharing_code/valid_if_blocks.stderr index a7e72b780affc..fcbf12235aa16 100644 --- a/tests/ui/branches_sharing_code/valid_if_blocks.stderr +++ b/tests/ui/branches_sharing_code/valid_if_blocks.stderr @@ -3,11 +3,12 @@ error: this `if` has identical blocks | LL | if false { | ______________^ +LL | | LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:110:12 + --> $DIR/valid_if_blocks.rs:111:12 | LL | } else { | ____________^ @@ -20,10 +21,11 @@ LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:120:15 + --> $DIR/valid_if_blocks.rs:121:15 | LL | if x == 0 { | _______________^ +LL | | LL | | let u = 19; LL | | println!("How are u today?"); LL | | let _ = "This is a string"; @@ -31,7 +33,7 @@ LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:124:12 + --> $DIR/valid_if_blocks.rs:126:12 | LL | } else { | ____________^ @@ -42,22 +44,23 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:131:23 + --> $DIR/valid_if_blocks.rs:133:23 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ | note: same as this - --> $DIR/valid_if_blocks.rs:131:34 + --> $DIR/valid_if_blocks.rs:133:34 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:137:23 + --> $DIR/valid_if_blocks.rs:140:23 | LL | } else if x == 68 { | _______________________^ +LL | | LL | | println!("I'm a doppelgänger"); LL | | // Don't listen to my clone below LL | | @@ -66,7 +69,7 @@ LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:142:12 + --> $DIR/valid_if_blocks.rs:146:12 | LL | } else { | ____________^ @@ -78,17 +81,18 @@ LL | | }; | |_____^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:151:23 + --> $DIR/valid_if_blocks.rs:155:23 | LL | } else if x == 68 { | _______________________^ +LL | | LL | | println!("I'm a doppelgänger"); LL | | // Don't listen to my clone below LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:154:12 + --> $DIR/valid_if_blocks.rs:159:12 | LL | } else { | ____________^ diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index ba1ef6e49168e..3794fc5d441c6 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -8,9 +8,11 @@ fn main() { // naive byte count let _ = x.iter().filter(|&&a| a == 0).count(); + //~^ ERROR: you appear to be counting bytes the naive way // naive byte count let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); + //~^ ERROR: you appear to be counting bytes the naive way // not an equality count, OK. let _ = x.iter().filter(|a| **a > 0).count(); @@ -28,6 +30,7 @@ fn main() { // naive byte count let _ = x.iter().filter(|a| b + 1 == **a).count(); + //~^ ERROR: you appear to be counting bytes the naive way let y = vec![0_u16; 3]; diff --git a/tests/ui/bytecount.stderr b/tests/ui/bytecount.stderr index 680b7b2bda8b9..39007f9d10aa2 100644 --- a/tests/ui/bytecount.stderr +++ b/tests/ui/bytecount.stderr @@ -11,13 +11,13 @@ LL | #[deny(clippy::naive_bytecount)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:13:13 + --> $DIR/bytecount.rs:14:13 | LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count((&x[..]), 0)` error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:30:13 + --> $DIR/bytecount.rs:32:13 | LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, b + 1)` diff --git a/tests/ui/cast.rs b/tests/ui/cast.rs index d2cfa41611844..d0a092093f3e0 100644 --- a/tests/ui/cast.rs +++ b/tests/ui/cast.rs @@ -14,56 +14,101 @@ fn main() { // Test clippy::cast_precision_loss let x0 = 1i32; x0 as f32; + //~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, + //~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings` let x1 = 1i64; x1 as f32; + //~^ ERROR: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, x1 as f64; + //~^ ERROR: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, let x2 = 1u32; x2 as f32; + //~^ ERROR: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, let x3 = 1u64; x3 as f32; + //~^ ERROR: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, x3 as f64; + //~^ ERROR: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, // Test clippy::cast_possible_truncation 1f32 as i32; + //~^ ERROR: casting `f32` to `i32` may truncate the value 1f32 as u32; + //~^ ERROR: casting `f32` to `u32` may truncate the value + //~| ERROR: casting `f32` to `u32` may lose the sign of the value + //~| NOTE: `-D clippy::cast-sign-loss` implied by `-D warnings` 1f64 as f32; + //~^ ERROR: casting `f64` to `f32` may truncate the value 1i32 as i8; + //~^ ERROR: casting `i32` to `i8` may truncate the value 1i32 as u8; + //~^ ERROR: casting `i32` to `u8` may truncate the value 1f64 as isize; + //~^ ERROR: casting `f64` to `isize` may truncate the value 1f64 as usize; + //~^ ERROR: casting `f64` to `usize` may truncate the value + //~| ERROR: casting `f64` to `usize` may lose the sign of the value 1f32 as u32 as u16; + //~^ ERROR: casting `u32` to `u16` may truncate the value + //~| ERROR: casting `f32` to `u32` may truncate the value + //~| ERROR: casting `f32` to `u32` may lose the sign of the value { let _x: i8 = 1i32 as _; + //~^ ERROR: casting `i32` to `i8` may truncate the value 1f32 as i32; + //~^ ERROR: casting `f32` to `i32` may truncate the value 1f64 as i32; + //~^ ERROR: casting `f64` to `i32` may truncate the value 1f32 as u8; + //~^ ERROR: casting `f32` to `u8` may truncate the value + //~| ERROR: casting `f32` to `u8` may lose the sign of the value } // Test clippy::cast_possible_wrap 1u8 as i8; + //~^ ERROR: casting `u8` to `i8` may wrap around the value + //~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings` 1u16 as i16; + //~^ ERROR: casting `u16` to `i16` may wrap around the value 1u32 as i32; + //~^ ERROR: casting `u32` to `i32` may wrap around the value 1u64 as i64; + //~^ ERROR: casting `u64` to `i64` may wrap around the value 1usize as isize; + //~^ ERROR: casting `usize` to `isize` may wrap around the value // should not wrap, usize is never 8 bits 1usize as i8; + //~^ ERROR: casting `usize` to `i8` may truncate the value // wraps on 16 bit ptr size 1usize as i16; + //~^ ERROR: casting `usize` to `i16` may truncate the value + //~| ERROR: casting `usize` to `i16` may wrap around the value on targets with 16-bit + //~| NOTE: `usize` and `isize` may be as small as 16 bits on some platforms // wraps on 32 bit ptr size 1usize as i32; + //~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid + //~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit // wraps on 64 bit ptr size 1usize as i64; + //~^ ERROR: casting `usize` to `i64` may wrap around the value on targets with 64-bit // should not wrap, isize is never 8 bits 1u8 as isize; // wraps on 16 bit ptr size 1u16 as isize; + //~^ ERROR: casting `u16` to `isize` may wrap around the value on targets with 16-bit + //~| NOTE: `usize` and `isize` may be as small as 16 bits on some platforms // wraps on 32 bit ptr size 1u32 as isize; + //~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit // wraps on 64 bit ptr size 1u64 as isize; + //~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid + //~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit // Test clippy::cast_sign_loss 1i32 as u32; -1i32 as u32; + //~^ ERROR: casting `i32` to `u32` may lose the sign of the value 1isize as usize; -1isize as usize; + //~^ ERROR: casting `isize` to `usize` may lose the sign of the value 0i8 as u8; i8::MAX as u8; i16::MAX as u16; @@ -132,6 +177,7 @@ fn main() { // Test for signed min // should be linted because signed (-99999999999i64).min(1) as i8; + //~^ ERROR: casting `i64` to `i8` may truncate the value // Test for various operations that remove enough bits for the result to fit (999999u64 & 1) as u8; @@ -145,6 +191,7 @@ fn main() { 999999u64.clamp(0, 255) as u8; // should still be linted 999999u64.clamp(0, 256) as u8; + //~^ ERROR: casting `u64` to `u8` may truncate the value #[derive(Clone, Copy)] enum E1 { @@ -167,7 +214,10 @@ fn main() { impl E2 { fn test(self) { let _ = self as u8; + //~^ ERROR: casting `main::E2` to `u8` may truncate the value let _ = Self::B as u8; + //~^ ERROR: casting `main::E2::B` to `u8` will truncate the value + //~| NOTE: `-D clippy::cast-enum-truncation` implied by `-D warnings` // Don't lint. `255..=256` fits in i16 let _ = self as i16; // Don't lint. @@ -208,7 +258,9 @@ fn main() { impl E5 { fn test(self) { let _ = self as i8; + //~^ ERROR: casting `main::E5` to `i8` may truncate the value let _ = Self::A as i8; + //~^ ERROR: casting `main::E5::A` to `i8` will truncate the value // Don't lint. `-129..=127` fits in i16 let _ = self as i16; // Don't lint. @@ -225,6 +277,7 @@ fn main() { impl E6 { fn test(self) { let _ = self as i16; + //~^ ERROR: casting `main::E6` to `i16` may truncate the value // Don't lint. `2^16-1` fits in u16 let _ = Self::A as u16; // Don't lint. `2^16-1..=2^16` fits in u32 @@ -243,6 +296,7 @@ fn main() { impl E7 { fn test(self) { let _ = self as usize; + //~^ ERROR: casting `main::E7` to `usize` may truncate the value on targets wi // Don't lint. let _ = Self::A as usize; // Don't lint. `2^32-1..=2^32` fits in u64 @@ -289,6 +343,7 @@ fn main() { impl E10 { fn test(self) { let _ = self as u16; + //~^ ERROR: casting `main::E10` to `u16` may truncate the value // Don't lint. let _ = Self::B as u32; // Don't lint. @@ -299,8 +354,10 @@ fn main() { fn avoid_subtract_overflow(q: u32) { let c = (q >> 16) as u8; + //~^ ERROR: casting `u32` to `u8` may truncate the value c as usize; let c = (q / 1000) as u8; + //~^ ERROR: casting `u32` to `u8` may truncate the value c as usize; } diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr index f0630743aa75c..5442ef5db16d2 100644 --- a/tests/ui/cast.stderr +++ b/tests/ui/cast.stderr @@ -7,37 +7,37 @@ LL | x0 as f32; = note: `-D clippy::cast-precision-loss` implied by `-D warnings` error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:18:5 + --> $DIR/cast.rs:20:5 | LL | x1 as f32; | ^^^^^^^^^ error: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast.rs:19:5 + --> $DIR/cast.rs:22:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:21:5 + --> $DIR/cast.rs:25:5 | LL | x2 as f32; | ^^^^^^^^^ error: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:23:5 + --> $DIR/cast.rs:28:5 | LL | x3 as f32; | ^^^^^^^^^ error: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast.rs:24:5 + --> $DIR/cast.rs:30:5 | LL | x3 as f64; | ^^^^^^^^^ error: casting `f32` to `i32` may truncate the value - --> $DIR/cast.rs:26:5 + --> $DIR/cast.rs:33:5 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL | 1f32 as i32; = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` error: casting `f32` to `u32` may truncate the value - --> $DIR/cast.rs:27:5 + --> $DIR/cast.rs:35:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | 1f32 as u32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:27:5 + --> $DIR/cast.rs:35:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL | 1f32 as u32; = note: `-D clippy::cast-sign-loss` implied by `-D warnings` error: casting `f64` to `f32` may truncate the value - --> $DIR/cast.rs:28:5 + --> $DIR/cast.rs:39:5 | LL | 1f64 as f32; | ^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | 1f64 as f32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `i32` to `i8` may truncate the value - --> $DIR/cast.rs:29:5 + --> $DIR/cast.rs:41:5 | LL | 1i32 as i8; | ^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | i8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u8` may truncate the value - --> $DIR/cast.rs:30:5 + --> $DIR/cast.rs:43:5 | LL | 1i32 as u8; | ^^^^^^^^^^ @@ -94,7 +94,7 @@ LL | u8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `f64` to `isize` may truncate the value - --> $DIR/cast.rs:31:5 + --> $DIR/cast.rs:45:5 | LL | 1f64 as isize; | ^^^^^^^^^^^^^ @@ -102,7 +102,7 @@ LL | 1f64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may truncate the value - --> $DIR/cast.rs:32:5 + --> $DIR/cast.rs:47:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ @@ -110,13 +110,13 @@ LL | 1f64 as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may lose the sign of the value - --> $DIR/cast.rs:32:5 + --> $DIR/cast.rs:47:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ error: casting `u32` to `u16` may truncate the value - --> $DIR/cast.rs:33:5 + --> $DIR/cast.rs:50:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^^^^^^^^ @@ -128,7 +128,7 @@ LL | u16::try_from(1f32 as u32); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `f32` to `u32` may truncate the value - --> $DIR/cast.rs:33:5 + --> $DIR/cast.rs:50:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ @@ -136,13 +136,13 @@ LL | 1f32 as u32 as u16; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:33:5 + --> $DIR/cast.rs:50:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ error: casting `i32` to `i8` may truncate the value - --> $DIR/cast.rs:35:22 + --> $DIR/cast.rs:55:22 | LL | let _x: i8 = 1i32 as _; | ^^^^^^^^^ @@ -154,7 +154,7 @@ LL | let _x: i8 = 1i32.try_into(); | ~~~~~~~~~~~~~~~ error: casting `f32` to `i32` may truncate the value - --> $DIR/cast.rs:36:9 + --> $DIR/cast.rs:57:9 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -162,7 +162,7 @@ LL | 1f32 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `i32` may truncate the value - --> $DIR/cast.rs:37:9 + --> $DIR/cast.rs:59:9 | LL | 1f64 as i32; | ^^^^^^^^^^^ @@ -170,7 +170,7 @@ LL | 1f64 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may truncate the value - --> $DIR/cast.rs:38:9 + --> $DIR/cast.rs:61:9 | LL | 1f32 as u8; | ^^^^^^^^^^ @@ -178,13 +178,13 @@ LL | 1f32 as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may lose the sign of the value - --> $DIR/cast.rs:38:9 + --> $DIR/cast.rs:61:9 | LL | 1f32 as u8; | ^^^^^^^^^^ error: casting `u8` to `i8` may wrap around the value - --> $DIR/cast.rs:41:5 + --> $DIR/cast.rs:66:5 | LL | 1u8 as i8; | ^^^^^^^^^ @@ -192,31 +192,31 @@ LL | 1u8 as i8; = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` error: casting `u16` to `i16` may wrap around the value - --> $DIR/cast.rs:42:5 + --> $DIR/cast.rs:69:5 | LL | 1u16 as i16; | ^^^^^^^^^^^ error: casting `u32` to `i32` may wrap around the value - --> $DIR/cast.rs:43:5 + --> $DIR/cast.rs:71:5 | LL | 1u32 as i32; | ^^^^^^^^^^^ error: casting `u64` to `i64` may wrap around the value - --> $DIR/cast.rs:44:5 + --> $DIR/cast.rs:73:5 | LL | 1u64 as i64; | ^^^^^^^^^^^ error: casting `usize` to `isize` may wrap around the value - --> $DIR/cast.rs:45:5 + --> $DIR/cast.rs:75:5 | LL | 1usize as isize; | ^^^^^^^^^^^^^^^ error: casting `usize` to `i8` may truncate the value - --> $DIR/cast.rs:47:5 + --> $DIR/cast.rs:78:5 | LL | 1usize as i8; | ^^^^^^^^^^^^ @@ -228,7 +228,7 @@ LL | i8::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may truncate the value - --> $DIR/cast.rs:49:5 + --> $DIR/cast.rs:81:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL | i16::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:49:5 + --> $DIR/cast.rs:81:5 | LL | 1usize as i16; | ^^^^^^^^^^^^^ @@ -249,7 +249,7 @@ LL | 1usize as i16; = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:86:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -261,19 +261,19 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:86:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:53:5 + --> $DIR/cast.rs:90:5 | LL | 1usize as i64; | ^^^^^^^^^^^^^ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:57:5 + --> $DIR/cast.rs:95:5 | LL | 1u16 as isize; | ^^^^^^^^^^^^^ @@ -282,13 +282,13 @@ LL | 1u16 as isize; = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:59:5 + --> $DIR/cast.rs:99:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:61:5 + --> $DIR/cast.rs:102:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -300,25 +300,25 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:61:5 + --> $DIR/cast.rs:102:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:64:5 + --> $DIR/cast.rs:107:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> $DIR/cast.rs:66:5 + --> $DIR/cast.rs:110:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> $DIR/cast.rs:134:5 + --> $DIR/cast.rs:179:5 | LL | (-99999999999i64).min(1) as i8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -330,7 +330,7 @@ LL | i8::try_from((-99999999999i64).min(1)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> $DIR/cast.rs:147:5 + --> $DIR/cast.rs:193:5 | LL | 999999u64.clamp(0, 256) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -342,7 +342,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E2` to `u8` may truncate the value - --> $DIR/cast.rs:169:21 + --> $DIR/cast.rs:216:21 | LL | let _ = self as u8; | ^^^^^^^^^^ @@ -354,7 +354,7 @@ LL | let _ = u8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E2::B` to `u8` will truncate the value - --> $DIR/cast.rs:170:21 + --> $DIR/cast.rs:218:21 | LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ @@ -362,7 +362,7 @@ LL | let _ = Self::B as u8; = note: `-D clippy::cast-enum-truncation` implied by `-D warnings` error: casting `main::E5` to `i8` may truncate the value - --> $DIR/cast.rs:210:21 + --> $DIR/cast.rs:260:21 | LL | let _ = self as i8; | ^^^^^^^^^^ @@ -374,13 +374,13 @@ LL | let _ = i8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E5::A` to `i8` will truncate the value - --> $DIR/cast.rs:211:21 + --> $DIR/cast.rs:262:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> $DIR/cast.rs:227:21 + --> $DIR/cast.rs:279:21 | LL | let _ = self as i16; | ^^^^^^^^^^^ @@ -392,7 +392,7 @@ LL | let _ = i16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:245:21 + --> $DIR/cast.rs:298:21 | LL | let _ = self as usize; | ^^^^^^^^^^^^^ @@ -404,7 +404,7 @@ LL | let _ = usize::try_from(self); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E10` to `u16` may truncate the value - --> $DIR/cast.rs:291:21 + --> $DIR/cast.rs:345:21 | LL | let _ = self as u16; | ^^^^^^^^^^^ @@ -416,7 +416,7 @@ LL | let _ = u16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:301:13 + --> $DIR/cast.rs:356:13 | LL | let c = (q >> 16) as u8; | ^^^^^^^^^^^^^^^ @@ -428,7 +428,7 @@ LL | let c = u8::try_from(q >> 16); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:304:13 + --> $DIR/cast.rs:360:13 | LL | let c = (q / 1000) as u8; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_alignment.rs b/tests/ui/cast_alignment.rs index 95bb883df1bf1..98ef5e36f9488 100644 --- a/tests/ui/cast_alignment.rs +++ b/tests/ui/cast_alignment.rs @@ -17,11 +17,16 @@ fn main() { // cast to more-strictly-aligned type (&1u8 as *const u8) as *const u16; + //~^ ERROR: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) + //~| NOTE: `-D clippy::cast-ptr-alignment` implied by `-D warnings` (&mut 1u8 as *mut u8) as *mut u16; + //~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 // cast to more-strictly-aligned type, but with the `pointer::cast` function. (&1u8 as *const u8).cast::(); + //~^ ERROR: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) (&mut 1u8 as *mut u8).cast::(); + //~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 /* These should be ok */ diff --git a/tests/ui/cast_alignment.stderr b/tests/ui/cast_alignment.stderr index 5df2b5b1094be..70510eaf6345a 100644 --- a/tests/ui/cast_alignment.stderr +++ b/tests/ui/cast_alignment.stderr @@ -7,19 +7,19 @@ LL | (&1u8 as *const u8) as *const u16; = note: `-D clippy::cast-ptr-alignment` implied by `-D warnings` error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) - --> $DIR/cast_alignment.rs:20:5 + --> $DIR/cast_alignment.rs:22:5 | LL | (&mut 1u8 as *mut u8) as *mut u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) (1 < 2 bytes) - --> $DIR/cast_alignment.rs:23:5 + --> $DIR/cast_alignment.rs:26:5 | LL | (&1u8 as *const u8).cast::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) - --> $DIR/cast_alignment.rs:24:5 + --> $DIR/cast_alignment.rs:28:5 | LL | (&mut 1u8 as *mut u8).cast::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_enum_constructor.rs b/tests/ui/cast_enum_constructor.rs index 0193454ad144c..3226f487b3aff 100644 --- a/tests/ui/cast_enum_constructor.rs +++ b/tests/ui/cast_enum_constructor.rs @@ -11,7 +11,10 @@ fn main() { } let _ = Foo::Y as usize; + //~^ ERROR: cast of an enum tuple constructor to an integer + //~| NOTE: `-D clippy::cast-enum-constructor` implied by `-D warnings` let _ = Foo::Y as isize; + //~^ ERROR: cast of an enum tuple constructor to an integer let _ = Foo::Y as fn(u32) -> Foo; let _ = Bar::X as usize; } diff --git a/tests/ui/cast_enum_constructor.stderr b/tests/ui/cast_enum_constructor.stderr index 710909dd26fa8..f0489f08f9105 100644 --- a/tests/ui/cast_enum_constructor.stderr +++ b/tests/ui/cast_enum_constructor.stderr @@ -7,7 +7,7 @@ LL | let _ = Foo::Y as usize; = note: `-D clippy::cast-enum-constructor` implied by `-D warnings` error: cast of an enum tuple constructor to an integer - --> $DIR/cast_enum_constructor.rs:14:13 + --> $DIR/cast_enum_constructor.rs:16:13 | LL | let _ = Foo::Y as isize; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_nan_to_int.rs b/tests/ui/cast_nan_to_int.rs index 287c5aa216bd3..2d7467ff0400d 100644 --- a/tests/ui/cast_nan_to_int.rs +++ b/tests/ui/cast_nan_to_int.rs @@ -3,12 +3,24 @@ fn main() { let _ = (0.0_f32 / -0.0) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f64::INFINITY * -0.0) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (0.0 * f32::INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f32::INFINITY - f32::INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 // those won't be linted: let _ = (1.0_f32 / 0.0) as usize; diff --git a/tests/ui/cast_nan_to_int.stderr b/tests/ui/cast_nan_to_int.stderr index 3539be75a19db..678db89954e51 100644 --- a/tests/ui/cast_nan_to_int.stderr +++ b/tests/ui/cast_nan_to_int.stderr @@ -8,7 +8,7 @@ LL | let _ = (0.0_f32 / -0.0) as usize; = note: `-D clippy::cast-nan-to-int` implied by `-D warnings` error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:6:13 + --> $DIR/cast_nan_to_int.rs:8:13 | LL | let _ = (f64::INFINITY * -0.0) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = (f64::INFINITY * -0.0) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:7:13 + --> $DIR/cast_nan_to_int.rs:11:13 | LL | let _ = (0.0 * f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let _ = (0.0 * f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:9:13 + --> $DIR/cast_nan_to_int.rs:15:13 | LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:10:13 + --> $DIR/cast_nan_to_int.rs:18:13 | LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:11:13 + --> $DIR/cast_nan_to_int.rs:21:13 | LL | let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size.rs b/tests/ui/cast_size.rs index 4d4341ab55cf3..95626b20b27bf 100644 --- a/tests/ui/cast_size.rs +++ b/tests/ui/cast_size.rs @@ -10,27 +10,47 @@ fn main() { // Casting from *size 1isize as i8; + //~^ ERROR: casting `isize` to `i8` may truncate the value let x0 = 1isize; let x1 = 1usize; x0 as f64; + //~^ ERROR: casting `isize` to `f64` causes a loss of precision on targets with 64-bit + //~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings` x1 as f64; + //~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit x0 as f32; + //~^ ERROR: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 b x1 as f32; + //~^ ERROR: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 b 1isize as i32; + //~^ ERROR: casting `isize` to `i32` may truncate the value on targets with 64-bit wid 1isize as u32; + //~^ ERROR: casting `isize` to `u32` may truncate the value on targets with 64-bit wid 1usize as u32; + //~^ ERROR: casting `usize` to `u32` may truncate the value on targets with 64-bit wid 1usize as i32; + //~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid + //~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit + //~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings` // Casting to *size 1i64 as isize; + //~^ ERROR: casting `i64` to `isize` may truncate the value on targets with 32-bit wid 1i64 as usize; + //~^ ERROR: casting `i64` to `usize` may truncate the value on targets with 32-bit wid 1u64 as isize; + //~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid + //~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit 1u64 as usize; + //~^ ERROR: casting `u64` to `usize` may truncate the value on targets with 32-bit wid 1u32 as isize; + //~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit 1u32 as usize; // Should not trigger any lint 1i32 as isize; // Neither should this 1i32 as usize; // Big integer literal to float 999_999_999 as f32; + //~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, 9_999_999_999_999_999usize as f64; + //~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit } //@no-rustfix diff --git a/tests/ui/cast_size.stderr b/tests/ui/cast_size.stderr index 6d2d49d9ed208..6c7459b3abaee 100644 --- a/tests/ui/cast_size.stderr +++ b/tests/ui/cast_size.stderr @@ -12,7 +12,7 @@ LL | i8::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:15:5 + --> $DIR/cast_size.rs:16:5 | LL | x0 as f64; | ^^^^^^^^^ @@ -20,25 +20,25 @@ LL | x0 as f64; = note: `-D clippy::cast-precision-loss` implied by `-D warnings` error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:16:5 + --> $DIR/cast_size.rs:19:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:17:5 + --> $DIR/cast_size.rs:21:5 | LL | x0 as f32; | ^^^^^^^^^ error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:18:5 + --> $DIR/cast_size.rs:23:5 | LL | x1 as f32; | ^^^^^^^^^ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:19:5 + --> $DIR/cast_size.rs:25:5 | LL | 1isize as i32; | ^^^^^^^^^^^^^ @@ -50,7 +50,7 @@ LL | i32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:20:5 + --> $DIR/cast_size.rs:27:5 | LL | 1isize as u32; | ^^^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL | u32::try_from(1isize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:21:5 + --> $DIR/cast_size.rs:29:5 | LL | 1usize as u32; | ^^^^^^^^^^^^^ @@ -74,7 +74,7 @@ LL | u32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:22:5 + --> $DIR/cast_size.rs:31:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:22:5 + --> $DIR/cast_size.rs:31:5 | LL | 1usize as i32; | ^^^^^^^^^^^^^ @@ -94,7 +94,7 @@ LL | 1usize as i32; = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:24:5 + --> $DIR/cast_size.rs:36:5 | LL | 1i64 as isize; | ^^^^^^^^^^^^^ @@ -106,7 +106,7 @@ LL | isize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:25:5 + --> $DIR/cast_size.rs:38:5 | LL | 1i64 as usize; | ^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL | usize::try_from(1i64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:26:5 + --> $DIR/cast_size.rs:40:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ @@ -130,13 +130,13 @@ LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:26:5 + --> $DIR/cast_size.rs:40:5 | LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:27:5 + --> $DIR/cast_size.rs:43:5 | LL | 1u64 as usize; | ^^^^^^^^^^^^^ @@ -148,19 +148,19 @@ LL | usize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:28:5 + --> $DIR/cast_size.rs:45:5 | LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:33:5 + --> $DIR/cast_size.rs:51:5 | LL | 999_999_999 as f32; | ^^^^^^^^^^^^^^^^^^ error: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:34:5 + --> $DIR/cast_size.rs:53:5 | LL | 9_999_999_999_999_999usize as f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cast_size_32bit.rs b/tests/ui/cast_size_32bit.rs index 7ca20d3ca4a76..5a06e34bdb8fb 100644 --- a/tests/ui/cast_size_32bit.rs +++ b/tests/ui/cast_size_32bit.rs @@ -10,26 +10,47 @@ fn main() { // Casting from *size 1isize as i8; + //~^ ERROR: casting `isize` to `i8` may truncate the value let x0 = 1isize; let x1 = 1usize; x0 as f64; + //~^ ERROR: casting `isize` to `f64` causes a loss of precision on targets with 64-bit + //~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings` x1 as f64; + //~^ ERROR: casting `usize` to `f64` causes a loss of precision on targets with 64-bit x0 as f32; + //~^ ERROR: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 b x1 as f32; + //~^ ERROR: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 b 1isize as i32; + //~^ ERROR: casting `isize` to `i32` may truncate the value on targets with 64-bit wid 1isize as u32; + //~^ ERROR: casting `isize` to `u32` may truncate the value on targets with 64-bit wid 1usize as u32; + //~^ ERROR: casting `usize` to `u32` may truncate the value on targets with 64-bit wid 1usize as i32; + //~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid + //~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit + //~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings` // Casting to *size 1i64 as isize; + //~^ ERROR: casting `i64` to `isize` may truncate the value on targets with 32-bit wid 1i64 as usize; + //~^ ERROR: casting `i64` to `usize` may truncate the value on targets with 32-bit wid 1u64 as isize; + //~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid + //~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit 1u64 as usize; + //~^ ERROR: casting `u64` to `usize` may truncate the value on targets with 32-bit wid 1u32 as isize; + //~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit 1u32 as usize; // Should not trigger any lint 1i32 as isize; // Neither should this 1i32 as usize; // Big integer literal to float 999_999_999 as f32; + //~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, 3_999_999_999usize as f64; + //~^ ERROR: casting integer literal to `f64` is unnecessary + //~| NOTE: `-D clippy::unnecessary-cast` implied by `-D warnings` } diff --git a/tests/ui/cast_slice_different_sizes.rs b/tests/ui/cast_slice_different_sizes.rs index 6d2f99b7db5d2..d8101030a8a2d 100644 --- a/tests/ui/cast_slice_different_sizes.rs +++ b/tests/ui/cast_slice_different_sizes.rs @@ -8,10 +8,14 @@ fn main() { // Because it's separate, it does not check the cast back to something of the same size let a = r_x as *const [i32]; let b = a as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme + //~| NOTE: `#[deny(clippy::cast_slice_different_sizes)]` on by default let c = b as *const [u32]; + //~^ ERROR: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (eleme // loses data let loss = r_x as *const [i32] as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme // Cast back to same size but different type loses no data, just type conversion // This is weird code but there's no reason for this lint specifically to fire *twice* on it @@ -19,7 +23,9 @@ fn main() { // Check casting through blocks is detected let loss_block_1 = { r_x as *const [i32] } as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme let loss_block_2 = { + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme let _ = (); r_x as *const [i32] } as *const [u8]; @@ -37,6 +43,7 @@ fn main() { // Check that the result of a long chain of casts is detected let long_chain_loss = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme let long_chain_restore = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8] as *const [u32]; } @@ -52,32 +59,40 @@ fn foo2(x: *mut [u8]) -> *mut [u8] { // Test that casts as part of function returns work fn bar(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as *mut [u8] } fn uwu(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as *mut _ } fn bar2(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as _ } // constify fn bar3(x: *mut [u16]) -> *const [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as _ } // unconstify fn bar4(x: *const [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as _ } // function returns plus blocks fn blocks(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s ({ x }) as _ } fn more_blocks(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s { ({ x }) as _ } + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (eleme } diff --git a/tests/ui/cast_slice_different_sizes.stderr b/tests/ui/cast_slice_different_sizes.stderr index cd2cdfff32582..a5c38e310f67a 100644 --- a/tests/ui/cast_slice_different_sizes.stderr +++ b/tests/ui/cast_slice_different_sizes.stderr @@ -7,28 +7,29 @@ LL | let b = a as *const [u8]; = note: `#[deny(clippy::cast_slice_different_sizes)]` on by default error: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (element size 4) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:11:13 + --> $DIR/cast_slice_different_sizes.rs:13:13 | LL | let c = b as *const [u32]; | ^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(b as *const u32, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:14:16 + --> $DIR/cast_slice_different_sizes.rs:17:16 | LL | let loss = r_x as *const [i32] as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:21:24 + --> $DIR/cast_slice_different_sizes.rs:25:24 | LL | let loss_block_1 = { r_x as *const [i32] } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts({ r_x as *const [i32] } as *const u8, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:22:24 + --> $DIR/cast_slice_different_sizes.rs:27:24 | LL | let loss_block_2 = { | ________________________^ +LL | | LL | | let _ = (); LL | | r_x as *const [i32] LL | | } as *const [u8]; @@ -37,82 +38,91 @@ LL | | } as *const [u8]; help: replace with `ptr::slice_from_raw_parts` | LL ~ let loss_block_2 = core::ptr::slice_from_raw_parts({ +LL + LL + let _ = (); LL + r_x as *const [i32] LL ~ } as *const u8, ..); | error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:39:27 + --> $DIR/cast_slice_different_sizes.rs:45:27 | LL | let long_chain_loss = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:54:36 + --> $DIR/cast_slice_different_sizes.rs:61:36 | LL | fn bar(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ +LL | | LL | | x as *mut [u8] LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:58:36 + --> $DIR/cast_slice_different_sizes.rs:66:36 | LL | fn uwu(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ +LL | | LL | | x as *mut _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:62:37 + --> $DIR/cast_slice_different_sizes.rs:71:37 | LL | fn bar2(x: *mut [u16]) -> *mut [u8] { | _____________________________________^ +LL | | LL | | x as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:67:39 + --> $DIR/cast_slice_different_sizes.rs:77:39 | LL | fn bar3(x: *mut [u16]) -> *const [u8] { | _______________________________________^ +LL | | LL | | x as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(x as *const u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:72:39 + --> $DIR/cast_slice_different_sizes.rs:83:39 | LL | fn bar4(x: *const [u16]) -> *mut [u8] { | _______________________________________^ +LL | | LL | | x as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:77:39 + --> $DIR/cast_slice_different_sizes.rs:89:39 | LL | fn blocks(x: *mut [u16]) -> *mut [u8] { | _______________________________________^ +LL | | LL | | ({ x }) as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:81:44 + --> $DIR/cast_slice_different_sizes.rs:94:44 | LL | fn more_blocks(x: *mut [u16]) -> *mut [u8] { | ____________________________________________^ +LL | | LL | | { ({ x }) as _ } +LL | | LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:82:5 + --> $DIR/cast_slice_different_sizes.rs:96:5 | LL | { ({ x }) as _ } | ^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` diff --git a/tests/ui/cfg_features.fixed b/tests/ui/cfg_features.fixed index c3e570698d7dc..3d52f2382ea72 100644 --- a/tests/ui/cfg_features.fixed +++ b/tests/ui/cfg_features.fixed @@ -2,11 +2,16 @@ fn main() { #[cfg(feature = "not-really-a-feature")] + //~^ ERROR: feature may misspelled as features + //~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings` let _ = 1 + 2; #[cfg(all(feature = "right", feature = "wrong"))] + //~^ ERROR: feature may misspelled as features let _ = 1 + 2; #[cfg(all(feature = "wrong1", any(feature = "right", feature = "wrong2", feature, features)))] + //~^ ERROR: feature may misspelled as features + //~| ERROR: feature may misspelled as features let _ = 1 + 2; } diff --git a/tests/ui/cfg_features.rs b/tests/ui/cfg_features.rs index bc4109c2c8964..a0344a0044799 100644 --- a/tests/ui/cfg_features.rs +++ b/tests/ui/cfg_features.rs @@ -2,11 +2,16 @@ fn main() { #[cfg(features = "not-really-a-feature")] + //~^ ERROR: feature may misspelled as features + //~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings` let _ = 1 + 2; #[cfg(all(feature = "right", features = "wrong"))] + //~^ ERROR: feature may misspelled as features let _ = 1 + 2; #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] + //~^ ERROR: feature may misspelled as features + //~| ERROR: feature may misspelled as features let _ = 1 + 2; } diff --git a/tests/ui/cfg_features.stderr b/tests/ui/cfg_features.stderr index 00405985d48c7..5f92dfe169c72 100644 --- a/tests/ui/cfg_features.stderr +++ b/tests/ui/cfg_features.stderr @@ -7,19 +7,19 @@ LL | #[cfg(features = "not-really-a-feature")] = note: `-D clippy::maybe-misused-cfg` implied by `-D warnings` error: feature may misspelled as features - --> $DIR/cfg_features.rs:7:34 + --> $DIR/cfg_features.rs:9:34 | LL | #[cfg(all(feature = "right", features = "wrong"))] | ^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong"` error: feature may misspelled as features - --> $DIR/cfg_features.rs:10:15 + --> $DIR/cfg_features.rs:13:15 | LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] | ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong1"` error: feature may misspelled as features - --> $DIR/cfg_features.rs:10:59 + --> $DIR/cfg_features.rs:13:59 | LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] | ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong2"` diff --git a/tests/ui/char_lit_as_u8.rs b/tests/ui/char_lit_as_u8.rs index e724c456b8883..7bb3daf0f1e72 100644 --- a/tests/ui/char_lit_as_u8.rs +++ b/tests/ui/char_lit_as_u8.rs @@ -3,4 +3,6 @@ fn main() { // no suggestion, since a byte literal won't work. let _ = '❤' as u8; + //~^ ERROR: casting a character literal to `u8` truncates + //~| NOTE: `char` is four bytes wide, but `u8` is a single byte } diff --git a/tests/ui/checked_unwrap/complex_conditionals.rs b/tests/ui/checked_unwrap/complex_conditionals.rs index 9e618350b1982..323dae380633d 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.rs +++ b/tests/ui/checked_unwrap/complex_conditionals.rs @@ -11,12 +11,16 @@ fn test_complex_conditions() { if x.is_ok() && y.is_err() { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` // will panic x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic // will panic y.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary y.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_err` } else { // not statically determinable whether any of the following will always succeed or always fail: x.unwrap(); @@ -32,27 +36,37 @@ fn test_complex_conditions() { } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` // will panic y.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary y.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok` } let z: Result<(), ()> = Ok(()); if x.is_ok() && !(y.is_ok() || z.is_err()) { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` // will panic x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic // will panic y.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary y.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok` // unnecessary z.unwrap(); + //~^ ERROR: called `unwrap` on `z` after checking its variant with `is_err` // will panic z.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic } if x.is_ok() || !(y.is_ok() && z.is_err()) { // not statically determinable whether any of the following will always succeed or always fail: @@ -62,16 +76,22 @@ fn test_complex_conditions() { } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` // unnecessary y.unwrap(); + //~^ ERROR: called `unwrap` on `y` after checking its variant with `is_ok` // will panic y.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic // will panic z.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary z.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `z` after checking its variant with `is_err` } } diff --git a/tests/ui/checked_unwrap/complex_conditionals.stderr b/tests/ui/checked_unwrap/complex_conditionals.stderr index f342815ac76ba..73c074a93393f 100644 --- a/tests/ui/checked_unwrap/complex_conditionals.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals.stderr @@ -15,7 +15,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:15:9 + --> $DIR/complex_conditionals.rs:16:9 | LL | if x.is_ok() && y.is_err() { | --------- because of this check @@ -30,7 +30,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:17:9 + --> $DIR/complex_conditionals.rs:19:9 | LL | if x.is_ok() && y.is_err() { | ---------- because of this check @@ -39,7 +39,7 @@ LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:19:9 + --> $DIR/complex_conditionals.rs:22:9 | LL | if x.is_ok() && y.is_err() { | ---------- the check is happening here @@ -50,7 +50,7 @@ LL | y.unwrap_err(); = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:34:9 + --> $DIR/complex_conditionals.rs:38:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check @@ -59,7 +59,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:36:9 + --> $DIR/complex_conditionals.rs:41:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here @@ -70,7 +70,7 @@ LL | x.unwrap_err(); = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:38:9 + --> $DIR/complex_conditionals.rs:44:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check @@ -79,7 +79,7 @@ LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:40:9 + --> $DIR/complex_conditionals.rs:47:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here @@ -90,7 +90,7 @@ LL | y.unwrap_err(); = help: try using `if let` or `match` error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:45:9 + --> $DIR/complex_conditionals.rs:53:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here @@ -101,7 +101,7 @@ LL | x.unwrap(); = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:47:9 + --> $DIR/complex_conditionals.rs:56:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check @@ -110,7 +110,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:49:9 + --> $DIR/complex_conditionals.rs:59:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check @@ -119,7 +119,7 @@ LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:51:9 + --> $DIR/complex_conditionals.rs:62:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here @@ -130,7 +130,7 @@ LL | y.unwrap_err(); = help: try using `if let` or `match` error: called `unwrap` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:53:9 + --> $DIR/complex_conditionals.rs:65:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- the check is happening here @@ -141,7 +141,7 @@ LL | z.unwrap(); = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:55:9 + --> $DIR/complex_conditionals.rs:68:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- because of this check @@ -150,7 +150,7 @@ LL | z.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:64:9 + --> $DIR/complex_conditionals.rs:78:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check @@ -159,7 +159,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:66:9 + --> $DIR/complex_conditionals.rs:81:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here @@ -170,7 +170,7 @@ LL | x.unwrap_err(); = help: try using `if let` or `match` error: called `unwrap` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:68:9 + --> $DIR/complex_conditionals.rs:84:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here @@ -181,7 +181,7 @@ LL | y.unwrap(); = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:70:9 + --> $DIR/complex_conditionals.rs:87:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check @@ -190,7 +190,7 @@ LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:72:9 + --> $DIR/complex_conditionals.rs:90:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- because of this check @@ -199,7 +199,7 @@ LL | z.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:74:9 + --> $DIR/complex_conditionals.rs:93:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- the check is happening here diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.rs b/tests/ui/checked_unwrap/complex_conditionals_nested.rs index 1ee8d16565b5c..68923793dcdf9 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.rs +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.rs @@ -11,9 +11,11 @@ fn test_nested() { if x.is_some() { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some` } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic } } } diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr index bf7c6750ccfda..d9f701a5b2e00 100644 --- a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr @@ -14,7 +14,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals_nested.rs:16:13 + --> $DIR/complex_conditionals_nested.rs:17:13 | LL | if x.is_some() { | ----------- because of this check diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs index 12522ae5ba12c..e82e7bcb06cb0 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -45,20 +45,26 @@ fn main() { if x.is_some() { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some` // unnecessary x.expect("an error message"); + //~^ ERROR: called `expect` on `x` after checking its variant with `is_some` } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // will panic x.expect("an error message"); + //~^ ERROR: this call to `expect()` will always panic } if x.is_none() { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic } else { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_none` } m!(x); // ok @@ -71,28 +77,38 @@ fn main() { if x.is_ok() { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` // unnecessary x.expect("an error message"); + //~^ ERROR: called `expect` on `x` after checking its variant with `is_ok` // will panic x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic } else { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // will panic x.expect("an error message"); + //~^ ERROR: this call to `expect()` will always panic // unnecessary x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` } if x.is_err() { // will panic x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic // unnecessary x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_err` } else { // unnecessary x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_err` // will panic x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic } if x.is_ok() { x = Err(()); diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr index 0c5a64979241f..ed603581ecddb 100644 --- a/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -14,7 +14,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:49:9 + --> $DIR/simple_conditionals.rs:50:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` @@ -23,7 +23,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:52:9 + --> $DIR/simple_conditionals.rs:54:9 | LL | if x.is_some() { | ----------- because of this check @@ -38,7 +38,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:54:9 + --> $DIR/simple_conditionals.rs:57:9 | LL | if x.is_some() { | ----------- because of this check @@ -47,7 +47,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:58:9 + --> $DIR/simple_conditionals.rs:62:9 | LL | if x.is_none() { | ----------- because of this check @@ -56,7 +56,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_none` - --> $DIR/simple_conditionals.rs:61:9 + --> $DIR/simple_conditionals.rs:66:9 | LL | if x.is_none() { | -------------- help: try: `if let Some(..) = x` @@ -79,7 +79,7 @@ LL | m!(x); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:73:9 + --> $DIR/simple_conditionals.rs:79:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` @@ -88,7 +88,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:75:9 + --> $DIR/simple_conditionals.rs:82:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` @@ -97,7 +97,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:77:9 + --> $DIR/simple_conditionals.rs:85:9 | LL | if x.is_ok() { | --------- because of this check @@ -106,7 +106,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:80:9 + --> $DIR/simple_conditionals.rs:89:9 | LL | if x.is_ok() { | --------- because of this check @@ -115,7 +115,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:82:9 + --> $DIR/simple_conditionals.rs:92:9 | LL | if x.is_ok() { | --------- because of this check @@ -124,7 +124,7 @@ LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:84:9 + --> $DIR/simple_conditionals.rs:95:9 | LL | if x.is_ok() { | ------------ help: try: `if let Err(..) = x` @@ -133,7 +133,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:88:9 + --> $DIR/simple_conditionals.rs:100:9 | LL | if x.is_err() { | ---------- because of this check @@ -142,7 +142,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:90:9 + --> $DIR/simple_conditionals.rs:103:9 | LL | if x.is_err() { | ------------- help: try: `if let Err(..) = x` @@ -151,7 +151,7 @@ LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:93:9 + --> $DIR/simple_conditionals.rs:107:9 | LL | if x.is_err() { | ------------- help: try: `if let Ok(..) = x` @@ -160,7 +160,7 @@ LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:95:9 + --> $DIR/simple_conditionals.rs:110:9 | LL | if x.is_err() { | ---------- because of this check diff --git a/tests/ui/cmp_null.rs b/tests/ui/cmp_null.rs index 2d2d04178c35d..ef1d93940aa6e 100644 --- a/tests/ui/cmp_null.rs +++ b/tests/ui/cmp_null.rs @@ -7,11 +7,14 @@ fn main() { let x = 0; let p: *const usize = &x; if p == ptr::null() { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~| NOTE: `-D clippy::cmp-null` implied by `-D warnings` println!("This is surprising!"); } let mut y = 0; let mut m: *mut usize = &mut y; if m == ptr::null_mut() { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method println!("This is surprising, too!"); } } diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr index a1f4c70fb2786..cc2ffb21b476b 100644 --- a/tests/ui/cmp_null.stderr +++ b/tests/ui/cmp_null.stderr @@ -7,7 +7,7 @@ LL | if p == ptr::null() { = note: `-D clippy::cmp-null` implied by `-D warnings` error: comparing with null is better expressed by the `.is_null()` method - --> $DIR/cmp_null.rs:14:8 + --> $DIR/cmp_null.rs:16:8 | LL | if m == ptr::null_mut() { | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/cmp_owned/without_suggestion.rs b/tests/ui/cmp_owned/without_suggestion.rs index d8a202cb6a1c6..ec45d635c1727 100644 --- a/tests/ui/cmp_owned/without_suggestion.rs +++ b/tests/ui/cmp_owned/without_suggestion.rs @@ -5,10 +5,13 @@ fn main() { let x = &Baz; let y = &Baz; y.to_owned() == *x; + //~^ ERROR: this creates an owned instance just for comparison + //~| NOTE: `-D clippy::cmp-owned` implied by `-D warnings` let x = &&Baz; let y = &Baz; y.to_owned() == **x; + //~^ ERROR: this creates an owned instance just for comparison let x = 0u32; let y = U32Wrapper(x); @@ -20,6 +23,7 @@ struct Foo; impl PartialEq for Foo { fn eq(&self, other: &Self) -> bool { self.to_owned() == *other + //~^ ERROR: this creates an owned instance just for comparison } } diff --git a/tests/ui/cmp_owned/without_suggestion.stderr b/tests/ui/cmp_owned/without_suggestion.stderr index d2dd14d8edbb8..fa7cb380eba18 100644 --- a/tests/ui/cmp_owned/without_suggestion.stderr +++ b/tests/ui/cmp_owned/without_suggestion.stderr @@ -7,13 +7,13 @@ LL | y.to_owned() == *x; = note: `-D clippy::cmp-owned` implied by `-D warnings` error: this creates an owned instance just for comparison - --> $DIR/without_suggestion.rs:11:5 + --> $DIR/without_suggestion.rs:13:5 | LL | y.to_owned() == **x; | ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating error: this creates an owned instance just for comparison - --> $DIR/without_suggestion.rs:22:9 + --> $DIR/without_suggestion.rs:25:9 | LL | self.to_owned() == *other | ^^^^^^^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating diff --git a/tests/ui/cognitive_complexity.rs b/tests/ui/cognitive_complexity.rs index 07bdaff00dc41..e8fd063a98f24 100644 --- a/tests/ui/cognitive_complexity.rs +++ b/tests/ui/cognitive_complexity.rs @@ -4,6 +4,7 @@ #[rustfmt::skip] fn main() { +//~^ ERROR: the function has a cognitive complexity of (28/25) if true { println!("a"); } @@ -89,6 +90,7 @@ fn main() { #[clippy::cognitive_complexity = "1"] fn kaboom() { + //~^ ERROR: the function has a cognitive complexity of (7/1) let n = 0; 'a: for i in 0..20 { 'b: for j in i..20 { @@ -147,7 +149,9 @@ fn lots_of_short_circuits2() -> bool { #[clippy::cognitive_complexity = "1"] fn baa() { + //~^ ERROR: the function has a cognitive complexity of (2/1) let x = || match 99 { + //~^ ERROR: the function has a cognitive complexity of (2/1) 0 => 0, 1 => 1, 2 => 2, @@ -165,6 +169,7 @@ fn baa() { #[clippy::cognitive_complexity = "1"] fn bar() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), _ => println!("bye"), @@ -176,6 +181,7 @@ fn bar() { /// Tests are usually complex but simple at the same time. `clippy::cognitive_complexity` used to /// give lots of false-positives in tests. fn dont_warn_on_tests() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), _ => println!("bye"), @@ -184,6 +190,7 @@ fn dont_warn_on_tests() { #[clippy::cognitive_complexity = "1"] fn barr() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -194,6 +201,7 @@ fn barr() { #[clippy::cognitive_complexity = "1"] fn barr2() { + //~^ ERROR: the function has a cognitive complexity of (3/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -210,6 +218,7 @@ fn barr2() { #[clippy::cognitive_complexity = "1"] fn barrr() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), 1 => panic!("bla"), @@ -220,6 +229,7 @@ fn barrr() { #[clippy::cognitive_complexity = "1"] fn barrr2() { + //~^ ERROR: the function has a cognitive complexity of (3/1) match 99 { 0 => println!("hi"), 1 => panic!("bla"), @@ -236,6 +246,7 @@ fn barrr2() { #[clippy::cognitive_complexity = "1"] fn barrrr() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -246,6 +257,7 @@ fn barrrr() { #[clippy::cognitive_complexity = "1"] fn barrrr2() { + //~^ ERROR: the function has a cognitive complexity of (3/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -262,6 +274,7 @@ fn barrrr2() { #[clippy::cognitive_complexity = "1"] fn cake() { + //~^ ERROR: the function has a cognitive complexity of (2/1) if 4 == 5 { println!("yea"); } else { @@ -272,6 +285,7 @@ fn cake() { #[clippy::cognitive_complexity = "1"] pub fn read_file(input_path: &str) -> String { + //~^ ERROR: the function has a cognitive complexity of (4/1) use std::fs::File; use std::io::{Read, Write}; use std::path::Path; @@ -303,6 +317,7 @@ enum Void {} #[clippy::cognitive_complexity = "1"] fn void(void: Void) { + //~^ ERROR: the function has a cognitive complexity of (2/1) if true { match void {} } @@ -354,6 +369,7 @@ fn early() -> Result { #[rustfmt::skip] #[clippy::cognitive_complexity = "1"] fn early_ret() -> i32 { +//~^ ERROR: the function has a cognitive complexity of (8/1) let a = if true { 42 } else { return 0; }; let a = if a < 99 { 42 } else { return 0; }; let a = if a < 99 { 42 } else { return 0; }; @@ -375,6 +391,7 @@ fn early_ret() -> i32 { #[clippy::cognitive_complexity = "1"] fn closures() { let x = |a: i32, b: i32| -> i32 { + //~^ ERROR: the function has a cognitive complexity of (2/1) if true { println!("moo"); } @@ -388,6 +405,7 @@ struct Moo; #[clippy::cognitive_complexity = "1"] impl Moo { fn moo(&self) { + //~^ ERROR: the function has a cognitive complexity of (2/1) if true { println!("moo"); } @@ -397,6 +415,7 @@ impl Moo { #[clippy::cognitive_complexity = "1"] mod issue9300 { async fn a() { + //~^ ERROR: the function has a cognitive complexity of (2/1) let a = 0; if a == 0 {} } @@ -404,6 +423,7 @@ mod issue9300 { pub struct S; impl S { pub async fn async_method() { + //~^ ERROR: the function has a cognitive complexity of (2/1) let a = 0; if a == 0 {} } diff --git a/tests/ui/cognitive_complexity.stderr b/tests/ui/cognitive_complexity.stderr index d867246301abd..a712b163b171c 100644 --- a/tests/ui/cognitive_complexity.stderr +++ b/tests/ui/cognitive_complexity.stderr @@ -8,7 +8,7 @@ LL | fn main() { = note: `-D clippy::cognitive-complexity` implied by `-D warnings` error: the function has a cognitive complexity of (7/1) - --> $DIR/cognitive_complexity.rs:91:4 + --> $DIR/cognitive_complexity.rs:92:4 | LL | fn kaboom() { | ^^^^^^ @@ -16,7 +16,7 @@ LL | fn kaboom() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:149:4 + --> $DIR/cognitive_complexity.rs:151:4 | LL | fn baa() { | ^^^ @@ -24,7 +24,7 @@ LL | fn baa() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:150:13 + --> $DIR/cognitive_complexity.rs:153:13 | LL | let x = || match 99 { | ^^ @@ -32,7 +32,7 @@ LL | let x = || match 99 { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:167:4 + --> $DIR/cognitive_complexity.rs:171:4 | LL | fn bar() { | ^^^ @@ -40,7 +40,7 @@ LL | fn bar() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:178:4 + --> $DIR/cognitive_complexity.rs:183:4 | LL | fn dont_warn_on_tests() { | ^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | fn dont_warn_on_tests() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:186:4 + --> $DIR/cognitive_complexity.rs:192:4 | LL | fn barr() { | ^^^^ @@ -56,7 +56,7 @@ LL | fn barr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> $DIR/cognitive_complexity.rs:196:4 + --> $DIR/cognitive_complexity.rs:203:4 | LL | fn barr2() { | ^^^^^ @@ -64,7 +64,7 @@ LL | fn barr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:212:4 + --> $DIR/cognitive_complexity.rs:220:4 | LL | fn barrr() { | ^^^^^ @@ -72,7 +72,7 @@ LL | fn barrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> $DIR/cognitive_complexity.rs:222:4 + --> $DIR/cognitive_complexity.rs:231:4 | LL | fn barrr2() { | ^^^^^^ @@ -80,7 +80,7 @@ LL | fn barrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:238:4 + --> $DIR/cognitive_complexity.rs:248:4 | LL | fn barrrr() { | ^^^^^^ @@ -88,7 +88,7 @@ LL | fn barrrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> $DIR/cognitive_complexity.rs:248:4 + --> $DIR/cognitive_complexity.rs:259:4 | LL | fn barrrr2() { | ^^^^^^^ @@ -96,7 +96,7 @@ LL | fn barrrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:264:4 + --> $DIR/cognitive_complexity.rs:276:4 | LL | fn cake() { | ^^^^ @@ -104,7 +104,7 @@ LL | fn cake() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (4/1) - --> $DIR/cognitive_complexity.rs:274:8 + --> $DIR/cognitive_complexity.rs:287:8 | LL | pub fn read_file(input_path: &str) -> String { | ^^^^^^^^^ @@ -112,7 +112,7 @@ LL | pub fn read_file(input_path: &str) -> String { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:305:4 + --> $DIR/cognitive_complexity.rs:319:4 | LL | fn void(void: Void) { | ^^^^ @@ -120,7 +120,7 @@ LL | fn void(void: Void) { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (8/1) - --> $DIR/cognitive_complexity.rs:356:4 + --> $DIR/cognitive_complexity.rs:371:4 | LL | fn early_ret() -> i32 { | ^^^^^^^^^ @@ -128,7 +128,7 @@ LL | fn early_ret() -> i32 { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:377:13 + --> $DIR/cognitive_complexity.rs:393:13 | LL | let x = |a: i32, b: i32| -> i32 { | ^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | let x = |a: i32, b: i32| -> i32 { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:390:8 + --> $DIR/cognitive_complexity.rs:407:8 | LL | fn moo(&self) { | ^^^ @@ -144,7 +144,7 @@ LL | fn moo(&self) { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:399:14 + --> $DIR/cognitive_complexity.rs:417:14 | LL | async fn a() { | ^ @@ -152,7 +152,7 @@ LL | async fn a() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:406:22 + --> $DIR/cognitive_complexity.rs:425:22 | LL | pub async fn async_method() { | ^^^^^^^^^^^^ diff --git a/tests/ui/cognitive_complexity_attr_used.rs b/tests/ui/cognitive_complexity_attr_used.rs index 771a26fc9a86d..6f6e89983d2b7 100644 --- a/tests/ui/cognitive_complexity_attr_used.rs +++ b/tests/ui/cognitive_complexity_attr_used.rs @@ -7,6 +7,7 @@ fn main() { #[clippy::cognitive_complexity = "0"] fn kaboom() { + //~^ ERROR: the function has a cognitive complexity of (3/0) if 42 == 43 { panic!(); } else if "cake" == "lie" { diff --git a/tests/ui/collapsible_match.rs b/tests/ui/collapsible_match.rs index 1d7a72846419f..7501fd2b0bd99 100644 --- a/tests/ui/collapsible_match.rs +++ b/tests/ui/collapsible_match.rs @@ -11,6 +11,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // match without block match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -20,6 +21,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // match with block match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -29,6 +31,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let, if let if let Ok(val) = res_opt { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` take(n); } } @@ -36,6 +39,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let else, if let else if let Ok(val) = res_opt { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` take(n); } else { return; @@ -47,6 +51,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let, match if let Ok(val) = res_opt { match val { + //~^ ERROR: this `match` can be collapsed into the outer `if let` Some(n) => foo(n), _ => (), } @@ -56,6 +61,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> match res_opt { Ok(val) => { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `match` take(n); } }, @@ -65,6 +71,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let else, match if let Ok(val) = res_opt { match val { + //~^ ERROR: this `match` can be collapsed into the outer `if let` Some(n) => foo(n), _ => return, } @@ -76,6 +83,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> match res_opt { Ok(val) => { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `match` take(n); } else { return; @@ -87,6 +95,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // None in inner match same as outer wild branch match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), None => return, }, @@ -96,6 +105,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // None in outer match same as inner wild branch match opt_opt { Some(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -261,6 +271,7 @@ pub enum Issue9647 { pub fn test_1(x: Issue9647) { if let Issue9647::A { a, .. } = x { if let Some(u) = a { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` println!("{u:?}") } } @@ -269,6 +280,7 @@ pub fn test_1(x: Issue9647) { pub fn test_2(x: Issue9647) { if let Issue9647::A { a: Some(a), .. } = x { if let Some(u) = a { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` println!("{u}") } } diff --git a/tests/ui/collapsible_match.stderr b/tests/ui/collapsible_match.stderr index 0294be60b43fd..51a5eedd761c2 100644 --- a/tests/ui/collapsible_match.stderr +++ b/tests/ui/collapsible_match.stderr @@ -3,6 +3,7 @@ error: this `match` can be collapsed into the outer `match` | LL | Ok(val) => match val { | ____________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -13,38 +14,42 @@ help: the outer pattern can be modified to include the inner pattern | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern = note: `-D clippy::collapsible-match` implied by `-D warnings` error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:22:20 + --> $DIR/collapsible_match.rs:23:20 | LL | Ok(val) => match val { | ____________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:22:12 + --> $DIR/collapsible_match.rs:23:12 | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:31:9 + --> $DIR/collapsible_match.rs:33:9 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:30:15 + --> $DIR/collapsible_match.rs:32:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -52,9 +57,10 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:38:9 + --> $DIR/collapsible_match.rs:41:9 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } else { LL | | return; @@ -62,7 +68,7 @@ LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:37:15 + --> $DIR/collapsible_match.rs:40:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -70,33 +76,35 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:49:9 + --> $DIR/collapsible_match.rs:53:9 | LL | / match val { +LL | | LL | | Some(n) => foo(n), LL | | _ => (), LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:48:15 + --> $DIR/collapsible_match.rs:52:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding -LL | match val { +... LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:58:13 + --> $DIR/collapsible_match.rs:63:13 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:57:12 + --> $DIR/collapsible_match.rs:62:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -104,27 +112,29 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:67:9 + --> $DIR/collapsible_match.rs:73:9 | LL | / match val { +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:66:15 + --> $DIR/collapsible_match.rs:72:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding -LL | match val { +... LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:78:13 + --> $DIR/collapsible_match.rs:85:13 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } else { LL | | return; @@ -132,7 +142,7 @@ LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:77:12 + --> $DIR/collapsible_match.rs:84:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -140,51 +150,56 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:89:20 + --> $DIR/collapsible_match.rs:97:20 | LL | Ok(val) => match val { | ____________________^ +LL | | LL | | Some(n) => foo(n), LL | | None => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:89:12 + --> $DIR/collapsible_match.rs:97:12 | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:98:22 + --> $DIR/collapsible_match.rs:107:22 | LL | Some(val) => match val { | ______________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:98:14 + --> $DIR/collapsible_match.rs:107:14 | LL | Some(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:263:9 + --> $DIR/collapsible_match.rs:273:9 | LL | / if let Some(u) = a { +LL | | LL | | println!("{u:?}") LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:262:27 + --> $DIR/collapsible_match.rs:272:27 | LL | if let Issue9647::A { a, .. } = x { | ^ replace this binding @@ -192,15 +207,16 @@ LL | if let Some(u) = a { | ^^^^^^^ with this pattern, prefixed by a: error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:271:9 + --> $DIR/collapsible_match.rs:282:9 | LL | / if let Some(u) = a { +LL | | LL | | println!("{u}") LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:270:35 + --> $DIR/collapsible_match.rs:281:35 | LL | if let Issue9647::A { a: Some(a), .. } = x { | ^ replace this binding diff --git a/tests/ui/collapsible_match2.rs b/tests/ui/collapsible_match2.rs index c8fb0a39e954c..56801f99e4545 100644 --- a/tests/ui/collapsible_match2.rs +++ b/tests/ui/collapsible_match2.rs @@ -11,6 +11,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> { match res_opt { Ok(val) if make() => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -18,6 +19,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> } match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -49,6 +51,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // deref reference value match Some(&[1]) { Some(s) => match *s { + //~^ ERROR: this `match` can be collapsed into the outer `match` [n] => foo(n), _ => (), }, @@ -58,6 +61,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // ref pattern and deref match Some(&[1]) { Some(ref s) => match s { + //~^ ERROR: this `match` can be collapsed into the outer `match` [n] => foo(n), _ => (), }, diff --git a/tests/ui/collapsible_match2.stderr b/tests/ui/collapsible_match2.stderr index 144dbe40a7ad6..f1b7c1417ef71 100644 --- a/tests/ui/collapsible_match2.stderr +++ b/tests/ui/collapsible_match2.stderr @@ -3,6 +3,7 @@ error: this `match` can be collapsed into the outer `match` | LL | Ok(val) if make() => match val { | __________________________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -13,30 +14,33 @@ help: the outer pattern can be modified to include the inner pattern | LL | Ok(val) if make() => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern = note: `-D clippy::collapsible-match` implied by `-D warnings` error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:20:24 + --> $DIR/collapsible_match2.rs:21:24 | LL | Ok(val) => match val { | ________________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:20:16 + --> $DIR/collapsible_match2.rs:21:16 | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:34:29 + --> $DIR/collapsible_match2.rs:36:29 | LL | $pat => match $e { | _____________________________^ @@ -49,7 +53,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ------------------------------------------------ in this macro invocation | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:46:28 + --> $DIR/collapsible_match2.rs:48:28 | LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ^^^ ^^^^^^^ with this pattern @@ -58,38 +62,42 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:51:20 + --> $DIR/collapsible_match2.rs:53:20 | LL | Some(s) => match *s { | ____________________^ +LL | | LL | | [n] => foo(n), LL | | _ => (), LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:51:14 + --> $DIR/collapsible_match2.rs:53:14 | LL | Some(s) => match *s { | ^ replace this binding +LL | LL | [n] => foo(n), | ^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:60:24 + --> $DIR/collapsible_match2.rs:63:24 | LL | Some(ref s) => match s { | ________________________^ +LL | | LL | | [n] => foo(n), LL | | _ => (), LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:60:14 + --> $DIR/collapsible_match2.rs:63:14 | LL | Some(ref s) => match s { | ^^^^^ replace this binding +LL | LL | [n] => foo(n), | ^^^ with this pattern diff --git a/tests/ui/collection_is_never_read.rs b/tests/ui/collection_is_never_read.rs index f7ba68fd8948e..bd281f7870cee 100644 --- a/tests/ui/collection_is_never_read.rs +++ b/tests/ui/collection_is_never_read.rs @@ -19,6 +19,8 @@ fn no_access_at_all() { fn write_without_read() { // The main use case for `collection_is_never_read`. let mut x = HashMap::new(); + //~^ ERROR: collection is never read + //~| NOTE: `-D clippy::collection-is-never-read` implied by `-D warnings` x.insert(1, 2); } @@ -58,6 +60,7 @@ fn read_in_closure() { fn write_in_closure() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read let _ = || { x.push(4); }; @@ -73,11 +76,13 @@ fn shadowing_1() { let x = HashMap::::new(); // Ok let _ = x.len(); let mut x = HashMap::new(); + //~^ ERROR: collection is never read x.insert(1, 2); } fn shadowing_2() { let mut x = HashMap::new(); + //~^ ERROR: collection is never read x.insert(1, 2); let x = HashMap::::new(); // Ok let _ = x.len(); @@ -86,18 +91,21 @@ fn shadowing_2() { #[allow(clippy::let_unit_value)] fn fake_read_1() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x.reverse(); let _: () = x.clear(); } fn fake_read_2() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x.reverse(); println!("{:?}", x.push(5)); } fn assignment() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read let y = vec![4, 5, 6]; // Ok x = y; } @@ -105,6 +113,7 @@ fn assignment() { #[allow(clippy::self_assignment)] fn self_assignment() { let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x = x; } @@ -122,6 +131,7 @@ fn method_argument_but_not_target() { fn insert_is_not_a_read() { let mut x = HashSet::new(); + //~^ ERROR: collection is never read x.insert(5); } @@ -136,6 +146,7 @@ fn not_read_if_return_value_not_used() { // `is_empty` does not modify the set, so it's a query. But since the return value is not used, the // lint does not consider it a read here. let x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x.is_empty(); } @@ -171,33 +182,43 @@ fn function_argument() { fn supported_types() { let mut x = std::collections::BTreeMap::new(); + //~^ ERROR: collection is never read x.insert(true, 1); let mut x = std::collections::BTreeSet::new(); + //~^ ERROR: collection is never read x.insert(1); let mut x = std::collections::BinaryHeap::new(); + //~^ ERROR: collection is never read x.push(1); let mut x = std::collections::HashMap::new(); + //~^ ERROR: collection is never read x.insert(1, 2); let mut x = std::collections::HashSet::new(); + //~^ ERROR: collection is never read x.insert(1); let mut x = std::collections::LinkedList::new(); + //~^ ERROR: collection is never read x.push_front(1); let mut x = Some(true); + //~^ ERROR: collection is never read x.insert(false); let mut x = String::from("hello"); + //~^ ERROR: collection is never read x.push('!'); let mut x = Vec::new(); + //~^ ERROR: collection is never read x.clear(); x.push(1); let mut x = std::collections::VecDeque::new(); + //~^ ERROR: collection is never read x.push_front(1); } diff --git a/tests/ui/collection_is_never_read.stderr b/tests/ui/collection_is_never_read.stderr index 32ba6b9bc2738..0d3f2fc602f81 100644 --- a/tests/ui/collection_is_never_read.stderr +++ b/tests/ui/collection_is_never_read.stderr @@ -7,115 +7,115 @@ LL | let mut x = HashMap::new(); = note: `-D clippy::collection-is-never-read` implied by `-D warnings` error: collection is never read - --> $DIR/collection_is_never_read.rs:60:5 + --> $DIR/collection_is_never_read.rs:62:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:75:5 + --> $DIR/collection_is_never_read.rs:78:5 | LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:80:5 + --> $DIR/collection_is_never_read.rs:84:5 | LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:88:5 + --> $DIR/collection_is_never_read.rs:93:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:94:5 + --> $DIR/collection_is_never_read.rs:100:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:100:5 + --> $DIR/collection_is_never_read.rs:107:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:107:5 + --> $DIR/collection_is_never_read.rs:115:5 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:124:5 + --> $DIR/collection_is_never_read.rs:133:5 | LL | let mut x = HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:138:5 + --> $DIR/collection_is_never_read.rs:148:5 | LL | let x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:173:5 + --> $DIR/collection_is_never_read.rs:184:5 | LL | let mut x = std::collections::BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:176:5 + --> $DIR/collection_is_never_read.rs:188:5 | LL | let mut x = std::collections::BTreeSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:179:5 + --> $DIR/collection_is_never_read.rs:192:5 | LL | let mut x = std::collections::BinaryHeap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:182:5 + --> $DIR/collection_is_never_read.rs:196:5 | LL | let mut x = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:185:5 + --> $DIR/collection_is_never_read.rs:200:5 | LL | let mut x = std::collections::HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:188:5 + --> $DIR/collection_is_never_read.rs:204:5 | LL | let mut x = std::collections::LinkedList::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:191:5 + --> $DIR/collection_is_never_read.rs:208:5 | LL | let mut x = Some(true); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:194:5 + --> $DIR/collection_is_never_read.rs:212:5 | LL | let mut x = String::from("hello"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:197:5 + --> $DIR/collection_is_never_read.rs:216:5 | LL | let mut x = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:201:5 + --> $DIR/collection_is_never_read.rs:221:5 | LL | let mut x = std::collections::VecDeque::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/comparison_chain.rs b/tests/ui/comparison_chain.rs index c12c6a310275d..266cee4c33890 100644 --- a/tests/ui/comparison_chain.rs +++ b/tests/ui/comparison_chain.rs @@ -12,6 +12,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() @@ -25,6 +26,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() @@ -33,6 +35,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if y > x { b() @@ -41,6 +44,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > 1 { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < 1 { b() @@ -115,12 +119,14 @@ fn g(x: f64, y: f64, z: f64) { fn h(x: T, y: T, z: T) { if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() @@ -129,6 +135,7 @@ fn h(x: T, y: T, z: T) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if y > x { b() diff --git a/tests/ui/comparison_chain.stderr b/tests/ui/comparison_chain.stderr index 2eeb50202cd43..db20b1fbb3b4b 100644 --- a/tests/ui/comparison_chain.stderr +++ b/tests/ui/comparison_chain.stderr @@ -2,6 +2,7 @@ error: `if` chain can be rewritten with `match` --> $DIR/comparison_chain.rs:14:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { LL | | b() @@ -12,13 +13,13 @@ LL | | } = note: `-D clippy::comparison-chain` implied by `-D warnings` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:27:5 + --> $DIR/comparison_chain.rs:28:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ @@ -26,13 +27,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:35:5 + --> $DIR/comparison_chain.rs:37:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if y > x { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ @@ -40,13 +41,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:43:5 + --> $DIR/comparison_chain.rs:46:5 | LL | / if x > 1 { +LL | | LL | | a() LL | | } else if x < 1 { -LL | | b() -LL | | } else if x == 1 { +... | LL | | c() LL | | } | |_____^ @@ -54,9 +55,10 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:117:5 + --> $DIR/comparison_chain.rs:121:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { LL | | b() @@ -66,13 +68,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:123:5 + --> $DIR/comparison_chain.rs:128:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ @@ -80,13 +82,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:131:5 + --> $DIR/comparison_chain.rs:137:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if y > x { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ diff --git a/tests/ui/const_comparisons.rs b/tests/ui/const_comparisons.rs index 8e265c9141c16..c0403758f1bb9 100644 --- a/tests/ui/const_comparisons.rs +++ b/tests/ui/const_comparisons.rs @@ -42,52 +42,96 @@ fn main() { status_code >= 400 && status_code < 500; // Correct status_code <= 400 && status_code > 500; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `400` < `500`, the expression evaluates to false for any value of `st status_code > 500 && status_code < 400; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` > `400`, the expression evaluates to false for any value of `st status_code < 500 && status_code > 500; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: `status_code` cannot simultaneously be greater than and less than `500` // More complex expressions status_code < { 400 } && status_code > { 500 }; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any valu status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluate status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to f status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: `status_code` cannot simultaneously be greater than and less than `STATUS_S // Comparing two different types, via the `impl PartialOrd for Status` status < { 400 } && status > { 500 }; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any valu status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluate status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to f status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: `status` cannot simultaneously be greater than and less than `STATUS_SERVER // Yoda conditions 500 <= status_code && 600 > status_code; // Correct 500 <= status_code && status_code <= 600; // Correct 500 >= status_code && 600 < status_code; // Incorrect + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st 500 >= status_code && status_code > 600; // Incorrect + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st // Yoda conditions, comparing two different types 500 <= status && 600 > status; // Correct 500 <= status && status <= 600; // Correct 500 >= status && 600 < status; // Incorrect + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st 500 >= status && status > 600; // Incorrect + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st // Expressions where one of the sides has no effect status_code < 200 && status_code <= 299; + //~^ ERROR: right-hand side of `&&` operator has no effect status_code > 200 && status_code >= 299; + //~^ ERROR: left-hand side of `&&` operator has no effect status_code >= 500 && status_code > 500; // Useless left + //~^ ERROR: left-hand side of `&&` operator has no effect status_code > 500 && status_code >= 500; // Useless right + //~^ ERROR: right-hand side of `&&` operator has no effect status_code <= 500 && status_code < 500; // Useless left + //~^ ERROR: left-hand side of `&&` operator has no effect status_code < 500 && status_code <= 500; // Useless right + //~^ ERROR: right-hand side of `&&` operator has no effect // Other types let name = "Steve"; name < "Jennifer" && name > "Shannon"; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any let numbers = [1, 2]; numbers < [3, 4] && numbers > [5, 6]; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value let letter = 'a'; letter < 'b' && letter > 'c'; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `'b'` < `'c'`, the expression evaluates to false for any value of `le let area = 42.0; area < std::f32::consts::E && area > std::f32::consts::PI; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `std::f32::consts::E` < `std::f32::consts::PI`, the expression evalua } diff --git a/tests/ui/const_comparisons.stderr b/tests/ui/const_comparisons.stderr index 90e6db647621a..e319ce8d17b89 100644 --- a/tests/ui/const_comparisons.stderr +++ b/tests/ui/const_comparisons.stderr @@ -8,7 +8,7 @@ LL | status_code <= 400 && status_code > 500; = note: `-D clippy::impossible-comparisons` implied by `-D warnings` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:45:5 + --> $DIR/const_comparisons.rs:47:5 | LL | status_code > 500 && status_code < 400; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | status_code > 500 && status_code < 400; = note: since `500` > `400`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:46:5 + --> $DIR/const_comparisons.rs:50:5 | LL | status_code < 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | status_code < 500 && status_code > 500; = note: `status_code` cannot simultaneously be greater than and less than `500` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:49:5 + --> $DIR/const_comparisons.rs:55:5 | LL | status_code < { 400 } && status_code > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | status_code < { 400 } && status_code > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:50:5 + --> $DIR/const_comparisons.rs:58:5 | LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:51:5 + --> $DIR/const_comparisons.rs:61:5 | LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:52:5 + --> $DIR/const_comparisons.rs:64:5 | LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; = note: `status_code` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:55:5 + --> $DIR/const_comparisons.rs:69:5 | LL | status < { 400 } && status > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | status < { 400 } && status > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:56:5 + --> $DIR/const_comparisons.rs:72:5 | LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:57:5 + --> $DIR/const_comparisons.rs:75:5 | LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:58:5 + --> $DIR/const_comparisons.rs:78:5 | LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; = note: `status` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:63:5 + --> $DIR/const_comparisons.rs:85:5 | LL | 500 >= status_code && 600 < status_code; // Incorrect | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | 500 >= status_code && 600 < status_code; // Incorrect = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:64:5 + --> $DIR/const_comparisons.rs:88:5 | LL | 500 >= status_code && status_code > 600; // Incorrect | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | 500 >= status_code && status_code > 600; // Incorrect = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:69:5 + --> $DIR/const_comparisons.rs:95:5 | LL | 500 >= status && 600 < status; // Incorrect | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | 500 >= status && 600 < status; // Incorrect = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:70:5 + --> $DIR/const_comparisons.rs:98:5 | LL | 500 >= status && status > 600; // Incorrect | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,80 +120,80 @@ LL | 500 >= status && status > 600; // Incorrect = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:73:5 + --> $DIR/const_comparisons.rs:103:5 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 200` evaluates to true, status_code <= 299` will always evaluate to true as well - --> $DIR/const_comparisons.rs:73:23 + --> $DIR/const_comparisons.rs:103:23 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-comparisons` implied by `-D warnings` error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:74:5 + --> $DIR/const_comparisons.rs:105:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code >= 299` evaluates to true, status_code > 200` will always evaluate to true as well - --> $DIR/const_comparisons.rs:74:5 + --> $DIR/const_comparisons.rs:105:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:76:5 + --> $DIR/const_comparisons.rs:108:5 | LL | status_code >= 500 && status_code > 500; // Useless left | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:76:5 + --> $DIR/const_comparisons.rs:108:5 | LL | status_code >= 500 && status_code > 500; // Useless left | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:77:5 + --> $DIR/const_comparisons.rs:110:5 | LL | status_code > 500 && status_code >= 500; // Useless right | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:77:23 + --> $DIR/const_comparisons.rs:110:23 | LL | status_code > 500 && status_code >= 500; // Useless right | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:78:5 + --> $DIR/const_comparisons.rs:112:5 | LL | status_code <= 500 && status_code < 500; // Useless left | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:78:5 + --> $DIR/const_comparisons.rs:112:5 | LL | status_code <= 500 && status_code < 500; // Useless left | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:79:5 + --> $DIR/const_comparisons.rs:114:5 | LL | status_code < 500 && status_code <= 500; // Useless right | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:79:23 + --> $DIR/const_comparisons.rs:114:23 | LL | status_code < 500 && status_code <= 500; // Useless right | ^^^^^^^^^^^^^^^^^^^^^ error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:83:5 + --> $DIR/const_comparisons.rs:119:5 | LL | name < "Jennifer" && name > "Shannon"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -201,7 +201,7 @@ LL | name < "Jennifer" && name > "Shannon"; = note: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any value of `name` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:86:5 + --> $DIR/const_comparisons.rs:124:5 | LL | numbers < [3, 4] && numbers > [5, 6]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | numbers < [3, 4] && numbers > [5, 6]; = note: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value of `numbers` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:89:5 + --> $DIR/const_comparisons.rs:129:5 | LL | letter < 'b' && letter > 'c'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | letter < 'b' && letter > 'c'; = note: since `'b'` < `'c'`, the expression evaluates to false for any value of `letter` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:92:5 + --> $DIR/const_comparisons.rs:134:5 | LL | area < std::f32::consts::E && area > std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/copy_iterator.rs b/tests/ui/copy_iterator.rs index ae67ebded4374..c0e5fc3e44674 100644 --- a/tests/ui/copy_iterator.rs +++ b/tests/ui/copy_iterator.rs @@ -4,6 +4,8 @@ struct Countdown(u8); impl Iterator for Countdown { + //~^ ERROR: you are implementing `Iterator` on a `Copy` type + //~| NOTE: consider implementing `IntoIterator` instead type Item = u8; fn next(&mut self) -> Option { diff --git a/tests/ui/copy_iterator.stderr b/tests/ui/copy_iterator.stderr index 6bc6fd6b6fa84..12a329bdc12b6 100644 --- a/tests/ui/copy_iterator.stderr +++ b/tests/ui/copy_iterator.stderr @@ -2,9 +2,9 @@ error: you are implementing `Iterator` on a `Copy` type --> $DIR/copy_iterator.rs:6:1 | LL | / impl Iterator for Countdown { -LL | | type Item = u8; LL | | -LL | | fn next(&mut self) -> Option { +LL | | +LL | | type Item = u8; ... | LL | | } LL | | } diff --git a/tests/ui/crashes/ice-10912.rs b/tests/ui/crashes/ice-10912.rs index 02f333070f948..8dfce19422171 100644 --- a/tests/ui/crashes/ice-10912.rs +++ b/tests/ui/crashes/ice-10912.rs @@ -1,4 +1,8 @@ #![warn(clippy::unreadable_literal)] -fn f2() -> impl Sized { && 3.14159265358979323846E } //@no-rustfix +fn f2() -> impl Sized { && 3.14159265358979323846E } +//~^ ERROR: expected at least one digit in exponent +//~| ERROR: long literal lacking separators +//~| NOTE: `-D clippy::unreadable-literal` implied by `-D warnings` + fn main() {} diff --git a/tests/ui/crashes/ice-10912.stderr b/tests/ui/crashes/ice-10912.stderr index a74ce731577d0..0833769feecf1 100644 --- a/tests/ui/crashes/ice-10912.stderr +++ b/tests/ui/crashes/ice-10912.stderr @@ -1,11 +1,11 @@ error: expected at least one digit in exponent - --> $DIR/ice-10912.rs:2:28 + --> $DIR/ice-10912.rs:3:28 | LL | fn f2() -> impl Sized { && 3.14159265358979323846E } | ^^^^^^^^^^^^^^^^^^^^^^^ error: long literal lacking separators - --> $DIR/ice-10912.rs:2:28 + --> $DIR/ice-10912.rs:3:28 | LL | fn f2() -> impl Sized { && 3.14159265358979323846E } | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider: `3.141_592_653_589_793_238_46` diff --git a/tests/ui/crashes/ice-2774.fixed b/tests/ui/crashes/ice-2774.fixed index d71b8fcad1f5b..96cf0d8540cd9 100644 --- a/tests/ui/crashes/ice-2774.fixed +++ b/tests/ui/crashes/ice-2774.fixed @@ -13,6 +13,8 @@ pub struct Foo; #[allow(clippy::implicit_hasher)] // This should not cause a "cannot relate bound region" ICE. pub fn add_barfoos_to_foos(bars: &HashSet<&Bar>) { + //~^ ERROR: the following explicit lifetimes could be elided: 'a + //~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings` let mut foos = HashSet::new(); foos.extend(bars.iter().map(|b| &b.foo)); } diff --git a/tests/ui/crashes/ice-2774.rs b/tests/ui/crashes/ice-2774.rs index 88cfa1f923c0b..464d7891c9f49 100644 --- a/tests/ui/crashes/ice-2774.rs +++ b/tests/ui/crashes/ice-2774.rs @@ -13,6 +13,8 @@ pub struct Foo; #[allow(clippy::implicit_hasher)] // This should not cause a "cannot relate bound region" ICE. pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { + //~^ ERROR: the following explicit lifetimes could be elided: 'a + //~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings` let mut foos = HashSet::new(); foos.extend(bars.iter().map(|b| &b.foo)); } diff --git a/tests/ui/crashes/ice-360.rs b/tests/ui/crashes/ice-360.rs index 2649674667be7..28589e1efeda5 100644 --- a/tests/ui/crashes/ice-360.rs +++ b/tests/ui/crashes/ice-360.rs @@ -3,10 +3,13 @@ fn main() {} fn no_panic(slice: &[T]) { let mut iter = slice.iter(); loop { + //~^ ERROR: this loop could be written as a `while let` loop + //~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings` let _ = match iter.next() { Some(ele) => ele, None => break, }; loop {} + //~^ ERROR: empty `loop {}` wastes CPU cycles } } diff --git a/tests/ui/crashes/ice-360.stderr b/tests/ui/crashes/ice-360.stderr index a2e2ab8fd192f..292b27dd934ed 100644 --- a/tests/ui/crashes/ice-360.stderr +++ b/tests/ui/crashes/ice-360.stderr @@ -2,18 +2,18 @@ error: this loop could be written as a `while let` loop --> $DIR/ice-360.rs:5:5 | LL | / loop { +LL | | +LL | | LL | | let _ = match iter.next() { -LL | | Some(ele) => ele, -LL | | None => break, -LL | | }; -LL | | loop {} +... | +LL | | LL | | } | |_____^ help: try: `while let Some(ele) = iter.next() { .. }` | = note: `-D clippy::while-let-loop` implied by `-D warnings` error: empty `loop {}` wastes CPU cycles - --> $DIR/ice-360.rs:10:9 + --> $DIR/ice-360.rs:12:9 | LL | loop {} | ^^^^^^^ diff --git a/tests/ui/crashes/ice-3717.fixed b/tests/ui/crashes/ice-3717.fixed index f48273e796a64..3f54b326979c9 100644 --- a/tests/ui/crashes/ice-3717.fixed +++ b/tests/ui/crashes/ice-3717.fixed @@ -5,6 +5,7 @@ use std::collections::HashSet; fn main() {} pub fn ice_3717(_: &HashSet) { + //~^ ERROR: parameter of type `HashSet` should be generalized over different hashers let _ = [0u8; 0]; let _: HashSet = HashSet::default(); } diff --git a/tests/ui/crashes/ice-3717.rs b/tests/ui/crashes/ice-3717.rs index f50714643fd25..2890a9277c719 100644 --- a/tests/ui/crashes/ice-3717.rs +++ b/tests/ui/crashes/ice-3717.rs @@ -5,6 +5,7 @@ use std::collections::HashSet; fn main() {} pub fn ice_3717(_: &HashSet) { + //~^ ERROR: parameter of type `HashSet` should be generalized over different hashers let _ = [0u8; 0]; let _: HashSet = HashSet::new(); } diff --git a/tests/ui/crashes/ice-3891.rs b/tests/ui/crashes/ice-3891.rs index 05c5134c8457b..a3f1ccad71ae6 100644 --- a/tests/ui/crashes/ice-3891.rs +++ b/tests/ui/crashes/ice-3891.rs @@ -1,3 +1,4 @@ fn main() { 1x; + //~^ ERROR: invalid suffix `x` for number literal } diff --git a/tests/ui/crashes/ice-3969.rs b/tests/ui/crashes/ice-3969.rs index 9b68cac7ff485..d5676cbd91d19 100644 --- a/tests/ui/crashes/ice-3969.rs +++ b/tests/ui/crashes/ice-3969.rs @@ -18,10 +18,13 @@ struct Dst { struct TwoStrs(str, str) where str: Sized; +//~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetim +//~| NOTE: `-D trivial-bounds` implied by `-D warnings` fn unsized_local() where for<'a> Dst: Sized, + //~^ ERROR: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend { let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); } @@ -29,6 +32,7 @@ where fn return_str() -> str where str: Sized, + //~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetim { *"Sized".to_string().into_boxed_str() } @@ -36,6 +40,7 @@ where fn use_op(s: String) -> String where String: ::std::ops::Neg, + //~^ ERROR: trait bound std::string::String: std::ops::Neg does not depend on any type { -s } @@ -43,6 +48,7 @@ where fn use_for() where i32: Iterator, + //~^ ERROR: trait bound i32: std::iter::Iterator does not depend on any type or lifeti { for _ in 2i32 {} } diff --git a/tests/ui/crashes/ice-3969.stderr b/tests/ui/crashes/ice-3969.stderr index 79018080886c0..bc10555693ca8 100644 --- a/tests/ui/crashes/ice-3969.stderr +++ b/tests/ui/crashes/ice-3969.stderr @@ -7,25 +7,25 @@ LL | str: Sized; = note: `-D trivial-bounds` implied by `-D warnings` error: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:24:30 + --> $DIR/ice-3969.rs:26:30 | LL | for<'a> Dst: Sized, | ^^^^^ error: trait bound str: std::marker::Sized does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:31:10 + --> $DIR/ice-3969.rs:34:10 | LL | str: Sized, | ^^^^^ error: trait bound std::string::String: std::ops::Neg does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:38:13 + --> $DIR/ice-3969.rs:42:13 | LL | String: ::std::ops::Neg, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: trait bound i32: std::iter::Iterator does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:45:10 + --> $DIR/ice-3969.rs:50:10 | LL | i32: Iterator, | ^^^^^^^^ diff --git a/tests/ui/crashes/ice-5835.fixed b/tests/ui/crashes/ice-5835.fixed index c11f68e85ca1e..c0532d685786d 100644 --- a/tests/ui/crashes/ice-5835.fixed +++ b/tests/ui/crashes/ice-5835.fixed @@ -1,6 +1,8 @@ #[rustfmt::skip] pub struct Foo { /// 位 + //~^ ERROR: using tabs in doc comments is not recommended + //~| NOTE: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` /// ^ Do not remove this tab character. /// It was required to trigger the ICE. pub bar: u8, diff --git a/tests/ui/crashes/ice-5835.rs b/tests/ui/crashes/ice-5835.rs index 5e99cb432b6e2..122bddd6ae679 100644 --- a/tests/ui/crashes/ice-5835.rs +++ b/tests/ui/crashes/ice-5835.rs @@ -1,6 +1,8 @@ #[rustfmt::skip] pub struct Foo { /// 位 + //~^ ERROR: using tabs in doc comments is not recommended + //~| NOTE: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` /// ^ Do not remove this tab character. /// It was required to trigger the ICE. pub bar: u8, diff --git a/tests/ui/crashes/ice-5872.fixed b/tests/ui/crashes/ice-5872.fixed index b009b2323ba62..c8e870c62fbfb 100644 --- a/tests/ui/crashes/ice-5872.fixed +++ b/tests/ui/crashes/ice-5872.fixed @@ -2,4 +2,6 @@ fn main() { let _ = vec![1, 2, 3].into_iter().next().is_none(); + //~^ ERROR: avoid using `collect()` when not needed + //~| NOTE: `-D clippy::needless-collect` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-5872.rs b/tests/ui/crashes/ice-5872.rs index 68afa8f8c3a84..c6ed313658922 100644 --- a/tests/ui/crashes/ice-5872.rs +++ b/tests/ui/crashes/ice-5872.rs @@ -2,4 +2,6 @@ fn main() { let _ = vec![1, 2, 3].into_iter().collect::>().is_empty(); + //~^ ERROR: avoid using `collect()` when not needed + //~| NOTE: `-D clippy::needless-collect` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-6254.rs b/tests/ui/crashes/ice-6254.rs index 8af60890390e7..2ae426cf789de 100644 --- a/tests/ui/crashes/ice-6254.rs +++ b/tests/ui/crashes/ice-6254.rs @@ -11,6 +11,8 @@ fn main() { // This used to cause an ICE (https://github.com/rust-lang/rust/issues/78071) match FOO_REF_REF { FOO_REF_REF => {}, + //~^ ERROR: to use a constant of type `Foo` in a pattern, `Foo` must be annotated + //~| NOTE: for more information, see issue #62411 {}, } } diff --git a/tests/ui/crashes/ice-7169.fixed b/tests/ui/crashes/ice-7169.fixed index 91cfbb38b77af..cf4077e4d8982 100644 --- a/tests/ui/crashes/ice-7169.fixed +++ b/tests/ui/crashes/ice-7169.fixed @@ -8,4 +8,6 @@ struct A { fn main() { if Ok::<_, ()>(A::::default()).is_ok() {} + //~^ ERROR: redundant pattern matching, consider using `is_ok()` + //~| NOTE: `-D clippy::redundant-pattern-matching` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-7169.rs b/tests/ui/crashes/ice-7169.rs index b203252f0a14a..b09e6f3846327 100644 --- a/tests/ui/crashes/ice-7169.rs +++ b/tests/ui/crashes/ice-7169.rs @@ -8,4 +8,6 @@ struct A { fn main() { if let Ok(_) = Ok::<_, ()>(A::::default()) {} + //~^ ERROR: redundant pattern matching, consider using `is_ok()` + //~| NOTE: `-D clippy::redundant-pattern-matching` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-7869.rs b/tests/ui/crashes/ice-7869.rs index 8f97a063a9a9f..774e22f6b4c59 100644 --- a/tests/ui/crashes/ice-7869.rs +++ b/tests/ui/crashes/ice-7869.rs @@ -1,4 +1,5 @@ enum Tila { + //~^ ERROR: all variants have the same prefix: `Työ` TyöAlkoi, TyöKeskeytyi, TyöValmis, diff --git a/tests/ui/crashes/ice-7869.stderr b/tests/ui/crashes/ice-7869.stderr index 35d1e8fd29573..61fc8a4817a7d 100644 --- a/tests/ui/crashes/ice-7869.stderr +++ b/tests/ui/crashes/ice-7869.stderr @@ -2,6 +2,7 @@ error: all variants have the same prefix: `Työ` --> $DIR/ice-7869.rs:1:1 | LL | / enum Tila { +LL | | LL | | TyöAlkoi, LL | | TyöKeskeytyi, LL | | TyöValmis, diff --git a/tests/ui/crashes/ice-8250.fixed b/tests/ui/crashes/ice-8250.fixed index 478b3b49270f0..984b61258c781 100644 --- a/tests/ui/crashes/ice-8250.fixed +++ b/tests/ui/crashes/ice-8250.fixed @@ -1,5 +1,7 @@ fn _f(s: &str) -> Option<()> { let _ = s[1..].split('.').next()?; + //~^ ERROR: unnecessary use of `splitn` + //~| NOTE: `-D clippy::needless-splitn` implied by `-D warnings` Some(()) } diff --git a/tests/ui/crashes/ice-8250.rs b/tests/ui/crashes/ice-8250.rs index d9a5ee1162a49..c1b2e48ba3c06 100644 --- a/tests/ui/crashes/ice-8250.rs +++ b/tests/ui/crashes/ice-8250.rs @@ -1,5 +1,7 @@ fn _f(s: &str) -> Option<()> { let _ = s[1..].splitn(2, '.').next()?; + //~^ ERROR: unnecessary use of `splitn` + //~| NOTE: `-D clippy::needless-splitn` implied by `-D warnings` Some(()) } diff --git a/tests/ui/crashes/ice-8821.fixed b/tests/ui/crashes/ice-8821.fixed index df297eea056ad..a25bb46f9ff7b 100644 --- a/tests/ui/crashes/ice-8821.fixed +++ b/tests/ui/crashes/ice-8821.fixed @@ -5,4 +5,6 @@ static FN: fn() = f; fn main() { FN(); + //~^ ERROR: this let-binding has unit value + //~| NOTE: `-D clippy::let-unit-value` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-8821.rs b/tests/ui/crashes/ice-8821.rs index fb87b79aeed87..082f7c92646a6 100644 --- a/tests/ui/crashes/ice-8821.rs +++ b/tests/ui/crashes/ice-8821.rs @@ -5,4 +5,6 @@ static FN: fn() = f; fn main() { let _: () = FN(); + //~^ ERROR: this let-binding has unit value + //~| NOTE: `-D clippy::let-unit-value` implied by `-D warnings` } diff --git a/tests/ui/crashes/ice-8850.fixed b/tests/ui/crashes/ice-8850.fixed index 2a5b4110c2441..4569b9e8793e2 100644 --- a/tests/ui/crashes/ice-8850.fixed +++ b/tests/ui/crashes/ice-8850.fixed @@ -2,12 +2,15 @@ fn fn_pointer_static() -> usize { static FN: fn() -> usize = || 1; FN() + 1 + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn fn_pointer_const() -> usize { const FN: fn() -> usize = || 1; FN() + 1 + //~^ ERROR: returning the result of a `let` binding from a block } fn deref_to_dyn_fn() -> usize { @@ -22,6 +25,7 @@ fn deref_to_dyn_fn() -> usize { static FN: Derefs = Derefs; FN() + 1 + //~^ ERROR: returning the result of a `let` binding from a block } fn main() {} diff --git a/tests/ui/crashes/ice-8850.rs b/tests/ui/crashes/ice-8850.rs index f2747ab2239a6..499756ecefe98 100644 --- a/tests/ui/crashes/ice-8850.rs +++ b/tests/ui/crashes/ice-8850.rs @@ -2,12 +2,15 @@ fn fn_pointer_static() -> usize { static FN: fn() -> usize = || 1; let res = FN() + 1; res + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn fn_pointer_const() -> usize { const FN: fn() -> usize = || 1; let res = FN() + 1; res + //~^ ERROR: returning the result of a `let` binding from a block } fn deref_to_dyn_fn() -> usize { @@ -22,6 +25,7 @@ fn deref_to_dyn_fn() -> usize { static FN: Derefs = Derefs; let res = FN() + 1; res + //~^ ERROR: returning the result of a `let` binding from a block } fn main() {} diff --git a/tests/ui/crashes/ice-8850.stderr b/tests/ui/crashes/ice-8850.stderr index 620fd1edaf790..41da3f715ae37 100644 --- a/tests/ui/crashes/ice-8850.stderr +++ b/tests/ui/crashes/ice-8850.stderr @@ -14,7 +14,7 @@ LL ~ FN() + 1 | error: returning the result of a `let` binding from a block - --> $DIR/ice-8850.rs:10:5 + --> $DIR/ice-8850.rs:12:5 | LL | let res = FN() + 1; | ------------------- unnecessary `let` binding @@ -28,7 +28,7 @@ LL ~ FN() + 1 | error: returning the result of a `let` binding from a block - --> $DIR/ice-8850.rs:24:5 + --> $DIR/ice-8850.rs:27:5 | LL | let res = FN() + 1; | ------------------- unnecessary `let` binding diff --git a/tests/ui/crashes/ice-9041.rs b/tests/ui/crashes/ice-9041.rs index 9adc30c680b6a..727d88f7fbd26 100644 --- a/tests/ui/crashes/ice-9041.rs +++ b/tests/ui/crashes/ice-9041.rs @@ -3,6 +3,8 @@ pub struct Thing; pub fn has_thing(things: &[Thing]) -> bool { let is_thing_ready = |_peer: &Thing| -> bool { todo!() }; things.iter().find(|p| is_thing_ready(p)).is_some() + //~^ ERROR: called `is_some()` after searching an `Iterator` with `find` + //~| NOTE: `-D clippy::search-is-some` implied by `-D warnings` } fn main() {} diff --git a/tests/ui/crashes/ice-9445.rs b/tests/ui/crashes/ice-9445.rs index c67b22f6f8c47..b6afbd33c79fb 100644 --- a/tests/ui/crashes/ice-9445.rs +++ b/tests/ui/crashes/ice-9445.rs @@ -1,3 +1,5 @@ const UNINIT: core::mem::MaybeUninit> = core::mem::MaybeUninit::uninit(); +//~^ ERROR: a `const` item should never be interior mutable +//~| NOTE: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` fn main() {} diff --git a/tests/ui/crashes/ice-9463.rs b/tests/ui/crashes/ice-9463.rs index 9564e77c24b1c..fa83d25b3942d 100644 --- a/tests/ui/crashes/ice-9463.rs +++ b/tests/ui/crashes/ice-9463.rs @@ -1,5 +1,9 @@ #![deny(arithmetic_overflow)] fn main() { let _x = -1_i32 >> -1; + //~^ ERROR: this arithmetic operation will overflow let _y = 1u32 >> 10000000000000u32; + //~^ ERROR: this arithmetic operation will overflow + //~| ERROR: literal out of range for `u32` + //~| NOTE: the literal `10000000000000u32` does not fit into the type `u32` whose rang } diff --git a/tests/ui/crashes/ice-9463.stderr b/tests/ui/crashes/ice-9463.stderr index 2b425e85a27b5..911795694c38e 100644 --- a/tests/ui/crashes/ice-9463.stderr +++ b/tests/ui/crashes/ice-9463.stderr @@ -11,13 +11,13 @@ LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow - --> $DIR/ice-9463.rs:4:14 + --> $DIR/ice-9463.rs:5:14 | LL | let _y = 1u32 >> 10000000000000u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift right by `1316134912_u32`, which would overflow error: literal out of range for `u32` - --> $DIR/ice-9463.rs:4:22 + --> $DIR/ice-9463.rs:5:22 | LL | let _y = 1u32 >> 10000000000000u32; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed index 7b4def818152c..8bd9eea75bb26 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed @@ -13,6 +13,7 @@ impl<'a> Foo for Baz<'a> {} impl Bar { fn baz(&self) -> impl Foo + '_ { + //~^ ERROR: the following explicit lifetimes could be elided: 'a Baz { bar: self } } } diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.rs b/tests/ui/crashes/needless_lifetimes_impl_trait.rs index 376ff97ba6036..06947e3a3513d 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.rs +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.rs @@ -13,6 +13,7 @@ impl<'a> Foo for Baz<'a> {} impl Bar { fn baz<'a>(&'a self) -> impl Foo + 'a { + //~^ ERROR: the following explicit lifetimes could be elided: 'a Baz { bar: self } } } diff --git a/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed b/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed index 517f9cdd42ccc..774dea3919396 100644 --- a/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed +++ b/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed @@ -5,5 +5,6 @@ struct Foo<'a>(&'a [(); 100]); fn test(x: &Foo<'_>) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn main() {} diff --git a/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs b/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs index dd3d8b8b6d156..f3d8871929a22 100644 --- a/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs +++ b/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs @@ -5,5 +5,6 @@ struct Foo<'a>(&'a [(); 100]); fn test(x: Foo<'_>) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn main() {} diff --git a/tests/ui/crate_level_checks/no_std_swap.rs b/tests/ui/crate_level_checks/no_std_swap.rs index d3571eaf0d7be..8ed45a3346550 100644 --- a/tests/ui/crate_level_checks/no_std_swap.rs +++ b/tests/ui/crate_level_checks/no_std_swap.rs @@ -10,5 +10,7 @@ fn main() { let mut b = 1337; a = b; + //~^ ERROR: this looks like you are trying to swap `a` and `b` + //~| NOTE: or maybe you should use `core::mem::replace`? b = a; } diff --git a/tests/ui/crate_level_checks/no_std_swap.stderr b/tests/ui/crate_level_checks/no_std_swap.stderr index 7d8ea3f76b0f6..9258c828aafc6 100644 --- a/tests/ui/crate_level_checks/no_std_swap.stderr +++ b/tests/ui/crate_level_checks/no_std_swap.stderr @@ -2,6 +2,8 @@ error: this looks like you are trying to swap `a` and `b` --> $DIR/no_std_swap.rs:12:5 | LL | / a = b; +LL | | +LL | | LL | | b = a; | |_________^ help: try: `core::mem::swap(&mut a, &mut b)` | diff --git a/tests/ui/crate_level_checks/std_main_recursion.rs b/tests/ui/crate_level_checks/std_main_recursion.rs index 89ff6609934d2..c2c3e0958ec78 100644 --- a/tests/ui/crate_level_checks/std_main_recursion.rs +++ b/tests/ui/crate_level_checks/std_main_recursion.rs @@ -3,4 +3,5 @@ fn main() { println!("Hello, World!"); main(); + //~^ ERROR: recursing into entrypoint `main` } diff --git a/tests/ui/dbg_macro.rs b/tests/ui/dbg_macro.rs index acbd463162ff2..149b08476192c 100644 --- a/tests/ui/dbg_macro.rs +++ b/tests/ui/dbg_macro.rs @@ -4,23 +4,33 @@ fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~| NOTE: `-D clippy::dbg-macro` implied by `-D warnings` } fn bar(_: ()) {} fn factorial(n: u32) -> u32 { if dbg!(n <= 1) { + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1) + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } else { dbg!(n * factorial(n - 1)) + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } } fn main() { dbg!(42); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(dbg!(dbg!(42))); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo(3) + dbg!(factorial(4)); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1, 2, dbg!(3, 4)); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1, 2, 3, 4, 5); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } fn issue9914() { @@ -41,11 +51,16 @@ fn issue9914() { } dbg!(); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool #[allow(clippy::let_unit_value)] let _ = dbg!(); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool bar(dbg!()); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo!(dbg!()); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo2!(foo!(dbg!())); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool expand_to_dbg!(); } @@ -67,22 +82,26 @@ mod issue7274 { struct MyThing; define_thing!(MyThing, { dbg!(2); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool }); } #[test] pub fn issue8481() { dbg!(1); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } #[cfg(test)] fn foo2() { dbg!(1); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } #[cfg(test)] mod mod1 { fn func() { dbg!(1); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } } diff --git a/tests/ui/dbg_macro.stderr b/tests/ui/dbg_macro.stderr index aa58fb09aff15..e63d07a5f2472 100644 --- a/tests/ui/dbg_macro.stderr +++ b/tests/ui/dbg_macro.stderr @@ -11,7 +11,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:11:8 + --> $DIR/dbg_macro.rs:13:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:12:9 + --> $DIR/dbg_macro.rs:15:9 | LL | dbg!(1) | ^^^^^^^ @@ -33,7 +33,7 @@ LL | 1 | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:14:9 + --> $DIR/dbg_macro.rs:18:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:19:5 + --> $DIR/dbg_macro.rs:24:5 | LL | dbg!(42); | ^^^^^^^^ @@ -55,7 +55,7 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:20:5 + --> $DIR/dbg_macro.rs:26:5 | LL | dbg!(dbg!(dbg!(42))); | ^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | dbg!(dbg!(42)); | ~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:21:14 + --> $DIR/dbg_macro.rs:28:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | foo(3) + factorial(4); | ~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:22:5 + --> $DIR/dbg_macro.rs:30:5 | LL | dbg!(1, 2, dbg!(3, 4)); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | (1, 2, dbg!(3, 4)); | ~~~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:23:5 + --> $DIR/dbg_macro.rs:32:5 | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | (1, 2, 3, 4, 5); | ~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:43:5 + --> $DIR/dbg_macro.rs:53:5 | LL | dbg!(); | ^^^^^^^ @@ -111,7 +111,7 @@ LL + | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:45:13 + --> $DIR/dbg_macro.rs:56:13 | LL | let _ = dbg!(); | ^^^^^^ @@ -122,7 +122,7 @@ LL | let _ = (); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:46:9 + --> $DIR/dbg_macro.rs:58:9 | LL | bar(dbg!()); | ^^^^^^ @@ -133,7 +133,7 @@ LL | bar(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:47:10 + --> $DIR/dbg_macro.rs:60:10 | LL | foo!(dbg!()); | ^^^^^^ @@ -144,7 +144,7 @@ LL | foo!(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:48:16 + --> $DIR/dbg_macro.rs:62:16 | LL | foo2!(foo!(dbg!())); | ^^^^^^ @@ -155,7 +155,7 @@ LL | foo2!(foo!(())); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:69:9 + --> $DIR/dbg_macro.rs:84:9 | LL | dbg!(2); | ^^^^^^^ @@ -166,7 +166,7 @@ LL | 2; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:75:5 + --> $DIR/dbg_macro.rs:91:5 | LL | dbg!(1); | ^^^^^^^ @@ -177,7 +177,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:80:5 + --> $DIR/dbg_macro.rs:97:5 | LL | dbg!(1); | ^^^^^^^ @@ -188,7 +188,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:86:9 + --> $DIR/dbg_macro.rs:104:9 | LL | dbg!(1); | ^^^^^^^ diff --git a/tests/ui/debug_assert_with_mut_call.rs b/tests/ui/debug_assert_with_mut_call.rs index 46faa0a7b9117..8d04be777c7b8 100644 --- a/tests/ui/debug_assert_with_mut_call.rs +++ b/tests/ui/debug_assert_with_mut_call.rs @@ -40,13 +40,20 @@ fn func_non_mutable() { fn func_mutable() { debug_assert!(bool_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` + //~| NOTE: `-D clippy::debug-assert-with-mut-call` implied by `-D warnings` debug_assert!(!bool_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert_eq!(0, u32_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(u32_mut(&mut 3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_ne!(1, u32_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(u32_mut(&mut 3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` } fn method_non_mutable() { @@ -62,20 +69,33 @@ fn method_non_mutable() { fn method_mutable() { debug_assert!(S.bool_self_mut()); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(!S.bool_self_mut()); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(S.bool_self_ref_arg_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(S.bool_self_mut_arg_ref(&3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(S.bool_self_mut_arg_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert_eq!(S.u32_self_mut(), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_ne!(S.u32_self_mut(), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` } fn misc() { @@ -84,27 +104,35 @@ fn misc() { debug_assert_eq!(v.get(0), Some(&1)); debug_assert_ne!(v[0], 2); debug_assert_eq!(v.pop(), Some(1)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_ne!(Some(3), v.pop()); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` let a = &mut 3; debug_assert!(bool_mut(a)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` // nested debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` // chained debug_assert_eq!(v.pop().unwrap(), 3); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` // format args debug_assert!(bool_ref(&3), "w/o format"); debug_assert!(bool_mut(&mut 3), "w/o format"); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(bool_ref(&3), "{} format", "w/"); debug_assert!(bool_mut(&mut 3), "{} format", "w/"); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` // sub block let mut x = 42_u32; debug_assert!({ bool_mut(&mut x); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert! x > 10 }); @@ -112,6 +140,7 @@ fn misc() { debug_assert!((|| { let mut x = 42; bool_mut(&mut x); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert! x > 10 })()); } diff --git a/tests/ui/debug_assert_with_mut_call.stderr b/tests/ui/debug_assert_with_mut_call.stderr index a2ca71b57a6fd..97c47064a3353 100644 --- a/tests/ui/debug_assert_with_mut_call.stderr +++ b/tests/ui/debug_assert_with_mut_call.stderr @@ -7,163 +7,163 @@ LL | debug_assert!(bool_mut(&mut 3)); = note: `-D clippy::debug-assert-with-mut-call` implied by `-D warnings` error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:43:20 + --> $DIR/debug_assert_with_mut_call.rs:45:20 | LL | debug_assert!(!bool_mut(&mut 3)); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:45:25 + --> $DIR/debug_assert_with_mut_call.rs:48:25 | LL | debug_assert_eq!(0, u32_mut(&mut 3)); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:46:22 + --> $DIR/debug_assert_with_mut_call.rs:50:22 | LL | debug_assert_eq!(u32_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:48:25 + --> $DIR/debug_assert_with_mut_call.rs:53:25 | LL | debug_assert_ne!(1, u32_mut(&mut 3)); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:49:22 + --> $DIR/debug_assert_with_mut_call.rs:55:22 | LL | debug_assert_ne!(u32_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:64:19 + --> $DIR/debug_assert_with_mut_call.rs:71:19 | LL | debug_assert!(S.bool_self_mut()); | ^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:65:20 + --> $DIR/debug_assert_with_mut_call.rs:73:20 | LL | debug_assert!(!S.bool_self_mut()); | ^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:66:19 + --> $DIR/debug_assert_with_mut_call.rs:75:19 | LL | debug_assert!(S.bool_self_ref_arg_mut(&mut 3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:67:19 + --> $DIR/debug_assert_with_mut_call.rs:77:19 | LL | debug_assert!(S.bool_self_mut_arg_ref(&3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:68:19 + --> $DIR/debug_assert_with_mut_call.rs:79:19 | LL | debug_assert!(S.bool_self_mut_arg_mut(&mut 3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:70:22 + --> $DIR/debug_assert_with_mut_call.rs:82:22 | LL | debug_assert_eq!(S.u32_self_mut(), 0); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:71:22 + --> $DIR/debug_assert_with_mut_call.rs:84:22 | LL | debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:72:22 + --> $DIR/debug_assert_with_mut_call.rs:86:22 | LL | debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:73:22 + --> $DIR/debug_assert_with_mut_call.rs:88:22 | LL | debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:75:22 + --> $DIR/debug_assert_with_mut_call.rs:91:22 | LL | debug_assert_ne!(S.u32_self_mut(), 1); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:76:22 + --> $DIR/debug_assert_with_mut_call.rs:93:22 | LL | debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:77:22 + --> $DIR/debug_assert_with_mut_call.rs:95:22 | LL | debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:78:22 + --> $DIR/debug_assert_with_mut_call.rs:97:22 | LL | debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:86:22 + --> $DIR/debug_assert_with_mut_call.rs:106:22 | LL | debug_assert_eq!(v.pop(), Some(1)); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:87:31 + --> $DIR/debug_assert_with_mut_call.rs:108:31 | LL | debug_assert_ne!(Some(3), v.pop()); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:90:19 + --> $DIR/debug_assert_with_mut_call.rs:112:19 | LL | debug_assert!(bool_mut(a)); | ^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:93:31 + --> $DIR/debug_assert_with_mut_call.rs:116:31 | LL | debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:96:22 + --> $DIR/debug_assert_with_mut_call.rs:120:22 | LL | debug_assert_eq!(v.pop().unwrap(), 3); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:100:19 + --> $DIR/debug_assert_with_mut_call.rs:125:19 | LL | debug_assert!(bool_mut(&mut 3), "w/o format"); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:102:19 + --> $DIR/debug_assert_with_mut_call.rs:128:19 | LL | debug_assert!(bool_mut(&mut 3), "{} format", "w/"); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:107:9 + --> $DIR/debug_assert_with_mut_call.rs:134:9 | LL | bool_mut(&mut x); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:114:9 + --> $DIR/debug_assert_with_mut_call.rs:142:9 | LL | bool_mut(&mut x); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/def_id_nocore.rs b/tests/ui/def_id_nocore.rs index da0816830b85f..190d636ebf34a 100644 --- a/tests/ui/def_id_nocore.rs +++ b/tests/ui/def_id_nocore.rs @@ -25,6 +25,7 @@ struct A; impl A { pub fn as_ref(self) -> &'static str { + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl "A" } } diff --git a/tests/ui/default_union_representation.rs b/tests/ui/default_union_representation.rs index 93b2d33da2cd2..41308b077bac6 100644 --- a/tests/ui/default_union_representation.rs +++ b/tests/ui/default_union_representation.rs @@ -2,6 +2,7 @@ #![warn(clippy::default_union_representation)] union NoAttribute { + //~^ ERROR: this union has the default representation a: i32, b: u32, } @@ -14,6 +15,7 @@ union ReprC { #[repr(packed)] union ReprPacked { + //~^ ERROR: this union has the default representation a: i32, b: u32, } @@ -32,6 +34,7 @@ union ReprCAlign { #[repr(align(32))] union ReprAlign { + //~^ ERROR: this union has the default representation a: i32, b: u32, } @@ -52,6 +55,7 @@ union ZSTsAndField2 { f3: (), } union ZSTAndTwoFields { + //~^ ERROR: this union has the default representation f0: u32, f1: u64, f2: (), diff --git a/tests/ui/default_union_representation.stderr b/tests/ui/default_union_representation.stderr index 8b7ed94cbc611..256eebc44200a 100644 --- a/tests/ui/default_union_representation.stderr +++ b/tests/ui/default_union_representation.stderr @@ -2,6 +2,7 @@ error: this union has the default representation --> $DIR/default_union_representation.rs:4:1 | LL | / union NoAttribute { +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -11,9 +12,10 @@ LL | | } = note: `-D clippy::default-union-representation` implied by `-D warnings` error: this union has the default representation - --> $DIR/default_union_representation.rs:16:1 + --> $DIR/default_union_representation.rs:17:1 | LL | / union ReprPacked { +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -22,9 +24,10 @@ LL | | } = help: consider annotating `ReprPacked` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> $DIR/default_union_representation.rs:34:1 + --> $DIR/default_union_representation.rs:36:1 | LL | / union ReprAlign { +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -33,9 +36,10 @@ LL | | } = help: consider annotating `ReprAlign` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> $DIR/default_union_representation.rs:54:1 + --> $DIR/default_union_representation.rs:57:1 | LL | / union ZSTAndTwoFields { +LL | | LL | | f0: u32, LL | | f1: u64, LL | | f2: (), diff --git a/tests/ui/deprecated_old.rs b/tests/ui/deprecated_old.rs index e89dca4fcfd4c..356ad5f060b6c 100644 --- a/tests/ui/deprecated_old.rs +++ b/tests/ui/deprecated_old.rs @@ -1,5 +1,9 @@ #[warn(unstable_as_slice)] +//~^ ERROR: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized +//~| NOTE: `-D renamed-and-removed-lints` implied by `-D warnings` #[warn(unstable_as_mut_slice)] +//~^ ERROR: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been st #[warn(misaligned_transmute)] +//~^ ERROR: lint `misaligned_transmute` has been removed: this lint has been split into ca fn main() {} diff --git a/tests/ui/deprecated_old.stderr b/tests/ui/deprecated_old.stderr index 8043ab0058a5e..5a6c4be80b246 100644 --- a/tests/ui/deprecated_old.stderr +++ b/tests/ui/deprecated_old.stderr @@ -7,13 +7,13 @@ LL | #[warn(unstable_as_slice)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 - --> $DIR/deprecated_old.rs:2:8 + --> $DIR/deprecated_old.rs:4:8 | LL | #[warn(unstable_as_mut_slice)] | ^^^^^^^^^^^^^^^^^^^^^ error: lint `misaligned_transmute` has been removed: this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr - --> $DIR/deprecated_old.rs:3:8 + --> $DIR/deprecated_old.rs:6:8 | LL | #[warn(misaligned_transmute)] | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/deref_addrof_double_trigger.rs b/tests/ui/deref_addrof_double_trigger.rs index 190ca5cc0a242..32582a3a8bfa3 100644 --- a/tests/ui/deref_addrof_double_trigger.rs +++ b/tests/ui/deref_addrof_double_trigger.rs @@ -8,10 +8,13 @@ fn main() { //This produces a suggestion of 'let b = *&a;' which //will trigger the 'clippy::deref_addrof' lint again let b = **&&a; + //~^ ERROR: immediately dereferencing a reference + //~| NOTE: `-D clippy::deref-addrof` implied by `-D warnings` { let mut x = 10; let y = *&mut x; + //~^ ERROR: immediately dereferencing a reference } { @@ -19,5 +22,6 @@ fn main() { //will trigger the 'clippy::deref_addrof' lint again let mut x = 10; let y = **&mut &mut x; + //~^ ERROR: immediately dereferencing a reference } } diff --git a/tests/ui/deref_addrof_double_trigger.stderr b/tests/ui/deref_addrof_double_trigger.stderr index 6fa5069b6b4bd..3463f0a1ab73e 100644 --- a/tests/ui/deref_addrof_double_trigger.stderr +++ b/tests/ui/deref_addrof_double_trigger.stderr @@ -7,13 +7,13 @@ LL | let b = **&&a; = note: `-D clippy::deref-addrof` implied by `-D warnings` error: immediately dereferencing a reference - --> $DIR/deref_addrof_double_trigger.rs:14:17 + --> $DIR/deref_addrof_double_trigger.rs:16:17 | LL | let y = *&mut x; | ^^^^^^^ help: try: `x` error: immediately dereferencing a reference - --> $DIR/deref_addrof_double_trigger.rs:21:18 + --> $DIR/deref_addrof_double_trigger.rs:24:18 | LL | let y = **&mut &mut x; | ^^^^^^^^^^^^ help: try: `&mut x` diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs index ff4dcbfa2f2d9..07df50f4661ae 100644 --- a/tests/ui/derive.rs +++ b/tests/ui/derive.rs @@ -9,6 +9,7 @@ struct Qux; impl Clone for Qux { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { Qux } @@ -33,6 +34,7 @@ struct Lt<'a> { } impl<'a> Clone for Lt<'a> { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { unimplemented!() } @@ -44,6 +46,7 @@ struct BigArray { } impl Clone for BigArray { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { unimplemented!() } @@ -55,6 +58,7 @@ struct FnPtr { } impl Clone for FnPtr { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { unimplemented!() } @@ -75,6 +79,7 @@ impl Clone for Generic { #[derive(Copy)] struct Generic2(T); impl Clone for Generic2 { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { Self(self.0.clone()) } diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index f7948e044b7e3..cf8e90cd844e6 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -2,6 +2,7 @@ error: you are implementing `Clone` explicitly on a `Copy` type --> $DIR/derive.rs:11:1 | LL | / impl Clone for Qux { +LL | | LL | | fn clone(&self) -> Self { LL | | Qux LL | | } @@ -12,6 +13,7 @@ note: consider deriving `Clone` or removing `Copy` --> $DIR/derive.rs:11:1 | LL | / impl Clone for Qux { +LL | | LL | | fn clone(&self) -> Self { LL | | Qux LL | | } @@ -20,9 +22,10 @@ LL | | } = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:35:1 + --> $DIR/derive.rs:36:1 | LL | / impl<'a> Clone for Lt<'a> { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -30,9 +33,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:35:1 + --> $DIR/derive.rs:36:1 | LL | / impl<'a> Clone for Lt<'a> { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -40,9 +44,10 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:46:1 + --> $DIR/derive.rs:48:1 | LL | / impl Clone for BigArray { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -50,9 +55,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:46:1 + --> $DIR/derive.rs:48:1 | LL | / impl Clone for BigArray { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -60,9 +66,10 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:57:1 + --> $DIR/derive.rs:60:1 | LL | / impl Clone for FnPtr { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -70,9 +77,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:57:1 + --> $DIR/derive.rs:60:1 | LL | / impl Clone for FnPtr { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -80,9 +88,10 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:77:1 + --> $DIR/derive.rs:81:1 | LL | / impl Clone for Generic2 { +LL | | LL | | fn clone(&self) -> Self { LL | | Self(self.0.clone()) LL | | } @@ -90,9 +99,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:77:1 + --> $DIR/derive.rs:81:1 | LL | / impl Clone for Generic2 { +LL | | LL | | fn clone(&self) -> Self { LL | | Self(self.0.clone()) LL | | } diff --git a/tests/ui/derive_ord_xor_partial_ord.rs b/tests/ui/derive_ord_xor_partial_ord.rs index 1fb3d51c46dc7..2c19942d420c9 100644 --- a/tests/ui/derive_ord_xor_partial_ord.rs +++ b/tests/ui/derive_ord_xor_partial_ord.rs @@ -20,6 +20,7 @@ impl PartialOrd for DeriveBoth { } #[derive(Ord, PartialEq, Eq)] +//~^ ERROR: you are deriving `Ord` but have implemented `PartialOrd` explicitly struct DeriveOrd; impl PartialOrd for DeriveOrd { @@ -29,6 +30,7 @@ impl PartialOrd for DeriveOrd { } #[derive(Ord, PartialEq, Eq)] +//~^ ERROR: you are deriving `Ord` but have implemented `PartialOrd` explicitly struct DeriveOrdWithExplicitTypeVariable; impl PartialOrd for DeriveOrdWithExplicitTypeVariable { @@ -41,6 +43,7 @@ impl PartialOrd for DeriveOrdWithExplicitType struct DerivePartialOrd; impl std::cmp::Ord for DerivePartialOrd { + //~^ ERROR: you are implementing `Ord` explicitly but have derived `PartialOrd` fn cmp(&self, other: &Self) -> Ordering { Ordering::Less } @@ -61,6 +64,7 @@ mod use_ord { struct DerivePartialOrdInUseOrd; impl Ord for DerivePartialOrdInUseOrd { + //~^ ERROR: you are implementing `Ord` explicitly but have derived `PartialOrd` fn cmp(&self, other: &Self) -> Ordering { Ordering::Less } diff --git a/tests/ui/derive_ord_xor_partial_ord.stderr b/tests/ui/derive_ord_xor_partial_ord.stderr index bd14883481404..ee900c5ea2762 100644 --- a/tests/ui/derive_ord_xor_partial_ord.stderr +++ b/tests/ui/derive_ord_xor_partial_ord.stderr @@ -5,7 +5,7 @@ LL | #[derive(Ord, PartialEq, Eq)] | ^^^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:25:1 + --> $DIR/derive_ord_xor_partial_ord.rs:26:1 | LL | impl PartialOrd for DeriveOrd { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,22 +13,23 @@ LL | impl PartialOrd for DeriveOrd { = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Ord` but have implemented `PartialOrd` explicitly - --> $DIR/derive_ord_xor_partial_ord.rs:31:10 + --> $DIR/derive_ord_xor_partial_ord.rs:32:10 | LL | #[derive(Ord, PartialEq, Eq)] | ^^^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:34:1 + --> $DIR/derive_ord_xor_partial_ord.rs:36:1 | LL | impl PartialOrd for DeriveOrdWithExplicitTypeVariable { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Ord` explicitly but have derived `PartialOrd` - --> $DIR/derive_ord_xor_partial_ord.rs:43:1 + --> $DIR/derive_ord_xor_partial_ord.rs:45:1 | LL | / impl std::cmp::Ord for DerivePartialOrd { +LL | | LL | | fn cmp(&self, other: &Self) -> Ordering { LL | | Ordering::Less LL | | } @@ -36,16 +37,17 @@ LL | | } | |_^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:40:10 + --> $DIR/derive_ord_xor_partial_ord.rs:42:10 | LL | #[derive(PartialOrd, PartialEq, Eq)] | ^^^^^^^^^^ = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Ord` explicitly but have derived `PartialOrd` - --> $DIR/derive_ord_xor_partial_ord.rs:63:5 + --> $DIR/derive_ord_xor_partial_ord.rs:66:5 | LL | / impl Ord for DerivePartialOrdInUseOrd { +LL | | LL | | fn cmp(&self, other: &Self) -> Ordering { LL | | Ordering::Less LL | | } @@ -53,7 +55,7 @@ LL | | } | |_____^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:60:14 + --> $DIR/derive_ord_xor_partial_ord.rs:63:14 | LL | #[derive(PartialOrd, PartialEq, Eq)] | ^^^^^^^^^^ diff --git a/tests/ui/derived_hash_with_manual_eq.rs b/tests/ui/derived_hash_with_manual_eq.rs index 8ad09a8de43d5..8423699d99ed8 100644 --- a/tests/ui/derived_hash_with_manual_eq.rs +++ b/tests/ui/derived_hash_with_manual_eq.rs @@ -10,6 +10,7 @@ impl PartialEq for Foo { } #[derive(Hash)] +//~^ ERROR: you are deriving `Hash` but have implemented `PartialEq` explicitly struct Bar; impl PartialEq for Bar { @@ -19,6 +20,7 @@ impl PartialEq for Bar { } #[derive(Hash)] +//~^ ERROR: you are deriving `Hash` but have implemented `PartialEq` explicitly struct Baz; impl PartialEq for Baz { diff --git a/tests/ui/derived_hash_with_manual_eq.stderr b/tests/ui/derived_hash_with_manual_eq.stderr index 230940f25fb60..8ef08f9fa5cbb 100644 --- a/tests/ui/derived_hash_with_manual_eq.stderr +++ b/tests/ui/derived_hash_with_manual_eq.stderr @@ -5,7 +5,7 @@ LL | #[derive(Hash)] | ^^^^ | note: `PartialEq` implemented here - --> $DIR/derived_hash_with_manual_eq.rs:15:1 + --> $DIR/derived_hash_with_manual_eq.rs:16:1 | LL | impl PartialEq for Bar { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -13,13 +13,13 @@ LL | impl PartialEq for Bar { = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Hash` but have implemented `PartialEq` explicitly - --> $DIR/derived_hash_with_manual_eq.rs:21:10 + --> $DIR/derived_hash_with_manual_eq.rs:22:10 | LL | #[derive(Hash)] | ^^^^ | note: `PartialEq` implemented here - --> $DIR/derived_hash_with_manual_eq.rs:24:1 + --> $DIR/derived_hash_with_manual_eq.rs:26:1 | LL | impl PartialEq for Baz { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/disallowed_names.rs b/tests/ui/disallowed_names.rs index 5889f04439ff4..9a701a2cbcfb8 100644 --- a/tests/ui/disallowed_names.rs +++ b/tests/ui/disallowed_names.rs @@ -10,11 +10,16 @@ #![warn(clippy::disallowed_names)] fn test(foo: ()) {} +//~^ ERROR: use of a disallowed/placeholder name `foo` +//~| NOTE: `-D clippy::disallowed-names` implied by `-D warnings` fn main() { let foo = 42; + //~^ ERROR: use of a disallowed/placeholder name `foo` let baz = 42; + //~^ ERROR: use of a disallowed/placeholder name `baz` let quux = 42; + //~^ ERROR: use of a disallowed/placeholder name `quux` // Unlike these others, `bar` is actually considered an acceptable name. // Among many other legitimate uses, bar commonly refers to a period of time in music. // See https://github.com/rust-lang/rust-clippy/issues/5225. @@ -26,23 +31,33 @@ fn main() { match (42, Some(1337), Some(0)) { (foo, Some(baz), quux @ Some(_)) => (), + //~^ ERROR: use of a disallowed/placeholder name `foo` + //~| ERROR: use of a disallowed/placeholder name `baz` + //~| ERROR: use of a disallowed/placeholder name `quux` _ => (), } } fn issue_1647(mut foo: u8) { + //~^ ERROR: use of a disallowed/placeholder name `foo` let mut baz = 0; + //~^ ERROR: use of a disallowed/placeholder name `baz` if let Some(mut quux) = Some(42) {} + //~^ ERROR: use of a disallowed/placeholder name `quux` } fn issue_1647_ref() { let ref baz = 0; + //~^ ERROR: use of a disallowed/placeholder name `baz` if let Some(ref quux) = Some(42) {} + //~^ ERROR: use of a disallowed/placeholder name `quux` } fn issue_1647_ref_mut() { let ref mut baz = 0; + //~^ ERROR: use of a disallowed/placeholder name `baz` if let Some(ref mut quux) = Some(42) {} + //~^ ERROR: use of a disallowed/placeholder name `quux` } mod tests { diff --git a/tests/ui/disallowed_names.stderr b/tests/ui/disallowed_names.stderr index 9ab68b641f137..259501a94e78c 100644 --- a/tests/ui/disallowed_names.stderr +++ b/tests/ui/disallowed_names.stderr @@ -7,79 +7,79 @@ LL | fn test(foo: ()) {} = note: `-D clippy::disallowed-names` implied by `-D warnings` error: use of a disallowed/placeholder name `foo` - --> $DIR/disallowed_names.rs:15:9 + --> $DIR/disallowed_names.rs:17:9 | LL | let foo = 42; | ^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:16:9 + --> $DIR/disallowed_names.rs:19:9 | LL | let baz = 42; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:17:9 + --> $DIR/disallowed_names.rs:21:9 | LL | let quux = 42; | ^^^^ error: use of a disallowed/placeholder name `foo` - --> $DIR/disallowed_names.rs:28:10 + --> $DIR/disallowed_names.rs:33:10 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:28:20 + --> $DIR/disallowed_names.rs:33:20 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:28:26 + --> $DIR/disallowed_names.rs:33:26 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^^ error: use of a disallowed/placeholder name `foo` - --> $DIR/disallowed_names.rs:33:19 + --> $DIR/disallowed_names.rs:41:19 | LL | fn issue_1647(mut foo: u8) { | ^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:34:13 + --> $DIR/disallowed_names.rs:43:13 | LL | let mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:35:21 + --> $DIR/disallowed_names.rs:45:21 | LL | if let Some(mut quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:39:13 + --> $DIR/disallowed_names.rs:50:13 | LL | let ref baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:40:21 + --> $DIR/disallowed_names.rs:52:21 | LL | if let Some(ref quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:44:17 + --> $DIR/disallowed_names.rs:57:17 | LL | let ref mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:45:25 + --> $DIR/disallowed_names.rs:59:25 | LL | if let Some(ref mut quux) = Some(42) {} | ^^^^ diff --git a/tests/ui/disallowed_script_idents.rs b/tests/ui/disallowed_script_idents.rs index 6fc6f9988ebe4..6b68fae318c03 100644 --- a/tests/ui/disallowed_script_idents.rs +++ b/tests/ui/disallowed_script_idents.rs @@ -9,6 +9,8 @@ fn main() { // Cyrillic is not allowed by default. let счётчик = 10; + //~^ ERROR: identifier `счётчик` has a Unicode script that is not allowed by configura // Same for japanese. let カウンタ = 10; + //~^ ERROR: identifier `カウンタ` has a Unicode script that is not allowed by configuratio } diff --git a/tests/ui/disallowed_script_idents.stderr b/tests/ui/disallowed_script_idents.stderr index 7b91d8c426b27..bf5cbe306c681 100644 --- a/tests/ui/disallowed_script_idents.stderr +++ b/tests/ui/disallowed_script_idents.stderr @@ -11,7 +11,7 @@ LL | #![deny(clippy::disallowed_script_idents)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: identifier `カウンタ` has a Unicode script that is not allowed by configuration: Katakana - --> $DIR/disallowed_script_idents.rs:13:9 + --> $DIR/disallowed_script_idents.rs:14:9 | LL | let カウンタ = 10; | ^^^^^^^^ diff --git a/tests/ui/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs index 9b1619baf0e6c..e0acf050949a1 100644 --- a/tests/ui/diverging_sub_expression.rs +++ b/tests/ui/diverging_sub_expression.rs @@ -18,7 +18,10 @@ impl A { fn main() { let b = true; b || diverge(); + //~^ ERROR: sub-expression diverges + //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` b || A.foo(); + //~^ ERROR: sub-expression diverges } #[allow(dead_code, unused_variables)] @@ -29,20 +32,28 @@ fn foobar() { 4 => return, 5 => continue, 6 => true || return, + //~^ ERROR: sub-expression diverges 7 => true || continue, + //~^ ERROR: sub-expression diverges 8 => break, 9 => diverge(), 3 => true || diverge(), + //~^ ERROR: sub-expression diverges 10 => match 42 { 99 => return, _ => true || panic!("boo"), + //~^ ERROR: sub-expression diverges }, // lint blocks as well 15 => true || { return; }, + //~^ ERROR: sub-expression diverges 16 => false || { return; }, + //~^ ERROR: sub-expression diverges // ... and when it's a single expression 17 => true || { return }, + //~^ ERROR: sub-expression diverges 18 => false || { return }, + //~^ ERROR: sub-expression diverges // ... but not when there's both an expression and a statement 19 => true || { _ = 1; return }, 20 => false || { _ = 1; return }, @@ -52,6 +63,7 @@ fn foobar() { 23 => true || { return; true }, 24 => true || { return; true }, _ => true || break, + //~^ ERROR: sub-expression diverges }; } } diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr index 243a5cf5369ad..042e2690ec41e 100644 --- a/tests/ui/diverging_sub_expression.stderr +++ b/tests/ui/diverging_sub_expression.stderr @@ -7,31 +7,31 @@ LL | b || diverge(); = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:21:10 + --> $DIR/diverging_sub_expression.rs:23:10 | LL | b || A.foo(); | ^^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:31:26 + --> $DIR/diverging_sub_expression.rs:34:26 | LL | 6 => true || return, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:32:26 + --> $DIR/diverging_sub_expression.rs:36:26 | LL | 7 => true || continue, | ^^^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:35:26 + --> $DIR/diverging_sub_expression.rs:40:26 | LL | 3 => true || diverge(), | ^^^^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:38:30 + --> $DIR/diverging_sub_expression.rs:44:30 | LL | _ => true || panic!("boo"), | ^^^^^^^^^^^^^ @@ -39,31 +39,31 @@ LL | _ => true || panic!("boo"), = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:41:29 + --> $DIR/diverging_sub_expression.rs:48:29 | LL | 15 => true || { return; }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:42:30 + --> $DIR/diverging_sub_expression.rs:50:30 | LL | 16 => false || { return; }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:44:29 + --> $DIR/diverging_sub_expression.rs:53:29 | LL | 17 => true || { return }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:45:30 + --> $DIR/diverging_sub_expression.rs:55:30 | LL | 18 => false || { return }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:54:26 + --> $DIR/diverging_sub_expression.rs:65:26 | LL | _ => true || break, | ^^^^^ diff --git a/tests/ui/doc/unbalanced_ticks.rs b/tests/ui/doc/unbalanced_ticks.rs index 101434b4f3be5..4a1711f79a020 100644 --- a/tests/ui/doc/unbalanced_ticks.rs +++ b/tests/ui/doc/unbalanced_ticks.rs @@ -5,16 +5,20 @@ #![warn(clippy::doc_markdown)] /// This is a doc comment with `unbalanced_tick marks and several words that +//~^ ERROR: backticks are unbalanced /// should be `encompassed_by` tick marks because they `contain_underscores`. /// Because of the initial `unbalanced_tick` pair, the error message is /// very `confusing_and_misleading`. fn main() {} /// This paragraph has `unbalanced_tick marks and should stop_linting. +//~^ ERROR: backticks are unbalanced /// /// This paragraph is fine and should_be linted normally. +//~^ ERROR: item in documentation is missing backticks /// /// Double unbalanced backtick from ``here to here` should lint. +//~^ ERROR: backticks are unbalanced /// /// Double balanced back ticks ``start end`` is fine. fn multiple_paragraphs() {} @@ -28,11 +32,15 @@ fn in_code_block() {} /// # `Fine` /// /// ## not_fine +//~^ ERROR: item in documentation is missing backticks /// /// ### `unbalanced +//~^ ERROR: backticks are unbalanced /// /// - This `item has unbalanced tick marks +//~^ ERROR: backticks are unbalanced /// - This item needs backticks_here +//~^ ERROR: item in documentation is missing backticks fn other_markdown() {} #[rustfmt::skip] diff --git a/tests/ui/doc/unbalanced_ticks.stderr b/tests/ui/doc/unbalanced_ticks.stderr index f2ac6bc3269aa..7a3544288be85 100644 --- a/tests/ui/doc/unbalanced_ticks.stderr +++ b/tests/ui/doc/unbalanced_ticks.stderr @@ -2,6 +2,7 @@ error: backticks are unbalanced --> $DIR/unbalanced_ticks.rs:7:1 | 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 LL | | /// very `confusing_and_misleading`. @@ -11,7 +12,7 @@ LL | | /// very `confusing_and_misleading`. = note: `-D clippy::doc-markdown` implied by `-D warnings` error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:13:1 + --> $DIR/unbalanced_ticks.rs:14:1 | LL | /// This paragraph has `unbalanced_tick marks and should stop_linting. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,7 +20,7 @@ LL | /// This paragraph has `unbalanced_tick marks and should stop_linting. = help: a backtick may be missing a pair error: item in documentation is missing backticks - --> $DIR/unbalanced_ticks.rs:15:32 + --> $DIR/unbalanced_ticks.rs:17:32 | LL | /// This paragraph is fine and should_be linted normally. | ^^^^^^^^^ @@ -30,7 +31,7 @@ LL | /// This paragraph is fine and `should_be` linted normally. | ~~~~~~~~~~~ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:17:1 + --> $DIR/unbalanced_ticks.rs:20:1 | LL | /// Double unbalanced backtick from ``here to here` should lint. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +39,7 @@ LL | /// Double unbalanced backtick from ``here to here` should lint. = help: a backtick may be missing a pair error: item in documentation is missing backticks - --> $DIR/unbalanced_ticks.rs:30:8 + --> $DIR/unbalanced_ticks.rs:34:8 | LL | /// ## not_fine | ^^^^^^^^ @@ -49,7 +50,7 @@ LL | /// ## `not_fine` | ~~~~~~~~~~ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:32:1 + --> $DIR/unbalanced_ticks.rs:37:1 | LL | /// ### `unbalanced | ^^^^^^^^^^^^^^^^^^^ @@ -57,7 +58,7 @@ LL | /// ### `unbalanced = help: a backtick may be missing a pair error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:34:1 + --> $DIR/unbalanced_ticks.rs:40:1 | LL | /// - This `item has unbalanced tick marks | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,7 +66,7 @@ LL | /// - This `item has unbalanced tick marks = help: a backtick may be missing a pair error: item in documentation is missing backticks - --> $DIR/unbalanced_ticks.rs:35:23 + --> $DIR/unbalanced_ticks.rs:42:23 | LL | /// - This item needs backticks_here | ^^^^^^^^^^^^^^ diff --git a/tests/ui/doc_errors.rs b/tests/ui/doc_errors.rs index 30fdd3b087371..86721f61d199c 100644 --- a/tests/ui/doc_errors.rs +++ b/tests/ui/doc_errors.rs @@ -5,20 +5,25 @@ use std::io; pub fn pub_fn_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section + //~| NOTE: `-D clippy::missing-errors-doc` implied by `-D warnings` unimplemented!(); } pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } /// This is not sufficiently documented. pub fn pub_fn_returning_io_result() -> io::Result<()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } /// This is not sufficiently documented. pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } @@ -49,11 +54,13 @@ pub struct Struct1; impl Struct1 { /// This is not sufficiently documented. pub fn pub_method_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } /// This is not sufficiently documented. pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } @@ -83,6 +90,7 @@ impl Struct1 { pub trait Trait1 { /// This is not sufficiently documented. fn trait_method_missing_errors_header() -> Result<(), ()>; + //~^ ERROR: docs for function returning `Result` missing `# Errors` section /// # Errors /// A description of the errors goes here. diff --git a/tests/ui/doc_errors.stderr b/tests/ui/doc_errors.stderr index d74f2dbfe1baa..a0356623003e8 100644 --- a/tests/ui/doc_errors.stderr +++ b/tests/ui/doc_errors.stderr @@ -7,37 +7,37 @@ LL | pub fn pub_fn_missing_errors_header() -> Result<(), ()> { = note: `-D clippy::missing-errors-doc` implied by `-D warnings` error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:11:1 + --> $DIR/doc_errors.rs:13:1 | LL | pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:16:1 + --> $DIR/doc_errors.rs:19:1 | LL | pub fn pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:21:1 + --> $DIR/doc_errors.rs:25:1 | LL | pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:51:5 + --> $DIR/doc_errors.rs:56:5 | LL | pub fn pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:56:5 + --> $DIR/doc_errors.rs:62:5 | LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:85:5 + --> $DIR/doc_errors.rs:92:5 | LL | fn trait_method_missing_errors_header() -> Result<(), ()>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/doc_link_with_quotes.rs b/tests/ui/doc_link_with_quotes.rs index 17c04c34e2461..37d0d13595737 100644 --- a/tests/ui/doc_link_with_quotes.rs +++ b/tests/ui/doc_link_with_quotes.rs @@ -5,6 +5,8 @@ fn main() { } /// Calls ['bar'] uselessly +//~^ ERROR: possible intra-doc link using quotes instead of backticks +//~| NOTE: `-D clippy::doc-link-with-quotes` implied by `-D warnings` pub fn foo() { bar() } diff --git a/tests/ui/double_must_use.rs b/tests/ui/double_must_use.rs index 26a387b3cf049..615de3e24743c 100644 --- a/tests/ui/double_must_use.rs +++ b/tests/ui/double_must_use.rs @@ -3,16 +3,19 @@ #[must_use] pub fn must_use_result() -> Result<(), ()> { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already unimplemented!(); } #[must_use] pub fn must_use_tuple() -> (Result<(), ()>, u8) { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already unimplemented!(); } #[must_use] pub fn must_use_array() -> [Result<(), ()>; 1] { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already unimplemented!(); } @@ -29,6 +32,7 @@ async fn async_must_use() -> usize { #[must_use] async fn async_must_use_result() -> Result<(), ()> { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already Ok(()) } diff --git a/tests/ui/double_must_use.stderr b/tests/ui/double_must_use.stderr index 49ab2ea3e12b4..46d56006ebfce 100644 --- a/tests/ui/double_must_use.stderr +++ b/tests/ui/double_must_use.stderr @@ -8,7 +8,7 @@ LL | pub fn must_use_result() -> Result<(), ()> { = note: `-D clippy::double-must-use` implied by `-D warnings` error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:10:1 + --> $DIR/double_must_use.rs:11:1 | LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { = help: either add some descriptive text or remove the attribute error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:15:1 + --> $DIR/double_must_use.rs:17:1 | LL | pub fn must_use_array() -> [Result<(), ()>; 1] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | pub fn must_use_array() -> [Result<(), ()>; 1] { = help: either add some descriptive text or remove the attribute error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:31:1 + --> $DIR/double_must_use.rs:34:1 | LL | async fn async_must_use_result() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/double_neg.rs b/tests/ui/double_neg.rs index 38a8fbd74dcf6..da82890443eb8 100644 --- a/tests/ui/double_neg.rs +++ b/tests/ui/double_neg.rs @@ -5,4 +5,6 @@ fn main() { -x; -(-x); --x; + //~^ ERROR: `--x` could be misinterpreted as pre-decrement by C programmers, is usuall + //~| NOTE: `-D clippy::double-neg` implied by `-D warnings` } diff --git a/tests/ui/double_parens.rs b/tests/ui/double_parens.rs index ff1dc76ab63b1..ab1459eed48bc 100644 --- a/tests/ui/double_parens.rs +++ b/tests/ui/double_parens.rs @@ -13,22 +13,28 @@ impl DummyStruct { fn simple_double_parens() -> i32 { ((0)) + //~^ ERROR: consider removing unnecessary double parentheses + //~| NOTE: `-D clippy::double-parens` implied by `-D warnings` } fn fn_double_parens() { dummy_fn((0)); + //~^ ERROR: consider removing unnecessary double parentheses } fn method_double_parens(x: DummyStruct) { x.dummy_method((0)); + //~^ ERROR: consider removing unnecessary double parentheses } fn tuple_double_parens() -> (i32, i32) { ((1, 2)) + //~^ ERROR: consider removing unnecessary double parentheses } fn unit_double_parens() { (()) + //~^ ERROR: consider removing unnecessary double parentheses } fn fn_tuple_ok() { @@ -51,6 +57,7 @@ fn method_unit_ok(x: DummyStruct) { fn inside_macro() { assert_eq!((1, 2), (1, 2), "Error"); assert_eq!(((1, 2)), (1, 2), "Error"); + //~^ ERROR: consider removing unnecessary double parentheses } fn main() {} diff --git a/tests/ui/double_parens.stderr b/tests/ui/double_parens.stderr index 40fcad2ab1d4a..303ddce024837 100644 --- a/tests/ui/double_parens.stderr +++ b/tests/ui/double_parens.stderr @@ -7,31 +7,31 @@ LL | ((0)) = note: `-D clippy::double-parens` implied by `-D warnings` error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:19:14 + --> $DIR/double_parens.rs:21:14 | LL | dummy_fn((0)); | ^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:23:20 + --> $DIR/double_parens.rs:26:20 | LL | x.dummy_method((0)); | ^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:27:5 + --> $DIR/double_parens.rs:31:5 | LL | ((1, 2)) | ^^^^^^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:31:5 + --> $DIR/double_parens.rs:36:5 | LL | (()) | ^^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:53:16 + --> $DIR/double_parens.rs:59:16 | LL | assert_eq!(((1, 2)), (1, 2), "Error"); | ^^^^^^^^ diff --git a/tests/ui/drop_non_drop.rs b/tests/ui/drop_non_drop.rs index 5a0ebde82c5d4..6dbcb7777d49e 100644 --- a/tests/ui/drop_non_drop.rs +++ b/tests/ui/drop_non_drop.rs @@ -20,6 +20,7 @@ fn main() { struct Foo; // Lint drop(Foo); + //~^ ERROR: call to `std::mem::drop` with a value that does not implement `Drop`. Drop // Don't lint drop(make_result(Foo)); // Don't lint @@ -35,6 +36,7 @@ fn main() { struct Baz(T); // Lint drop(Baz(Foo)); + //~^ ERROR: call to `std::mem::drop` with a value that does not implement `Drop`. Drop // Don't lint drop(Baz(Bar)); } diff --git a/tests/ui/drop_non_drop.stderr b/tests/ui/drop_non_drop.stderr index b86057c0c321f..15e7c6eeca276 100644 --- a/tests/ui/drop_non_drop.stderr +++ b/tests/ui/drop_non_drop.stderr @@ -12,13 +12,13 @@ LL | drop(Foo); = note: `-D clippy::drop-non-drop` implied by `-D warnings` error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_non_drop.rs:37:5 + --> $DIR/drop_non_drop.rs:38:5 | LL | drop(Baz(Foo)); | ^^^^^^^^^^^^^^ | note: argument has type `main::Baz` - --> $DIR/drop_non_drop.rs:37:10 + --> $DIR/drop_non_drop.rs:38:10 | LL | drop(Baz(Foo)); | ^^^^^^^^ diff --git a/tests/ui/duplicate_underscore_argument.rs b/tests/ui/duplicate_underscore_argument.rs index 54d748c7ce280..118f6e4a34c0a 100644 --- a/tests/ui/duplicate_underscore_argument.rs +++ b/tests/ui/duplicate_underscore_argument.rs @@ -2,6 +2,8 @@ #[allow(dead_code, unused)] fn join_the_dark_side(darth: i32, _darth: i32) {} +//~^ ERROR: `darth` already exists, having another argument having almost the same name ma +//~| NOTE: `-D clippy::duplicate-underscore-argument` implied by `-D warnings` fn join_the_light_side(knight: i32, _master: i32) {} // the Force is strong with this one fn main() { diff --git a/tests/ui/empty_enum.rs b/tests/ui/empty_enum.rs index a2e5c13c45282..77357c15d957f 100644 --- a/tests/ui/empty_enum.rs +++ b/tests/ui/empty_enum.rs @@ -3,5 +3,6 @@ // Enable never type to test empty enum lint #![feature(never_type)] enum Empty {} +//~^ ERROR: enum with no variants fn main() {} diff --git a/tests/ui/empty_loop_no_std.rs b/tests/ui/empty_loop_no_std.rs index f9ab443dfd94a..5fe32351ed450 100644 --- a/tests/ui/empty_loop_no_std.rs +++ b/tests/ui/empty_loop_no_std.rs @@ -11,6 +11,7 @@ use core::panic::PanicInfo; fn main(argc: isize, argv: *const *const u8) -> isize { // This should trigger the lint loop {} + //~^ ERROR: empty `loop {}` wastes CPU cycles } #[panic_handler] @@ -23,4 +24,5 @@ fn panic(_info: &PanicInfo) -> ! { extern "C" fn eh_personality() { // This should also trigger the lint loop {} + //~^ ERROR: empty `loop {}` wastes CPU cycles } diff --git a/tests/ui/empty_loop_no_std.stderr b/tests/ui/empty_loop_no_std.stderr index 71af64f49d522..417b7f01c78a9 100644 --- a/tests/ui/empty_loop_no_std.stderr +++ b/tests/ui/empty_loop_no_std.stderr @@ -8,7 +8,7 @@ LL | loop {} = note: `-D clippy::empty-loop` implied by `-D warnings` error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop_no_std.rs:25:5 + --> $DIR/empty_loop_no_std.rs:26:5 | LL | loop {} | ^^^^^^^ diff --git a/tests/ui/enum_clike_unportable_variant.rs b/tests/ui/enum_clike_unportable_variant.rs index abe42a2305f52..964e5634ddb11 100644 --- a/tests/ui/enum_clike_unportable_variant.rs +++ b/tests/ui/enum_clike_unportable_variant.rs @@ -6,6 +6,8 @@ #[repr(usize)] enum NonPortable { X = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~| NOTE: `-D clippy::enum-clike-unportable-variant` implied by `-D warnings` Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, @@ -13,9 +15,11 @@ enum NonPortable { enum NonPortableNoHint { X = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets } #[repr(isize)] @@ -23,21 +27,27 @@ enum NonPortableSigned { X = -1, Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets A = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets B = i32::MIN as isize, C = (i32::MIN as isize) - 1, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets } enum NonPortableSignedNoHint { X = -1, Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets A = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets } #[repr(usize)] enum NonPortable2 { X = ::Number, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets Y = 0, } diff --git a/tests/ui/enum_variants.rs b/tests/ui/enum_variants.rs index 531652a0e0026..85df852f72965 100644 --- a/tests/ui/enum_variants.rs +++ b/tests/ui/enum_variants.rs @@ -12,7 +12,10 @@ enum FakeCallType2 { } enum Foo { + //~^ ERROR: all variants have the same prefix: `c` cFoo, + //~^ ERROR: variant name ends with the enum's name + //~| NOTE: `-D clippy::enum-variant-names` implied by `-D warnings` cBar, cBaz, } @@ -23,9 +26,13 @@ enum Fooo { } enum Food { + //~^ ERROR: all variants have the same prefix: `Food` FoodGood, + //~^ ERROR: variant name starts with the enum's name FoodMiddle, + //~^ ERROR: variant name starts with the enum's name FoodBad, + //~^ ERROR: variant name starts with the enum's name } enum Stuff { @@ -33,6 +40,7 @@ enum Stuff { } enum BadCallType { + //~^ ERROR: all variants have the same prefix: `CallType` CallTypeCall, CallTypeCreate, CallTypeDestroy, @@ -45,6 +53,7 @@ enum TwoCallType { } enum Consts { + //~^ ERROR: all variants have the same prefix: `Constant` ConstantInt, ConstantCake, ConstantLie, @@ -57,6 +66,7 @@ enum Two { } enum Something { + //~^ ERROR: all variants have the same prefix: `C` CCall, CCreate, CCryogenize, @@ -79,6 +89,7 @@ enum Sealll { } enum Seallll { + //~^ ERROR: all variants have the same prefix: `WithOut` WithOutCake, WithOutTea, WithOut, @@ -134,12 +145,14 @@ pub enum NetworkLayer { // should lint suggesting `IData`, not only `Data` (see #4639) enum IDataRequest { + //~^ ERROR: all variants have the same postfix: `IData` PutIData(String), GetIData(String), DeleteUnpubIData(String), } enum HIDataRequest { + //~^ ERROR: all variants have the same postfix: `HIData` PutHIData(String), GetHIData(String), DeleteUnpubHIData(String), @@ -160,6 +173,7 @@ enum Phase { mod issue9018 { enum DoLint { + //~^ ERROR: all variants have the same prefix: `_Type` _TypeCreate, _TypeRead, _TypeUpdate, @@ -167,6 +181,7 @@ mod issue9018 { } enum DoLintToo { + //~^ ERROR: all variants have the same postfix: `Type` _CreateType, _UpdateType, _DeleteType, diff --git a/tests/ui/enum_variants.stderr b/tests/ui/enum_variants.stderr index 7342aff80f016..1cfe48cd797f9 100644 --- a/tests/ui/enum_variants.stderr +++ b/tests/ui/enum_variants.stderr @@ -1,5 +1,5 @@ error: variant name ends with the enum's name - --> $DIR/enum_variants.rs:15:5 + --> $DIR/enum_variants.rs:16:5 | LL | cFoo, | ^^^^ @@ -10,8 +10,10 @@ error: all variants have the same prefix: `c` --> $DIR/enum_variants.rs:14:1 | LL | / enum Foo { +LL | | LL | | cFoo, -LL | | cBar, +LL | | +... | LL | | cBaz, LL | | } | |_^ @@ -19,39 +21,42 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:26:5 + --> $DIR/enum_variants.rs:30:5 | LL | FoodGood, | ^^^^^^^^ error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:27:5 + --> $DIR/enum_variants.rs:32:5 | LL | FoodMiddle, | ^^^^^^^^^^ error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:28:5 + --> $DIR/enum_variants.rs:34:5 | LL | FoodBad, | ^^^^^^^ error: all variants have the same prefix: `Food` - --> $DIR/enum_variants.rs:25:1 + --> $DIR/enum_variants.rs:28:1 | LL | / enum Food { +LL | | LL | | FoodGood, -LL | | FoodMiddle, -LL | | FoodBad, +LL | | +... | +LL | | LL | | } | |_^ | = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `CallType` - --> $DIR/enum_variants.rs:35:1 + --> $DIR/enum_variants.rs:42:1 | LL | / enum BadCallType { +LL | | LL | | CallTypeCall, LL | | CallTypeCreate, LL | | CallTypeDestroy, @@ -61,9 +66,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `Constant` - --> $DIR/enum_variants.rs:47:1 + --> $DIR/enum_variants.rs:55:1 | LL | / enum Consts { +LL | | LL | | ConstantInt, LL | | ConstantCake, LL | | ConstantLie, @@ -73,9 +79,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `C` - --> $DIR/enum_variants.rs:59:1 + --> $DIR/enum_variants.rs:68:1 | LL | / enum Something { +LL | | LL | | CCall, LL | | CCreate, LL | | CCryogenize, @@ -85,9 +92,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `WithOut` - --> $DIR/enum_variants.rs:81:1 + --> $DIR/enum_variants.rs:91:1 | LL | / enum Seallll { +LL | | LL | | WithOutCake, LL | | WithOutTea, LL | | WithOut, @@ -97,9 +105,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `IData` - --> $DIR/enum_variants.rs:136:1 + --> $DIR/enum_variants.rs:147:1 | LL | / enum IDataRequest { +LL | | LL | | PutIData(String), LL | | GetIData(String), LL | | DeleteUnpubIData(String), @@ -109,9 +118,10 @@ LL | | } = help: remove the postfixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `HIData` - --> $DIR/enum_variants.rs:142:1 + --> $DIR/enum_variants.rs:154:1 | LL | / enum HIDataRequest { +LL | | LL | | PutHIData(String), LL | | GetHIData(String), LL | | DeleteUnpubHIData(String), @@ -121,9 +131,10 @@ LL | | } = help: remove the postfixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `_Type` - --> $DIR/enum_variants.rs:162:5 + --> $DIR/enum_variants.rs:175:5 | LL | / enum DoLint { +LL | | LL | | _TypeCreate, LL | | _TypeRead, LL | | _TypeUpdate, @@ -134,9 +145,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `Type` - --> $DIR/enum_variants.rs:169:5 + --> $DIR/enum_variants.rs:183:5 | LL | / enum DoLintToo { +LL | | LL | | _CreateType, LL | | _UpdateType, LL | | _DeleteType, diff --git a/tests/ui/eprint_with_newline.fixed b/tests/ui/eprint_with_newline.fixed index d0349e68622a6..7383d784c8410 100644 --- a/tests/ui/eprint_with_newline.fixed +++ b/tests/ui/eprint_with_newline.fixed @@ -3,10 +3,16 @@ fn main() { eprintln!("Hello"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` eprintln!("Hello {}", "world"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprintln!("Hello {} {}", "world", "#2"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprintln!("{}", 1265); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprintln!(); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline // these are all fine eprint!(""); @@ -29,6 +35,7 @@ fn main() { // #3514 eprint!("\\n"); eprintln!("\\"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("\\\\n"); // Raw strings @@ -37,9 +44,11 @@ fn main() { // Literal newlines should also fail eprintln!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline ); eprintln!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline ); @@ -47,6 +56,7 @@ fn main() { eprint!("\r\n"); eprint!("foo\r\n"); eprintln!("\\r"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/eprint_with_newline.rs b/tests/ui/eprint_with_newline.rs index 9446d5d651a17..5b114056411d9 100644 --- a/tests/ui/eprint_with_newline.rs +++ b/tests/ui/eprint_with_newline.rs @@ -3,10 +3,16 @@ fn main() { eprint!("Hello\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` eprint!("Hello {}\n", "world"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("Hello {} {}\n", "world", "#2"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("{}\n", 1265); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline // these are all fine eprint!(""); @@ -29,6 +35,7 @@ fn main() { // #3514 eprint!("\\n"); eprint!("\\\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("\\\\n"); // Raw strings @@ -37,10 +44,12 @@ fn main() { // Literal newlines should also fail eprint!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline " " ); eprint!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline r" " ); @@ -49,6 +58,7 @@ fn main() { eprint!("\r\n"); eprint!("foo\r\n"); eprint!("\\r\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/eprint_with_newline.stderr b/tests/ui/eprint_with_newline.stderr index e92b1ba672fe7..934c4c8317314 100644 --- a/tests/ui/eprint_with_newline.stderr +++ b/tests/ui/eprint_with_newline.stderr @@ -12,7 +12,7 @@ LL + eprintln!("Hello"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:6:5 + --> $DIR/eprint_with_newline.rs:8:5 | LL | eprint!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + eprintln!("Hello {}", "world"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:7:5 + --> $DIR/eprint_with_newline.rs:10:5 | LL | eprint!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + eprintln!("Hello {} {}", "world", "#2"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:8:5 + --> $DIR/eprint_with_newline.rs:12:5 | LL | eprint!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + eprintln!("{}", 1265); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:9:5 + --> $DIR/eprint_with_newline.rs:14:5 | LL | eprint!("\n"); | ^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + eprintln!(); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:31:5 + --> $DIR/eprint_with_newline.rs:37:5 | LL | eprint!("\\\n"); | ^^^^^^^^^^^^^^^ @@ -72,9 +72,10 @@ LL + eprintln!("\\"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:39:5 + --> $DIR/eprint_with_newline.rs:46:5 | LL | / eprint!( +LL | | LL | | " LL | | " LL | | ); @@ -83,13 +84,15 @@ LL | | ); help: use `eprintln!` instead | LL ~ eprintln!( +LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:43:5 + --> $DIR/eprint_with_newline.rs:51:5 | LL | / eprint!( +LL | | LL | | r" LL | | " LL | | ); @@ -98,11 +101,12 @@ LL | | ); help: use `eprintln!` instead | LL ~ eprintln!( +LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:51:5 + --> $DIR/eprint_with_newline.rs:60:5 | LL | eprint!("\\r\n"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/eq_op.rs b/tests/ui/eq_op.rs index e973e5ba2fb1e..7c2c131875182 100644 --- a/tests/ui/eq_op.rs +++ b/tests/ui/eq_op.rs @@ -5,51 +5,80 @@ fn main() { // simple values and comparisons let _ = 1 == 1; + //~^ ERROR: equal expressions as operands to `==` + //~| NOTE: `-D clippy::eq-op` implied by `-D warnings` let _ = "no" == "no"; + //~^ ERROR: equal expressions as operands to `==` // even though I agree that no means no ;-) let _ = false != false; + //~^ ERROR: equal expressions as operands to `!=` let _ = 1.5 < 1.5; + //~^ ERROR: equal expressions as operands to `<` let _ = 1u64 >= 1u64; + //~^ ERROR: equal expressions as operands to `>=` let x = f32::NAN; let _ = x != x; + //~^ ERROR: equal expressions as operands to `!=` + //~| NOTE: if you intended to check if the operand is NaN, use `.is_nan()` instead // casts, methods, parentheses let _ = (1u32 as u64) & (1u32 as u64); + //~^ ERROR: equal expressions as operands to `&` #[rustfmt::skip] { let _ = 1 ^ ((((((1)))))); + //~^ ERROR: equal expressions as operands to `^` }; // unary and binary operators let _ = (-(2) < -(2)); + //~^ ERROR: equal expressions as operands to `<` let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); + //~^ ERROR: equal expressions as operands to `==` + //~| ERROR: equal expressions as operands to `&` + //~| ERROR: equal expressions as operands to `&` let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; + //~^ ERROR: equal expressions as operands to `==` // various other things let _ = ([1] != [1]); + //~^ ERROR: equal expressions as operands to `!=` let _ = ((1, 2) != (1, 2)); + //~^ ERROR: equal expressions as operands to `!=` let _ = vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros // const folding let _ = 1 + 1 == 2; + //~^ ERROR: equal expressions as operands to `==` let _ = 1 - 1 == 0; + //~^ ERROR: equal expressions as operands to `==` + //~| ERROR: equal expressions as operands to `-` let _ = 1 - 1; + //~^ ERROR: equal expressions as operands to `-` let _ = 1 / 1; + //~^ ERROR: equal expressions as operands to `/` let _ = true && true; + //~^ ERROR: equal expressions as operands to `&&` let _ = true || true; + //~^ ERROR: equal expressions as operands to `||` let a: u32 = 0; let b: u32 = 0; let _ = a == b && b == a; + //~^ ERROR: equal expressions as operands to `&&` let _ = a != b && b != a; + //~^ ERROR: equal expressions as operands to `&&` let _ = a < b && b > a; + //~^ ERROR: equal expressions as operands to `&&` let _ = a <= b && b >= a; + //~^ ERROR: equal expressions as operands to `&&` let mut a = vec![1]; let _ = a == a; + //~^ ERROR: equal expressions as operands to `==` let _ = 2 * a.len() == 2 * a.len(); // ok, functions let _ = a.pop() == a.pop(); // ok, functions @@ -60,6 +89,7 @@ fn main() { const B: u32 = 10; const C: u32 = A / B; // ok, different named constants const D: u32 = A / A; + //~^ ERROR: equal expressions as operands to `/` } macro_rules! check_if_named_foo { @@ -91,6 +121,7 @@ struct Nested { fn check_nested(n1: &Nested, n2: &Nested) -> bool { // `n2.inner.0.0` mistyped as `n1.inner.0.0` (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 + //~^ ERROR: equal expressions as operands to `==` } #[test] diff --git a/tests/ui/eq_op.stderr b/tests/ui/eq_op.stderr index c7fa253bdca26..315d94cc90e62 100644 --- a/tests/ui/eq_op.stderr +++ b/tests/ui/eq_op.stderr @@ -7,31 +7,31 @@ LL | let _ = 1 == 1; = note: `-D clippy::eq-op` implied by `-D warnings` error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:8:13 + --> $DIR/eq_op.rs:10:13 | LL | let _ = "no" == "no"; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:10:13 + --> $DIR/eq_op.rs:13:13 | LL | let _ = false != false; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:11:13 + --> $DIR/eq_op.rs:15:13 | LL | let _ = 1.5 < 1.5; | ^^^^^^^^^ error: equal expressions as operands to `>=` - --> $DIR/eq_op.rs:12:13 + --> $DIR/eq_op.rs:17:13 | LL | let _ = 1u64 >= 1u64; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:14:13 + --> $DIR/eq_op.rs:20:13 | LL | let _ = x != x; | ^^^^^^ @@ -39,139 +39,139 @@ LL | let _ = x != x; = note: if you intended to check if the operand is NaN, use `.is_nan()` instead error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:17:13 + --> $DIR/eq_op.rs:25:13 | LL | let _ = (1u32 as u64) & (1u32 as u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `^` - --> $DIR/eq_op.rs:20:17 + --> $DIR/eq_op.rs:29:17 | LL | let _ = 1 ^ ((((((1)))))); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:24:13 + --> $DIR/eq_op.rs:34:13 | LL | let _ = (-(2) < -(2)); | ^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:25:13 + --> $DIR/eq_op.rs:36:13 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:25:14 + --> $DIR/eq_op.rs:36:14 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:25:35 + --> $DIR/eq_op.rs:36:35 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:26:13 + --> $DIR/eq_op.rs:40:13 | LL | let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:29:13 + --> $DIR/eq_op.rs:44:13 | LL | let _ = ([1] != [1]); | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:30:13 + --> $DIR/eq_op.rs:46:13 | LL | let _ = ((1, 2) != (1, 2)); | ^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:34:13 + --> $DIR/eq_op.rs:51:13 | LL | let _ = 1 + 1 == 2; | ^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:35:13 + --> $DIR/eq_op.rs:53:13 | LL | let _ = 1 - 1 == 0; | ^^^^^^^^^^ error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:35:13 + --> $DIR/eq_op.rs:53:13 | LL | let _ = 1 - 1 == 0; | ^^^^^ error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:37:13 + --> $DIR/eq_op.rs:57:13 | LL | let _ = 1 - 1; | ^^^^^ error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:38:13 + --> $DIR/eq_op.rs:59:13 | LL | let _ = 1 / 1; | ^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:39:13 + --> $DIR/eq_op.rs:61:13 | LL | let _ = true && true; | ^^^^^^^^^^^^ error: equal expressions as operands to `||` - --> $DIR/eq_op.rs:41:13 + --> $DIR/eq_op.rs:64:13 | LL | let _ = true || true; | ^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:46:13 + --> $DIR/eq_op.rs:70:13 | LL | let _ = a == b && b == a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:47:13 + --> $DIR/eq_op.rs:72:13 | LL | let _ = a != b && b != a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:48:13 + --> $DIR/eq_op.rs:74:13 | LL | let _ = a < b && b > a; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:49:13 + --> $DIR/eq_op.rs:76:13 | LL | let _ = a <= b && b >= a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:52:13 + --> $DIR/eq_op.rs:80:13 | LL | let _ = a == a; | ^^^^^^ error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:62:20 + --> $DIR/eq_op.rs:91:20 | LL | const D: u32 = A / A; | ^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:93:5 + --> $DIR/eq_op.rs:123:5 | LL | (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/eq_op_macros.rs b/tests/ui/eq_op_macros.rs index 4824067722890..a511af4a31c8c 100644 --- a/tests/ui/eq_op_macros.rs +++ b/tests/ui/eq_op_macros.rs @@ -21,7 +21,9 @@ fn main() { // lint identical args in `assert_eq!` assert_eq!(a, a); + //~^ ERROR: identical args used in this `assert_eq!` macro call assert_eq!(a + 1, a + 1); + //~^ ERROR: identical args used in this `assert_eq!` macro call // ok assert_eq!(a, b); assert_eq!(a, a + 1); @@ -29,7 +31,9 @@ fn main() { // lint identical args in `assert_ne!` assert_ne!(a, a); + //~^ ERROR: identical args used in this `assert_ne!` macro call assert_ne!(a + 1, a + 1); + //~^ ERROR: identical args used in this `assert_ne!` macro call // ok assert_ne!(a, b); assert_ne!(a, a + 1); @@ -37,7 +41,9 @@ fn main() { // lint identical args in `debug_assert_eq!` debug_assert_eq!(a, a); + //~^ ERROR: identical args used in this `debug_assert_eq!` macro call debug_assert_eq!(a + 1, a + 1); + //~^ ERROR: identical args used in this `debug_assert_eq!` macro call // ok debug_assert_eq!(a, b); debug_assert_eq!(a, a + 1); @@ -45,7 +51,9 @@ fn main() { // lint identical args in `debug_assert_ne!` debug_assert_ne!(a, a); + //~^ ERROR: identical args used in this `debug_assert_ne!` macro call debug_assert_ne!(a + 1, a + 1); + //~^ ERROR: identical args used in this `debug_assert_ne!` macro call // ok debug_assert_ne!(a, b); debug_assert_ne!(a, a + 1); diff --git a/tests/ui/eq_op_macros.stderr b/tests/ui/eq_op_macros.stderr index cb9b0c01862bf..3c60cdbc5ca95 100644 --- a/tests/ui/eq_op_macros.stderr +++ b/tests/ui/eq_op_macros.stderr @@ -50,43 +50,43 @@ LL | assert_eq!(a, a); | ^^^^ error: identical args used in this `assert_eq!` macro call - --> $DIR/eq_op_macros.rs:24:16 + --> $DIR/eq_op_macros.rs:25:16 | LL | assert_eq!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `assert_ne!` macro call - --> $DIR/eq_op_macros.rs:31:16 + --> $DIR/eq_op_macros.rs:33:16 | LL | assert_ne!(a, a); | ^^^^ error: identical args used in this `assert_ne!` macro call - --> $DIR/eq_op_macros.rs:32:16 + --> $DIR/eq_op_macros.rs:35:16 | LL | assert_ne!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:39:22 + --> $DIR/eq_op_macros.rs:43:22 | LL | debug_assert_eq!(a, a); | ^^^^ error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:40:22 + --> $DIR/eq_op_macros.rs:45:22 | LL | debug_assert_eq!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:47:22 + --> $DIR/eq_op_macros.rs:53:22 | LL | debug_assert_ne!(a, a); | ^^^^ error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:48:22 + --> $DIR/eq_op_macros.rs:55:22 | LL | debug_assert_ne!(a + 1, a + 1); | ^^^^^^^^^^^^ diff --git a/tests/ui/erasing_op.rs b/tests/ui/erasing_op.rs index 74985029e008a..00c74f23fed04 100644 --- a/tests/ui/erasing_op.rs +++ b/tests/ui/erasing_op.rs @@ -33,11 +33,17 @@ impl core::ops::Mul for Vec1 { #[warn(clippy::erasing_op)] fn test(x: u8) { x * 0; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou + //~| NOTE: `-D clippy::erasing-op` implied by `-D warnings` 0 & x; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou 0 / x; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou 0 * Meter; // no error: Output type is different from the non-zero argument 0 * Vec1 { x: 5 }; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou Vec1 { x: 5 } * 0; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou } fn main() { diff --git a/tests/ui/erasing_op.stderr b/tests/ui/erasing_op.stderr index 97941252355af..7b9608fe45228 100644 --- a/tests/ui/erasing_op.stderr +++ b/tests/ui/erasing_op.stderr @@ -7,25 +7,25 @@ LL | x * 0; = note: `-D clippy::erasing-op` implied by `-D warnings` error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:36:5 + --> $DIR/erasing_op.rs:38:5 | LL | 0 & x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:37:5 + --> $DIR/erasing_op.rs:40:5 | LL | 0 / x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:39:5 + --> $DIR/erasing_op.rs:43:5 | LL | 0 * Vec1 { x: 5 }; | ^^^^^^^^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:40:5 + --> $DIR/erasing_op.rs:45:5 | LL | Vec1 { x: 5 } * 0; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/error_impl_error.rs b/tests/ui/error_impl_error.rs index 40ce4181bf34a..05003f7d047ca 100644 --- a/tests/ui/error_impl_error.rs +++ b/tests/ui/error_impl_error.rs @@ -5,6 +5,7 @@ pub mod a { #[derive(Debug)] pub struct Error; + //~^ ERROR: exported type named `Error` that implements `Error` impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -18,6 +19,7 @@ pub mod a { mod b { #[derive(Debug)] pub(super) enum Error {} + //~^ ERROR: exported type named `Error` that implements `Error` impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -30,6 +32,7 @@ mod b { pub mod c { pub union Error { + //~^ ERROR: exported type named `Error` that implements `Error` a: u32, b: u32, } @@ -51,6 +54,7 @@ pub mod c { pub mod d { pub type Error = std::fmt::Error; + //~^ ERROR: exported type alias named `Error` that implements `Error` } mod e { diff --git a/tests/ui/error_impl_error.stderr b/tests/ui/error_impl_error.stderr index f3e04b6416731..54a55d5dcf4b1 100644 --- a/tests/ui/error_impl_error.stderr +++ b/tests/ui/error_impl_error.stderr @@ -5,38 +5,38 @@ LL | pub struct Error; | ^^^^^ | note: `Error` was implemented here - --> $DIR/error_impl_error.rs:15:5 + --> $DIR/error_impl_error.rs:16:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::error-impl-error` implied by `-D warnings` error: exported type named `Error` that implements `Error` - --> $DIR/error_impl_error.rs:20:21 + --> $DIR/error_impl_error.rs:21:21 | LL | pub(super) enum Error {} | ^^^^^ | note: `Error` was implemented here - --> $DIR/error_impl_error.rs:28:5 + --> $DIR/error_impl_error.rs:30:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type named `Error` that implements `Error` - --> $DIR/error_impl_error.rs:32:15 + --> $DIR/error_impl_error.rs:34:15 | LL | pub union Error { | ^^^^^ | note: `Error` was implemented here - --> $DIR/error_impl_error.rs:49:5 + --> $DIR/error_impl_error.rs:52:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type alias named `Error` that implements `Error` - --> $DIR/error_impl_error.rs:53:14 + --> $DIR/error_impl_error.rs:56:14 | LL | pub type Error = std::fmt::Error; | ^^^^^ diff --git a/tests/ui/exit1.rs b/tests/ui/exit1.rs index 4eac6eb74672f..a89f6dd4ca0eb 100644 --- a/tests/ui/exit1.rs +++ b/tests/ui/exit1.rs @@ -3,6 +3,8 @@ fn not_main() { if true { std::process::exit(4); + //~^ ERROR: usage of `process::exit` + //~| NOTE: `-D clippy::exit` implied by `-D warnings` } } diff --git a/tests/ui/exit2.rs b/tests/ui/exit2.rs index 4b693ed7083f0..d5ff93fb9ccb8 100644 --- a/tests/ui/exit2.rs +++ b/tests/ui/exit2.rs @@ -2,6 +2,8 @@ fn also_not_main() { std::process::exit(3); + //~^ ERROR: usage of `process::exit` + //~| NOTE: `-D clippy::exit` implied by `-D warnings` } fn main() { diff --git a/tests/ui/expect.rs b/tests/ui/expect.rs index 1588579bb0f2f..f15b3d37e154b 100644 --- a/tests/ui/expect.rs +++ b/tests/ui/expect.rs @@ -4,12 +4,15 @@ fn expect_option() { let opt = Some(0); let _ = opt.expect(""); + //~^ ERROR: used `expect()` on an `Option` value } fn expect_result() { let res: Result = Ok(0); let _ = res.expect(""); + //~^ ERROR: used `expect()` on a `Result` value let _ = res.expect_err(""); + //~^ ERROR: used `expect_err()` on a `Result` value } fn main() { diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr index f787fa973a32e..c9a29624d530a 100644 --- a/tests/ui/expect.stderr +++ b/tests/ui/expect.stderr @@ -8,7 +8,7 @@ LL | let _ = opt.expect(""); = note: `-D clippy::expect-used` implied by `-D warnings` error: used `expect()` on a `Result` value - --> $DIR/expect.rs:11:13 + --> $DIR/expect.rs:12:13 | LL | let _ = res.expect(""); | ^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = res.expect(""); = note: if this value is an `Err`, it will panic error: used `expect_err()` on a `Result` value - --> $DIR/expect.rs:12:13 + --> $DIR/expect.rs:14:13 | LL | let _ = res.expect_err(""); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/expect_tool_lint_rfc_2383.rs b/tests/ui/expect_tool_lint_rfc_2383.rs index 7963bf0f3a6a2..5fab9ceb67971 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.rs +++ b/tests/ui/expect_tool_lint_rfc_2383.rs @@ -33,10 +33,13 @@ mod rustc_warn { //! See #[expect(dead_code)] + //~^ ERROR: this lint expectation is unfulfilled + //~| NOTE: `-D unfulfilled-lint-expectations` implied by `-D warnings` pub fn rustc_lints() { let x = 42; #[expect(illegal_floating_point_literal_pattern)] + //~^ ERROR: this lint expectation is unfulfilled match x { 5 => {}, 6 => {}, @@ -111,6 +114,7 @@ mod clippy_warn { //! See #[expect(clippy::almost_swapped)] + //~^ ERROR: this lint expectation is unfulfilled fn foo() { let mut a = 0; let mut b = 9; @@ -118,16 +122,19 @@ mod clippy_warn { } #[expect(clippy::bytes_nth)] + //~^ ERROR: this lint expectation is unfulfilled fn bar() { let _ = "Hello".as_bytes().get(3); } #[expect(clippy::if_same_then_else)] + //~^ ERROR: this lint expectation is unfulfilled fn baz() { let _ = if true { 33 } else { 42 }; } #[expect(clippy::overly_complex_bool_expr)] + //~^ ERROR: this lint expectation is unfulfilled fn burger() { let a = false; let b = true; diff --git a/tests/ui/expect_tool_lint_rfc_2383.stderr b/tests/ui/expect_tool_lint_rfc_2383.stderr index 7ce9e855b5e05..1a08d77113a40 100644 --- a/tests/ui/expect_tool_lint_rfc_2383.stderr +++ b/tests/ui/expect_tool_lint_rfc_2383.stderr @@ -7,31 +7,31 @@ LL | #[expect(dead_code)] = note: `-D unfulfilled-lint-expectations` implied by `-D warnings` error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:39:18 + --> $DIR/expect_tool_lint_rfc_2383.rs:41:18 | LL | #[expect(illegal_floating_point_literal_pattern)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:113:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:116:14 | LL | #[expect(clippy::almost_swapped)] | ^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:120:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:124:14 | LL | #[expect(clippy::bytes_nth)] | ^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:125:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:130:14 | LL | #[expect(clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:130:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:136:14 | LL | #[expect(clippy::overly_complex_bool_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/explicit_counter_loop.rs b/tests/ui/explicit_counter_loop.rs index 15dc9669efa96..c25e79a36171f 100644 --- a/tests/ui/explicit_counter_loop.rs +++ b/tests/ui/explicit_counter_loop.rs @@ -5,22 +5,27 @@ fn main() { let mut vec = vec![1, 2, 3, 4]; let mut _index = 0; for _v in &vec { + //~^ ERROR: the variable `_index` is used as a loop counter + //~| NOTE: `-D clippy::explicit-counter-loop` implied by `-D warnings` _index += 1 } let mut _index = 1; _index = 0; for _v in &vec { + //~^ ERROR: the variable `_index` is used as a loop counter _index += 1 } let mut _index = 0; for _v in &mut vec { + //~^ ERROR: the variable `_index` is used as a loop counter _index += 1; } let mut _index = 0; for _v in vec { + //~^ ERROR: the variable `_index` is used as a loop counter _index += 1; } @@ -108,6 +113,7 @@ mod issue_1219 { let text = "banana"; let mut count = 0; for ch in text.chars() { + //~^ ERROR: the variable `count` is used as a loop counter println!("{}", count); count += 1; if ch == 'a' { @@ -119,6 +125,7 @@ mod issue_1219 { let text = "banana"; let mut count = 0; for ch in text.chars() { + //~^ ERROR: the variable `count` is used as a loop counter println!("{}", count); count += 1; for i in 0..2 { @@ -177,6 +184,7 @@ mod issue_1670 { pub fn test() { let mut count = 0; for _i in 3..10 { + //~^ ERROR: the variable `count` is used as a loop counter count += 1; } } @@ -217,6 +225,7 @@ mod issue_7920 { // should suggest `enumerate` for _item in slice { + //~^ ERROR: the variable `idx_usize` is used as a loop counter if idx_usize == index_usize { break; } @@ -229,6 +238,8 @@ mod issue_7920 { // should suggest `zip` for _item in slice { + //~^ ERROR: the variable `idx_u32` is used as a loop counter + //~| NOTE: `idx_u32` is of type `u32`, making it ineligible for `Iterator::enumera if idx_u32 == index_u32 { break; } diff --git a/tests/ui/explicit_counter_loop.stderr b/tests/ui/explicit_counter_loop.stderr index 0677e4d78c8be..3b36f28617bb0 100644 --- a/tests/ui/explicit_counter_loop.stderr +++ b/tests/ui/explicit_counter_loop.stderr @@ -7,49 +7,49 @@ LL | for _v in &vec { = note: `-D clippy::explicit-counter-loop` implied by `-D warnings` error: the variable `_index` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:13:5 + --> $DIR/explicit_counter_loop.rs:15:5 | LL | for _v in &vec { | ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()` error: the variable `_index` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:18:5 + --> $DIR/explicit_counter_loop.rs:21:5 | LL | for _v in &mut vec { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter_mut().enumerate()` error: the variable `_index` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:23:5 + --> $DIR/explicit_counter_loop.rs:27:5 | LL | for _v in vec { | ^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.into_iter().enumerate()` error: the variable `count` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:110:9 + --> $DIR/explicit_counter_loop.rs:115:9 | LL | for ch in text.chars() { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` error: the variable `count` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:121:9 + --> $DIR/explicit_counter_loop.rs:127:9 | LL | for ch in text.chars() { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` error: the variable `count` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:179:9 + --> $DIR/explicit_counter_loop.rs:186:9 | LL | for _i in 3..10 { | ^^^^^^^^^^^^^^^ help: consider using: `for (count, _i) in (3..10).enumerate()` error: the variable `idx_usize` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:219:9 + --> $DIR/explicit_counter_loop.rs:227:9 | LL | for _item in slice { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_usize, _item) in slice.iter().enumerate()` error: the variable `idx_u32` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:231:9 + --> $DIR/explicit_counter_loop.rs:240:9 | LL | for _item in slice { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_u32, _item) in (0_u32..).zip(slice.iter())` diff --git a/tests/ui/extra_unused_type_parameters_unfixable.rs b/tests/ui/extra_unused_type_parameters_unfixable.rs index 10b39aa8f2c5b..65b53eb2e4b3a 100644 --- a/tests/ui/extra_unused_type_parameters_unfixable.rs +++ b/tests/ui/extra_unused_type_parameters_unfixable.rs @@ -1,6 +1,7 @@ #![warn(clippy::extra_unused_type_parameters)] fn unused_where_clause(x: U) +//~^ ERROR: type parameter `T` goes unused in function definition where T: Default, { @@ -8,6 +9,7 @@ where } fn unused_multi_where_clause(x: U) +//~^ ERROR: type parameters go unused in function definition: T, V where T: Default, { @@ -15,6 +17,7 @@ where } fn unused_all_where_clause() +//~^ ERROR: type parameters go unused in function definition: T, U, V where T: Default, { diff --git a/tests/ui/extra_unused_type_parameters_unfixable.stderr b/tests/ui/extra_unused_type_parameters_unfixable.stderr index a9580cc894f35..bbd0cf478ab3c 100644 --- a/tests/ui/extra_unused_type_parameters_unfixable.stderr +++ b/tests/ui/extra_unused_type_parameters_unfixable.stderr @@ -8,7 +8,7 @@ LL | fn unused_where_clause(x: U) = note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings` error: type parameters go unused in function definition: T, V - --> $DIR/extra_unused_type_parameters_unfixable.rs:10:30 + --> $DIR/extra_unused_type_parameters_unfixable.rs:11:30 | LL | fn unused_multi_where_clause(x: U) | ^ ^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn unused_multi_where_clause(x: U) = help: consider removing the parameters error: type parameters go unused in function definition: T, U, V - --> $DIR/extra_unused_type_parameters_unfixable.rs:17:28 + --> $DIR/extra_unused_type_parameters_unfixable.rs:19:28 | LL | fn unused_all_where_clause() | ^ ^^^^^^^^^^ ^^^^^^^^^^ diff --git a/tests/ui/fallible_impl_from.rs b/tests/ui/fallible_impl_from.rs index fb6e8ec706b17..a81e51fcac75a 100644 --- a/tests/ui/fallible_impl_from.rs +++ b/tests/ui/fallible_impl_from.rs @@ -4,6 +4,7 @@ // docs example struct Foo(i32); impl From for Foo { + //~^ ERROR: consider implementing `TryFrom` instead fn from(s: String) -> Self { Foo(s.parse().unwrap()) } @@ -25,6 +26,7 @@ impl From for Valid { struct Invalid; impl From for Invalid { + //~^ ERROR: consider implementing `TryFrom` instead fn from(i: usize) -> Invalid { if i != 42 { panic!(); @@ -34,6 +36,7 @@ impl From for Invalid { } impl From> for Invalid { + //~^ ERROR: consider implementing `TryFrom` instead fn from(s: Option) -> Invalid { let s = s.unwrap(); if !s.is_empty() { @@ -52,6 +55,7 @@ impl ProjStrTrait for Box { type ProjString = String; } impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { + //~^ ERROR: consider implementing `TryFrom` instead fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { if s.parse::().ok().unwrap() != 42 { panic!("{:?}", s); diff --git a/tests/ui/fallible_impl_from.stderr b/tests/ui/fallible_impl_from.stderr index 21761484f8c45..96074ca89ea0f 100644 --- a/tests/ui/fallible_impl_from.stderr +++ b/tests/ui/fallible_impl_from.stderr @@ -2,6 +2,7 @@ error: consider implementing `TryFrom` instead --> $DIR/fallible_impl_from.rs:6:1 | LL | / impl From for Foo { +LL | | LL | | fn from(s: String) -> Self { LL | | Foo(s.parse().unwrap()) LL | | } @@ -10,7 +11,7 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:8:13 + --> $DIR/fallible_impl_from.rs:9:13 | LL | Foo(s.parse().unwrap()) | ^^^^^^^^^^^^^^^^^^ @@ -21,12 +22,12 @@ LL | #![deny(clippy::fallible_impl_from)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:27:1 + --> $DIR/fallible_impl_from.rs:28:1 | LL | / impl From for Invalid { +LL | | LL | | fn from(i: usize) -> Invalid { LL | | if i != 42 { -LL | | panic!(); ... | LL | | } LL | | } @@ -34,19 +35,19 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:30:13 + --> $DIR/fallible_impl_from.rs:32:13 | LL | panic!(); | ^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:36:1 + --> $DIR/fallible_impl_from.rs:38:1 | LL | / impl From> for Invalid { +LL | | LL | | fn from(s: Option) -> Invalid { LL | | let s = s.unwrap(); -LL | | if !s.is_empty() { ... | LL | | } LL | | } @@ -54,7 +55,7 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:38:17 + --> $DIR/fallible_impl_from.rs:41:17 | LL | let s = s.unwrap(); | ^^^^^^^^^^ @@ -68,12 +69,12 @@ LL | panic!("{:?}", s); = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:54:1 + --> $DIR/fallible_impl_from.rs:57:1 | LL | / impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { +LL | | LL | | fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { LL | | if s.parse::().ok().unwrap() != 42 { -LL | | panic!("{:?}", s); ... | LL | | } LL | | } @@ -81,7 +82,7 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:56:12 + --> $DIR/fallible_impl_from.rs:60:12 | LL | if s.parse::().ok().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/filetype_is_file.rs b/tests/ui/filetype_is_file.rs index d3ad36e40b53c..9e8a4c04324b0 100644 --- a/tests/ui/filetype_is_file.rs +++ b/tests/ui/filetype_is_file.rs @@ -7,16 +7,19 @@ fn main() -> std::io::Result<()> { // !filetype.is_dir() if fs::metadata("foo.txt")?.file_type().is_file() { + //~^ ERROR: `FileType::is_file()` only covers regular files // read file } // positive of filetype.is_dir() if !fs::metadata("foo.txt")?.file_type().is_file() { + //~^ ERROR: `!FileType::is_file()` only denies regular files // handle dir } // false positive of filetype.is_dir() if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { + //~^ ERROR: `FileType::is_file()` only covers regular files // ... } diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr index 36142deb3092a..718d287e6799f 100644 --- a/tests/ui/filetype_is_file.stderr +++ b/tests/ui/filetype_is_file.stderr @@ -8,7 +8,7 @@ LL | if fs::metadata("foo.txt")?.file_type().is_file() { = note: `-D clippy::filetype-is-file` implied by `-D warnings` error: `!FileType::is_file()` only denies regular files - --> $DIR/filetype_is_file.rs:14:8 + --> $DIR/filetype_is_file.rs:15:8 | LL | if !fs::metadata("foo.txt")?.file_type().is_file() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | if !fs::metadata("foo.txt")?.file_type().is_file() { = help: use `FileType::is_dir()` instead error: `FileType::is_file()` only covers regular files - --> $DIR/filetype_is_file.rs:19:9 + --> $DIR/filetype_is_file.rs:21:9 | LL | if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/filter_map_next.rs b/tests/ui/filter_map_next.rs index dbeb2354309c9..9077b8fca23e2 100644 --- a/tests/ui/filter_map_next.rs +++ b/tests/ui/filter_map_next.rs @@ -5,6 +5,8 @@ fn main() { #[rustfmt::skip] let _: Option = vec![1, 2, 3, 4, 5, 6] + //~^ ERROR: called `filter_map(..).next()` on an `Iterator`. This is more succinctly e + //~| NOTE: `-D clippy::filter-map-next` implied by `-D warnings` .into_iter() .filter_map(|x| { if x == 2 { diff --git a/tests/ui/filter_map_next.stderr b/tests/ui/filter_map_next.stderr index ddc982c93fe6d..3220ee51c2ac9 100644 --- a/tests/ui/filter_map_next.stderr +++ b/tests/ui/filter_map_next.stderr @@ -3,9 +3,9 @@ error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly | LL | let _: Option = vec![1, 2, 3, 4, 5, 6] | __________________________^ +LL | | +LL | | LL | | .into_iter() -LL | | .filter_map(|x| { -LL | | if x == 2 { ... | LL | | }) LL | | .next(); diff --git a/tests/ui/float_arithmetic.rs b/tests/ui/float_arithmetic.rs index a928c35e8bc99..1647273c436d8 100644 --- a/tests/ui/float_arithmetic.rs +++ b/tests/ui/float_arithmetic.rs @@ -13,40 +13,58 @@ fn main() { let mut f = 1.0f32; f * 2.0; + //~^ ERROR: floating-point arithmetic detected + //~| NOTE: `-D clippy::float-arithmetic` implied by `-D warnings` 1.0 + f; + //~^ ERROR: floating-point arithmetic detected f * 2.0; + //~^ ERROR: floating-point arithmetic detected f / 2.0; + //~^ ERROR: floating-point arithmetic detected f - 2.0 * 4.2; + //~^ ERROR: floating-point arithmetic detected -f; + //~^ ERROR: floating-point arithmetic detected f += 1.0; + //~^ ERROR: floating-point arithmetic detected f -= 1.0; + //~^ ERROR: floating-point arithmetic detected f *= 2.0; + //~^ ERROR: floating-point arithmetic detected f /= 2.0; + //~^ ERROR: floating-point arithmetic detected } // also warn about floating point arith with references involved pub fn float_arith_ref() { 3.1_f32 + &1.2_f32; + //~^ ERROR: floating-point arithmetic detected &3.4_f32 + 1.5_f32; + //~^ ERROR: floating-point arithmetic detected &3.5_f32 + &1.3_f32; + //~^ ERROR: floating-point arithmetic detected } pub fn float_foo(f: &f32) -> f32 { let a = 5.1; a + f + //~^ ERROR: floating-point arithmetic detected } pub fn float_bar(f1: &f32, f2: &f32) -> f32 { f1 + f2 + //~^ ERROR: floating-point arithmetic detected } pub fn float_baz(f1: f32, f2: &f32) -> f32 { f1 + f2 + //~^ ERROR: floating-point arithmetic detected } pub fn float_qux(f1: f32, f2: f32) -> f32 { (&f1 + &f2) + //~^ ERROR: floating-point arithmetic detected } diff --git a/tests/ui/float_arithmetic.stderr b/tests/ui/float_arithmetic.stderr index 1ceffb35beede..fe8446c98167a 100644 --- a/tests/ui/float_arithmetic.stderr +++ b/tests/ui/float_arithmetic.stderr @@ -7,97 +7,97 @@ LL | f * 2.0; = note: `-D clippy::float-arithmetic` implied by `-D warnings` error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:17:5 + --> $DIR/float_arithmetic.rs:19:5 | LL | 1.0 + f; | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:18:5 + --> $DIR/float_arithmetic.rs:21:5 | LL | f * 2.0; | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:19:5 + --> $DIR/float_arithmetic.rs:23:5 | LL | f / 2.0; | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:20:5 + --> $DIR/float_arithmetic.rs:25:5 | LL | f - 2.0 * 4.2; | ^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:21:5 + --> $DIR/float_arithmetic.rs:27:5 | LL | -f; | ^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:23:5 + --> $DIR/float_arithmetic.rs:30:5 | LL | f += 1.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:24:5 + --> $DIR/float_arithmetic.rs:32:5 | LL | f -= 1.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:25:5 + --> $DIR/float_arithmetic.rs:34:5 | LL | f *= 2.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:26:5 + --> $DIR/float_arithmetic.rs:36:5 | LL | f /= 2.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:32:5 + --> $DIR/float_arithmetic.rs:43:5 | LL | 3.1_f32 + &1.2_f32; | ^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:33:5 + --> $DIR/float_arithmetic.rs:45:5 | LL | &3.4_f32 + 1.5_f32; | ^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:34:5 + --> $DIR/float_arithmetic.rs:47:5 | LL | &3.5_f32 + &1.3_f32; | ^^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:39:5 + --> $DIR/float_arithmetic.rs:53:5 | LL | a + f | ^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:43:5 + --> $DIR/float_arithmetic.rs:58:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:47:5 + --> $DIR/float_arithmetic.rs:63:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:51:5 + --> $DIR/float_arithmetic.rs:68:5 | LL | (&f1 + &f2) | ^^^^^^^^^^^ diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index b0a6a64a18aff..a547a67430fd2 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -55,14 +55,20 @@ fn main() { ONE != 0.0; // no error, comparison with zero is ok twice(ONE) != ONE; ONE as f64 != 2.0; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` ONE as f64 != 0.0; // no error, comparison with zero is ok let x: f64 = 1.0; x == 1.0; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` x != 0f64; // no error, comparison with zero is ok twice(x) != twice(ONE as f64); + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` x < 0.0; // no errors, lower or greater comparisons need no fuzzyness x > 0.0; @@ -83,12 +89,18 @@ fn main() { ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; // ok, because lhs is zero regardless of i NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` let a1: [f32; 1] = [0.0]; let a2: [f32; 1] = [1.1]; a1 == a2; + //~^ ERROR: strict comparison of `f32` or `f64` arrays + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` a1[0] == a2[0]; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` // no errors - comparing signums is ok let x32 = 3.21f32; diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr index e3e9f3949fdf8..5836b5603d6eb 100644 --- a/tests/ui/float_cmp.stderr +++ b/tests/ui/float_cmp.stderr @@ -8,7 +8,7 @@ LL | ONE as f64 != 2.0; = note: `-D clippy::float-cmp` implied by `-D warnings` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:62:5 + --> $DIR/float_cmp.rs:64:5 | LL | x == 1.0; | ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin` @@ -16,7 +16,7 @@ LL | x == 1.0; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:65:5 + --> $DIR/float_cmp.rs:69:5 | LL | twice(x) != twice(ONE as f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin` @@ -24,7 +24,7 @@ LL | twice(x) != twice(ONE as f64); = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:85:5 + --> $DIR/float_cmp.rs:91:5 | LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin` @@ -32,7 +32,7 @@ LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` arrays - --> $DIR/float_cmp.rs:90:5 + --> $DIR/float_cmp.rs:98:5 | LL | a1 == a2; | ^^^^^^^^ @@ -40,7 +40,7 @@ LL | a1 == a2; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:91:5 + --> $DIR/float_cmp.rs:101:5 | LL | a1[0] == a2[0]; | ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin` diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs index 1493d4f1d37f3..47ea0e19c68b9 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -14,15 +14,29 @@ fn eq_one(x: f32) -> bool { fn main() { // has errors 1f32 == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` TWO == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` TWO != ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` ONE + ONE == TWO; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` let x = 1; x as f32 == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` let v = 0.9; v == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` v != ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` // no errors, lower than or greater than comparisons v < ONE; @@ -55,4 +69,6 @@ fn main() { // has errors NON_ZERO_ARRAY == NON_ZERO_ARRAY2; + //~^ ERROR: strict comparison of `f32` or `f64` constant arrays + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` } diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index 65c45648ab380..4de1d58adc0f3 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -8,7 +8,7 @@ LL | 1f32 == ONE; = note: `-D clippy::float-cmp-const` implied by `-D warnings` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:17:5 + --> $DIR/float_cmp_const.rs:19:5 | LL | TWO == ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin` @@ -16,7 +16,7 @@ LL | TWO == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:18:5 + --> $DIR/float_cmp_const.rs:22:5 | LL | TWO != ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin` @@ -24,7 +24,7 @@ LL | TWO != ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:19:5 + --> $DIR/float_cmp_const.rs:25:5 | LL | ONE + ONE == TWO; | ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin` @@ -32,7 +32,7 @@ LL | ONE + ONE == TWO; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:21:5 + --> $DIR/float_cmp_const.rs:29:5 | LL | x as f32 == ONE; | ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin` @@ -40,7 +40,7 @@ LL | x as f32 == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:24:5 + --> $DIR/float_cmp_const.rs:34:5 | LL | v == ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin` @@ -48,7 +48,7 @@ LL | v == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:25:5 + --> $DIR/float_cmp_const.rs:37:5 | LL | v != ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin` @@ -56,7 +56,7 @@ LL | v != ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant arrays - --> $DIR/float_cmp_const.rs:57:5 + --> $DIR/float_cmp_const.rs:71:5 | LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/float_equality_without_abs.rs b/tests/ui/float_equality_without_abs.rs index 4048c3a7855ba..6363472d8990a 100644 --- a/tests/ui/float_equality_without_abs.rs +++ b/tests/ui/float_equality_without_abs.rs @@ -2,6 +2,8 @@ //@no-rustfix pub fn is_roughly_equal(a: f32, b: f32) -> bool { (a - b) < f32::EPSILON + //~^ ERROR: float equality check without `.abs()` + //~| NOTE: `-D clippy::float-equality-without-abs` implied by `-D warnings` } pub fn main() { @@ -11,16 +13,26 @@ pub fn main() { let b = 0.0500001; let _ = (a - b) < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = a - b < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = a - b.abs() < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = (a as f64 - b as f64) < f64::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = 1.0 - 2.0 < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > (a - b); + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > a - b; + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > a - b.abs(); + //~^ ERROR: float equality check without `.abs()` let _ = f64::EPSILON > (a as f64 - b as f64); + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > 1.0 - 2.0; + //~^ ERROR: float equality check without `.abs()` // those are correct let _ = (a - b).abs() < f32::EPSILON; diff --git a/tests/ui/float_equality_without_abs.stderr b/tests/ui/float_equality_without_abs.stderr index b34c8159da04d..c9806019f1fa7 100644 --- a/tests/ui/float_equality_without_abs.stderr +++ b/tests/ui/float_equality_without_abs.stderr @@ -9,7 +9,7 @@ LL | (a - b) < f32::EPSILON = note: `-D clippy::float-equality-without-abs` implied by `-D warnings` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:13:13 + --> $DIR/float_equality_without_abs.rs:15:13 | LL | let _ = (a - b) < f32::EPSILON; | -------^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | let _ = (a - b) < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:14:13 + --> $DIR/float_equality_without_abs.rs:17:13 | LL | let _ = a - b < f32::EPSILON; | -----^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | let _ = a - b < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:15:13 + --> $DIR/float_equality_without_abs.rs:19:13 | LL | let _ = a - b.abs() < f32::EPSILON; | -----------^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | let _ = a - b.abs() < f32::EPSILON; | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:16:13 + --> $DIR/float_equality_without_abs.rs:21:13 | LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | ---------------------^^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | help: add `.abs()`: `(a as f64 - b as f64).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:17:13 + --> $DIR/float_equality_without_abs.rs:23:13 | LL | let _ = 1.0 - 2.0 < f32::EPSILON; | ---------^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _ = 1.0 - 2.0 < f32::EPSILON; | help: add `.abs()`: `(1.0 - 2.0).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:19:13 + --> $DIR/float_equality_without_abs.rs:26:13 | LL | let _ = f32::EPSILON > (a - b); | ^^^^^^^^^^^^^^^------- @@ -57,7 +57,7 @@ LL | let _ = f32::EPSILON > (a - b); | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:20:13 + --> $DIR/float_equality_without_abs.rs:28:13 | LL | let _ = f32::EPSILON > a - b; | ^^^^^^^^^^^^^^^----- @@ -65,7 +65,7 @@ LL | let _ = f32::EPSILON > a - b; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:21:13 + --> $DIR/float_equality_without_abs.rs:30:13 | LL | let _ = f32::EPSILON > a - b.abs(); | ^^^^^^^^^^^^^^^----------- @@ -73,7 +73,7 @@ LL | let _ = f32::EPSILON > a - b.abs(); | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:22:13 + --> $DIR/float_equality_without_abs.rs:32:13 | LL | let _ = f64::EPSILON > (a as f64 - b as f64); | ^^^^^^^^^^^^^^^--------------------- @@ -81,7 +81,7 @@ LL | let _ = f64::EPSILON > (a as f64 - b as f64); | help: add `.abs()`: `(a as f64 - b as f64).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:23:13 + --> $DIR/float_equality_without_abs.rs:34:13 | LL | let _ = f32::EPSILON > 1.0 - 2.0; | ^^^^^^^^^^^^^^^--------- diff --git a/tests/ui/fn_address_comparisons.rs b/tests/ui/fn_address_comparisons.rs index 362dcb4fd80ca..35535bd4fddd0 100644 --- a/tests/ui/fn_address_comparisons.rs +++ b/tests/ui/fn_address_comparisons.rs @@ -13,7 +13,10 @@ fn main() { // These should fail: let _ = f == a; + //~^ ERROR: comparing with a non-unique address of a function item + //~| NOTE: `-D clippy::fn-address-comparisons` implied by `-D warnings` let _ = f != a; + //~^ ERROR: comparing with a non-unique address of a function item // These should be fine: let _ = f == g; diff --git a/tests/ui/fn_address_comparisons.stderr b/tests/ui/fn_address_comparisons.stderr index 9c1b5419a4319..87415a0d9048c 100644 --- a/tests/ui/fn_address_comparisons.stderr +++ b/tests/ui/fn_address_comparisons.stderr @@ -7,7 +7,7 @@ LL | let _ = f == a; = note: `-D clippy::fn-address-comparisons` implied by `-D warnings` error: comparing with a non-unique address of a function item - --> $DIR/fn_address_comparisons.rs:16:13 + --> $DIR/fn_address_comparisons.rs:18:13 | LL | let _ = f != a; | ^^^^^^ diff --git a/tests/ui/fn_params_excessive_bools.rs b/tests/ui/fn_params_excessive_bools.rs index f53e531629aae..cc18708d25faf 100644 --- a/tests/ui/fn_params_excessive_bools.rs +++ b/tests/ui/fn_params_excessive_bools.rs @@ -17,22 +17,27 @@ foo!(); #[no_mangle] extern "C" fn k(_: bool, _: bool, _: bool, _: bool) {} fn g(_: bool, _: bool, _: bool, _: bool) {} +//~^ ERROR: more than 3 bools in function parameters fn h(_: bool, _: bool, _: bool) {} fn e(_: S, _: S, _: Box, _: Vec) {} fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} +//~^ ERROR: more than 3 bools in function parameters struct S; trait Trait { // should warn for trait functions with and without body fn f(_: bool, _: bool, _: bool, _: bool); + //~^ ERROR: more than 3 bools in function parameters fn g(_: bool, _: bool, _: bool, _: Vec); #[allow(clippy::fn_params_excessive_bools)] fn h(_: bool, _: bool, _: bool, _: bool, _: bool, _: bool); fn i(_: bool, _: bool, _: bool, _: bool) {} + //~^ ERROR: more than 3 bools in function parameters } impl S { fn f(&self, _: bool, _: bool, _: bool, _: bool) {} + //~^ ERROR: more than 3 bools in function parameters fn g(&self, _: bool, _: bool, _: bool) {} #[no_mangle] extern "C" fn h(_: bool, _: bool, _: bool, _: bool) {} @@ -48,6 +53,8 @@ impl Trait for S { fn main() { fn n(_: bool, _: u32, _: bool, _: Box, _: bool, _: bool) { + //~^ ERROR: more than 3 bools in function parameters fn nn(_: bool, _: bool, _: bool, _: bool) {} + //~^ ERROR: more than 3 bools in function parameters } } diff --git a/tests/ui/fn_params_excessive_bools.stderr b/tests/ui/fn_params_excessive_bools.stderr index 43363b46972c3..db09418cd808e 100644 --- a/tests/ui/fn_params_excessive_bools.stderr +++ b/tests/ui/fn_params_excessive_bools.stderr @@ -8,7 +8,7 @@ LL | fn g(_: bool, _: bool, _: bool, _: bool) {} = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:22:1 + --> $DIR/fn_params_excessive_bools.rs:23:1 | LL | fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:27:5 + --> $DIR/fn_params_excessive_bools.rs:29:5 | LL | fn f(_: bool, _: bool, _: bool, _: bool); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn f(_: bool, _: bool, _: bool, _: bool); = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:31:5 + --> $DIR/fn_params_excessive_bools.rs:34:5 | LL | fn i(_: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | fn i(_: bool, _: bool, _: bool, _: bool) {} = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:35:5 + --> $DIR/fn_params_excessive_bools.rs:39:5 | LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,17 +40,19 @@ LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {} = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:50:5 + --> $DIR/fn_params_excessive_bools.rs:55:5 | LL | / fn n(_: bool, _: u32, _: bool, _: Box, _: bool, _: bool) { +LL | | LL | | fn nn(_: bool, _: bool, _: bool, _: bool) {} +LL | | LL | | } | |_____^ | = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:51:9 + --> $DIR/fn_params_excessive_bools.rs:57:9 | LL | fn nn(_: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/fn_to_numeric_cast.rs b/tests/ui/fn_to_numeric_cast.rs index 05053270c5bc6..09128d8176e08 100644 --- a/tests/ui/fn_to_numeric_cast.rs +++ b/tests/ui/fn_to_numeric_cast.rs @@ -8,17 +8,30 @@ fn foo() -> String { fn test_function_to_numeric_cast() { let _ = foo as i8; + //~^ ERROR: casting function pointer `foo` to `i8`, which truncates the value + //~| NOTE: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` let _ = foo as i16; + //~^ ERROR: casting function pointer `foo` to `i16`, which truncates the value let _ = foo as i32; + //~^ ERROR: casting function pointer `foo` to `i32`, which truncates the value let _ = foo as i64; + //~^ ERROR: casting function pointer `foo` to `i64` + //~| NOTE: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` let _ = foo as i128; + //~^ ERROR: casting function pointer `foo` to `i128` let _ = foo as isize; + //~^ ERROR: casting function pointer `foo` to `isize` let _ = foo as u8; + //~^ ERROR: casting function pointer `foo` to `u8`, which truncates the value let _ = foo as u16; + //~^ ERROR: casting function pointer `foo` to `u16`, which truncates the value let _ = foo as u32; + //~^ ERROR: casting function pointer `foo` to `u32`, which truncates the value let _ = foo as u64; + //~^ ERROR: casting function pointer `foo` to `u64` let _ = foo as u128; + //~^ ERROR: casting function pointer `foo` to `u128` // Casting to usize is OK and should not warn let _ = foo as usize; @@ -32,17 +45,28 @@ fn test_function_var_to_numeric_cast() { let abc: fn() -> String = foo; let _ = abc as i8; + //~^ ERROR: casting function pointer `abc` to `i8`, which truncates the value let _ = abc as i16; + //~^ ERROR: casting function pointer `abc` to `i16`, which truncates the value let _ = abc as i32; + //~^ ERROR: casting function pointer `abc` to `i32`, which truncates the value let _ = abc as i64; + //~^ ERROR: casting function pointer `abc` to `i64` let _ = abc as i128; + //~^ ERROR: casting function pointer `abc` to `i128` let _ = abc as isize; + //~^ ERROR: casting function pointer `abc` to `isize` let _ = abc as u8; + //~^ ERROR: casting function pointer `abc` to `u8`, which truncates the value let _ = abc as u16; + //~^ ERROR: casting function pointer `abc` to `u16`, which truncates the value let _ = abc as u32; + //~^ ERROR: casting function pointer `abc` to `u32`, which truncates the value let _ = abc as u64; + //~^ ERROR: casting function pointer `abc` to `u64` let _ = abc as u128; + //~^ ERROR: casting function pointer `abc` to `u128` // Casting to usize is OK and should not warn let _ = abc as usize; @@ -50,6 +74,7 @@ fn test_function_var_to_numeric_cast() { fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { f as i32 + //~^ ERROR: casting function pointer `f` to `i32`, which truncates the value } fn main() {} diff --git a/tests/ui/fn_to_numeric_cast.stderr b/tests/ui/fn_to_numeric_cast.stderr index e9549e157cd91..5b2e8bdf30b06 100644 --- a/tests/ui/fn_to_numeric_cast.stderr +++ b/tests/ui/fn_to_numeric_cast.stderr @@ -7,19 +7,19 @@ LL | let _ = foo as i8; = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` error: casting function pointer `foo` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:11:13 + --> $DIR/fn_to_numeric_cast.rs:13:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:12:13 + --> $DIR/fn_to_numeric_cast.rs:15:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `i64` - --> $DIR/fn_to_numeric_cast.rs:13:13 + --> $DIR/fn_to_numeric_cast.rs:17:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: try: `foo as usize` @@ -27,115 +27,115 @@ LL | let _ = foo as i64; = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` error: casting function pointer `foo` to `i128` - --> $DIR/fn_to_numeric_cast.rs:14:13 + --> $DIR/fn_to_numeric_cast.rs:20:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `isize` - --> $DIR/fn_to_numeric_cast.rs:15:13 + --> $DIR/fn_to_numeric_cast.rs:22:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:17:13 + --> $DIR/fn_to_numeric_cast.rs:25:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:18:13 + --> $DIR/fn_to_numeric_cast.rs:27:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:19:13 + --> $DIR/fn_to_numeric_cast.rs:29:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u64` - --> $DIR/fn_to_numeric_cast.rs:20:13 + --> $DIR/fn_to_numeric_cast.rs:31:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `foo` to `u128` - --> $DIR/fn_to_numeric_cast.rs:21:13 + --> $DIR/fn_to_numeric_cast.rs:33:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: try: `foo as usize` error: casting function pointer `abc` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:34:13 + --> $DIR/fn_to_numeric_cast.rs:47:13 | LL | let _ = abc as i8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:35:13 + --> $DIR/fn_to_numeric_cast.rs:49:13 | LL | let _ = abc as i16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:36:13 + --> $DIR/fn_to_numeric_cast.rs:51:13 | LL | let _ = abc as i32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i64` - --> $DIR/fn_to_numeric_cast.rs:37:13 + --> $DIR/fn_to_numeric_cast.rs:53:13 | LL | let _ = abc as i64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `i128` - --> $DIR/fn_to_numeric_cast.rs:38:13 + --> $DIR/fn_to_numeric_cast.rs:55:13 | LL | let _ = abc as i128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `isize` - --> $DIR/fn_to_numeric_cast.rs:39:13 + --> $DIR/fn_to_numeric_cast.rs:57:13 | LL | let _ = abc as isize; | ^^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:41:13 + --> $DIR/fn_to_numeric_cast.rs:60:13 | LL | let _ = abc as u8; | ^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:42:13 + --> $DIR/fn_to_numeric_cast.rs:62:13 | LL | let _ = abc as u16; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:43:13 + --> $DIR/fn_to_numeric_cast.rs:64:13 | LL | let _ = abc as u32; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u64` - --> $DIR/fn_to_numeric_cast.rs:44:13 + --> $DIR/fn_to_numeric_cast.rs:66:13 | LL | let _ = abc as u64; | ^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `abc` to `u128` - --> $DIR/fn_to_numeric_cast.rs:45:13 + --> $DIR/fn_to_numeric_cast.rs:68:13 | LL | let _ = abc as u128; | ^^^^^^^^^^^ help: try: `abc as usize` error: casting function pointer `f` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:52:5 + --> $DIR/fn_to_numeric_cast.rs:76:5 | LL | f as i32 | ^^^^^^^^ help: try: `f as usize` diff --git a/tests/ui/fn_to_numeric_cast_32bit.rs b/tests/ui/fn_to_numeric_cast_32bit.rs index 62ce97f098d4c..93e9361f4dc5b 100644 --- a/tests/ui/fn_to_numeric_cast_32bit.rs +++ b/tests/ui/fn_to_numeric_cast_32bit.rs @@ -8,17 +8,30 @@ fn foo() -> String { fn test_function_to_numeric_cast() { let _ = foo as i8; + //~^ ERROR: casting function pointer `foo` to `i8`, which truncates the value + //~| NOTE: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` let _ = foo as i16; + //~^ ERROR: casting function pointer `foo` to `i16`, which truncates the value let _ = foo as i32; + //~^ ERROR: casting function pointer `foo` to `i32`, which truncates the value let _ = foo as i64; + //~^ ERROR: casting function pointer `foo` to `i64` + //~| NOTE: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` let _ = foo as i128; + //~^ ERROR: casting function pointer `foo` to `i128` let _ = foo as isize; + //~^ ERROR: casting function pointer `foo` to `isize` let _ = foo as u8; + //~^ ERROR: casting function pointer `foo` to `u8`, which truncates the value let _ = foo as u16; + //~^ ERROR: casting function pointer `foo` to `u16`, which truncates the value let _ = foo as u32; + //~^ ERROR: casting function pointer `foo` to `u32`, which truncates the value let _ = foo as u64; + //~^ ERROR: casting function pointer `foo` to `u64` let _ = foo as u128; + //~^ ERROR: casting function pointer `foo` to `u128` // Casting to usize is OK and should not warn let _ = foo as usize; @@ -32,17 +45,28 @@ fn test_function_var_to_numeric_cast() { let abc: fn() -> String = foo; let _ = abc as i8; + //~^ ERROR: casting function pointer `abc` to `i8`, which truncates the value let _ = abc as i16; + //~^ ERROR: casting function pointer `abc` to `i16`, which truncates the value let _ = abc as i32; + //~^ ERROR: casting function pointer `abc` to `i32`, which truncates the value let _ = abc as i64; + //~^ ERROR: casting function pointer `abc` to `i64` let _ = abc as i128; + //~^ ERROR: casting function pointer `abc` to `i128` let _ = abc as isize; + //~^ ERROR: casting function pointer `abc` to `isize` let _ = abc as u8; + //~^ ERROR: casting function pointer `abc` to `u8`, which truncates the value let _ = abc as u16; + //~^ ERROR: casting function pointer `abc` to `u16`, which truncates the value let _ = abc as u32; + //~^ ERROR: casting function pointer `abc` to `u32`, which truncates the value let _ = abc as u64; + //~^ ERROR: casting function pointer `abc` to `u64` let _ = abc as u128; + //~^ ERROR: casting function pointer `abc` to `u128` // Casting to usize is OK and should not warn let _ = abc as usize; @@ -50,6 +74,7 @@ fn test_function_var_to_numeric_cast() { fn fn_with_fn_args(f: fn(i32) -> i32) -> i32 { f as i32 + //~^ ERROR: casting function pointer `f` to `i32`, which truncates the value } fn main() {} diff --git a/tests/ui/fn_to_numeric_cast_any.rs b/tests/ui/fn_to_numeric_cast_any.rs index b77aefd38e590..95abc0ac68dd5 100644 --- a/tests/ui/fn_to_numeric_cast_any.rs +++ b/tests/ui/fn_to_numeric_cast_any.rs @@ -21,40 +21,58 @@ impl Trait for Struct {} fn fn_pointer_to_integer() { let _ = foo as i8; + //~^ ERROR: casting function pointer `foo` to `i8` + //~| NOTE: `-D clippy::fn-to-numeric-cast-any` implied by `-D warnings` let _ = foo as i16; + //~^ ERROR: casting function pointer `foo` to `i16` let _ = foo as i32; + //~^ ERROR: casting function pointer `foo` to `i32` let _ = foo as i64; + //~^ ERROR: casting function pointer `foo` to `i64` let _ = foo as i128; + //~^ ERROR: casting function pointer `foo` to `i128` let _ = foo as isize; + //~^ ERROR: casting function pointer `foo` to `isize` let _ = foo as u8; + //~^ ERROR: casting function pointer `foo` to `u8` let _ = foo as u16; + //~^ ERROR: casting function pointer `foo` to `u16` let _ = foo as u32; + //~^ ERROR: casting function pointer `foo` to `u32` let _ = foo as u64; + //~^ ERROR: casting function pointer `foo` to `u64` let _ = foo as u128; + //~^ ERROR: casting function pointer `foo` to `u128` let _ = foo as usize; + //~^ ERROR: casting function pointer `foo` to `usize` } fn static_method_to_integer() { let _ = Struct::static_method as usize; + //~^ ERROR: casting function pointer `Struct::static_method` to `usize` } fn fn_with_fn_arg(f: fn(i32) -> u32) -> usize { f as usize + //~^ ERROR: casting function pointer `f` to `usize` } fn fn_with_generic_static_trait_method() -> usize { T::static_method as usize + //~^ ERROR: casting function pointer `T::static_method` to `usize` } fn closure_to_fn_to_integer() { let clos = |x| x * 2_u32; let _ = (clos as fn(u32) -> u32) as usize; + //~^ ERROR: casting function pointer `(clos as fn(u32) -> u32)` to `usize` } fn fn_to_raw_ptr() { let _ = foo as *const (); + //~^ ERROR: casting function pointer `foo` to `*const ()` } fn cast_fn_to_self() { diff --git a/tests/ui/fn_to_numeric_cast_any.stderr b/tests/ui/fn_to_numeric_cast_any.stderr index a6c4a77672f86..36058965479c0 100644 --- a/tests/ui/fn_to_numeric_cast_any.stderr +++ b/tests/ui/fn_to_numeric_cast_any.stderr @@ -7,97 +7,97 @@ LL | let _ = foo as i8; = note: `-D clippy::fn-to-numeric-cast-any` implied by `-D warnings` error: casting function pointer `foo` to `i16` - --> $DIR/fn_to_numeric_cast_any.rs:24:13 + --> $DIR/fn_to_numeric_cast_any.rs:26:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i16` error: casting function pointer `foo` to `i32` - --> $DIR/fn_to_numeric_cast_any.rs:25:13 + --> $DIR/fn_to_numeric_cast_any.rs:28:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i32` error: casting function pointer `foo` to `i64` - --> $DIR/fn_to_numeric_cast_any.rs:26:13 + --> $DIR/fn_to_numeric_cast_any.rs:30:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i64` error: casting function pointer `foo` to `i128` - --> $DIR/fn_to_numeric_cast_any.rs:27:13 + --> $DIR/fn_to_numeric_cast_any.rs:32:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i128` error: casting function pointer `foo` to `isize` - --> $DIR/fn_to_numeric_cast_any.rs:28:13 + --> $DIR/fn_to_numeric_cast_any.rs:34:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as isize` error: casting function pointer `foo` to `u8` - --> $DIR/fn_to_numeric_cast_any.rs:30:13 + --> $DIR/fn_to_numeric_cast_any.rs:37:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u8` error: casting function pointer `foo` to `u16` - --> $DIR/fn_to_numeric_cast_any.rs:31:13 + --> $DIR/fn_to_numeric_cast_any.rs:39:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u16` error: casting function pointer `foo` to `u32` - --> $DIR/fn_to_numeric_cast_any.rs:32:13 + --> $DIR/fn_to_numeric_cast_any.rs:41:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u32` error: casting function pointer `foo` to `u64` - --> $DIR/fn_to_numeric_cast_any.rs:33:13 + --> $DIR/fn_to_numeric_cast_any.rs:43:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u64` error: casting function pointer `foo` to `u128` - --> $DIR/fn_to_numeric_cast_any.rs:34:13 + --> $DIR/fn_to_numeric_cast_any.rs:45:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u128` error: casting function pointer `foo` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:35:13 + --> $DIR/fn_to_numeric_cast_any.rs:47:13 | LL | let _ = foo as usize; | ^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as usize` error: casting function pointer `Struct::static_method` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:39:13 + --> $DIR/fn_to_numeric_cast_any.rs:52:13 | LL | let _ = Struct::static_method as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `Struct::static_method() as usize` error: casting function pointer `f` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:43:5 + --> $DIR/fn_to_numeric_cast_any.rs:57:5 | LL | f as usize | ^^^^^^^^^^ help: did you mean to invoke the function?: `f() as usize` error: casting function pointer `T::static_method` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:47:5 + --> $DIR/fn_to_numeric_cast_any.rs:62:5 | LL | T::static_method as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `T::static_method() as usize` error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:53:13 + --> $DIR/fn_to_numeric_cast_any.rs:69:13 | LL | let _ = (clos as fn(u32) -> u32) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `(clos as fn(u32) -> u32)() as usize` error: casting function pointer `foo` to `*const ()` - --> $DIR/fn_to_numeric_cast_any.rs:57:13 + --> $DIR/fn_to_numeric_cast_any.rs:74:13 | LL | let _ = foo as *const (); | ^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as *const ()` diff --git a/tests/ui/for_kv_map.fixed b/tests/ui/for_kv_map.fixed index 703ae98e8ed57..a2112d7b73005 100644 --- a/tests/ui/for_kv_map.fixed +++ b/tests/ui/for_kv_map.fixed @@ -7,11 +7,14 @@ use std::rc::Rc; fn main() { let m: HashMap = HashMap::new(); for v in m.values() { + //~^ ERROR: you seem to want to iterate on a map's values + //~| NOTE: `-D clippy::for-kv-map` implied by `-D warnings` let _v = v; } let m: Rc> = Rc::new(HashMap::new()); for v in (*m).values() { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; // Here the `*` is not actually necessary, but the test tests that we don't // suggest @@ -20,17 +23,20 @@ fn main() { let mut m: HashMap = HashMap::new(); for v in m.values_mut() { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: &mut HashMap = &mut HashMap::new(); for v in (*m).values_mut() { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: HashMap = HashMap::new(); let rm = &m; for k in rm.keys() { + //~^ ERROR: you seem to want to iterate on a map's keys let _k = k; } diff --git a/tests/ui/for_kv_map.rs b/tests/ui/for_kv_map.rs index 39a8d960a7e91..1b7959b8f92d6 100644 --- a/tests/ui/for_kv_map.rs +++ b/tests/ui/for_kv_map.rs @@ -7,11 +7,14 @@ use std::rc::Rc; fn main() { let m: HashMap = HashMap::new(); for (_, v) in &m { + //~^ ERROR: you seem to want to iterate on a map's values + //~| NOTE: `-D clippy::for-kv-map` implied by `-D warnings` let _v = v; } let m: Rc> = Rc::new(HashMap::new()); for (_, v) in &*m { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; // Here the `*` is not actually necessary, but the test tests that we don't // suggest @@ -20,17 +23,20 @@ fn main() { let mut m: HashMap = HashMap::new(); for (_, v) in &mut m { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: &mut HashMap = &mut HashMap::new(); for (_, v) in &mut *m { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: HashMap = HashMap::new(); let rm = &m; for (k, _value) in rm { + //~^ ERROR: you seem to want to iterate on a map's keys let _k = k; } diff --git a/tests/ui/for_kv_map.stderr b/tests/ui/for_kv_map.stderr index e5cc7c1466ab4..d5e4ef0b4ba36 100644 --- a/tests/ui/for_kv_map.stderr +++ b/tests/ui/for_kv_map.stderr @@ -11,7 +11,7 @@ LL | for v in m.values() { | ~ ~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:14:19 + --> $DIR/for_kv_map.rs:16:19 | LL | for (_, v) in &*m { | ^^^ @@ -22,7 +22,7 @@ LL | for v in (*m).values() { | ~ ~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:22:19 + --> $DIR/for_kv_map.rs:25:19 | LL | for (_, v) in &mut m { | ^^^^^^ @@ -33,7 +33,7 @@ LL | for v in m.values_mut() { | ~ ~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:27:19 + --> $DIR/for_kv_map.rs:31:19 | LL | for (_, v) in &mut *m { | ^^^^^^^ @@ -44,7 +44,7 @@ LL | for v in (*m).values_mut() { | ~ ~~~~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's keys - --> $DIR/for_kv_map.rs:33:24 + --> $DIR/for_kv_map.rs:38:24 | LL | for (k, _value) in rm { | ^^ diff --git a/tests/ui/forget_non_drop.rs b/tests/ui/forget_non_drop.rs index 7580cf95ebfa8..2459f51a38dac 100644 --- a/tests/ui/forget_non_drop.rs +++ b/tests/ui/forget_non_drop.rs @@ -11,6 +11,7 @@ fn main() { struct Foo; // Lint forget(Foo); + //~^ ERROR: call to `std::mem::forget` with a value that does not implement `Drop`. Fo struct Bar; impl Drop for Bar { @@ -22,6 +23,7 @@ fn main() { struct Baz(T); // Lint forget(Baz(Foo)); + //~^ ERROR: call to `std::mem::forget` with a value that does not implement `Drop`. Fo // Don't lint forget(Baz(Bar)); } diff --git a/tests/ui/forget_non_drop.stderr b/tests/ui/forget_non_drop.stderr index 194e37c8b4247..4634dc67f02db 100644 --- a/tests/ui/forget_non_drop.stderr +++ b/tests/ui/forget_non_drop.stderr @@ -12,13 +12,13 @@ LL | forget(Foo); = note: `-D clippy::forget-non-drop` implied by `-D warnings` error: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it - --> $DIR/forget_non_drop.rs:24:5 + --> $DIR/forget_non_drop.rs:25:5 | LL | forget(Baz(Foo)); | ^^^^^^^^^^^^^^^^ | note: argument has type `main::Baz` - --> $DIR/forget_non_drop.rs:24:12 + --> $DIR/forget_non_drop.rs:25:12 | LL | forget(Baz(Foo)); | ^^^^^^^^ diff --git a/tests/ui/format_args_unfixable.rs b/tests/ui/format_args_unfixable.rs index 423bfaf97965e..b7492e38b256b 100644 --- a/tests/ui/format_args_unfixable.rs +++ b/tests/ui/format_args_unfixable.rs @@ -24,31 +24,49 @@ fn main() { let x = 'x'; println!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("{}: {}", error, format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("{:?}: {}", error, format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("{{}}: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!(r#"error: "{}""#, format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("error: {}", format!(r#"something failed at "{}""#, Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("error: {}", format!("something failed at {} {0}", Location::caller())); + //~^ ERROR: `format!` in `println!` args let _ = format!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `format!` args let _ = write!( + //~^ ERROR: `format!` in `write!` args stdout(), "error: {}", format!("something failed at {}", Location::caller()) ); let _ = writeln!( + //~^ ERROR: `format!` in `writeln!` args stdout(), "error: {}", format!("something failed at {}", Location::caller()) ); print!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `print!` args eprint!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `eprint!` args eprintln!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `eprintln!` args let _ = format_args!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `format_args!` args assert!(true, "error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `assert!` args assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `assert_eq!` args assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `assert_ne!` args panic!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `panic!` args // negative tests println!("error: {}", format_args!("something failed at {}", Location::caller())); diff --git a/tests/ui/format_args_unfixable.stderr b/tests/ui/format_args_unfixable.stderr index c1be48c3b7269..430c435957931 100644 --- a/tests/ui/format_args_unfixable.stderr +++ b/tests/ui/format_args_unfixable.stderr @@ -9,7 +9,7 @@ LL | println!("error: {}", format!("something failed at {}", Location::calle = note: `-D clippy::format-in-format-args` implied by `-D warnings` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:27:5 + --> $DIR/format_args_unfixable.rs:28:5 | LL | println!("{}: {}", error, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | println!("{}: {}", error, format!("something failed at {}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:28:5 + --> $DIR/format_args_unfixable.rs:30:5 | LL | println!("{:?}: {}", error, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | println!("{:?}: {}", error, format!("something failed at {}", Location: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:29:5 + --> $DIR/format_args_unfixable.rs:32:5 | LL | println!("{{}}: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | println!("{{}}: {}", format!("something failed at {}", Location::caller = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:30:5 + --> $DIR/format_args_unfixable.rs:34:5 | LL | println!(r#"error: "{}""#, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | println!(r#"error: "{}""#, format!("something failed at {}", Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:31:5 + --> $DIR/format_args_unfixable.rs:36:5 | LL | println!("error: {}", format!(r#"something failed at "{}""#, Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | println!("error: {}", format!(r#"something failed at "{}""#, Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:32:5 + --> $DIR/format_args_unfixable.rs:38:5 | LL | println!("error: {}", format!("something failed at {} {0}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | println!("error: {}", format!("something failed at {} {0}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `format!` args - --> $DIR/format_args_unfixable.rs:33:13 + --> $DIR/format_args_unfixable.rs:40:13 | LL | let _ = format!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,10 +72,11 @@ LL | let _ = format!("error: {}", format!("something failed at {}", Location = help: or consider changing `format!` to `format_args!` error: `format!` in `write!` args - --> $DIR/format_args_unfixable.rs:34:13 + --> $DIR/format_args_unfixable.rs:42:13 | LL | let _ = write!( | _____________^ +LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -86,10 +87,11 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `writeln!` args - --> $DIR/format_args_unfixable.rs:39:13 + --> $DIR/format_args_unfixable.rs:48:13 | LL | let _ = writeln!( | _____________^ +LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -100,7 +102,7 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `print!` args - --> $DIR/format_args_unfixable.rs:44:5 + --> $DIR/format_args_unfixable.rs:54:5 | LL | print!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +111,7 @@ LL | print!("error: {}", format!("something failed at {}", Location::caller( = help: or consider changing `format!` to `format_args!` error: `format!` in `eprint!` args - --> $DIR/format_args_unfixable.rs:45:5 + --> $DIR/format_args_unfixable.rs:56:5 | LL | eprint!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +120,7 @@ LL | eprint!("error: {}", format!("something failed at {}", Location::caller = help: or consider changing `format!` to `format_args!` error: `format!` in `eprintln!` args - --> $DIR/format_args_unfixable.rs:46:5 + --> $DIR/format_args_unfixable.rs:58:5 | LL | eprintln!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -127,7 +129,7 @@ LL | eprintln!("error: {}", format!("something failed at {}", Location::call = help: or consider changing `format!` to `format_args!` error: `format!` in `format_args!` args - --> $DIR/format_args_unfixable.rs:47:13 + --> $DIR/format_args_unfixable.rs:60:13 | LL | let _ = format_args!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +138,7 @@ LL | let _ = format_args!("error: {}", format!("something failed at {}", Loc = help: or consider changing `format!` to `format_args!` error: `format!` in `assert!` args - --> $DIR/format_args_unfixable.rs:48:5 + --> $DIR/format_args_unfixable.rs:62:5 | LL | assert!(true, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +147,7 @@ LL | assert!(true, "error: {}", format!("something failed at {}", Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `assert_eq!` args - --> $DIR/format_args_unfixable.rs:49:5 + --> $DIR/format_args_unfixable.rs:64:5 | LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +156,7 @@ LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Locatio = help: or consider changing `format!` to `format_args!` error: `format!` in `assert_ne!` args - --> $DIR/format_args_unfixable.rs:50:5 + --> $DIR/format_args_unfixable.rs:66:5 | LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -163,7 +165,7 @@ LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Locatio = help: or consider changing `format!` to `format_args!` error: `format!` in `panic!` args - --> $DIR/format_args_unfixable.rs:51:5 + --> $DIR/format_args_unfixable.rs:68:5 | LL | panic!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/format_collect.rs b/tests/ui/format_collect.rs index c7f2b7b695074..26ebdc6c0cb61 100644 --- a/tests/ui/format_collect.rs +++ b/tests/ui/format_collect.rs @@ -3,11 +3,13 @@ fn hex_encode(bytes: &[u8]) -> String { bytes.iter().map(|b| format!("{b:02X}")).collect() + //~^ ERROR: use of `format!` to build up a string from an iterator } #[rustfmt::skip] fn hex_encode_deep(bytes: &[u8]) -> String { bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() + //~^ ERROR: use of `format!` to build up a string from an iterator } macro_rules! fmt { @@ -22,6 +24,7 @@ fn from_macro(bytes: &[u8]) -> String { fn with_block() -> String { (1..10) + //~^ ERROR: use of `format!` to build up a string from an iterator .map(|s| { let y = 1; format!("{s} {y}") diff --git a/tests/ui/format_collect.stderr b/tests/ui/format_collect.stderr index d918f1ed466b1..79e353111f387 100644 --- a/tests/ui/format_collect.stderr +++ b/tests/ui/format_collect.stderr @@ -18,27 +18,28 @@ LL | bytes.iter().map(|b| format!("{b:02X}")).collect() = note: `-D clippy::format-collect` implied by `-D warnings` error: use of `format!` to build up a string from an iterator - --> $DIR/format_collect.rs:10:5 + --> $DIR/format_collect.rs:11:5 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: call `fold` instead - --> $DIR/format_collect.rs:10:18 + --> $DIR/format_collect.rs:11:18 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^ help: ... and use the `write!` macro here - --> $DIR/format_collect.rs:10:32 + --> $DIR/format_collect.rs:11:32 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^^^^^^^^^^^^^^^^ = note: this can be written more efficiently by appending to a `String` directly error: use of `format!` to build up a string from an iterator - --> $DIR/format_collect.rs:24:5 + --> $DIR/format_collect.rs:26:5 | LL | / (1..10) +LL | | LL | | .map(|s| { LL | | let y = 1; LL | | format!("{s} {y}") @@ -47,12 +48,12 @@ LL | | .collect() | |__________________^ | help: call `fold` instead - --> $DIR/format_collect.rs:25:10 + --> $DIR/format_collect.rs:28:10 | LL | .map(|s| { | ^^^ help: ... and use the `write!` macro here - --> $DIR/format_collect.rs:27:13 + --> $DIR/format_collect.rs:30:13 | LL | format!("{s} {y}") | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/format_push_string.rs b/tests/ui/format_push_string.rs index 89423ffe1cf8c..735ae3393289e 100644 --- a/tests/ui/format_push_string.rs +++ b/tests/ui/format_push_string.rs @@ -3,7 +3,9 @@ fn main() { let mut string = String::new(); string += &format!("{:?}", 1234); + //~^ ERROR: `format!(..)` appended to existing `String` string.push_str(&format!("{:?}", 5678)); + //~^ ERROR: `format!(..)` appended to existing `String` } mod issue9493 { @@ -11,6 +13,7 @@ mod issue9493 { let mut hex = String::with_capacity(vector.len() * 2); for byte in vector { hex += &(if upper { + //~^ ERROR: `format!(..)` appended to existing `String` format!("{byte:02X}") } else { format!("{byte:02x}") @@ -23,12 +26,14 @@ mod issue9493 { let mut s = String::new(); // if let s += &(if let Some(_a) = Some(1234) { + //~^ ERROR: `format!(..)` appended to existing `String` format!("{}", 1234) } else { format!("{}", 1234) }); // match s += &(match Some(1234) { + //~^ ERROR: `format!(..)` appended to existing `String` Some(_) => format!("{}", 1234), None => format!("{}", 1234), }); diff --git a/tests/ui/format_push_string.stderr b/tests/ui/format_push_string.stderr index 76762c4a1d1f7..d862dd6dc5f36 100644 --- a/tests/ui/format_push_string.stderr +++ b/tests/ui/format_push_string.stderr @@ -8,7 +8,7 @@ LL | string += &format!("{:?}", 1234); = note: `-D clippy::format-push-string` implied by `-D warnings` error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:6:5 + --> $DIR/format_push_string.rs:7:5 | LL | string.push_str(&format!("{:?}", 5678)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,9 +16,10 @@ LL | string.push_str(&format!("{:?}", 5678)); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:13:13 + --> $DIR/format_push_string.rs:15:13 | LL | / hex += &(if upper { +LL | | LL | | format!("{byte:02X}") LL | | } else { LL | | format!("{byte:02x}") @@ -28,9 +29,10 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:25:9 + --> $DIR/format_push_string.rs:28:9 | LL | / s += &(if let Some(_a) = Some(1234) { +LL | | LL | | format!("{}", 1234) LL | | } else { LL | | format!("{}", 1234) @@ -40,9 +42,10 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:31:9 + --> $DIR/format_push_string.rs:35:9 | LL | / s += &(match Some(1234) { +LL | | LL | | Some(_) => format!("{}", 1234), LL | | None => format!("{}", 1234), LL | | }); diff --git a/tests/ui/formatting.rs b/tests/ui/formatting.rs index 471a8e0de6e19..312fa2aa40ad2 100644 --- a/tests/ui/formatting.rs +++ b/tests/ui/formatting.rs @@ -14,10 +14,16 @@ fn main() { // weird op_eq formatting: let mut a = 42; a =- 35; + //~^ ERROR: this looks like you are trying to use `.. -= ..`, but you really are doing + //~| NOTE: to remove this lint, use either `-=` or `= -` a =* &191; + //~^ ERROR: this looks like you are trying to use `.. *= ..`, but you really are doing + //~| NOTE: to remove this lint, use either `*=` or `= *` let mut b = true; b =! false; + //~^ ERROR: this looks like you are trying to use `.. != ..`, but you really are doing + //~| NOTE: to remove this lint, use either `!=` or `= !` // those are ok: a = -35; @@ -27,10 +33,14 @@ fn main() { // possible missing comma in an array let _ = &[ -1, -2, -3 // <= no comma here + //~^ ERROR: possibly missing a comma here + //~| NOTE: to remove this lint, add a comma or write the expr in a single line -4, -5, -6 ]; let _ = &[ -1, -2, -3 // <= no comma here + //~^ ERROR: possibly missing a comma here + //~| NOTE: to remove this lint, add a comma or write the expr in a single line *4, -5, -6 ]; @@ -68,6 +78,8 @@ fn main() { // lint if it doesn't let _ = &[ -1 + //~^ ERROR: possibly missing a comma here + //~| NOTE: to remove this lint, add a comma or write the expr in a single line -4, ]; } diff --git a/tests/ui/formatting.stderr b/tests/ui/formatting.stderr index caccd5cba1784..1266d143cb165 100644 --- a/tests/ui/formatting.stderr +++ b/tests/ui/formatting.stderr @@ -8,7 +8,7 @@ LL | a =- 35; = note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings` error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)` - --> $DIR/formatting.rs:17:6 + --> $DIR/formatting.rs:19:6 | LL | a =* &191; | ^^^^ @@ -16,7 +16,7 @@ LL | a =* &191; = note: to remove this lint, use either `*=` or `= *` error: this looks like you are trying to use `.. != ..`, but you really are doing `.. = (! ..)` - --> $DIR/formatting.rs:20:6 + --> $DIR/formatting.rs:24:6 | LL | b =! false; | ^^^^ @@ -24,7 +24,7 @@ LL | b =! false; = note: to remove this lint, use either `!=` or `= !` error: possibly missing a comma here - --> $DIR/formatting.rs:29:19 + --> $DIR/formatting.rs:35:19 | LL | -1, -2, -3 // <= no comma here | ^ @@ -33,7 +33,7 @@ LL | -1, -2, -3 // <= no comma here = note: `-D clippy::possible-missing-comma` implied by `-D warnings` error: possibly missing a comma here - --> $DIR/formatting.rs:33:19 + --> $DIR/formatting.rs:41:19 | LL | -1, -2, -3 // <= no comma here | ^ @@ -41,7 +41,7 @@ LL | -1, -2, -3 // <= no comma here = note: to remove this lint, add a comma or write the expr in a single line error: possibly missing a comma here - --> $DIR/formatting.rs:70:11 + --> $DIR/formatting.rs:80:11 | LL | -1 | ^ diff --git a/tests/ui/from_over_into_unfixable.rs b/tests/ui/from_over_into_unfixable.rs index c769e38eb33a0..0c1f39f93fd33 100644 --- a/tests/ui/from_over_into_unfixable.rs +++ b/tests/ui/from_over_into_unfixable.rs @@ -9,6 +9,7 @@ macro_rules! in_macro { } impl Into for String { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> InMacro { InMacro(in_macro!()) } @@ -17,6 +18,7 @@ impl Into for String { struct WeirdUpperSelf; impl Into for &'static [u8] { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> WeirdUpperSelf { let _ = Self::default(); WeirdUpperSelf @@ -26,6 +28,7 @@ impl Into for &'static [u8] { struct ContainsVal; impl Into for ContainsVal { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> u8 { let val = 1; val + 1 @@ -37,6 +40,7 @@ pub struct Lval(T); pub struct Rval(T); impl Into> for Lval { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> Rval { Rval(self) } diff --git a/tests/ui/from_over_into_unfixable.stderr b/tests/ui/from_over_into_unfixable.stderr index 2ab9b9d6b17cc..3470eff9e9585 100644 --- a/tests/ui/from_over_into_unfixable.stderr +++ b/tests/ui/from_over_into_unfixable.stderr @@ -8,7 +8,7 @@ LL | impl Into for String { = note: `-D clippy::from-over-into` implied by `-D warnings` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:19:1 + --> $DIR/from_over_into_unfixable.rs:20:1 | LL | impl Into for &'static [u8] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | impl Into for &'static [u8] { = help: replace the `Into` implementation with `From<&'static [u8]>` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:28:1 + --> $DIR/from_over_into_unfixable.rs:30:1 | LL | impl Into for ContainsVal { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | impl Into for ContainsVal { = help: replace the `Into` implementation with `From` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:39:1 + --> $DIR/from_over_into_unfixable.rs:42:1 | LL | impl Into> for Lval { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/from_raw_with_void_ptr.rs b/tests/ui/from_raw_with_void_ptr.rs index 95ef6425fad9a..81472070eb4ce 100644 --- a/tests/ui/from_raw_with_void_ptr.rs +++ b/tests/ui/from_raw_with_void_ptr.rs @@ -9,6 +9,7 @@ fn main() { // must lint let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void; let _ = unsafe { Box::from_raw(ptr) }; + //~^ ERROR: creating a `Box` from a void raw pointer // shouldn't be linted let _ = unsafe { Box::from_raw(ptr as *mut usize) }; @@ -20,16 +21,20 @@ fn main() { // must lint let ptr = Rc::into_raw(Rc::new(42usize)) as *mut c_void; let _ = unsafe { Rc::from_raw(ptr) }; + //~^ ERROR: creating a `Rc` from a void raw pointer // must lint let ptr = Arc::into_raw(Arc::new(42usize)) as *mut c_void; let _ = unsafe { Arc::from_raw(ptr) }; + //~^ ERROR: creating a `Arc` from a void raw pointer // must lint let ptr = std::rc::Weak::into_raw(Rc::downgrade(&Rc::new(42usize))) as *mut c_void; let _ = unsafe { std::rc::Weak::from_raw(ptr) }; + //~^ ERROR: creating a `Weak` from a void raw pointer // must lint let ptr = std::sync::Weak::into_raw(Arc::downgrade(&Arc::new(42usize))) as *mut c_void; let _ = unsafe { std::sync::Weak::from_raw(ptr) }; + //~^ ERROR: creating a `Weak` from a void raw pointer } diff --git a/tests/ui/from_raw_with_void_ptr.stderr b/tests/ui/from_raw_with_void_ptr.stderr index 1963d08014b15..b6460862419d3 100644 --- a/tests/ui/from_raw_with_void_ptr.stderr +++ b/tests/ui/from_raw_with_void_ptr.stderr @@ -12,49 +12,49 @@ LL | let _ = unsafe { Box::from_raw(ptr) }; = note: `-D clippy::from-raw-with-void-ptr` implied by `-D warnings` error: creating a `Rc` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:22:22 + --> $DIR/from_raw_with_void_ptr.rs:23:22 | LL | let _ = unsafe { Rc::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:22:35 + --> $DIR/from_raw_with_void_ptr.rs:23:35 | LL | let _ = unsafe { Rc::from_raw(ptr) }; | ^^^ error: creating a `Arc` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:26:22 + --> $DIR/from_raw_with_void_ptr.rs:28:22 | LL | let _ = unsafe { Arc::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:26:36 + --> $DIR/from_raw_with_void_ptr.rs:28:36 | LL | let _ = unsafe { Arc::from_raw(ptr) }; | ^^^ error: creating a `Weak` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:30:22 + --> $DIR/from_raw_with_void_ptr.rs:33:22 | LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:30:46 + --> $DIR/from_raw_with_void_ptr.rs:33:46 | LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) }; | ^^^ error: creating a `Weak` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:34:22 + --> $DIR/from_raw_with_void_ptr.rs:38:22 | LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:34:48 + --> $DIR/from_raw_with_void_ptr.rs:38:48 | LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) }; | ^^^ diff --git a/tests/ui/from_str_radix_10.fixed b/tests/ui/from_str_radix_10.fixed index b0fb88f988ada..8c253bfd99a57 100644 --- a/tests/ui/from_str_radix_10.fixed +++ b/tests/ui/from_str_radix_10.fixed @@ -26,17 +26,26 @@ impl std::ops::Add for Test { fn main() -> Result<(), Box> { // all of these should trigger the lint "30".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~| NOTE: `-D clippy::from-str-radix-10` implied by `-D warnings` "24".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` "100".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` "7".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` ("10".to_owned() + "5").parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` (Test + Test).parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let string = "300"; string.parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let stringier = "400".to_string(); stringier.parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` // none of these should trigger the lint u16::from_str_radix("20", 3)?; diff --git a/tests/ui/from_str_radix_10.rs b/tests/ui/from_str_radix_10.rs index 2f2ea04847a98..e9d02215710cb 100644 --- a/tests/ui/from_str_radix_10.rs +++ b/tests/ui/from_str_radix_10.rs @@ -26,17 +26,26 @@ impl std::ops::Add for Test { fn main() -> Result<(), Box> { // all of these should trigger the lint u32::from_str_radix("30", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~| NOTE: `-D clippy::from-str-radix-10` implied by `-D warnings` i64::from_str_radix("24", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` isize::from_str_radix("100", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` u8::from_str_radix("7", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` u16::from_str_radix(&("10".to_owned() + "5"), 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` i128::from_str_radix(Test + Test, 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let string = "300"; i32::from_str_radix(string, 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let stringier = "400".to_string(); i32::from_str_radix(&stringier, 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` // none of these should trigger the lint u16::from_str_radix("20", 3)?; diff --git a/tests/ui/from_str_radix_10.stderr b/tests/ui/from_str_radix_10.stderr index da5c16f8d01a8..1fbd1e3a5f20d 100644 --- a/tests/ui/from_str_radix_10.stderr +++ b/tests/ui/from_str_radix_10.stderr @@ -7,43 +7,43 @@ LL | u32::from_str_radix("30", 10)?; = note: `-D clippy::from-str-radix-10` implied by `-D warnings` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:29:5 + --> $DIR/from_str_radix_10.rs:31:5 | LL | i64::from_str_radix("24", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"24".parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:30:5 + --> $DIR/from_str_radix_10.rs:33:5 | LL | isize::from_str_radix("100", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"100".parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:31:5 + --> $DIR/from_str_radix_10.rs:35:5 | LL | u8::from_str_radix("7", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"7".parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:32:5 + --> $DIR/from_str_radix_10.rs:37:5 | LL | u16::from_str_radix(&("10".to_owned() + "5"), 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `("10".to_owned() + "5").parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:33:5 + --> $DIR/from_str_radix_10.rs:39:5 | LL | i128::from_str_radix(Test + Test, 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(Test + Test).parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:36:5 + --> $DIR/from_str_radix_10.rs:43:5 | LL | i32::from_str_radix(string, 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:39:5 + --> $DIR/from_str_radix_10.rs:47:5 | LL | i32::from_str_radix(&stringier, 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `stringier.parse::()` diff --git a/tests/ui/functions.rs b/tests/ui/functions.rs index 18149bfbc3fe0..0aef60959593b 100644 --- a/tests/ui/functions.rs +++ b/tests/ui/functions.rs @@ -6,9 +6,12 @@ fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} +//~^ ERROR: this function has too many arguments (8/7) +//~| NOTE: `-D clippy::too-many-arguments` implied by `-D warnings` #[rustfmt::skip] fn bad_multiline( +//~^ ERROR: this function has too many arguments (8/7) one: u32, two: u32, three: &str, @@ -43,6 +46,7 @@ extern "C" fn extern_fn( pub trait Foo { fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool); fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); + //~^ ERROR: this function has too many arguments (8/7) fn ptr(p: *const u8); } @@ -52,6 +56,7 @@ pub struct Bar; impl Bar { fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} + //~^ ERROR: this function has too many arguments (8/7) } // ok, we don’t want to warn implementations @@ -61,8 +66,12 @@ impl Foo for Bar { fn ptr(p: *const u8) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked + //~| NOTE: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings` println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked } } @@ -74,16 +83,22 @@ fn private(p: *const u8) { pub fn public(p: *const u8) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un } type Alias = *const u8; pub fn type_alias(p: Alias) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un } impl Bar { @@ -93,8 +108,11 @@ impl Bar { pub fn public(self, p: *const u8) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked } pub fn public_ok(self, p: *const u8) { diff --git a/tests/ui/functions.stderr b/tests/ui/functions.stderr index 8ebd4997f4f6e..fb8f4511e9951 100644 --- a/tests/ui/functions.stderr +++ b/tests/ui/functions.stderr @@ -7,31 +7,31 @@ LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f = note: `-D clippy::too-many-arguments` implied by `-D warnings` error: this function has too many arguments (8/7) - --> $DIR/functions.rs:11:1 + --> $DIR/functions.rs:13:1 | LL | / fn bad_multiline( +LL | | LL | | one: u32, LL | | two: u32, -LL | | three: &str, ... | LL | | eight: () LL | | ) { | |__^ error: this function has too many arguments (8/7) - --> $DIR/functions.rs:45:5 + --> $DIR/functions.rs:48:5 | LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this function has too many arguments (8/7) - --> $DIR/functions.rs:54:5 + --> $DIR/functions.rs:58:5 | LL | fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:63:34 + --> $DIR/functions.rs:68:34 | LL | println!("{}", unsafe { *p }); | ^ @@ -39,67 +39,67 @@ LL | println!("{}", unsafe { *p }); = note: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings` error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:64:35 + --> $DIR/functions.rs:71:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:65:33 + --> $DIR/functions.rs:73:33 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:76:30 + --> $DIR/functions.rs:85:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:77:31 + --> $DIR/functions.rs:87:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:78:29 + --> $DIR/functions.rs:89:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:84:30 + --> $DIR/functions.rs:96:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:85:31 + --> $DIR/functions.rs:98:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:86:29 + --> $DIR/functions.rs:100:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:95:34 + --> $DIR/functions.rs:110:34 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:96:35 + --> $DIR/functions.rs:112:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:97:33 + --> $DIR/functions.rs:114:33 | LL | unsafe { std::ptr::read(p) }; | ^ diff --git a/tests/ui/functions_maxlines.rs b/tests/ui/functions_maxlines.rs index 5e1ee55e01040..a3496f56d4a62 100644 --- a/tests/ui/functions_maxlines.rs +++ b/tests/ui/functions_maxlines.rs @@ -56,6 +56,8 @@ fn good_lines() { } fn bad_lines() { + //~^ ERROR: this function has too many lines (102/100) + //~| NOTE: `-D clippy::too-many-lines` implied by `-D warnings` println!("Dont get confused by braces: {{}}"); println!("This is bad."); println!("This is bad."); diff --git a/tests/ui/functions_maxlines.stderr b/tests/ui/functions_maxlines.stderr index dc6c8ba2f154d..6551892363c49 100644 --- a/tests/ui/functions_maxlines.stderr +++ b/tests/ui/functions_maxlines.stderr @@ -2,9 +2,9 @@ error: this function has too many lines (102/100) --> $DIR/functions_maxlines.rs:58:1 | LL | / fn bad_lines() { +LL | | +LL | | LL | | println!("Dont get confused by braces: {{}}"); -LL | | println!("This is bad."); -LL | | println!("This is bad."); ... | LL | | println!("This is bad."); LL | | } diff --git a/tests/ui/future_not_send.rs b/tests/ui/future_not_send.rs index 858036692d68f..06090e2713dee 100644 --- a/tests/ui/future_not_send.rs +++ b/tests/ui/future_not_send.rs @@ -5,10 +5,12 @@ use std::rc::Rc; use std::sync::Arc; async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { + //~^ ERROR: future cannot be sent between threads safely async { true }.await } pub async fn public_future(rc: Rc<[u8]>) { + //~^ ERROR: future cannot be sent between threads safely async { true }.await; } @@ -17,10 +19,12 @@ pub async fn public_send(arc: Arc<[u8]>) -> bool { } async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { + //~^ ERROR: future cannot be sent between threads safely true } pub async fn public_future2(rc: Rc<[u8]>) {} +//~^ ERROR: future cannot be sent between threads safely pub async fn public_send2(arc: Arc<[u8]>) -> bool { false @@ -32,11 +36,13 @@ struct Dummy { impl Dummy { async fn private_future(&self) -> usize { + //~^ ERROR: future cannot be sent between threads safely async { true }.await; self.rc.len() } pub async fn public_future(&self) { + //~^ ERROR: future cannot be sent between threads safely self.private_future().await; } @@ -47,6 +53,7 @@ impl Dummy { } async fn generic_future(t: T) -> T +//~^ ERROR: future cannot be sent between threads safely where T: Send, { @@ -63,6 +70,7 @@ where } async fn unclear_future(t: T) {} +//~^ ERROR: future cannot be sent between threads safely fn main() { let rc = Rc::new([1, 2, 3]); diff --git a/tests/ui/future_not_send.stderr b/tests/ui/future_not_send.stderr index 5c6348962a5eb..9628cf3a1b952 100644 --- a/tests/ui/future_not_send.stderr +++ b/tests/ui/future_not_send.stderr @@ -5,20 +5,22 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:20 + --> $DIR/future_not_send.rs:9:20 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | -- has type `std::rc::Rc<[u8]>` which is not `Send` +LL | LL | async { true }.await | ^^^^^ await occurs here, with `rc` maybe used later LL | } | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:20 + --> $DIR/future_not_send.rs:9:20 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | ---- has type `&std::cell::Cell` which is not `Send` +LL | LL | async { true }.await | ^^^^^ await occurs here, with `cell` maybe used later LL | } @@ -27,16 +29,17 @@ LL | } = note: `-D clippy::future-not-send` implied by `-D warnings` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:11:42 + --> $DIR/future_not_send.rs:12:42 | LL | pub async fn public_future(rc: Rc<[u8]>) { | ^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:12:20 + --> $DIR/future_not_send.rs:14:20 | LL | pub async fn public_future(rc: Rc<[u8]>) { | -- has type `std::rc::Rc<[u8]>` which is not `Send` +LL | LL | async { true }.await; | ^^^^^ await occurs here, with `rc` maybe used later LL | } @@ -44,48 +47,49 @@ LL | } = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:19:63 + --> $DIR/future_not_send.rs:21:63 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ future returned by `private_future2` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:19:26 + --> $DIR/future_not_send.rs:21:26 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^ has type `std::rc::Rc<[u8]>` which is not `Send` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` - --> $DIR/future_not_send.rs:19:40 + --> $DIR/future_not_send.rs:21:40 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ has type `&std::cell::Cell` which is not `Send`, because `std::cell::Cell` is not `Sync` = note: `std::cell::Cell` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:23:43 + --> $DIR/future_not_send.rs:26:43 | LL | pub async fn public_future2(rc: Rc<[u8]>) {} | ^ future returned by `public_future2` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:23:29 + --> $DIR/future_not_send.rs:26:29 | LL | pub async fn public_future2(rc: Rc<[u8]>) {} | ^^ has type `std::rc::Rc<[u8]>` which is not `Send` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:34:39 + --> $DIR/future_not_send.rs:38:39 | LL | async fn private_future(&self) -> usize { | ^^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:35:24 + --> $DIR/future_not_send.rs:40:24 | LL | async fn private_future(&self) -> usize { | ----- has type `&Dummy` which is not `Send` +LL | LL | async { true }.await; | ^^^^^ await occurs here, with `&self` maybe used later LL | self.rc.len() @@ -94,16 +98,17 @@ LL | } = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:39:39 + --> $DIR/future_not_send.rs:44:39 | LL | pub async fn public_future(&self) { | ^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:40:31 + --> $DIR/future_not_send.rs:46:31 | LL | pub async fn public_future(&self) { | ----- has type `&Dummy` which is not `Send` +LL | LL | self.private_future().await; | ^^^^^ await occurs here, with `&self` maybe used later LL | } @@ -111,13 +116,13 @@ LL | } = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:49:37 + --> $DIR/future_not_send.rs:55:37 | LL | async fn generic_future(t: T) -> T | ^ future returned by `generic_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:54:20 + --> $DIR/future_not_send.rs:61:20 | LL | let rt = &t; | -- has type `&T` which is not `Send` @@ -129,13 +134,13 @@ LL | } = note: `T` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:65:34 + --> $DIR/future_not_send.rs:72:34 | LL | async fn unclear_future(t: T) {} | ^ future returned by `unclear_future` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:65:28 + --> $DIR/future_not_send.rs:72:28 | LL | async fn unclear_future(t: T) {} | ^ has type `T` which is not `Send` diff --git a/tests/ui/if_let_mutex.rs b/tests/ui/if_let_mutex.rs index 321feb0224ed1..cb6915e0ebaaa 100644 --- a/tests/ui/if_let_mutex.rs +++ b/tests/ui/if_let_mutex.rs @@ -8,6 +8,7 @@ fn do_stuff(_: T) {} fn if_let() { let m = Mutex::new(1_u8); if let Err(locked) = m.lock() { + //~^ ERROR: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a d do_stuff(locked); } else { let lock = m.lock().unwrap(); @@ -20,6 +21,7 @@ fn if_let() { fn if_let_option() { let m = Mutex::new(Some(0_u8)); if let Some(locked) = m.lock().unwrap().deref() { + //~^ ERROR: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a d do_stuff(locked); } else { let lock = m.lock().unwrap(); @@ -41,6 +43,7 @@ fn if_let_different_mutex() { fn mutex_ref(mutex: &Mutex) { if let Ok(i) = mutex.lock() { + //~^ ERROR: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a d do_stuff(i); } else { let _x = mutex.lock(); diff --git a/tests/ui/if_let_mutex.stderr b/tests/ui/if_let_mutex.stderr index da0cc25f0ab52..6bbaadbe85539 100644 --- a/tests/ui/if_let_mutex.stderr +++ b/tests/ui/if_let_mutex.stderr @@ -5,6 +5,7 @@ LL | if let Err(locked) = m.lock() { | ^ - this Mutex will remain locked for the entire `if let`-block... | _____| | | +LL | | LL | | do_stuff(locked); LL | | } else { LL | | let lock = m.lock().unwrap(); @@ -17,12 +18,13 @@ LL | | }; = note: `-D clippy::if-let-mutex` implied by `-D warnings` error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> $DIR/if_let_mutex.rs:22:5 + --> $DIR/if_let_mutex.rs:23:5 | LL | if let Some(locked) = m.lock().unwrap().deref() { | ^ - this Mutex will remain locked for the entire `if let`-block... | _____| | | +LL | | LL | | do_stuff(locked); LL | | } else { LL | | let lock = m.lock().unwrap(); @@ -34,12 +36,13 @@ LL | | }; = help: move the lock call outside of the `if let ...` expression error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> $DIR/if_let_mutex.rs:43:5 + --> $DIR/if_let_mutex.rs:45:5 | LL | if let Ok(i) = mutex.lock() { | ^ ----- this Mutex will remain locked for the entire `if let`-block... | _____| | | +LL | | LL | | do_stuff(i); LL | | } else { LL | | let _x = mutex.lock(); diff --git a/tests/ui/if_not_else.rs b/tests/ui/if_not_else.rs index b7012b43d2976..fd30e3702a275 100644 --- a/tests/ui/if_not_else.rs +++ b/tests/ui/if_not_else.rs @@ -10,11 +10,13 @@ fn bla() -> bool { fn main() { if !bla() { + //~^ ERROR: unnecessary boolean `not` operation println!("Bugs"); } else { println!("Bunny"); } if 4 != 5 { + //~^ ERROR: unnecessary `!=` operation println!("Bugs"); } else { println!("Bunny"); diff --git a/tests/ui/if_not_else.stderr b/tests/ui/if_not_else.stderr index 46671c15274f7..2a7500fdc61a0 100644 --- a/tests/ui/if_not_else.stderr +++ b/tests/ui/if_not_else.stderr @@ -2,6 +2,7 @@ error: unnecessary boolean `not` operation --> $DIR/if_not_else.rs:12:5 | LL | / if !bla() { +LL | | LL | | println!("Bugs"); LL | | } else { LL | | println!("Bunny"); @@ -12,9 +13,10 @@ LL | | } = note: `-D clippy::if-not-else` implied by `-D warnings` error: unnecessary `!=` operation - --> $DIR/if_not_else.rs:17:5 + --> $DIR/if_not_else.rs:18:5 | LL | / if 4 != 5 { +LL | | LL | | println!("Bugs"); LL | | } else { LL | | println!("Bunny"); diff --git a/tests/ui/if_then_some_else_none.rs b/tests/ui/if_then_some_else_none.rs index 0e89fdb0dfa28..8fa0f34a6c423 100644 --- a/tests/ui/if_then_some_else_none.rs +++ b/tests/ui/if_then_some_else_none.rs @@ -3,6 +3,7 @@ fn main() { // Should issue an error. let _ = if foo() { + //~^ ERROR: this could be simplified with `bool::then` println!("true!"); Some("foo") } else { @@ -11,6 +12,7 @@ fn main() { // Should issue an error when macros are used. let _ = if matches!(true, true) { + //~^ ERROR: this could be simplified with `bool::then` println!("true!"); Some(matches!(true, false)) } else { @@ -20,10 +22,12 @@ fn main() { // Should issue an error. Binary expression `o < 32` should be parenthesized. let x = Some(5); let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); + //~^ ERROR: this could be simplified with `bool::then_some` // Should issue an error. Unary expression `!x` should be parenthesized. let x = true; let _ = if !x { Some(0) } else { None }; + //~^ ERROR: this could be simplified with `bool::then_some` // Should not issue an error since the `else` block has a statement besides `None`. let _ = if foo() { @@ -79,6 +83,7 @@ fn _msrv_1_49() { #[clippy::msrv = "1.50"] fn _msrv_1_50() { let _ = if foo() { + //~^ ERROR: this could be simplified with `bool::then` println!("true!"); Some(150) } else { diff --git a/tests/ui/if_then_some_else_none.stderr b/tests/ui/if_then_some_else_none.stderr index d728a3c31a3ba..f63298a7fce86 100644 --- a/tests/ui/if_then_some_else_none.stderr +++ b/tests/ui/if_then_some_else_none.stderr @@ -3,6 +3,7 @@ error: this could be simplified with `bool::then` | LL | let _ = if foo() { | _____________^ +LL | | LL | | println!("true!"); LL | | Some("foo") LL | | } else { @@ -14,10 +15,11 @@ LL | | }; = note: `-D clippy::if-then-some-else-none` implied by `-D warnings` error: this could be simplified with `bool::then` - --> $DIR/if_then_some_else_none.rs:13:13 + --> $DIR/if_then_some_else_none.rs:14:13 | LL | let _ = if matches!(true, true) { | _____________^ +LL | | LL | | println!("true!"); LL | | Some(matches!(true, false)) LL | | } else { @@ -28,7 +30,7 @@ LL | | }; = help: consider using `bool::then` like: `matches!(true, true).then(|| { /* snippet */ matches!(true, false) })` error: this could be simplified with `bool::then_some` - --> $DIR/if_then_some_else_none.rs:22:28 + --> $DIR/if_then_some_else_none.rs:24:28 | LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +38,7 @@ LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); = help: consider using `bool::then_some` like: `(o < 32).then_some(o)` error: this could be simplified with `bool::then_some` - --> $DIR/if_then_some_else_none.rs:26:13 + --> $DIR/if_then_some_else_none.rs:29:13 | LL | let _ = if !x { Some(0) } else { None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,10 +46,11 @@ LL | let _ = if !x { Some(0) } else { None }; = help: consider using `bool::then_some` like: `(!x).then_some(0)` error: this could be simplified with `bool::then` - --> $DIR/if_then_some_else_none.rs:81:13 + --> $DIR/if_then_some_else_none.rs:85:13 | LL | let _ = if foo() { | _____________^ +LL | | LL | | println!("true!"); LL | | Some(150) LL | | } else { diff --git a/tests/ui/impl.rs b/tests/ui/impl.rs index aea52a852f987..7f452cb46e068 100644 --- a/tests/ui/impl.rs +++ b/tests/ui/impl.rs @@ -8,6 +8,7 @@ impl MyStruct { } impl MyStruct { + //~^ ERROR: multiple implementations of this structure fn second() {} } @@ -22,6 +23,7 @@ mod submod { } impl super::MyStruct { + //~^ ERROR: multiple implementations of this structure fn third() {} } } @@ -42,6 +44,7 @@ impl WithArgs { fn f2() {} } impl WithArgs { + //~^ ERROR: multiple implementations of this structure fn f3() {} } @@ -63,5 +66,6 @@ impl OneAllowedImpl {} #[allow(clippy::multiple_inherent_impl)] impl OneAllowedImpl {} impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed. +//~^ ERROR: multiple implementations of this structure fn main() {} diff --git a/tests/ui/impl.stderr b/tests/ui/impl.stderr index e28b1bf0cdd94..2eac1ce3dd7b5 100644 --- a/tests/ui/impl.stderr +++ b/tests/ui/impl.stderr @@ -2,6 +2,7 @@ error: multiple implementations of this structure --> $DIR/impl.rs:10:1 | LL | / impl MyStruct { +LL | | LL | | fn second() {} LL | | } | |_^ @@ -16,9 +17,10 @@ LL | | } = note: `-D clippy::multiple-inherent-impl` implied by `-D warnings` error: multiple implementations of this structure - --> $DIR/impl.rs:24:5 + --> $DIR/impl.rs:25:5 | LL | / impl super::MyStruct { +LL | | LL | | fn third() {} LL | | } | |_____^ @@ -32,15 +34,16 @@ LL | | } | |_^ error: multiple implementations of this structure - --> $DIR/impl.rs:44:1 + --> $DIR/impl.rs:46:1 | LL | / impl WithArgs { +LL | | LL | | fn f3() {} LL | | } | |_^ | note: first implementation here - --> $DIR/impl.rs:41:1 + --> $DIR/impl.rs:43:1 | LL | / impl WithArgs { LL | | fn f2() {} @@ -48,13 +51,13 @@ LL | | } | |_^ error: multiple implementations of this structure - --> $DIR/impl.rs:65:1 + --> $DIR/impl.rs:68:1 | LL | impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed. | ^^^^^^^^^^^^^^^^^^^^^^ | note: first implementation here - --> $DIR/impl.rs:62:1 + --> $DIR/impl.rs:65:1 | LL | impl OneAllowedImpl {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/impl_trait_in_params.rs b/tests/ui/impl_trait_in_params.rs index 8944f6b58fd43..b652e4a4abe2e 100644 --- a/tests/ui/impl_trait_in_params.rs +++ b/tests/ui/impl_trait_in_params.rs @@ -6,7 +6,10 @@ pub trait AnotherTrait {} // Should warn pub fn a(_: impl Trait) {} +//~^ ERROR: '`impl Trait` used as a function parameter' +//~| NOTE: `-D clippy::impl-trait-in-params` implied by `-D warnings` pub fn c(_: C, _: impl Trait) {} +//~^ ERROR: '`impl Trait` used as a function parameter' fn d(_: impl AnotherTrait) {} // Shouldn't warn diff --git a/tests/ui/impl_trait_in_params.stderr b/tests/ui/impl_trait_in_params.stderr index 80383743525fa..ad035abc635bb 100644 --- a/tests/ui/impl_trait_in_params.stderr +++ b/tests/ui/impl_trait_in_params.stderr @@ -11,7 +11,7 @@ LL | pub fn a<{ /* Generic name */ }: Trait>(_: impl Trait) {} | +++++++++++++++++++++++++++++++ error: '`impl Trait` used as a function parameter' - --> $DIR/impl_trait_in_params.rs:9:29 + --> $DIR/impl_trait_in_params.rs:11:29 | LL | pub fn c(_: C, _: impl Trait) {} | ^^^^^^^^^^ diff --git a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs index 2f8d5cf30c77a..1173a95d06599 100644 --- a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs +++ b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs @@ -21,6 +21,8 @@ impl cmp::Ord for A { } impl PartialOrd for A { + //~^ ERROR: incorrect implementation of `partial_cmp` on an `Ord` type + //~| NOTE: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default fn partial_cmp(&self, other: &Self) -> Option { // NOTE: This suggestion is wrong, as `Ord` is not in scope. But this should be fine as it isn't // automatically applied @@ -44,6 +46,7 @@ impl cmp::Ord for B { } impl PartialOrd for B { + //~^ ERROR: incorrect implementation of `partial_cmp` on an `Ord` type fn partial_cmp(&self, other: &Self) -> Option { // This calls `B.cmp`, not `Ord::cmp`! Some(self.cmp(other)) diff --git a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr index f4374c2812877..09d7a32e3342a 100644 --- a/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr +++ b/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr @@ -2,6 +2,8 @@ error: incorrect implementation of `partial_cmp` on an `Ord` type --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:23:1 | LL | / impl PartialOrd for A { +LL | | +LL | | LL | | fn partial_cmp(&self, other: &Self) -> Option { | | _____________________________________________________________- LL | || // NOTE: This suggestion is wrong, as `Ord` is not in scope. But this should be fine as it isn't @@ -15,9 +17,10 @@ LL | | } = note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default error: incorrect implementation of `partial_cmp` on an `Ord` type - --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:46:1 + --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:48:1 | LL | / impl PartialOrd for B { +LL | | LL | | fn partial_cmp(&self, other: &Self) -> Option { | | _____________________________________________________________- LL | || // This calls `B.cmp`, not `Ord::cmp`! diff --git a/tests/ui/index_refutable_slice/if_let_slice_binding.fixed b/tests/ui/index_refutable_slice/if_let_slice_binding.fixed index 1f0a9ca25a494..13f0cbe9cc887 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.fixed +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.fixed @@ -12,18 +12,21 @@ fn lintable_examples() { // Try with reference let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some([slice_0, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice_0); } // Try with copy let slice: Option<[u32; 3]> = Some([1, 2, 3]); if let Some([slice_0, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice_0); } // Try with long slice and small indices let slice: Option<[u32; 9]> = Some([1, 2, 3, 4, 5, 6, 7, 8, 9]); if let Some([slice_0, _, slice_2, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice_2); println!("{}", slice_0); } @@ -31,6 +34,7 @@ fn lintable_examples() { // Multiple bindings let slice_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([5, 6, 7]); if let SomeEnum::One([slice_0, ..]) | SomeEnum::Three([slice_0, ..]) = slice_wrapped { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice_0); } @@ -38,6 +42,8 @@ fn lintable_examples() { let a_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([9, 5, 1]); let b_wrapped: Option<[u32; 2]> = Some([4, 6]); if let (SomeEnum::Three([_, _, a_2, ..]), Some([_, b_1, ..])) = (a_wrapped, b_wrapped) { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + //~| ERROR: this binding can be a slice pattern to avoid indexing println!("{} -> {}", a_2, b_1); } @@ -45,6 +51,7 @@ fn lintable_examples() { // borrowed and `String` doesn't implement copy let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some([_, ref slice_1, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice_1); } println!("{:?}", slice); @@ -53,6 +60,7 @@ fn lintable_examples() { // a reference let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some([slice_0, ..]) = &slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice_0); } println!("{:?}", slice); @@ -122,6 +130,7 @@ fn check_slice_in_struct() { // Test 1: Field access if let Some([slice_0, ..]) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_awesome { println!("This is awesome! {}", slice_0); } @@ -129,6 +138,7 @@ fn check_slice_in_struct() { // Test 2: function access if let Some([slice_0, ..]) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_super_awesome() { println!("This is super awesome! {}", slice_0); } diff --git a/tests/ui/index_refutable_slice/if_let_slice_binding.rs b/tests/ui/index_refutable_slice/if_let_slice_binding.rs index 0a3374d11b03f..d8d38c167fa57 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.rs +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.rs @@ -12,18 +12,21 @@ fn lintable_examples() { // Try with reference let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some(slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[0]); } // Try with copy let slice: Option<[u32; 3]> = Some([1, 2, 3]); if let Some(slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[0]); } // Try with long slice and small indices let slice: Option<[u32; 9]> = Some([1, 2, 3, 4, 5, 6, 7, 8, 9]); if let Some(slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[2]); println!("{}", slice[0]); } @@ -31,6 +34,7 @@ fn lintable_examples() { // Multiple bindings let slice_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([5, 6, 7]); if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[0]); } @@ -38,6 +42,8 @@ fn lintable_examples() { let a_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([9, 5, 1]); let b_wrapped: Option<[u32; 2]> = Some([4, 6]); if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + //~| ERROR: this binding can be a slice pattern to avoid indexing println!("{} -> {}", a[2], b[1]); } @@ -45,6 +51,7 @@ fn lintable_examples() { // borrowed and `String` doesn't implement copy let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some(ref slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice[1]); } println!("{:?}", slice); @@ -53,6 +60,7 @@ fn lintable_examples() { // a reference let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some(slice) = &slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice[0]); } println!("{:?}", slice); @@ -122,6 +130,7 @@ fn check_slice_in_struct() { // Test 1: Field access if let Some(slice) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_awesome { println!("This is awesome! {}", slice[0]); } @@ -129,6 +138,7 @@ fn check_slice_in_struct() { // Test 2: function access if let Some(slice) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_super_awesome() { println!("This is super awesome! {}", slice[0]); } diff --git a/tests/ui/index_refutable_slice/if_let_slice_binding.stderr b/tests/ui/index_refutable_slice/if_let_slice_binding.stderr index 0a13ac1354e57..f0e635954c5a9 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.stderr +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.stderr @@ -19,7 +19,7 @@ LL | println!("{}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:20:17 + --> $DIR/if_let_slice_binding.rs:21:17 | LL | if let Some(slice) = slice { | ^^^^^ @@ -34,7 +34,7 @@ LL | println!("{}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:26:17 + --> $DIR/if_let_slice_binding.rs:28:17 | LL | if let Some(slice) = slice { | ^^^^^ @@ -50,7 +50,7 @@ LL ~ println!("{}", slice_0); | error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:33:26 + --> $DIR/if_let_slice_binding.rs:36:26 | LL | if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped { | ^^^^^ @@ -65,7 +65,7 @@ LL | println!("{}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:40:29 + --> $DIR/if_let_slice_binding.rs:44:29 | LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { | ^ @@ -80,7 +80,7 @@ LL | println!("{} -> {}", a_2, b[1]); | ~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:40:38 + --> $DIR/if_let_slice_binding.rs:44:38 | LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { | ^ @@ -95,7 +95,7 @@ LL | println!("{} -> {}", a[2], b_1); | ~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:47:21 + --> $DIR/if_let_slice_binding.rs:53:21 | LL | if let Some(ref slice) = slice { | ^^^^^ @@ -110,7 +110,7 @@ LL | println!("{:?}", slice_1); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:55:17 + --> $DIR/if_let_slice_binding.rs:62:17 | LL | if let Some(slice) = &slice { | ^^^^^ @@ -125,7 +125,7 @@ LL | println!("{:?}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:124:17 + --> $DIR/if_let_slice_binding.rs:132:17 | LL | if let Some(slice) = wrap.inner { | ^^^^^ @@ -140,7 +140,7 @@ LL | println!("This is awesome! {}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:131:17 + --> $DIR/if_let_slice_binding.rs:140:17 | LL | if let Some(slice) = wrap.inner { | ^^^^^ diff --git a/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed b/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed index d07b469cf3f01..72edc539f0431 100644 --- a/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed +++ b/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed @@ -21,6 +21,7 @@ fn main() { if_chain! { let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some([slice_0, ..]) = slice; + //~^ ERROR: this binding can be a slice pattern to avoid indexing then { println!("{}", slice_0); } diff --git a/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs b/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs index 406e82083f88f..7b474ba423b9a 100644 --- a/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs +++ b/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs @@ -21,6 +21,7 @@ fn main() { if_chain! { let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some(slice) = slice; + //~^ ERROR: this binding can be a slice pattern to avoid indexing then { println!("{}", slice[0]); } diff --git a/tests/ui/indexing_slicing_index.rs b/tests/ui/indexing_slicing_index.rs index f7f7ea4103534..f0da5dfc60bd6 100644 --- a/tests/ui/indexing_slicing_index.rs +++ b/tests/ui/indexing_slicing_index.rs @@ -12,7 +12,9 @@ const ARR: [i32; 2] = [1, 2]; const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +//~^ ERROR: indexing may panic const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. +//~^ ERROR: indexing may panic const fn idx() -> usize { 1 @@ -25,6 +27,7 @@ fn main() { let x = [1, 2, 3, 4]; let index: usize = 1; x[index]; + //~^ ERROR: indexing may panic // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. x[4]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. @@ -40,8 +43,10 @@ fn main() { x[const { idx4() }]; // This should be linted, since `suppress-restriction-lint-in-const` default is false. const { &ARR[idx()] }; + //~^ ERROR: indexing may panic // This should be linted, since `suppress-restriction-lint-in-const` default is false. const { &ARR[idx4()] }; + //~^ ERROR: indexing may panic let y = &x; // Ok, referencing shouldn't affect this lint. See the issue 6021 @@ -51,8 +56,11 @@ fn main() { let v = vec![0; 5]; v[0]; + //~^ ERROR: indexing may panic v[10]; + //~^ ERROR: indexing may panic v[1 << 3]; + //~^ ERROR: indexing may panic // Out of bounds const N: usize = 15; @@ -63,5 +71,7 @@ fn main() { // Ok, should not produce stderr. x[M]; v[N]; + //~^ ERROR: indexing may panic v[M]; + //~^ ERROR: indexing may panic } diff --git a/tests/ui/indexing_slicing_index.stderr b/tests/ui/indexing_slicing_index.stderr index 1db2eb1397cde..edb47d39412ba 100644 --- a/tests/ui/indexing_slicing_index.stderr +++ b/tests/ui/indexing_slicing_index.stderr @@ -9,7 +9,7 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re = note: `-D clippy::indexing-slicing` implied by `-D warnings` error: indexing may panic - --> $DIR/indexing_slicing_index.rs:15:24 + --> $DIR/indexing_slicing_index.rs:16:24 | LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. | ^^^^^^^^^^^ @@ -18,19 +18,19 @@ LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. = note: the suggestion might not be applicable in constant blocks error[E0080]: evaluation of `main::{constant#3}` failed - --> $DIR/indexing_slicing_index.rs:44:14 + --> $DIR/indexing_slicing_index.rs:48:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 note: erroneous constant used - --> $DIR/indexing_slicing_index.rs:44:5 + --> $DIR/indexing_slicing_index.rs:48:5 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^^^^^^^^^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:27:5 + --> $DIR/indexing_slicing_index.rs:29:5 | LL | x[index]; | ^^^^^^^^ @@ -38,7 +38,7 @@ LL | x[index]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:42:14 + --> $DIR/indexing_slicing_index.rs:45:14 | LL | const { &ARR[idx()] }; | ^^^^^^^^^^ @@ -47,7 +47,7 @@ LL | const { &ARR[idx()] }; = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:44:14 + --> $DIR/indexing_slicing_index.rs:48:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | const { &ARR[idx4()] }; = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:53:5 + --> $DIR/indexing_slicing_index.rs:58:5 | LL | v[0]; | ^^^^ @@ -64,7 +64,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:54:5 + --> $DIR/indexing_slicing_index.rs:60:5 | LL | v[10]; | ^^^^^ @@ -72,7 +72,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:55:5 + --> $DIR/indexing_slicing_index.rs:62:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -80,7 +80,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:65:5 + --> $DIR/indexing_slicing_index.rs:73:5 | LL | v[N]; | ^^^^ @@ -88,7 +88,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:66:5 + --> $DIR/indexing_slicing_index.rs:75:5 | LL | v[M]; | ^^^^ @@ -96,7 +96,7 @@ LL | v[M]; = help: consider using `.get(n)` or `.get_mut(n)` instead error[E0080]: evaluation of constant value failed - --> $DIR/indexing_slicing_index.rs:15:24 + --> $DIR/indexing_slicing_index.rs:16:24 | LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 diff --git a/tests/ui/indexing_slicing_slice.rs b/tests/ui/indexing_slicing_slice.rs index ea111a48b29fe..fc591021ed6b0 100644 --- a/tests/ui/indexing_slicing_slice.rs +++ b/tests/ui/indexing_slicing_slice.rs @@ -10,12 +10,22 @@ fn main() { let index_from: usize = 2; let index_to: usize = 3; &x[index..]; + //~^ ERROR: slicing may panic &x[..index]; + //~^ ERROR: slicing may panic &x[index_from..index_to]; + //~^ ERROR: slicing may panic &x[index_from..][..index_to]; + //~^ ERROR: slicing may panic + //~| ERROR: slicing may panic &x[5..][..10]; + //~^ ERROR: slicing may panic + //~| ERROR: range is out of bounds + //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` &x[0..][..3]; + //~^ ERROR: slicing may panic &x[1..][..5]; + //~^ ERROR: slicing may panic &x[0..].get(..3); // Ok, should not produce stderr. &x[0..3]; // Ok, should not produce stderr. @@ -23,15 +33,22 @@ fn main() { let y = &x; &y[1..2]; &y[0..=4]; + //~^ ERROR: range is out of bounds &y[..=4]; + //~^ ERROR: range is out of bounds &y[..]; // Ok, should not produce stderr. let v = vec![0; 5]; &v[10..100]; + //~^ ERROR: slicing may panic &x[10..][..100]; + //~^ ERROR: slicing may panic + //~| ERROR: range is out of bounds &v[10..]; + //~^ ERROR: slicing may panic &v[..100]; + //~^ ERROR: slicing may panic &v[..]; // Ok, should not produce stderr. } diff --git a/tests/ui/indexing_slicing_slice.stderr b/tests/ui/indexing_slicing_slice.stderr index 6a75d57453797..0f83ea52d01ba 100644 --- a/tests/ui/indexing_slicing_slice.stderr +++ b/tests/ui/indexing_slicing_slice.stderr @@ -8,7 +8,7 @@ LL | &x[index..]; = note: `-D clippy::indexing-slicing` implied by `-D warnings` error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:13:6 + --> $DIR/indexing_slicing_slice.rs:14:6 | LL | &x[..index]; | ^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | &x[..index]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:14:6 + --> $DIR/indexing_slicing_slice.rs:16:6 | LL | &x[index_from..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | &x[index_from..index_to]; = help: consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:15:6 + --> $DIR/indexing_slicing_slice.rs:18:6 | LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | &x[index_from..][..index_to]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:15:6 + --> $DIR/indexing_slicing_slice.rs:18:6 | LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | &x[index_from..][..index_to]; = help: consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:16:6 + --> $DIR/indexing_slicing_slice.rs:21:6 | LL | &x[5..][..10]; | ^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | &x[5..][..10]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:16:8 + --> $DIR/indexing_slicing_slice.rs:21:8 | LL | &x[5..][..10]; | ^ @@ -56,7 +56,7 @@ LL | &x[5..][..10]; = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:17:6 + --> $DIR/indexing_slicing_slice.rs:25:6 | LL | &x[0..][..3]; | ^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | &x[0..][..3]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:18:6 + --> $DIR/indexing_slicing_slice.rs:27:6 | LL | &x[1..][..5]; | ^^^^^^^^^^^ @@ -72,19 +72,19 @@ LL | &x[1..][..5]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:25:12 + --> $DIR/indexing_slicing_slice.rs:35:12 | LL | &y[0..=4]; | ^ error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:26:11 + --> $DIR/indexing_slicing_slice.rs:37:11 | LL | &y[..=4]; | ^ error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:31:6 + --> $DIR/indexing_slicing_slice.rs:43:6 | LL | &v[10..100]; | ^^^^^^^^^^ @@ -92,7 +92,7 @@ LL | &v[10..100]; = help: consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:32:6 + --> $DIR/indexing_slicing_slice.rs:45:6 | LL | &x[10..][..100]; | ^^^^^^^^^^^^^^ @@ -100,13 +100,13 @@ LL | &x[10..][..100]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:32:8 + --> $DIR/indexing_slicing_slice.rs:45:8 | LL | &x[10..][..100]; | ^^ error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:33:6 + --> $DIR/indexing_slicing_slice.rs:48:6 | LL | &v[10..]; | ^^^^^^^ @@ -114,7 +114,7 @@ LL | &v[10..]; = help: consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:34:6 + --> $DIR/indexing_slicing_slice.rs:50:6 | LL | &v[..100]; | ^^^^^^^^ diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs index 7821dd44812df..da95ba04b821b 100644 --- a/tests/ui/infinite_iter.rs +++ b/tests/ui/infinite_iter.rs @@ -9,10 +9,13 @@ fn square_is_lower_64(x: &u32) -> bool { #[deny(clippy::infinite_iter)] fn infinite_iters() { repeat(0_u8).collect::>(); + //~^ ERROR: infinite iteration detected // infinite iter (0..8_u32).take_while(square_is_lower_64).cycle().count(); + //~^ ERROR: infinite iteration detected // infinite iter (0..8_u64).chain(0..).max(); + //~^ ERROR: infinite iteration detected // infinite iter (0_usize..) .chain([0usize, 1, 2].iter().cloned()) @@ -20,6 +23,7 @@ fn infinite_iters() { .min(); // infinite iter (0..8_u32) + //~^ ERROR: infinite iteration detected .rev() .cycle() .map(|x| x + 1_u32) @@ -28,8 +32,10 @@ fn infinite_iters() { (0..3_u32).flat_map(|x| x..).sum::(); // infinite iter (0_usize..).flat_map(|x| 0..x).product::(); + //~^ ERROR: infinite iteration detected // infinite iter (0_u64..).filter(|x| x % 2 == 0).last(); + //~^ ERROR: infinite iteration detected // not an infinite, because ranges are double-ended (0..42_u64).by_ref().last(); // iterator is not exhausted @@ -40,10 +46,13 @@ fn infinite_iters() { fn potential_infinite_iters() { // maybe infinite iter (0..).zip((0..).take_while(square_is_lower_64)).count(); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter repeat(42).take_while(|x| *x == 42).chain(0..42).max(); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter (1..) + //~^ ERROR: possible infinite iteration detected .scan(0, |state, x| { *state += x; Some(*state) @@ -51,12 +60,16 @@ fn potential_infinite_iters() { .min(); // maybe infinite iter (0..).find(|x| *x == 24); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter (0..).position(|x| x == 24); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter (0..).any(|x| x == 24); + //~^ ERROR: possible infinite iteration detected // maybe infinite iter (0..).all(|x| x == 24); + //~^ ERROR: possible infinite iteration detected // not infinite (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); @@ -82,6 +95,8 @@ mod finite_collect { fn check_collect() { // Infinite iter let _: HashSet = (0..).collect(); + //~^ ERROR: infinite iteration detected + //~| NOTE: `#[deny(clippy::infinite_iter)]` on by default // Some data structures don't collect infinitely, such as `ArrayVec` let _: C = (0..).collect(); diff --git a/tests/ui/infinite_iter.stderr b/tests/ui/infinite_iter.stderr index 39d2fcc71aa69..d0d0f0db443bb 100644 --- a/tests/ui/infinite_iter.stderr +++ b/tests/ui/infinite_iter.stderr @@ -11,21 +11,22 @@ LL | #[deny(clippy::infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:13:5 + --> $DIR/infinite_iter.rs:14:5 | LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:15:5 + --> $DIR/infinite_iter.rs:17:5 | LL | (0..8_u64).chain(0..).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:22:5 + --> $DIR/infinite_iter.rs:25:5 | LL | / (0..8_u32) +LL | | LL | | .rev() LL | | .cycle() LL | | .map(|x| x + 1_u32) @@ -33,39 +34,40 @@ LL | | .for_each(|x| println!("{}", x)); | |________________________________________^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:30:5 + --> $DIR/infinite_iter.rs:34:5 | LL | (0_usize..).flat_map(|x| 0..x).product::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:32:5 + --> $DIR/infinite_iter.rs:37:5 | LL | (0_u64..).filter(|x| x % 2 == 0).last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:42:5 + --> $DIR/infinite_iter.rs:48:5 | LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/infinite_iter.rs:39:8 + --> $DIR/infinite_iter.rs:45:8 | LL | #[deny(clippy::maybe_infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:44:5 + --> $DIR/infinite_iter.rs:51:5 | LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:46:5 + --> $DIR/infinite_iter.rs:54:5 | LL | / (1..) +LL | | LL | | .scan(0, |state, x| { LL | | *state += x; LL | | Some(*state) @@ -74,31 +76,31 @@ LL | | .min(); | |______________^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:53:5 + --> $DIR/infinite_iter.rs:62:5 | LL | (0..).find(|x| *x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:55:5 + --> $DIR/infinite_iter.rs:65:5 | LL | (0..).position(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:57:5 + --> $DIR/infinite_iter.rs:68:5 | LL | (0..).any(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:59:5 + --> $DIR/infinite_iter.rs:71:5 | LL | (0..).all(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:84:31 + --> $DIR/infinite_iter.rs:97:31 | LL | let _: HashSet = (0..).collect(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs index d68889751d86a..281e12c7b938a 100644 --- a/tests/ui/infinite_loop.rs +++ b/tests/ui/infinite_loop.rs @@ -7,6 +7,8 @@ fn fn_constref(i: &i32) -> i32 { unimplemented!() } fn fn_mutref(i: &mut i32) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + //~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` unimplemented!() } fn fooi() -> i32 { @@ -20,11 +22,15 @@ fn immutable_condition() { // Should warn when all vars mentioned are immutable let y = 0; while y < 10 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - y is immutable"); } let x = 0; while y < 10 && x < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop let mut k = 1; k += 2; println!("KO - x and y immutable"); @@ -32,6 +38,8 @@ fn immutable_condition() { let cond = false; while !cond { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - cond immutable"); } @@ -76,15 +84,21 @@ fn unused_var() { let (mut i, mut j) = (0, 0); while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop j = 3; println!("KO - i not mentioned"); } while i < 3 && j > 0 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - i and j not mentioned"); } while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop let mut i = 5; fn_mutref(&mut i); println!("KO - shadowed"); @@ -100,11 +114,15 @@ fn used_immutable() { let mut i = 0; while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop fn_constref(&i); println!("KO - const reference"); } while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop fn_val(i); println!("KO - passed by value"); } @@ -171,6 +189,8 @@ impl Counter { fn print_n(&self, n: usize) { while self.count < n { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - {} is not mutated", self.count); } } @@ -179,6 +199,8 @@ impl Counter { fn while_loop_with_break_and_return() { let y = 0; while y < 10 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop if y == 0 { break; } @@ -186,6 +208,8 @@ fn while_loop_with_break_and_return() { } while y < 10 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop if y == 0 { return; } diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 2312612d3aa00..5ba806be867f5 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -1,5 +1,5 @@ error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:22:11 + --> $DIR/infinite_loop.rs:24:11 | LL | while y < 10 { | ^^^^^^ @@ -8,7 +8,7 @@ LL | while y < 10 { = note: `#[deny(clippy::while_immutable_condition)]` on by default error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:27:11 + --> $DIR/infinite_loop.rs:31:11 | LL | while y < 10 && x < 3 { | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | while y < 10 && x < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:34:11 + --> $DIR/infinite_loop.rs:40:11 | LL | while !cond { | ^^^^^ @@ -24,7 +24,7 @@ LL | while !cond { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:78:11 + --> $DIR/infinite_loop.rs:86:11 | LL | while i < 3 { | ^^^^^ @@ -32,7 +32,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:83:11 + --> $DIR/infinite_loop.rs:93:11 | LL | while i < 3 && j > 0 { | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | while i < 3 && j > 0 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:87:11 + --> $DIR/infinite_loop.rs:99:11 | LL | while i < 3 { | ^^^^^ @@ -48,7 +48,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:102:11 + --> $DIR/infinite_loop.rs:116:11 | LL | while i < 3 { | ^^^^^ @@ -56,7 +56,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:107:11 + --> $DIR/infinite_loop.rs:123:11 | LL | while i < 3 { | ^^^^^ @@ -64,7 +64,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:173:15 + --> $DIR/infinite_loop.rs:191:15 | LL | while self.count < n { | ^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | while self.count < n { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:181:11 + --> $DIR/infinite_loop.rs:201:11 | LL | while y < 10 { | ^^^^^^ @@ -82,7 +82,7 @@ LL | while y < 10 { = help: rewrite it as `if cond { loop { } }` error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:188:11 + --> $DIR/infinite_loop.rs:210:11 | LL | while y < 10 { | ^^^^^^ diff --git a/tests/ui/inherent_to_string.rs b/tests/ui/inherent_to_string.rs index adb0389a043f8..7b938cdd758c3 100644 --- a/tests/ui/inherent_to_string.rs +++ b/tests/ui/inherent_to_string.rs @@ -20,6 +20,7 @@ struct J; impl A { // Should be detected; emit warning fn to_string(&self) -> String { + //~^ ERROR: implementation of inherent method `to_string(&self) -> String` for type `A "A.to_string()".to_string() } @@ -44,6 +45,7 @@ impl B { impl C { // Should be detected and emit error as C also implements Display fn to_string(&self) -> String { + //~^ ERROR: type `C` implements inherent method `to_string(&self) -> String` which sha "C.to_string()".to_string() } } diff --git a/tests/ui/inherent_to_string.stderr b/tests/ui/inherent_to_string.stderr index 579b3c8c56f7c..cfe8600e92606 100644 --- a/tests/ui/inherent_to_string.stderr +++ b/tests/ui/inherent_to_string.stderr @@ -2,6 +2,7 @@ error: implementation of inherent method `to_string(&self) -> String` for type ` --> $DIR/inherent_to_string.rs:22:5 | LL | / fn to_string(&self) -> String { +LL | | LL | | "A.to_string()".to_string() LL | | } | |_____^ @@ -10,9 +11,10 @@ LL | | } = note: `-D clippy::inherent-to-string` implied by `-D warnings` error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display` - --> $DIR/inherent_to_string.rs:46:5 + --> $DIR/inherent_to_string.rs:47:5 | LL | / fn to_string(&self) -> String { +LL | | LL | | "C.to_string()".to_string() LL | | } | |_____^ diff --git a/tests/ui/inspect_for_each.rs b/tests/ui/inspect_for_each.rs index 7fe45c83bcacb..974690eaa8e4f 100644 --- a/tests/ui/inspect_for_each.rs +++ b/tests/ui/inspect_for_each.rs @@ -5,6 +5,7 @@ fn main() { let mut b: Vec = Vec::new(); a.into_iter().inspect(|x| assert!(*x > 0)).for_each(|x| { + //~^ ERROR: called `inspect(..).for_each(..)` on an `Iterator` let y = do_some(x); let z = do_more(y); b.push(z); diff --git a/tests/ui/inspect_for_each.stderr b/tests/ui/inspect_for_each.stderr index 67c2d5e53c78d..bdeb1d844609b 100644 --- a/tests/ui/inspect_for_each.stderr +++ b/tests/ui/inspect_for_each.stderr @@ -3,6 +3,7 @@ error: called `inspect(..).for_each(..)` on an `Iterator` | LL | a.into_iter().inspect(|x| assert!(*x > 0)).for_each(|x| { | ___________________^ +LL | | LL | | let y = do_some(x); LL | | let z = do_more(y); LL | | b.push(z); diff --git a/tests/ui/integer_division.rs b/tests/ui/integer_division.rs index 800c75257524a..137548fecf4a8 100644 --- a/tests/ui/integer_division.rs +++ b/tests/ui/integer_division.rs @@ -3,7 +3,10 @@ fn main() { let two = 2; let n = 1 / 2; + //~^ ERROR: integer division let o = 1 / two; + //~^ ERROR: integer division let p = two / 4; + //~^ ERROR: integer division let x = 1. / 2.0; } diff --git a/tests/ui/integer_division.stderr b/tests/ui/integer_division.stderr index ca80012792075..9bc41ef8385e7 100644 --- a/tests/ui/integer_division.stderr +++ b/tests/ui/integer_division.stderr @@ -8,7 +8,7 @@ LL | let n = 1 / 2; = note: `-D clippy::integer-division` implied by `-D warnings` error: integer division - --> $DIR/integer_division.rs:6:13 + --> $DIR/integer_division.rs:7:13 | LL | let o = 1 / two; | ^^^^^^^ @@ -16,7 +16,7 @@ LL | let o = 1 / two; = help: division of integers may cause loss of precision. consider using floats error: integer division - --> $DIR/integer_division.rs:7:13 + --> $DIR/integer_division.rs:9:13 | LL | let p = two / 4; | ^^^^^^^ diff --git a/tests/ui/invalid_upcast_comparisons.rs b/tests/ui/invalid_upcast_comparisons.rs index 697416dcee831..a9db15f209733 100644 --- a/tests/ui/invalid_upcast_comparisons.rs +++ b/tests/ui/invalid_upcast_comparisons.rs @@ -19,36 +19,61 @@ fn main() { // always false, since no u8 can be > 300 (u8 as u32) > 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~| NOTE: `-D clippy::invalid-upcast-comparisons` implied by `-D warnings` (u8 as i32) > 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as u32) == 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) == 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 < (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 < (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 == (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 == (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // inverted of the above (u8 as u32) <= 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) <= 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as u32) != 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) != 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 >= (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 >= (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 != (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 != (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // always false, since u8 -> i32 doesn't wrap (u8 as i32) < 0; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is -5 != (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // inverted of the above (u8 as i32) >= 0; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is -5 == (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // always false, since no u8 can be 1337 1337 == (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 1337 == (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // inverted of the above 1337 != (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 1337 != (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // Those are Ok: (u8 as u32) > 20; @@ -63,7 +88,9 @@ fn main() { (u8 as i8) == -1; (u8 as i8) != -1; (u8 as i32) > -1; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) < -1; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u32 as i32) < -5; (u32 as i32) < 10; @@ -80,6 +107,7 @@ fn main() { -5 > (u32 as i32); -5 >= (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is -5 == (u32 as i32); } diff --git a/tests/ui/invalid_upcast_comparisons.stderr b/tests/ui/invalid_upcast_comparisons.stderr index 03c3fb80aaabc..b201db3ddb14e 100644 --- a/tests/ui/invalid_upcast_comparisons.stderr +++ b/tests/ui/invalid_upcast_comparisons.stderr @@ -7,157 +7,157 @@ LL | (u8 as u32) > 300; = note: `-D clippy::invalid-upcast-comparisons` implied by `-D warnings` error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:22:5 + --> $DIR/invalid_upcast_comparisons.rs:24:5 | LL | (u8 as i32) > 300; | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:23:5 + --> $DIR/invalid_upcast_comparisons.rs:26:5 | LL | (u8 as u32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:24:5 + --> $DIR/invalid_upcast_comparisons.rs:28:5 | LL | (u8 as i32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:25:5 + --> $DIR/invalid_upcast_comparisons.rs:30:5 | LL | 300 < (u8 as u32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:26:5 + --> $DIR/invalid_upcast_comparisons.rs:32:5 | LL | 300 < (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:27:5 + --> $DIR/invalid_upcast_comparisons.rs:34:5 | LL | 300 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:28:5 + --> $DIR/invalid_upcast_comparisons.rs:36:5 | LL | 300 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:30:5 + --> $DIR/invalid_upcast_comparisons.rs:39:5 | LL | (u8 as u32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:31:5 + --> $DIR/invalid_upcast_comparisons.rs:41:5 | LL | (u8 as i32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:32:5 + --> $DIR/invalid_upcast_comparisons.rs:43:5 | LL | (u8 as u32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:33:5 + --> $DIR/invalid_upcast_comparisons.rs:45:5 | LL | (u8 as i32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:34:5 + --> $DIR/invalid_upcast_comparisons.rs:47:5 | LL | 300 >= (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:35:5 + --> $DIR/invalid_upcast_comparisons.rs:49:5 | LL | 300 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:36:5 + --> $DIR/invalid_upcast_comparisons.rs:51:5 | LL | 300 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:37:5 + --> $DIR/invalid_upcast_comparisons.rs:53:5 | LL | 300 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:40:5 + --> $DIR/invalid_upcast_comparisons.rs:57:5 | LL | (u8 as i32) < 0; | ^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:41:5 + --> $DIR/invalid_upcast_comparisons.rs:59:5 | LL | -5 != (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:43:5 + --> $DIR/invalid_upcast_comparisons.rs:62:5 | LL | (u8 as i32) >= 0; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:44:5 + --> $DIR/invalid_upcast_comparisons.rs:64:5 | LL | -5 == (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:47:5 + --> $DIR/invalid_upcast_comparisons.rs:68:5 | LL | 1337 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:48:5 + --> $DIR/invalid_upcast_comparisons.rs:70:5 | LL | 1337 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:50:5 + --> $DIR/invalid_upcast_comparisons.rs:73:5 | LL | 1337 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:51:5 + --> $DIR/invalid_upcast_comparisons.rs:75:5 | LL | 1337 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:65:5 + --> $DIR/invalid_upcast_comparisons.rs:90:5 | LL | (u8 as i32) > -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:66:5 + --> $DIR/invalid_upcast_comparisons.rs:92:5 | LL | (u8 as i32) < -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:82:5 + --> $DIR/invalid_upcast_comparisons.rs:109:5 | LL | -5 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/issue-7447.rs b/tests/ui/issue-7447.rs index de4362c4df70e..7e7ef209d4852 100644 --- a/tests/ui/issue-7447.rs +++ b/tests/ui/issue-7447.rs @@ -24,5 +24,8 @@ pub struct ByteView<'a> { fn main() { byte_view(panic!()); + //~^ ERROR: sub-expression diverges + //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` group_entries(panic!()); + //~^ ERROR: sub-expression diverges } diff --git a/tests/ui/issue-7447.stderr b/tests/ui/issue-7447.stderr index 7a113740c6a47..27e102af62fbb 100644 --- a/tests/ui/issue-7447.stderr +++ b/tests/ui/issue-7447.stderr @@ -8,7 +8,7 @@ LL | byte_view(panic!()); = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: sub-expression diverges - --> $DIR/issue-7447.rs:27:19 + --> $DIR/issue-7447.rs:29:19 | LL | group_entries(panic!()); | ^^^^^^^^ diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs index 8e0620e52b65f..23453207b4e5e 100644 --- a/tests/ui/issue_4266.rs +++ b/tests/ui/issue_4266.rs @@ -2,10 +2,13 @@ #![allow(clippy::uninlined_format_args)] async fn sink1<'a>(_: &'a str) {} // lint +//~^ ERROR: the following explicit lifetimes could be elided: 'a +//~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings` async fn sink1_elided(_: &str) {} // ok // lint async fn one_to_one<'a>(s: &'a str) -> &'a str { + //~^ ERROR: the following explicit lifetimes could be elided: 'a s } @@ -26,6 +29,7 @@ struct Foo; impl Foo { // ok pub async fn new(&mut self) -> Self { + //~^ ERROR: methods called `new` usually take no `self` Foo {} } } diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr index 5b60646ef21df..acfa01e9f2b31 100644 --- a/tests/ui/issue_4266.stderr +++ b/tests/ui/issue_4266.stderr @@ -7,13 +7,13 @@ LL | async fn sink1<'a>(_: &'a str) {} // lint = note: `-D clippy::needless-lifetimes` implied by `-D warnings` error: the following explicit lifetimes could be elided: 'a - --> $DIR/issue_4266.rs:8:21 + --> $DIR/issue_4266.rs:10:21 | LL | async fn one_to_one<'a>(s: &'a str) -> &'a str { | ^^ ^^ error: methods called `new` usually take no `self` - --> $DIR/issue_4266.rs:28:22 + --> $DIR/issue_4266.rs:31:22 | LL | pub async fn new(&mut self) -> Self { | ^^^^^^^^^ diff --git a/tests/ui/items_after_statement.rs b/tests/ui/items_after_statement.rs index f12cb8f22e270..943e7c1167605 100644 --- a/tests/ui/items_after_statement.rs +++ b/tests/ui/items_after_statement.rs @@ -11,6 +11,8 @@ fn ok() { fn last() { foo(); fn foo() { + //~^ ERROR: adding items after statements is confusing, since items exist from the sta + //~| NOTE: `-D clippy::items-after-statements` implied by `-D warnings` println!("foo"); } } @@ -18,6 +20,7 @@ fn last() { fn main() { foo(); fn foo() { + //~^ ERROR: adding items after statements is confusing, since items exist from the sta println!("foo"); } foo(); diff --git a/tests/ui/items_after_statement.stderr b/tests/ui/items_after_statement.stderr index f69635a977bd7..0e043b1742ff0 100644 --- a/tests/ui/items_after_statement.stderr +++ b/tests/ui/items_after_statement.stderr @@ -2,6 +2,8 @@ error: adding items after statements is confusing, since items exist from the st --> $DIR/items_after_statement.rs:13:5 | LL | / fn foo() { +LL | | +LL | | LL | | println!("foo"); LL | | } | |_____^ @@ -9,15 +11,16 @@ LL | | } = note: `-D clippy::items-after-statements` implied by `-D warnings` error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/items_after_statement.rs:20:5 + --> $DIR/items_after_statement.rs:22:5 | LL | / fn foo() { +LL | | LL | | println!("foo"); LL | | } | |_____^ error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/items_after_statement.rs:33:13 + --> $DIR/items_after_statement.rs:36:13 | LL | / fn say_something() { LL | | println!("something"); diff --git a/tests/ui/iter_not_returning_iterator.rs b/tests/ui/iter_not_returning_iterator.rs index cce216fc649b1..e694bc7ac62fb 100644 --- a/tests/ui/iter_not_returning_iterator.rs +++ b/tests/ui/iter_not_returning_iterator.rs @@ -28,10 +28,13 @@ struct Counter2 { impl Data2 { fn iter(&self) -> Counter2 { + //~^ ERROR: this method is named `iter` but its return type does not implement `Iterat + //~| NOTE: `-D clippy::iter-not-returning-iterator` implied by `-D warnings` todo!() } fn iter_mut(&self) -> Counter2 { + //~^ ERROR: this method is named `iter_mut` but its return type does not implement `It todo!() } } @@ -48,6 +51,7 @@ impl Iterator for Counter { trait Iter { type I; fn iter(&self) -> Self::I; + //~^ ERROR: this method is named `iter` but its return type does not implement `Iterat } impl Iter for () { diff --git a/tests/ui/iter_not_returning_iterator.stderr b/tests/ui/iter_not_returning_iterator.stderr index 44f0295583695..3145ade4448ba 100644 --- a/tests/ui/iter_not_returning_iterator.stderr +++ b/tests/ui/iter_not_returning_iterator.stderr @@ -7,13 +7,13 @@ LL | fn iter(&self) -> Counter2 { = note: `-D clippy::iter-not-returning-iterator` implied by `-D warnings` error: this method is named `iter_mut` but its return type does not implement `Iterator` - --> $DIR/iter_not_returning_iterator.rs:34:5 + --> $DIR/iter_not_returning_iterator.rs:36:5 | LL | fn iter_mut(&self) -> Counter2 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this method is named `iter` but its return type does not implement `Iterator` - --> $DIR/iter_not_returning_iterator.rs:50:5 + --> $DIR/iter_not_returning_iterator.rs:53:5 | LL | fn iter(&self) -> Self::I; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/iter_skip_next_unfixable.rs b/tests/ui/iter_skip_next_unfixable.rs index 4dd8cb599d52b..9c224f4117d3f 100644 --- a/tests/ui/iter_skip_next_unfixable.rs +++ b/tests/ui/iter_skip_next_unfixable.rs @@ -7,13 +7,16 @@ fn main() { let test_string = "1|1 2"; let sp = test_string.split('|').map(|s| s.trim()); let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect(); + //~^ ERROR: called `skip(..).next()` on an iterator if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ ERROR: called `skip(..).next()` on an iterator }; fn check(s: T) where T: Iterator, { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ ERROR: called `skip(..).next()` on an iterator } } diff --git a/tests/ui/iter_skip_next_unfixable.stderr b/tests/ui/iter_skip_next_unfixable.stderr index 4062706f94206..3160dc03a4fdb 100644 --- a/tests/ui/iter_skip_next_unfixable.stderr +++ b/tests/ui/iter_skip_next_unfixable.stderr @@ -12,25 +12,25 @@ LL | let sp = test_string.split('|').map(|s| s.trim()); = note: `-D clippy::iter-skip-next` implied by `-D warnings` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next_unfixable.rs:11:29 + --> $DIR/iter_skip_next_unfixable.rs:12:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` | help: for this change `s` has to be mutable - --> $DIR/iter_skip_next_unfixable.rs:10:17 + --> $DIR/iter_skip_next_unfixable.rs:11:17 | LL | if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) { | ^ error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next_unfixable.rs:17:29 + --> $DIR/iter_skip_next_unfixable.rs:19:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` | help: for this change `s` has to be mutable - --> $DIR/iter_skip_next_unfixable.rs:13:17 + --> $DIR/iter_skip_next_unfixable.rs:15:17 | LL | fn check(s: T) | ^ diff --git a/tests/ui/iterator_step_by_zero.rs b/tests/ui/iterator_step_by_zero.rs index 33ec78e9a4160..0b51842df2e39 100644 --- a/tests/ui/iterator_step_by_zero.rs +++ b/tests/ui/iterator_step_by_zero.rs @@ -2,8 +2,12 @@ #[warn(clippy::iterator_step_by_zero)] fn main() { let _ = vec!["A", "B", "B"].iter().step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime + //~| NOTE: `-D clippy::iterator-step-by-zero` implied by `-D warnings` let _ = "XXX".chars().step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime let _ = (0..1).step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime // No error, not an iterator. let y = NotIterator; @@ -13,14 +17,18 @@ fn main() { let _ = (0..1).step_by(1); let _ = (1..).step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime let _ = (1..=2).step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime let x = 0..1; let _ = x.step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime // check const eval let v1 = vec![1, 2, 3]; let _ = v1.iter().step_by(2 / 3); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime } struct NotIterator; diff --git a/tests/ui/iterator_step_by_zero.stderr b/tests/ui/iterator_step_by_zero.stderr index b470e2ed2eab9..fcf2930c26b29 100644 --- a/tests/ui/iterator_step_by_zero.stderr +++ b/tests/ui/iterator_step_by_zero.stderr @@ -7,37 +7,37 @@ LL | let _ = vec!["A", "B", "B"].iter().step_by(0); = note: `-D clippy::iterator-step-by-zero` implied by `-D warnings` error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:5:13 + --> $DIR/iterator_step_by_zero.rs:7:13 | LL | let _ = "XXX".chars().step_by(0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:6:13 + --> $DIR/iterator_step_by_zero.rs:9:13 | LL | let _ = (0..1).step_by(0); | ^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:15:13 + --> $DIR/iterator_step_by_zero.rs:19:13 | LL | let _ = (1..).step_by(0); | ^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:16:13 + --> $DIR/iterator_step_by_zero.rs:21:13 | LL | let _ = (1..=2).step_by(0); | ^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:19:13 + --> $DIR/iterator_step_by_zero.rs:25:13 | LL | let _ = x.step_by(0); | ^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:23:13 + --> $DIR/iterator_step_by_zero.rs:30:13 | LL | let _ = v1.iter().step_by(2 / 3); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/large_futures.fixed b/tests/ui/large_futures.fixed index afe89cf6e94d8..4c192d1c8d1bd 100644 --- a/tests/ui/large_futures.fixed +++ b/tests/ui/large_futures.fixed @@ -9,16 +9,21 @@ async fn big_fut(_arg: [u8; 1024 * 16]) {} async fn wait() { let f = async { Box::pin(big_fut([0u8; 1024 * 16])).await; + //~^ ERROR: large future with a size of 16385 bytes + //~| NOTE: `-D clippy::large-futures` implied by `-D warnings` }; Box::pin(f).await + //~^ ERROR: large future with a size of 16386 bytes } async fn calls_fut(fut: impl std::future::Future) { loop { Box::pin(wait()).await; + //~^ ERROR: large future with a size of 16387 bytes if true { return fut.await; } else { Box::pin(wait()).await; + //~^ ERROR: large future with a size of 16387 bytes } } } @@ -26,7 +31,9 @@ async fn calls_fut(fut: impl std::future::Future) { pub async fn test() { let fut = big_fut([0u8; 1024 * 16]); Box::pin(foo()).await; + //~^ ERROR: large future with a size of 65540 bytes Box::pin(calls_fut(fut)).await; + //~^ ERROR: large future with a size of 49159 bytes } pub fn foo() -> impl std::future::Future { @@ -39,6 +46,7 @@ pub fn foo() -> impl std::future::Future { pub async fn lines() { Box::pin(async { + //~^ ERROR: large future with a size of 65540 bytes let x = [0i32; 1024 * 16]; async {}.await; println!("{:?}", x); diff --git a/tests/ui/large_futures.rs b/tests/ui/large_futures.rs index e0f6b3d9d3b44..557d89a9cf99d 100644 --- a/tests/ui/large_futures.rs +++ b/tests/ui/large_futures.rs @@ -9,16 +9,21 @@ async fn big_fut(_arg: [u8; 1024 * 16]) {} async fn wait() { let f = async { big_fut([0u8; 1024 * 16]).await; + //~^ ERROR: large future with a size of 16385 bytes + //~| NOTE: `-D clippy::large-futures` implied by `-D warnings` }; f.await + //~^ ERROR: large future with a size of 16386 bytes } async fn calls_fut(fut: impl std::future::Future) { loop { wait().await; + //~^ ERROR: large future with a size of 16387 bytes if true { return fut.await; } else { wait().await; + //~^ ERROR: large future with a size of 16387 bytes } } } @@ -26,7 +31,9 @@ async fn calls_fut(fut: impl std::future::Future) { pub async fn test() { let fut = big_fut([0u8; 1024 * 16]); foo().await; + //~^ ERROR: large future with a size of 65540 bytes calls_fut(fut).await; + //~^ ERROR: large future with a size of 49159 bytes } pub fn foo() -> impl std::future::Future { @@ -39,6 +46,7 @@ pub fn foo() -> impl std::future::Future { pub async fn lines() { async { + //~^ ERROR: large future with a size of 65540 bytes let x = [0i32; 1024 * 16]; async {}.await; println!("{:?}", x); diff --git a/tests/ui/large_futures.stderr b/tests/ui/large_futures.stderr index 5bcf054884e41..5a0f00b67ec4d 100644 --- a/tests/ui/large_futures.stderr +++ b/tests/ui/large_futures.stderr @@ -7,39 +7,40 @@ LL | big_fut([0u8; 1024 * 16]).await; = note: `-D clippy::large-futures` implied by `-D warnings` error: large future with a size of 16386 bytes - --> $DIR/large_futures.rs:13:5 + --> $DIR/large_futures.rs:15:5 | LL | f.await | ^ help: consider `Box::pin` on it: `Box::pin(f)` error: large future with a size of 16387 bytes - --> $DIR/large_futures.rs:17:9 + --> $DIR/large_futures.rs:20:9 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 16387 bytes - --> $DIR/large_futures.rs:21:13 + --> $DIR/large_futures.rs:25:13 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:28:5 + --> $DIR/large_futures.rs:33:5 | LL | foo().await; | ^^^^^ help: consider `Box::pin` on it: `Box::pin(foo())` error: large future with a size of 49159 bytes - --> $DIR/large_futures.rs:29:5 + --> $DIR/large_futures.rs:35:5 | LL | calls_fut(fut).await; | ^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(calls_fut(fut))` error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:41:5 + --> $DIR/large_futures.rs:48:5 | LL | / async { +LL | | LL | | let x = [0i32; 1024 * 16]; LL | | async {}.await; LL | | println!("{:?}", x); @@ -49,6 +50,7 @@ LL | | } help: consider `Box::pin` on it | LL ~ Box::pin(async { +LL + LL + let x = [0i32; 1024 * 16]; LL + async {}.await; LL + println!("{:?}", x); @@ -56,7 +58,7 @@ LL + }) | error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:52:13 + --> $DIR/large_futures.rs:60:13 | LL | / async { LL | | let x = [0i32; 1024 * 16]; diff --git a/tests/ui/large_stack_arrays.rs b/tests/ui/large_stack_arrays.rs index 3e9d5e6a4ca32..d5c4f95f8c422 100644 --- a/tests/ui/large_stack_arrays.rs +++ b/tests/ui/large_stack_arrays.rs @@ -27,17 +27,24 @@ fn issue_10741() { } let _x = [build(); 3]; + //~^ ERROR: allocating a local array larger than 512000 bytes let _y = [build(), build(), build()]; + //~^ ERROR: allocating a local array larger than 512000 bytes } fn main() { let bad = ( [0u32; 20_000_000], + //~^ ERROR: allocating a local array larger than 512000 bytes [S { data: [0; 32] }; 5000], + //~^ ERROR: allocating a local array larger than 512000 bytes [Some(""); 20_000_000], + //~^ ERROR: allocating a local array larger than 512000 bytes [E::T(0); 5000], + //~^ ERROR: allocating a local array larger than 512000 bytes [0u8; usize::MAX], + //~^ ERROR: allocating a local array larger than 512000 bytes ); let good = ( diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr index 118d39566abee..5126f45278554 100644 --- a/tests/ui/large_stack_arrays.stderr +++ b/tests/ui/large_stack_arrays.stderr @@ -8,7 +8,7 @@ LL | let _x = [build(); 3]; = note: `-D clippy::large-stack-arrays` implied by `-D warnings` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:31:14 + --> $DIR/large_stack_arrays.rs:32:14 | LL | let _y = [build(), build(), build()]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _y = [build(), build(), build()]; = help: consider allocating on the heap with `vec![build(), build(), build()].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:36:9 + --> $DIR/large_stack_arrays.rs:38:9 | LL | [0u32; 20_000_000], | ^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | [0u32; 20_000_000], = help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:37:9 + --> $DIR/large_stack_arrays.rs:40:9 | LL | [S { data: [0; 32] }; 5000], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | [S { data: [0; 32] }; 5000], = help: consider allocating on the heap with `vec![S { data: [0; 32] }; 5000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:38:9 + --> $DIR/large_stack_arrays.rs:42:9 | LL | [Some(""); 20_000_000], | ^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | [Some(""); 20_000_000], = help: consider allocating on the heap with `vec![Some(""); 20_000_000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:39:9 + --> $DIR/large_stack_arrays.rs:44:9 | LL | [E::T(0); 5000], | ^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | [E::T(0); 5000], = help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:40:9 + --> $DIR/large_stack_arrays.rs:46:9 | LL | [0u8; usize::MAX], | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/large_stack_frames.rs b/tests/ui/large_stack_frames.rs index cd9d0c8a67a8a..f32368f93975c 100644 --- a/tests/ui/large_stack_frames.rs +++ b/tests/ui/large_stack_frames.rs @@ -23,6 +23,8 @@ impl Default for ArrayDefault { } fn many_small_arrays() { + //~^ ERROR: this function allocates a large amount of stack space + //~| NOTE: allocating large amounts of stack space can overflow the stack let x = [0u8; 500_000]; let x2 = [0u8; 500_000]; let x3 = [0u8; 500_000]; @@ -32,10 +34,14 @@ fn many_small_arrays() { } fn large_return_value() -> ArrayDefault<1_000_000> { + //~^ ERROR: this function allocates a large amount of stack space + //~| NOTE: allocating large amounts of stack space can overflow the stack Default::default() } fn large_fn_arg(x: ArrayDefault<1_000_000>) { + //~^ ERROR: this function allocates a large amount of stack space + //~| NOTE: allocating large amounts of stack space can overflow the stack black_box(&x); } diff --git a/tests/ui/large_stack_frames.stderr b/tests/ui/large_stack_frames.stderr index d57df8596fe56..6b14badca69ff 100644 --- a/tests/ui/large_stack_frames.stderr +++ b/tests/ui/large_stack_frames.stderr @@ -2,9 +2,9 @@ error: this function allocates a large amount of stack space --> $DIR/large_stack_frames.rs:25:1 | LL | / fn many_small_arrays() { +LL | | +LL | | LL | | let x = [0u8; 500_000]; -LL | | let x2 = [0u8; 500_000]; -LL | | let x3 = [0u8; 500_000]; ... | LL | | black_box((&x, &x2, &x3, &x4, &x5)); LL | | } @@ -14,9 +14,11 @@ LL | | } = note: `-D clippy::large-stack-frames` implied by `-D warnings` error: this function allocates a large amount of stack space - --> $DIR/large_stack_frames.rs:34:1 + --> $DIR/large_stack_frames.rs:36:1 | LL | / fn large_return_value() -> ArrayDefault<1_000_000> { +LL | | +LL | | LL | | Default::default() LL | | } | |_^ @@ -24,9 +26,11 @@ LL | | } = note: allocating large amounts of stack space can overflow the stack error: this function allocates a large amount of stack space - --> $DIR/large_stack_frames.rs:38:1 + --> $DIR/large_stack_frames.rs:42:1 | LL | / fn large_fn_arg(x: ArrayDefault<1_000_000>) { +LL | | +LL | | LL | | black_box(&x); LL | | } | |_^ diff --git a/tests/ui/len_without_is_empty.rs b/tests/ui/len_without_is_empty.rs index 52aabefaed20a..ac6c3e06365c6 100644 --- a/tests/ui/len_without_is_empty.rs +++ b/tests/ui/len_without_is_empty.rs @@ -5,6 +5,8 @@ pub struct PubOne; impl PubOne { pub fn len(&self) -> isize { + //~^ ERROR: struct `PubOne` has a public `len` method, but no `is_empty` method + //~| NOTE: `-D clippy::len-without-is-empty` implied by `-D warnings` 1 } } @@ -53,6 +55,7 @@ impl PubAllowedStruct { } pub trait PubTraitsToo { + //~^ ERROR: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` fn len(&self) -> isize; } @@ -66,6 +69,7 @@ pub struct HasIsEmpty; impl HasIsEmpty { pub fn len(&self) -> isize { + //~^ ERROR: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` me 1 } @@ -78,6 +82,7 @@ pub struct HasWrongIsEmpty; impl HasWrongIsEmpty { pub fn len(&self) -> isize { + //~^ ERROR: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` met 1 } @@ -90,6 +95,7 @@ pub struct MismatchedSelf; impl MismatchedSelf { pub fn len(self) -> isize { + //~^ ERROR: struct `MismatchedSelf` has a public `len` method, but the `is_empty` meth 1 } @@ -169,6 +175,7 @@ pub trait InheritingEmpty: Empty { pub trait Foo: Sized {} pub trait DependsOnFoo: Foo { + //~^ ERROR: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_empty` fn len(&mut self) -> usize; } @@ -214,6 +221,7 @@ impl OptionalLen2 { pub struct OptionalLen3; impl OptionalLen3 { pub fn len(&self) -> usize { + //~^ ERROR: struct `OptionalLen3` has a public `len` method, but the `is_empty` method 0 } @@ -226,6 +234,8 @@ impl OptionalLen3 { pub struct ResultLen; impl ResultLen { pub fn len(&self) -> Result { + //~^ ERROR: struct `ResultLen` has a public `len` method, but the `is_empty` method ha + //~| ERROR: this returns a `Result<_, ()>` Ok(0) } @@ -238,10 +248,12 @@ impl ResultLen { pub struct ResultLen2; impl ResultLen2 { pub fn len(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } pub fn is_empty(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(true) } } @@ -249,6 +261,7 @@ impl ResultLen2 { pub struct ResultLen3; impl ResultLen3 { pub fn len(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } @@ -290,6 +303,7 @@ impl AsyncLenWithoutIsEmpty { } pub async fn len(&self) -> usize { + //~^ ERROR: struct `AsyncLenWithoutIsEmpty` has a public `len` method, but no `is_empt usize::from(!self.async_task().await) } } @@ -302,6 +316,7 @@ impl AsyncOptionLenWithoutIsEmpty { } pub async fn len(&self) -> Option { + //~^ ERROR: struct `AsyncOptionLenWithoutIsEmpty` has a public `len` method, but no `i None } } @@ -323,6 +338,7 @@ impl AsyncResultLenWithoutIsEmpty { } pub async fn len(&self) -> Result { + //~^ ERROR: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `i Err(()) } } diff --git a/tests/ui/len_without_is_empty.stderr b/tests/ui/len_without_is_empty.stderr index 1bce1734b81af..1042ea2e1b389 100644 --- a/tests/ui/len_without_is_empty.stderr +++ b/tests/ui/len_without_is_empty.stderr @@ -7,87 +7,89 @@ LL | pub fn len(&self) -> isize { = note: `-D clippy::len-without-is-empty` implied by `-D warnings` error: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` method - --> $DIR/len_without_is_empty.rs:55:1 + --> $DIR/len_without_is_empty.rs:57:1 | LL | / pub trait PubTraitsToo { +LL | | LL | | fn len(&self) -> isize; LL | | } | |_^ error: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` method - --> $DIR/len_without_is_empty.rs:68:5 + --> $DIR/len_without_is_empty.rs:71:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:72:5 + --> $DIR/len_without_is_empty.rs:76:5 | LL | fn is_empty(&self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:80:5 + --> $DIR/len_without_is_empty.rs:84:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:84:5 + --> $DIR/len_without_is_empty.rs:89:5 | LL | pub fn is_empty(&self, x: u32) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` error: struct `MismatchedSelf` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:92:5 + --> $DIR/len_without_is_empty.rs:97:5 | LL | pub fn len(self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:96:5 + --> $DIR/len_without_is_empty.rs:102:5 | LL | pub fn is_empty(&self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(self) -> bool` error: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_empty` method - --> $DIR/len_without_is_empty.rs:171:1 + --> $DIR/len_without_is_empty.rs:177:1 | LL | / pub trait DependsOnFoo: Foo { +LL | | LL | | fn len(&mut self) -> usize; LL | | } | |_^ error: struct `OptionalLen3` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:216:5 + --> $DIR/len_without_is_empty.rs:223:5 | LL | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:221:5 + --> $DIR/len_without_is_empty.rs:229:5 | LL | pub fn is_empty(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` error: struct `ResultLen` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:228:5 + --> $DIR/len_without_is_empty.rs:236:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:233:5 + --> $DIR/len_without_is_empty.rs:243:5 | LL | pub fn is_empty(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` or `(&self) -> Result error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:228:5 + --> $DIR/len_without_is_empty.rs:236:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +98,7 @@ LL | pub fn len(&self) -> Result { = note: `-D clippy::result-unit-err` implied by `-D warnings` error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:240:5 + --> $DIR/len_without_is_empty.rs:250:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +106,7 @@ LL | pub fn len(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:244:5 + --> $DIR/len_without_is_empty.rs:255:5 | LL | pub fn is_empty(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +114,7 @@ LL | pub fn is_empty(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:251:5 + --> $DIR/len_without_is_empty.rs:263:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,19 +122,19 @@ LL | pub fn len(&self) -> Result { = help: use a custom `Error` type instead error: struct `AsyncLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> $DIR/len_without_is_empty.rs:292:5 + --> $DIR/len_without_is_empty.rs:305:5 | LL | pub async fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncOptionLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> $DIR/len_without_is_empty.rs:304:5 + --> $DIR/len_without_is_empty.rs:318:5 | LL | pub async fn len(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> $DIR/len_without_is_empty.rs:325:5 + --> $DIR/len_without_is_empty.rs:340:5 | LL | pub async fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/let_and_return.fixed b/tests/ui/let_and_return.fixed index 32119996e3d9b..88b8ae6737583 100644 --- a/tests/ui/let_and_return.fixed +++ b/tests/ui/let_and_return.fixed @@ -7,12 +7,15 @@ fn test() -> i32 { let _y = 0; // no warning 5 + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn test_inner() -> i32 { if true { 5 + //~^ ERROR: returning the result of a `let` binding from a block } else { 0 } @@ -75,6 +78,7 @@ fn issue_3792() -> String { // https://github.com/rust-lang/rust/pull/93965 stdin.lock().lines().next().unwrap().unwrap() + //~^ ERROR: returning the result of a `let` binding from a block } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -165,6 +169,7 @@ mod issue_5729 { fn foo_cloned(&self) -> Arc { Arc::clone(&self.foo) as _ + //~^ ERROR: returning the result of a `let` binding from a block } } } diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs index 64665cc906f61..f366842c5d771 100644 --- a/tests/ui/let_and_return.rs +++ b/tests/ui/let_and_return.rs @@ -7,12 +7,15 @@ fn test() -> i32 { let _y = 0; // no warning let x = 5; x + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn test_inner() -> i32 { if true { let x = 5; x + //~^ ERROR: returning the result of a `let` binding from a block } else { 0 } @@ -75,6 +78,7 @@ fn issue_3792() -> String { // https://github.com/rust-lang/rust/pull/93965 let line = stdin.lock().lines().next().unwrap().unwrap(); line + //~^ ERROR: returning the result of a `let` binding from a block } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -165,6 +169,7 @@ mod issue_5729 { fn foo_cloned(&self) -> Arc { let clone = Arc::clone(&self.foo); clone + //~^ ERROR: returning the result of a `let` binding from a block } } } diff --git a/tests/ui/let_and_return.stderr b/tests/ui/let_and_return.stderr index 4ca0a05c858fb..3f60b69df4567 100644 --- a/tests/ui/let_and_return.stderr +++ b/tests/ui/let_and_return.stderr @@ -14,7 +14,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:15:9 + --> $DIR/let_and_return.rs:17:9 | LL | let x = 5; | ---------- unnecessary `let` binding @@ -28,7 +28,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:77:5 + --> $DIR/let_and_return.rs:80:5 | LL | let line = stdin.lock().lines().next().unwrap().unwrap(); | --------------------------------------------------------- unnecessary `let` binding @@ -42,7 +42,7 @@ LL ~ stdin.lock().lines().next().unwrap().unwrap() | error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:167:13 + --> $DIR/let_and_return.rs:171:13 | LL | let clone = Arc::clone(&self.foo); | ---------------------------------- unnecessary `let` binding diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs index 1271a1c123607..9869d945299e0 100644 --- a/tests/ui/let_if_seq.rs +++ b/tests/ui/let_if_seq.rs @@ -64,11 +64,15 @@ fn main() { issue985_alt(); let mut foo = 0; + //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~| NOTE: you might not need `mut` at all if f() { foo = 42; } let mut bar = 0; + //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~| NOTE: you might not need `mut` at all if f() { f(); bar = 42; @@ -77,6 +81,7 @@ fn main() { } let quz; + //~^ ERROR: `if _ { .. } else { .. }` is an expression if f() { quz = 42; } else { @@ -106,6 +111,8 @@ fn main() { // baz needs to be mut let mut baz = 0; + //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~| NOTE: you might not need `mut` at all if f() { baz = 42; } diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr index f2e0edb6fbc30..b739268dacd55 100644 --- a/tests/ui/let_if_seq.stderr +++ b/tests/ui/let_if_seq.stderr @@ -2,6 +2,8 @@ error: `if _ { .. } else { .. }` is an expression --> $DIR/let_if_seq.rs:66:5 | LL | / let mut foo = 0; +LL | | +LL | | LL | | if f() { LL | | foo = 42; LL | | } @@ -11,13 +13,13 @@ LL | | } = note: `-D clippy::useless-let-if-seq` implied by `-D warnings` error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:71:5 + --> $DIR/let_if_seq.rs:73:5 | LL | / let mut bar = 0; +LL | | +LL | | LL | | if f() { -LL | | f(); -LL | | bar = 42; -LL | | } else { +... | LL | | f(); LL | | } | |_____^ help: it is more idiomatic to write: `let bar = if f() { ..; 42 } else { ..; 0 };` @@ -25,9 +27,10 @@ LL | | } = note: you might not need `mut` at all error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:79:5 + --> $DIR/let_if_seq.rs:83:5 | LL | / let quz; +LL | | LL | | if f() { LL | | quz = 42; LL | | } else { @@ -36,9 +39,11 @@ LL | | } | |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };` error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:108:5 + --> $DIR/let_if_seq.rs:113:5 | LL | / let mut baz = 0; +LL | | +LL | | LL | | if f() { LL | | baz = 42; LL | | } diff --git a/tests/ui/let_underscore_future.rs b/tests/ui/let_underscore_future.rs index f904868577db2..873ae667ab71a 100644 --- a/tests/ui/let_underscore_future.rs +++ b/tests/ui/let_underscore_future.rs @@ -9,12 +9,17 @@ fn custom() -> impl Future { } fn do_something_to_future(future: &mut impl Future) {} +//~^ ERROR: this argument is a mutable reference, but not used mutably +//~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` fn main() { let _ = some_async_fn(); + //~^ ERROR: non-binding `let` on a future let _ = custom(); + //~^ ERROR: non-binding `let` on a future let mut future = some_async_fn(); do_something_to_future(&mut future); let _ = future; + //~^ ERROR: non-binding `let` on a future } diff --git a/tests/ui/let_underscore_future.stderr b/tests/ui/let_underscore_future.stderr index ff1e2b8c90195..e3a628236e708 100644 --- a/tests/ui/let_underscore_future.stderr +++ b/tests/ui/let_underscore_future.stderr @@ -1,5 +1,5 @@ error: non-binding `let` on a future - --> $DIR/let_underscore_future.rs:14:5 + --> $DIR/let_underscore_future.rs:16:5 | LL | let _ = some_async_fn(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | let _ = some_async_fn(); = note: `-D clippy::let-underscore-future` implied by `-D warnings` error: non-binding `let` on a future - --> $DIR/let_underscore_future.rs:15:5 + --> $DIR/let_underscore_future.rs:18:5 | LL | let _ = custom(); | ^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = custom(); = help: consider awaiting the future or dropping explicitly with `std::mem::drop` error: non-binding `let` on a future - --> $DIR/let_underscore_future.rs:19:5 + --> $DIR/let_underscore_future.rs:23:5 | LL | let _ = future; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/let_underscore_lock.rs b/tests/ui/let_underscore_lock.rs index 87f12e2789f09..ccac73be79e4d 100644 --- a/tests/ui/let_underscore_lock.rs +++ b/tests/ui/let_underscore_lock.rs @@ -8,13 +8,17 @@ fn main() { let p_m: Mutex<()> = Mutex::const_new(RawMutex::INIT, ()); let _ = p_m.lock(); + //~^ ERROR: non-binding `let` on a synchronization lock let p_m1 = Mutex::new(0); let _ = p_m1.lock(); + //~^ ERROR: non-binding `let` on a synchronization lock let p_rw = RwLock::new(0); let _ = p_rw.read(); + //~^ ERROR: non-binding `let` on a synchronization lock let _ = p_rw.write(); + //~^ ERROR: non-binding `let` on a synchronization lock // These shouldn't throw an error. let _ = p_m; diff --git a/tests/ui/let_underscore_lock.stderr b/tests/ui/let_underscore_lock.stderr index 5027e6b3cbc77..9c9ff9c917c87 100644 --- a/tests/ui/let_underscore_lock.stderr +++ b/tests/ui/let_underscore_lock.stderr @@ -8,7 +8,7 @@ LL | let _ = p_m.lock(); = note: `-D clippy::let-underscore-lock` implied by `-D warnings` error: non-binding `let` on a synchronization lock - --> $DIR/let_underscore_lock.rs:13:5 + --> $DIR/let_underscore_lock.rs:14:5 | LL | let _ = p_m1.lock(); | ^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = p_m1.lock(); = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` error: non-binding `let` on a synchronization lock - --> $DIR/let_underscore_lock.rs:16:5 + --> $DIR/let_underscore_lock.rs:18:5 | LL | let _ = p_rw.read(); | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let _ = p_rw.read(); = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` error: non-binding `let` on a synchronization lock - --> $DIR/let_underscore_lock.rs:17:5 + --> $DIR/let_underscore_lock.rs:20:5 | LL | let _ = p_rw.write(); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/let_underscore_must_use.rs b/tests/ui/let_underscore_must_use.rs index 1edb77c748bfb..3290d087724e6 100644 --- a/tests/ui/let_underscore_must_use.rs +++ b/tests/ui/let_underscore_must_use.rs @@ -65,30 +65,42 @@ impl Trait for S { fn main() { let _ = f(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = g(); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = h(); let _ = l(0_u32); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let s = S {}; let _ = s.f(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = s.g(); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = s.k(); let _ = S::h(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = S::p(); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = S::a(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = if true { Ok(()) } else { Err(()) }; + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let a = Result::<(), ()>::Ok(()); let _ = a.is_ok(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = a.map(|_| ()); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = a; + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type #[allow(clippy::let_underscore_must_use)] let _ = a; diff --git a/tests/ui/let_underscore_must_use.stderr b/tests/ui/let_underscore_must_use.stderr index 28d760eb46ecc..5cd02a6e81221 100644 --- a/tests/ui/let_underscore_must_use.stderr +++ b/tests/ui/let_underscore_must_use.stderr @@ -8,7 +8,7 @@ LL | let _ = f(); = note: `-D clippy::let-underscore-must-use` implied by `-D warnings` error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:68:5 + --> $DIR/let_underscore_must_use.rs:69:5 | LL | let _ = g(); | ^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = g(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:70:5 + --> $DIR/let_underscore_must_use.rs:72:5 | LL | let _ = l(0_u32); | ^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let _ = l(0_u32); = help: consider explicitly using function result error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:74:5 + --> $DIR/let_underscore_must_use.rs:77:5 | LL | let _ = s.f(); | ^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _ = s.f(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:75:5 + --> $DIR/let_underscore_must_use.rs:79:5 | LL | let _ = s.g(); | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let _ = s.g(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:78:5 + --> $DIR/let_underscore_must_use.rs:83:5 | LL | let _ = S::h(); | ^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let _ = S::h(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:79:5 + --> $DIR/let_underscore_must_use.rs:85:5 | LL | let _ = S::p(); | ^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = S::p(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:81:5 + --> $DIR/let_underscore_must_use.rs:88:5 | LL | let _ = S::a(); | ^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let _ = S::a(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:83:5 + --> $DIR/let_underscore_must_use.rs:91:5 | LL | let _ = if true { Ok(()) } else { Err(()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | let _ = if true { Ok(()) } else { Err(()) }; = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:87:5 + --> $DIR/let_underscore_must_use.rs:96:5 | LL | let _ = a.is_ok(); | ^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | let _ = a.is_ok(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:89:5 + --> $DIR/let_underscore_must_use.rs:99:5 | LL | let _ = a.map(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | let _ = a.map(|_| ()); = help: consider explicitly using expression value error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:91:5 + --> $DIR/let_underscore_must_use.rs:102:5 | LL | let _ = a; | ^^^^^^^^^^ diff --git a/tests/ui/linkedlist.rs b/tests/ui/linkedlist.rs index 690ea810a6214..e1e6cff980979 100644 --- a/tests/ui/linkedlist.rs +++ b/tests/ui/linkedlist.rs @@ -6,12 +6,17 @@ extern crate alloc; use alloc::collections::linked_list::LinkedList; const C: LinkedList = LinkedList::new(); +//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu static S: LinkedList = LinkedList::new(); +//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu trait Foo { type Baz = LinkedList; + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str fn foo(_: LinkedList); + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str const BAR: Option>; + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str } // Ok, we don’t want to warn for implementations; see issue #605. @@ -22,16 +27,20 @@ impl Foo for LinkedList { pub struct Bar { priv_linked_list_field: LinkedList, + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str pub pub_linked_list_field: LinkedList, } impl Bar { fn foo(_: LinkedList) {} + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str } // All of these test should be trigger the lint because they are not // part of the public api fn test(my_favorite_linked_list: LinkedList) {} +//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu fn test_ret() -> Option> { + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu None } fn test_local_not_linted() { diff --git a/tests/ui/linkedlist.stderr b/tests/ui/linkedlist.stderr index c76c949613129..b31b0cd9314e6 100644 --- a/tests/ui/linkedlist.stderr +++ b/tests/ui/linkedlist.stderr @@ -8,7 +8,7 @@ LL | const C: LinkedList = LinkedList::new(); = note: `-D clippy::linkedlist` implied by `-D warnings` error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:9:11 + --> $DIR/linkedlist.rs:10:11 | LL | static S: LinkedList = LinkedList::new(); | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | static S: LinkedList = LinkedList::new(); = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:12:16 + --> $DIR/linkedlist.rs:14:16 | LL | type Baz = LinkedList; | ^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | type Baz = LinkedList; = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:13:15 + --> $DIR/linkedlist.rs:16:15 | LL | fn foo(_: LinkedList); | ^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | fn foo(_: LinkedList); = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:14:23 + --> $DIR/linkedlist.rs:18:23 | LL | const BAR: Option>; | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | const BAR: Option>; = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:24:29 + --> $DIR/linkedlist.rs:29:29 | LL | priv_linked_list_field: LinkedList, | ^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | priv_linked_list_field: LinkedList, = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:28:15 + --> $DIR/linkedlist.rs:34:15 | LL | fn foo(_: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | fn foo(_: LinkedList) {} = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:33:34 + --> $DIR/linkedlist.rs:40:34 | LL | fn test(my_favorite_linked_list: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | fn test(my_favorite_linked_list: LinkedList) {} = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:34:25 + --> $DIR/linkedlist.rs:42:25 | LL | fn test_ret() -> Option> { | ^^^^^^^^^^^^^^ diff --git a/tests/ui/literals.rs b/tests/ui/literals.rs index 1a276153c7383..c275b04d886bb 100644 --- a/tests/ui/literals.rs +++ b/tests/ui/literals.rs @@ -11,16 +11,32 @@ fn main() { let ok1 = 0xABCD; let ok3 = 0xab_cd; let ok4 = 0xab_cd_i32; + //~^ ERROR: integer type suffix should not be separated by an underscore + //~| NOTE: `-D clippy::separated-literal-suffix` implied by `-D warnings` let ok5 = 0xAB_CD_u32; + //~^ ERROR: integer type suffix should not be separated by an underscore let ok5 = 0xAB_CD_isize; + //~^ ERROR: integer type suffix should not be separated by an underscore let fail1 = 0xabCD; + //~^ ERROR: inconsistent casing in hexadecimal literal + //~| NOTE: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` let fail2 = 0xabCD_u32; + //~^ ERROR: integer type suffix should not be separated by an underscore + //~| ERROR: inconsistent casing in hexadecimal literal let fail2 = 0xabCD_isize; + //~^ ERROR: integer type suffix should not be separated by an underscore + //~| ERROR: inconsistent casing in hexadecimal literal let fail_multi_zero = 000_123usize; + //~^ ERROR: integer type suffix should be separated by an underscore + //~| NOTE: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` + //~| ERROR: this is a decimal constant + //~| NOTE: `-D clippy::zero-prefixed-literal` implied by `-D warnings` let ok9 = 0; let ok10 = 0_i64; + //~^ ERROR: integer type suffix should not be separated by an underscore let fail8 = 0123; + //~^ ERROR: this is a decimal constant let ok11 = 0o123; let ok12 = 0b10_1010; @@ -30,13 +46,20 @@ fn main() { let ok15 = 0xab_cabc_abca_bcab_cabc; let ok16 = 0xFE_BAFE_ABAB_ABCD; let ok17 = 0x123_4567_8901_usize; + //~^ ERROR: integer type suffix should not be separated by an underscore let ok18 = 0xF; let fail19 = 12_3456_21; + //~^ ERROR: digits grouped inconsistently by underscores + //~| NOTE: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` let fail22 = 3__4___23; + //~^ ERROR: digits grouped inconsistently by underscores let fail23 = 3__16___23; + //~^ ERROR: digits grouped inconsistently by underscores let fail24 = 0xAB_ABC_AB; + //~^ ERROR: digits of hex, binary or octal literal not in groups of equal size + //~| NOTE: `-D clippy::unusual-byte-groupings` implied by `-D warnings` let fail25 = 0b01_100_101; let ok26 = 0x6_A0_BF; let ok27 = 0b1_0010_0101; @@ -45,6 +68,9 @@ fn main() { fn issue9651() { // lint but octal form is not possible here let _ = 08; + //~^ ERROR: this is a decimal constant let _ = 09; + //~^ ERROR: this is a decimal constant let _ = 089; + //~^ ERROR: this is a decimal constant } diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr index 2a7785d4fb245..7c79436752fca 100644 --- a/tests/ui/literals.stderr +++ b/tests/ui/literals.stderr @@ -7,19 +7,19 @@ LL | let ok4 = 0xab_cd_i32; = note: `-D clippy::separated-literal-suffix` implied by `-D warnings` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:14:15 + --> $DIR/literals.rs:16:15 | LL | let ok5 = 0xAB_CD_u32; | ^^^^^^^^^^^ help: remove the underscore: `0xAB_CDu32` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:15:15 + --> $DIR/literals.rs:18:15 | LL | let ok5 = 0xAB_CD_isize; | ^^^^^^^^^^^^^ help: remove the underscore: `0xAB_CDisize` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:16:17 + --> $DIR/literals.rs:20:17 | LL | let fail1 = 0xabCD; | ^^^^^^ @@ -27,31 +27,31 @@ LL | let fail1 = 0xabCD; = note: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:17:17 + --> $DIR/literals.rs:23:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ help: remove the underscore: `0xabCDu32` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:17:17 + --> $DIR/literals.rs:23:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:18:17 + --> $DIR/literals.rs:26:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ help: remove the underscore: `0xabCDisize` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:18:17 + --> $DIR/literals.rs:26:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ error: integer type suffix should be separated by an underscore - --> $DIR/literals.rs:19:27 + --> $DIR/literals.rs:29:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ help: add an underscore: `000_123_usize` @@ -59,7 +59,7 @@ LL | let fail_multi_zero = 000_123usize; = note: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` error: this is a decimal constant - --> $DIR/literals.rs:19:27 + --> $DIR/literals.rs:29:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ @@ -75,13 +75,13 @@ LL | let fail_multi_zero = 0o123usize; | ~~~~~~~~~~ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:22:16 + --> $DIR/literals.rs:36:16 | LL | let ok10 = 0_i64; | ^^^^^ help: remove the underscore: `0i64` error: this is a decimal constant - --> $DIR/literals.rs:23:17 + --> $DIR/literals.rs:38:17 | LL | let fail8 = 0123; | ^^^^ @@ -96,13 +96,13 @@ LL | let fail8 = 0o123; | ~~~~~ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:32:16 + --> $DIR/literals.rs:48:16 | LL | let ok17 = 0x123_4567_8901_usize; | ^^^^^^^^^^^^^^^^^^^^^ help: remove the underscore: `0x123_4567_8901usize` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:35:18 + --> $DIR/literals.rs:52:18 | LL | let fail19 = 12_3456_21; | ^^^^^^^^^^ help: consider: `12_345_621` @@ -110,19 +110,19 @@ LL | let fail19 = 12_3456_21; = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:36:18 + --> $DIR/literals.rs:55:18 | LL | let fail22 = 3__4___23; | ^^^^^^^^^ help: consider: `3_423` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:37:18 + --> $DIR/literals.rs:57:18 | LL | let fail23 = 3__16___23; | ^^^^^^^^^^ help: consider: `31_623` error: digits of hex, binary or octal literal not in groups of equal size - --> $DIR/literals.rs:39:18 + --> $DIR/literals.rs:60:18 | LL | let fail24 = 0xAB_ABC_AB; | ^^^^^^^^^^^ help: consider: `0x0ABA_BCAB` @@ -130,7 +130,7 @@ LL | let fail24 = 0xAB_ABC_AB; = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` error: this is a decimal constant - --> $DIR/literals.rs:47:13 + --> $DIR/literals.rs:70:13 | LL | let _ = 08; | ^^ @@ -141,7 +141,7 @@ LL | let _ = 8; | ~ error: this is a decimal constant - --> $DIR/literals.rs:48:13 + --> $DIR/literals.rs:72:13 | LL | let _ = 09; | ^^ @@ -152,7 +152,7 @@ LL | let _ = 9; | ~ error: this is a decimal constant - --> $DIR/literals.rs:49:13 + --> $DIR/literals.rs:74:13 | LL | let _ = 089; | ^^^ diff --git a/tests/ui/manual_clamp.fixed b/tests/ui/manual_clamp.fixed index 592d172228147..c5355cce8e212 100644 --- a/tests/ui/manual_clamp.fixed +++ b/tests/ui/manual_clamp.fixed @@ -27,8 +27,12 @@ fn main() { let x3 = input.clamp(min, max); let x4 = input.clamp(min, max); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x5 = input.clamp(min, max); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x6 = input.clamp(min, max); @@ -60,22 +64,54 @@ fn main() { let input: i32 = cmp_min_max(1); // These can only be detected if exactly one of the arguments to the inner function is const. let x16 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x17 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x18 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x19 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x20 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x21 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x22 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x23 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let input: f64 = cmp_min_max(1) as f64; let x24 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x25 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x26 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x27 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x28 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x29 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x30 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x31 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() } let mut x32 = input; x32 = x32.clamp(min, max); diff --git a/tests/ui/manual_clamp.rs b/tests/ui/manual_clamp.rs index cdfd8e4c3fe3e..cacb40ae027f3 100644 --- a/tests/ui/manual_clamp.rs +++ b/tests/ui/manual_clamp.rs @@ -19,6 +19,8 @@ fn main() { let (input, min, max) = (0, -2, 3); // Lint let x0 = if max < input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min max } else if min > input { min @@ -27,6 +29,8 @@ fn main() { }; let x1 = if input > max { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min max } else if input < min { min @@ -35,6 +39,8 @@ fn main() { }; let x2 = if input < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min min } else if input > max { max @@ -43,6 +49,8 @@ fn main() { }; let x3 = if min > input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min min } else if max < input { max @@ -51,22 +59,32 @@ fn main() { }; let x4 = input.max(min).min(max); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x5 = input.min(max).max(min); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x6 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if x > max => max, x if x < min => min, x => x, }; let x7 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if x < min => min, x if x > max => max, x => x, }; let x8 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if max < x => max, x if min > x => min, x => x, @@ -74,6 +92,8 @@ fn main() { let mut x9 = input; if x9 < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x9 = min; } if x9 > max { @@ -81,6 +101,8 @@ fn main() { } let x10 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if min > x => min, x if max < x => max, x => x, @@ -89,6 +111,8 @@ fn main() { let mut x11 = input; let _ = 1; if x11 > max { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x11 = max; } if x11 < min { @@ -97,6 +121,8 @@ fn main() { let mut x12 = input; if min > x12 { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x12 = min; } if max < x12 { @@ -105,6 +131,8 @@ fn main() { let mut x13 = input; if max < x13 { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x13 = max; } if min > x13 { @@ -112,6 +140,8 @@ fn main() { } let x14 = if input > CONST_MAX { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min CONST_MAX } else if input < CONST_MIN { CONST_MIN @@ -121,6 +151,8 @@ fn main() { { let (input, min, max) = (0.0f64, -2.0, 3.0); let x15 = if input > max { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() max } else if input < min { min @@ -132,25 +164,59 @@ fn main() { let input: i32 = cmp_min_max(1); // These can only be detected if exactly one of the arguments to the inner function is const. let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let input: f64 = cmp_min_max(1) as f64; let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() } let mut x32 = input; if x32 < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x32 = min; } else if x32 > max { x32 = max; @@ -159,6 +225,8 @@ fn main() { // It's important this be the last set of statements let mut x33 = input; if max < x33 { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x33 = max; } if min > x33 { @@ -319,6 +387,8 @@ fn msrv_1_49() { fn msrv_1_50() { let (input, min, max) = (0, -1, 2); let _ = if input < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min min } else if input > max { max diff --git a/tests/ui/manual_clamp.stderr b/tests/ui/manual_clamp.stderr index 988ad1527e837..95e0cf5d4ec51 100644 --- a/tests/ui/manual_clamp.stderr +++ b/tests/ui/manual_clamp.stderr @@ -1,10 +1,11 @@ error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:76:5 + --> $DIR/manual_clamp.rs:94:5 | LL | / if x9 < min { +LL | | +LL | | LL | | x9 = min; -LL | | } -LL | | if x9 > max { +... | LL | | x9 = max; LL | | } | |_____^ help: replace with clamp: `x9 = x9.clamp(min, max);` @@ -13,12 +14,13 @@ LL | | } = note: `-D clippy::manual-clamp` implied by `-D warnings` error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:91:5 + --> $DIR/manual_clamp.rs:113:5 | LL | / if x11 > max { +LL | | +LL | | LL | | x11 = max; -LL | | } -LL | | if x11 < min { +... | LL | | x11 = min; LL | | } | |_____^ help: replace with clamp: `x11 = x11.clamp(min, max);` @@ -26,12 +28,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:99:5 + --> $DIR/manual_clamp.rs:123:5 | LL | / if min > x12 { +LL | | +LL | | LL | | x12 = min; -LL | | } -LL | | if max < x12 { +... | LL | | x12 = max; LL | | } | |_____^ help: replace with clamp: `x12 = x12.clamp(min, max);` @@ -39,12 +42,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:107:5 + --> $DIR/manual_clamp.rs:133:5 | LL | / if max < x13 { +LL | | +LL | | LL | | x13 = max; -LL | | } -LL | | if min > x13 { +... | LL | | x13 = min; LL | | } | |_____^ help: replace with clamp: `x13 = x13.clamp(min, max);` @@ -52,12 +56,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:161:5 + --> $DIR/manual_clamp.rs:227:5 | LL | / if max < x33 { +LL | | +LL | | LL | | x33 = max; -LL | | } -LL | | if min > x33 { +... | LL | | x33 = min; LL | | } | |_____^ help: replace with clamp: `x33 = x33.clamp(min, max);` @@ -69,10 +74,10 @@ error: clamp-like pattern without using clamp function | LL | let x0 = if max < input { | ______________^ +LL | | +LL | | LL | | max -LL | | } else if min > input { -LL | | min -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -80,14 +85,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:29:14 + --> $DIR/manual_clamp.rs:31:14 | LL | let x1 = if input > max { | ______________^ +LL | | +LL | | LL | | max -LL | | } else if input < min { -LL | | min -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -95,14 +100,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:37:14 + --> $DIR/manual_clamp.rs:41:14 | LL | let x2 = if input < min { | ______________^ +LL | | +LL | | LL | | min -LL | | } else if input > max { -LL | | max -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -110,14 +115,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:45:14 + --> $DIR/manual_clamp.rs:51:14 | LL | let x3 = if min > input { | ______________^ +LL | | +LL | | LL | | min -LL | | } else if max < input { -LL | | max -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -125,7 +130,7 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:53:14 + --> $DIR/manual_clamp.rs:61:14 | LL | let x4 = input.max(min).min(max); | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)` @@ -133,7 +138,7 @@ LL | let x4 = input.max(min).min(max); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:55:14 + --> $DIR/manual_clamp.rs:65:14 | LL | let x5 = input.min(max).max(min); | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)` @@ -141,10 +146,12 @@ LL | let x5 = input.min(max).max(min); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:57:14 + --> $DIR/manual_clamp.rs:69:14 | LL | let x6 = match input { | ______________^ +LL | | +LL | | LL | | x if x > max => max, LL | | x if x < min => min, LL | | x => x, @@ -154,10 +161,12 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:63:14 + --> $DIR/manual_clamp.rs:77:14 | LL | let x7 = match input { | ______________^ +LL | | +LL | | LL | | x if x < min => min, LL | | x if x > max => max, LL | | x => x, @@ -167,10 +176,12 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:69:14 + --> $DIR/manual_clamp.rs:85:14 | LL | let x8 = match input { | ______________^ +LL | | +LL | | LL | | x if max < x => max, LL | | x if min > x => min, LL | | x => x, @@ -180,10 +191,12 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:83:15 + --> $DIR/manual_clamp.rs:103:15 | LL | let x10 = match input { | _______________^ +LL | | +LL | | LL | | x if min > x => min, LL | | x if max < x => max, LL | | x => x, @@ -193,14 +206,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:114:15 + --> $DIR/manual_clamp.rs:142:15 | LL | let x14 = if input > CONST_MAX { | _______________^ +LL | | +LL | | LL | | CONST_MAX -LL | | } else if input < CONST_MIN { -LL | | CONST_MIN -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -208,14 +221,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:123:19 + --> $DIR/manual_clamp.rs:153:19 | LL | let x15 = if input > max { | ___________________^ +LL | | +LL | | LL | | max -LL | | } else if input < min { -LL | | min -LL | | } else { +... | LL | | input LL | | }; | |_________^ help: replace with clamp: `input.clamp(min, max)` @@ -224,7 +237,7 @@ LL | | }; = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:134:19 + --> $DIR/manual_clamp.rs:166:19 | LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -232,7 +245,7 @@ LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:135:19 + --> $DIR/manual_clamp.rs:169:19 | LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -240,7 +253,7 @@ LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:136:19 + --> $DIR/manual_clamp.rs:172:19 | LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -248,7 +261,7 @@ LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:137:19 + --> $DIR/manual_clamp.rs:175:19 | LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -256,7 +269,7 @@ LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:138:19 + --> $DIR/manual_clamp.rs:178:19 | LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -264,7 +277,7 @@ LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:139:19 + --> $DIR/manual_clamp.rs:181:19 | LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -272,7 +285,7 @@ LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:140:19 + --> $DIR/manual_clamp.rs:184:19 | LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -280,7 +293,7 @@ LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:141:19 + --> $DIR/manual_clamp.rs:187:19 | LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -288,7 +301,7 @@ LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:143:19 + --> $DIR/manual_clamp.rs:191:19 | LL | let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -297,7 +310,7 @@ LL | let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:144:19 + --> $DIR/manual_clamp.rs:194:19 | LL | let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -306,7 +319,7 @@ LL | let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:145:19 + --> $DIR/manual_clamp.rs:197:19 | LL | let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -315,7 +328,7 @@ LL | let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:146:19 + --> $DIR/manual_clamp.rs:200:19 | LL | let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -324,7 +337,7 @@ LL | let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:147:19 + --> $DIR/manual_clamp.rs:203:19 | LL | let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -333,7 +346,7 @@ LL | let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:148:19 + --> $DIR/manual_clamp.rs:206:19 | LL | let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -342,7 +355,7 @@ LL | let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:149:19 + --> $DIR/manual_clamp.rs:209:19 | LL | let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -351,7 +364,7 @@ LL | let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:150:19 + --> $DIR/manual_clamp.rs:212:19 | LL | let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -360,9 +373,11 @@ LL | let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:153:5 + --> $DIR/manual_clamp.rs:217:5 | LL | / if x32 < min { +LL | | +LL | | LL | | x32 = min; LL | | } else if x32 > max { LL | | x32 = max; @@ -372,14 +387,14 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:321:13 + --> $DIR/manual_clamp.rs:389:13 | LL | let _ = if input < min { | _____________^ +LL | | +LL | | LL | | min -LL | | } else if input > max { -LL | | max -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` diff --git a/tests/ui/manual_find.rs b/tests/ui/manual_find.rs index bab37c465353a..0a105b0359e50 100644 --- a/tests/ui/manual_find.rs +++ b/tests/ui/manual_find.rs @@ -3,6 +3,8 @@ //@no-rustfix fn vec_string(strings: Vec) -> Option { for s in strings { + //~^ ERROR: manual implementation of `Iterator::find` + //~| NOTE: you may need to dereference some variables if s == String::new() { return Some(s); } @@ -12,6 +14,8 @@ fn vec_string(strings: Vec) -> Option { fn tuple(arr: Vec<(String, i32)>) -> Option { for (s, _) in arr { + //~^ ERROR: manual implementation of `Iterator::find` + //~| NOTE: you may need to dereference some variables if s == String::new() { return Some(s); } diff --git a/tests/ui/manual_find.stderr b/tests/ui/manual_find.stderr index ea04bb066e61d..41aa00a8bc14b 100644 --- a/tests/ui/manual_find.stderr +++ b/tests/ui/manual_find.stderr @@ -2,9 +2,10 @@ error: manual implementation of `Iterator::find` --> $DIR/manual_find.rs:5:5 | LL | / for s in strings { +LL | | +LL | | LL | | if s == String::new() { -LL | | return Some(s); -LL | | } +... | LL | | } LL | | None | |________^ help: replace with an iterator: `strings.into_iter().find(|s| s == String::new())` @@ -13,12 +14,13 @@ LL | | None = note: `-D clippy::manual-find` implied by `-D warnings` error: manual implementation of `Iterator::find` - --> $DIR/manual_find.rs:14:5 + --> $DIR/manual_find.rs:16:5 | LL | / for (s, _) in arr { +LL | | +LL | | LL | | if s == String::new() { -LL | | return Some(s); -LL | | } +... | LL | | } LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|(s, _)| s).find(|s| s == String::new())` diff --git a/tests/ui/manual_flatten.rs b/tests/ui/manual_flatten.rs index b7ea0644d29a9..d57333ace040d 100644 --- a/tests/ui/manual_flatten.rs +++ b/tests/ui/manual_flatten.rs @@ -5,6 +5,7 @@ fn main() { // Test for loop over implicitly adjusted `Iterator` with `if let` expression let x = vec![Some(1), Some(2), Some(3)]; for n in x { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(y) = n { println!("{}", y); } @@ -13,6 +14,7 @@ fn main() { // Test for loop over implicitly adjusted `Iterator` with `if let` statement let y: Vec> = vec![]; for n in y.clone() { + //~^ ERROR: unnecessary `if let` since only the `Ok` variant of the iterator element i if let Ok(n) = n { println!("{}", n); }; @@ -20,6 +22,7 @@ fn main() { // Test for loop over by reference for n in &y { + //~^ ERROR: unnecessary `if let` since only the `Ok` variant of the iterator element i if let Ok(n) = n { println!("{}", n); } @@ -28,6 +31,7 @@ fn main() { // Test for loop over an implicit reference let z = &y; for n in z { + //~^ ERROR: unnecessary `if let` since only the `Ok` variant of the iterator element i if let Ok(n) = n { println!("{}", n); } @@ -37,6 +41,7 @@ fn main() { let z = vec![Some(1), Some(2), Some(3)]; let z = z.iter(); for n in z { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(m) = n { println!("{}", m); } @@ -70,6 +75,7 @@ fn main() { let vec_of_ref = vec![&Some(1)]; for n in &vec_of_ref { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(n) = n { println!("{:?}", n); } @@ -77,6 +83,7 @@ fn main() { let vec_of_ref = &vec_of_ref; for n in vec_of_ref { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(n) = n { println!("{:?}", n); } @@ -84,6 +91,7 @@ fn main() { let slice_of_ref = &[&Some(1)]; for n in slice_of_ref { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(n) = n { println!("{:?}", n); } @@ -114,6 +122,7 @@ fn main() { fn run_unformatted_tests() { // Skip rustfmt here on purpose so the suggestion does not fit in one line for n in vec![ + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element Some(1), Some(2), Some(3) diff --git a/tests/ui/manual_flatten.stderr b/tests/ui/manual_flatten.stderr index 180a6ff4e9a73..227bf3c5eaedf 100644 --- a/tests/ui/manual_flatten.stderr +++ b/tests/ui/manual_flatten.stderr @@ -5,6 +5,7 @@ LL | for n in x { | ^ - help: try: `x.into_iter().flatten()` | _____| | | +LL | | LL | | if let Some(y) = n { LL | | println!("{}", y); LL | | } @@ -12,7 +13,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:8:9 + --> $DIR/manual_flatten.rs:9:9 | LL | / if let Some(y) = n { LL | | println!("{}", y); @@ -21,12 +22,13 @@ LL | | } = note: `-D clippy::manual-flatten` implied by `-D warnings` error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> $DIR/manual_flatten.rs:15:5 + --> $DIR/manual_flatten.rs:16:5 | LL | for n in y.clone() { | ^ --------- help: try: `y.clone().into_iter().flatten()` | _____| | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | }; @@ -34,7 +36,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:16:9 + --> $DIR/manual_flatten.rs:18:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -42,12 +44,13 @@ LL | | }; | |_________^ error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> $DIR/manual_flatten.rs:22:5 + --> $DIR/manual_flatten.rs:24:5 | LL | for n in &y { | ^ -- help: try: `y.iter().flatten()` | _____| | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | } @@ -55,7 +58,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:23:9 + --> $DIR/manual_flatten.rs:26:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -63,12 +66,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> $DIR/manual_flatten.rs:30:5 + --> $DIR/manual_flatten.rs:33:5 | LL | for n in z { | ^ - help: try: `z.iter().flatten()` | _____| | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | } @@ -76,7 +80,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:31:9 + --> $DIR/manual_flatten.rs:35:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -84,12 +88,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:39:5 + --> $DIR/manual_flatten.rs:43:5 | LL | for n in z { | ^ - help: try: `z.flatten()` | _____| | | +LL | | LL | | if let Some(m) = n { LL | | println!("{}", m); LL | | } @@ -97,7 +102,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:40:9 + --> $DIR/manual_flatten.rs:45:9 | LL | / if let Some(m) = n { LL | | println!("{}", m); @@ -105,12 +110,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:72:5 + --> $DIR/manual_flatten.rs:77:5 | LL | for n in &vec_of_ref { | ^ ----------- help: try: `vec_of_ref.iter().copied().flatten()` | _____| | | +LL | | LL | | if let Some(n) = n { LL | | println!("{:?}", n); LL | | } @@ -118,7 +124,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:73:9 + --> $DIR/manual_flatten.rs:79:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -126,12 +132,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:79:5 + --> $DIR/manual_flatten.rs:85:5 | LL | for n in vec_of_ref { | ^ ---------- help: try: `vec_of_ref.iter().copied().flatten()` | _____| | | +LL | | LL | | if let Some(n) = n { LL | | println!("{:?}", n); LL | | } @@ -139,7 +146,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:80:9 + --> $DIR/manual_flatten.rs:87:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -147,12 +154,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:86:5 + --> $DIR/manual_flatten.rs:93:5 | LL | for n in slice_of_ref { | ^ ------------ help: try: `slice_of_ref.iter().copied().flatten()` | _____| | | +LL | | LL | | if let Some(n) = n { LL | | println!("{:?}", n); LL | | } @@ -160,7 +168,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:87:9 + --> $DIR/manual_flatten.rs:95:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -168,19 +176,19 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:116:5 + --> $DIR/manual_flatten.rs:124:5 | LL | / for n in vec![ +LL | | LL | | Some(1), LL | | Some(2), -LL | | Some(3) ... | LL | | } LL | | } | |_____^ | help: remove the `if let` statement in the for loop and then... - --> $DIR/manual_flatten.rs:121:9 + --> $DIR/manual_flatten.rs:130:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -189,6 +197,7 @@ LL | | } help: try | LL ~ for n in vec![ +LL + LL + Some(1), LL + Some(2), LL + Some(3) diff --git a/tests/ui/manual_let_else.rs b/tests/ui/manual_let_else.rs index 0cb525566809f..6775fdc921f9a 100644 --- a/tests/ui/manual_let_else.rs +++ b/tests/ui/manual_let_else.rs @@ -23,13 +23,17 @@ fn main() {} fn fire() { let v = if let Some(v_some) = g() { v_some } else { return }; + //~^ ERROR: this could be rewritten as `let...else` + //~| NOTE: `-D clippy::manual-let-else` implied by `-D warnings` let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { return; }; let v = if let Some(v) = g() { + //~^ ERROR: this could be rewritten as `let...else` // Blocks around the identity should have no impact { { v } @@ -43,14 +47,18 @@ fn fire() { // continue and break diverge loop { let v = if let Some(v_some) = g() { v_some } else { continue }; + //~^ ERROR: this could be rewritten as `let...else` let v = if let Some(v_some) = g() { v_some } else { break }; + //~^ ERROR: this could be rewritten as `let...else` } // panic also diverges let v = if let Some(v_some) = g() { v_some } else { panic!() }; + //~^ ERROR: this could be rewritten as `let...else` // abort also diverges let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { std::process::abort() @@ -58,6 +66,7 @@ fn fire() { // If whose two branches diverge also diverges let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { if true { return } else { panic!() } @@ -65,6 +74,7 @@ fn fire() { // Diverging after an if still makes the block diverge: let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { if true {} @@ -75,6 +85,7 @@ fn fire() { // Note: the corresponding let-else requires a ; at the end of the match // as otherwise the type checker does not turn it into a ! type. let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { match () { @@ -85,9 +96,11 @@ fn fire() { // An if's expression can cause divergence: let v = if let Some(v_some) = g() { v_some } else { if panic!() {} }; + //~^ ERROR: this could be rewritten as `let...else` // An expression of a match can cause divergence: let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { match panic!() { @@ -97,6 +110,7 @@ fn fire() { // Top level else if let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else if true { return; @@ -106,6 +120,7 @@ fn fire() { // All match arms diverge let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { match (g(), g()) { @@ -123,6 +138,7 @@ fn fire() { // Tuples supported for the declared variables let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { return; @@ -130,6 +146,7 @@ fn fire() { // Tuples supported with multiple bindings let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) { + //~^ ERROR: this could be rewritten as `let...else` (w_some, v_some) } else { return; @@ -148,25 +165,31 @@ fn fire() { } let v = if let Variant::A(a, 0) = e() { a } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // `mut v` is inserted into the pattern let mut v = if let Variant::B(b) = e() { b } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // Nesting works let nested = Ok(Some(e())); let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { + //~^ ERROR: this could be rewritten as `let...else` b } else { return; }; // dot dot works let v = if let Variant::A(.., a) = e() { a } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // () is preserved: a bit of an edge case but make sure it stays around let w = if let (Some(v), ()) = (g(), ()) { v } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // Tuple structs work let w = if let Some(S { v: x }) = Some(S { v: 0 }) { + //~^ ERROR: this could be rewritten as `let...else` x } else { return; @@ -174,6 +197,7 @@ fn fire() { // Field init shorthand is suggested let v = if let Some(S { v: x }) = Some(S { v: 0 }) { + //~^ ERROR: this could be rewritten as `let...else` x } else { return; @@ -181,6 +205,7 @@ fn fire() { // Multi-field structs also work let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { + //~^ ERROR: this could be rewritten as `let...else` (x, v, w) } else { return; @@ -297,6 +322,7 @@ fn not_fire() { let ff = Some(1); let _ = match ff { + //~^ ERROR: this could be rewritten as `let...else` Some(value) => value, _ => macro_call!(), }; diff --git a/tests/ui/manual_let_else.stderr b/tests/ui/manual_let_else.stderr index 912302b17a8f4..309ce3986f370 100644 --- a/tests/ui/manual_let_else.stderr +++ b/tests/ui/manual_let_else.stderr @@ -7,9 +7,10 @@ LL | let v = if let Some(v_some) = g() { v_some } else { return }; = note: `-D clippy::manual-let-else` implied by `-D warnings` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:26:5 + --> $DIR/manual_let_else.rs:28:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | return; @@ -24,12 +25,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:32:5 + --> $DIR/manual_let_else.rs:35:5 | LL | / let v = if let Some(v) = g() { +LL | | LL | | // Blocks around the identity should have no impact LL | | { -LL | | { v } ... | LL | | return; LL | | }; @@ -45,27 +46,28 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:45:9 + --> $DIR/manual_let_else.rs:49:9 | LL | let v = if let Some(v_some) = g() { v_some } else { continue }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { continue };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:46:9 + --> $DIR/manual_let_else.rs:51:9 | LL | let v = if let Some(v_some) = g() { v_some } else { break }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { break };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:50:5 + --> $DIR/manual_let_else.rs:56:5 | LL | let v = if let Some(v_some) = g() { v_some } else { panic!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { panic!() };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:53:5 + --> $DIR/manual_let_else.rs:60:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | std::process::abort() @@ -80,9 +82,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:60:5 + --> $DIR/manual_let_else.rs:68:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | if true { return } else { panic!() } @@ -97,9 +100,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:67:5 + --> $DIR/manual_let_else.rs:76:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | if true {} @@ -116,12 +120,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:77:5 + --> $DIR/manual_let_else.rs:87:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { -LL | | match () { ... | LL | | } LL | | }; @@ -138,19 +142,19 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:87:5 + --> $DIR/manual_let_else.rs:98:5 | LL | let v = if let Some(v_some) = g() { v_some } else { if panic!() {} }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { if panic!() {} };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:90:5 + --> $DIR/manual_let_else.rs:102:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { -LL | | match panic!() { -LL | | _ => {}, +... | LL | | } LL | | }; | |______^ @@ -165,13 +169,13 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:99:5 + --> $DIR/manual_let_else.rs:112:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else if true { -LL | | return; -LL | | } else { +... | LL | | panic!("diverge"); LL | | }; | |______^ @@ -186,12 +190,12 @@ LL + } }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:108:5 + --> $DIR/manual_let_else.rs:122:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { -LL | | match (g(), g()) { ... | LL | | } LL | | }; @@ -215,9 +219,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:125:5 + --> $DIR/manual_let_else.rs:140:5 | LL | / let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { +LL | | LL | | v_some LL | | } else { LL | | return; @@ -232,9 +237,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:132:5 + --> $DIR/manual_let_else.rs:148:5 | LL | / let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) { +LL | | LL | | (w_some, v_some) LL | | } else { LL | | return; @@ -249,7 +255,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:141:13 + --> $DIR/manual_let_else.rs:158:13 | LL | let $n = if let Some(v) = $e { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some($n) = g() else { return };` @@ -260,21 +266,22 @@ LL | create_binding_if_some!(w, g()); = note: this error originates in the macro `create_binding_if_some` (in Nightly builds, run with -Z macro-backtrace for more info) error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:150:5 + --> $DIR/manual_let_else.rs:167:5 | LL | let v = if let Variant::A(a, 0) = e() { a } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(v, 0) = e() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:153:5 + --> $DIR/manual_let_else.rs:171:5 | LL | let mut v = if let Variant::B(b) = e() { b } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::B(mut v) = e() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:157:5 + --> $DIR/manual_let_else.rs:176:5 | LL | / let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { +LL | | LL | | b LL | | } else { LL | | return; @@ -289,21 +296,22 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:163:5 + --> $DIR/manual_let_else.rs:183:5 | LL | let v = if let Variant::A(.., a) = e() { a } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(.., v) = e() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:166:5 + --> $DIR/manual_let_else.rs:187:5 | LL | let w = if let (Some(v), ()) = (g(), ()) { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let (Some(w), ()) = (g(), ()) else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:169:5 + --> $DIR/manual_let_else.rs:191:5 | LL | / let w = if let Some(S { v: x }) = Some(S { v: 0 }) { +LL | | LL | | x LL | | } else { LL | | return; @@ -318,9 +326,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:176:5 + --> $DIR/manual_let_else.rs:199:5 | LL | / let v = if let Some(S { v: x }) = Some(S { v: 0 }) { +LL | | LL | | x LL | | } else { LL | | return; @@ -335,9 +344,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:183:5 + --> $DIR/manual_let_else.rs:207:5 | LL | / let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { +LL | | LL | | (x, v, w) LL | | } else { LL | | return; @@ -352,9 +362,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:299:5 + --> $DIR/manual_let_else.rs:324:5 | LL | / let _ = match ff { +LL | | LL | | Some(value) => value, LL | | _ => macro_call!(), LL | | }; diff --git a/tests/ui/manual_let_else_match.rs b/tests/ui/manual_let_else_match.rs index 73ff69eec4ed7..e6af47384200e 100644 --- a/tests/ui/manual_let_else_match.rs +++ b/tests/ui/manual_let_else_match.rs @@ -34,11 +34,14 @@ fn main() {} fn fire() { let v = match g() { + //~^ ERROR: this could be rewritten as `let...else` + //~| NOTE: `-D clippy::manual-let-else` implied by `-D warnings` Some(v_some) => v_some, None => return, }; let v = match g() { + //~^ ERROR: this could be rewritten as `let...else` Some(v_some) => v_some, _ => return, }; @@ -46,11 +49,13 @@ fn fire() { loop { // More complex pattern for the identity arm and diverging arm let v = match h() { + //~^ ERROR: this could be rewritten as `let...else` (Some(v), None) | (None, Some(v)) => v, (Some(_), Some(_)) | (None, None) => continue, }; // Custom enums are supported as long as the "else" arm is a simple _ let v = match build_enum() { + //~^ ERROR: this could be rewritten as `let...else` Variant::Bar(v) | Variant::Baz(v) => v, _ => continue, }; @@ -59,12 +64,14 @@ fn fire() { // There is a _ in the diverging arm // TODO also support unused bindings aka _v let v = match f() { + //~^ ERROR: this could be rewritten as `let...else` Ok(v) => v, Err(_) => return, }; // Err(()) is an allowed pattern let v = match f().map_err(|_| ()) { + //~^ ERROR: this could be rewritten as `let...else` Ok(v) => v, Err(()) => return, }; @@ -72,17 +79,20 @@ fn fire() { let f = Variant::Bar(1); let _value = match f { + //~^ ERROR: this could be rewritten as `let...else` Variant::Bar(v) | Variant::Baz(v) => v, _ => return, }; let _value = match Some(build_enum()) { + //~^ ERROR: this could be rewritten as `let...else` Some(Variant::Bar(v) | Variant::Baz(v)) => v, _ => return, }; let data = [1_u8, 2, 3, 4, 0, 0, 0, 0]; let data = match data.as_slice() { + //~^ ERROR: this could be rewritten as `let...else` [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, _ => return, }; diff --git a/tests/ui/manual_let_else_match.stderr b/tests/ui/manual_let_else_match.stderr index 3fd9a637605b5..fb7d83f32440b 100644 --- a/tests/ui/manual_let_else_match.stderr +++ b/tests/ui/manual_let_else_match.stderr @@ -2,6 +2,8 @@ error: this could be rewritten as `let...else` --> $DIR/manual_let_else_match.rs:36:5 | LL | / let v = match g() { +LL | | +LL | | LL | | Some(v_some) => v_some, LL | | None => return, LL | | }; @@ -10,72 +12,80 @@ LL | | }; = note: `-D clippy::manual-let-else` implied by `-D warnings` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:41:5 + --> $DIR/manual_let_else_match.rs:43:5 | LL | / let v = match g() { +LL | | LL | | Some(v_some) => v_some, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let Some(v) = g() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:48:9 + --> $DIR/manual_let_else_match.rs:51:9 | LL | / let v = match h() { +LL | | LL | | (Some(v), None) | (None, Some(v)) => v, LL | | (Some(_), Some(_)) | (None, None) => continue, LL | | }; | |__________^ help: consider writing: `let ((Some(v), None) | (None, Some(v))) = h() else { continue };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:53:9 + --> $DIR/manual_let_else_match.rs:57:9 | LL | / let v = match build_enum() { +LL | | LL | | Variant::Bar(v) | Variant::Baz(v) => v, LL | | _ => continue, LL | | }; | |__________^ help: consider writing: `let (Variant::Bar(v) | Variant::Baz(v)) = build_enum() else { continue };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:61:5 + --> $DIR/manual_let_else_match.rs:66:5 | LL | / let v = match f() { +LL | | LL | | Ok(v) => v, LL | | Err(_) => return, LL | | }; | |______^ help: consider writing: `let Ok(v) = f() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:67:5 + --> $DIR/manual_let_else_match.rs:73:5 | LL | / let v = match f().map_err(|_| ()) { +LL | | LL | | Ok(v) => v, LL | | Err(()) => return, LL | | }; | |______^ help: consider writing: `let Ok(v) = f().map_err(|_| ()) else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:74:5 + --> $DIR/manual_let_else_match.rs:81:5 | LL | / let _value = match f { +LL | | LL | | Variant::Bar(v) | Variant::Baz(v) => v, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let (Variant::Bar(_value) | Variant::Baz(_value)) = f else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:79:5 + --> $DIR/manual_let_else_match.rs:87:5 | LL | / let _value = match Some(build_enum()) { +LL | | LL | | Some(Variant::Bar(v) | Variant::Baz(v)) => v, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let Some(Variant::Bar(_value) | Variant::Baz(_value)) = Some(build_enum()) else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:85:5 + --> $DIR/manual_let_else_match.rs:94:5 | LL | / let data = match data.as_slice() { +LL | | LL | | [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, LL | | _ => return, LL | | }; diff --git a/tests/ui/manual_memcpy/with_loop_counters.rs b/tests/ui/manual_memcpy/with_loop_counters.rs index 5f70221ec6eef..786d7e6e24454 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.rs +++ b/tests/ui/manual_memcpy/with_loop_counters.rs @@ -3,48 +3,57 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let mut count = 0; for i in 3..src.len() { + //~^ ERROR: it looks like you're manually copying between slices + //~| NOTE: `-D clippy::manual-memcpy` implied by `-D warnings` dst[i] = src[count]; count += 1; } let mut count = 0; for i in 3..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i]; count += 1; } let mut count = 3; for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i]; count += 1; } let mut count = 3; for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } let mut count = 0; for i in 3..(3 + src.len()) { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } let mut count = 3; for i in 5..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count - 2]; count += 1; } let mut count = 2; for i in 0..dst.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } let mut count = 5; for i in 3..10 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } @@ -52,6 +61,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 3; let mut count2 = 30; for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i]; dst2[count2] = src[i]; count += 1; @@ -62,6 +72,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) // arithmetic ones let mut count = 0 << 1; for i in 0..1 << 1 { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i + 2]; count += 1; } @@ -69,6 +80,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) // make sure incrementing expressions without semicolons at the end of loops are handled correctly. let mut count = 0; for i in 3..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1 } diff --git a/tests/ui/manual_memcpy/with_loop_counters.stderr b/tests/ui/manual_memcpy/with_loop_counters.stderr index 79d40c0bcb1d9..e23c95dc8a4af 100644 --- a/tests/ui/manual_memcpy/with_loop_counters.stderr +++ b/tests/ui/manual_memcpy/with_loop_counters.stderr @@ -2,6 +2,8 @@ error: it looks like you're manually copying between slices --> $DIR/with_loop_counters.rs:5:5 | LL | / for i in 3..src.len() { +LL | | +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } @@ -10,72 +12,80 @@ LL | | } = note: `-D clippy::manual-memcpy` implied by `-D warnings` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:11:5 + --> $DIR/with_loop_counters.rs:13:5 | LL | / for i in 3..src.len() { +LL | | LL | | dst[count] = src[i]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[..(src.len() - 3)].copy_from_slice(&src[3..]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:17:5 + --> $DIR/with_loop_counters.rs:20:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[count] = src[i]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..(src.len() + 3)].copy_from_slice(&src[..]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:23:5 + --> $DIR/with_loop_counters.rs:27:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[3..(src.len() + 3)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:29:5 + --> $DIR/with_loop_counters.rs:34:5 | LL | / for i in 3..(3 + src.len()) { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..(3 + src.len())].copy_from_slice(&src[..(3 + src.len() - 3)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:35:5 + --> $DIR/with_loop_counters.rs:41:5 | LL | / for i in 5..src.len() { +LL | | LL | | dst[i] = src[count - 2]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[5..src.len()].copy_from_slice(&src[(3 - 2)..((src.len() - 2) + 3 - 5)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:41:5 + --> $DIR/with_loop_counters.rs:48:5 | LL | / for i in 0..dst.len() { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[2..(dst.len() + 2)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:47:5 + --> $DIR/with_loop_counters.rs:55:5 | LL | / for i in 3..10 { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..10].copy_from_slice(&src[5..(10 + 5 - 3)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:54:5 + --> $DIR/with_loop_counters.rs:63:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[count] = src[i]; LL | | dst2[count2] = src[i]; LL | | count += 1; @@ -90,18 +100,20 @@ LL + dst2[30..(src.len() + 30)].copy_from_slice(&src[..]); | error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:64:5 + --> $DIR/with_loop_counters.rs:74:5 | LL | / for i in 0..1 << 1 { +LL | | LL | | dst[count] = src[i + 2]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].copy_from_slice(&src[2..((1 << 1) + 2)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:71:5 + --> $DIR/with_loop_counters.rs:82:5 | LL | / for i in 3..src.len() { +LL | | LL | | dst[i] = src[count]; LL | | count += 1 LL | | } diff --git a/tests/ui/manual_memcpy/without_loop_counters.rs b/tests/ui/manual_memcpy/without_loop_counters.rs index 1a1db6a632998..a224001a3dfd6 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.rs +++ b/tests/ui/manual_memcpy/without_loop_counters.rs @@ -6,26 +6,32 @@ const LOOP_OFFSET: usize = 5000; pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // plain manual memcpy for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices + //~| NOTE: `-D clippy::manual-memcpy` implied by `-D warnings` dst[i] = src[i]; } // dst offset memcpy for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i + 10] = src[i]; } // src offset memcpy for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i + 10]; } // src offset memcpy for i in 11..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - 10]; } // overwrite entire dst for i in 0..dst.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i]; } @@ -39,6 +45,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // multiple copies - suggest two memcpy statements for i in 10..256 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - 5]; dst2[i + 500] = src[i] } @@ -51,6 +58,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let some_var = 5; // Offset in variable for i in 10..LOOP_OFFSET { + //~^ ERROR: it looks like you're manually copying between slices dst[i + LOOP_OFFSET] = src[i - some_var]; } @@ -64,6 +72,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // make sure vectors are supported for i in 0..src_vec.len() { + //~^ ERROR: it looks like you're manually copying between slices dst_vec[i] = src_vec[i]; } @@ -93,20 +102,24 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let from = 1; for i in from..from + src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - from]; } for i in from..from + 3 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - from]; } #[allow(clippy::identity_op)] for i in 0..5 { + //~^ ERROR: it looks like you're manually copying between slices dst[i - 0] = src[i]; } #[allow(clippy::reversed_empty_ranges)] for i in 0..0 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i]; } @@ -130,6 +143,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { #[warn(clippy::needless_range_loop, clippy::manual_memcpy)] pub fn manual_clone(src: &[String], dst: &mut [String]) { for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i].clone(); } } diff --git a/tests/ui/manual_memcpy/without_loop_counters.stderr b/tests/ui/manual_memcpy/without_loop_counters.stderr index 1c6a7d5c04e0a..4f02c698a0d6b 100644 --- a/tests/ui/manual_memcpy/without_loop_counters.stderr +++ b/tests/ui/manual_memcpy/without_loop_counters.stderr @@ -2,6 +2,8 @@ error: it looks like you're manually copying between slices --> $DIR/without_loop_counters.rs:8:5 | LL | / for i in 0..src.len() { +LL | | +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[..]);` @@ -9,41 +11,46 @@ LL | | } = note: `-D clippy::manual-memcpy` implied by `-D warnings` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:13:5 + --> $DIR/without_loop_counters.rs:15:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i + 10] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[10..(src.len() + 10)].copy_from_slice(&src[..]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:18:5 + --> $DIR/without_loop_counters.rs:21:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i] = src[i + 10]; LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[10..(src.len() + 10)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:23:5 + --> $DIR/without_loop_counters.rs:27:5 | LL | / for i in 11..src.len() { +LL | | LL | | dst[i] = src[i - 10]; LL | | } | |_____^ help: try replacing the loop by: `dst[11..src.len()].copy_from_slice(&src[(11 - 10)..(src.len() - 10)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:28:5 + --> $DIR/without_loop_counters.rs:33:5 | LL | / for i in 0..dst.len() { +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[..dst.len()]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:41:5 + --> $DIR/without_loop_counters.rs:47:5 | LL | / for i in 10..256 { +LL | | LL | | dst[i] = src[i - 5]; LL | | dst2[i + 500] = src[i] LL | | } @@ -56,57 +63,64 @@ LL + dst2[(10 + 500)..(256 + 500)].copy_from_slice(&src[10..256]); | error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:53:5 + --> $DIR/without_loop_counters.rs:60:5 | LL | / for i in 10..LOOP_OFFSET { +LL | | LL | | dst[i + LOOP_OFFSET] = src[i - some_var]; LL | | } | |_____^ help: try replacing the loop by: `dst[(10 + LOOP_OFFSET)..(LOOP_OFFSET + LOOP_OFFSET)].copy_from_slice(&src[(10 - some_var)..(LOOP_OFFSET - some_var)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:66:5 + --> $DIR/without_loop_counters.rs:74:5 | LL | / for i in 0..src_vec.len() { +LL | | LL | | dst_vec[i] = src_vec[i]; LL | | } | |_____^ help: try replacing the loop by: `dst_vec[..src_vec.len()].copy_from_slice(&src_vec[..]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:95:5 + --> $DIR/without_loop_counters.rs:104:5 | LL | / for i in from..from + src.len() { +LL | | LL | | dst[i] = src[i - from]; LL | | } | |_____^ help: try replacing the loop by: `dst[from..(from + src.len())].copy_from_slice(&src[..(from + src.len() - from)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:99:5 + --> $DIR/without_loop_counters.rs:109:5 | LL | / for i in from..from + 3 { +LL | | LL | | dst[i] = src[i - from]; LL | | } | |_____^ help: try replacing the loop by: `dst[from..(from + 3)].copy_from_slice(&src[..(from + 3 - from)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:104:5 + --> $DIR/without_loop_counters.rs:115:5 | LL | / for i in 0..5 { +LL | | LL | | dst[i - 0] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..5].copy_from_slice(&src[..5]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:109:5 + --> $DIR/without_loop_counters.rs:121:5 | LL | / for i in 0..0 { +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..0].copy_from_slice(&src[..0]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:132:5 + --> $DIR/without_loop_counters.rs:145:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i] = src[i].clone(); LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..]);` diff --git a/tests/ui/manual_non_exhaustive_enum.rs b/tests/ui/manual_non_exhaustive_enum.rs index b5199065017a8..0e439dabfd651 100644 --- a/tests/ui/manual_non_exhaustive_enum.rs +++ b/tests/ui/manual_non_exhaustive_enum.rs @@ -3,6 +3,7 @@ #![allow(unused)] //@no-rustfix enum E { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern A, B, #[doc(hidden)] @@ -12,6 +13,7 @@ enum E { // user forgot to remove the marker #[non_exhaustive] enum Ep { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern A, B, #[doc(hidden)] diff --git a/tests/ui/manual_non_exhaustive_enum.stderr b/tests/ui/manual_non_exhaustive_enum.stderr index 087f766be70d2..ab068d4827e71 100644 --- a/tests/ui/manual_non_exhaustive_enum.stderr +++ b/tests/ui/manual_non_exhaustive_enum.stderr @@ -6,6 +6,7 @@ LL | enum E { | | | _help: add the attribute: `#[non_exhaustive] enum E` | | +LL | | LL | | A, LL | | B, LL | | #[doc(hidden)] @@ -14,16 +15,17 @@ LL | | } | |_^ | help: remove this variant - --> $DIR/manual_non_exhaustive_enum.rs:9:5 + --> $DIR/manual_non_exhaustive_enum.rs:10:5 | LL | _C, | ^^ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_enum.rs:14:1 + --> $DIR/manual_non_exhaustive_enum.rs:15:1 | LL | / enum Ep { +LL | | LL | | A, LL | | B, LL | | #[doc(hidden)] @@ -32,7 +34,7 @@ LL | | } | |_^ | help: remove this variant - --> $DIR/manual_non_exhaustive_enum.rs:18:5 + --> $DIR/manual_non_exhaustive_enum.rs:20:5 | LL | _C, | ^^ diff --git a/tests/ui/manual_non_exhaustive_struct.rs b/tests/ui/manual_non_exhaustive_struct.rs index 9935427f50100..4b2803ccc4a79 100644 --- a/tests/ui/manual_non_exhaustive_struct.rs +++ b/tests/ui/manual_non_exhaustive_struct.rs @@ -3,6 +3,7 @@ //@no-rustfix mod structs { struct S { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern pub a: i32, pub b: i32, _c: (), @@ -11,6 +12,7 @@ mod structs { // user forgot to remove the private field #[non_exhaustive] struct Sp { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern pub a: i32, pub b: i32, _c: (), @@ -52,10 +54,12 @@ mod structs { mod tuple_structs { struct T(pub i32, pub i32, ()); + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern // user forgot to remove the private field #[non_exhaustive] struct Tp(pub i32, pub i32, ()); + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern // some other fields are private, should be ignored struct PrivateFields(pub i32, i32, ()); diff --git a/tests/ui/manual_non_exhaustive_struct.stderr b/tests/ui/manual_non_exhaustive_struct.stderr index d0bed8e11211a..c062af6356c46 100644 --- a/tests/ui/manual_non_exhaustive_struct.stderr +++ b/tests/ui/manual_non_exhaustive_struct.stderr @@ -6,6 +6,7 @@ LL | struct S { | | | _____help: add the attribute: `#[non_exhaustive] struct S` | | +LL | | LL | | pub a: i32, LL | | pub b: i32, LL | | _c: (), @@ -13,16 +14,17 @@ LL | | } | |_____^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:8:9 + --> $DIR/manual_non_exhaustive_struct.rs:9:9 | LL | _c: (), | ^^^^^^ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:13:5 + --> $DIR/manual_non_exhaustive_struct.rs:14:5 | LL | / struct Sp { +LL | | LL | | pub a: i32, LL | | pub b: i32, LL | | _c: (), @@ -30,13 +32,13 @@ LL | | } | |_____^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:16:9 + --> $DIR/manual_non_exhaustive_struct.rs:18:9 | LL | _c: (), | ^^^^^^ error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:54:5 + --> $DIR/manual_non_exhaustive_struct.rs:56:5 | LL | struct T(pub i32, pub i32, ()); | --------^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,19 +46,19 @@ LL | struct T(pub i32, pub i32, ()); | help: add the attribute: `#[non_exhaustive] struct T` | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:54:32 + --> $DIR/manual_non_exhaustive_struct.rs:56:32 | LL | struct T(pub i32, pub i32, ()); | ^^ error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:58:5 + --> $DIR/manual_non_exhaustive_struct.rs:61:5 | LL | struct Tp(pub i32, pub i32, ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:58:33 + --> $DIR/manual_non_exhaustive_struct.rs:61:33 | LL | struct Tp(pub i32, pub i32, ()); | ^^ diff --git a/tests/ui/manual_strip.rs b/tests/ui/manual_strip.rs index 99c83354419d7..8bd0300e6bcce 100644 --- a/tests/ui/manual_strip.rs +++ b/tests/ui/manual_strip.rs @@ -5,6 +5,7 @@ fn main() { if s.starts_with("ab") { str::to_string(&s["ab".len()..]); + //~^ ERROR: stripping a prefix manually s["ab".len()..].to_string(); str::to_string(&s[2..]); @@ -13,6 +14,7 @@ fn main() { if s.ends_with("bc") { str::to_string(&s[..s.len() - "bc".len()]); + //~^ ERROR: stripping a suffix manually s[..s.len() - "bc".len()].to_string(); str::to_string(&s[..s.len() - 2]); @@ -22,6 +24,7 @@ fn main() { // Character patterns if s.starts_with('a') { str::to_string(&s[1..]); + //~^ ERROR: stripping a prefix manually s[1..].to_string(); } @@ -29,12 +32,14 @@ fn main() { let prefix = "ab"; if s.starts_with(prefix) { str::to_string(&s[prefix.len()..]); + //~^ ERROR: stripping a prefix manually } // Constant prefix const PREFIX: &str = "ab"; if s.starts_with(PREFIX) { str::to_string(&s[PREFIX.len()..]); + //~^ ERROR: stripping a prefix manually str::to_string(&s[2..]); } @@ -42,12 +47,14 @@ fn main() { const TARGET: &str = "abc"; if TARGET.starts_with(prefix) { str::to_string(&TARGET[prefix.len()..]); + //~^ ERROR: stripping a prefix manually } // String target - not mutated. let s1: String = "abc".into(); if s1.starts_with("ab") { s1[2..].to_uppercase(); + //~^ ERROR: stripping a prefix manually } // String target - mutated. (Don't lint.) @@ -78,5 +85,6 @@ fn msrv_1_45() { let s = "abc"; if s.starts_with('a') { s[1..].to_string(); + //~^ ERROR: stripping a prefix manually } } diff --git a/tests/ui/manual_strip.stderr b/tests/ui/manual_strip.stderr index f592e898fc928..e7be2b4b9cec2 100644 --- a/tests/ui/manual_strip.stderr +++ b/tests/ui/manual_strip.stderr @@ -14,6 +14,7 @@ help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix("ab") { LL ~ str::to_string(); +LL | LL ~ .to_string(); LL | LL ~ str::to_string(); @@ -21,13 +22,13 @@ LL ~ .to_string(); | error: stripping a suffix manually - --> $DIR/manual_strip.rs:15:24 + --> $DIR/manual_strip.rs:16:24 | LL | str::to_string(&s[..s.len() - "bc".len()]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the suffix was tested here - --> $DIR/manual_strip.rs:14:5 + --> $DIR/manual_strip.rs:15:5 | LL | if s.ends_with("bc") { | ^^^^^^^^^^^^^^^^^^^^^ @@ -35,6 +36,7 @@ help: try using the `strip_suffix` method | LL ~ if let Some() = s.strip_suffix("bc") { LL ~ str::to_string(); +LL | LL ~ .to_string(); LL | LL ~ str::to_string(); @@ -42,13 +44,13 @@ LL ~ .to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:24:24 + --> $DIR/manual_strip.rs:26:24 | LL | str::to_string(&s[1..]); | ^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:23:5 + --> $DIR/manual_strip.rs:25:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -56,17 +58,18 @@ help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix('a') { LL ~ str::to_string(); +LL | LL ~ .to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:31:24 + --> $DIR/manual_strip.rs:34:24 | LL | str::to_string(&s[prefix.len()..]); | ^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:30:5 + --> $DIR/manual_strip.rs:33:5 | LL | if s.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,13 +80,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:37:24 + --> $DIR/manual_strip.rs:41:24 | LL | str::to_string(&s[PREFIX.len()..]); | ^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:36:5 + --> $DIR/manual_strip.rs:40:5 | LL | if s.starts_with(PREFIX) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,17 +94,18 @@ help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix(PREFIX) { LL ~ str::to_string(); +LL | LL ~ str::to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:44:24 + --> $DIR/manual_strip.rs:49:24 | LL | str::to_string(&TARGET[prefix.len()..]); | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:43:5 + --> $DIR/manual_strip.rs:48:5 | LL | if TARGET.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,13 +116,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:50:9 + --> $DIR/manual_strip.rs:56:9 | LL | s1[2..].to_uppercase(); | ^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:49:5 + --> $DIR/manual_strip.rs:55:5 | LL | if s1.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -129,13 +133,13 @@ LL ~ .to_uppercase(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:80:9 + --> $DIR/manual_strip.rs:87:9 | LL | s[1..].to_string(); | ^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:79:5 + --> $DIR/manual_strip.rs:86:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/many_single_char_names.rs b/tests/ui/many_single_char_names.rs index 88fcce66873aa..68578340d90e1 100644 --- a/tests/ui/many_single_char_names.rs +++ b/tests/ui/many_single_char_names.rs @@ -3,6 +3,10 @@ fn bla() { let a: i32; + //~^ ERROR: 5 bindings with single-character names in scope + //~| NOTE: `-D clippy::many-single-char-names` implied by `-D warnings` + //~| ERROR: 6 bindings with single-character names in scope + //~| ERROR: 5 bindings with single-character names in scope let (b, c, d): (i32, i64, i16); { { @@ -28,9 +32,11 @@ fn bla() { } fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} +//~^ ERROR: 8 bindings with single-character names in scope fn bindings2() { let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); + //~^ ERROR: 8 bindings with single-character names in scope } fn shadowing() { diff --git a/tests/ui/many_single_char_names.stderr b/tests/ui/many_single_char_names.stderr index ade0f84bc5065..4f5a69a9b6092 100644 --- a/tests/ui/many_single_char_names.stderr +++ b/tests/ui/many_single_char_names.stderr @@ -3,6 +3,7 @@ error: 5 bindings with single-character names in scope | LL | let a: i32; | ^ +... LL | let (b, c, d): (i32, i64, i16); | ^ ^ ^ ... @@ -16,6 +17,7 @@ error: 6 bindings with single-character names in scope | LL | let a: i32; | ^ +... LL | let (b, c, d): (i32, i64, i16); | ^ ^ ^ ... @@ -29,6 +31,7 @@ error: 5 bindings with single-character names in scope | LL | let a: i32; | ^ +... LL | let (b, c, d): (i32, i64, i16); | ^ ^ ^ ... @@ -36,13 +39,13 @@ LL | e => panic!(), | ^ error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:30:13 + --> $DIR/many_single_char_names.rs:34:13 | LL | fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} | ^ ^ ^ ^ ^ ^ ^ ^ error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:33:10 + --> $DIR/many_single_char_names.rs:38:10 | LL | let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); | ^ ^ ^ ^ ^ ^ ^ ^ diff --git a/tests/ui/map_err.rs b/tests/ui/map_err.rs index bb35ab1a14efa..07c51784407a6 100644 --- a/tests/ui/map_err.rs +++ b/tests/ui/map_err.rs @@ -20,6 +20,7 @@ fn main() -> Result<(), Errors> { let x = u32::try_from(-123_i32); println!("{:?}", x.map_err(|_| Errors::Ignored)); + //~^ ERROR: `map_err(|_|...` wildcard pattern discards the original error // Should not warn you because you explicitly ignore the parameter // using a named wildcard value diff --git a/tests/ui/map_flatten.rs b/tests/ui/map_flatten.rs index fca4fe0bcb780..76916d4659197 100644 --- a/tests/ui/map_flatten.rs +++ b/tests/ui/map_flatten.rs @@ -6,6 +6,8 @@ fn long_span() { let _: Option = Some(1) .map(|x| { + //~^ ERROR: called `map(..).flatten()` on `Option` + //~| NOTE: `-D clippy::map-flatten` implied by `-D warnings` if x <= 5 { Some(x) } else { @@ -16,6 +18,7 @@ fn long_span() { let _: Result = Ok(1) .map(|x| { + //~^ ERROR: called `map(..).flatten()` on `Result` if x == 1 { Ok(x) } else { @@ -28,6 +31,7 @@ fn long_span() { fn do_something() { } let _: Result = result .map(|res| { + //~^ ERROR: called `map(..).flatten()` on `Result` if res > 0 { do_something(); Ok(res) @@ -40,6 +44,7 @@ fn long_span() { let _: Vec<_> = vec![5_i8; 6] .into_iter() .map(|some_value| { + //~^ ERROR: called `map(..).flatten()` on `Iterator` if some_value > 3 { Some(some_value) } else { diff --git a/tests/ui/map_flatten.stderr b/tests/ui/map_flatten.stderr index 4b2630d685847..88fdd04c02367 100644 --- a/tests/ui/map_flatten.stderr +++ b/tests/ui/map_flatten.stderr @@ -3,9 +3,9 @@ error: called `map(..).flatten()` on `Option` | LL | .map(|x| { | __________^ +LL | | +LL | | LL | | if x <= 5 { -LL | | Some(x) -LL | | } else { ... | LL | | }) LL | | .flatten(); @@ -15,6 +15,8 @@ LL | | .flatten(); help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { +LL + +LL + LL + if x <= 5 { LL + Some(x) LL + } else { @@ -24,13 +26,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Result` - --> $DIR/map_flatten.rs:18:10 + --> $DIR/map_flatten.rs:20:10 | LL | .map(|x| { | __________^ +LL | | LL | | if x == 1 { LL | | Ok(x) -LL | | } else { ... | LL | | }) LL | | .flatten(); @@ -39,6 +41,7 @@ LL | | .flatten(); help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { +LL + LL + if x == 1 { LL + Ok(x) LL + } else { @@ -48,13 +51,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Result` - --> $DIR/map_flatten.rs:30:10 + --> $DIR/map_flatten.rs:33:10 | LL | .map(|res| { | __________^ +LL | | LL | | if res > 0 { LL | | do_something(); -LL | | Ok(res) ... | LL | | }) LL | | .flatten(); @@ -63,6 +66,7 @@ LL | | .flatten(); help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|res| { +LL + LL + if res > 0 { LL + do_something(); LL + Ok(res) @@ -73,13 +77,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten.rs:42:10 + --> $DIR/map_flatten.rs:46:10 | LL | .map(|some_value| { | __________^ +LL | | LL | | if some_value > 3 { LL | | Some(some_value) -LL | | } else { ... | LL | | }) LL | | .flatten() @@ -88,6 +92,7 @@ LL | | .flatten() help: try replacing `map` with `filter_map` and remove the `.flatten()` | LL ~ .filter_map(|some_value| { +LL + LL + if some_value > 3 { LL + Some(some_value) LL + } else { diff --git a/tests/ui/match_bool.rs b/tests/ui/match_bool.rs index d7a379f9ac320..f84af393e47fa 100644 --- a/tests/ui/match_bool.rs +++ b/tests/ui/match_bool.rs @@ -5,17 +5,20 @@ fn match_bool() { let test: bool = true; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression true => 0, false => 42, }; let option = 1; match option == 1 { + //~^ ERROR: you seem to be trying to match on a boolean expression true => 1, false => 0, }; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression true => (), false => { println!("Noooo!"); @@ -23,6 +26,7 @@ fn match_bool() { }; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression false => { println!("Noooo!"); }, @@ -30,6 +34,11 @@ fn match_bool() { }; match test && test { + //~^ ERROR: this boolean expression can be simplified + //~| NOTE: `-D clippy::nonminimal-bool` implied by `-D warnings` + //~| ERROR: you seem to be trying to match on a boolean expression + //~| ERROR: equal expressions as operands to `&&` + //~| NOTE: `#[deny(clippy::eq_op)]` on by default false => { println!("Noooo!"); }, @@ -37,6 +46,7 @@ fn match_bool() { }; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression false => { println!("Noooo!"); }, diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index 32311f73db345..351ebfc08cdbd 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> $DIR/match_bool.rs:32:11 + --> $DIR/match_bool.rs:36:11 | LL | match test && test { | ^^^^^^^^^^^^ help: try: `test` @@ -10,6 +10,7 @@ error: you seem to be trying to match on a boolean expression --> $DIR/match_bool.rs:7:5 | LL | / match test { +LL | | LL | | true => 0, LL | | false => 42, LL | | }; @@ -22,18 +23,20 @@ LL | #![deny(clippy::match_bool)] | ^^^^^^^^^^^^^^^^^^ error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:13:5 + --> $DIR/match_bool.rs:14:5 | LL | / match option == 1 { +LL | | LL | | true => 1, LL | | false => 0, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if option == 1 { 1 } else { 0 }` error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:18:5 + --> $DIR/match_bool.rs:20:5 | LL | / match test { +LL | | LL | | true => (), LL | | false => { LL | | println!("Noooo!"); @@ -49,9 +52,10 @@ LL ~ }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:25:5 + --> $DIR/match_bool.rs:28:5 | LL | / match test { +LL | | LL | | false => { LL | | println!("Noooo!"); LL | | }, @@ -67,12 +71,13 @@ LL ~ }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:32:5 + --> $DIR/match_bool.rs:36:5 | LL | / match test && test { -LL | | false => { -LL | | println!("Noooo!"); -LL | | }, +LL | | +LL | | +LL | | +... | LL | | _ => (), LL | | }; | |_____^ @@ -85,7 +90,7 @@ LL ~ }; | error: equal expressions as operands to `&&` - --> $DIR/match_bool.rs:32:11 + --> $DIR/match_bool.rs:36:11 | LL | match test && test { | ^^^^^^^^^^^^ @@ -93,12 +98,12 @@ LL | match test && test { = note: `#[deny(clippy::eq_op)]` on by default error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:39:5 + --> $DIR/match_bool.rs:48:5 | LL | / match test { +LL | | LL | | false => { LL | | println!("Noooo!"); -LL | | }, ... | LL | | }, LL | | }; diff --git a/tests/ui/match_on_vec_items.rs b/tests/ui/match_on_vec_items.rs index 45a74f5c5ddea..f7b8500faa4a0 100644 --- a/tests/ui/match_on_vec_items.rs +++ b/tests/ui/match_on_vec_items.rs @@ -8,6 +8,8 @@ fn match_with_wildcard() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic + //~| NOTE: `-D clippy::match-on-vec-items` implied by `-D warnings` 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -15,6 +17,7 @@ fn match_with_wildcard() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => {}, @@ -28,6 +31,7 @@ fn match_without_wildcard() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic 0 => println!("0"), 1 => println!("1"), num => {}, @@ -35,6 +39,7 @@ fn match_without_wildcard() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), [ref sub @ ..] => {}, @@ -48,6 +53,7 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic 0 => println!("0"), 1 => println!("1"), _ => println!("Hello, World!"), @@ -55,6 +61,7 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => println!("Hello, World!"), @@ -68,6 +75,7 @@ fn match_vec_ref() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -75,6 +83,7 @@ fn match_vec_ref() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => {}, diff --git a/tests/ui/match_on_vec_items.stderr b/tests/ui/match_on_vec_items.stderr index fc4a3ce19463f..71038aaad49fb 100644 --- a/tests/ui/match_on_vec_items.stderr +++ b/tests/ui/match_on_vec_items.stderr @@ -7,43 +7,43 @@ LL | match arr[idx] { = note: `-D clippy::match-on-vec-items` implied by `-D warnings` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:17:11 + --> $DIR/match_on_vec_items.rs:19:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:30:11 + --> $DIR/match_on_vec_items.rs:33:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:37:11 + --> $DIR/match_on_vec_items.rs:41:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:50:11 + --> $DIR/match_on_vec_items.rs:55:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:57:11 + --> $DIR/match_on_vec_items.rs:63:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:70:11 + --> $DIR/match_on_vec_items.rs:77:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:77:11 + --> $DIR/match_on_vec_items.rs:85:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` diff --git a/tests/ui/match_overlapping_arm.rs b/tests/ui/match_overlapping_arm.rs index b78c1fd06d44d..c2c2f28392d77 100644 --- a/tests/ui/match_overlapping_arm.rs +++ b/tests/ui/match_overlapping_arm.rs @@ -10,12 +10,14 @@ fn overlapping() { match 42 { 0..=10 => println!("0..=10"), + //~^ ERROR: some ranges overlap 0..=11 => println!("0..=11"), _ => (), } match 42 { 0..=5 => println!("0..=5"), + //~^ ERROR: some ranges overlap 6..=7 => println!("6..=7"), FOO..=11 => println!("FOO..=11"), _ => (), @@ -53,6 +55,7 @@ fn overlapping() { match 42 { 0..11 => println!("0..11"), + //~^ ERROR: some ranges overlap 0..=11 => println!("0..=11"), _ => (), } @@ -78,11 +81,13 @@ fn overlapping() { match 42 { 5..14 => println!("5..14"), 0..=10 => println!("0..=10"), + //~^ ERROR: some ranges overlap _ => (), } match 42 { 0..7 => println!("0..7"), + //~^ ERROR: some ranges overlap 0..=10 => println!("0..=10"), _ => (), } @@ -95,6 +100,7 @@ fn overlapping() { match 42 { ..=23 => println!("..=23"), + //~^ ERROR: some ranges overlap ..26 => println!("..26"), _ => (), } @@ -104,6 +110,7 @@ fn overlapping() { 5..=10 => (), 0..=20 => (), 21..=30 => (), + //~^ ERROR: some ranges overlap 21..=40 => (), _ => (), } @@ -118,6 +125,7 @@ fn overlapping() { // Only warn about the first if there are multiple overlaps match 42u128 { 0..=0x0000_0000_0000_00ff => (), + //~^ ERROR: some ranges overlap 0..=0x0000_0000_0000_ffff => (), 0..=0x0000_0000_ffff_ffff => (), 0..=0xffff_ffff_ffff_ffff => (), diff --git a/tests/ui/match_overlapping_arm.stderr b/tests/ui/match_overlapping_arm.stderr index b98d4799e42ca..ceec40e8def0f 100644 --- a/tests/ui/match_overlapping_arm.stderr +++ b/tests/ui/match_overlapping_arm.stderr @@ -5,92 +5,92 @@ LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:13:9 + --> $DIR/match_overlapping_arm.rs:14:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ = note: `-D clippy::match-overlapping-arm` implied by `-D warnings` error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:18:9 + --> $DIR/match_overlapping_arm.rs:19:9 | LL | 0..=5 => println!("0..=5"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:20:9 + --> $DIR/match_overlapping_arm.rs:22:9 | LL | FOO..=11 => println!("FOO..=11"), | ^^^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:55:9 + --> $DIR/match_overlapping_arm.rs:57:9 | LL | 0..11 => println!("0..11"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:56:9 + --> $DIR/match_overlapping_arm.rs:59:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:80:9 + --> $DIR/match_overlapping_arm.rs:83:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:79:9 + --> $DIR/match_overlapping_arm.rs:82:9 | LL | 5..14 => println!("5..14"), | ^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:85:9 + --> $DIR/match_overlapping_arm.rs:89:9 | LL | 0..7 => println!("0..7"), | ^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:86:9 + --> $DIR/match_overlapping_arm.rs:91:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:97:9 + --> $DIR/match_overlapping_arm.rs:102:9 | LL | ..=23 => println!("..=23"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:98:9 + --> $DIR/match_overlapping_arm.rs:104:9 | LL | ..26 => println!("..26"), | ^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:106:9 + --> $DIR/match_overlapping_arm.rs:112:9 | LL | 21..=30 => (), | ^^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:107:9 + --> $DIR/match_overlapping_arm.rs:114:9 | LL | 21..=40 => (), | ^^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:120:9 + --> $DIR/match_overlapping_arm.rs:127:9 | LL | 0..=0x0000_0000_0000_00ff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:121:9 + --> $DIR/match_overlapping_arm.rs:129:9 | LL | 0..=0x0000_0000_0000_ffff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match_same_arms_non_exhaustive.rs b/tests/ui/match_same_arms_non_exhaustive.rs index 096858f3a67d5..1ee048bf7f6c3 100644 --- a/tests/ui/match_same_arms_non_exhaustive.rs +++ b/tests/ui/match_same_arms_non_exhaustive.rs @@ -39,6 +39,7 @@ pub fn g(x: Ordering) { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => panic!(), + //~^ ERROR: this match arm has an identical body to the `_` wildcard arm _ => panic!(), } } @@ -52,6 +53,7 @@ mod g { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => panic!(), + //~^ ERROR: this match arm has an identical body to the `_` wildcard arm _ => panic!(), } } diff --git a/tests/ui/match_same_arms_non_exhaustive.stderr b/tests/ui/match_same_arms_non_exhaustive.stderr index 088f7d5c06242..9ee8f14ad90e2 100644 --- a/tests/ui/match_same_arms_non_exhaustive.stderr +++ b/tests/ui/match_same_arms_non_exhaustive.stderr @@ -6,21 +6,21 @@ LL | Ordering::AcqRel | Ordering::SeqCst => panic!(), | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms_non_exhaustive.rs:42:9 + --> $DIR/match_same_arms_non_exhaustive.rs:43:9 | LL | _ => panic!(), | ^^^^^^^^^^^^^ = note: `-D clippy::match-same-arms` implied by `-D warnings` error: this match arm has an identical body to the `_` wildcard arm - --> $DIR/match_same_arms_non_exhaustive.rs:54:13 + --> $DIR/match_same_arms_non_exhaustive.rs:55:13 | LL | Ordering::AcqRel | Ordering::SeqCst => panic!(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms_non_exhaustive.rs:55:13 + --> $DIR/match_same_arms_non_exhaustive.rs:57:13 | LL | _ => panic!(), | ^^^^^^^^^^^^^ diff --git a/tests/ui/match_wild_err_arm.rs b/tests/ui/match_wild_err_arm.rs index 5a552e4ae51a5..7bdd75d7f4639 100644 --- a/tests/ui/match_wild_err_arm.rs +++ b/tests/ui/match_wild_err_arm.rs @@ -22,18 +22,24 @@ fn match_wild_err_arm() { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => panic!("err"), + //~^ ERROR: `Err(_)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => panic!(), + //~^ ERROR: `Err(_)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => { + //~^ ERROR: `Err(_)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms panic!(); }, } @@ -42,6 +48,8 @@ fn match_wild_err_arm() { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_e) => panic!(), + //~^ ERROR: `Err(_e)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms } // Allowed when used in `panic!`. diff --git a/tests/ui/match_wild_err_arm.stderr b/tests/ui/match_wild_err_arm.stderr index a9f54feacdb58..696ba7303a96c 100644 --- a/tests/ui/match_wild_err_arm.stderr +++ b/tests/ui/match_wild_err_arm.stderr @@ -8,7 +8,7 @@ LL | Err(_) => panic!("err"), = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` error: `Err(_)` matches all errors - --> $DIR/match_wild_err_arm.rs:30:9 + --> $DIR/match_wild_err_arm.rs:32:9 | LL | Err(_) => panic!(), | ^^^^^^ @@ -16,7 +16,7 @@ LL | Err(_) => panic!(), = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable error: `Err(_)` matches all errors - --> $DIR/match_wild_err_arm.rs:36:9 + --> $DIR/match_wild_err_arm.rs:40:9 | LL | Err(_) => { | ^^^^^^ @@ -24,7 +24,7 @@ LL | Err(_) => { = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable error: `Err(_e)` matches all errors - --> $DIR/match_wild_err_arm.rs:44:9 + --> $DIR/match_wild_err_arm.rs:50:9 | LL | Err(_e) => panic!(), | ^^^^^^^ diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs index b6c8d9e53d80e..1f508b3bca289 100644 --- a/tests/ui/mem_forget.rs +++ b/tests/ui/mem_forget.rs @@ -12,15 +12,23 @@ fn main() { let six: Arc = Arc::new(6); memstuff::forget(six); + //~^ ERROR: usage of `mem::forget` on `Drop` type + //~| NOTE: argument has type `std::sync::Arc` let seven: Rc = Rc::new(7); std::mem::forget(seven); + //~^ ERROR: usage of `mem::forget` on `Drop` type + //~| NOTE: argument has type `std::rc::Rc` let eight: Vec = vec![8]; forgetSomething(eight); + //~^ ERROR: usage of `mem::forget` on `Drop` type + //~| NOTE: argument has type `std::vec::Vec` let string = String::new(); std::mem::forget(string); + //~^ ERROR: usage of `mem::forget` on type with `Drop` fields + //~| NOTE: argument has type `std::string::String` std::mem::forget(7); } diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr index 8004b2aa8db7a..dd2ea7518559f 100644 --- a/tests/ui/mem_forget.stderr +++ b/tests/ui/mem_forget.stderr @@ -8,7 +8,7 @@ LL | memstuff::forget(six); = note: `-D clippy::mem-forget` implied by `-D warnings` error: usage of `mem::forget` on `Drop` type - --> $DIR/mem_forget.rs:17:5 + --> $DIR/mem_forget.rs:19:5 | LL | std::mem::forget(seven); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | std::mem::forget(seven); = note: argument has type `std::rc::Rc` error: usage of `mem::forget` on `Drop` type - --> $DIR/mem_forget.rs:20:5 + --> $DIR/mem_forget.rs:24:5 | LL | forgetSomething(eight); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | forgetSomething(eight); = note: argument has type `std::vec::Vec` error: usage of `mem::forget` on type with `Drop` fields - --> $DIR/mem_forget.rs:23:5 + --> $DIR/mem_forget.rs:29:5 | LL | std::mem::forget(string); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/methods_unfixable.rs b/tests/ui/methods_unfixable.rs index e12b8136d2b9c..ee59983a7573e 100644 --- a/tests/ui/methods_unfixable.rs +++ b/tests/ui/methods_unfixable.rs @@ -7,4 +7,5 @@ fn main() { pub fn issue10029() { let iter = (0..10); let _ = iter.filter(|_| true).next(); + //~^ ERROR: called `filter(..).next()` on an `Iterator`. This is more succinctly expre } diff --git a/tests/ui/min_max.rs b/tests/ui/min_max.rs index 1215a02286c28..cf64f85f9bb5f 100644 --- a/tests/ui/min_max.rs +++ b/tests/ui/min_max.rs @@ -20,11 +20,17 @@ impl NotOrd { fn main() { let x = 2usize; min(1, max(3, x)); + //~^ ERROR: this `min`/`max` combination leads to constant result + //~| NOTE: `-D clippy::min-max` implied by `-D warnings` min(max(3, x), 1); + //~^ ERROR: this `min`/`max` combination leads to constant result max(min(x, 1), 3); + //~^ ERROR: this `min`/`max` combination leads to constant result max(3, min(x, 1)); + //~^ ERROR: this `min`/`max` combination leads to constant result my_max(3, my_min(x, 1)); + //~^ ERROR: this `min`/`max` combination leads to constant result min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x @@ -35,24 +41,32 @@ fn main() { let s = "Hello"; min("Apple", max("Zoo", s)); + //~^ ERROR: this `min`/`max` combination leads to constant result max(min(s, "Apple"), "Zoo"); + //~^ ERROR: this `min`/`max` combination leads to constant result max("Apple", min(s, "Zoo")); // ok let f = 3f32; x.min(1).max(3); + //~^ ERROR: this `min`/`max` combination leads to constant result x.max(3).min(1); + //~^ ERROR: this `min`/`max` combination leads to constant result f.max(3f32).min(1f32); + //~^ ERROR: this `min`/`max` combination leads to constant result x.max(1).min(3); // ok x.min(3).max(1); // ok f.min(3f32).max(1f32); // ok max(x.min(1), 3); + //~^ ERROR: this `min`/`max` combination leads to constant result min(x.max(1), 3); // ok s.max("Zoo").min("Apple"); + //~^ ERROR: this `min`/`max` combination leads to constant result s.min("Apple").max("Zoo"); + //~^ ERROR: this `min`/`max` combination leads to constant result s.min("Zoo").max("Apple"); // ok diff --git a/tests/ui/min_max.stderr b/tests/ui/min_max.stderr index 402b094f4f77b..128394e627ca9 100644 --- a/tests/ui/min_max.stderr +++ b/tests/ui/min_max.stderr @@ -7,73 +7,73 @@ LL | min(1, max(3, x)); = note: `-D clippy::min-max` implied by `-D warnings` error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:23:5 + --> $DIR/min_max.rs:25:5 | LL | min(max(3, x), 1); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:24:5 + --> $DIR/min_max.rs:27:5 | LL | max(min(x, 1), 3); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:25:5 + --> $DIR/min_max.rs:29:5 | LL | max(3, min(x, 1)); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:27:5 + --> $DIR/min_max.rs:32:5 | LL | my_max(3, my_min(x, 1)); | ^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:37:5 + --> $DIR/min_max.rs:43:5 | LL | min("Apple", max("Zoo", s)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:38:5 + --> $DIR/min_max.rs:45:5 | LL | max(min(s, "Apple"), "Zoo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:43:5 + --> $DIR/min_max.rs:51:5 | LL | x.min(1).max(3); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:44:5 + --> $DIR/min_max.rs:53:5 | LL | x.max(3).min(1); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:45:5 + --> $DIR/min_max.rs:55:5 | LL | f.max(3f32).min(1f32); | ^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:51:5 + --> $DIR/min_max.rs:62:5 | LL | max(x.min(1), 3); | ^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:54:5 + --> $DIR/min_max.rs:66:5 | LL | s.max("Zoo").min("Apple"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:55:5 + --> $DIR/min_max.rs:68:5 | LL | s.min("Apple").max("Zoo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/min_rust_version_attr.rs b/tests/ui/min_rust_version_attr.rs index 955e7eb727634..5fe3306d6fc83 100644 --- a/tests/ui/min_rust_version_attr.rs +++ b/tests/ui/min_rust_version_attr.rs @@ -11,11 +11,13 @@ fn just_under_msrv() { #[clippy::msrv = "1.43.0"] fn meets_msrv() { let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } #[clippy::msrv = "1.44.0"] fn just_above_msrv() { let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } #[clippy::msrv = "1.42"] @@ -26,6 +28,7 @@ fn no_patch_under() { #[clippy::msrv = "1.43"] fn no_patch_meets() { let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } fn inner_attr_under() { @@ -36,6 +39,7 @@ fn inner_attr_under() { fn inner_attr_meets() { #![clippy::msrv = "1.43"] let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } // https://github.com/rust-lang/rust-clippy/issues/6920 @@ -46,6 +50,7 @@ fn scoping() { // Should warn let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found mod a { #![clippy::msrv = "1.42.0"] @@ -53,6 +58,7 @@ fn scoping() { fn should_warn() { #![clippy::msrv = "1.43.0"] let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } fn should_not_warn() { diff --git a/tests/ui/min_rust_version_attr.stderr b/tests/ui/min_rust_version_attr.stderr index 7e2135584efde..3c8555c62446c 100644 --- a/tests/ui/min_rust_version_attr.stderr +++ b/tests/ui/min_rust_version_attr.stderr @@ -8,7 +8,7 @@ LL | let log2_10 = 3.321928094887362; = note: `#[deny(clippy::approx_constant)]` on by default error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:18:19 + --> $DIR/min_rust_version_attr.rs:19:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:28:19 + --> $DIR/min_rust_version_attr.rs:30:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:38:19 + --> $DIR/min_rust_version_attr.rs:41:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:48:19 + --> $DIR/min_rust_version_attr.rs:52:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:55:27 + --> $DIR/min_rust_version_attr.rs:60:27 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/min_rust_version_invalid_attr.rs b/tests/ui/min_rust_version_invalid_attr.rs index 02892f329af67..c8a0d6641675a 100644 --- a/tests/ui/min_rust_version_invalid_attr.rs +++ b/tests/ui/min_rust_version_invalid_attr.rs @@ -1,18 +1,23 @@ #![feature(custom_inner_attributes)] #![clippy::msrv = "invalid.version"] +//~^ ERROR: `invalid.version` is not a valid Rust version fn main() {} #[clippy::msrv = "invalid.version"] +//~^ ERROR: `invalid.version` is not a valid Rust version fn outer_attr() {} mod multiple { #![clippy::msrv = "1.40"] #![clippy::msrv = "=1.35.0"] + //~^ ERROR: `msrv` is defined multiple times #![clippy::msrv = "1.10.1"] + //~^ ERROR: `msrv` is defined multiple times mod foo { #![clippy::msrv = "1"] #![clippy::msrv = "1.0.0"] + //~^ ERROR: `msrv` is defined multiple times } } diff --git a/tests/ui/min_rust_version_invalid_attr.stderr b/tests/ui/min_rust_version_invalid_attr.stderr index 675b780315251..8d4071e258ebc 100644 --- a/tests/ui/min_rust_version_invalid_attr.stderr +++ b/tests/ui/min_rust_version_invalid_attr.stderr @@ -5,43 +5,43 @@ LL | #![clippy::msrv = "invalid.version"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `invalid.version` is not a valid Rust version - --> $DIR/min_rust_version_invalid_attr.rs:6:1 + --> $DIR/min_rust_version_invalid_attr.rs:7:1 | LL | #[clippy::msrv = "invalid.version"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `msrv` is defined multiple times - --> $DIR/min_rust_version_invalid_attr.rs:11:5 + --> $DIR/min_rust_version_invalid_attr.rs:13:5 | LL | #![clippy::msrv = "=1.35.0"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first definition found here - --> $DIR/min_rust_version_invalid_attr.rs:10:5 + --> $DIR/min_rust_version_invalid_attr.rs:12:5 | LL | #![clippy::msrv = "1.40"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `msrv` is defined multiple times - --> $DIR/min_rust_version_invalid_attr.rs:12:5 + --> $DIR/min_rust_version_invalid_attr.rs:15:5 | LL | #![clippy::msrv = "1.10.1"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first definition found here - --> $DIR/min_rust_version_invalid_attr.rs:10:5 + --> $DIR/min_rust_version_invalid_attr.rs:12:5 | LL | #![clippy::msrv = "1.40"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `msrv` is defined multiple times - --> $DIR/min_rust_version_invalid_attr.rs:16:9 + --> $DIR/min_rust_version_invalid_attr.rs:20:9 | LL | #![clippy::msrv = "1.0.0"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first definition found here - --> $DIR/min_rust_version_invalid_attr.rs:15:9 + --> $DIR/min_rust_version_invalid_attr.rs:19:9 | LL | #![clippy::msrv = "1"] | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mismatching_type_param_order.rs b/tests/ui/mismatching_type_param_order.rs index 40c1fcae1fd3f..af2882e41fb10 100644 --- a/tests/ui/mismatching_type_param_order.rs +++ b/tests/ui/mismatching_type_param_order.rs @@ -9,9 +9,12 @@ fn main() { // lint on both params impl Foo {} + //~^ ERROR: `Foo` has a similarly named generic type parameter `B` in its declaration, + //~| ERROR: `Foo` has a similarly named generic type parameter `A` in its declaration, // lint on the 2nd param impl Foo {} + //~^ ERROR: `Foo` has a similarly named generic type parameter `A` in its declaration, // should not lint impl Foo {} @@ -23,6 +26,8 @@ fn main() { // should not lint on lifetimes impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} + //~^ ERROR: `FooLifetime` has a similarly named generic type parameter `B` in its decl + //~| ERROR: `FooLifetime` has a similarly named generic type parameter `A` in its decl struct Bar { x: i32, @@ -39,6 +44,9 @@ fn main() { } impl FooEnum {} + //~^ ERROR: `FooEnum` has a similarly named generic type parameter `C` in its declarat + //~| ERROR: `FooEnum` has a similarly named generic type parameter `A` in its declarat + //~| ERROR: `FooEnum` has a similarly named generic type parameter `B` in its declarat // also works for unions union FooUnion @@ -50,6 +58,8 @@ fn main() { } impl FooUnion where A: Copy {} + //~^ ERROR: `FooUnion` has a similarly named generic type parameter `B` in its declara + //~| ERROR: `FooUnion` has a similarly named generic type parameter `A` in its declara impl FooUnion where diff --git a/tests/ui/mismatching_type_param_order.stderr b/tests/ui/mismatching_type_param_order.stderr index 204d499055774..b3200a51d7857 100644 --- a/tests/ui/mismatching_type_param_order.stderr +++ b/tests/ui/mismatching_type_param_order.stderr @@ -16,7 +16,7 @@ LL | impl Foo {} = help: try `B`, or a name that does not conflict with `Foo`'s generic params error: `Foo` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:14:23 + --> $DIR/mismatching_type_param_order.rs:16:23 | LL | impl Foo {} | ^ @@ -24,7 +24,7 @@ LL | impl Foo {} = help: try `B`, or a name that does not conflict with `Foo`'s generic params error: `FooLifetime` has a similarly named generic type parameter `B` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:25:44 + --> $DIR/mismatching_type_param_order.rs:28:44 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -32,7 +32,7 @@ LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} = help: try `A`, or a name that does not conflict with `FooLifetime`'s generic params error: `FooLifetime` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:25:47 + --> $DIR/mismatching_type_param_order.rs:28:47 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -40,7 +40,7 @@ LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} = help: try `B`, or a name that does not conflict with `FooLifetime`'s generic params error: `FooEnum` has a similarly named generic type parameter `C` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:41:27 + --> $DIR/mismatching_type_param_order.rs:46:27 | LL | impl FooEnum {} | ^ @@ -48,7 +48,7 @@ LL | impl FooEnum {} = help: try `A`, or a name that does not conflict with `FooEnum`'s generic params error: `FooEnum` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:41:30 + --> $DIR/mismatching_type_param_order.rs:46:30 | LL | impl FooEnum {} | ^ @@ -56,7 +56,7 @@ LL | impl FooEnum {} = help: try `B`, or a name that does not conflict with `FooEnum`'s generic params error: `FooEnum` has a similarly named generic type parameter `B` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:41:33 + --> $DIR/mismatching_type_param_order.rs:46:33 | LL | impl FooEnum {} | ^ @@ -64,7 +64,7 @@ LL | impl FooEnum {} = help: try `C`, or a name that does not conflict with `FooEnum`'s generic params error: `FooUnion` has a similarly named generic type parameter `B` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:52:31 + --> $DIR/mismatching_type_param_order.rs:60:31 | LL | impl FooUnion where A: Copy {} | ^ @@ -72,7 +72,7 @@ LL | impl FooUnion where A: Copy {} = help: try `A`, or a name that does not conflict with `FooUnion`'s generic params error: `FooUnion` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:52:34 + --> $DIR/mismatching_type_param_order.rs:60:34 | LL | impl FooUnion where A: Copy {} | ^ diff --git a/tests/ui/misnamed_getters.fixed b/tests/ui/misnamed_getters.fixed index fd7d127655872..2a7a2067ee083 100644 --- a/tests/ui/misnamed_getters.fixed +++ b/tests/ui/misnamed_getters.fixed @@ -9,25 +9,32 @@ struct A { impl A { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + //~| NOTE: `-D clippy::misnamed-getters` implied by `-D warnings` &self.a } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.b } fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } fn c(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.c } fn c_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.c } } @@ -39,17 +46,21 @@ union B { impl B { unsafe fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.a } unsafe fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } unsafe fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.b } unsafe fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } @@ -62,17 +73,21 @@ impl B { } unsafe fn a_unchecked(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.a } unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } unsafe fn b_unchecked(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.b } unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } @@ -105,16 +120,20 @@ impl core::ops::DerefMut for D { impl D { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.a } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } fn d(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.d } fn d_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.d } } diff --git a/tests/ui/misnamed_getters.rs b/tests/ui/misnamed_getters.rs index 03e7dac7df94c..56ddc46c4d4a7 100644 --- a/tests/ui/misnamed_getters.rs +++ b/tests/ui/misnamed_getters.rs @@ -9,25 +9,32 @@ struct A { impl A { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + //~| NOTE: `-D clippy::misnamed-getters` implied by `-D warnings` &self.b } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.a } fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } fn c(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } fn c_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } } @@ -39,17 +46,21 @@ union B { impl B { unsafe fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } unsafe fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } unsafe fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.a } unsafe fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } @@ -62,17 +73,21 @@ impl B { } unsafe fn a_unchecked(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } unsafe fn b_unchecked(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.a } unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } @@ -105,16 +120,20 @@ impl core::ops::DerefMut for D { impl D { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } fn d(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } fn d_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } } diff --git a/tests/ui/misnamed_getters.stderr b/tests/ui/misnamed_getters.stderr index 1e38a83d019a6..58f6f3eb7387c 100644 --- a/tests/ui/misnamed_getters.stderr +++ b/tests/ui/misnamed_getters.stderr @@ -2,6 +2,8 @@ error: getter function appears to return the wrong field --> $DIR/misnamed_getters.rs:11:5 | LL | / fn a(&self) -> &u8 { +LL | | +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } @@ -10,153 +12,170 @@ LL | | } = note: `-D clippy::misnamed-getters` implied by `-D warnings` error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:14:5 + --> $DIR/misnamed_getters.rs:16:5 | LL | / fn a_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:18:5 + --> $DIR/misnamed_getters.rs:21:5 | LL | / fn b(self) -> u8 { +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:22:5 + --> $DIR/misnamed_getters.rs:26:5 | LL | / fn b_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:26:5 + --> $DIR/misnamed_getters.rs:31:5 | LL | / fn c(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.c` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:30:5 + --> $DIR/misnamed_getters.rs:36:5 | LL | / fn c_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.c` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:41:5 + --> $DIR/misnamed_getters.rs:48:5 | LL | / unsafe fn a(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:44:5 + --> $DIR/misnamed_getters.rs:52:5 | LL | / unsafe fn a_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:48:5 + --> $DIR/misnamed_getters.rs:57:5 | LL | / unsafe fn b(self) -> u8 { +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:52:5 + --> $DIR/misnamed_getters.rs:62:5 | LL | / unsafe fn b_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:64:5 + --> $DIR/misnamed_getters.rs:75:5 | LL | / unsafe fn a_unchecked(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:67:5 + --> $DIR/misnamed_getters.rs:79:5 | LL | / unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:71:5 + --> $DIR/misnamed_getters.rs:84:5 | LL | / unsafe fn b_unchecked(self) -> u8 { +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:75:5 + --> $DIR/misnamed_getters.rs:89:5 | LL | / unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:107:5 + --> $DIR/misnamed_getters.rs:122:5 | LL | / fn a(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:110:5 + --> $DIR/misnamed_getters.rs:126:5 | LL | / fn a_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:114:5 + --> $DIR/misnamed_getters.rs:131:5 | LL | / fn d(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.d` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:117:5 + --> $DIR/misnamed_getters.rs:135:5 | LL | / fn d_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.d` LL | | } diff --git a/tests/ui/missing_assert_message.rs b/tests/ui/missing_assert_message.rs index af1358f61b5cb..2ad8e0127edf7 100644 --- a/tests/ui/missing_assert_message.rs +++ b/tests/ui/missing_assert_message.rs @@ -10,29 +10,45 @@ macro_rules! bar { // Should trigger warning fn asserts_without_message() { assert!(foo()); + //~^ ERROR: assert without any message assert_eq!(foo(), foo()); + //~^ ERROR: assert without any message assert_ne!(foo(), foo()); + //~^ ERROR: assert without any message debug_assert!(foo()); + //~^ ERROR: assert without any message debug_assert_eq!(foo(), foo()); + //~^ ERROR: assert without any message debug_assert_ne!(foo(), foo()); + //~^ ERROR: assert without any message } // Should trigger warning fn asserts_without_message_but_with_macro_calls() { assert!(bar!(true)); + //~^ ERROR: assert without any message assert!(bar!(true, false)); + //~^ ERROR: assert without any message assert_eq!(bar!(true), foo()); + //~^ ERROR: assert without any message assert_ne!(bar!(true, true), bar!(true)); + //~^ ERROR: assert without any message } // Should trigger warning fn asserts_with_trailing_commas() { assert!(foo(),); + //~^ ERROR: assert without any message assert_eq!(foo(), foo(),); + //~^ ERROR: assert without any message assert_ne!(foo(), foo(),); + //~^ ERROR: assert without any message debug_assert!(foo(),); + //~^ ERROR: assert without any message debug_assert_eq!(foo(), foo(),); + //~^ ERROR: assert without any message debug_assert_ne!(foo(), foo(),); + //~^ ERROR: assert without any message } // Should not trigger warning diff --git a/tests/ui/missing_assert_message.stderr b/tests/ui/missing_assert_message.stderr index 33a5c1f8e0526..00b9a36e9091f 100644 --- a/tests/ui/missing_assert_message.stderr +++ b/tests/ui/missing_assert_message.stderr @@ -8,7 +8,7 @@ LL | assert!(foo()); = note: `-D clippy::missing-assert-message` implied by `-D warnings` error: assert without any message - --> $DIR/missing_assert_message.rs:13:5 + --> $DIR/missing_assert_message.rs:14:5 | LL | assert_eq!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | assert_eq!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:14:5 + --> $DIR/missing_assert_message.rs:16:5 | LL | assert_ne!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | assert_ne!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:15:5 + --> $DIR/missing_assert_message.rs:18:5 | LL | debug_assert!(foo()); | ^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | debug_assert!(foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:16:5 + --> $DIR/missing_assert_message.rs:20:5 | LL | debug_assert_eq!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | debug_assert_eq!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:17:5 + --> $DIR/missing_assert_message.rs:22:5 | LL | debug_assert_ne!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | debug_assert_ne!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:22:5 + --> $DIR/missing_assert_message.rs:28:5 | LL | assert!(bar!(true)); | ^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | assert!(bar!(true)); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:23:5 + --> $DIR/missing_assert_message.rs:30:5 | LL | assert!(bar!(true, false)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | assert!(bar!(true, false)); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:24:5 + --> $DIR/missing_assert_message.rs:32:5 | LL | assert_eq!(bar!(true), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | assert_eq!(bar!(true), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:25:5 + --> $DIR/missing_assert_message.rs:34:5 | LL | assert_ne!(bar!(true, true), bar!(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | assert_ne!(bar!(true, true), bar!(true)); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:30:5 + --> $DIR/missing_assert_message.rs:40:5 | LL | assert!(foo(),); | ^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | assert!(foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:31:5 + --> $DIR/missing_assert_message.rs:42:5 | LL | assert_eq!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | assert_eq!(foo(), foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:32:5 + --> $DIR/missing_assert_message.rs:44:5 | LL | assert_ne!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | assert_ne!(foo(), foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:33:5 + --> $DIR/missing_assert_message.rs:46:5 | LL | debug_assert!(foo(),); | ^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | debug_assert!(foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:34:5 + --> $DIR/missing_assert_message.rs:48:5 | LL | debug_assert_eq!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | debug_assert_eq!(foo(), foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:35:5 + --> $DIR/missing_assert_message.rs:50:5 | LL | debug_assert_ne!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/missing_const_for_fn/could_be_const.rs b/tests/ui/missing_const_for_fn/could_be_const.rs index 3aaee67e1d971..6985c2d0c1956 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.rs +++ b/tests/ui/missing_const_for_fn/could_be_const.rs @@ -12,37 +12,45 @@ struct Game { impl Game { // Could be const pub fn new() -> Self { + //~^ ERROR: this could be a `const fn` + //~| NOTE: `-D clippy::missing-const-for-fn` implied by `-D warnings` Self { guess: 42 } } fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { + //~^ ERROR: this could be a `const fn` b } } // Could be const fn one() -> i32 { + //~^ ERROR: this could be a `const fn` 1 } // Could also be const fn two() -> i32 { + //~^ ERROR: this could be a `const fn` let abc = 2; abc } // Could be const (since Rust 1.39) fn string() -> String { + //~^ ERROR: this could be a `const fn` String::new() } // Could be const unsafe fn four() -> i32 { + //~^ ERROR: this could be a `const fn` 4 } // Could also be const fn generic(t: T) -> T { + //~^ ERROR: this could be a `const fn` t } @@ -51,6 +59,7 @@ fn sub(x: u32) -> usize { } fn generic_arr(t: [T; 1]) -> T { + //~^ ERROR: this could be a `const fn` t[0] } @@ -64,6 +73,7 @@ mod with_drop { impl B { // This can be const, because `a` is passed by reference pub fn b(self, a: &A) -> B { + //~^ ERROR: this could be a `const fn` B } } @@ -73,6 +83,7 @@ mod with_drop { mod const_fn_stabilized_before_msrv { // This could be const because `u8::is_ascii_digit` is a stable const function in 1.47. fn const_fn_stabilized_before_msrv(byte: u8) { + //~^ ERROR: this could be a `const fn` byte.is_ascii_digit(); } } @@ -84,6 +95,7 @@ fn msrv_1_45() -> i32 { #[clippy::msrv = "1.46"] fn msrv_1_46() -> i32 { + //~^ ERROR: this could be a `const fn` 46 } diff --git a/tests/ui/missing_const_for_fn/could_be_const.stderr b/tests/ui/missing_const_for_fn/could_be_const.stderr index 66cf4e3152934..5c6f9e8a7f0d6 100644 --- a/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -2,6 +2,8 @@ error: this could be a `const fn` --> $DIR/could_be_const.rs:14:5 | LL | / pub fn new() -> Self { +LL | | +LL | | LL | | Self { guess: 42 } LL | | } | |_____^ @@ -9,82 +11,92 @@ LL | | } = note: `-D clippy::missing-const-for-fn` implied by `-D warnings` error: this could be a `const fn` - --> $DIR/could_be_const.rs:18:5 + --> $DIR/could_be_const.rs:20:5 | LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { +LL | | LL | | b LL | | } | |_____^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:24:1 + --> $DIR/could_be_const.rs:27:1 | LL | / fn one() -> i32 { +LL | | LL | | 1 LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:29:1 + --> $DIR/could_be_const.rs:33:1 | LL | / fn two() -> i32 { +LL | | LL | | let abc = 2; LL | | abc LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:35:1 + --> $DIR/could_be_const.rs:40:1 | LL | / fn string() -> String { +LL | | LL | | String::new() LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:40:1 + --> $DIR/could_be_const.rs:46:1 | LL | / unsafe fn four() -> i32 { +LL | | LL | | 4 LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:45:1 + --> $DIR/could_be_const.rs:52:1 | LL | / fn generic(t: T) -> T { +LL | | LL | | t LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:53:1 + --> $DIR/could_be_const.rs:61:1 | LL | / fn generic_arr(t: [T; 1]) -> T { +LL | | LL | | t[0] LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:66:9 + --> $DIR/could_be_const.rs:75:9 | LL | / pub fn b(self, a: &A) -> B { +LL | | LL | | B LL | | } | |_________^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:75:5 + --> $DIR/could_be_const.rs:85:5 | LL | / fn const_fn_stabilized_before_msrv(byte: u8) { +LL | | LL | | byte.is_ascii_digit(); LL | | } | |_____^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:86:1 + --> $DIR/could_be_const.rs:97:1 | LL | / fn msrv_1_46() -> i32 { +LL | | LL | | 46 LL | | } | |_^ diff --git a/tests/ui/missing_doc_crate_missing.rs b/tests/ui/missing_doc_crate_missing.rs index 51fd57df8df1d..73584ac8c67d3 100644 --- a/tests/ui/missing_doc_crate_missing.rs +++ b/tests/ui/missing_doc_crate_missing.rs @@ -1,3 +1,5 @@ #![warn(clippy::missing_docs_in_private_items)] +//~^ ERROR: missing documentation for the crate +//~| NOTE: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` fn main() {} diff --git a/tests/ui/missing_doc_crate_missing.stderr b/tests/ui/missing_doc_crate_missing.stderr index 19516bf5fab0e..75e033cc94b48 100644 --- a/tests/ui/missing_doc_crate_missing.stderr +++ b/tests/ui/missing_doc_crate_missing.stderr @@ -3,6 +3,8 @@ error: missing documentation for the crate | LL | / #![warn(clippy::missing_docs_in_private_items)] LL | | +LL | | +LL | | LL | | fn main() {} | |____________^ | diff --git a/tests/ui/missing_fields_in_debug.rs b/tests/ui/missing_fields_in_debug.rs index c156d394eceaa..e91e8ab7f475e 100644 --- a/tests/ui/missing_fields_in_debug.rs +++ b/tests/ui/missing_fields_in_debug.rs @@ -11,6 +11,7 @@ struct NamedStruct1Ignored { } impl fmt::Debug for NamedStruct1Ignored { + //~^ ERROR: manual `Debug` impl does not include all fields // unused field: hidden fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter @@ -29,6 +30,7 @@ struct NamedStructMultipleIgnored { } impl fmt::Debug for NamedStructMultipleIgnored { + //~^ ERROR: manual `Debug` impl does not include all fields // unused fields: hidden, hidden2, hidden4 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter @@ -90,6 +92,7 @@ struct MultiExprDebugImpl { // ok impl fmt::Debug for MultiExprDebugImpl { + //~^ ERROR: manual `Debug` impl does not include all fields fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { let mut f = formatter.debug_struct("MultiExprDebugImpl"); f.field("a", &self.a); diff --git a/tests/ui/missing_fields_in_debug.stderr b/tests/ui/missing_fields_in_debug.stderr index ef9d02abab7db..51b5e7b314ace 100644 --- a/tests/ui/missing_fields_in_debug.stderr +++ b/tests/ui/missing_fields_in_debug.stderr @@ -2,9 +2,9 @@ error: manual `Debug` impl does not include all fields --> $DIR/missing_fields_in_debug.rs:13:1 | LL | / impl fmt::Debug for NamedStruct1Ignored { +LL | | LL | | // unused field: hidden LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { -LL | | formatter ... | LL | | } LL | | } @@ -20,29 +20,29 @@ LL | hidden: u32, = note: `-D clippy::missing-fields-in-debug` implied by `-D warnings` error: manual `Debug` impl does not include all fields - --> $DIR/missing_fields_in_debug.rs:31:1 + --> $DIR/missing_fields_in_debug.rs:32:1 | LL | / impl fmt::Debug for NamedStructMultipleIgnored { +LL | | LL | | // unused fields: hidden, hidden2, hidden4 LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { -LL | | formatter ... | LL | | } LL | | } | |_^ | note: this field is unused - --> $DIR/missing_fields_in_debug.rs:25:5 + --> $DIR/missing_fields_in_debug.rs:26:5 | LL | hidden: u32, | ^^^^^^^^^^^ note: this field is unused - --> $DIR/missing_fields_in_debug.rs:26:5 + --> $DIR/missing_fields_in_debug.rs:27:5 | LL | hidden2: String, | ^^^^^^^^^^^^^^^ note: this field is unused - --> $DIR/missing_fields_in_debug.rs:28:5 + --> $DIR/missing_fields_in_debug.rs:29:5 | LL | hidden4: ((((u8), u16), u32), u64), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -50,19 +50,19 @@ LL | hidden4: ((((u8), u16), u32), u64), = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields error: manual `Debug` impl does not include all fields - --> $DIR/missing_fields_in_debug.rs:92:1 + --> $DIR/missing_fields_in_debug.rs:94:1 | LL | / impl fmt::Debug for MultiExprDebugImpl { +LL | | LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { LL | | let mut f = formatter.debug_struct("MultiExprDebugImpl"); -LL | | f.field("a", &self.a); -LL | | f.finish() +... | LL | | } LL | | } | |_^ | note: this field is unused - --> $DIR/missing_fields_in_debug.rs:88:5 + --> $DIR/missing_fields_in_debug.rs:90:5 | LL | b: String, | ^^^^^^^^^ diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index c5cf97d3cd655..dca85b94d5ee5 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -18,6 +18,8 @@ pub mod pub_module {} // ok fn foo() {} // missing #[inline] pub fn pub_foo() {} +//~^ ERROR: missing `#[inline]` for a function +//~| NOTE: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` #[inline] pub fn pub_foo_inline() {} // ok #[inline(always)] @@ -35,6 +37,7 @@ pub trait PubBar { fn PubBar_a(); // ok // missing #[inline] fn PubBar_b() {} + //~^ ERROR: missing `#[inline]` for a default trait method #[inline] fn PubBar_c() {} // ok } @@ -50,10 +53,13 @@ impl PubBar for Foo { impl PubBar for PubFoo { // missing #[inline] fn PubBar_a() {} + //~^ ERROR: missing `#[inline]` for a method // missing #[inline] fn PubBar_b() {} + //~^ ERROR: missing `#[inline]` for a method // missing #[inline] fn PubBar_c() {} + //~^ ERROR: missing `#[inline]` for a method } // do not need inline because Foo is not exported @@ -65,6 +71,7 @@ impl Foo { impl PubFoo { // missing #[inline] pub fn PubFooImpl() {} + //~^ ERROR: missing `#[inline]` for a method } // do not lint this since users cannot control the external code diff --git a/tests/ui/missing_inline.stderr b/tests/ui/missing_inline.stderr index 73f876c1d1a31..be24af49273f2 100644 --- a/tests/ui/missing_inline.stderr +++ b/tests/ui/missing_inline.stderr @@ -7,31 +7,31 @@ LL | pub fn pub_foo() {} = note: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` error: missing `#[inline]` for a default trait method - --> $DIR/missing_inline.rs:37:5 + --> $DIR/missing_inline.rs:39:5 | LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:52:5 + --> $DIR/missing_inline.rs:55:5 | LL | fn PubBar_a() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:54:5 + --> $DIR/missing_inline.rs:58:5 | LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:56:5 + --> $DIR/missing_inline.rs:61:5 | LL | fn PubBar_c() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:67:5 + --> $DIR/missing_inline.rs:73:5 | LL | pub fn PubFooImpl() {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/missing_trait_methods.rs b/tests/ui/missing_trait_methods.rs index 8df885919a3e6..1b09b717ff70a 100644 --- a/tests/ui/missing_trait_methods.rs +++ b/tests/ui/missing_trait_methods.rs @@ -20,8 +20,10 @@ trait B { struct Partial; impl A for Partial {} +//~^ ERROR: missing trait method provided by default: `provided` impl B for Partial { + //~^ ERROR: missing trait method provided by default: `b` fn required() {} fn a(_: usize) -> usize { diff --git a/tests/ui/missing_trait_methods.stderr b/tests/ui/missing_trait_methods.stderr index 0c5205e196572..8f50e76135c4d 100644 --- a/tests/ui/missing_trait_methods.stderr +++ b/tests/ui/missing_trait_methods.stderr @@ -12,7 +12,7 @@ LL | fn provided() {} = note: `-D clippy::missing-trait-methods` implied by `-D warnings` error: missing trait method provided by default: `b` - --> $DIR/missing_trait_methods.rs:24:1 + --> $DIR/missing_trait_methods.rs:25:1 | LL | impl B for Partial { | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mixed_read_write_in_expression.rs b/tests/ui/mixed_read_write_in_expression.rs index 6efc7657ec0c9..241536abdfbd7 100644 --- a/tests/ui/mixed_read_write_in_expression.rs +++ b/tests/ui/mixed_read_write_in_expression.rs @@ -12,9 +12,11 @@ fn main() { x = 1; 1 } + x; + //~^ ERROR: unsequenced read of `x` // Example from iss#277 x += { + //~^ ERROR: unsequenced read of `x` x = 20; 2 }; @@ -28,6 +30,7 @@ fn main() { let base = Foo { a: 4, b: 5 }; let foo = Foo { a: x, + //~^ ERROR: unsequenced read of `x` ..{ x = 6; base @@ -37,6 +40,7 @@ fn main() { let closure = || { let mut x = 0; x += { + //~^ ERROR: unsequenced read of `x` x = 20; 2 }; diff --git a/tests/ui/mixed_read_write_in_expression.stderr b/tests/ui/mixed_read_write_in_expression.stderr index 8cc68b0ac7b43..e0b405ddece9b 100644 --- a/tests/ui/mixed_read_write_in_expression.stderr +++ b/tests/ui/mixed_read_write_in_expression.stderr @@ -12,37 +12,37 @@ LL | x = 1; = note: `-D clippy::mixed-read-write-in-expression` implied by `-D warnings` error: unsequenced read of `x` - --> $DIR/mixed_read_write_in_expression.rs:17:5 + --> $DIR/mixed_read_write_in_expression.rs:18:5 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> $DIR/mixed_read_write_in_expression.rs:18:9 + --> $DIR/mixed_read_write_in_expression.rs:20:9 | LL | x = 20; | ^^^^^^ error: unsequenced read of `x` - --> $DIR/mixed_read_write_in_expression.rs:30:12 + --> $DIR/mixed_read_write_in_expression.rs:32:12 | LL | a: x, | ^ | note: whether read occurs before this write depends on evaluation order - --> $DIR/mixed_read_write_in_expression.rs:32:13 + --> $DIR/mixed_read_write_in_expression.rs:35:13 | LL | x = 6; | ^^^^^ error: unsequenced read of `x` - --> $DIR/mixed_read_write_in_expression.rs:39:9 + --> $DIR/mixed_read_write_in_expression.rs:42:9 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> $DIR/mixed_read_write_in_expression.rs:40:13 + --> $DIR/mixed_read_write_in_expression.rs:44:13 | LL | x = 20; | ^^^^^^ diff --git a/tests/ui/module_inception.rs b/tests/ui/module_inception.rs index 802c3ec39b64b..ad46e0c29aee3 100644 --- a/tests/ui/module_inception.rs +++ b/tests/ui/module_inception.rs @@ -3,11 +3,14 @@ pub mod foo2 { pub mod bar2 { pub mod bar2 { + //~^ ERROR: module has the same name as its containing module + //~| NOTE: `-D clippy::module-inception` implied by `-D warnings` pub mod foo2 {} } pub mod foo2 {} } pub mod foo2 { + //~^ ERROR: module has the same name as its containing module pub mod bar2 {} } } @@ -15,11 +18,13 @@ pub mod foo2 { mod foo { mod bar { mod bar { + //~^ ERROR: module has the same name as its containing module mod foo {} } mod foo {} } mod foo { + //~^ ERROR: module has the same name as its containing module mod bar {} } } diff --git a/tests/ui/module_inception.stderr b/tests/ui/module_inception.stderr index ebb8e296f4646..b4f80a5bc7c2f 100644 --- a/tests/ui/module_inception.stderr +++ b/tests/ui/module_inception.stderr @@ -2,6 +2,8 @@ error: module has the same name as its containing module --> $DIR/module_inception.rs:5:9 | LL | / pub mod bar2 { +LL | | +LL | | LL | | pub mod foo2 {} LL | | } | |_________^ @@ -9,25 +11,28 @@ LL | | } = note: `-D clippy::module-inception` implied by `-D warnings` error: module has the same name as its containing module - --> $DIR/module_inception.rs:10:5 + --> $DIR/module_inception.rs:12:5 | LL | / pub mod foo2 { +LL | | LL | | pub mod bar2 {} LL | | } | |_____^ error: module has the same name as its containing module - --> $DIR/module_inception.rs:17:9 + --> $DIR/module_inception.rs:20:9 | LL | / mod bar { +LL | | LL | | mod foo {} LL | | } | |_________^ error: module has the same name as its containing module - --> $DIR/module_inception.rs:22:5 + --> $DIR/module_inception.rs:26:5 | LL | / mod foo { +LL | | LL | | mod bar {} LL | | } | |_____^ diff --git a/tests/ui/module_name_repetitions.rs b/tests/ui/module_name_repetitions.rs index fb2c7612343c8..a6cf03890983f 100644 --- a/tests/ui/module_name_repetitions.rs +++ b/tests/ui/module_name_repetitions.rs @@ -6,10 +6,16 @@ mod foo { pub fn foo() {} pub fn foo_bar() {} + //~^ ERROR: item name starts with its containing module's name + //~| NOTE: `-D clippy::module-name-repetitions` implied by `-D warnings` pub fn bar_foo() {} + //~^ ERROR: item name ends with its containing module's name pub struct FooCake; + //~^ ERROR: item name starts with its containing module's name pub enum CakeFoo {} + //~^ ERROR: item name ends with its containing module's name pub struct Foo7Bar; + //~^ ERROR: item name starts with its containing module's name // Should not warn pub struct Foobar; diff --git a/tests/ui/module_name_repetitions.stderr b/tests/ui/module_name_repetitions.stderr index 277801194a1d5..3c7fa1def2ba2 100644 --- a/tests/ui/module_name_repetitions.stderr +++ b/tests/ui/module_name_repetitions.stderr @@ -7,25 +7,25 @@ LL | pub fn foo_bar() {} = note: `-D clippy::module-name-repetitions` implied by `-D warnings` error: item name ends with its containing module's name - --> $DIR/module_name_repetitions.rs:9:12 + --> $DIR/module_name_repetitions.rs:11:12 | LL | pub fn bar_foo() {} | ^^^^^^^ error: item name starts with its containing module's name - --> $DIR/module_name_repetitions.rs:10:16 + --> $DIR/module_name_repetitions.rs:13:16 | LL | pub struct FooCake; | ^^^^^^^ error: item name ends with its containing module's name - --> $DIR/module_name_repetitions.rs:11:14 + --> $DIR/module_name_repetitions.rs:15:14 | LL | pub enum CakeFoo {} | ^^^^^^^ error: item name starts with its containing module's name - --> $DIR/module_name_repetitions.rs:12:16 + --> $DIR/module_name_repetitions.rs:17:16 | LL | pub struct Foo7Bar; | ^^^^^^^ diff --git a/tests/ui/modulo_arithmetic_float.rs b/tests/ui/modulo_arithmetic_float.rs index b1861f07cd189..37895ea09e72c 100644 --- a/tests/ui/modulo_arithmetic_float.rs +++ b/tests/ui/modulo_arithmetic_float.rs @@ -4,22 +4,42 @@ fn main() { // Lint when both sides are const and of the opposite sign -1.6 % 2.1; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1.600 % + //~| NOTE: double check for expected result especially when interoperating with differ 1.6 % -2.1; + //~^ ERROR: you are using modulo operator on constants with different signs: `1.600 % + //~| NOTE: double check for expected result especially when interoperating with differ (1.1 - 2.3) % (1.1 + 2.3); + //~^ ERROR: you are using modulo operator on constants with different signs: `-1.200 % + //~| NOTE: double check for expected result especially when interoperating with differ (1.1 + 2.3) % (1.1 - 2.3); + //~^ ERROR: you are using modulo operator on constants with different signs: `3.400 % + //~| NOTE: double check for expected result especially when interoperating with differ // Lint on floating point numbers let a_f32: f32 = -1.6; let mut b_f32: f32 = 2.1; a_f32 % b_f32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f32 % a_f32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f32 %= a_f32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_f64: f64 = -1.6; let mut b_f64: f64 = 2.1; a_f64 % b_f64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f64 % a_f64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f64 %= a_f64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ // No lint when both sides are const and of the same sign 1.6 % 2.1; diff --git a/tests/ui/modulo_arithmetic_float.stderr b/tests/ui/modulo_arithmetic_float.stderr index 36106de31f0bc..3faf8c5aee1c1 100644 --- a/tests/ui/modulo_arithmetic_float.stderr +++ b/tests/ui/modulo_arithmetic_float.stderr @@ -8,7 +8,7 @@ LL | -1.6 % 2.1; = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` error: you are using modulo operator on constants with different signs: `1.600 % -2.100` - --> $DIR/modulo_arithmetic_float.rs:7:5 + --> $DIR/modulo_arithmetic_float.rs:9:5 | LL | 1.6 % -2.1; | ^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | 1.6 % -2.1; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on constants with different signs: `-1.200 % 3.400` - --> $DIR/modulo_arithmetic_float.rs:8:5 + --> $DIR/modulo_arithmetic_float.rs:12:5 | LL | (1.1 - 2.3) % (1.1 + 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | (1.1 - 2.3) % (1.1 + 2.3); = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on constants with different signs: `3.400 % -1.200` - --> $DIR/modulo_arithmetic_float.rs:9:5 + --> $DIR/modulo_arithmetic_float.rs:15:5 | LL | (1.1 + 2.3) % (1.1 - 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | (1.1 + 2.3) % (1.1 - 2.3); = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:14:5 + --> $DIR/modulo_arithmetic_float.rs:22:5 | LL | a_f32 % b_f32; | ^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | a_f32 % b_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:15:5 + --> $DIR/modulo_arithmetic_float.rs:25:5 | LL | b_f32 % a_f32; | ^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | b_f32 % a_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:16:5 + --> $DIR/modulo_arithmetic_float.rs:28:5 | LL | b_f32 %= a_f32; | ^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | b_f32 %= a_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:20:5 + --> $DIR/modulo_arithmetic_float.rs:34:5 | LL | a_f64 % b_f64; | ^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | a_f64 % b_f64; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:21:5 + --> $DIR/modulo_arithmetic_float.rs:37:5 | LL | b_f64 % a_f64; | ^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | b_f64 % a_f64; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:22:5 + --> $DIR/modulo_arithmetic_float.rs:40:5 | LL | b_f64 %= a_f64; | ^^^^^^^^^^^^^^ diff --git a/tests/ui/modulo_arithmetic_integral.rs b/tests/ui/modulo_arithmetic_integral.rs index fc1acc39ebc77..4dbed24026cf5 100644 --- a/tests/ui/modulo_arithmetic_integral.rs +++ b/tests/ui/modulo_arithmetic_integral.rs @@ -6,43 +6,77 @@ fn main() { let a = -1; let mut b = 2; a % b; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b % a; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b %= a; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i8: i8 = 1; let mut b_i8: i8 = 2; a_i8 % b_i8; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i8 %= a_i8; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i16: i16 = 1; let mut b_i16: i16 = 2; a_i16 % b_i16; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i16 %= a_i16; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i32: i32 = 1; let mut b_i32: i32 = 2; a_i32 % b_i32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i32 %= a_i32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i64: i64 = 1; let mut b_i64: i64 = 2; a_i64 % b_i64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i64 %= a_i64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i128: i128 = 1; let mut b_i128: i128 = 2; a_i128 % b_i128; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i128 %= a_i128; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_isize: isize = 1; let mut b_isize: isize = 2; a_isize % b_isize; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_isize %= a_isize; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a = 1; let mut b = 2; a % b; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b %= a; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ // No lint on unsigned integral value let a_u8: u8 = 17; diff --git a/tests/ui/modulo_arithmetic_integral.stderr b/tests/ui/modulo_arithmetic_integral.stderr index 9ff676ff6bcb1..6d61afa0c3114 100644 --- a/tests/ui/modulo_arithmetic_integral.stderr +++ b/tests/ui/modulo_arithmetic_integral.stderr @@ -9,7 +9,7 @@ LL | a % b; = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:9:5 + --> $DIR/modulo_arithmetic_integral.rs:11:5 | LL | b % a; | ^^^^^ @@ -18,7 +18,7 @@ LL | b % a; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:10:5 + --> $DIR/modulo_arithmetic_integral.rs:14:5 | LL | b %= a; | ^^^^^^ @@ -27,7 +27,7 @@ LL | b %= a; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:14:5 + --> $DIR/modulo_arithmetic_integral.rs:20:5 | LL | a_i8 % b_i8; | ^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | a_i8 % b_i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:15:5 + --> $DIR/modulo_arithmetic_integral.rs:23:5 | LL | b_i8 %= a_i8; | ^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | b_i8 %= a_i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:19:5 + --> $DIR/modulo_arithmetic_integral.rs:29:5 | LL | a_i16 % b_i16; | ^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | a_i16 % b_i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:20:5 + --> $DIR/modulo_arithmetic_integral.rs:32:5 | LL | b_i16 %= a_i16; | ^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | b_i16 %= a_i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:24:5 + --> $DIR/modulo_arithmetic_integral.rs:38:5 | LL | a_i32 % b_i32; | ^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | a_i32 % b_i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:25:5 + --> $DIR/modulo_arithmetic_integral.rs:41:5 | LL | b_i32 %= a_i32; | ^^^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | b_i32 %= a_i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:29:5 + --> $DIR/modulo_arithmetic_integral.rs:47:5 | LL | a_i64 % b_i64; | ^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | a_i64 % b_i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:30:5 + --> $DIR/modulo_arithmetic_integral.rs:50:5 | LL | b_i64 %= a_i64; | ^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | b_i64 %= a_i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:34:5 + --> $DIR/modulo_arithmetic_integral.rs:56:5 | LL | a_i128 % b_i128; | ^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | a_i128 % b_i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:35:5 + --> $DIR/modulo_arithmetic_integral.rs:59:5 | LL | b_i128 %= a_i128; | ^^^^^^^^^^^^^^^^ @@ -117,7 +117,7 @@ LL | b_i128 %= a_i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:39:5 + --> $DIR/modulo_arithmetic_integral.rs:65:5 | LL | a_isize % b_isize; | ^^^^^^^^^^^^^^^^^ @@ -126,7 +126,7 @@ LL | a_isize % b_isize; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:40:5 + --> $DIR/modulo_arithmetic_integral.rs:68:5 | LL | b_isize %= a_isize; | ^^^^^^^^^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | b_isize %= a_isize; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:44:5 + --> $DIR/modulo_arithmetic_integral.rs:74:5 | LL | a % b; | ^^^^^ @@ -144,7 +144,7 @@ LL | a % b; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:45:5 + --> $DIR/modulo_arithmetic_integral.rs:77:5 | LL | b %= a; | ^^^^^^ diff --git a/tests/ui/modulo_arithmetic_integral_const.rs b/tests/ui/modulo_arithmetic_integral_const.rs index 3ebe46bc5be7c..dbc679a69825c 100644 --- a/tests/ui/modulo_arithmetic_integral_const.rs +++ b/tests/ui/modulo_arithmetic_integral_const.rs @@ -9,23 +9,57 @@ fn main() { // Lint when both sides are const and of the opposite sign -1 % 2; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1 % -2; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ (1 - 2) % (1 + 2); + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 3` + //~| NOTE: double check for expected result especially when interoperating with differ (1 + 2) % (1 - 2); + //~^ ERROR: you are using modulo operator on constants with different signs: `3 % -1` + //~| NOTE: double check for expected result especially when interoperating with differ 35 * (7 - 4 * 2) % (-500 * -600); + //~^ ERROR: you are using modulo operator on constants with different signs: `-35 % 30 + //~| NOTE: double check for expected result especially when interoperating with differ -1i8 % 2i8; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i8 % -2i8; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i16 % 2i16; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i16 % -2i16; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i32 % 2i32; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i32 % -2i32; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i64 % 2i64; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i64 % -2i64; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i128 % 2i128; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i128 % -2i128; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1isize % 2isize; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1isize % -2isize; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ // No lint when both sides are const and of the same sign 1 % 2; diff --git a/tests/ui/modulo_arithmetic_integral_const.stderr b/tests/ui/modulo_arithmetic_integral_const.stderr index 1453d44f488f3..59267b0e79696 100644 --- a/tests/ui/modulo_arithmetic_integral_const.stderr +++ b/tests/ui/modulo_arithmetic_integral_const.stderr @@ -9,7 +9,7 @@ LL | -1 % 2; = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:12:5 + --> $DIR/modulo_arithmetic_integral_const.rs:14:5 | LL | 1 % -2; | ^^^^^^ @@ -18,7 +18,7 @@ LL | 1 % -2; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 3` - --> $DIR/modulo_arithmetic_integral_const.rs:13:5 + --> $DIR/modulo_arithmetic_integral_const.rs:17:5 | LL | (1 - 2) % (1 + 2); | ^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | (1 - 2) % (1 + 2); = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `3 % -1` - --> $DIR/modulo_arithmetic_integral_const.rs:14:5 + --> $DIR/modulo_arithmetic_integral_const.rs:20:5 | LL | (1 + 2) % (1 - 2); | ^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | (1 + 2) % (1 - 2); = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-35 % 300000` - --> $DIR/modulo_arithmetic_integral_const.rs:15:5 + --> $DIR/modulo_arithmetic_integral_const.rs:23:5 | LL | 35 * (7 - 4 * 2) % (-500 * -600); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | 35 * (7 - 4 * 2) % (-500 * -600); = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:17:5 + --> $DIR/modulo_arithmetic_integral_const.rs:27:5 | LL | -1i8 % 2i8; | ^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | -1i8 % 2i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:18:5 + --> $DIR/modulo_arithmetic_integral_const.rs:30:5 | LL | 1i8 % -2i8; | ^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | 1i8 % -2i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:19:5 + --> $DIR/modulo_arithmetic_integral_const.rs:33:5 | LL | -1i16 % 2i16; | ^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | -1i16 % 2i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:20:5 + --> $DIR/modulo_arithmetic_integral_const.rs:36:5 | LL | 1i16 % -2i16; | ^^^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | 1i16 % -2i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:21:5 + --> $DIR/modulo_arithmetic_integral_const.rs:39:5 | LL | -1i32 % 2i32; | ^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | -1i32 % 2i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:22:5 + --> $DIR/modulo_arithmetic_integral_const.rs:42:5 | LL | 1i32 % -2i32; | ^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | 1i32 % -2i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:23:5 + --> $DIR/modulo_arithmetic_integral_const.rs:45:5 | LL | -1i64 % 2i64; | ^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | -1i64 % 2i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:24:5 + --> $DIR/modulo_arithmetic_integral_const.rs:48:5 | LL | 1i64 % -2i64; | ^^^^^^^^^^^^ @@ -117,7 +117,7 @@ LL | 1i64 % -2i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:25:5 + --> $DIR/modulo_arithmetic_integral_const.rs:51:5 | LL | -1i128 % 2i128; | ^^^^^^^^^^^^^^ @@ -126,7 +126,7 @@ LL | -1i128 % 2i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:26:5 + --> $DIR/modulo_arithmetic_integral_const.rs:54:5 | LL | 1i128 % -2i128; | ^^^^^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | 1i128 % -2i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:27:5 + --> $DIR/modulo_arithmetic_integral_const.rs:57:5 | LL | -1isize % 2isize; | ^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | -1isize % 2isize; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:28:5 + --> $DIR/modulo_arithmetic_integral_const.rs:60:5 | LL | 1isize % -2isize; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/modulo_one.rs b/tests/ui/modulo_one.rs index 656b0b5cedcc2..c1dbe9d9a8787 100644 --- a/tests/ui/modulo_one.rs +++ b/tests/ui/modulo_one.rs @@ -6,23 +6,34 @@ static STATIC_NEG_ONE: i64 = 1 - 2; fn main() { 10 % 1; + //~^ ERROR: any number modulo 1 will be 0 + //~| NOTE: `-D clippy::modulo-one` implied by `-D warnings` 10 % -1; + //~^ ERROR: any number modulo -1 will panic/overflow or result in 0 10 % 2; // also caught by rustc i32::MIN % (-1); + //~^ ERROR: this operation will panic at runtime + //~| NOTE: `#[deny(unconditional_panic)]` on by default + //~| ERROR: any number modulo -1 will panic/overflow or result in 0 const ONE: u32 = 1 * 1; const NEG_ONE: i64 = 1 - 2; const INT_MIN: i64 = i64::MIN; 2 % ONE; + //~^ ERROR: any number modulo 1 will be 0 // NOT caught by lint 5 % STATIC_ONE; 2 % NEG_ONE; + //~^ ERROR: any number modulo -1 will panic/overflow or result in 0 // NOT caught by lint 5 % STATIC_NEG_ONE; // also caught by rustc INT_MIN % NEG_ONE; + //~^ ERROR: this operation will panic at runtime + //~| ERROR: any number modulo -1 will panic/overflow or result in 0 // ONLY caught by rustc INT_MIN % STATIC_NEG_ONE; + //~^ ERROR: this operation will panic at runtime } diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr index 0793e6386930b..62e23ee9a595f 100644 --- a/tests/ui/modulo_one.stderr +++ b/tests/ui/modulo_one.stderr @@ -1,5 +1,5 @@ error: this operation will panic at runtime - --> $DIR/modulo_one.rs:12:5 + --> $DIR/modulo_one.rs:15:5 | LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ attempt to compute `i32::MIN % -1_i32`, which would overflow @@ -7,13 +7,13 @@ LL | i32::MIN % (-1); = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime - --> $DIR/modulo_one.rs:25:5 + --> $DIR/modulo_one.rs:33:5 | LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: this operation will panic at runtime - --> $DIR/modulo_one.rs:27:5 + --> $DIR/modulo_one.rs:37:5 | LL | INT_MIN % STATIC_NEG_ONE; | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow @@ -27,31 +27,31 @@ LL | 10 % 1; = note: `-D clippy::modulo-one` implied by `-D warnings` error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:9:5 + --> $DIR/modulo_one.rs:11:5 | LL | 10 % -1; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:12:5 + --> $DIR/modulo_one.rs:15:5 | LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ error: any number modulo 1 will be 0 - --> $DIR/modulo_one.rs:18:5 + --> $DIR/modulo_one.rs:24:5 | LL | 2 % ONE; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:21:5 + --> $DIR/modulo_one.rs:28:5 | LL | 2 % NEG_ONE; | ^^^^^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:25:5 + --> $DIR/modulo_one.rs:33:5 | LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/multi_assignments.rs b/tests/ui/multi_assignments.rs index b186bf8bbdb42..cdbf13b68889e 100644 --- a/tests/ui/multi_assignments.rs +++ b/tests/ui/multi_assignments.rs @@ -2,8 +2,15 @@ fn main() { let (mut a, mut b, mut c, mut d) = ((), (), (), ()); a = b = c; + //~^ ERROR: assignments don't nest intuitively + //~| NOTE: `-D clippy::multi-assignments` implied by `-D warnings` a = b = c = d; + //~^ ERROR: assignments don't nest intuitively + //~| ERROR: assignments don't nest intuitively a = b = { c }; + //~^ ERROR: assignments don't nest intuitively a = { b = c }; + //~^ ERROR: assignments don't nest intuitively a = (b = c); + //~^ ERROR: assignments don't nest intuitively } diff --git a/tests/ui/multi_assignments.stderr b/tests/ui/multi_assignments.stderr index d6c42bb698cf9..813e920f74d74 100644 --- a/tests/ui/multi_assignments.stderr +++ b/tests/ui/multi_assignments.stderr @@ -7,31 +7,31 @@ LL | a = b = c; = note: `-D clippy::multi-assignments` implied by `-D warnings` error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:5:5 + --> $DIR/multi_assignments.rs:7:5 | LL | a = b = c = d; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:5:9 + --> $DIR/multi_assignments.rs:7:9 | LL | a = b = c = d; | ^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:6:5 + --> $DIR/multi_assignments.rs:10:5 | LL | a = b = { c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:7:5 + --> $DIR/multi_assignments.rs:12:5 | LL | a = { b = c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:8:5 + --> $DIR/multi_assignments.rs:14:5 | LL | a = (b = c); | ^^^^^^^^^^^ diff --git a/tests/ui/mut_from_ref.rs b/tests/ui/mut_from_ref.rs index 8c0c23b657065..0ab6d77de1e1d 100644 --- a/tests/ui/mut_from_ref.rs +++ b/tests/ui/mut_from_ref.rs @@ -5,12 +5,14 @@ struct Foo; impl Foo { fn this_wont_hurt_a_bit(&self) -> &mut Foo { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } } trait Ouch { fn ouch(x: &Foo) -> &mut Foo; + //~^ ERROR: mutable borrow from immutable input(s) } impl Ouch for Foo { @@ -20,14 +22,17 @@ impl Ouch for Foo { } fn fail(x: &u32) -> &mut u16 { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } @@ -42,6 +47,7 @@ fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 { } unsafe fn also_broken(x: &u32) -> &mut u32 { + //~^ ERROR: mutable borrow from immutable input(s) unimplemented!() } diff --git a/tests/ui/mut_from_ref.stderr b/tests/ui/mut_from_ref.stderr index c20ff54bf949b..1c3df2b54fca0 100644 --- a/tests/ui/mut_from_ref.stderr +++ b/tests/ui/mut_from_ref.stderr @@ -12,61 +12,61 @@ LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo { = note: `-D clippy::mut-from-ref` implied by `-D warnings` error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:13:25 + --> $DIR/mut_from_ref.rs:14:25 | LL | fn ouch(x: &Foo) -> &mut Foo; | ^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:13:16 + --> $DIR/mut_from_ref.rs:14:16 | LL | fn ouch(x: &Foo) -> &mut Foo; | ^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:22:21 + --> $DIR/mut_from_ref.rs:24:21 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:22:12 + --> $DIR/mut_from_ref.rs:24:12 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:26:50 + --> $DIR/mut_from_ref.rs:29:50 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:26:25 + --> $DIR/mut_from_ref.rs:29:25 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:30:67 + --> $DIR/mut_from_ref.rs:34:67 | LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:30:27 + --> $DIR/mut_from_ref.rs:34:27 | LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { | ^^^^^^^ ^^^^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:44:35 + --> $DIR/mut_from_ref.rs:49:35 | LL | unsafe fn also_broken(x: &u32) -> &mut u32 { | ^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:44:26 + --> $DIR/mut_from_ref.rs:49:26 | LL | unsafe fn also_broken(x: &u32) -> &mut u32 { | ^^^^ diff --git a/tests/ui/mut_key.rs b/tests/ui/mut_key.rs index 24cf2fbbf12ac..8069213217683 100644 --- a/tests/ui/mut_key.rs +++ b/tests/ui/mut_key.rs @@ -29,7 +29,13 @@ impl Hash for Key { } fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> HashSet { + //~^ ERROR: mutable key type + //~| NOTE: `-D clippy::mutable-key-type` implied by `-D warnings` + //~| ERROR: mutable key type + //~| ERROR: this argument is a mutable reference, but not used mutably + //~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` let _other: HashMap = HashMap::new(); + //~^ ERROR: mutable key type m.keys().cloned().collect() } @@ -57,6 +63,7 @@ fn generics_are_ok_too(_m: &mut HashSet) { fn tuples(_m: &mut HashMap<((), U), ()>) {} fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} +//~^ ERROR: mutable key type fn main() { let _ = should_not_take_this_arg(&mut HashMap::new(), 1); @@ -69,18 +76,31 @@ fn main() { raw_mut_ptr_is_ok(&mut HashMap::new()); let _map = HashMap::, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::<&mut Cell, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::<&mut usize, usize>::new(); + //~^ ERROR: mutable key type // Collection types from `std` who's impl of `Hash` or `Ord` delegate their type parameters let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::, ()>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::, usize>::new(); + //~^ ERROR: mutable key type // Smart pointers from `std` who's impl of `Hash` or `Ord` delegate their type parameters let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type } diff --git a/tests/ui/mut_key.stderr b/tests/ui/mut_key.stderr index 3f756f5f0e598..bce9d4b589274 100644 --- a/tests/ui/mut_key.stderr +++ b/tests/ui/mut_key.stderr @@ -13,91 +13,91 @@ LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> Hash | ^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:32:5 + --> $DIR/mut_key.rs:37:5 | LL | let _other: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:59:22 + --> $DIR/mut_key.rs:65:22 | LL | fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:71:5 + --> $DIR/mut_key.rs:78:5 | LL | let _map = HashMap::, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:72:5 + --> $DIR/mut_key.rs:80:5 | LL | let _map = HashMap::<&mut Cell, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:73:5 + --> $DIR/mut_key.rs:82:5 | LL | let _map = HashMap::<&mut usize, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:75:5 + --> $DIR/mut_key.rs:85:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:76:5 + --> $DIR/mut_key.rs:87:5 | LL | let _map = HashMap::, ()>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:77:5 + --> $DIR/mut_key.rs:89:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:78:5 + --> $DIR/mut_key.rs:91:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:79:5 + --> $DIR/mut_key.rs:93:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:80:5 + --> $DIR/mut_key.rs:95:5 | LL | let _map = HashMap::>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:81:5 + --> $DIR/mut_key.rs:97:5 | LL | let _map = HashMap::, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:83:5 + --> $DIR/mut_key.rs:100:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:84:5 + --> $DIR/mut_key.rs:102:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:85:5 + --> $DIR/mut_key.rs:104:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/mut_range_bound.rs b/tests/ui/mut_range_bound.rs index 2c0d71ef0dd15..7aebbf4981ee8 100644 --- a/tests/ui/mut_range_bound.rs +++ b/tests/ui/mut_range_bound.rs @@ -6,6 +6,8 @@ fn mut_range_bound_upper() { let mut m = 4; for i in 0..m { m = 5; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged } } @@ -13,6 +15,8 @@ fn mut_range_bound_lower() { let mut m = 4; for i in m..10 { m *= 2; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged } } @@ -21,7 +25,11 @@ fn mut_range_bound_both() { let mut n = 6; for i in m..n { m = 5; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged n = 7; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged } } @@ -36,6 +44,8 @@ fn mut_borrow_range_bound() { let mut m = 4; for i in 0..m { let n = &mut m; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged *n += 1; } } @@ -69,6 +79,8 @@ fn mut_range_bound_no_immediate_break() { for i in 0..m { // warning because it is not immediately followed by break m = 2; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged if m == 4 { break; } @@ -79,6 +91,8 @@ fn mut_range_bound_no_immediate_break() { if n == 4 { // FIXME: warning because it is not immediately followed by break n = 1; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged let _ = 2; break; } diff --git a/tests/ui/mut_range_bound.stderr b/tests/ui/mut_range_bound.stderr index 6183135fc9c13..c9de5393a2b17 100644 --- a/tests/ui/mut_range_bound.stderr +++ b/tests/ui/mut_range_bound.stderr @@ -8,7 +8,7 @@ LL | m = 5; = note: `-D clippy::mut-range-bound` implied by `-D warnings` error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:15:9 + --> $DIR/mut_range_bound.rs:17:9 | LL | m *= 2; | ^ @@ -16,7 +16,7 @@ LL | m *= 2; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:23:9 + --> $DIR/mut_range_bound.rs:27:9 | LL | m = 5; | ^ @@ -24,7 +24,7 @@ LL | m = 5; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:24:9 + --> $DIR/mut_range_bound.rs:30:9 | LL | n = 7; | ^ @@ -32,7 +32,7 @@ LL | n = 7; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:38:22 + --> $DIR/mut_range_bound.rs:46:22 | LL | let n = &mut m; | ^ @@ -40,7 +40,7 @@ LL | let n = &mut m; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:71:9 + --> $DIR/mut_range_bound.rs:81:9 | LL | m = 2; | ^ @@ -48,7 +48,7 @@ LL | m = 2; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:81:13 + --> $DIR/mut_range_bound.rs:93:13 | LL | n = 1; | ^ diff --git a/tests/ui/mut_reference.rs b/tests/ui/mut_reference.rs index 80edfb261e8ef..f3db226e4e7fc 100644 --- a/tests/ui/mut_reference.rs +++ b/tests/ui/mut_reference.rs @@ -22,18 +22,24 @@ impl MyStruct { fn takes_an_immutable_reference(&self, a: &i32) {} fn takes_a_mutable_reference(&self, a: &mut i32) {} + //~^ ERROR: this argument is a mutable reference, but not used mutably + //~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` } #[warn(clippy::unnecessary_mut_passed)] fn main() { // Functions takes_an_immutable_reference(&mut 42); + //~^ ERROR: the function `takes_an_immutable_reference` doesn't need a mutable referen + //~| NOTE: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` let as_ptr: fn(&i32) = takes_an_immutable_reference; as_ptr(&mut 42); + //~^ ERROR: the function `as_ptr` doesn't need a mutable reference // Methods let my_struct = MyStruct; my_struct.takes_an_immutable_reference(&mut 42); + //~^ ERROR: the method `takes_an_immutable_reference` doesn't need a mutable reference // No error diff --git a/tests/ui/mut_reference.stderr b/tests/ui/mut_reference.stderr index d8a71d264610a..4346560cea51e 100644 --- a/tests/ui/mut_reference.stderr +++ b/tests/ui/mut_reference.stderr @@ -1,5 +1,5 @@ error: the function `takes_an_immutable_reference` doesn't need a mutable reference - --> $DIR/mut_reference.rs:30:34 + --> $DIR/mut_reference.rs:32:34 | LL | takes_an_immutable_reference(&mut 42); | ^^^^^^^ @@ -7,13 +7,13 @@ LL | takes_an_immutable_reference(&mut 42); = note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` error: the function `as_ptr` doesn't need a mutable reference - --> $DIR/mut_reference.rs:32:12 + --> $DIR/mut_reference.rs:36:12 | LL | as_ptr(&mut 42); | ^^^^^^^ error: the method `takes_an_immutable_reference` doesn't need a mutable reference - --> $DIR/mut_reference.rs:36:44 + --> $DIR/mut_reference.rs:41:44 | LL | my_struct.takes_an_immutable_reference(&mut 42); | ^^^^^^^ diff --git a/tests/ui/mutex_atomic.rs b/tests/ui/mutex_atomic.rs index 47b3dad398977..198b95d8c9486 100644 --- a/tests/ui/mutex_atomic.rs +++ b/tests/ui/mutex_atomic.rs @@ -6,12 +6,21 @@ fn main() { use std::sync::Mutex; Mutex::new(true); + //~^ ERROR: consider using an `AtomicBool` instead of a `Mutex` here; if you just want + //~| NOTE: `-D clippy::mutex-atomic` implied by `-D warnings` Mutex::new(5usize); + //~^ ERROR: consider using an `AtomicUsize` instead of a `Mutex` here; if you just wan Mutex::new(9isize); + //~^ ERROR: consider using an `AtomicIsize` instead of a `Mutex` here; if you just wan let mut x = 4u32; Mutex::new(&x as *const u32); + //~^ ERROR: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want Mutex::new(&mut x as *mut u32); + //~^ ERROR: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want Mutex::new(0u32); + //~^ ERROR: consider using an `AtomicUsize` instead of a `Mutex` here; if you just wan + //~| NOTE: `-D clippy::mutex-integer` implied by `-D warnings` Mutex::new(0i32); + //~^ ERROR: consider using an `AtomicIsize` instead of a `Mutex` here; if you just wan Mutex::new(0f32); // there are no float atomics, so this should not lint } diff --git a/tests/ui/mutex_atomic.stderr b/tests/ui/mutex_atomic.stderr index 262028a8723a3..2f669067da6fa 100644 --- a/tests/ui/mutex_atomic.stderr +++ b/tests/ui/mutex_atomic.stderr @@ -7,31 +7,31 @@ LL | Mutex::new(true); = note: `-D clippy::mutex-atomic` implied by `-D warnings` error: consider using an `AtomicUsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:9:5 + --> $DIR/mutex_atomic.rs:11:5 | LL | Mutex::new(5usize); | ^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicIsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:10:5 + --> $DIR/mutex_atomic.rs:13:5 | LL | Mutex::new(9isize); | ^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:12:5 + --> $DIR/mutex_atomic.rs:16:5 | LL | Mutex::new(&x as *const u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:13:5 + --> $DIR/mutex_atomic.rs:18:5 | LL | Mutex::new(&mut x as *mut u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicUsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:14:5 + --> $DIR/mutex_atomic.rs:20:5 | LL | Mutex::new(0u32); | ^^^^^^^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | Mutex::new(0u32); = note: `-D clippy::mutex-integer` implied by `-D warnings` error: consider using an `AtomicIsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:15:5 + --> $DIR/mutex_atomic.rs:23:5 | LL | Mutex::new(0i32); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/needless_borrow_pat.fixed b/tests/ui/needless_borrow_pat.fixed index a9091d784a7f8..8f8887f08a270 100644 --- a/tests/ui/needless_borrow_pat.fixed +++ b/tests/ui/needless_borrow_pat.fixed @@ -57,18 +57,22 @@ fn main() { // Err, reference to a &String let _: &String = match Some(&x) { Some(x) => x, + //~^ ERROR: this pattern creates a reference to a reference + //~| NOTE: `-D clippy::needless-borrow` implied by `-D warnings` None => return, }; // Err, reference to a &String. let _: &String = match Some(&x) { Some(x) => x, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _: &String = match Some(&x) { Some(x) => { + //~^ ERROR: this pattern creates a reference to a reference f1(x); f1(x); x @@ -79,16 +83,19 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(x) => m1!(x), + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _ = |&x: &&String| { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; }; // Err, reference to a &String let (y,) = (&x,); + //~^ ERROR: this pattern creates a reference to a reference let _: &String = y; let y = &&x; @@ -99,6 +106,7 @@ fn main() { // Err, reference to a &u32. Don't suggest adding a reference to the field access. let _: u32 = match Some(&x) { Some(x) => x.0, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; @@ -109,12 +117,14 @@ fn main() { // Err, reference to &u32. let _: &u32 = match E::A(&0) { E::A(x) | E::B(x) => x, + //~^ ERROR: this pattern creates a reference to a reference }; // Err, reference to &String. if_chain! { if true; if let Some(x) = Some(&String::new()); + //~^ ERROR: this pattern creates a reference to a reference then { f1(x); } @@ -123,6 +133,7 @@ fn main() { // Err, reference to a &String fn f2<'a>(&x: &&'a String) -> &'a String { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; x } @@ -130,6 +141,7 @@ fn f2<'a>(&x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; } } @@ -138,6 +150,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; } } diff --git a/tests/ui/needless_borrow_pat.rs b/tests/ui/needless_borrow_pat.rs index 222e8e617995d..56dbd923f2560 100644 --- a/tests/ui/needless_borrow_pat.rs +++ b/tests/ui/needless_borrow_pat.rs @@ -57,18 +57,22 @@ fn main() { // Err, reference to a &String let _: &String = match Some(&x) { Some(ref x) => x, + //~^ ERROR: this pattern creates a reference to a reference + //~| NOTE: `-D clippy::needless-borrow` implied by `-D warnings` None => return, }; // Err, reference to a &String. let _: &String = match Some(&x) { Some(ref x) => *x, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _: &String = match Some(&x) { Some(ref x) => { + //~^ ERROR: this pattern creates a reference to a reference f1(x); f1(*x); x @@ -79,16 +83,19 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(ref x) => m1!(x), + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _ = |&ref x: &&String| { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; }; // Err, reference to a &String let (ref y,) = (&x,); + //~^ ERROR: this pattern creates a reference to a reference let _: &String = *y; let y = &&x; @@ -99,6 +106,7 @@ fn main() { // Err, reference to a &u32. Don't suggest adding a reference to the field access. let _: u32 = match Some(&x) { Some(ref x) => x.0, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; @@ -109,12 +117,14 @@ fn main() { // Err, reference to &u32. let _: &u32 = match E::A(&0) { E::A(ref x) | E::B(ref x) => *x, + //~^ ERROR: this pattern creates a reference to a reference }; // Err, reference to &String. if_chain! { if true; if let Some(ref x) = Some(&String::new()); + //~^ ERROR: this pattern creates a reference to a reference then { f1(x); } @@ -123,6 +133,7 @@ fn main() { // Err, reference to a &String fn f2<'a>(&ref x: &&'a String) -> &'a String { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; *x } @@ -130,6 +141,7 @@ fn f2<'a>(&ref x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; } } @@ -138,6 +150,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = *x; } } diff --git a/tests/ui/needless_borrow_pat.stderr b/tests/ui/needless_borrow_pat.stderr index 2d9b8f1590213..4eac32fcd9cfa 100644 --- a/tests/ui/needless_borrow_pat.stderr +++ b/tests/ui/needless_borrow_pat.stderr @@ -7,7 +7,7 @@ LL | Some(ref x) => x, = note: `-D clippy::needless-borrow` implied by `-D warnings` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:65:14 + --> $DIR/needless_borrow_pat.rs:67:14 | LL | Some(ref x) => *x, | ^^^^^ @@ -18,7 +18,7 @@ LL | Some(x) => x, | ~ ~ error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:71:14 + --> $DIR/needless_borrow_pat.rs:74:14 | LL | Some(ref x) => { | ^^^^^ @@ -26,24 +26,25 @@ LL | Some(ref x) => { help: try | LL ~ Some(x) => { +LL | LL | f1(x); LL ~ f1(x); | error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:81:14 + --> $DIR/needless_borrow_pat.rs:85:14 | LL | Some(ref x) => m1!(x), | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:86:15 + --> $DIR/needless_borrow_pat.rs:91:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:91:10 + --> $DIR/needless_borrow_pat.rs:97:10 | LL | let (ref y,) = (&x,); | ^^^^^ @@ -51,17 +52,18 @@ LL | let (ref y,) = (&x,); help: try | LL ~ let (y,) = (&x,); +LL | LL ~ let _: &String = y; | error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:101:14 + --> $DIR/needless_borrow_pat.rs:108:14 | LL | Some(ref x) => x.0, | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:111:14 + --> $DIR/needless_borrow_pat.rs:119:14 | LL | E::A(ref x) | E::B(ref x) => *x, | ^^^^^ ^^^^^ @@ -72,13 +74,13 @@ LL | E::A(x) | E::B(x) => x, | ~ ~ ~ error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:117:21 + --> $DIR/needless_borrow_pat.rs:126:21 | LL | if let Some(ref x) = Some(&String::new()); | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:125:12 + --> $DIR/needless_borrow_pat.rs:135:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -86,18 +88,19 @@ LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { help: try | LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { +LL | LL | let _: &String = x; LL ~ x | error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:132:11 + --> $DIR/needless_borrow_pat.rs:143:11 | LL | fn f(&ref x: &&String) { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:140:11 + --> $DIR/needless_borrow_pat.rs:152:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -105,6 +108,7 @@ LL | fn f(&ref x: &&String) { help: try | LL ~ fn f(&x: &&String) { +LL | LL ~ let _: &String = x; | diff --git a/tests/ui/needless_collect_indirect.rs b/tests/ui/needless_collect_indirect.rs index 1c236a601b967..9d66c5f255fe5 100644 --- a/tests/ui/needless_collect_indirect.rs +++ b/tests/ui/needless_collect_indirect.rs @@ -7,12 +7,17 @@ use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque}; fn main() { let sample = [1; 5]; let indirect_iter = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed + //~| NOTE: `-D clippy::needless-collect` implied by `-D warnings` indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>(); let indirect_len = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len(); let indirect_empty = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed indirect_empty.is_empty(); let indirect_contains = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed indirect_contains.contains(&&5); let indirect_negative = sample.iter().collect::>(); indirect_negative.len(); @@ -25,6 +30,7 @@ fn main() { let a = "a".to_string(); let sample = vec![a.clone(), "b".to_string(), "c".to_string()]; let non_copy_contains = sample.into_iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed non_copy_contains.contains(&a); // Fix #5991 @@ -54,21 +60,25 @@ mod issue7110 { fn lint_vec(string: &str) -> usize { let buffer: Vec<&str> = string.split('/').collect(); + //~^ ERROR: avoid using `collect()` when not needed buffer.len() } fn lint_vec_deque() -> usize { let sample = [1; 5]; let indirect_len: VecDeque<_> = sample.iter().collect(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len() } fn lint_linked_list() -> usize { let sample = [1; 5]; let indirect_len: LinkedList<_> = sample.iter().collect(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len() } fn lint_binary_heap() -> usize { let sample = [1; 5]; let indirect_len: BinaryHeap<_> = sample.iter().collect(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len() } fn dont_lint(string: &str) -> usize { @@ -129,6 +139,7 @@ mod issue_8553 { for i in 0..2 { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&i); @@ -154,6 +165,7 @@ mod issue_8553 { while n > 2 { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&n); @@ -183,6 +195,7 @@ mod issue_8553 { loop { if n < 2 { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&n); @@ -219,6 +232,7 @@ mod issue_8553 { while let Some(value) = optional { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); if n < 2 { // Do lint @@ -244,6 +258,7 @@ mod issue_8553 { let vec = vec![1, 2]; let v: Vec = vec.iter().map(|i| i * i).collect(); let w = v.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed // Do lint for _ in 0..w.len() { todo!(); @@ -266,6 +281,7 @@ mod issue_8553 { let mut vec = vec![1, 2]; let mut v: Vec = vec.iter().map(|i| i * i).collect(); let mut w = v.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed // Do lint while 1 == w.len() { todo!(); @@ -288,6 +304,7 @@ mod issue_8553 { let mut vec = vec![1, 2]; let mut v: Vec = vec.iter().map(|i| i * i).collect(); let mut w = v.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed // Do lint while let Some(i) = Some(w.len()) { todo!(); diff --git a/tests/ui/needless_collect_indirect.stderr b/tests/ui/needless_collect_indirect.stderr index 8f84c5596889c..9337a7412425a 100644 --- a/tests/ui/needless_collect_indirect.stderr +++ b/tests/ui/needless_collect_indirect.stderr @@ -3,6 +3,7 @@ error: avoid using `collect()` when not needed | LL | let indirect_iter = sample.iter().collect::>(); | ^^^^^^^ +... LL | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>(); | ------------------------- the iterator could be used here instead | @@ -10,123 +11,141 @@ LL | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>( help: use the original Iterator instead of collecting it and then producing a new one | LL ~ +LL | +LL | LL ~ sample.iter().map(|x| (x, x + 1)).collect::>(); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:11:38 + --> $DIR/needless_collect_indirect.rs:13:38 | LL | let indirect_len = sample.iter().collect::>(); | ^^^^^^^ +LL | LL | indirect_len.len(); | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count(); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:13:40 + --> $DIR/needless_collect_indirect.rs:16:40 | LL | let indirect_empty = sample.iter().collect::>(); | ^^^^^^^ +LL | LL | indirect_empty.is_empty(); | ------------------------- the iterator could be used here instead | help: check if the original Iterator has anything instead of collecting it and seeing if it's empty | LL ~ +LL | LL ~ sample.iter().next().is_none(); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:15:43 + --> $DIR/needless_collect_indirect.rs:19:43 | LL | let indirect_contains = sample.iter().collect::>(); | ^^^^^^^ +LL | LL | indirect_contains.contains(&&5); | ------------------------------- the iterator could be used here instead | help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL ~ sample.iter().any(|x| x == &5); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:27:48 + --> $DIR/needless_collect_indirect.rs:32:48 | LL | let non_copy_contains = sample.into_iter().collect::>(); | ^^^^^^^ +LL | LL | non_copy_contains.contains(&a); | ------------------------------ the iterator could be used here instead | help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL ~ sample.into_iter().any(|x| x == a); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:56:51 + --> $DIR/needless_collect_indirect.rs:62:51 | LL | let buffer: Vec<&str> = string.split('/').collect(); | ^^^^^^^ +LL | LL | buffer.len() | ------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ string.split('/').count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:61:55 + --> $DIR/needless_collect_indirect.rs:68:55 | LL | let indirect_len: VecDeque<_> = sample.iter().collect(); | ^^^^^^^ +LL | LL | indirect_len.len() | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:66:57 + --> $DIR/needless_collect_indirect.rs:74:57 | LL | let indirect_len: LinkedList<_> = sample.iter().collect(); | ^^^^^^^ +LL | LL | indirect_len.len() | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:71:57 + --> $DIR/needless_collect_indirect.rs:80:57 | LL | let indirect_len: BinaryHeap<_> = sample.iter().collect(); | ^^^^^^^ +LL | LL | indirect_len.len() | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:131:59 + --> $DIR/needless_collect_indirect.rs:141:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -137,13 +156,14 @@ LL | y.contains(&i); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL | let z: Vec = vec.iter().map(|k| k * k).collect(); LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == i); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:156:59 + --> $DIR/needless_collect_indirect.rs:167:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -154,13 +174,14 @@ LL | y.contains(&n); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL | let z: Vec = vec.iter().map(|k| k * k).collect(); LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:185:63 + --> $DIR/needless_collect_indirect.rs:197:63 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -171,13 +192,14 @@ LL | y.contains(&n); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL | let z: Vec = vec.iter().map(|k| k * k).collect(); LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:221:59 + --> $DIR/needless_collect_indirect.rs:234:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -188,56 +210,59 @@ LL | y.contains(&n); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ -LL | let z: Vec = vec.iter().map(|k| k * k).collect(); -LL | if n < 2 { +LL | + ... LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:246:26 + --> $DIR/needless_collect_indirect.rs:260:26 | LL | let w = v.iter().collect::>(); | ^^^^^^^ -LL | // Do lint +... LL | for _ in 0..w.len() { | ------- the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL | // Do lint LL ~ for _ in 0..v.iter().count() { | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:268:30 + --> $DIR/needless_collect_indirect.rs:283:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ -LL | // Do lint +... LL | while 1 == w.len() { | ------- the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL | // Do lint LL ~ while 1 == v.iter().count() { | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:290:30 + --> $DIR/needless_collect_indirect.rs:306:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ -LL | // Do lint +... LL | while let Some(i) = Some(w.len()) { | ------- the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL | // Do lint LL ~ while let Some(i) = Some(v.iter().count()) { | diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index 12e6c7deb9c20..c26a292c8cb57 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -28,6 +28,7 @@ fn main() { let i = 0; println!("bar {} ", i); } else { + //~^ ERROR: this `else` block is redundant continue; } @@ -43,6 +44,7 @@ fn main() { } if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + //~^ ERROR: there is no need for an explicit `else` block for this `if` expression continue; } else { println!("Blabber"); @@ -56,6 +58,7 @@ fn main() { fn simple_loop() { loop { continue; + //~^ ERROR: this `continue` expression is redundant } } @@ -63,6 +66,7 @@ fn simple_loop2() { loop { println!("bleh"); continue; + //~^ ERROR: this `continue` expression is redundant } } @@ -70,6 +74,7 @@ fn simple_loop2() { fn simple_loop3() { loop { continue + //~^ ERROR: this `continue` expression is redundant } } @@ -78,6 +83,7 @@ fn simple_loop4() { loop { println!("bleh"); continue + //~^ ERROR: this `continue` expression is redundant } } @@ -128,12 +134,14 @@ mod issue_2329 { if condition() { println!("bar-3"); } else { + //~^ ERROR: this `else` block is redundant continue 'inner; } println!("bar-4"); update_condition(); if condition() { + //~^ ERROR: there is no need for an explicit `else` block for this `if` ex continue; } else { println!("bar-5"); diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index 7f9f644643f97..9a65248c9913f 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -3,6 +3,7 @@ error: this `else` block is redundant | LL | } else { | ________________^ +LL | | LL | | continue; LL | | } | |_________^ @@ -25,6 +26,7 @@ LL | | } println!("lama"); } if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + continue; } else { println!("Blabber"); @@ -35,9 +37,10 @@ LL | | } = note: `-D clippy::needless-continue` implied by `-D warnings` error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:45:9 + --> $DIR/needless_continue.rs:46:9 | LL | / if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { +LL | | LL | | continue; LL | | } else { LL | | println!("Blabber"); @@ -47,6 +50,7 @@ LL | | } | = help: consider dropping the `else` clause if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + continue; } { @@ -55,7 +59,7 @@ LL | | } } error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:58:9 + --> $DIR/needless_continue.rs:60:9 | LL | continue; | ^^^^^^^^^ @@ -63,7 +67,7 @@ LL | continue; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:65:9 + --> $DIR/needless_continue.rs:68:9 | LL | continue; | ^^^^^^^^^ @@ -71,7 +75,7 @@ LL | continue; = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:72:9 + --> $DIR/needless_continue.rs:76:9 | LL | continue | ^^^^^^^^ @@ -79,7 +83,7 @@ LL | continue = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:80:9 + --> $DIR/needless_continue.rs:85:9 | LL | continue | ^^^^^^^^ @@ -87,10 +91,11 @@ LL | continue = help: consider dropping the `continue` expression error: this `else` block is redundant - --> $DIR/needless_continue.rs:130:24 + --> $DIR/needless_continue.rs:136:24 | LL | } else { | ________________________^ +LL | | LL | | continue 'inner; LL | | } | |_________________^ @@ -102,6 +107,7 @@ LL | | } println!("bar-4"); update_condition(); if condition() { + continue; } else { println!("bar-5"); @@ -110,9 +116,10 @@ LL | | } } error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:136:17 + --> $DIR/needless_continue.rs:143:17 | LL | / if condition() { +LL | | LL | | continue; LL | | } else { LL | | println!("bar-5"); @@ -121,6 +128,7 @@ LL | | } | = help: consider dropping the `else` clause if condition() { + continue; } { diff --git a/tests/ui/needless_doc_main.rs b/tests/ui/needless_doc_main.rs index 83e9bbaa3af43..d31b9047eaaeb 100644 --- a/tests/ui/needless_doc_main.rs +++ b/tests/ui/needless_doc_main.rs @@ -5,27 +5,32 @@ /// This should lint /// ``` /// fn main() { +//~^ ERROR: needless `fn main` in doctest +//~| NOTE: `-D clippy::needless-doctest-main` implied by `-D warnings` /// unimplemented!(); /// } /// ``` -/// +/// /// With an explicit return type it should lint too /// ```edition2015 /// fn main() -> () { +//~^ ERROR: needless `fn main` in doctest /// unimplemented!(); /// } /// ``` -/// +/// /// This should, too. /// ```rust /// fn main() { +//~^ ERROR: needless `fn main` in doctest /// unimplemented!(); /// } /// ``` -/// +/// /// This one too. /// ```no_run /// fn main() { +//~^ ERROR: needless `fn main` in doctest /// unimplemented!(); /// } /// ``` diff --git a/tests/ui/needless_doc_main.stderr b/tests/ui/needless_doc_main.stderr index 05c7f9d33a792..be6675e6482e0 100644 --- a/tests/ui/needless_doc_main.stderr +++ b/tests/ui/needless_doc_main.stderr @@ -7,19 +7,19 @@ LL | /// fn main() { = note: `-D clippy::needless-doctest-main` implied by `-D warnings` error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:14:4 + --> $DIR/needless_doc_main.rs:16:4 | LL | /// fn main() -> () { | ^^^^^^^^^^^^^^^^^^ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:21:4 + --> $DIR/needless_doc_main.rs:24:4 | LL | /// fn main() { | ^^^^^^^^^^^^ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:28:4 + --> $DIR/needless_doc_main.rs:32:4 | LL | /// fn main() { | ^^^^^^^^^^^^ diff --git a/tests/ui/needless_for_each_unfixable.rs b/tests/ui/needless_for_each_unfixable.rs index 588d7cb070c70..2220cf9e11eef 100644 --- a/tests/ui/needless_for_each_unfixable.rs +++ b/tests/ui/needless_for_each_unfixable.rs @@ -6,6 +6,8 @@ fn main() { let v: Vec = Vec::new(); // This is unfixable because the closure includes `return`. v.iter().for_each(|v| { + //~^ ERROR: needless use of `for_each` + //~| NOTE: `-D clippy::needless-for-each` implied by `-D warnings` if *v == 10 { return; } else { diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index 9c7f3d47121d0..dad0053f5591b 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -2,10 +2,10 @@ error: needless use of `for_each` --> $DIR/needless_for_each_unfixable.rs:8:5 | LL | / v.iter().for_each(|v| { +LL | | +LL | | LL | | if *v == 10 { -LL | | return; -LL | | } else { -LL | | println!("{}", v); +... | LL | | } LL | | }); | |_______^ @@ -14,6 +14,8 @@ LL | | }); help: try | LL ~ for v in v.iter() { +LL + +LL + LL + if *v == 10 { LL + return; LL + } else { diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index ce4bc9286bef0..14cba5a7eb520 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -16,6 +16,8 @@ use std::mem::MaybeUninit; // `v` should be warned // `w`, `x` and `y` are allowed (moved or mutated) fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| NOTE: `-D clippy::needless-pass-by-value` implied by `-D warnings` assert_eq!(v.len(), 42); consume(w); @@ -30,12 +32,15 @@ fn consume(_: T) {} struct Wrapper(String); fn bar(x: String, y: Wrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body assert_eq!(x.len(), 42); assert_eq!(y.0.len(), 42); } // V implements `Borrow`, but should be warned correctly 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 println!("{}", t.borrow()); println!("{}", u.as_ref()); consume(&v); @@ -48,6 +53,7 @@ fn test_fn i32>(f: F) { // x should be warned, but y is ok fn test_match(x: Option>, y: Option>) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body match x { Some(Some(_)) => 1, // not moved _ => 0, @@ -61,6 +67,8 @@ fn test_match(x: Option>, y: Option>) { // x and y should be warned, but z is ok fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body let Wrapper(s) = z; // moved let Wrapper(ref t) = y; // not moved let Wrapper(_) = y; // still not moved @@ -77,8 +85,13 @@ impl<'a, T> Serialize for &'a T where T: Serialize {} impl Serialize for i32 {} fn test_blanket_ref(_foo: T, _serializable: S) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body 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 + //~| ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body s.capacity(); let _ = t.clone(); u.capacity(); @@ -92,7 +105,9 @@ impl S { self, // taking `self` by value is always allowed s: String, + //~^ ERROR: this argument is passed by value, but not consumed in the function bod t: String, + //~^ ERROR: this argument is passed by value, but not consumed in the function bod ) -> usize { s.len() + t.capacity() } @@ -102,6 +117,8 @@ impl S { } fn baz(&self, _u: U, _s: Self) {} + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body } trait FalsePositive { @@ -124,12 +141,16 @@ fn range>(range: T) { struct CopyWrapper(u32); fn bar_copy(x: u32, y: CopyWrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body assert_eq!(x, 42); assert_eq!(y.0, 42); } // x and y should be warned, but z is ok fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body let CopyWrapper(s) = z; // moved let CopyWrapper(ref t) = y; // not moved let CopyWrapper(_) = y; // still not moved @@ -142,11 +163,13 @@ fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { trait Bar<'a, A> {} impl<'b, T> Bar<'b, T> for T {} fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body // Also this should not cause an ICE. See #2831 trait Club<'a, A> {} impl Club<'static, T> for T {} fn more_fun(_item: impl Club<'static, i32>) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn is_sync(_: T) where diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 0e660a77dc0cc..a6bf30b1cdfb4 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -7,55 +7,55 @@ LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec $DIR/needless_pass_by_value.rs:32:11 + --> $DIR/needless_pass_by_value.rs:34: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 - --> $DIR/needless_pass_by_value.rs:32:22 + --> $DIR/needless_pass_by_value.rs:34:22 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:38:71 + --> $DIR/needless_pass_by_value.rs:42:71 | LL | fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { | ^ help: consider taking a reference instead: `&V` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:50:18 + --> $DIR/needless_pass_by_value.rs:55:18 | LL | fn test_match(x: Option>, y: Option>) { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option>` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:63:24 + --> $DIR/needless_pass_by_value.rs:69:24 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:63:36 + --> $DIR/needless_pass_by_value.rs:69:36 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:79:49 + --> $DIR/needless_pass_by_value.rs:87:49 | LL | fn test_blanket_ref(_foo: T, _serializable: S) {} | ^ help: consider taking a reference instead: `&T` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:18 + --> $DIR/needless_pass_by_value.rs:90:18 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:29 + --> $DIR/needless_pass_by_value.rs:90:29 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ @@ -70,13 +70,13 @@ LL | let _ = t.to_string(); | ~~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:40 + --> $DIR/needless_pass_by_value.rs:90:40 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ help: consider taking a reference instead: `&Vec` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:53 + --> $DIR/needless_pass_by_value.rs:90:53 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ @@ -91,85 +91,85 @@ LL | let _ = v.to_owned(); | ~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:94:12 + --> $DIR/needless_pass_by_value.rs:107: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 - --> $DIR/needless_pass_by_value.rs:95:12 + --> $DIR/needless_pass_by_value.rs:109:12 | LL | t: String, | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:104:23 + --> $DIR/needless_pass_by_value.rs:119:23 | LL | fn baz(&self, _u: U, _s: Self) {} | ^ help: consider taking a reference instead: `&U` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:104:30 + --> $DIR/needless_pass_by_value.rs:119:30 | LL | fn baz(&self, _u: U, _s: Self) {} | ^^^^ help: consider taking a reference instead: `&Self` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:126:24 + --> $DIR/needless_pass_by_value.rs:143:24 | LL | fn bar_copy(x: u32, y: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:29 + --> $DIR/needless_pass_by_value.rs:150:29 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:45 + --> $DIR/needless_pass_by_value.rs:150:45 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:61 + --> $DIR/needless_pass_by_value.rs:150:61 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:144:40 + --> $DIR/needless_pass_by_value.rs:165:40 | LL | fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {} | ^ help: consider taking a reference instead: `&S` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:149:20 + --> $DIR/needless_pass_by_value.rs:171:20 | LL | fn more_fun(_item: impl Club<'static, i32>) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>` diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs index 7457a93c5f559..3f2421953301e 100644 --- a/tests/ui/needless_range_loop.rs +++ b/tests/ui/needless_range_loop.rs @@ -13,6 +13,8 @@ fn main() { let mut vec = vec![1, 2, 3, 4]; let vec2 = vec![1, 2, 3, 4]; for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec` + //~| NOTE: `-D clippy::needless-range-loop` implied by `-D warnings` println!("{}", vec[i]); } @@ -22,19 +24,23 @@ fn main() { } for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec` let _ = vec[i]; } // ICE #746 for j in 0..4 { + //~^ ERROR: the loop variable `j` is only used to index `STATIC` println!("{:?}", STATIC[j]); } for j in 0..4 { + //~^ ERROR: the loop variable `j` is only used to index `CONST` println!("{:?}", CONST[j]); } for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is used to index `vec` println!("{} {}", vec[i], i); } for i in 0..vec.len() { @@ -43,39 +49,48 @@ fn main() { } for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec2` println!("{}", vec2[i]); } for i in 5..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 0..MAX_LEN { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 0..=MAX_LEN { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 5..10 { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 5..=10 { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 5..vec.len() { + //~^ ERROR: the loop variable `i` is used to index `vec` println!("{} {}", vec[i], i); } for i in 5..10 { + //~^ ERROR: the loop variable `i` is used to index `vec` println!("{} {}", vec[i], i); } // #2542 for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is used to index `vec` vec[i] = Some(1).unwrap_or_else(|| panic!("error on {}", i)); } diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr index 8ca6b880ceae7..0358b2fb0251a 100644 --- a/tests/ui/needless_range_loop.stderr +++ b/tests/ui/needless_range_loop.stderr @@ -11,7 +11,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:24:14 + --> $DIR/needless_range_loop.rs:26:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `j` is only used to index `STATIC` - --> $DIR/needless_range_loop.rs:29:14 + --> $DIR/needless_range_loop.rs:32:14 | LL | for j in 0..4 { | ^^^^ @@ -33,7 +33,7 @@ LL | for in &STATIC { | ~~~~~~ ~~~~~~~ error: the loop variable `j` is only used to index `CONST` - --> $DIR/needless_range_loop.rs:33:14 + --> $DIR/needless_range_loop.rs:37:14 | LL | for j in 0..4 { | ^^^^ @@ -44,7 +44,7 @@ LL | for in &CONST { | ~~~~~~ ~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:37:14 + --> $DIR/needless_range_loop.rs:42:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | for (i, ) in vec.iter().enumerate() { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec2` - --> $DIR/needless_range_loop.rs:45:14 + --> $DIR/needless_range_loop.rs:51:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -66,7 +66,7 @@ LL | for in vec2.iter().take(vec.len()) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:49:14 + --> $DIR/needless_range_loop.rs:56:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -77,7 +77,7 @@ LL | for in vec.iter().skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:53:14 + --> $DIR/needless_range_loop.rs:61:14 | LL | for i in 0..MAX_LEN { | ^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | for in vec.iter().take(MAX_LEN) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:57:14 + --> $DIR/needless_range_loop.rs:66:14 | LL | for i in 0..=MAX_LEN { | ^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | for in vec.iter().take(MAX_LEN + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:61:14 + --> $DIR/needless_range_loop.rs:71:14 | LL | for i in 5..10 { | ^^^^^ @@ -110,7 +110,7 @@ LL | for in vec.iter().take(10).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:65:14 + --> $DIR/needless_range_loop.rs:76:14 | LL | for i in 5..=10 { | ^^^^^^ @@ -121,7 +121,7 @@ LL | for in vec.iter().take(10 + 1).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:69:14 + --> $DIR/needless_range_loop.rs:81:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL | for (i, ) in vec.iter().enumerate().skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:73:14 + --> $DIR/needless_range_loop.rs:86:14 | LL | for i in 5..10 { | ^^^^^ @@ -143,7 +143,7 @@ LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:78:14 + --> $DIR/needless_range_loop.rs:92:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ diff --git a/tests/ui/needless_range_loop2.rs b/tests/ui/needless_range_loop2.rs index 66cd15401f922..787ff18f338d2 100644 --- a/tests/ui/needless_range_loop2.rs +++ b/tests/ui/needless_range_loop2.rs @@ -9,6 +9,8 @@ fn main() { let ns = vec![2, 3, 5, 7]; for i in 3..10 { + //~^ ERROR: the loop variable `i` is only used to index `ns` + //~| NOTE: `-D clippy::needless-range-loop` implied by `-D warnings` println!("{}", ns[i]); } @@ -30,12 +32,14 @@ fn main() { let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { + //~^ ERROR: the loop variable `i` is only used to index `ms` ms[i] *= 2; } assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]); let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { + //~^ ERROR: the loop variable `i` is only used to index `ms` let x = &mut ms[i]; *x *= 2; } @@ -60,6 +64,7 @@ fn main() { let mut vec = vec![0; 9]; for i in x..x + 4 { + //~^ ERROR: the loop variable `i` is only used to index `vec` vec[i] += 1; } @@ -67,20 +72,24 @@ fn main() { let mut vec = vec![0; 10]; for i in x..=x + 4 { + //~^ ERROR: the loop variable `i` is only used to index `vec` vec[i] += 1; } let arr = [1, 2, 3]; for i in 0..3 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } for i in 0..2 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } for i in 1..3 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } diff --git a/tests/ui/needless_range_loop2.stderr b/tests/ui/needless_range_loop2.stderr index 8c4f5d954a975..6e6ef73c1f6e8 100644 --- a/tests/ui/needless_range_loop2.stderr +++ b/tests/ui/needless_range_loop2.stderr @@ -11,7 +11,7 @@ LL | for in ns.iter().take(10).skip(3) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> $DIR/needless_range_loop2.rs:32:14 + --> $DIR/needless_range_loop2.rs:34:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> $DIR/needless_range_loop2.rs:38:14 + --> $DIR/needless_range_loop2.rs:41:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop2.rs:62:14 + --> $DIR/needless_range_loop2.rs:66:14 | LL | for i in x..x + 4 { | ^^^^^^^^ @@ -44,7 +44,7 @@ LL | for in vec.iter_mut().skip(x).take(4) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop2.rs:69:14 + --> $DIR/needless_range_loop2.rs:74:14 | LL | for i in x..=x + 4 { | ^^^^^^^^^ @@ -55,7 +55,7 @@ LL | for in vec.iter_mut().skip(x).take(4 + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> $DIR/needless_range_loop2.rs:75:14 + --> $DIR/needless_range_loop2.rs:81:14 | LL | for i in 0..3 { | ^^^^ @@ -66,7 +66,7 @@ LL | for in &arr { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `arr` - --> $DIR/needless_range_loop2.rs:79:14 + --> $DIR/needless_range_loop2.rs:86:14 | LL | for i in 0..2 { | ^^^^ @@ -77,7 +77,7 @@ LL | for in arr.iter().take(2) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> $DIR/needless_range_loop2.rs:83:14 + --> $DIR/needless_range_loop2.rs:91:14 | LL | for i in 1..3 { | ^^^^ diff --git a/tests/ui/needless_update.rs b/tests/ui/needless_update.rs index 4e8517cad1006..7c59abf07aba9 100644 --- a/tests/ui/needless_update.rs +++ b/tests/ui/needless_update.rs @@ -17,6 +17,8 @@ fn main() { S { ..base }; // no error S { a: 1, ..base }; // no error S { a: 1, b: 1, ..base }; + //~^ ERROR: struct update has no effect, all the fields in the struct have already bee + //~| NOTE: `-D clippy::needless-update` implied by `-D warnings` let base = T { x: 0, y: 0 }; T { ..base }; // no error diff --git a/tests/ui/neg_cmp_op_on_partial_ord.rs b/tests/ui/neg_cmp_op_on_partial_ord.rs index 2d392c593b3e7..c79fd26652601 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.rs +++ b/tests/ui/neg_cmp_op_on_partial_ord.rs @@ -14,15 +14,20 @@ fn main() { // Not Less but potentially Greater, Equal or Uncomparable. let _not_less = !(a_value < another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce + //~| NOTE: `-D clippy::neg-cmp-op-on-partial-ord` implied by `-D warnings` // Not Less or Equal but potentially Greater or Uncomparable. let _not_less_or_equal = !(a_value <= another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce // Not Greater but potentially Less, Equal or Uncomparable. let _not_greater = !(a_value > another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce // Not Greater or Equal but potentially Less or Uncomparable. let _not_greater_or_equal = !(a_value >= another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce // --- Good --- diff --git a/tests/ui/neg_cmp_op_on_partial_ord.stderr b/tests/ui/neg_cmp_op_on_partial_ord.stderr index c78560007217d..c2e1f8702ddeb 100644 --- a/tests/ui/neg_cmp_op_on_partial_ord.stderr +++ b/tests/ui/neg_cmp_op_on_partial_ord.stderr @@ -7,19 +7,19 @@ LL | let _not_less = !(a_value < another_value); = note: `-D clippy::neg-cmp-op-on-partial-ord` implied by `-D warnings` error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:19:30 + --> $DIR/neg_cmp_op_on_partial_ord.rs:21:30 | LL | let _not_less_or_equal = !(a_value <= another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:22:24 + --> $DIR/neg_cmp_op_on_partial_ord.rs:25:24 | LL | let _not_greater = !(a_value > another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:25:33 + --> $DIR/neg_cmp_op_on_partial_ord.rs:29:33 | LL | let _not_greater_or_equal = !(a_value >= another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/never_loop.rs b/tests/ui/never_loop.rs index 22ff1c35b30f9..001b94391ca81 100644 --- a/tests/ui/never_loop.rs +++ b/tests/ui/never_loop.rs @@ -10,6 +10,8 @@ fn test1() { let mut x = 0; loop { + //~^ ERROR: this loop never actually loops + //~| NOTE: `#[deny(clippy::never_loop)]` on by default // clippy::never_loop x += 1; if x == 1 { @@ -32,6 +34,7 @@ fn test2() { fn test3() { let mut x = 0; loop { + //~^ ERROR: this loop never actually loops // never loops x += 1; break; @@ -52,8 +55,10 @@ fn test4() { fn test5() { let i = 0; loop { + //~^ ERROR: this loop never actually loops // never loops while i == 0 { + //~^ ERROR: this loop never actually loops // never loops break; } @@ -66,6 +71,7 @@ fn test6() { 'outer: loop { x += 1; loop { + //~^ ERROR: this loop never actually loops // never loops if x == 5 { break; @@ -102,6 +108,7 @@ fn test8() { fn test9() { let x = Some(1); while let Some(y) = x { + //~^ ERROR: this loop never actually loops // never loops return; } @@ -109,6 +116,7 @@ fn test9() { fn test10() { for x in 0..10 { + //~^ ERROR: this loop never actually loops // never loops match x { 1 => break, @@ -157,6 +165,7 @@ pub fn test13() { pub fn test14() { let mut a = true; 'outer: while a { + //~^ ERROR: this loop never actually loops // never loops while a { if a { @@ -172,6 +181,7 @@ pub fn test14() { pub fn test15() { 'label: loop { while false { + //~^ ERROR: this loop never actually loops break 'label; } } @@ -223,6 +233,7 @@ pub fn test18() { }; // never loops let _ = loop { + //~^ ERROR: this loop never actually loops let Some(x) = x else { return; }; @@ -244,9 +255,12 @@ pub fn test19() { pub fn test20() { 'a: loop { + //~^ ERROR: this loop never actually loops 'b: { break 'b 'c: { break 'a; + //~^ ERROR: sub-expression diverges + //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` }; } } @@ -278,6 +292,7 @@ pub fn test23() { for _ in 0..10 { 'block: { for _ in 0..20 { + //~^ ERROR: this loop never actually loops break 'block; } } @@ -322,6 +337,7 @@ pub fn test26() { pub fn test27() { loop { + //~^ ERROR: this loop never actually loops 'label: { let x = true; // Lints because we cannot prove it's always `true` diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index 0446c09cd5bcc..6d6d2c8ac52e0 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -2,9 +2,9 @@ error: this loop never actually loops --> $DIR/never_loop.rs:12:5 | LL | / loop { +LL | | +LL | | LL | | // clippy::never_loop -LL | | x += 1; -LL | | if x == 1 { ... | LL | | break; LL | | } @@ -13,9 +13,10 @@ LL | | } = note: `#[deny(clippy::never_loop)]` on by default error: this loop never actually loops - --> $DIR/never_loop.rs:34:5 + --> $DIR/never_loop.rs:36:5 | LL | / loop { +LL | | LL | | // never loops LL | | x += 1; LL | | break; @@ -23,55 +24,57 @@ LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:54:5 + --> $DIR/never_loop.rs:57:5 | LL | / loop { +LL | | LL | | // never loops LL | | while i == 0 { -LL | | // never loops ... | LL | | return; LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:56:9 + --> $DIR/never_loop.rs:60:9 | LL | / while i == 0 { +LL | | LL | | // never loops LL | | break; LL | | } | |_________^ error: this loop never actually loops - --> $DIR/never_loop.rs:68:9 + --> $DIR/never_loop.rs:73:9 | LL | / loop { +LL | | LL | | // never loops LL | | if x == 5 { -LL | | break; -LL | | } +... | LL | | continue 'outer; LL | | } | |_________^ error: this loop never actually loops - --> $DIR/never_loop.rs:104:5 + --> $DIR/never_loop.rs:110:5 | LL | / while let Some(y) = x { +LL | | LL | | // never loops LL | | return; LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:111:5 + --> $DIR/never_loop.rs:118:5 | LL | / for x in 0..10 { +LL | | LL | | // never loops LL | | match x { -LL | | 1 => break, -LL | | _ => return, +... | LL | | } LL | | } | |_____^ @@ -82,52 +85,53 @@ LL | if let Some(x) = (0..10).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> $DIR/never_loop.rs:159:5 + --> $DIR/never_loop.rs:167:5 | LL | / 'outer: while a { +LL | | LL | | // never loops LL | | while a { -LL | | if a { ... | LL | | break 'outer; LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:174:9 + --> $DIR/never_loop.rs:183:9 | LL | / while false { +LL | | LL | | break 'label; LL | | } | |_________^ error: this loop never actually loops - --> $DIR/never_loop.rs:225:13 + --> $DIR/never_loop.rs:235:13 | LL | let _ = loop { | _____________^ +LL | | LL | | let Some(x) = x else { LL | | return; -LL | | }; -LL | | +... | LL | | break x; LL | | }; | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:246:5 + --> $DIR/never_loop.rs:257:5 | LL | / 'a: loop { +LL | | LL | | 'b: { LL | | break 'b 'c: { -LL | | break 'a; -LL | | }; +... | LL | | } LL | | } | |_____^ error: sub-expression diverges - --> $DIR/never_loop.rs:249:17 + --> $DIR/never_loop.rs:261:17 | LL | break 'a; | ^^^^^^^^ @@ -135,9 +139,10 @@ LL | break 'a; = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` error: this loop never actually loops - --> $DIR/never_loop.rs:280:13 + --> $DIR/never_loop.rs:294:13 | LL | / for _ in 0..20 { +LL | | LL | | break 'block; LL | | } | |_____________^ @@ -148,12 +153,12 @@ LL | if let Some(_) = (0..20).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> $DIR/never_loop.rs:324:5 + --> $DIR/never_loop.rs:339:5 | LL | / loop { +LL | | LL | | 'label: { LL | | let x = true; -LL | | // Lints because we cannot prove it's always `true` ... | LL | | } LL | | } diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index 4eff62b85ff68..b944f531ef660 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -48,6 +48,8 @@ impl R for S3 { impl S3 { // should trigger the lint pub fn new(_: String) -> impl R { + //~^ ERROR: methods called `new` usually return `Self` + //~| NOTE: `-D clippy::new-ret-no-self` implied by `-D warnings` S3 } } @@ -80,6 +82,7 @@ struct U; impl U { // should trigger lint pub fn new() -> u32 { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -89,6 +92,7 @@ struct V; impl V { // should trigger lint pub fn new(_: String) -> u32 { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -125,6 +129,7 @@ struct TupleReturnerBad; impl TupleReturnerBad { // should trigger lint pub fn new() -> (u32, u32) { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -152,6 +157,7 @@ struct MutPointerReturnerBad; impl MutPointerReturnerBad { // should trigger lint pub fn new() -> *mut V { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -170,6 +176,7 @@ struct GenericReturnerBad; impl GenericReturnerBad { // should trigger lint pub fn new() -> Option { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -223,6 +230,7 @@ mod issue5435 { pub trait TraitRet { // should trigger lint as we are in trait definition fn new() -> String; + //~^ ERROR: methods called `new` usually return `Self` } pub struct StructRet; impl TraitRet for StructRet { @@ -235,6 +243,7 @@ mod issue5435 { pub trait TraitRet2 { // should trigger lint fn new(_: String) -> String; + //~^ ERROR: methods called `new` usually return `Self` } trait TupleReturnerOk { @@ -270,6 +279,7 @@ mod issue5435 { trait TupleReturnerBad { // should trigger lint fn new() -> (u32, u32) { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -297,6 +307,7 @@ mod issue5435 { trait MutPointerReturnerBad { // should trigger lint fn new() -> *mut V { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -367,6 +378,7 @@ mod issue7344 { impl RetImplTraitNoSelf { // should trigger lint fn new(t: T) -> impl Into { + //~^ ERROR: methods called `new` usually return `Self` 1 } } @@ -388,6 +400,7 @@ mod issue7344 { impl RetImplTraitNoSelf2 { // should trigger lint fn new(t: T) -> impl Trait2<(), i32> { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!() } } diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index 2b053b462b164..4c76603f596d8 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -2,6 +2,8 @@ error: methods called `new` usually return `Self` --> $DIR/new_ret_no_self.rs:50:5 | LL | / pub fn new(_: String) -> impl R { +LL | | +LL | | LL | | S3 LL | | } | |_____^ @@ -9,85 +11,94 @@ LL | | } = note: `-D clippy::new-ret-no-self` implied by `-D warnings` error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:82:5 + --> $DIR/new_ret_no_self.rs:84:5 | LL | / pub fn new() -> u32 { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:91:5 + --> $DIR/new_ret_no_self.rs:94:5 | LL | / pub fn new(_: String) -> u32 { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:127:5 + --> $DIR/new_ret_no_self.rs:131:5 | LL | / pub fn new() -> (u32, u32) { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:154:5 + --> $DIR/new_ret_no_self.rs:159:5 | LL | / pub fn new() -> *mut V { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:172:5 + --> $DIR/new_ret_no_self.rs:178:5 | LL | / pub fn new() -> Option { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:225:9 + --> $DIR/new_ret_no_self.rs:232:9 | LL | fn new() -> String; | ^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:237:9 + --> $DIR/new_ret_no_self.rs:245:9 | LL | fn new(_: String) -> String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:272:9 + --> $DIR/new_ret_no_self.rs:281:9 | LL | / fn new() -> (u32, u32) { +LL | | LL | | unimplemented!(); LL | | } | |_________^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:299:9 + --> $DIR/new_ret_no_self.rs:309:9 | LL | / fn new() -> *mut V { +LL | | LL | | unimplemented!(); LL | | } | |_________^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:369:9 + --> $DIR/new_ret_no_self.rs:380:9 | LL | / fn new(t: T) -> impl Into { +LL | | LL | | 1 LL | | } | |_________^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:390:9 + --> $DIR/new_ret_no_self.rs:402:9 | LL | / fn new(t: T) -> impl Trait2<(), i32> { +LL | | LL | | unimplemented!() LL | | } | |_________^ diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed index 56359a4cbc3cf..1c7ba1a48c90d 100644 --- a/tests/ui/new_without_default.fixed +++ b/tests/ui/new_without_default.fixed @@ -16,6 +16,8 @@ impl Default for Foo { impl Foo { pub fn new() -> Foo { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` + //~| NOTE: `-D clippy::new-without-default` implied by `-D warnings` Foo } } @@ -30,6 +32,7 @@ impl Default for Bar { impl Bar { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Bar` Bar } } @@ -100,6 +103,7 @@ impl<'c> Default for LtKo<'c> { impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { + //~^ ERROR: you should consider adding a `Default` implementation for `LtKo<'c>` unimplemented!() } } @@ -198,6 +202,7 @@ impl Default for NewNotEqualToDerive { impl NewNotEqualToDerive { // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving. pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `NewNotEqualToDe NewNotEqualToDerive { foo: 1 } } } @@ -212,6 +217,7 @@ impl Default for FooGenerics { impl FooGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `FooGenerics` Self(Default::default()) } } @@ -225,6 +231,7 @@ impl Default for BarGenerics { impl BarGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `BarGenerics` Self(Default::default()) } } @@ -242,6 +249,7 @@ pub mod issue7220 { impl Foo { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` todo!() } } diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index bbd7a51d6b984..964aa0f63da8e 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -10,6 +10,8 @@ pub struct Foo; impl Foo { pub fn new() -> Foo { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` + //~| NOTE: `-D clippy::new-without-default` implied by `-D warnings` Foo } } @@ -18,6 +20,7 @@ pub struct Bar; impl Bar { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Bar` Bar } } @@ -82,6 +85,7 @@ pub struct LtKo<'a> { impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { + //~^ ERROR: you should consider adding a `Default` implementation for `LtKo<'c>` unimplemented!() } } @@ -174,6 +178,7 @@ pub struct NewNotEqualToDerive { impl NewNotEqualToDerive { // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving. pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `NewNotEqualToDe NewNotEqualToDerive { foo: 1 } } } @@ -182,6 +187,7 @@ impl NewNotEqualToDerive { pub struct FooGenerics(std::marker::PhantomData); impl FooGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `FooGenerics` Self(Default::default()) } } @@ -189,6 +195,7 @@ impl FooGenerics { pub struct BarGenerics(std::marker::PhantomData); impl BarGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `BarGenerics` Self(Default::default()) } } @@ -200,6 +207,7 @@ pub mod issue7220 { impl Foo { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` todo!() } } diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index 61973abcde88c..4293cd5972df7 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -2,6 +2,8 @@ error: you should consider adding a `Default` implementation for `Foo` --> $DIR/new_without_default.rs:12:5 | LL | / pub fn new() -> Foo { +LL | | +LL | | LL | | Foo LL | | } | |_____^ @@ -17,9 +19,10 @@ LL + } | error: you should consider adding a `Default` implementation for `Bar` - --> $DIR/new_without_default.rs:20:5 + --> $DIR/new_without_default.rs:22:5 | LL | / pub fn new() -> Self { +LL | | LL | | Bar LL | | } | |_____^ @@ -34,9 +37,10 @@ LL + } | error: you should consider adding a `Default` implementation for `LtKo<'c>` - --> $DIR/new_without_default.rs:84:5 + --> $DIR/new_without_default.rs:87:5 | LL | / pub fn new() -> LtKo<'c> { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -51,9 +55,10 @@ LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> $DIR/new_without_default.rs:176:5 + --> $DIR/new_without_default.rs:180:5 | LL | / pub fn new() -> Self { +LL | | LL | | NewNotEqualToDerive { foo: 1 } LL | | } | |_____^ @@ -68,9 +73,10 @@ LL + } | error: you should consider adding a `Default` implementation for `FooGenerics` - --> $DIR/new_without_default.rs:184:5 + --> $DIR/new_without_default.rs:189:5 | LL | / pub fn new() -> Self { +LL | | LL | | Self(Default::default()) LL | | } | |_____^ @@ -85,9 +91,10 @@ LL + } | error: you should consider adding a `Default` implementation for `BarGenerics` - --> $DIR/new_without_default.rs:191:5 + --> $DIR/new_without_default.rs:197:5 | LL | / pub fn new() -> Self { +LL | | LL | | Self(Default::default()) LL | | } | |_____^ @@ -102,9 +109,10 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo` - --> $DIR/new_without_default.rs:202:9 + --> $DIR/new_without_default.rs:209:9 | LL | / pub fn new() -> Self { +LL | | LL | | todo!() LL | | } | |_________^ @@ -121,7 +129,7 @@ LL ~ impl Foo { | error: you should consider adding a `Default` implementation for `MyStruct` - --> $DIR/new_without_default.rs:247:5 + --> $DIR/new_without_default.rs:255:5 | LL | / pub fn new() -> Self { LL | | Self { _kv: None } diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index 6a726941be893..c52f4389192fd 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -96,36 +96,67 @@ fn main() { let s2 = get_struct(); 0; + //~^ ERROR: statement with no effect + //~| NOTE: `-D clippy::no-effect` implied by `-D warnings` s2; + //~^ ERROR: statement with no effect Unit; + //~^ ERROR: statement with no effect Tuple(0); + //~^ ERROR: statement with no effect Struct { field: 0 }; + //~^ ERROR: statement with no effect Struct { ..s }; + //~^ ERROR: statement with no effect Union { a: 0 }; + //~^ ERROR: statement with no effect Enum::Tuple(0); + //~^ ERROR: statement with no effect Enum::Struct { field: 0 }; + //~^ ERROR: statement with no effect 5 + 6; + //~^ ERROR: statement with no effect *&42; + //~^ ERROR: statement with no effect &6; + //~^ ERROR: statement with no effect (5, 6, 7); + //~^ ERROR: statement with no effect ..; + //~^ ERROR: statement with no effect 5..; + //~^ ERROR: statement with no effect ..5; + //~^ ERROR: statement with no effect 5..6; + //~^ ERROR: statement with no effect 5..=6; + //~^ ERROR: statement with no effect [42, 55]; + //~^ ERROR: statement with no effect [42, 55][1]; + //~^ ERROR: statement with no effect (42, 55).1; + //~^ ERROR: statement with no effect [42; 55]; + //~^ ERROR: statement with no effect [42; 55][13]; + //~^ ERROR: statement with no effect let mut x = 0; || x += 5; + //~^ ERROR: statement with no effect let s: String = "foo".into(); FooString { s: s }; + //~^ ERROR: statement with no effect let _unused = 1; + //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~| NOTE: `-D clippy::no-effect-underscore-binding` implied by `-D warnings` let _penguin = || println!("Some helpful closure"); + //~^ ERROR: binding to `_` prefixed variable with no side-effect let _duck = Struct { field: 0 }; + //~^ ERROR: binding to `_` prefixed variable with no side-effect let _cat = [2, 4, 6, 8][2]; + //~^ ERROR: binding to `_` prefixed variable with no side-effect #[allow(clippy::no_effect)] 0; diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr index 64edfc32504e5..4b8499a23a5de 100644 --- a/tests/ui/no_effect.stderr +++ b/tests/ui/no_effect.stderr @@ -7,151 +7,151 @@ LL | 0; = note: `-D clippy::no-effect` implied by `-D warnings` error: statement with no effect - --> $DIR/no_effect.rs:99:5 + --> $DIR/no_effect.rs:101:5 | LL | s2; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:100:5 + --> $DIR/no_effect.rs:103:5 | LL | Unit; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:101:5 + --> $DIR/no_effect.rs:105:5 | LL | Tuple(0); | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:102:5 + --> $DIR/no_effect.rs:107:5 | LL | Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:103:5 + --> $DIR/no_effect.rs:109:5 | LL | Struct { ..s }; | ^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:104:5 + --> $DIR/no_effect.rs:111:5 | LL | Union { a: 0 }; | ^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:105:5 + --> $DIR/no_effect.rs:113:5 | LL | Enum::Tuple(0); | ^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:106:5 + --> $DIR/no_effect.rs:115:5 | LL | Enum::Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:107:5 + --> $DIR/no_effect.rs:117:5 | LL | 5 + 6; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:108:5 + --> $DIR/no_effect.rs:119:5 | LL | *&42; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:109:5 + --> $DIR/no_effect.rs:121:5 | LL | &6; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:110:5 + --> $DIR/no_effect.rs:123:5 | LL | (5, 6, 7); | ^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:111:5 + --> $DIR/no_effect.rs:125:5 | LL | ..; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:112:5 + --> $DIR/no_effect.rs:127:5 | LL | 5..; | ^^^^ error: statement with no effect - --> $DIR/no_effect.rs:113:5 + --> $DIR/no_effect.rs:129:5 | LL | ..5; | ^^^^ error: statement with no effect - --> $DIR/no_effect.rs:114:5 + --> $DIR/no_effect.rs:131:5 | LL | 5..6; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:115:5 + --> $DIR/no_effect.rs:133:5 | LL | 5..=6; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:116:5 + --> $DIR/no_effect.rs:135:5 | LL | [42, 55]; | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:117:5 + --> $DIR/no_effect.rs:137:5 | LL | [42, 55][1]; | ^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:118:5 + --> $DIR/no_effect.rs:139:5 | LL | (42, 55).1; | ^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:119:5 + --> $DIR/no_effect.rs:141:5 | LL | [42; 55]; | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:120:5 + --> $DIR/no_effect.rs:143:5 | LL | [42; 55][13]; | ^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:122:5 + --> $DIR/no_effect.rs:146:5 | LL | || x += 5; | ^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:124:5 + --> $DIR/no_effect.rs:149:5 | LL | FooString { s: s }; | ^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:125:5 + --> $DIR/no_effect.rs:151:5 | LL | let _unused = 1; | ^^^^^^^^^^^^^^^^ @@ -159,19 +159,19 @@ LL | let _unused = 1; = note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings` error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:126:5 + --> $DIR/no_effect.rs:154:5 | LL | let _penguin = || println!("Some helpful closure"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:127:5 + --> $DIR/no_effect.rs:156:5 | LL | let _duck = Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:128:5 + --> $DIR/no_effect.rs:158:5 | LL | let _cat = [2, 4, 6, 8][2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/no_effect_replace.rs b/tests/ui/no_effect_replace.rs index ad17d53f78906..e4fd5caae2a5d 100644 --- a/tests/ui/no_effect_replace.rs +++ b/tests/ui/no_effect_replace.rs @@ -2,21 +2,30 @@ fn main() { let _ = "12345".replace('1', "1"); + //~^ ERROR: replacing text with itself + //~| NOTE: `-D clippy::no-effect-replace` implied by `-D warnings` let _ = "12345".replace("12", "12"); + //~^ ERROR: replacing text with itself let _ = String::new().replace("12", "12"); + //~^ ERROR: replacing text with itself let _ = "12345".replacen('1', "1", 1); + //~^ ERROR: replacing text with itself let _ = "12345".replacen("12", "12", 1); + //~^ ERROR: replacing text with itself let _ = String::new().replacen("12", "12", 1); + //~^ ERROR: replacing text with itself let _ = "12345".replace("12", "22"); let _ = "12345".replacen("12", "22", 1); let mut x = X::default(); let _ = "hello".replace(&x.f(), &x.f()); + //~^ ERROR: replacing text with itself let _ = "hello".replace(&x.f(), &x.ff()); let _ = "hello".replace(&y(), &y()); + //~^ ERROR: replacing text with itself let _ = "hello".replace(&y(), &z()); let _ = Replaceme.replace("a", "a"); diff --git a/tests/ui/no_effect_replace.stderr b/tests/ui/no_effect_replace.stderr index 53a28aa73b707..685b20b75d41d 100644 --- a/tests/ui/no_effect_replace.stderr +++ b/tests/ui/no_effect_replace.stderr @@ -7,43 +7,43 @@ LL | let _ = "12345".replace('1', "1"); = note: `-D clippy::no-effect-replace` implied by `-D warnings` error: replacing text with itself - --> $DIR/no_effect_replace.rs:5:13 + --> $DIR/no_effect_replace.rs:7:13 | LL | let _ = "12345".replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:6:13 + --> $DIR/no_effect_replace.rs:9:13 | LL | let _ = String::new().replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:8:13 + --> $DIR/no_effect_replace.rs:12:13 | LL | let _ = "12345".replacen('1', "1", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:9:13 + --> $DIR/no_effect_replace.rs:14:13 | LL | let _ = "12345".replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:10:13 + --> $DIR/no_effect_replace.rs:16:13 | LL | let _ = String::new().replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:16:13 + --> $DIR/no_effect_replace.rs:23:13 | LL | let _ = "hello".replace(&x.f(), &x.f()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:19:13 + --> $DIR/no_effect_replace.rs:27:13 | LL | let _ = "hello".replace(&y(), &y()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/no_effect_return.rs b/tests/ui/no_effect_return.rs index 186d42134fd36..f6585aa30a6f0 100644 --- a/tests/ui/no_effect_return.rs +++ b/tests/ui/no_effect_return.rs @@ -7,6 +7,8 @@ use std::ops::ControlFlow; fn a() -> u32 { { 0u32; + //~^ ERROR: statement with no effect + //~| NOTE: `-D clippy::no-effect` implied by `-D warnings` } 0 } @@ -14,6 +16,7 @@ fn a() -> u32 { async fn b() -> u32 { { 0u32; + //~^ ERROR: statement with no effect } 0 } @@ -22,6 +25,7 @@ type C = i32; async fn c() -> C { { 0i32 as C; + //~^ ERROR: statement with no effect } 0 } @@ -30,6 +34,7 @@ fn d() -> u128 { { // not last stmt 0u128; + //~^ ERROR: statement with no effect println!("lol"); } 0 @@ -39,6 +44,7 @@ fn e() -> u32 { { // mismatched types 0u16; + //~^ ERROR: statement with no effect } 0 } @@ -46,6 +52,7 @@ fn e() -> u32 { fn f() -> [u16; 1] { { [1u16]; + //~^ ERROR: statement with no effect } [1] } @@ -53,6 +60,7 @@ fn f() -> [u16; 1] { fn g() -> ControlFlow<()> { { ControlFlow::Break::<()>(()); + //~^ ERROR: statement with no effect } ControlFlow::Continue(()) } @@ -69,6 +77,7 @@ fn h() -> Vec { fn i() -> () { { (); + //~^ ERROR: statement with no effect } () } @@ -77,6 +86,7 @@ fn j() { { // does not suggest on function without explicit return type (); + //~^ ERROR: statement with no effect } () } diff --git a/tests/ui/no_effect_return.stderr b/tests/ui/no_effect_return.stderr index 2b55bcb881eec..6b146a03abc11 100644 --- a/tests/ui/no_effect_return.stderr +++ b/tests/ui/no_effect_return.stderr @@ -9,7 +9,7 @@ LL | 0u32; = note: `-D clippy::no-effect` implied by `-D warnings` error: statement with no effect - --> $DIR/no_effect_return.rs:16:9 + --> $DIR/no_effect_return.rs:18:9 | LL | 0u32; | -^^^^ @@ -17,7 +17,7 @@ LL | 0u32; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:24:9 + --> $DIR/no_effect_return.rs:27:9 | LL | 0i32 as C; | -^^^^^^^^^ @@ -25,19 +25,19 @@ LL | 0i32 as C; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:32:9 + --> $DIR/no_effect_return.rs:36:9 | LL | 0u128; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect_return.rs:41:9 + --> $DIR/no_effect_return.rs:46:9 | LL | 0u16; | ^^^^^ error: statement with no effect - --> $DIR/no_effect_return.rs:48:9 + --> $DIR/no_effect_return.rs:54:9 | LL | [1u16]; | -^^^^^^ @@ -45,7 +45,7 @@ LL | [1u16]; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:55:9 + --> $DIR/no_effect_return.rs:62:9 | LL | ControlFlow::Break::<()>(()); | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL | ControlFlow::Break::<()>(()); | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:71:9 + --> $DIR/no_effect_return.rs:79:9 | LL | (); | -^^ @@ -61,7 +61,7 @@ LL | (); | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:79:9 + --> $DIR/no_effect_return.rs:88:9 | LL | (); | ^^^ diff --git a/tests/ui/no_mangle_with_rust_abi.rs b/tests/ui/no_mangle_with_rust_abi.rs index 7ae9468230403..8c1ea81d2ac9a 100644 --- a/tests/ui/no_mangle_with_rust_abi.rs +++ b/tests/ui/no_mangle_with_rust_abi.rs @@ -4,22 +4,28 @@ #[no_mangle] fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI +//~| NOTE: `-D clippy::no-mangle-with-rust-abi` implied by `-D warnings` #[no_mangle] pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI /// # Safety /// This function shouldn't be called unless the horsemen are ready #[no_mangle] pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI /// # Safety /// This function shouldn't be called unless the horsemen are ready #[no_mangle] unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI #[no_mangle] fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( + //~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI arg_one: u32, arg_two: usize, ) -> u32 { diff --git a/tests/ui/no_mangle_with_rust_abi.stderr b/tests/ui/no_mangle_with_rust_abi.stderr index 9f5fc90dc12ba..721dcf603b1fd 100644 --- a/tests/ui/no_mangle_with_rust_abi.stderr +++ b/tests/ui/no_mangle_with_rust_abi.stderr @@ -15,7 +15,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 - --> $DIR/no_mangle_with_rust_abi.rs:9:1 + --> $DIR/no_mangle_with_rust_abi.rs:11:1 | LL | pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,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 - --> $DIR/no_mangle_with_rust_abi.rs:14:1 + --> $DIR/no_mangle_with_rust_abi.rs:17:1 | LL | pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,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 - --> $DIR/no_mangle_with_rust_abi.rs:19:1 + --> $DIR/no_mangle_with_rust_abi.rs:23:1 | LL | unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,9 +60,10 @@ 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 - --> $DIR/no_mangle_with_rust_abi.rs:22:1 + --> $DIR/no_mangle_with_rust_abi.rs:27:1 | LL | / fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( +LL | | LL | | arg_one: u32, LL | | arg_two: usize, LL | | ) -> u32 { diff --git a/tests/ui/non_minimal_cfg2.rs b/tests/ui/non_minimal_cfg2.rs index a4c6abce38764..f9e3ba4dacdad 100644 --- a/tests/ui/non_minimal_cfg2.rs +++ b/tests/ui/non_minimal_cfg2.rs @@ -1,6 +1,8 @@ #![allow(unused)] #[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_send_fields_in_send_ty.rs b/tests/ui/non_send_fields_in_send_ty.rs index 514fb25c8cfd8..c6855a0969681 100644 --- a/tests/ui/non_send_fields_in_send_ty.rs +++ b/tests/ui/non_send_fields_in_send_ty.rs @@ -15,6 +15,7 @@ pub struct RingBuffer { } unsafe impl Send for RingBuffer {} +//~^ ERROR: some fields in `RingBuffer` are not safe to be sent to another thread // noise_search / RUSTSEC-2020-0141 pub struct MvccRwLock { @@ -23,6 +24,7 @@ pub struct MvccRwLock { } unsafe impl Send for MvccRwLock {} +//~^ ERROR: some fields in `MvccRwLock` are not safe to be sent to another thread // async-coap / RUSTSEC-2020-0124 pub struct ArcGuard { @@ -31,6 +33,7 @@ pub struct ArcGuard { } unsafe impl Send for ArcGuard {} +//~^ ERROR: some fields in `ArcGuard` are not safe to be sent to another thread // rusb / RUSTSEC-2020-0098 extern "C" { @@ -47,6 +50,7 @@ pub struct DeviceHandle { } unsafe impl Send for DeviceHandle {} +//~^ ERROR: some fields in `DeviceHandle` are not safe to be sent to another thread // Other basic tests pub struct NoGeneric { @@ -54,6 +58,7 @@ pub struct NoGeneric { } unsafe impl Send for NoGeneric {} +//~^ ERROR: some fields in `NoGeneric` are not safe to be sent to another thread pub struct MultiField { field1: T, @@ -62,6 +67,7 @@ pub struct MultiField { } unsafe impl Send for MultiField {} +//~^ ERROR: some fields in `MultiField` are not safe to be sent to another thread pub enum MyOption { MySome(T), @@ -69,6 +75,7 @@ pub enum MyOption { } unsafe impl Send for MyOption {} +//~^ ERROR: some fields in `MyOption` are not safe to be sent to another thread // Test types that contain `NonNull` instead of raw pointers (#8045) pub struct WrappedNonNull(UnsafeCell>); @@ -81,6 +88,7 @@ pub struct MultiParam { } unsafe impl Send for MultiParam {} +//~^ ERROR: some fields in `MultiParam` are not safe to be sent to another thread // Tests for raw pointer heuristic extern "C" { @@ -99,6 +107,7 @@ pub struct HeuristicTest { } unsafe impl Send for HeuristicTest {} +//~^ ERROR: some fields in `HeuristicTest` are not safe to be sent to another thread // Test attributes #[allow(clippy::non_send_fields_in_send_ty)] @@ -118,6 +127,7 @@ pub enum AttrTest3 { unsafe impl Send for AttrTest1 {} unsafe impl Send for AttrTest2 {} unsafe impl Send for AttrTest3 {} +//~^ ERROR: some fields in `AttrTest3` are not safe to be sent to another thread // Multiple non-overlapping `Send` for a single type pub struct Complex { @@ -126,8 +136,10 @@ pub struct Complex { } unsafe impl

Send for Complex {} +//~^ ERROR: some fields in `Complex` are not safe to be sent to another thread // `MutexGuard` is non-Send unsafe impl Send for Complex> {} +//~^ ERROR: some fields in `Complex>` are not safe to be sent fn main() {} diff --git a/tests/ui/non_send_fields_in_send_ty.stderr b/tests/ui/non_send_fields_in_send_ty.stderr index e912b59a6e7b0..08a53b3a891cf 100644 --- a/tests/ui/non_send_fields_in_send_ty.stderr +++ b/tests/ui/non_send_fields_in_send_ty.stderr @@ -13,155 +13,155 @@ LL | data: Vec>, = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` error: some fields in `MvccRwLock` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:25:1 + --> $DIR/non_send_fields_in_send_ty.rs:26:1 | LL | unsafe impl Send for MvccRwLock {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `lock` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:22:5 + --> $DIR/non_send_fields_in_send_ty.rs:23:5 | LL | lock: Mutex>, | ^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Mutex>: Send` error: some fields in `ArcGuard` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:33:1 + --> $DIR/non_send_fields_in_send_ty.rs:35:1 | LL | unsafe impl Send for ArcGuard {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `head` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:30:5 + --> $DIR/non_send_fields_in_send_ty.rs:32:5 | LL | head: Arc, | ^^^^^^^^^^^^^ = help: add bounds on type parameter `RC` that satisfy `Arc: Send` error: some fields in `DeviceHandle` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:49:1 + --> $DIR/non_send_fields_in_send_ty.rs:52:1 | LL | unsafe impl Send for DeviceHandle {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `context` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:45:5 + --> $DIR/non_send_fields_in_send_ty.rs:48:5 | LL | context: T, | ^^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `NoGeneric` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:56:1 + --> $DIR/non_send_fields_in_send_ty.rs:60:1 | LL | unsafe impl Send for NoGeneric {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `rc_is_not_send` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:53:5 + --> $DIR/non_send_fields_in_send_ty.rs:57:5 | LL | rc_is_not_send: Rc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `MultiField` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:64:1 + --> $DIR/non_send_fields_in_send_ty.rs:69:1 | LL | unsafe impl Send for MultiField {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:59:5 + --> $DIR/non_send_fields_in_send_ty.rs:64:5 | LL | field1: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:60:5 + --> $DIR/non_send_fields_in_send_ty.rs:65:5 | LL | field2: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field3` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:61:5 + --> $DIR/non_send_fields_in_send_ty.rs:66:5 | LL | field3: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `MyOption` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:71:1 + --> $DIR/non_send_fields_in_send_ty.rs:77:1 | LL | unsafe impl Send for MyOption {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:67:12 + --> $DIR/non_send_fields_in_send_ty.rs:73:12 | LL | MySome(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `MultiParam` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:83:1 + --> $DIR/non_send_fields_in_send_ty.rs:90:1 | LL | unsafe impl Send for MultiParam {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `vec` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:80:5 + --> $DIR/non_send_fields_in_send_ty.rs:87:5 | LL | vec: Vec<(A, B)>, | ^^^^^^^^^^^^^^^^ = help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send` error: some fields in `HeuristicTest` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:101:1 + --> $DIR/non_send_fields_in_send_ty.rs:109:1 | LL | unsafe impl Send for HeuristicTest {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field4` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:96:5 + --> $DIR/non_send_fields_in_send_ty.rs:104:5 | LL | field4: (*const NonSend, Rc), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `AttrTest3` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:120:1 + --> $DIR/non_send_fields_in_send_ty.rs:129:1 | LL | unsafe impl Send for AttrTest3 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:115:11 + --> $DIR/non_send_fields_in_send_ty.rs:124:11 | LL | Enum2(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `Complex` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:128:1 + --> $DIR/non_send_fields_in_send_ty.rs:138:1 | LL | unsafe impl

Send for Complex {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:124:5 + --> $DIR/non_send_fields_in_send_ty.rs:134:5 | LL | field1: A, | ^^^^^^^^^ = help: add `P: Send` bound in `Send` impl error: some fields in `Complex>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:131:1 + --> $DIR/non_send_fields_in_send_ty.rs:142:1 | LL | unsafe impl Send for Complex> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:125:5 + --> $DIR/non_send_fields_in_send_ty.rs:135:5 | LL | field2: B, | ^^^^^^^^^ diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 9bb97bd50286b..da7876e772ee9 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -11,15 +11,23 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = !true; + //~^ ERROR: this boolean expression can be simplified + //~| NOTE: `-D clippy::nonminimal-bool` implied by `-D warnings` let _ = !false; + //~^ ERROR: this boolean expression can be simplified let _ = !!a; + //~^ ERROR: this boolean expression can be simplified let _ = false || a; + //~^ ERROR: this boolean expression can be simplified // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; let _ = !(!a && b); + //~^ ERROR: this boolean expression can be simplified let _ = !(!a || b); + //~^ ERROR: this boolean expression can be simplified let _ = !a && !(b && c); + //~^ ERROR: this boolean expression can be simplified } fn equality_stuff() { @@ -28,10 +36,15 @@ fn equality_stuff() { let c: i32 = unimplemented!(); let d: i32 = unimplemented!(); let _ = a == b && c == 5 && a == b; + //~^ ERROR: this boolean expression can be simplified let _ = a == b || c == 5 || a == b; + //~^ ERROR: this boolean expression can be simplified let _ = a == b && c == 5 && b == a; + //~^ ERROR: this boolean expression can be simplified let _ = a != b || !(a != b || c == d); + //~^ ERROR: this boolean expression can be simplified let _ = a != b && !(a != b && c == d); + //~^ ERROR: this boolean expression can be simplified } fn issue3847(a: u32, b: u32) -> bool { @@ -62,6 +75,7 @@ fn check_expect() { fn issue9428() { if matches!(true, true) && true { + //~^ ERROR: this boolean expression can be simplified println!("foo"); } } diff --git a/tests/ui/nonminimal_bool.stderr b/tests/ui/nonminimal_bool.stderr index 087e57867e6d1..2eba55555f438 100644 --- a/tests/ui/nonminimal_bool.stderr +++ b/tests/ui/nonminimal_bool.stderr @@ -7,43 +7,43 @@ LL | let _ = !true; = note: `-D clippy::nonminimal-bool` implied by `-D warnings` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:14:13 + --> $DIR/nonminimal_bool.rs:16:13 | LL | let _ = !false; | ^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:15:13 + --> $DIR/nonminimal_bool.rs:18:13 | LL | let _ = !!a; | ^^^ help: try: `a` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:16:13 + --> $DIR/nonminimal_bool.rs:20:13 | LL | let _ = false || a; | ^^^^^^^^^^ help: try: `a` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:20:13 + --> $DIR/nonminimal_bool.rs:25:13 | LL | let _ = !(!a && b); | ^^^^^^^^^^ help: try: `a || !b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:21:13 + --> $DIR/nonminimal_bool.rs:27:13 | LL | let _ = !(!a || b); | ^^^^^^^^^^ help: try: `a && !b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:22:13 + --> $DIR/nonminimal_bool.rs:29:13 | LL | let _ = !a && !(b && c); | ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:30:13 + --> $DIR/nonminimal_bool.rs:38:13 | LL | let _ = a == b && c == 5 && a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:31:13 + --> $DIR/nonminimal_bool.rs:40:13 | LL | let _ = a == b || c == 5 || a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL | let _ = a == b || c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:32:13 + --> $DIR/nonminimal_bool.rs:42:13 | LL | let _ = a == b && c == 5 && b == a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -82,7 +82,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:33:13 + --> $DIR/nonminimal_bool.rs:44:13 | LL | let _ = a != b || !(a != b || c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +95,7 @@ LL | let _ = a != b || c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:34:13 + --> $DIR/nonminimal_bool.rs:46:13 | LL | let _ = a != b && !(a != b && c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | let _ = a != b && c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:64:8 + --> $DIR/nonminimal_bool.rs:77:8 | LL | if matches!(true, true) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(true, true)` diff --git a/tests/ui/octal_escapes.rs b/tests/ui/octal_escapes.rs index 68fd3f2180d4e..3915dfdb8418b 100644 --- a/tests/ui/octal_escapes.rs +++ b/tests/ui/octal_escapes.rs @@ -3,15 +3,24 @@ fn main() { let _bad1 = "\033[0m"; + //~^ ERROR: octal-looking escape in string literal let _bad2 = b"\033[0m"; + //~^ ERROR: octal-looking escape in byte string literal let _bad3 = "\\\033[0m"; + //~^ ERROR: octal-looking escape in string literal // maximum 3 digits (\012 is the escape) let _bad4 = "\01234567"; + //~^ ERROR: octal-looking escape in string literal let _bad5 = "\0\03"; + //~^ ERROR: octal-looking escape in string literal let _bad6 = "Text-\055\077-MoreText"; + //~^ ERROR: octal-looking escape in string literal let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; + //~^ ERROR: octal-looking escape in string literal let _bad8 = "锈\01锈"; + //~^ ERROR: octal-looking escape in string literal let _bad9 = "锈\011锈"; + //~^ ERROR: octal-looking escape in string literal let _good1 = "\\033[0m"; let _good2 = "\0\\0"; diff --git a/tests/ui/octal_escapes.stderr b/tests/ui/octal_escapes.stderr index 078118eb7f204..98f7d21261f5b 100644 --- a/tests/ui/octal_escapes.stderr +++ b/tests/ui/octal_escapes.stderr @@ -16,7 +16,7 @@ LL | let _bad1 = "\x0033[0m"; | ~~~~~~~~~~~ error: octal-looking escape in byte string literal - --> $DIR/octal_escapes.rs:6:17 + --> $DIR/octal_escapes.rs:7:17 | LL | let _bad2 = b"\033[0m"; | ^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let _bad2 = b"\x0033[0m"; | ~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:7:17 + --> $DIR/octal_escapes.rs:9:17 | LL | let _bad3 = "\\\033[0m"; | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let _bad3 = "\\\x0033[0m"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:9:17 + --> $DIR/octal_escapes.rs:12:17 | LL | let _bad4 = "\01234567"; | ^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let _bad4 = "\x001234567"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:10:17 + --> $DIR/octal_escapes.rs:14:17 | LL | let _bad5 = "\0\03"; | ^^^^^^^ @@ -80,7 +80,7 @@ LL | let _bad5 = "\0\x003"; | ~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:11:17 + --> $DIR/octal_escapes.rs:16:17 | LL | let _bad6 = "Text-\055\077-MoreText"; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _bad6 = "Text-\x0055\x0077-MoreText"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:12:17 + --> $DIR/octal_escapes.rs:18:17 | LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | let _bad7 = "EvenMoreText-\x001\x002-ShortEscapes"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:13:17 + --> $DIR/octal_escapes.rs:20:17 | LL | let _bad8 = "锈\01锈"; | ^^^^^^^^^ @@ -128,7 +128,7 @@ LL | let _bad8 = "锈\x001锈"; | ~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:14:17 + --> $DIR/octal_escapes.rs:22:17 | LL | let _bad9 = "锈\011锈"; | ^^^^^^^^^^ diff --git a/tests/ui/ok_expect.rs b/tests/ui/ok_expect.rs index 2047ee689d95c..c2ad21e22ff8c 100644 --- a/tests/ui/ok_expect.rs +++ b/tests/ui/ok_expect.rs @@ -14,16 +14,21 @@ fn main() { let _ = res.unwrap(); res.ok().expect("disaster!"); + //~^ ERROR: called `ok().expect()` on a `Result` value // the following should not warn, since `expect` isn't implemented unless // the error type implements `Debug` let res2: Result = Ok(0); res2.ok().expect("oh noes!"); let res3: Result> = Ok(0); res3.ok().expect("whoof"); + //~^ ERROR: called `ok().expect()` on a `Result` value let res4: Result = Ok(0); res4.ok().expect("argh"); + //~^ ERROR: called `ok().expect()` on a `Result` value let res5: io::Result = Ok(0); res5.ok().expect("oops"); + //~^ ERROR: called `ok().expect()` on a `Result` value let res6: Result = Ok(0); res6.ok().expect("meh"); + //~^ ERROR: called `ok().expect()` on a `Result` value } diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr index ab9df26ebc37e..4c295d7a4c257 100644 --- a/tests/ui/ok_expect.stderr +++ b/tests/ui/ok_expect.stderr @@ -8,7 +8,7 @@ LL | res.ok().expect("disaster!"); = note: `-D clippy::ok-expect` implied by `-D warnings` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:22:5 + --> $DIR/ok_expect.rs:23:5 | LL | res3.ok().expect("whoof"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | res3.ok().expect("whoof"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:24:5 + --> $DIR/ok_expect.rs:26:5 | LL | res4.ok().expect("argh"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | res4.ok().expect("argh"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:26:5 + --> $DIR/ok_expect.rs:29:5 | LL | res5.ok().expect("oops"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | res5.ok().expect("oops"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:28:5 + --> $DIR/ok_expect.rs:32: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 871b3a79f3f6b..169fb790f8c5c 100644 --- a/tests/ui/only_used_in_recursion.rs +++ b/tests/ui/only_used_in_recursion.rs @@ -9,14 +9,18 @@ fn _simple2(x: u32) -> u32 { } fn _one_unused(flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { _one_unused(flag - 1, a) } } fn _two_unused(flag: u32, a: u32, b: i32) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } } fn _with_calc(flag: u32, a: i64) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { @@ -30,6 +34,8 @@ fn _used_with_flag(flag: u32, a: u32) -> usize { } fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { @@ -38,6 +44,8 @@ fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { } fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { @@ -46,6 +54,7 @@ fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { } fn _not_primitive(flag: u32, b: String) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } } @@ -53,10 +62,13 @@ struct A; impl A { fn _method(flag: usize, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { Self::_method(flag - 1, a) } } fn _method_self(&self, flag: usize, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { self._method_self(flag - 1, a) } } } @@ -68,10 +80,12 @@ trait B { impl B for A { fn method(flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { Self::method(flag - 1, a) } } fn method_self(&self, flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { self.method_self(flag - 1, a) } } } @@ -98,10 +112,12 @@ impl B for u32 { trait C { fn method(flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { Self::method(flag - 1, a) } } fn method_self(&self, flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { self.method_self(flag - 1, a) } } } diff --git a/tests/ui/only_used_in_recursion.stderr b/tests/ui/only_used_in_recursion.stderr index 571e5c4b5faa9..b731d37c62c44 100644 --- a/tests/ui/only_used_in_recursion.stderr +++ b/tests/ui/only_used_in_recursion.stderr @@ -5,188 +5,188 @@ LL | fn _one_unused(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:12:53 + --> $DIR/only_used_in_recursion.rs:13:53 | LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) } | ^ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:15:27 + --> $DIR/only_used_in_recursion.rs:16: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 - --> $DIR/only_used_in_recursion.rs:16:53 + --> $DIR/only_used_in_recursion.rs:19:53 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:15:35 + --> $DIR/only_used_in_recursion.rs:16: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 - --> $DIR/only_used_in_recursion.rs:16:56 + --> $DIR/only_used_in_recursion.rs:19:56 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:19:26 + --> $DIR/only_used_in_recursion.rs:22: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 - --> $DIR/only_used_in_recursion.rs:23:32 + --> $DIR/only_used_in_recursion.rs:27:32 | LL | _with_calc(flag - 1, (-a + 10) * 5) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:32:33 + --> $DIR/only_used_in_recursion.rs:36: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 - --> $DIR/only_used_in_recursion.rs:36:38 + --> $DIR/only_used_in_recursion.rs:42:38 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:32:41 + --> $DIR/only_used_in_recursion.rs:36: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 - --> $DIR/only_used_in_recursion.rs:36:45 + --> $DIR/only_used_in_recursion.rs:42:45 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:40:35 + --> $DIR/only_used_in_recursion.rs:46: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 - --> $DIR/only_used_in_recursion.rs:44:39 + --> $DIR/only_used_in_recursion.rs:52:39 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:40:43 + --> $DIR/only_used_in_recursion.rs:46: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 - --> $DIR/only_used_in_recursion.rs:44:43 + --> $DIR/only_used_in_recursion.rs:52:43 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:48:30 + --> $DIR/only_used_in_recursion.rs:56: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 - --> $DIR/only_used_in_recursion.rs:49:56 + --> $DIR/only_used_in_recursion.rs:58:56 | LL | if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:55:29 + --> $DIR/only_used_in_recursion.rs:64:29 | LL | fn _method(flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:56:59 + --> $DIR/only_used_in_recursion.rs:66:59 | LL | if flag == 0 { 0 } else { Self::_method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:59:22 + --> $DIR/only_used_in_recursion.rs:69:22 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^^^^ | note: parameter used here - --> $DIR/only_used_in_recursion.rs:60:35 + --> $DIR/only_used_in_recursion.rs:72:35 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^^^^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:59:41 + --> $DIR/only_used_in_recursion.rs:69: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 - --> $DIR/only_used_in_recursion.rs:60:63 + --> $DIR/only_used_in_recursion.rs:72:63 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:70:26 + --> $DIR/only_used_in_recursion.rs:82:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:71:58 + --> $DIR/only_used_in_recursion.rs:84:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:74:38 + --> $DIR/only_used_in_recursion.rs:87: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 - --> $DIR/only_used_in_recursion.rs:75:62 + --> $DIR/only_used_in_recursion.rs:89:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:100:26 + --> $DIR/only_used_in_recursion.rs:114:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:101:58 + --> $DIR/only_used_in_recursion.rs:116:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:104:38 + --> $DIR/only_used_in_recursion.rs:119: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 - --> $DIR/only_used_in_recursion.rs:105:62 + --> $DIR/only_used_in_recursion.rs:121:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ diff --git a/tests/ui/only_used_in_recursion2.rs b/tests/ui/only_used_in_recursion2.rs index 587114b7cb8d9..1353ff8816ad1 100644 --- a/tests/ui/only_used_in_recursion2.rs +++ b/tests/ui/only_used_in_recursion2.rs @@ -1,7 +1,9 @@ #![warn(clippy::only_used_in_recursion)] //@no-rustfix fn _with_inner(flag: u32, a: u32, b: u32) -> usize { + //~^ ERROR: parameter is only used in recursion fn inner(flag: u32, a: u32) -> u32 { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { inner(flag, a) } } @@ -10,6 +12,7 @@ fn _with_inner(flag: u32, a: u32, b: u32) -> usize { } fn _with_closure(a: Option, b: u32, f: impl Fn(u32, u32) -> Option) -> u32 { + //~^ ERROR: parameter is only used in recursion if let Some(x) = a.and_then(|x| f(x, x)) { _with_closure(Some(x), b, f) } else { @@ -60,6 +63,7 @@ impl E<()> for () { } fn overwritten_param(flag: u32, mut a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { return 0; } else if flag > 5 { @@ -71,6 +75,7 @@ fn overwritten_param(flag: u32, mut a: usize) -> usize { } fn field_direct(flag: u32, mut a: (usize,)) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { diff --git a/tests/ui/only_used_in_recursion2.stderr b/tests/ui/only_used_in_recursion2.stderr index 8dcbfdd612ef2..ae349fd29e957 100644 --- a/tests/ui/only_used_in_recursion2.stderr +++ b/tests/ui/only_used_in_recursion2.stderr @@ -5,56 +5,56 @@ LL | fn _with_inner(flag: u32, a: u32, b: u32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:9:52 + --> $DIR/only_used_in_recursion2.rs:11:52 | LL | if flag == 0 { 0 } else { _with_inner(flag, a, b + x) } | ^ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:4:25 + --> $DIR/only_used_in_recursion2.rs:5:25 | LL | fn inner(flag: u32, a: u32) -> u32 { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:5:47 + --> $DIR/only_used_in_recursion2.rs:7:47 | LL | if flag == 0 { 0 } else { inner(flag, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:12:34 + --> $DIR/only_used_in_recursion2.rs:14:34 | LL | fn _with_closure(a: Option, b: u32, f: impl Fn(u32, u32) -> Option) -> u32 { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:14:32 + --> $DIR/only_used_in_recursion2.rs:17:32 | LL | _with_closure(Some(x), b, f) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:62:37 + --> $DIR/only_used_in_recursion2.rs:65:37 | LL | fn overwritten_param(flag: u32, mut a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:70:29 + --> $DIR/only_used_in_recursion2.rs:74:29 | LL | overwritten_param(flag, a) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:73:32 + --> $DIR/only_used_in_recursion2.rs:77:32 | LL | fn field_direct(flag: u32, mut a: (usize,)) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:78:32 + --> $DIR/only_used_in_recursion2.rs:83:32 | LL | field_direct(flag - 1, a) | ^ diff --git a/tests/ui/op_ref.fixed b/tests/ui/op_ref.fixed index ea7898e2b355d..183dcf4f08635 100644 --- a/tests/ui/op_ref.fixed +++ b/tests/ui/op_ref.fixed @@ -9,6 +9,8 @@ fn main() { let unwanted = &tracked_fds - &new_fds; let foo = 5 - 6; + //~^ ERROR: needlessly taken reference of both operands + //~| NOTE: `-D clippy::op-ref` implied by `-D warnings` let bar = String::new(); let bar = "foo" == &bar; @@ -54,6 +56,7 @@ fn main() { let x = Y(1); let y = Y(2); let z = x & y; + //~^ ERROR: taken reference of right operand } #[derive(Clone, Copy)] @@ -87,7 +90,9 @@ impl Mul for A { let two = 2; let three = 3; let _ = one * self; + //~^ ERROR: taken reference of right operand let _ = two + three; + //~^ ERROR: taken reference of right operand // Removing the reference would lead to unconditional recursion self * &rhs } diff --git a/tests/ui/op_ref.rs b/tests/ui/op_ref.rs index 07226b0a1a83b..6ed4f23d2bd7b 100644 --- a/tests/ui/op_ref.rs +++ b/tests/ui/op_ref.rs @@ -9,6 +9,8 @@ fn main() { let unwanted = &tracked_fds - &new_fds; let foo = &5 - &6; + //~^ ERROR: needlessly taken reference of both operands + //~| NOTE: `-D clippy::op-ref` implied by `-D warnings` let bar = String::new(); let bar = "foo" == &bar; @@ -54,6 +56,7 @@ fn main() { let x = Y(1); let y = Y(2); let z = x & &y; + //~^ ERROR: taken reference of right operand } #[derive(Clone, Copy)] @@ -87,7 +90,9 @@ impl Mul for A { let two = 2; let three = 3; let _ = one * &self; + //~^ ERROR: taken reference of right operand let _ = two + &three; + //~^ ERROR: taken reference of right operand // Removing the reference would lead to unconditional recursion self * &rhs } diff --git a/tests/ui/op_ref.stderr b/tests/ui/op_ref.stderr index fe36c01166ff7..5f3769ddfab4b 100644 --- a/tests/ui/op_ref.stderr +++ b/tests/ui/op_ref.stderr @@ -11,7 +11,7 @@ LL | let foo = 5 - 6; | ~ ~ error: taken reference of right operand - --> $DIR/op_ref.rs:56:13 + --> $DIR/op_ref.rs:58:13 | LL | let z = x & &y; | ^^^^-- @@ -19,7 +19,7 @@ LL | let z = x & &y; | help: use the right value directly: `y` error: taken reference of right operand - --> $DIR/op_ref.rs:89:17 + --> $DIR/op_ref.rs:92:17 | LL | let _ = one * &self; | ^^^^^^----- @@ -27,7 +27,7 @@ LL | let _ = one * &self; | help: use the right value directly: `self` error: taken reference of right operand - --> $DIR/op_ref.rs:90:17 + --> $DIR/op_ref.rs:94:17 | LL | let _ = two + &three; | ^^^^^^------ diff --git a/tests/ui/open_options.rs b/tests/ui/open_options.rs index 9063fafbcd040..0cdc5bf2bb592 100644 --- a/tests/ui/open_options.rs +++ b/tests/ui/open_options.rs @@ -4,11 +4,19 @@ use std::fs::OpenOptions; #[warn(clippy::nonsensical_open_options)] fn main() { OpenOptions::new().read(true).truncate(true).open("foo.txt"); + //~^ ERROR: file opened with `truncate` and `read` + //~| NOTE: `-D clippy::nonsensical-open-options` implied by `-D warnings` OpenOptions::new().append(true).truncate(true).open("foo.txt"); + //~^ ERROR: file opened with `append` and `truncate` OpenOptions::new().read(true).read(false).open("foo.txt"); + //~^ ERROR: the method `read` is called more than once OpenOptions::new().create(true).create(false).open("foo.txt"); + //~^ ERROR: the method `create` is called more than once OpenOptions::new().write(true).write(false).open("foo.txt"); + //~^ ERROR: the method `write` is called more than once OpenOptions::new().append(true).append(false).open("foo.txt"); + //~^ ERROR: the method `append` is called more than once OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); + //~^ ERROR: the method `truncate` is called more than once } diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr index 26fe9f6fb206f..c136cf2dbf405 100644 --- a/tests/ui/open_options.stderr +++ b/tests/ui/open_options.stderr @@ -7,37 +7,37 @@ LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); = note: `-D clippy::nonsensical-open-options` implied by `-D warnings` error: file opened with `append` and `truncate` - --> $DIR/open_options.rs:7:5 + --> $DIR/open_options.rs:9:5 | LL | OpenOptions::new().append(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `read` is called more than once - --> $DIR/open_options.rs:9:5 + --> $DIR/open_options.rs:12:5 | LL | OpenOptions::new().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `create` is called more than once - --> $DIR/open_options.rs:10:5 + --> $DIR/open_options.rs:14:5 | LL | OpenOptions::new().create(true).create(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `write` is called more than once - --> $DIR/open_options.rs:11:5 + --> $DIR/open_options.rs:16:5 | LL | OpenOptions::new().write(true).write(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `append` is called more than once - --> $DIR/open_options.rs:12:5 + --> $DIR/open_options.rs:18:5 | LL | OpenOptions::new().append(true).append(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `truncate` is called more than once - --> $DIR/open_options.rs:13:5 + --> $DIR/open_options.rs:20:5 | LL | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/option_option.rs b/tests/ui/option_option.rs index 2faab9e035d99..9bbdd3aaacce5 100644 --- a/tests/ui/option_option.rs +++ b/tests/ui/option_option.rs @@ -2,40 +2,51 @@ #![allow(clippy::unnecessary_wraps)] const C: Option> = None; +//~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if static S: Option> = None; +//~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if fn input(_: Option>) {} +//~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if fn output() -> Option> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if None } fn output_nested() -> Vec>> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if vec![None] } // The lint only generates one warning for this fn output_nested_nested() -> Option>> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if None } struct Struct { x: Option>, + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } impl Struct { fn struct_fn() -> Option> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum None } } trait Trait { fn trait_fn() -> Option>; + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } enum Enum { Tuple(Option>), + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum Struct { x: Option> }, + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } // The lint allows this @@ -77,6 +88,7 @@ mod issue_4298 { #[serde(default)] #[serde(borrow)] foo: Option>>, + //~^ ERROR: consider using `Option` instead of `Option>` or a custom } #[allow(clippy::option_option)] diff --git a/tests/ui/option_option.stderr b/tests/ui/option_option.stderr index a925bb35b04d8..fcae9655dbf7f 100644 --- a/tests/ui/option_option.stderr +++ b/tests/ui/option_option.stderr @@ -11,67 +11,67 @@ LL | #![deny(clippy::option_option)] | ^^^^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:5:11 + --> $DIR/option_option.rs:6:11 | LL | static S: Option> = None; | ^^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:7:13 + --> $DIR/option_option.rs:9:13 | LL | fn input(_: Option>) {} | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:9:16 + --> $DIR/option_option.rs:12:16 | LL | fn output() -> Option> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:13:27 + --> $DIR/option_option.rs:17:27 | LL | fn output_nested() -> Vec>> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:18:30 + --> $DIR/option_option.rs:23:30 | LL | fn output_nested_nested() -> Option>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:23:8 + --> $DIR/option_option.rs:29:8 | LL | x: Option>, | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:27:23 + --> $DIR/option_option.rs:34:23 | LL | fn struct_fn() -> Option> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:33:22 + --> $DIR/option_option.rs:41:22 | LL | fn trait_fn() -> Option>; | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:37:11 + --> $DIR/option_option.rs:46:11 | LL | Tuple(Option>), | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:38:17 + --> $DIR/option_option.rs:48:17 | LL | Struct { x: Option> }, | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:79:14 + --> $DIR/option_option.rs:90:14 | LL | foo: Option>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs index a5605cc14d484..81674653bdd3b 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ b/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -7,5 +7,8 @@ fn main() { // issue 3102 let num = 1; &x[num..10]; + //~^ ERROR: range is out of bounds + //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` &x[10..num]; + //~^ ERROR: range is out of bounds } diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/tests/ui/out_of_bounds_indexing/issue-3102.stderr index 8a09688a90ceb..b50b76bd9b2e8 100644 --- a/tests/ui/out_of_bounds_indexing/issue-3102.stderr +++ b/tests/ui/out_of_bounds_indexing/issue-3102.stderr @@ -7,7 +7,7 @@ LL | &x[num..10]; = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` error: range is out of bounds - --> $DIR/issue-3102.rs:10:8 + --> $DIR/issue-3102.rs:12:8 | LL | &x[10..num]; | ^^ diff --git a/tests/ui/out_of_bounds_indexing/simple.rs b/tests/ui/out_of_bounds_indexing/simple.rs index 4c541c23f5f47..c38ca51238165 100644 --- a/tests/ui/out_of_bounds_indexing/simple.rs +++ b/tests/ui/out_of_bounds_indexing/simple.rs @@ -5,11 +5,18 @@ fn main() { let x = [1, 2, 3, 4]; &x[..=4]; + //~^ ERROR: range is out of bounds + //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` &x[1..5]; + //~^ ERROR: range is out of bounds &x[5..]; + //~^ ERROR: range is out of bounds &x[..5]; + //~^ ERROR: range is out of bounds &x[5..].iter().map(|x| 2 * x).collect::>(); + //~^ ERROR: range is out of bounds &x[0..=4]; + //~^ ERROR: range is out of bounds &x[4..]; // Ok, should not produce stderr. &x[..4]; // Ok, should not produce stderr. diff --git a/tests/ui/out_of_bounds_indexing/simple.stderr b/tests/ui/out_of_bounds_indexing/simple.stderr index 3d95afcdab233..ea5e83e87e089 100644 --- a/tests/ui/out_of_bounds_indexing/simple.stderr +++ b/tests/ui/out_of_bounds_indexing/simple.stderr @@ -7,31 +7,31 @@ LL | &x[..=4]; = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` error: range is out of bounds - --> $DIR/simple.rs:8:11 + --> $DIR/simple.rs:10:11 | LL | &x[1..5]; | ^ error: range is out of bounds - --> $DIR/simple.rs:9:8 + --> $DIR/simple.rs:12:8 | LL | &x[5..]; | ^ error: range is out of bounds - --> $DIR/simple.rs:10:10 + --> $DIR/simple.rs:14:10 | LL | &x[..5]; | ^ error: range is out of bounds - --> $DIR/simple.rs:11:8 + --> $DIR/simple.rs:16:8 | LL | &x[5..].iter().map(|x| 2 * x).collect::>(); | ^ error: range is out of bounds - --> $DIR/simple.rs:12:12 + --> $DIR/simple.rs:18:12 | LL | &x[0..=4]; | ^ diff --git a/tests/ui/overflow_check_conditional.rs b/tests/ui/overflow_check_conditional.rs index 14a6b98d07d14..a70bb3bc47bfb 100644 --- a/tests/ui/overflow_check_conditional.rs +++ b/tests/ui/overflow_check_conditional.rs @@ -3,13 +3,22 @@ fn test(a: u32, b: u32, c: u32) { if a + b < a {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust + //~| NOTE: `-D clippy::overflow-check-conditional` implied by `-D warnings` if a > a + b {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust if a + b < b {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust if b > a + b {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust if a - b > b {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if b < a - b {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if a - b > a {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if a < a - b {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if a + b < c {} if c > a + b {} if a - b < c {} diff --git a/tests/ui/overflow_check_conditional.stderr b/tests/ui/overflow_check_conditional.stderr index 3ec2298f828ae..b1e9f1eee54f3 100644 --- a/tests/ui/overflow_check_conditional.stderr +++ b/tests/ui/overflow_check_conditional.stderr @@ -7,43 +7,43 @@ LL | if a + b < a {} = note: `-D clippy::overflow-check-conditional` implied by `-D warnings` error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:6:8 + --> $DIR/overflow_check_conditional.rs:8:8 | LL | if a > a + b {} | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:7:8 + --> $DIR/overflow_check_conditional.rs:10:8 | LL | if a + b < b {} | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:8:8 + --> $DIR/overflow_check_conditional.rs:12:8 | LL | if b > a + b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:9:8 + --> $DIR/overflow_check_conditional.rs:14:8 | LL | if a - b > b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:10:8 + --> $DIR/overflow_check_conditional.rs:16:8 | LL | if b < a - b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:11:8 + --> $DIR/overflow_check_conditional.rs:18:8 | LL | if a - b > a {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:12:8 + --> $DIR/overflow_check_conditional.rs:20:8 | LL | if a < a - b {} | ^^^^^^^^^ diff --git a/tests/ui/overly_complex_bool_expr.fixed b/tests/ui/overly_complex_bool_expr.fixed index f143cf70fcfad..e44f6063156a7 100644 --- a/tests/ui/overly_complex_bool_expr.fixed +++ b/tests/ui/overly_complex_bool_expr.fixed @@ -9,8 +9,10 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = a; + //~^ ERROR: this boolean expression contains a logic bug let _ = !(a && b); let _ = false; + //~^ ERROR: this boolean expression contains a logic bug // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; @@ -21,8 +23,11 @@ fn equality_stuff() { let a: i32 = unimplemented!(); let b: i32 = unimplemented!(); let _ = false; + //~^ ERROR: this boolean expression contains a logic bug let _ = false; + //~^ ERROR: this boolean expression contains a logic bug let _ = false; + //~^ ERROR: this boolean expression contains a logic bug let _ = a > b && a == b; } diff --git a/tests/ui/overly_complex_bool_expr.rs b/tests/ui/overly_complex_bool_expr.rs index 04a30a83250e1..f010a8537e7f7 100644 --- a/tests/ui/overly_complex_bool_expr.rs +++ b/tests/ui/overly_complex_bool_expr.rs @@ -9,8 +9,10 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = a && b || a; + //~^ ERROR: this boolean expression contains a logic bug let _ = !(a && b); let _ = false && a; + //~^ ERROR: this boolean expression contains a logic bug // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; @@ -21,8 +23,11 @@ fn equality_stuff() { let a: i32 = unimplemented!(); let b: i32 = unimplemented!(); let _ = a == b && a != b; + //~^ ERROR: this boolean expression contains a logic bug let _ = a < b && a >= b; + //~^ ERROR: this boolean expression contains a logic bug let _ = a > b && a <= b; + //~^ ERROR: this boolean expression contains a logic bug let _ = a > b && a == b; } diff --git a/tests/ui/overly_complex_bool_expr.stderr b/tests/ui/overly_complex_bool_expr.stderr index e989f2ece3080..d296b88224d8c 100644 --- a/tests/ui/overly_complex_bool_expr.stderr +++ b/tests/ui/overly_complex_bool_expr.stderr @@ -12,49 +12,49 @@ LL | let _ = a && b || a; = note: `-D clippy::overly-complex-bool-expr` implied by `-D warnings` error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:13:13 + --> $DIR/overly_complex_bool_expr.rs:14:13 | LL | let _ = false && a; | ^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:13:22 + --> $DIR/overly_complex_bool_expr.rs:14:22 | LL | let _ = false && a; | ^ error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:23:13 + --> $DIR/overly_complex_bool_expr.rs:25:13 | LL | let _ = a == b && a != b; | ^^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:23:13 + --> $DIR/overly_complex_bool_expr.rs:25:13 | LL | let _ = a == b && a != b; | ^^^^^^ error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:24:13 + --> $DIR/overly_complex_bool_expr.rs:27:13 | LL | let _ = a < b && a >= b; | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:24:13 + --> $DIR/overly_complex_bool_expr.rs:27:13 | LL | let _ = a < b && a >= b; | ^^^^^ error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:25:13 + --> $DIR/overly_complex_bool_expr.rs:29:13 | LL | let _ = a > b && a <= b; | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:25:13 + --> $DIR/overly_complex_bool_expr.rs:29:13 | LL | let _ = a > b && a <= b; | ^^^^^ diff --git a/tests/ui/panic_in_result_fn.rs b/tests/ui/panic_in_result_fn.rs index e75eb1b6eadd8..41e2f5226899d 100644 --- a/tests/ui/panic_in_result_fn.rs +++ b/tests/ui/panic_in_result_fn.rs @@ -4,6 +4,7 @@ struct A; impl A { fn result_with_panic() -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { panic!("error"); } @@ -50,6 +51,7 @@ impl A { } fn function_result_with_panic() -> Result // should emit lint +//~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { panic!("error"); } diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr index b758fc2381248..9040018f1d4c9 100644 --- a/tests/ui/panic_in_result_fn.stderr +++ b/tests/ui/panic_in_result_fn.stderr @@ -2,6 +2,7 @@ error: used `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:6:5 | LL | / fn result_with_panic() -> Result // should emit lint +LL | | LL | | { LL | | panic!("error"); LL | | } @@ -9,16 +10,17 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:8:9 + --> $DIR/panic_in_result_fn.rs:9:9 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` error: used `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn.rs:52:1 + --> $DIR/panic_in_result_fn.rs:53:1 | LL | / fn function_result_with_panic() -> Result // should emit lint +LL | | LL | | { LL | | panic!("error"); LL | | } @@ -26,7 +28,7 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:54:5 + --> $DIR/panic_in_result_fn.rs:56:5 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/panic_in_result_fn_assertions.rs b/tests/ui/panic_in_result_fn_assertions.rs index 08ab4d8681edd..672c4c7383392 100644 --- a/tests/ui/panic_in_result_fn_assertions.rs +++ b/tests/ui/panic_in_result_fn_assertions.rs @@ -5,18 +5,21 @@ struct A; impl A { fn result_with_assert_with_message(x: i32) -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { assert!(x == 5, "wrong argument"); Ok(true) } fn result_with_assert_eq(x: i32) -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { assert_eq!(x, 5); Ok(true) } fn result_with_assert_ne(x: i32) -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { assert_ne!(x, 1); Ok(true) diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr index 0dd213a7eede9..368a9970af850 100644 --- a/tests/ui/panic_in_result_fn_assertions.stderr +++ b/tests/ui/panic_in_result_fn_assertions.stderr @@ -2,6 +2,7 @@ error: used `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn_assertions.rs:7:5 | LL | / fn result_with_assert_with_message(x: i32) -> Result // should emit lint +LL | | LL | | { LL | | assert!(x == 5, "wrong argument"); LL | | Ok(true) @@ -10,16 +11,17 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:9:9 + --> $DIR/panic_in_result_fn_assertions.rs:10:9 | LL | assert!(x == 5, "wrong argument"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` error: used `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_assertions.rs:13:5 + --> $DIR/panic_in_result_fn_assertions.rs:14:5 | LL | / fn result_with_assert_eq(x: i32) -> Result // should emit lint +LL | | LL | | { LL | | assert_eq!(x, 5); LL | | Ok(true) @@ -28,15 +30,16 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:15:9 + --> $DIR/panic_in_result_fn_assertions.rs:17:9 | LL | assert_eq!(x, 5); | ^^^^^^^^^^^^^^^^ error: used `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_assertions.rs:19:5 + --> $DIR/panic_in_result_fn_assertions.rs:21:5 | LL | / fn result_with_assert_ne(x: i32) -> Result // should emit lint +LL | | LL | | { LL | | assert_ne!(x, 1); LL | | Ok(true) @@ -45,7 +48,7 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:21:9 + --> $DIR/panic_in_result_fn_assertions.rs:24:9 | LL | assert_ne!(x, 1); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/panicking_macros.rs b/tests/ui/panicking_macros.rs index 041ef17fa6834..dccfbd409e503 100644 --- a/tests/ui/panicking_macros.rs +++ b/tests/ui/panicking_macros.rs @@ -21,41 +21,61 @@ fn inline_const() { fn panic() { let a = 2; panic!(); + //~^ ERROR: `panic` should not be present in production code + //~| NOTE: `-D clippy::panic` implied by `-D warnings` panic!("message"); + //~^ ERROR: `panic` should not be present in production code panic!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: `panic` should not be present in production code let b = a + 2; } fn todo() { let a = 2; todo!(); + //~^ ERROR: `todo` should not be present in production code + //~| NOTE: `-D clippy::todo` implied by `-D warnings` todo!("message"); + //~^ ERROR: `todo` should not be present in production code todo!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: `todo` should not be present in production code let b = a + 2; } fn unimplemented() { let a = 2; unimplemented!(); + //~^ ERROR: `unimplemented` should not be present in production code + //~| NOTE: `-D clippy::unimplemented` implied by `-D warnings` unimplemented!("message"); + //~^ ERROR: `unimplemented` should not be present in production code unimplemented!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: `unimplemented` should not be present in production code let b = a + 2; } fn unreachable() { let a = 2; unreachable!(); + //~^ ERROR: usage of the `unreachable!` macro + //~| NOTE: `-D clippy::unreachable` implied by `-D warnings` unreachable!("message"); + //~^ ERROR: usage of the `unreachable!` macro unreachable!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: usage of the `unreachable!` macro let b = a + 2; } fn core_versions() { use core::{panic, todo, unimplemented, unreachable}; panic!(); + //~^ ERROR: `panic` should not be present in production code todo!(); + //~^ ERROR: `todo` should not be present in production code unimplemented!(); + //~^ ERROR: `unimplemented` should not be present in production code unreachable!(); + //~^ ERROR: usage of the `unreachable!` macro } fn assert() { diff --git a/tests/ui/panicking_macros.stderr b/tests/ui/panicking_macros.stderr index 4ceb6d1440f61..b47220d2cdc35 100644 --- a/tests/ui/panicking_macros.stderr +++ b/tests/ui/panicking_macros.stderr @@ -7,19 +7,19 @@ LL | panic!(); = note: `-D clippy::panic` implied by `-D warnings` error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:24:5 + --> $DIR/panicking_macros.rs:26:5 | LL | panic!("message"); | ^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:25:5 + --> $DIR/panicking_macros.rs:28:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:31:5 + --> $DIR/panicking_macros.rs:35:5 | LL | todo!(); | ^^^^^^^ @@ -27,19 +27,19 @@ LL | todo!(); = note: `-D clippy::todo` implied by `-D warnings` error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:32:5 + --> $DIR/panicking_macros.rs:38:5 | LL | todo!("message"); | ^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:33:5 + --> $DIR/panicking_macros.rs:40:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:39:5 + --> $DIR/panicking_macros.rs:47:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ @@ -47,19 +47,19 @@ LL | unimplemented!(); = note: `-D clippy::unimplemented` implied by `-D warnings` error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:40:5 + --> $DIR/panicking_macros.rs:50:5 | LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:41:5 + --> $DIR/panicking_macros.rs:52:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:47:5 + --> $DIR/panicking_macros.rs:59:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ @@ -67,37 +67,37 @@ LL | unreachable!(); = note: `-D clippy::unreachable` implied by `-D warnings` error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:48:5 + --> $DIR/panicking_macros.rs:62:5 | LL | unreachable!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:49:5 + --> $DIR/panicking_macros.rs:64:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:55:5 + --> $DIR/panicking_macros.rs:71:5 | LL | panic!(); | ^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:56:5 + --> $DIR/panicking_macros.rs:73:5 | LL | todo!(); | ^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:57:5 + --> $DIR/panicking_macros.rs:75:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:58:5 + --> $DIR/panicking_macros.rs:77:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ diff --git a/tests/ui/partial_pub_fields.rs b/tests/ui/partial_pub_fields.rs index 668545da84419..316b36c25eacd 100644 --- a/tests/ui/partial_pub_fields.rs +++ b/tests/ui/partial_pub_fields.rs @@ -8,19 +8,23 @@ fn main() { pub struct FileSet { files: HashMap, pub paths: HashMap, + //~^ ERROR: mixed usage of pub and non-pub fields } pub struct Color { pub r: u8, pub g: u8, b: u8, + //~^ ERROR: mixed usage of pub and non-pub fields } pub struct Point(i32, pub i32); + //~^ ERROR: mixed usage of pub and non-pub fields pub struct Visibility { r#pub: bool, pub pos: u32, + //~^ ERROR: mixed usage of pub and non-pub fields } // Don't lint on empty structs; diff --git a/tests/ui/partial_pub_fields.stderr b/tests/ui/partial_pub_fields.stderr index 84cfc1a91940d..95960201769e2 100644 --- a/tests/ui/partial_pub_fields.stderr +++ b/tests/ui/partial_pub_fields.stderr @@ -8,7 +8,7 @@ LL | pub paths: HashMap, = note: `-D clippy::partial-pub-fields` implied by `-D warnings` error: mixed usage of pub and non-pub fields - --> $DIR/partial_pub_fields.rs:16:9 + --> $DIR/partial_pub_fields.rs:17:9 | LL | b: u8, | ^ @@ -16,7 +16,7 @@ LL | b: u8, = help: consider using public field here error: mixed usage of pub and non-pub fields - --> $DIR/partial_pub_fields.rs:19:27 + --> $DIR/partial_pub_fields.rs:21:27 | LL | pub struct Point(i32, pub i32); | ^^^ @@ -24,7 +24,7 @@ LL | pub struct Point(i32, pub i32); = help: consider using private field here error: mixed usage of pub and non-pub fields - --> $DIR/partial_pub_fields.rs:23:9 + --> $DIR/partial_pub_fields.rs:26:9 | LL | pub pos: u32, | ^^^ diff --git a/tests/ui/partialeq_ne_impl.rs b/tests/ui/partialeq_ne_impl.rs index 1338d3c74d554..555eeebe1c78a 100644 --- a/tests/ui/partialeq_ne_impl.rs +++ b/tests/ui/partialeq_ne_impl.rs @@ -7,6 +7,8 @@ impl PartialEq for Foo { true } fn ne(&self, _: &Foo) -> bool { + //~^ ERROR: re-implementing `PartialEq::ne` is unnecessary + //~| NOTE: `-D clippy::partialeq-ne-impl` implied by `-D warnings` false } } diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr index b92da4511b48d..04b29dd8764aa 100644 --- a/tests/ui/partialeq_ne_impl.stderr +++ b/tests/ui/partialeq_ne_impl.stderr @@ -2,6 +2,8 @@ error: re-implementing `PartialEq::ne` is unnecessary --> $DIR/partialeq_ne_impl.rs:9:5 | LL | / fn ne(&self, _: &Foo) -> bool { +LL | | +LL | | LL | | false LL | | } | |_____^ diff --git a/tests/ui/pattern_type_mismatch/mutability.rs b/tests/ui/pattern_type_mismatch/mutability.rs index 55a8c26215e9e..61dee47cb1927 100644 --- a/tests/ui/pattern_type_mismatch/mutability.rs +++ b/tests/ui/pattern_type_mismatch/mutability.rs @@ -7,12 +7,14 @@ fn should_lint() { let value = &Some(23); match value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type _ => (), } let value = &mut Some(23); match value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type _ => (), } } diff --git a/tests/ui/pattern_type_mismatch/mutability.stderr b/tests/ui/pattern_type_mismatch/mutability.stderr index 87fb243b65efd..b512f5e1ee256 100644 --- a/tests/ui/pattern_type_mismatch/mutability.stderr +++ b/tests/ui/pattern_type_mismatch/mutability.stderr @@ -8,7 +8,7 @@ LL | Some(_) => (), = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/mutability.rs:15:9 + --> $DIR/mutability.rs:16:9 | LL | Some(_) => (), | ^^^^^^^ diff --git a/tests/ui/pattern_type_mismatch/pattern_alternatives.rs b/tests/ui/pattern_type_mismatch/pattern_alternatives.rs index 065ea9fb9b5a4..558d496ae2c0f 100644 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.rs +++ b/tests/ui/pattern_type_mismatch/pattern_alternatives.rs @@ -13,8 +13,11 @@ fn alternatives() { // not ok if let Value::B | Value::A(_) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let &Value::B | &Value::A(Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let Value::B | Value::A(Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &Value::B | &Value::A(_) = ref_value {} diff --git a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr index a91b5ac6cf742..8e0d13bc8bdb8 100644 --- a/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr @@ -8,7 +8,7 @@ LL | if let Value::B | Value::A(_) = ref_value {} = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/pattern_alternatives.rs:16:34 + --> $DIR/pattern_alternatives.rs:17:34 | LL | if let &Value::B | &Value::A(Some(_)) = ref_value {} | ^^^^^^^ @@ -16,7 +16,7 @@ LL | if let &Value::B | &Value::A(Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_alternatives.rs:17:32 + --> $DIR/pattern_alternatives.rs:19:32 | LL | if let Value::B | Value::A(Some(_)) = *ref_value {} | ^^^^^^^ diff --git a/tests/ui/pattern_type_mismatch/pattern_structs.rs b/tests/ui/pattern_type_mismatch/pattern_structs.rs index 417b1c107c55b..d9b22693f297f 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.rs +++ b/tests/ui/pattern_type_mismatch/pattern_structs.rs @@ -11,8 +11,11 @@ fn struct_types() { // not ok let Struct { .. } = ref_value; + //~^ ERROR: type of pattern does not match the expression type if let &Struct { ref_inner: Some(_) } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let Struct { ref_inner: Some(_) } = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok let &Struct { .. } = ref_value; @@ -30,10 +33,15 @@ fn struct_enum_variants() { // not ok if let StructEnum::Var { .. } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let StructEnum::Empty = ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &StructEnum::Var { .. } = ref_value {} diff --git a/tests/ui/pattern_type_mismatch/pattern_structs.stderr b/tests/ui/pattern_type_mismatch/pattern_structs.stderr index 8bc5c63baab5b..a0c7a67b521e2 100644 --- a/tests/ui/pattern_type_mismatch/pattern_structs.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_structs.stderr @@ -8,7 +8,7 @@ LL | let Struct { .. } = ref_value; = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:14:33 + --> $DIR/pattern_structs.rs:15:33 | LL | if let &Struct { ref_inner: Some(_) } = ref_value {} | ^^^^^^^ @@ -16,7 +16,7 @@ LL | if let &Struct { ref_inner: Some(_) } = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:15:32 + --> $DIR/pattern_structs.rs:17:32 | LL | if let Struct { ref_inner: Some(_) } = *ref_value {} | ^^^^^^^ @@ -24,7 +24,7 @@ LL | if let Struct { ref_inner: Some(_) } = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:32:12 + --> $DIR/pattern_structs.rs:35:12 | LL | if let StructEnum::Var { .. } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | if let StructEnum::Var { .. } = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:33:12 + --> $DIR/pattern_structs.rs:37:12 | LL | if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:34:42 + --> $DIR/pattern_structs.rs:39:42 | LL | if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^ @@ -48,7 +48,7 @@ LL | if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:35:41 + --> $DIR/pattern_structs.rs:41:41 | LL | if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} | ^^^^^^^ @@ -56,7 +56,7 @@ LL | if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:36:12 + --> $DIR/pattern_structs.rs:43:12 | LL | if let StructEnum::Empty = ref_value {} | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/pattern_type_mismatch/pattern_tuples.rs b/tests/ui/pattern_type_mismatch/pattern_tuples.rs index 19504a051d8b1..f44e3543c96ad 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.rs +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.rs @@ -9,8 +9,11 @@ fn tuple_types() { // not ok let TupleStruct(_) = ref_value; + //~^ ERROR: type of pattern does not match the expression type if let &TupleStruct(Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let TupleStruct(Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok let &TupleStruct(_) = ref_value; @@ -28,9 +31,13 @@ fn tuple_enum_variants() { // not ok if let TupleEnum::Var(_) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let &TupleEnum::Var(Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let TupleEnum::Var(Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let TupleEnum::Empty = ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &TupleEnum::Var(_) = ref_value {} @@ -46,8 +53,11 @@ fn plain_tuples() { // not ok let (_a, _b) = ref_value; + //~^ ERROR: type of pattern does not match the expression type if let &(_a, Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let (_a, Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok let &(_a, _b) = ref_value; diff --git a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr index a1ef540d28313..1001f4f63c686 100644 --- a/tests/ui/pattern_type_mismatch/pattern_tuples.stderr +++ b/tests/ui/pattern_type_mismatch/pattern_tuples.stderr @@ -8,7 +8,7 @@ LL | let TupleStruct(_) = ref_value; = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:12:25 + --> $DIR/pattern_tuples.rs:13:25 | LL | if let &TupleStruct(Some(_)) = ref_value {} | ^^^^^^^ @@ -16,7 +16,7 @@ LL | if let &TupleStruct(Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:13:24 + --> $DIR/pattern_tuples.rs:15:24 | LL | if let TupleStruct(Some(_)) = *ref_value {} | ^^^^^^^ @@ -24,7 +24,7 @@ LL | if let TupleStruct(Some(_)) = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:30:12 + --> $DIR/pattern_tuples.rs:33:12 | LL | if let TupleEnum::Var(_) = ref_value {} | ^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | if let TupleEnum::Var(_) = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:31:28 + --> $DIR/pattern_tuples.rs:35:28 | LL | if let &TupleEnum::Var(Some(_)) = ref_value {} | ^^^^^^^ @@ -40,7 +40,7 @@ LL | if let &TupleEnum::Var(Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:32:27 + --> $DIR/pattern_tuples.rs:37:27 | LL | if let TupleEnum::Var(Some(_)) = *ref_value {} | ^^^^^^^ @@ -48,7 +48,7 @@ LL | if let TupleEnum::Var(Some(_)) = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:33:12 + --> $DIR/pattern_tuples.rs:39:12 | LL | if let TupleEnum::Empty = ref_value {} | ^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | if let TupleEnum::Empty = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:48:9 + --> $DIR/pattern_tuples.rs:55:9 | LL | let (_a, _b) = ref_value; | ^^^^^^^^ @@ -64,7 +64,7 @@ LL | let (_a, _b) = ref_value; = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:49:18 + --> $DIR/pattern_tuples.rs:57:18 | LL | if let &(_a, Some(_)) = ref_value {} | ^^^^^^^ @@ -72,7 +72,7 @@ LL | if let &(_a, Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:50:17 + --> $DIR/pattern_tuples.rs:59:17 | LL | if let (_a, Some(_)) = *ref_value {} | ^^^^^^^ diff --git a/tests/ui/pattern_type_mismatch/syntax.rs b/tests/ui/pattern_type_mismatch/syntax.rs index e89917c41e8c1..dbc7c3f31061c 100644 --- a/tests/ui/pattern_type_mismatch/syntax.rs +++ b/tests/ui/pattern_type_mismatch/syntax.rs @@ -9,6 +9,7 @@ fn syntax_match() { // not ok match ref_value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type None => (), } @@ -28,6 +29,7 @@ fn syntax_if_let() { // not ok if let Some(_) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &Some(_) = ref_value {} @@ -39,6 +41,7 @@ fn syntax_while_let() { // not ok while let Some(_) = ref_value { + //~^ ERROR: type of pattern does not match the expression type break; } @@ -57,6 +60,7 @@ fn syntax_for() { // not ok for (_a, _b) in slice.iter() {} + //~^ ERROR: type of pattern does not match the expression type // ok for &(_a, _b) in slice.iter() {} @@ -67,6 +71,7 @@ fn syntax_let() { // not ok let (_n, _m) = ref_value; + //~^ ERROR: type of pattern does not match the expression type // ok let &(_n, _m) = ref_value; @@ -76,6 +81,7 @@ fn syntax_let() { fn syntax_fn() { // not ok fn foo((_a, _b): &(i32, i32)) {} + //~^ ERROR: type of pattern does not match the expression type // ok fn foo_ok_1(&(_a, _b): &(i32, i32)) {} @@ -90,6 +96,7 @@ fn syntax_closure() { // not ok foo(|(_a, _b)| ()); + //~^ ERROR: type of pattern does not match the expression type // ok foo(|&(_a, _b)| ()); @@ -106,6 +113,7 @@ fn macro_with_expression() { // not ok matching_macro!(match value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type _ => (), }); diff --git a/tests/ui/pattern_type_mismatch/syntax.stderr b/tests/ui/pattern_type_mismatch/syntax.stderr index f56a3a893801b..36869598815d7 100644 --- a/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/tests/ui/pattern_type_mismatch/syntax.stderr @@ -8,7 +8,7 @@ LL | Some(_) => (), = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` error: type of pattern does not match the expression type - --> $DIR/syntax.rs:30:12 + --> $DIR/syntax.rs:31:12 | LL | if let Some(_) = ref_value {} | ^^^^^^^ @@ -16,7 +16,7 @@ LL | if let Some(_) = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:41:15 + --> $DIR/syntax.rs:43:15 | LL | while let Some(_) = ref_value { | ^^^^^^^ @@ -24,7 +24,7 @@ LL | while let Some(_) = ref_value { = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:59:9 + --> $DIR/syntax.rs:62:9 | LL | for (_a, _b) in slice.iter() {} | ^^^^^^^^ @@ -32,7 +32,7 @@ LL | for (_a, _b) in slice.iter() {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:69:9 + --> $DIR/syntax.rs:73:9 | LL | let (_n, _m) = ref_value; | ^^^^^^^^ @@ -40,7 +40,7 @@ LL | let (_n, _m) = ref_value; = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:78:12 + --> $DIR/syntax.rs:83:12 | LL | fn foo((_a, _b): &(i32, i32)) {} | ^^^^^^^^ @@ -48,7 +48,7 @@ LL | fn foo((_a, _b): &(i32, i32)) {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:92:10 + --> $DIR/syntax.rs:98:10 | LL | foo(|(_a, _b)| ()); | ^^^^^^^^ @@ -56,7 +56,7 @@ LL | foo(|(_a, _b)| ()); = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:108:9 + --> $DIR/syntax.rs:115:9 | LL | Some(_) => (), | ^^^^^^^ @@ -64,7 +64,7 @@ LL | Some(_) => (), = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:128:17 + --> $DIR/syntax.rs:136:17 | LL | Some(_) => (), | ^^^^^^^ diff --git a/tests/ui/permissions_set_readonly_false.rs b/tests/ui/permissions_set_readonly_false.rs index 28c00d100942c..5a84a64fd2d10 100644 --- a/tests/ui/permissions_set_readonly_false.rs +++ b/tests/ui/permissions_set_readonly_false.rs @@ -17,6 +17,8 @@ fn main() { let mut permissions = metadata.permissions(); // lint here permissions.set_readonly(false); + //~^ ERROR: call to `set_readonly` with argument `false` + //~| NOTE: on Unix platforms this results in the file being world writable // no lint permissions.set_readonly(true); diff --git a/tests/ui/print.rs b/tests/ui/print.rs index 366ccc2b3bd58..9ac4b51e1afd9 100644 --- a/tests/ui/print.rs +++ b/tests/ui/print.rs @@ -9,6 +9,8 @@ struct Foo; impl Display for Foo { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{:?}", 43.1415) + //~^ ERROR: use of `Debug`-based formatting + //~| NOTE: `-D clippy::use-debug` implied by `-D warnings` } } @@ -21,13 +23,21 @@ impl Debug for Foo { fn main() { println!("Hello"); + //~^ ERROR: use of `println!` + //~| NOTE: `-D clippy::print-stdout` implied by `-D warnings` print!("Hello"); + //~^ ERROR: use of `print!` print!("Hello {}", "World"); + //~^ ERROR: use of `print!` print!("Hello {:?}", "World"); + //~^ ERROR: use of `print!` + //~| ERROR: use of `Debug`-based formatting print!("Hello {:#?}", "#orld"); + //~^ ERROR: use of `print!` + //~| ERROR: use of `Debug`-based formatting assert_eq!(42, 1337); diff --git a/tests/ui/print.stderr b/tests/ui/print.stderr index 1754c418381a1..e9d88df33f597 100644 --- a/tests/ui/print.stderr +++ b/tests/ui/print.stderr @@ -7,7 +7,7 @@ LL | write!(f, "{:?}", 43.1415) = note: `-D clippy::use-debug` implied by `-D warnings` error: use of `println!` - --> $DIR/print.rs:23:5 + --> $DIR/print.rs:25:5 | LL | println!("Hello"); | ^^^^^^^^^^^^^^^^^ @@ -15,37 +15,37 @@ LL | println!("Hello"); = note: `-D clippy::print-stdout` implied by `-D warnings` error: use of `print!` - --> $DIR/print.rs:24:5 + --> $DIR/print.rs:28:5 | LL | print!("Hello"); | ^^^^^^^^^^^^^^^ error: use of `print!` - --> $DIR/print.rs:26:5 + --> $DIR/print.rs:31:5 | LL | print!("Hello {}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `print!` - --> $DIR/print.rs:28:5 + --> $DIR/print.rs:34:5 | LL | print!("Hello {:?}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> $DIR/print.rs:28:19 + --> $DIR/print.rs:34:19 | LL | print!("Hello {:?}", "World"); | ^^^^ error: use of `print!` - --> $DIR/print.rs:30:5 + --> $DIR/print.rs:38:5 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> $DIR/print.rs:30:19 + --> $DIR/print.rs:38:19 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^ diff --git a/tests/ui/print_in_format_impl.rs b/tests/ui/print_in_format_impl.rs index deafcbfb8c366..261f50832199c 100644 --- a/tests/ui/print_in_format_impl.rs +++ b/tests/ui/print_in_format_impl.rs @@ -18,11 +18,17 @@ impl Debug for Foo { static WORKS_WITH_NESTED_ITEMS: bool = true; print!("{}", 1); + //~^ ERROR: use of `print!` in `Debug` impl + //~| NOTE: `-D clippy::print-in-format-impl` implied by `-D warnings` println!("{}", 2); + //~^ ERROR: use of `println!` in `Debug` impl eprint!("{}", 3); + //~^ ERROR: use of `eprint!` in `Debug` impl eprintln!("{}", 4); + //~^ ERROR: use of `eprintln!` in `Debug` impl nested! { println!("nested"); + //~^ ERROR: use of `println!` in `Debug` impl }; write!(f, "{}", 5); @@ -36,6 +42,7 @@ impl Debug for Foo { impl Display for Foo { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { print!("Display"); + //~^ ERROR: use of `print!` in `Display` impl write!(f, "Display"); Ok(()) @@ -46,6 +53,7 @@ struct UnnamedFormatter; impl Debug for UnnamedFormatter { fn fmt(&self, _: &mut Formatter) -> Result<(), Error> { println!("UnnamedFormatter"); + //~^ ERROR: use of `println!` in `Debug` impl Ok(()) } } diff --git a/tests/ui/print_in_format_impl.stderr b/tests/ui/print_in_format_impl.stderr index 63b7179bca7dc..7a7a2dc1c2a7f 100644 --- a/tests/ui/print_in_format_impl.stderr +++ b/tests/ui/print_in_format_impl.stderr @@ -7,37 +7,37 @@ LL | print!("{}", 1); = note: `-D clippy::print-in-format-impl` implied by `-D warnings` error: use of `println!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:21:9 + --> $DIR/print_in_format_impl.rs:23:9 | LL | println!("{}", 2); | ^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `eprint!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:22:9 + --> $DIR/print_in_format_impl.rs:25:9 | LL | eprint!("{}", 3); | ^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `eprintln!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:23:9 + --> $DIR/print_in_format_impl.rs:27:9 | LL | eprintln!("{}", 4); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `println!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:25:13 + --> $DIR/print_in_format_impl.rs:30:13 | LL | println!("nested"); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `print!` in `Display` impl - --> $DIR/print_in_format_impl.rs:38:9 + --> $DIR/print_in_format_impl.rs:44:9 | LL | print!("Display"); | ^^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `println!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:48:9 + --> $DIR/print_in_format_impl.rs:55:9 | LL | println!("UnnamedFormatter"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(..)` diff --git a/tests/ui/print_literal.fixed b/tests/ui/print_literal.fixed index 48fe024ef63f7..88cd3a54b4100 100644 --- a/tests/ui/print_literal.fixed +++ b/tests/ui/print_literal.fixed @@ -25,19 +25,32 @@ fn main() { // these should throw warnings print!("Hello world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::print-literal` implied by `-D warnings` println!("Hello {} world", world); + //~^ ERROR: literal with an empty format string println!("Hello world"); + //~^ ERROR: literal with an empty format string println!("a literal {:.4}", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning println!("hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either println!("hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // The string literal from `file!()` has a callsite span that isn't marked as coming from an // expansion diff --git a/tests/ui/print_literal.rs b/tests/ui/print_literal.rs index 538513e9156f8..bd7444c9606ab 100644 --- a/tests/ui/print_literal.rs +++ b/tests/ui/print_literal.rs @@ -25,19 +25,32 @@ fn main() { // these should throw warnings print!("Hello {}", "world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::print-literal` implied by `-D warnings` println!("Hello {} {}", world, "world"); + //~^ ERROR: literal with an empty format string println!("Hello {}", "world"); + //~^ ERROR: literal with an empty format string println!("{} {:.4}", "a literal", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning println!("{0} {1}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("{1} {0}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either println!("{foo} {bar}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("{bar} {foo}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // The string literal from `file!()` has a callsite span that isn't marked as coming from an // expansion diff --git a/tests/ui/print_literal.stderr b/tests/ui/print_literal.stderr index 71c8d188f1678..d7a2fa7f4bb47 100644 --- a/tests/ui/print_literal.stderr +++ b/tests/ui/print_literal.stderr @@ -12,7 +12,7 @@ LL + print!("Hello world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:28:36 + --> $DIR/print_literal.rs:30:36 | LL | println!("Hello {} {}", world, "world"); | ^^^^^^^ @@ -24,7 +24,7 @@ LL + println!("Hello {} world", world); | error: literal with an empty format string - --> $DIR/print_literal.rs:29:26 + --> $DIR/print_literal.rs:32:26 | LL | println!("Hello {}", "world"); | ^^^^^^^ @@ -36,7 +36,7 @@ LL + println!("Hello world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:30:26 + --> $DIR/print_literal.rs:34:26 | LL | println!("{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + println!("a literal {:.4}", 5); | error: literal with an empty format string - --> $DIR/print_literal.rs:35:25 + --> $DIR/print_literal.rs:40:25 | LL | println!("{0} {1}", "hello", "world"); | ^^^^^^^ @@ -60,7 +60,7 @@ LL + println!("hello {1}", "world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:35:34 + --> $DIR/print_literal.rs:40:34 | LL | println!("{0} {1}", "hello", "world"); | ^^^^^^^ @@ -72,7 +72,7 @@ LL + println!("{0} world", "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:36:34 + --> $DIR/print_literal.rs:43:34 | LL | println!("{1} {0}", "hello", "world"); | ^^^^^^^ @@ -84,7 +84,7 @@ LL + println!("world {0}", "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:36:25 + --> $DIR/print_literal.rs:43:25 | LL | println!("{1} {0}", "hello", "world"); | ^^^^^^^ @@ -96,7 +96,7 @@ LL + println!("{1} hello", "world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:39:35 + --> $DIR/print_literal.rs:48:35 | LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -108,7 +108,7 @@ LL + println!("hello {bar}", bar = "world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:39:50 + --> $DIR/print_literal.rs:48:50 | LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -120,7 +120,7 @@ LL + println!("{foo} world", foo = "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:40:50 + --> $DIR/print_literal.rs:51:50 | LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -132,7 +132,7 @@ LL + println!("world {foo}", foo = "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:40:35 + --> $DIR/print_literal.rs:51:35 | LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ diff --git a/tests/ui/print_stderr.rs b/tests/ui/print_stderr.rs index fa07e74a7be47..109f43ffe25d1 100644 --- a/tests/ui/print_stderr.rs +++ b/tests/ui/print_stderr.rs @@ -2,7 +2,10 @@ fn main() { eprintln!("Hello"); + //~^ ERROR: use of `eprintln!` + //~| NOTE: `-D clippy::print-stderr` implied by `-D warnings` println!("This should not do anything"); eprint!("World"); + //~^ ERROR: use of `eprint!` print!("Nor should this"); } diff --git a/tests/ui/print_stderr.stderr b/tests/ui/print_stderr.stderr index 5af735af65769..0a56fbcec9999 100644 --- a/tests/ui/print_stderr.stderr +++ b/tests/ui/print_stderr.stderr @@ -7,7 +7,7 @@ LL | eprintln!("Hello"); = note: `-D clippy::print-stderr` implied by `-D warnings` error: use of `eprint!` - --> $DIR/print_stderr.rs:6:5 + --> $DIR/print_stderr.rs:8:5 | LL | eprint!("World"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/print_with_newline.fixed b/tests/ui/print_with_newline.fixed index c9c3b925aa699..7ac6d2870c123 100644 --- a/tests/ui/print_with_newline.fixed +++ b/tests/ui/print_with_newline.fixed @@ -5,10 +5,16 @@ fn main() { println!("Hello"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` println!("Hello {}", "world"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline println!("Hello {} {}", "world", "#2"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline println!("{}", 1265); + //~^ ERROR: using `print!()` with a format string that ends in a single newline println!(); + //~^ ERROR: using `print!()` with a format string that ends in a single newline // these are all fine print!(""); @@ -31,6 +37,7 @@ fn main() { // #3514 print!("\\n"); println!("\\"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("\\\\n"); // Raw strings @@ -39,9 +46,11 @@ fn main() { // Literal newlines should also fail println!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline ); println!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline ); @@ -50,6 +59,7 @@ fn main() { print!("foo\r\n"); // should fail println!("\\r"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/print_with_newline.rs b/tests/ui/print_with_newline.rs index aaddbcd4be824..602d1ea3ec0e1 100644 --- a/tests/ui/print_with_newline.rs +++ b/tests/ui/print_with_newline.rs @@ -5,10 +5,16 @@ fn main() { print!("Hello\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` print!("Hello {}\n", "world"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("Hello {} {}\n", "world", "#2"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("{}\n", 1265); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline // these are all fine print!(""); @@ -31,6 +37,7 @@ fn main() { // #3514 print!("\\n"); print!("\\\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("\\\\n"); // Raw strings @@ -39,10 +46,12 @@ fn main() { // Literal newlines should also fail print!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline " " ); print!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline r" " ); @@ -52,6 +61,7 @@ fn main() { print!("foo\r\n"); // should fail print!("\\r\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr index 16cec220f8346..1c5f2548c89b6 100644 --- a/tests/ui/print_with_newline.stderr +++ b/tests/ui/print_with_newline.stderr @@ -12,7 +12,7 @@ LL + println!("Hello"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:8:5 + --> $DIR/print_with_newline.rs:10:5 | LL | print!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + println!("Hello {}", "world"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:9:5 + --> $DIR/print_with_newline.rs:12:5 | LL | print!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + println!("Hello {} {}", "world", "#2"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:10:5 + --> $DIR/print_with_newline.rs:14:5 | LL | print!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + println!("{}", 1265); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:11:5 + --> $DIR/print_with_newline.rs:16:5 | LL | print!("\n"); | ^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + println!(); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:33:5 + --> $DIR/print_with_newline.rs:39:5 | LL | print!("\\\n"); | ^^^^^^^^^^^^^^ @@ -72,9 +72,10 @@ LL + println!("\\"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:41:5 + --> $DIR/print_with_newline.rs:48:5 | LL | / print!( +LL | | LL | | " LL | | " LL | | ); @@ -83,13 +84,15 @@ LL | | ); help: use `println!` instead | LL ~ println!( +LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:45:5 + --> $DIR/print_with_newline.rs:53:5 | LL | / print!( +LL | | LL | | r" LL | | " LL | | ); @@ -98,11 +101,12 @@ LL | | ); help: use `println!` instead | LL ~ println!( +LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:54:5 + --> $DIR/print_with_newline.rs:63:5 | LL | print!("\\r\n"); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/proc_macro.rs b/tests/ui/proc_macro.rs index b77874034d0ba..e5b155dd1b8da 100644 --- a/tests/ui/proc_macro.rs +++ b/tests/ui/proc_macro.rs @@ -7,6 +7,7 @@ use proc_macro::TokenStream; #[allow(dead_code)] fn f() { let _x = 3.14; + //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found } #[proc_macro] diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index be02856b08896..91e2e7fd6427f 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -12,26 +12,33 @@ use std::borrow::Cow; use std::path::{Path, PathBuf}; fn do_vec(x: &Vec) { + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will do + //~| NOTE: `-D clippy::ptr-arg` implied by `-D warnings` //Nothing here } fn do_vec_mut(x: &mut Vec) { + //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w //Nothing here } fn do_str(x: &String) { + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d //Nothing here either } fn do_str_mut(x: &mut String) { + //~^ ERROR: writing `&mut String` instead of `&mut str` involves a new object where a slic //Nothing here either } fn do_path(x: &PathBuf) { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice will //Nothing here either } fn do_path_mut(x: &mut PathBuf) { + //~^ ERROR: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a sl //Nothing here either } @@ -40,6 +47,7 @@ fn main() {} trait Foo { type Item; fn do_vec(x: &Vec); + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will fn do_item(x: &Self::Item); } @@ -53,6 +61,7 @@ impl Foo for Bar { } fn cloned(x: &Vec) -> Vec { + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will do let e = x.clone(); let f = e.clone(); // OK let g = x; @@ -62,6 +71,7 @@ fn cloned(x: &Vec) -> Vec { } fn str_cloned(x: &String) -> String { + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d let a = x.clone(); let b = x.clone(); let c = b.clone(); @@ -70,6 +80,7 @@ fn str_cloned(x: &String) -> String { } fn path_cloned(x: &PathBuf) -> PathBuf { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice will let a = x.clone(); let b = x.clone(); let c = b.clone(); @@ -78,6 +89,7 @@ fn path_cloned(x: &PathBuf) -> PathBuf { } fn false_positive_capacity(x: &Vec, y: &String) { + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d let a = x.capacity(); let b = y.clone(); let c = y.as_str(); @@ -92,6 +104,7 @@ fn false_positive_capacity_too(x: &String) -> String { #[allow(dead_code)] fn test_cow_with_ref(c: &Cow<[i32]>) {} +//~^ ERROR: using a reference to `Cow` is not recommended fn test_cow(c: Cow<[i32]>) { let _c = c; @@ -121,6 +134,7 @@ mod issue_5644 { } fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec, _s: &String) {} + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice wi struct S; impl S { @@ -150,22 +164,26 @@ mod issue6509 { use std::path::PathBuf; fn foo_vec(vec: &Vec) { + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will let _ = vec.clone().pop(); let _ = vec.clone().clone(); } fn foo_path(path: &PathBuf) { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice let _ = path.clone().pop(); let _ = path.clone().clone(); } fn foo_str(str: &PathBuf) { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice let _ = str.clone().pop(); let _ = str.clone().clone(); } } fn mut_vec_slice_methods(v: &mut Vec) { + //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w v.copy_within(1..5, 10); } @@ -228,6 +246,9 @@ fn dyn_trait_ok(a: &mut Vec, b: &mut String, c: &mut PathBuf) { } fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { + //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w + //~| ERROR: writing `&mut String` instead of `&mut str` involves a new object where a slic + //~| ERROR: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a sl trait T {} impl T for Vec {} impl T for [U] {} @@ -251,14 +272,17 @@ mod issue_9218 { // This one has an anonymous lifetime so it's not okay fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { + //~^ ERROR: using a reference to `Cow` is not recommended todo!() } // These two's return types don't use use 'a so it's not okay fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { + //~^ ERROR: using a reference to `Cow` is not recommended todo!() } fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { + //~^ ERROR: using a reference to `Cow` is not recommended todo!() } diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr index 0e9dd760f453a..e5708ce3a7e2e 100644 --- a/tests/ui/ptr_arg.stderr +++ b/tests/ui/ptr_arg.stderr @@ -7,43 +7,43 @@ LL | fn do_vec(x: &Vec) { = note: `-D clippy::ptr-arg` implied by `-D warnings` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:18:18 + --> $DIR/ptr_arg.rs:20:18 | LL | fn do_vec_mut(x: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [i64]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:22:14 + --> $DIR/ptr_arg.rs:25:14 | LL | fn do_str(x: &String) { | ^^^^^^^ help: change this to: `&str` error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:26:18 + --> $DIR/ptr_arg.rs:30:18 | LL | fn do_str_mut(x: &mut String) { | ^^^^^^^^^^^ help: change this to: `&mut str` error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:30:15 + --> $DIR/ptr_arg.rs:35:15 | LL | fn do_path(x: &PathBuf) { | ^^^^^^^^ help: change this to: `&Path` error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:34:19 + --> $DIR/ptr_arg.rs:40:19 | LL | fn do_path_mut(x: &mut PathBuf) { | ^^^^^^^^^^^^ help: change this to: `&mut Path` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:42:18 + --> $DIR/ptr_arg.rs:49: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 - --> $DIR/ptr_arg.rs:55:14 + --> $DIR/ptr_arg.rs:63:14 | LL | fn cloned(x: &Vec) -> Vec { | ^^^^^^^^ @@ -51,6 +51,7 @@ LL | fn cloned(x: &Vec) -> Vec { help: change this to | LL ~ fn cloned(x: &[u8]) -> Vec { +LL | LL ~ let e = x.to_owned(); LL | let f = e.clone(); // OK LL | let g = x; @@ -60,7 +61,7 @@ LL ~ x.to_owned() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:64:18 + --> $DIR/ptr_arg.rs:73:18 | LL | fn str_cloned(x: &String) -> String { | ^^^^^^^ @@ -68,6 +69,7 @@ LL | fn str_cloned(x: &String) -> String { help: change this to | LL ~ fn str_cloned(x: &str) -> String { +LL | LL ~ let a = x.to_owned(); LL ~ let b = x.to_owned(); LL | let c = b.clone(); @@ -76,7 +78,7 @@ LL ~ x.to_owned() | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:72:19 + --> $DIR/ptr_arg.rs:82:19 | LL | fn path_cloned(x: &PathBuf) -> PathBuf { | ^^^^^^^^ @@ -84,6 +86,7 @@ LL | fn path_cloned(x: &PathBuf) -> PathBuf { help: change this to | LL ~ fn path_cloned(x: &Path) -> PathBuf { +LL | LL ~ let a = x.to_path_buf(); LL ~ let b = x.to_path_buf(); LL | let c = b.clone(); @@ -92,7 +95,7 @@ LL ~ x.to_path_buf() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:80:44 + --> $DIR/ptr_arg.rs:91:44 | LL | fn false_positive_capacity(x: &Vec, y: &String) { | ^^^^^^^ @@ -100,25 +103,26 @@ LL | fn false_positive_capacity(x: &Vec, y: &String) { help: change this to | LL ~ fn false_positive_capacity(x: &Vec, y: &str) { +LL | LL | let a = x.capacity(); LL ~ let b = y.to_owned(); LL ~ let c = y; | error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:94:25 + --> $DIR/ptr_arg.rs:106: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 - --> $DIR/ptr_arg.rs:123:66 + --> $DIR/ptr_arg.rs:136:66 | LL | fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec, _s: &String) {} | ^^^^^^^ help: change this to: `&str` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:152:21 + --> $DIR/ptr_arg.rs:166:21 | LL | fn foo_vec(vec: &Vec) { | ^^^^^^^^ @@ -126,12 +130,13 @@ LL | fn foo_vec(vec: &Vec) { help: change this to | LL ~ fn foo_vec(vec: &[u8]) { +LL | LL ~ let _ = vec.to_owned().pop(); LL ~ let _ = vec.to_owned().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:157:23 + --> $DIR/ptr_arg.rs:172:23 | LL | fn foo_path(path: &PathBuf) { | ^^^^^^^^ @@ -139,12 +144,13 @@ LL | fn foo_path(path: &PathBuf) { help: change this to | LL ~ fn foo_path(path: &Path) { +LL | LL ~ let _ = path.to_path_buf().pop(); LL ~ let _ = path.to_path_buf().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:162:21 + --> $DIR/ptr_arg.rs:178:21 | LL | fn foo_str(str: &PathBuf) { | ^^^^^^^^ @@ -152,48 +158,49 @@ LL | fn foo_str(str: &PathBuf) { help: change this to | LL ~ fn foo_str(str: &Path) { +LL | LL ~ let _ = str.to_path_buf().pop(); LL ~ let _ = str.to_path_buf().clone(); | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:168:29 + --> $DIR/ptr_arg.rs:185:29 | LL | fn mut_vec_slice_methods(v: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [u32]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:230:17 + --> $DIR/ptr_arg.rs:248:17 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^^ help: change this to: `&mut [u32]` error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:230:35 + --> $DIR/ptr_arg.rs:248:35 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^ help: change this to: `&mut str` error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:230:51 + --> $DIR/ptr_arg.rs:248:51 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^ help: change this to: `&mut Path` error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:253:39 + --> $DIR/ptr_arg.rs:274: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 - --> $DIR/ptr_arg.rs:258:36 + --> $DIR/ptr_arg.rs:280: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 - --> $DIR/ptr_arg.rs:261:40 + --> $DIR/ptr_arg.rs:284:40 | LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` diff --git a/tests/ui/pub_use.rs b/tests/ui/pub_use.rs index 65542bedec7bc..aef947e406a68 100644 --- a/tests/ui/pub_use.rs +++ b/tests/ui/pub_use.rs @@ -8,6 +8,7 @@ pub mod outer { } // should be linted pub use inner::Test; + //~^ ERROR: using `pub use` } // should not be linted diff --git a/tests/ui/question_mark_used.rs b/tests/ui/question_mark_used.rs index 8c3ef789697fc..715d7fab8eed2 100644 --- a/tests/ui/question_mark_used.rs +++ b/tests/ui/question_mark_used.rs @@ -9,6 +9,7 @@ fn other_function() -> Option { fn my_function() -> Option { other_function()?; + //~^ ERROR: question mark operator was used None } diff --git a/tests/ui/range.rs b/tests/ui/range.rs index 46edf0921bf2c..9541812b06911 100644 --- a/tests/ui/range.rs +++ b/tests/ui/range.rs @@ -4,6 +4,8 @@ fn main() { let v1 = vec![1, 2, 3]; let v2 = vec![4, 5]; let _x = v1.iter().zip(0..v1.len()); + //~^ ERROR: it is more idiomatic to use `v1.iter().enumerate()` + //~| NOTE: `-D clippy::range-zip-with-len` implied by `-D warnings` let _y = v1.iter().zip(0..v2.len()); // No error } diff --git a/tests/ui/rc_clone_in_vec_init/arc.rs b/tests/ui/rc_clone_in_vec_init/arc.rs index 9cb7f48e75b54..1c9e9aa7ef47d 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.rs +++ b/tests/ui/rc_clone_in_vec_init/arc.rs @@ -7,6 +7,8 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Arc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance } fn should_warn_simple_case_with_big_indentation() { @@ -15,12 +17,16 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Arc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance } } } fn should_warn_complex_case() { let v = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance std::sync::Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -30,6 +36,8 @@ fn should_warn_complex_case() { ]; let v1 = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance Arc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/tests/ui/rc_clone_in_vec_init/arc.stderr b/tests/ui/rc_clone_in_vec_init/arc.stderr index 3e82d4e57b757..87f7ed56cd3c6 100644 --- a/tests/ui/rc_clone_in_vec_init/arc.stderr +++ b/tests/ui/rc_clone_in_vec_init/arc.stderr @@ -23,7 +23,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:17:21 + --> $DIR/arc.rs:19:21 | LL | let v = vec![Arc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,13 +46,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:23:13 + --> $DIR/arc.rs:27:13 | LL | let v = vec![ | _____________^ +LL | | +LL | | LL | | std::sync::Arc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; @@ -76,13 +76,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:32:14 + --> $DIR/arc.rs:38:14 | LL | let v1 = vec![ | ______________^ +LL | | +LL | | LL | | Arc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; diff --git a/tests/ui/rc_clone_in_vec_init/rc.rs b/tests/ui/rc_clone_in_vec_init/rc.rs index 5b7ac062ddc94..01cc433cbdae1 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.rs +++ b/tests/ui/rc_clone_in_vec_init/rc.rs @@ -8,6 +8,8 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Rc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance } fn should_warn_simple_case_with_big_indentation() { @@ -16,12 +18,16 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Rc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance } } } fn should_warn_complex_case() { let v = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance std::rc::Rc::new(Mutex::new({ let x = 1; dbg!(x); @@ -31,6 +37,8 @@ fn should_warn_complex_case() { ]; let v1 = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance Rc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/tests/ui/rc_clone_in_vec_init/rc.stderr b/tests/ui/rc_clone_in_vec_init/rc.stderr index 278e497480483..3fa187f0b813d 100644 --- a/tests/ui/rc_clone_in_vec_init/rc.stderr +++ b/tests/ui/rc_clone_in_vec_init/rc.stderr @@ -23,7 +23,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:18:21 + --> $DIR/rc.rs:20:21 | LL | let v = vec![Rc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,13 +46,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:24:13 + --> $DIR/rc.rs:28:13 | LL | let v = vec![ | _____________^ +LL | | +LL | | LL | | std::rc::Rc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; @@ -76,13 +76,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:33:14 + --> $DIR/rc.rs:39:14 | LL | let v1 = vec![ | ______________^ +LL | | +LL | | LL | | Rc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; diff --git a/tests/ui/rc_clone_in_vec_init/weak.rs b/tests/ui/rc_clone_in_vec_init/weak.rs index 386cccd88f6c2..fd2895d40458a 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.rs +++ b/tests/ui/rc_clone_in_vec_init/weak.rs @@ -8,10 +8,18 @@ fn main() {} fn should_warn_simple_case() { let v = vec![SyncWeak::::new(); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v2 = vec![UnSyncWeak::::new(); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance } fn should_warn_simple_case_with_big_indentation() { @@ -20,13 +28,19 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance } } } fn should_warn_complex_case() { let v = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance Arc::downgrade(&Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -36,6 +50,8 @@ fn should_warn_complex_case() { ]; let v1 = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance Rc::downgrade(&Rc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/tests/ui/rc_clone_in_vec_init/weak.stderr b/tests/ui/rc_clone_in_vec_init/weak.stderr index ffb78590a0c88..9b60c22c28106 100644 --- a/tests/ui/rc_clone_in_vec_init/weak.stderr +++ b/tests/ui/rc_clone_in_vec_init/weak.stderr @@ -23,7 +23,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:11:14 + --> $DIR/weak.rs:13:14 | LL | let v2 = vec![UnSyncWeak::::new(); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:13:13 + --> $DIR/weak.rs:17:13 | LL | let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:14:13 + --> $DIR/weak.rs:20:13 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:22:21 + --> $DIR/weak.rs:30:21 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -115,7 +115,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:23:22 + --> $DIR/weak.rs:33:22 | LL | let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -138,13 +138,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:29:13 + --> $DIR/weak.rs:41:13 | LL | let v = vec![ | _____________^ +LL | | +LL | | LL | | Arc::downgrade(&Arc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; @@ -168,13 +168,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:38:14 + --> $DIR/weak.rs:52:14 | LL | let v1 = vec![ | ______________^ +LL | | +LL | | LL | | Rc::downgrade(&Rc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; diff --git a/tests/ui/rc_mutex.rs b/tests/ui/rc_mutex.rs index 432972bbc3175..40adb3ddce955 100644 --- a/tests/ui/rc_mutex.rs +++ b/tests/ui/rc_mutex.rs @@ -6,6 +6,7 @@ use std::sync::Mutex; pub struct MyStructWithPrivItem { foo: Rc>, + //~^ ERROR: usage of `Rc>` } pub struct MyStructWithPubItem { @@ -24,8 +25,11 @@ pub enum MyEnum { // All of these test should be trigger the lint because they are not // part of the public api fn test1(foo: Rc>) {} +//~^ ERROR: usage of `Rc>` fn test2(foo: Rc>) {} +//~^ ERROR: usage of `Rc>` fn test3(foo: Rc>>) {} +//~^ ERROR: usage of `Rc>` // All of these test should be allowed because they are part of the // public api and `avoid_breaking_exported_api` is `false` by default. diff --git a/tests/ui/rc_mutex.stderr b/tests/ui/rc_mutex.stderr index cee3bd8b224dc..e21337b0f2ed4 100644 --- a/tests/ui/rc_mutex.stderr +++ b/tests/ui/rc_mutex.stderr @@ -8,7 +8,7 @@ LL | foo: Rc>, = note: `-D clippy::rc-mutex` implied by `-D warnings` error: usage of `Rc>` - --> $DIR/rc_mutex.rs:26:18 + --> $DIR/rc_mutex.rs:27:18 | LL | fn test1(foo: Rc>) {} | ^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn test1(foo: Rc>) {} = help: consider using `Rc>` or `Arc>` instead error: usage of `Rc>` - --> $DIR/rc_mutex.rs:27:15 + --> $DIR/rc_mutex.rs:29:15 | LL | fn test2(foo: Rc>) {} | ^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn test2(foo: Rc>) {} = help: consider using `Rc>` or `Arc>` instead error: usage of `Rc>` - --> $DIR/rc_mutex.rs:28:15 + --> $DIR/rc_mutex.rs:31:15 | LL | fn test3(foo: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/read_zero_byte_vec.rs b/tests/ui/read_zero_byte_vec.rs index 979955489b64e..76b9b98185119 100644 --- a/tests/ui/read_zero_byte_vec.rs +++ b/tests/ui/read_zero_byte_vec.rs @@ -19,29 +19,36 @@ fn test() -> io::Result<()> { // should lint let mut data = Vec::with_capacity(20); f.read_exact(&mut data).unwrap(); + //~^ ERROR: reading zero byte data to `Vec` + //~| NOTE: `-D clippy::read-zero-byte-vec` implied by `-D warnings` // should lint let mut data2 = Vec::with_capacity(cap); f.read_exact(&mut data2)?; + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data3 = Vec::new(); f.read_exact(&mut data3)?; + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data4 = vec![]; let _ = f.read(&mut data4)?; + //~^ ERROR: reading zero byte data to `Vec` // should lint let _ = { let mut data5 = Vec::new(); f.read(&mut data5) + //~^ ERROR: reading zero byte data to `Vec` }; // should lint let _ = { let mut data6: Vec = Default::default(); f.read(&mut data6) + //~^ ERROR: reading zero byte data to `Vec` }; // should not lint @@ -72,20 +79,24 @@ async fn test_futures(r: &mut R) { // should lint let mut data = Vec::new(); r.read(&mut data).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data2 = Vec::new(); r.read_exact(&mut data2).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` } async fn test_tokio(r: &mut R) { // should lint let mut data = Vec::new(); r.read(&mut data).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data2 = Vec::new(); r.read_exact(&mut data2).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` } fn main() {} diff --git a/tests/ui/read_zero_byte_vec.stderr b/tests/ui/read_zero_byte_vec.stderr index 4c7f605f4c2a5..b80a614eceba3 100644 --- a/tests/ui/read_zero_byte_vec.stderr +++ b/tests/ui/read_zero_byte_vec.stderr @@ -7,55 +7,55 @@ LL | f.read_exact(&mut data).unwrap(); = note: `-D clippy::read-zero-byte-vec` implied by `-D warnings` error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:25:5 + --> $DIR/read_zero_byte_vec.rs:27:5 | LL | f.read_exact(&mut data2)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `data2.resize(cap, 0); f.read_exact(&mut data2)?;` error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:29:5 + --> $DIR/read_zero_byte_vec.rs:32:5 | LL | f.read_exact(&mut data3)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:33:5 + --> $DIR/read_zero_byte_vec.rs:37:5 | LL | let _ = f.read(&mut data4)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:38:9 + --> $DIR/read_zero_byte_vec.rs:43:9 | LL | f.read(&mut data5) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:44:9 + --> $DIR/read_zero_byte_vec.rs:50:9 | LL | f.read(&mut data6) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:74:5 + --> $DIR/read_zero_byte_vec.rs:81:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:78:5 + --> $DIR/read_zero_byte_vec.rs:86:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:84:5 + --> $DIR/read_zero_byte_vec.rs:93:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:88:5 + --> $DIR/read_zero_byte_vec.rs:98:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/readonly_write_lock.fixed b/tests/ui/readonly_write_lock.fixed index ae622a4100bf3..76f4a43ae5300 100644 --- a/tests/ui/readonly_write_lock.fixed +++ b/tests/ui/readonly_write_lock.fixed @@ -14,11 +14,14 @@ fn main() { { let writer = lock.read().unwrap(); + //~^ ERROR: this write lock is used only for reading + //~| NOTE: `-D clippy::readonly-write-lock` implied by `-D warnings` dbg!(&writer); } { let writer = lock.read().unwrap(); + //~^ ERROR: this write lock is used only for reading accept_i32(*writer); } diff --git a/tests/ui/readonly_write_lock.rs b/tests/ui/readonly_write_lock.rs index 656b45787e8a0..3d1d3855fe129 100644 --- a/tests/ui/readonly_write_lock.rs +++ b/tests/ui/readonly_write_lock.rs @@ -14,11 +14,14 @@ fn main() { { let writer = lock.write().unwrap(); + //~^ ERROR: this write lock is used only for reading + //~| NOTE: `-D clippy::readonly-write-lock` implied by `-D warnings` dbg!(&writer); } { let writer = lock.write().unwrap(); + //~^ ERROR: this write lock is used only for reading accept_i32(*writer); } diff --git a/tests/ui/readonly_write_lock.stderr b/tests/ui/readonly_write_lock.stderr index e3d8fce7b2ce0..ca754e5c8f29d 100644 --- a/tests/ui/readonly_write_lock.stderr +++ b/tests/ui/readonly_write_lock.stderr @@ -7,7 +7,7 @@ LL | let writer = lock.write().unwrap(); = note: `-D clippy::readonly-write-lock` implied by `-D warnings` error: this write lock is used only for reading - --> $DIR/readonly_write_lock.rs:21:22 + --> $DIR/readonly_write_lock.rs:23:22 | LL | let writer = lock.write().unwrap(); | ^^^^^^^^^^^^ help: consider using a read lock instead: `lock.read()` diff --git a/tests/ui/recursive_format_impl.rs b/tests/ui/recursive_format_impl.rs index b92490b4c5234..b3eafc6dad7a9 100644 --- a/tests/ui/recursive_format_impl.rs +++ b/tests/ui/recursive_format_impl.rs @@ -29,6 +29,8 @@ impl B for A { impl fmt::Display for A { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.to_string()) + //~^ ERROR: using `self.to_string` in `fmt::Display` implementation will cause inf + //~| NOTE: `-D clippy::recursive-format-impl` implied by `-D warnings` } } @@ -73,6 +75,7 @@ struct G; impl std::fmt::Display for G { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -82,12 +85,14 @@ struct H; impl std::fmt::Display for H { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } impl std::fmt::Debug for H { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", &self) + //~^ ERROR: using `self` as `Debug` in `impl Debug` will cause infinite recursion } } @@ -97,6 +102,7 @@ struct H2; impl std::fmt::Display for H2 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &&&self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -171,12 +177,14 @@ impl std::ops::Deref for J { impl std::fmt::Display for J { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", &*self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } impl std::fmt::Debug for J { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", &*self) + //~^ ERROR: using `self` as `Debug` in `impl Debug` will cause infinite recursion } } @@ -193,6 +201,7 @@ impl std::ops::Deref for J2 { impl std::fmt::Display for J2 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", *self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -209,6 +218,7 @@ impl std::ops::Deref for J3 { impl std::fmt::Display for J3 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", **&&*self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -225,6 +235,7 @@ impl std::ops::Deref for J4 { impl std::fmt::Display for J4 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", &&**&&*self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } diff --git a/tests/ui/recursive_format_impl.stderr b/tests/ui/recursive_format_impl.stderr index 8a58b9a3b178b..c80e90ba61bc2 100644 --- a/tests/ui/recursive_format_impl.stderr +++ b/tests/ui/recursive_format_impl.stderr @@ -7,7 +7,7 @@ LL | write!(f, "{}", self.to_string()) = note: `-D clippy::recursive-format-impl` implied by `-D warnings` error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:75:9 + --> $DIR/recursive_format_impl.rs:77:9 | LL | write!(f, "{}", self) | ^^^^^^^^^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | write!(f, "{}", self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:84:9 + --> $DIR/recursive_format_impl.rs:87:9 | LL | write!(f, "{}", &self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | write!(f, "{}", &self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Debug` in `impl Debug` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:90:9 + --> $DIR/recursive_format_impl.rs:94:9 | LL | write!(f, "{:?}", &self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | write!(f, "{:?}", &self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:99:9 + --> $DIR/recursive_format_impl.rs:104:9 | LL | write!(f, "{}", &&&self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | write!(f, "{}", &&&self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:173:9 + --> $DIR/recursive_format_impl.rs:179:9 | LL | write!(f, "{}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL | write!(f, "{}", &*self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Debug` in `impl Debug` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:179:9 + --> $DIR/recursive_format_impl.rs:186:9 | LL | write!(f, "{:?}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | write!(f, "{:?}", &*self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:195:9 + --> $DIR/recursive_format_impl.rs:203:9 | LL | write!(f, "{}", *self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | write!(f, "{}", *self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:211:9 + --> $DIR/recursive_format_impl.rs:220:9 | LL | write!(f, "{}", **&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +71,7 @@ LL | write!(f, "{}", **&&*self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:227:9 + --> $DIR/recursive_format_impl.rs:237:9 | LL | write!(f, "{}", &&**&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_allocation.rs b/tests/ui/redundant_allocation.rs index 9eb58a3e53f6a..b3257c04f8296 100644 --- a/tests/ui/redundant_allocation.rs +++ b/tests/ui/redundant_allocation.rs @@ -14,14 +14,24 @@ mod outer_box { use std::sync::Arc; pub fn box_test6(foo: Box>) {} + //~^ ERROR: usage of `Box>` + //~| NOTE: `Rc` is already on the heap, `Box>` makes an extra allocation pub fn box_test7(foo: Box>) {} + //~^ ERROR: usage of `Box>` + //~| NOTE: `Arc` is already on the heap, `Box>` makes an extra allocation pub fn box_test8() -> Box>> { + //~^ ERROR: usage of `Box>>` + //~| NOTE: `Rc>` is already on the heap, `Box>>` makes an e unimplemented!(); } pub fn box_test9(foo: Box>) -> Box>> { + //~^ ERROR: usage of `Box>` + //~| NOTE: `Arc` is already on the heap, `Box>` makes an extra allocation + //~| ERROR: usage of `Box>>` + //~| NOTE: `Arc>` is already on the heap, `Box>>` makes an extra a unimplemented!(); } } @@ -33,14 +43,24 @@ mod outer_rc { use std::sync::Arc; pub fn rc_test5(a: Rc>) {} + //~^ ERROR: usage of `Rc>` + //~| NOTE: `Box` is already on the heap, `Rc>` makes an extra allocati pub fn rc_test7(a: Rc>) {} + //~^ ERROR: usage of `Rc>` + //~| NOTE: `Arc` is already on the heap, `Rc>` makes an extra allocati pub fn rc_test8() -> Rc>> { + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an unimplemented!(); } pub fn rc_test9(foo: Rc>) -> Rc>> { + //~^ ERROR: usage of `Rc>` + //~| NOTE: `Arc` is already on the heap, `Rc>` makes an extra allocation + //~| ERROR: usage of `Rc>>` + //~| NOTE: `Arc>` is already on the heap, `Rc>>` makes an extra al unimplemented!(); } } @@ -52,14 +72,24 @@ mod outer_arc { use std::sync::Arc; pub fn arc_test5(a: Arc>) {} + //~^ ERROR: usage of `Arc>` + //~| NOTE: `Box` is already on the heap, `Arc>` makes an extra allocat pub fn arc_test6(a: Arc>) {} + //~^ ERROR: usage of `Arc>` + //~| NOTE: `Rc` is already on the heap, `Arc>` makes an extra allocatio pub fn arc_test8() -> Arc>> { + //~^ ERROR: usage of `Arc>>` + //~| NOTE: `Box>` is already on the heap, `Arc>>` makes an unimplemented!(); } pub fn arc_test9(foo: Arc>) -> Arc>> { + //~^ ERROR: usage of `Arc>` + //~| NOTE: `Rc` is already on the heap, `Arc>` makes an extra allocation + //~| ERROR: usage of `Arc>>` + //~| NOTE: `Rc>` is already on the heap, `Arc>>` makes an extra all unimplemented!(); } } @@ -82,6 +112,8 @@ mod box_dyn { pub fn test_rc(_: Rc>) {} pub fn test_arc(_: Arc>) {} pub fn test_rc_box(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an ex } // https://github.com/rust-lang/rust-clippy/issues/8604 @@ -114,9 +146,17 @@ mod box_fat_ptr { pub fn test_box_custom(_: Box>) {} pub fn test_rc_box_str(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an extra pub fn test_rc_box_slice(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes a pub fn test_rc_box_path(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an extr pub fn test_rc_box_custom(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes } fn main() {} diff --git a/tests/ui/redundant_allocation.stderr b/tests/ui/redundant_allocation.stderr index a9a1eed702b43..233e3eb42896e 100644 --- a/tests/ui/redundant_allocation.stderr +++ b/tests/ui/redundant_allocation.stderr @@ -9,7 +9,7 @@ LL | pub fn box_test6(foo: Box>) {} = note: `-D clippy::redundant-allocation` implied by `-D warnings` error: usage of `Box>` - --> $DIR/redundant_allocation.rs:18:30 + --> $DIR/redundant_allocation.rs:20:30 | LL | pub fn box_test7(foo: Box>) {} | ^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | pub fn box_test7(foo: Box>) {} = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> $DIR/redundant_allocation.rs:20:27 + --> $DIR/redundant_allocation.rs:24:27 | LL | pub fn box_test8() -> Box>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | pub fn box_test8() -> Box>> { = help: consider using just `Box>` or `Rc>` error: usage of `Box>` - --> $DIR/redundant_allocation.rs:24:30 + --> $DIR/redundant_allocation.rs:30:30 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> $DIR/redundant_allocation.rs:24:46 + --> $DIR/redundant_allocation.rs:30:46 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box>` or `Arc>` error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:35:24 + --> $DIR/redundant_allocation.rs:45:24 | LL | pub fn rc_test5(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | pub fn rc_test5(a: Rc>) {} = help: consider using just `Rc` or `Box` error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:37:24 + --> $DIR/redundant_allocation.rs:49:24 | LL | pub fn rc_test7(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -63,7 +63,7 @@ LL | pub fn rc_test7(a: Rc>) {} = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:39:26 + --> $DIR/redundant_allocation.rs:53:26 | LL | pub fn rc_test8() -> Rc>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | pub fn rc_test8() -> Rc>> { = help: consider using just `Rc>` or `Box>` error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:43:29 + --> $DIR/redundant_allocation.rs:59:29 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^ @@ -81,7 +81,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:43:44 + --> $DIR/redundant_allocation.rs:59:44 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc>` or `Arc>` error: usage of `Arc>` - --> $DIR/redundant_allocation.rs:54:25 + --> $DIR/redundant_allocation.rs:74:25 | LL | pub fn arc_test5(a: Arc>) {} | ^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | pub fn arc_test5(a: Arc>) {} = help: consider using just `Arc` or `Box` error: usage of `Arc>` - --> $DIR/redundant_allocation.rs:56:25 + --> $DIR/redundant_allocation.rs:78:25 | LL | pub fn arc_test6(a: Arc>) {} | ^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL | pub fn arc_test6(a: Arc>) {} = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> $DIR/redundant_allocation.rs:58:27 + --> $DIR/redundant_allocation.rs:82:27 | LL | pub fn arc_test8() -> Arc>> { | ^^^^^^^^^^^^^^^^^^^^^ @@ -117,7 +117,7 @@ LL | pub fn arc_test8() -> Arc>> { = help: consider using just `Arc>` or `Box>` error: usage of `Arc>` - --> $DIR/redundant_allocation.rs:62:30 + --> $DIR/redundant_allocation.rs:88:30 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^ @@ -126,7 +126,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> $DIR/redundant_allocation.rs:62:45 + --> $DIR/redundant_allocation.rs:88:45 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^^^^^^^ @@ -135,7 +135,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc>` or `Rc>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:84:27 + --> $DIR/redundant_allocation.rs:114:27 | LL | pub fn test_rc_box(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | pub fn test_rc_box(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:116:31 + --> $DIR/redundant_allocation.rs:148:31 | LL | pub fn test_rc_box_str(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^ @@ -153,7 +153,7 @@ LL | pub fn test_rc_box_str(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:117:33 + --> $DIR/redundant_allocation.rs:151:33 | LL | pub fn test_rc_box_slice(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -162,7 +162,7 @@ LL | pub fn test_rc_box_slice(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:118:32 + --> $DIR/redundant_allocation.rs:154:32 | LL | pub fn test_rc_box_path(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^ @@ -171,7 +171,7 @@ LL | pub fn test_rc_box_path(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:119:34 + --> $DIR/redundant_allocation.rs:157:34 | LL | pub fn test_rc_box_custom(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_closure_call_early.rs b/tests/ui/redundant_closure_call_early.rs index 5649d8dd14c48..6f9c9fd522241 100644 --- a/tests/ui/redundant_closure_call_early.rs +++ b/tests/ui/redundant_closure_call_early.rs @@ -7,9 +7,12 @@ fn main() { // lint here let mut k = (|m| m + 1)(i); + //~^ ERROR: try not to call a closure in the expression where it is declared + //~| NOTE: `-D clippy::redundant-closure-call` implied by `-D warnings` // lint here k = (|a, b| a * b)(1, 5); + //~^ ERROR: try not to call a closure in the expression where it is declared // don't lint these #[allow(clippy::needless_return)] diff --git a/tests/ui/redundant_closure_call_early.stderr b/tests/ui/redundant_closure_call_early.stderr index 2735e41738f0d..4a2ce175b5ce1 100644 --- a/tests/ui/redundant_closure_call_early.stderr +++ b/tests/ui/redundant_closure_call_early.stderr @@ -7,7 +7,7 @@ LL | let mut k = (|m| m + 1)(i); = note: `-D clippy::redundant-closure-call` implied by `-D warnings` error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_early.rs:12:9 + --> $DIR/redundant_closure_call_early.rs:14:9 | LL | k = (|a, b| a * b)(1, 5); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_closure_call_late.rs b/tests/ui/redundant_closure_call_late.rs index 5612827bd3933..dc369c3bc092f 100644 --- a/tests/ui/redundant_closure_call_late.rs +++ b/tests/ui/redundant_closure_call_late.rs @@ -14,12 +14,16 @@ fn main() { // lint here let redun_closure = || 1; i = redun_closure(); + //~^ ERROR: closure called just once immediately after it was declared + //~| NOTE: `-D clippy::redundant-closure-call` implied by `-D warnings` // shadowed closures are supported, lint here let shadowed_closure = || 1; i = shadowed_closure(); + //~^ ERROR: closure called just once immediately after it was declared let shadowed_closure = || 2; i = shadowed_closure(); + //~^ ERROR: closure called just once immediately after it was declared // don't lint here let shadowed_closure = || 2; diff --git a/tests/ui/redundant_closure_call_late.stderr b/tests/ui/redundant_closure_call_late.stderr index 4eca43a2b599a..4a0fe95d57345 100644 --- a/tests/ui/redundant_closure_call_late.stderr +++ b/tests/ui/redundant_closure_call_late.stderr @@ -7,13 +7,13 @@ LL | i = redun_closure(); = note: `-D clippy::redundant-closure-call` implied by `-D warnings` error: closure called just once immediately after it was declared - --> $DIR/redundant_closure_call_late.rs:20:5 + --> $DIR/redundant_closure_call_late.rs:22:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ error: closure called just once immediately after it was declared - --> $DIR/redundant_closure_call_late.rs:22:5 + --> $DIR/redundant_closure_call_late.rs:25:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/redundant_else.rs b/tests/ui/redundant_else.rs index 64f566735cd95..8bcf2ce5233da 100644 --- a/tests/ui/redundant_else.rs +++ b/tests/ui/redundant_else.rs @@ -8,6 +8,7 @@ fn main() { println!("Love your neighbor;"); break; } else { + //~^ ERROR: redundant else block println!("yet don't pull down your hedge."); } // continue @@ -15,6 +16,7 @@ fn main() { println!("He that lies down with Dogs,"); continue; } else { + //~^ ERROR: redundant else block println!("shall rise up with fleas."); } // match block @@ -24,6 +26,7 @@ fn main() { _ => return, } } else { + //~^ ERROR: redundant else block println!("You may delay, but time will not."); } } @@ -33,6 +36,7 @@ fn main() { } else if foo() { return; } else { + //~^ ERROR: redundant else block println!("A fat kitchen makes a lean will."); } // let binding outside of block @@ -40,6 +44,7 @@ fn main() { if foo() { return; } else { + //~^ ERROR: redundant else block 1 } }; @@ -50,6 +55,7 @@ fn main() { } else if foo() { return; } else { + //~^ ERROR: redundant else block 2 } }; @@ -59,6 +65,7 @@ fn main() { if foo() { return; } else { + //~^ ERROR: redundant else block 1 } } else { diff --git a/tests/ui/redundant_else.stderr b/tests/ui/redundant_else.stderr index de9d00a60246c..d6759422e953b 100644 --- a/tests/ui/redundant_else.stderr +++ b/tests/ui/redundant_else.stderr @@ -3,6 +3,7 @@ error: redundant else block | LL | } else { | ________________^ +LL | | LL | | println!("yet don't pull down your hedge."); LL | | } | |_________^ @@ -11,10 +12,11 @@ LL | | } = note: `-D clippy::redundant-else` implied by `-D warnings` error: redundant else block - --> $DIR/redundant_else.rs:17:16 + --> $DIR/redundant_else.rs:18:16 | LL | } else { | ________________^ +LL | | LL | | println!("shall rise up with fleas."); LL | | } | |_________^ @@ -22,10 +24,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:26:16 + --> $DIR/redundant_else.rs:28:16 | LL | } else { | ________________^ +LL | | LL | | println!("You may delay, but time will not."); LL | | } | |_________^ @@ -33,10 +36,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:35:12 + --> $DIR/redundant_else.rs:38:12 | LL | } else { | ____________^ +LL | | LL | | println!("A fat kitchen makes a lean will."); LL | | } | |_____^ @@ -44,10 +48,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:42:16 + --> $DIR/redundant_else.rs:46:16 | LL | } else { | ________________^ +LL | | LL | | 1 LL | | } | |_________^ @@ -55,10 +60,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:52:16 + --> $DIR/redundant_else.rs:57:16 | LL | } else { | ________________^ +LL | | LL | | 2 LL | | } | |_________^ @@ -66,10 +72,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:61:16 + --> $DIR/redundant_else.rs:67:16 | LL | } else { | ________________^ +LL | | LL | | 1 LL | | } | |_________^ diff --git a/tests/ui/redundant_static_lifetimes_multiple.rs b/tests/ui/redundant_static_lifetimes_multiple.rs index abaa146010c90..bfcab420b1f40 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.rs +++ b/tests/ui/redundant_static_lifetimes_multiple.rs @@ -2,13 +2,24 @@ // these are rustfixable, but run-rustfix tests cannot handle them const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static +//~^ ERROR: constants have by default a `'static` lifetime +//~| NOTE: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` +//~| ERROR: constants have by default a `'static` lifetime const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; +//~^ ERROR: constants have by default a `'static` lifetime +//~| ERROR: constants have by default a `'static` lifetime static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static +//~^ ERROR: statics have by default a `'static` lifetime +//~| ERROR: statics have by default a `'static` lifetime static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static +//~^ ERROR: statics have by default a `'static` lifetime +//~| ERROR: statics have by default a `'static` lifetime static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; +//~^ ERROR: statics have by default a `'static` lifetime +//~| ERROR: statics have by default a `'static` lifetime fn main() {} diff --git a/tests/ui/redundant_static_lifetimes_multiple.stderr b/tests/ui/redundant_static_lifetimes_multiple.stderr index 0ef9841e90620..297f505d96841 100644 --- a/tests/ui/redundant_static_lifetimes_multiple.stderr +++ b/tests/ui/redundant_static_lifetimes_multiple.stderr @@ -13,49 +13,49 @@ LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:6:29 + --> $DIR/redundant_static_lifetimes_multiple.rs:9:29 | LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:6:39 + --> $DIR/redundant_static_lifetimes_multiple.rs:9:39 | LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:8:40 + --> $DIR/redundant_static_lifetimes_multiple.rs:13:40 | LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:8:55 + --> $DIR/redundant_static_lifetimes_multiple.rs:13:55 | LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:10:26 + --> $DIR/redundant_static_lifetimes_multiple.rs:17:26 | LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:10:38 + --> $DIR/redundant_static_lifetimes_multiple.rs:17:38 | LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:12:37 + --> $DIR/redundant_static_lifetimes_multiple.rs:21:37 | LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:12:47 + --> $DIR/redundant_static_lifetimes_multiple.rs:21:47 | LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^---- help: consider removing `'static`: `&str` diff --git a/tests/ui/redundant_type_annotations.rs b/tests/ui/redundant_type_annotations.rs index 09dbd3c9b39e1..acf53fea2bb2c 100644 --- a/tests/ui/redundant_type_annotations.rs +++ b/tests/ui/redundant_type_annotations.rs @@ -79,8 +79,12 @@ impl Pie { // Everything here should be lint let v: u32 = self.return_an_int(); + //~^ ERROR: redundant type annotation + //~| NOTE: `-D clippy::redundant-type-annotations` implied by `-D warnings` let v: &u32 = self.return_a_ref(); + //~^ ERROR: redundant type annotation let v: &Slice = self.return_a_ref_to_struct(); + //~^ ERROR: redundant type annotation } } @@ -153,36 +157,50 @@ fn test_functions() { // Everything here should be lint let _return: String = return_a_string(); + //~^ ERROR: redundant type annotation let _return: Pie = return_a_struct(); + //~^ ERROR: redundant type annotation let _return: Pizza = return_an_enum(); + //~^ ERROR: redundant type annotation let _return: u32 = return_an_int(); + //~^ ERROR: redundant type annotation let _return: String = String::new(); + //~^ ERROR: redundant type annotation let new_pie: Pie = Pie::new(); + //~^ ERROR: redundant type annotation let _return: u32 = new_pie.return_an_int(); + //~^ ERROR: redundant type annotation let _return: u32 = Pie::associated_return_an_int(); + //~^ ERROR: redundant type annotation let _return: String = Pie::associated_return_a_string(); + //~^ ERROR: redundant type annotation } fn test_simple_types() { // Everything here should be lint let _var: u32 = u32::MAX; + //~^ ERROR: redundant type annotation let _var: u32 = 5_u32; + //~^ ERROR: redundant type annotation let _var: &str = "test"; + //~^ ERROR: redundant type annotation let _var: &[u8] = b"test"; + //~^ ERROR: redundant type annotation let _var: bool = false; + //~^ ERROR: redundant type annotation } fn issue11190() {} diff --git a/tests/ui/redundant_type_annotations.stderr b/tests/ui/redundant_type_annotations.stderr index 988ebe6372268..927761c74372c 100644 --- a/tests/ui/redundant_type_annotations.stderr +++ b/tests/ui/redundant_type_annotations.stderr @@ -7,97 +7,97 @@ LL | let v: u32 = self.return_an_int(); = note: `-D clippy::redundant-type-annotations` implied by `-D warnings` error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:82:9 + --> $DIR/redundant_type_annotations.rs:84:9 | LL | let v: &u32 = self.return_a_ref(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:83:9 + --> $DIR/redundant_type_annotations.rs:86:9 | LL | let v: &Slice = self.return_a_ref_to_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:155:5 + --> $DIR/redundant_type_annotations.rs:159:5 | LL | let _return: String = return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:157:5 + --> $DIR/redundant_type_annotations.rs:162:5 | LL | let _return: Pie = return_a_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:159:5 + --> $DIR/redundant_type_annotations.rs:165:5 | LL | let _return: Pizza = return_an_enum(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:161:5 + --> $DIR/redundant_type_annotations.rs:168:5 | LL | let _return: u32 = return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:163:5 + --> $DIR/redundant_type_annotations.rs:171:5 | LL | let _return: String = String::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:165:5 + --> $DIR/redundant_type_annotations.rs:174:5 | LL | let new_pie: Pie = Pie::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:167:5 + --> $DIR/redundant_type_annotations.rs:177:5 | LL | let _return: u32 = new_pie.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:169:5 + --> $DIR/redundant_type_annotations.rs:180:5 | LL | let _return: u32 = Pie::associated_return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:171:5 + --> $DIR/redundant_type_annotations.rs:183:5 | LL | let _return: String = Pie::associated_return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:177:5 + --> $DIR/redundant_type_annotations.rs:190:5 | LL | let _var: u32 = u32::MAX; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:179:5 + --> $DIR/redundant_type_annotations.rs:193:5 | LL | let _var: u32 = 5_u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:181:5 + --> $DIR/redundant_type_annotations.rs:196:5 | LL | let _var: &str = "test"; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:183:5 + --> $DIR/redundant_type_annotations.rs:199:5 | LL | let _var: &[u8] = b"test"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:185:5 + --> $DIR/redundant_type_annotations.rs:202:5 | LL | let _var: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/ref_binding_to_reference.rs b/tests/ui/ref_binding_to_reference.rs index b14ae6841e908..a4444c95e33c7 100644 --- a/tests/ui/ref_binding_to_reference.rs +++ b/tests/ui/ref_binding_to_reference.rs @@ -29,12 +29,15 @@ fn main() { // Err, reference to a &String let _: &&String = match Some(&x) { Some(ref x) => x, + //~^ ERROR: this pattern creates a reference to a reference + //~| NOTE: `-D clippy::ref-binding-to-reference` implied by `-D warnings` None => return, }; // Err, reference to a &String let _: &&String = match Some(&x) { Some(ref x) => { + //~^ ERROR: this pattern creates a reference to a reference f1(x); f1(*x); x @@ -45,17 +48,20 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(ref x) => m2!(x), + //~^ ERROR: this pattern creates a reference to a reference None => return, } // Err, reference to a &String let _ = |&ref x: &&String| { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; }; } // Err, reference to a &String fn f2<'a>(&ref x: &&'a String) -> &'a String { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; *x } @@ -63,6 +69,7 @@ fn f2<'a>(&ref x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; } } @@ -71,6 +78,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; } } diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr index 016feb103df6e..2505d7d500bf8 100644 --- a/tests/ui/ref_binding_to_reference.stderr +++ b/tests/ui/ref_binding_to_reference.stderr @@ -11,7 +11,7 @@ LL | Some(x) => &x, | ~ ~~ error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:37:14 + --> $DIR/ref_binding_to_reference.rs:39:14 | LL | Some(ref x) => { | ^^^^^ @@ -19,13 +19,14 @@ LL | Some(ref x) => { help: try | LL ~ Some(x) => { +LL | LL | f1(x); LL ~ f1(x); LL ~ &x | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:47:14 + --> $DIR/ref_binding_to_reference.rs:50:14 | LL | Some(ref x) => m2!(x), | ^^^^^ @@ -36,7 +37,7 @@ LL | Some(x) => m2!(&x), | ~ ~~ error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:52:15 + --> $DIR/ref_binding_to_reference.rs:56:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ @@ -44,11 +45,12 @@ LL | let _ = |&ref x: &&String| { help: try | LL ~ let _ = |&x: &&String| { +LL | LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:58:12 + --> $DIR/ref_binding_to_reference.rs:63:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -56,12 +58,13 @@ LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { help: try | LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { +LL | LL ~ let _: &&String = &x; LL ~ x | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:65:11 + --> $DIR/ref_binding_to_reference.rs:71:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -69,11 +72,12 @@ LL | fn f(&ref x: &&String) { help: try | LL ~ fn f(&x: &&String) { +LL | LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:73:11 + --> $DIR/ref_binding_to_reference.rs:80:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -81,6 +85,7 @@ LL | fn f(&ref x: &&String) { help: try | LL ~ fn f(&x: &&String) { +LL | LL ~ let _: &&String = &x; | diff --git a/tests/ui/ref_option_ref.rs b/tests/ui/ref_option_ref.rs index 9c766ca329215..44001c45e99a9 100644 --- a/tests/ui/ref_option_ref.rs +++ b/tests/ui/ref_option_ref.rs @@ -8,27 +8,37 @@ static THRESHOLD: i32 = 10; static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt +//~| NOTE: `-D clippy::ref-option-ref` implied by `-D warnings` const CONST_THRESHOLD: &i32 = &10; const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD); +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt type RefOptRefU32<'a> = &'a Option<&'a u32>; +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt type RefOptRef<'a, T> = &'a Option<&'a T>; +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt fn foo(data: &Option<&u32>) {} +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt fn bar(data: &u32) -> &Option<&u32> { + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt &None } struct StructRef<'a> { data: &'a Option<&'a u32>, + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to } struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt enum EnumRef<'a> { Variant1(u32), Variant2(&'a Option<&'a u32>), + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to } trait RefOptTrait { @@ -38,12 +48,14 @@ trait RefOptTrait { impl RefOptTrait for u32 { type A = &'static Option<&'static Self>; + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to fn foo(&self, _: Self::A) {} } fn main() { let x: &Option<&u32> = &None; + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to } fn issue9682(arg: &Option<&mut String>) { diff --git a/tests/ui/ref_option_ref.stderr b/tests/ui/ref_option_ref.stderr index b61334758e854..430dd9c0e8dc8 100644 --- a/tests/ui/ref_option_ref.stderr +++ b/tests/ui/ref_option_ref.stderr @@ -7,61 +7,61 @@ LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); = note: `-D clippy::ref-option-ref` implied by `-D warnings` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:12:18 + --> $DIR/ref_option_ref.rs:14: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>` - --> $DIR/ref_option_ref.rs:14:25 + --> $DIR/ref_option_ref.rs:17: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>` - --> $DIR/ref_option_ref.rs:15:25 + --> $DIR/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>` - --> $DIR/ref_option_ref.rs:17:14 + --> $DIR/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>` - --> $DIR/ref_option_ref.rs:19:23 + --> $DIR/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>` - --> $DIR/ref_option_ref.rs:24:11 + --> $DIR/ref_option_ref.rs:31: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>` - --> $DIR/ref_option_ref.rs:27:32 + --> $DIR/ref_option_ref.rs:35: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>` - --> $DIR/ref_option_ref.rs:31:14 + --> $DIR/ref_option_ref.rs:40: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>` - --> $DIR/ref_option_ref.rs:40:14 + --> $DIR/ref_option_ref.rs:50: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>` - --> $DIR/ref_option_ref.rs:46:12 + --> $DIR/ref_option_ref.rs:57: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 c51e0bc76efda..acd42ec89b62f 100644 --- a/tests/ui/ref_patterns.rs +++ b/tests/ui/ref_patterns.rs @@ -6,14 +6,17 @@ fn use_in_pattern() { match opt { None => {}, Some(ref opt) => {}, + //~^ ERROR: usage of ref pattern } } fn use_in_binding() { let x = 5; let ref y = x; + //~^ ERROR: usage of ref pattern } fn use_in_parameter(ref x: i32) {} +//~^ ERROR: usage of ref pattern fn main() {} diff --git a/tests/ui/ref_patterns.stderr b/tests/ui/ref_patterns.stderr index aa007782683a6..5883a7883e64d 100644 --- a/tests/ui/ref_patterns.stderr +++ b/tests/ui/ref_patterns.stderr @@ -8,7 +8,7 @@ LL | Some(ref opt) => {}, = note: `-D clippy::ref-patterns` implied by `-D warnings` error: usage of ref pattern - --> $DIR/ref_patterns.rs:14:9 + --> $DIR/ref_patterns.rs:15:9 | LL | let ref y = x; | ^^^^^ @@ -16,7 +16,7 @@ LL | let ref y = x; = help: consider using `&` for clarity instead error: usage of ref pattern - --> $DIR/ref_patterns.rs:17:21 + --> $DIR/ref_patterns.rs:19:21 | LL | fn use_in_parameter(ref x: i32) {} | ^^^^^ diff --git a/tests/ui/regex.rs b/tests/ui/regex.rs index 89d1d94945454..5259d9ce04bbf 100644 --- a/tests/ui/regex.rs +++ b/tests/ui/regex.rs @@ -16,13 +16,19 @@ const NOT_A_REAL_REGEX: &str = "foobar"; fn syntax_error() { let pipe_in_wrong_position = Regex::new("|"); + //~^ ERROR: trivial regex let pipe_in_wrong_position_builder = RegexBuilder::new("|"); + //~^ ERROR: trivial regex let wrong_char_ranice = Regex::new("[z-a]"); + //~^ ERROR: regex syntax error: invalid character class range, the start must be <= th + //~| NOTE: `-D clippy::invalid-regex` implied by `-D warnings` let some_unicode = Regex::new("[é-è]"); + //~^ ERROR: regex syntax error: invalid character class range, the start must be <= th let some_regex = Regex::new(OPENING_PAREN); let binary_pipe_in_wrong_position = BRegex::new("|"); + //~^ ERROR: trivial regex let some_binary_regex = BRegex::new(OPENING_PAREN); let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); @@ -47,36 +53,49 @@ fn syntax_error() { let escaped_string_span = Regex::new("\\b\\c"); let aux_span = Regex::new("(?ixi)"); + //~^ ERROR: regex syntax error: duplicate flag let should_not_lint = Regex::new("(?u)."); let should_not_lint = BRegex::new("(?u)."); let invalid_utf8_should_not_lint = BRegex::new("(?-u)."); let invalid_utf8_should_lint = Regex::new("(?-u)."); + //~^ ERROR: regex syntax error: pattern can match invalid UTF-8 } fn trivial_regex() { let trivial_eq = Regex::new("^foobar$"); + //~^ ERROR: trivial regex let trivial_eq_builder = RegexBuilder::new("^foobar$"); + //~^ ERROR: trivial regex let trivial_starts_with = Regex::new("^foobar"); + //~^ ERROR: trivial regex let trivial_ends_with = Regex::new("foobar$"); + //~^ ERROR: trivial regex let trivial_contains = Regex::new("foobar"); + //~^ ERROR: trivial regex let trivial_contains = Regex::new(NOT_A_REAL_REGEX); + //~^ ERROR: trivial regex let trivial_backslash = Regex::new("a\\.b"); + //~^ ERROR: trivial regex // unlikely corner cases let trivial_empty = Regex::new(""); + //~^ ERROR: trivial regex let trivial_empty = Regex::new("^"); + //~^ ERROR: trivial regex let trivial_empty = Regex::new("^$"); + //~^ ERROR: trivial regex let binary_trivial_empty = BRegex::new("^$"); + //~^ ERROR: trivial regex // non-trivial regexes let non_trivial_dot = Regex::new("a.b"); diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index 4f758799f73c6..ed5aa29e079e1 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -8,7 +8,7 @@ LL | let pipe_in_wrong_position = Regex::new("|"); = note: `-D clippy::trivial-regex` implied by `-D warnings` error: trivial regex - --> $DIR/regex.rs:19:60 + --> $DIR/regex.rs:20:60 | LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); | ^^^ @@ -16,7 +16,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 - --> $DIR/regex.rs:20:42 + --> $DIR/regex.rs:22:42 | LL | let wrong_char_ranice = Regex::new("[z-a]"); | ^^^ @@ -24,7 +24,7 @@ LL | let wrong_char_ranice = Regex::new("[z-a]"); = note: `-D clippy::invalid-regex` implied by `-D warnings` error: regex syntax error: invalid character class range, the start must be <= the end - --> $DIR/regex.rs:21:37 + --> $DIR/regex.rs:25:37 | LL | let some_unicode = Regex::new("[é-è]"); | ^^^ @@ -33,13 +33,13 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:23:33 + --> $DIR/regex.rs:28:33 | LL | let some_regex = Regex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ error: trivial regex - --> $DIR/regex.rs:25:53 + --> $DIR/regex.rs:30:53 | LL | let binary_pipe_in_wrong_position = BRegex::new("|"); | ^^^ @@ -50,7 +50,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:26:41 + --> $DIR/regex.rs:32:41 | LL | let some_binary_regex = BRegex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -59,7 +59,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:27:56 + --> $DIR/regex.rs:33:56 | LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -68,7 +68,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:39:37 + --> $DIR/regex.rs:45:37 | LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -77,7 +77,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:40:39 + --> $DIR/regex.rs:46:39 | LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ @@ -86,7 +86,7 @@ error: regex parse error: \b\c ^^ error: unrecognized escape sequence - --> $DIR/regex.rs:47:42 + --> $DIR/regex.rs:53:42 | LL | let escaped_string_span = Regex::new("\\b\\c"); | ^^^^^^^^ @@ -94,19 +94,19 @@ LL | let escaped_string_span = Regex::new("\\b\\c"); = help: consider using a raw string literal: `r".."` error: regex syntax error: duplicate flag - --> $DIR/regex.rs:49:34 + --> $DIR/regex.rs:55:34 | LL | let aux_span = Regex::new("(?ixi)"); | ^ ^ error: regex syntax error: pattern can match invalid UTF-8 - --> $DIR/regex.rs:54:53 + --> $DIR/regex.rs:61:53 | LL | let invalid_utf8_should_lint = Regex::new("(?-u)."); | ^ error: trivial regex - --> $DIR/regex.rs:58:33 + --> $DIR/regex.rs:66:33 | LL | let trivial_eq = Regex::new("^foobar$"); | ^^^^^^^^^^ @@ -114,7 +114,7 @@ LL | let trivial_eq = Regex::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> $DIR/regex.rs:60:48 + --> $DIR/regex.rs:69:48 | LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); | ^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> $DIR/regex.rs:62:42 + --> $DIR/regex.rs:72:42 | LL | let trivial_starts_with = Regex::new("^foobar"); | ^^^^^^^^^ @@ -130,7 +130,7 @@ LL | let trivial_starts_with = Regex::new("^foobar"); = help: consider using `str::starts_with` error: trivial regex - --> $DIR/regex.rs:64:40 + --> $DIR/regex.rs:75:40 | LL | let trivial_ends_with = Regex::new("foobar$"); | ^^^^^^^^^ @@ -138,7 +138,7 @@ LL | let trivial_ends_with = Regex::new("foobar$"); = help: consider using `str::ends_with` error: trivial regex - --> $DIR/regex.rs:66:39 + --> $DIR/regex.rs:78:39 | LL | let trivial_contains = Regex::new("foobar"); | ^^^^^^^^ @@ -146,7 +146,7 @@ LL | let trivial_contains = Regex::new("foobar"); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:68:39 + --> $DIR/regex.rs:81:39 | LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); | ^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:70:40 + --> $DIR/regex.rs:84:40 | LL | let trivial_backslash = Regex::new("a\\.b"); | ^^^^^^^ @@ -162,7 +162,7 @@ LL | let trivial_backslash = Regex::new("a\\.b"); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:73:36 + --> $DIR/regex.rs:88:36 | LL | let trivial_empty = Regex::new(""); | ^^ @@ -170,7 +170,7 @@ LL | let trivial_empty = Regex::new(""); = help: the regex is unlikely to be useful as it is error: trivial regex - --> $DIR/regex.rs:75:36 + --> $DIR/regex.rs:91:36 | LL | let trivial_empty = Regex::new("^"); | ^^^ @@ -178,7 +178,7 @@ LL | let trivial_empty = Regex::new("^"); = help: the regex is unlikely to be useful as it is error: trivial regex - --> $DIR/regex.rs:77:36 + --> $DIR/regex.rs:94:36 | LL | let trivial_empty = Regex::new("^$"); | ^^^^ @@ -186,7 +186,7 @@ LL | let trivial_empty = Regex::new("^$"); = help: consider using `str::is_empty` error: trivial regex - --> $DIR/regex.rs:79:44 + --> $DIR/regex.rs:97:44 | LL | let binary_trivial_empty = BRegex::new("^$"); | ^^^^ diff --git a/tests/ui/repl_uninit.rs b/tests/ui/repl_uninit.rs index f15b58e28de2e..01bdf79e64225 100644 --- a/tests/ui/repl_uninit.rs +++ b/tests/ui/repl_uninit.rs @@ -13,18 +13,22 @@ fn main() { // the following is UB if `might_panic` panics unsafe { let taken_v = mem::replace(&mut v, mem::uninitialized()); + //~^ ERROR: replacing with `mem::uninitialized()` + //~| NOTE: `-D clippy::mem-replace-with-uninit` implied by `-D warnings` let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } unsafe { let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); + //~^ ERROR: replacing with `mem::MaybeUninit::uninit().assume_init()` let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } unsafe { let taken_v = mem::replace(&mut v, mem::zeroed()); + //~^ ERROR: replacing with `mem::zeroed()` let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } @@ -37,5 +41,6 @@ fn main() { // this is still not OK, because uninit let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; + //~^ ERROR: replacing with `mem::uninitialized()` *uref = taken_u + 1; } diff --git a/tests/ui/repl_uninit.stderr b/tests/ui/repl_uninit.stderr index 09468eeaea4bf..6bbefcadb8639 100644 --- a/tests/ui/repl_uninit.stderr +++ b/tests/ui/repl_uninit.stderr @@ -7,13 +7,13 @@ LL | let taken_v = mem::replace(&mut v, mem::uninitialized()); = note: `-D clippy::mem-replace-with-uninit` implied by `-D warnings` error: replacing with `mem::MaybeUninit::uninit().assume_init()` - --> $DIR/repl_uninit.rs:21:23 + --> $DIR/repl_uninit.rs:23:23 | LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)` error: replacing with `mem::zeroed()` - --> $DIR/repl_uninit.rs:27:23 + --> $DIR/repl_uninit.rs:30:23 | LL | let taken_v = mem::replace(&mut v, mem::zeroed()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | let taken_v = mem::replace(&mut v, mem::zeroed()); = help: consider using a default value or the `take_mut` crate instead error: replacing with `mem::uninitialized()` - --> $DIR/repl_uninit.rs:39:28 + --> $DIR/repl_uninit.rs:43:28 | LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)` diff --git a/tests/ui/rest_pat_in_fully_bound_structs.rs b/tests/ui/rest_pat_in_fully_bound_structs.rs index 086331af6b567..e25609f756017 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.rs +++ b/tests/ui/rest_pat_in_fully_bound_structs.rs @@ -20,13 +20,16 @@ fn main() { match a_struct { A { a: 5, b: 42, c: "", .. } => {}, // Lint - A { a: 0, b: 0, c: "", .. } => {}, // Lint + //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr + A { a: 0, b: 0, c: "", .. } => {}, // Lint + //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr _ => {}, } match a_struct { A { a: 5, b: 42, .. } => {}, A { a: 0, b: 0, c: "", .. } => {}, // Lint + //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr _ => {}, } diff --git a/tests/ui/rest_pat_in_fully_bound_structs.stderr b/tests/ui/rest_pat_in_fully_bound_structs.stderr index e15633fb1a136..f8e4087823d61 100644 --- a/tests/ui/rest_pat_in_fully_bound_structs.stderr +++ b/tests/ui/rest_pat_in_fully_bound_structs.stderr @@ -8,15 +8,15 @@ LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint = note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings` error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> $DIR/rest_pat_in_fully_bound_structs.rs:23:9 + --> $DIR/rest_pat_in_fully_bound_structs.rs:24:9 | -LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint +LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider removing `..` from this binding error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> $DIR/rest_pat_in_fully_bound_structs.rs:29:9 + --> $DIR/rest_pat_in_fully_bound_structs.rs:31:9 | LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/result_large_err.rs b/tests/ui/result_large_err.rs index 1c12cebfd971a..14a1f7e1db57f 100644 --- a/tests/ui/result_large_err.rs +++ b/tests/ui/result_large_err.rs @@ -6,6 +6,7 @@ pub fn small_err() -> Result<(), u128> { } pub fn large_err() -> Result<(), [u8; 512]> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -17,16 +18,19 @@ pub struct FullyDefinedLargeError { impl FullyDefinedLargeError { pub fn ret() -> Result<(), Self> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } pub fn struct_error() -> Result<(), FullyDefinedLargeError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } type Fdlr = std::result::Result; pub fn large_err_via_type_alias(x: T) -> Fdlr { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(x) } @@ -35,6 +39,7 @@ pub fn param_small_error() -> Result<(), (R, u128)> { } pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeError)> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -46,6 +51,7 @@ pub enum LargeErrorVariants { impl LargeErrorVariants<()> { pub fn large_enum_error() -> Result<(), Self> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } @@ -58,12 +64,14 @@ enum MultipleLargeVariants { impl MultipleLargeVariants { fn large_enum_error() -> Result<(), Self> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } trait TraitForcesLargeError { fn large_error() -> Result<(), [u8; 512]> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } @@ -83,6 +91,7 @@ pub union FullyDefinedUnionError { } pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -92,6 +101,7 @@ pub union UnionError { } pub fn param_large_union() -> Result<(), UnionError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -101,10 +111,12 @@ pub struct ArrayError { } pub fn array_error_subst() -> Result<(), ArrayError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } pub fn array_error() -> Result<(), ArrayError<(i32, T), U>> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } diff --git a/tests/ui/result_large_err.stderr b/tests/ui/result_large_err.stderr index c386edfd21571..c51531f55db67 100644 --- a/tests/ui/result_large_err.stderr +++ b/tests/ui/result_large_err.stderr @@ -8,7 +8,7 @@ LL | pub fn large_err() -> Result<(), [u8; 512]> { = note: `-D clippy::result-large-err` implied by `-D warnings` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:19:21 + --> $DIR/result_large_err.rs:20:21 | LL | pub fn ret() -> Result<(), Self> { | ^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes @@ -16,7 +16,7 @@ LL | pub fn ret() -> Result<(), Self> { = help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:24:26 + --> $DIR/result_large_err.rs:26:26 | LL | pub fn struct_error() -> Result<(), FullyDefinedLargeError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes @@ -24,7 +24,7 @@ LL | pub fn struct_error() -> Result<(), FullyDefinedLargeError> { = help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:29:45 + --> $DIR/result_large_err.rs:32:45 | LL | pub fn large_err_via_type_alias(x: T) -> Fdlr { | ^^^^^^^ the `Err`-variant is at least 240 bytes @@ -32,7 +32,7 @@ LL | pub fn large_err_via_type_alias(x: T) -> Fdlr { = help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:37:34 + --> $DIR/result_large_err.rs:41:34 | LL | pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeError)> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 256 bytes @@ -40,7 +40,7 @@ LL | pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeErro = help: try reducing the size of `(u128, R, FullyDefinedLargeError)`, for example by boxing large elements or replacing it with `Box<(u128, R, FullyDefinedLargeError)>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:48:34 + --> $DIR/result_large_err.rs:53:34 | LL | _Omg([u8; 512]), | --------------- the largest variant contains at least 512 bytes @@ -51,7 +51,7 @@ LL | pub fn large_enum_error() -> Result<(), Self> { = help: try reducing the size of `LargeErrorVariants<()>`, for example by boxing large elements or replacing it with `Box>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:60:30 + --> $DIR/result_large_err.rs:66:30 | LL | _Biggest([u8; 1024]), | -------------------- the largest variant contains at least 1024 bytes @@ -64,7 +64,7 @@ LL | fn large_enum_error() -> Result<(), Self> { = help: try reducing the size of `MultipleLargeVariants`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:66:25 + --> $DIR/result_large_err.rs:73:25 | LL | fn large_error() -> Result<(), [u8; 512]> { | ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -72,7 +72,7 @@ LL | fn large_error() -> Result<(), [u8; 512]> { = help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:85:29 + --> $DIR/result_large_err.rs:93:29 | LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -80,7 +80,7 @@ LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { = help: try reducing the size of `FullyDefinedUnionError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:94:40 + --> $DIR/result_large_err.rs:103:40 | LL | pub fn param_large_union() -> Result<(), UnionError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -88,7 +88,7 @@ LL | pub fn param_large_union() -> Result<(), UnionError> { = help: try reducing the size of `UnionError`, for example by boxing large elements or replacing it with `Box>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:103:34 + --> $DIR/result_large_err.rs:113:34 | LL | pub fn array_error_subst() -> Result<(), ArrayError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes @@ -96,7 +96,7 @@ LL | pub fn array_error_subst() -> Result<(), ArrayError> { = help: try reducing the size of `ArrayError`, for example by boxing large elements or replacing it with `Box>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:107:31 + --> $DIR/result_large_err.rs:118:31 | LL | pub fn array_error() -> Result<(), ArrayError<(i32, T), U>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes diff --git a/tests/ui/result_map_unit_fn_unfixable.rs b/tests/ui/result_map_unit_fn_unfixable.rs index ae853554d325e..a4dfc8f293d3f 100644 --- a/tests/ui/result_map_unit_fn_unfixable.rs +++ b/tests/ui/result_map_unit_fn_unfixable.rs @@ -21,26 +21,33 @@ fn result_map_unit_fn() { let x = HasResult { field: Ok(10) }; x.field.map(|value| { do_nothing(value); do_nothing(value) }); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t + //~| NOTE: `-D clippy::result-map-unit-fn` implied by `-D warnings` x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t // Suggestion for the let block should be `{ ... }` as it's too difficult to build a // proper suggestion for these cases x.field.map(|value| { + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t do_nothing(value); do_nothing(value) }); x.field.map(|value| { do_nothing(value); do_nothing(value); }); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t // The following should suggest `if let Ok(_X) ...` as it's difficult to generate a proper let variable name for them let res: Result = Ok(42).map(diverge); "12".parse::().map(diverge); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a function that returns let res: Result<(), usize> = Ok(plus_one(1)).map(do_nothing); // Should suggest `if let Ok(_y) ...` to not override the existing foo variable let y: Result = Ok(42); y.map(do_nothing); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a function that returns } fn main() {} diff --git a/tests/ui/result_map_unit_fn_unfixable.stderr b/tests/ui/result_map_unit_fn_unfixable.stderr index 75ec1ba80245e..ba17e22d0b359 100644 --- a/tests/ui/result_map_unit_fn_unfixable.stderr +++ b/tests/ui/result_map_unit_fn_unfixable.stderr @@ -9,7 +9,7 @@ LL | x.field.map(|value| { do_nothing(value); do_nothing(value) }); = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:25:5 + --> $DIR/result_map_unit_fn_unfixable.rs:27:5 | LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -17,9 +17,10 @@ LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) | help: try: `if let Ok(value) = x.field { ... }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:29:5 + --> $DIR/result_map_unit_fn_unfixable.rs:32:5 | LL | // x.field.map(|value| { +LL | || LL | || do_nothing(value); LL | || do_nothing(value) LL | || }); @@ -28,7 +29,7 @@ LL | || }); | error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:33:5 + --> $DIR/result_map_unit_fn_unfixable.rs:37:5 | LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -36,7 +37,7 @@ LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); | help: try: `if let Ok(value) = x.field { ... }` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:37:5 + --> $DIR/result_map_unit_fn_unfixable.rs:42:5 | LL | "12".parse::().map(diverge); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -44,7 +45,7 @@ LL | "12".parse::().map(diverge); | help: try: `if let Ok(a) = "12".parse::() { diverge(a) }` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:43:5 + --> $DIR/result_map_unit_fn_unfixable.rs:49:5 | LL | y.map(do_nothing); | ^^^^^^^^^^^^^^^^^- diff --git a/tests/ui/result_unit_error.rs b/tests/ui/result_unit_error.rs index a4ec803024edf..f3159f2e95154 100644 --- a/tests/ui/result_unit_error.rs +++ b/tests/ui/result_unit_error.rs @@ -1,6 +1,7 @@ #![warn(clippy::result_unit_err)] pub fn returns_unit_error() -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Err(()) } @@ -10,8 +11,10 @@ fn private_unit_errors() -> Result { pub trait HasUnitError { fn get_that_error(&self) -> Result; + //~^ ERROR: this returns a `Result<_, ()>` fn get_this_one_too(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Err(()) } } @@ -30,6 +33,7 @@ pub struct UnitErrorHolder; impl UnitErrorHolder { pub fn unit_error(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } } @@ -39,6 +43,7 @@ pub mod issue_6546 { type ResInv = Result; pub fn should_lint() -> ResInv<(), usize> { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } diff --git a/tests/ui/result_unit_error.stderr b/tests/ui/result_unit_error.stderr index 8393a4bf03bc0..252c72481f513 100644 --- a/tests/ui/result_unit_error.stderr +++ b/tests/ui/result_unit_error.stderr @@ -8,7 +8,7 @@ LL | pub fn returns_unit_error() -> Result { = note: `-D clippy::result-unit-err` implied by `-D warnings` error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:12:5 + --> $DIR/result_unit_error.rs:13:5 | LL | fn get_that_error(&self) -> Result; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | fn get_that_error(&self) -> Result; = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:14:5 + --> $DIR/result_unit_error.rs:16:5 | LL | fn get_this_one_too(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn get_this_one_too(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:32:5 + --> $DIR/result_unit_error.rs:35:5 | LL | pub fn unit_error(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | pub fn unit_error(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:41:5 + --> $DIR/result_unit_error.rs:45:5 | LL | pub fn should_lint() -> ResInv<(), usize> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/return_self_not_must_use.rs b/tests/ui/return_self_not_must_use.rs index 9b33ad6d3f6b3..ec6f0feb8e656 100644 --- a/tests/ui/return_self_not_must_use.rs +++ b/tests/ui/return_self_not_must_use.rs @@ -6,6 +6,7 @@ pub struct Bar; pub trait Whatever { fn what(&self) -> Self; + //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` // There should be no warning here! (returns a reference) fn what2(&self) -> &Self; } @@ -16,9 +17,11 @@ impl Bar { Self } pub fn foo(&self) -> Self { + //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` Self } pub fn bar(self) -> Self { + //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` self } // There should be no warning here! (private method) diff --git a/tests/ui/return_self_not_must_use.stderr b/tests/ui/return_self_not_must_use.stderr index 34932fe1c2c55..adfd6564d99cb 100644 --- a/tests/ui/return_self_not_must_use.stderr +++ b/tests/ui/return_self_not_must_use.stderr @@ -8,9 +8,10 @@ LL | fn what(&self) -> Self; = note: `-D clippy::return-self-not-must-use` implied by `-D warnings` error: missing `#[must_use]` attribute on a method returning `Self` - --> $DIR/return_self_not_must_use.rs:18:5 + --> $DIR/return_self_not_must_use.rs:19:5 | LL | / pub fn foo(&self) -> Self { +LL | | LL | | Self LL | | } | |_____^ @@ -18,9 +19,10 @@ LL | | } = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type error: missing `#[must_use]` attribute on a method returning `Self` - --> $DIR/return_self_not_must_use.rs:21:5 + --> $DIR/return_self_not_must_use.rs:23:5 | LL | / pub fn bar(self) -> Self { +LL | | LL | | self LL | | } | |_____^ diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.rs b/tests/ui/reversed_empty_ranges_loops_unfixable.rs index 50264ef68cc06..cd1701dd4bf23 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.rs +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.rs @@ -3,10 +3,13 @@ fn main() { for i in 5..5 { + //~^ ERROR: this range is empty so it will yield no values + //~| NOTE: `-D clippy::reversed-empty-ranges` implied by `-D warnings` println!("{}", i); } for i in (5 + 2)..(8 - 1) { + //~^ ERROR: this range is empty so it will yield no values println!("{}", i); } } diff --git a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr index 4490ff35f5a69..f644631749524 100644 --- a/tests/ui/reversed_empty_ranges_loops_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_loops_unfixable.stderr @@ -7,7 +7,7 @@ LL | for i in 5..5 { = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_unfixable.rs:9:14 + --> $DIR/reversed_empty_ranges_loops_unfixable.rs:11:14 | LL | for i in (5 + 2)..(8 - 1) { | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/reversed_empty_ranges_unfixable.rs b/tests/ui/reversed_empty_ranges_unfixable.rs index 264d3d1e95af4..16c1121ae0697 100644 --- a/tests/ui/reversed_empty_ranges_unfixable.rs +++ b/tests/ui/reversed_empty_ranges_unfixable.rs @@ -6,9 +6,13 @@ const SOME_NUM: usize = 3; fn main() { let arr = [1, 2, 3, 4, 5]; let _ = &arr[3usize..=1usize]; + //~^ ERROR: this range is reversed and using it to index a slice will panic at run-tim + //~| NOTE: `-D clippy::reversed-empty-ranges` implied by `-D warnings` let _ = &arr[SOME_NUM..1]; + //~^ ERROR: this range is reversed and using it to index a slice will panic at run-tim for _ in ANSWER..ANSWER {} + //~^ ERROR: this range is empty so it will yield no values // Should not be linted, see issue #5689 let _ = (42 + 10..42 + 10).map(|x| x / 2).find(|&x| x == 21); diff --git a/tests/ui/reversed_empty_ranges_unfixable.stderr b/tests/ui/reversed_empty_ranges_unfixable.stderr index f23d4eb0f9ca4..d32301742d346 100644 --- a/tests/ui/reversed_empty_ranges_unfixable.stderr +++ b/tests/ui/reversed_empty_ranges_unfixable.stderr @@ -7,13 +7,13 @@ LL | let _ = &arr[3usize..=1usize]; = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` error: this range is reversed and using it to index a slice will panic at run-time - --> $DIR/reversed_empty_ranges_unfixable.rs:9:18 + --> $DIR/reversed_empty_ranges_unfixable.rs:11:18 | LL | let _ = &arr[SOME_NUM..1]; | ^^^^^^^^^^^ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_unfixable.rs:11:14 + --> $DIR/reversed_empty_ranges_unfixable.rs:14:14 | LL | for _ in ANSWER..ANSWER {} | ^^^^^^^^^^^^^^ diff --git a/tests/ui/same_item_push.rs b/tests/ui/same_item_push.rs index af01a8df71b01..df9c2817f5083 100644 --- a/tests/ui/same_item_push.rs +++ b/tests/ui/same_item_push.rs @@ -21,28 +21,33 @@ fn main() { let item = 2; for _ in 5..=20 { vec.push(item); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec: Vec = Vec::new(); for _ in 0..15 { let item = 2; vec.push(item); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec: Vec = Vec::new(); for _ in 0..15 { vec.push(13); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec = Vec::new(); for _ in 0..20 { vec.push(VALUE); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec = Vec::new(); let item = VALUE; for _ in 0..20 { vec.push(item); + //~^ ERROR: it looks like the same item is being pushed into this Vec } // ** non-linted cases ** diff --git a/tests/ui/same_item_push.stderr b/tests/ui/same_item_push.stderr index 1d1254d9fcc61..8e876e914cea9 100644 --- a/tests/ui/same_item_push.stderr +++ b/tests/ui/same_item_push.stderr @@ -8,7 +8,7 @@ LL | vec.push(item); = note: `-D clippy::same-item-push` implied by `-D warnings` error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:29:9 + --> $DIR/same_item_push.rs:30:9 | LL | vec.push(item); | ^^^ @@ -16,7 +16,7 @@ LL | vec.push(item); = help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item) error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:34:9 + --> $DIR/same_item_push.rs:36:9 | LL | vec.push(13); | ^^^ @@ -24,7 +24,7 @@ LL | vec.push(13); = help: try using vec![13;SIZE] or vec.resize(NEW_SIZE, 13) error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:39:9 + --> $DIR/same_item_push.rs:42:9 | LL | vec.push(VALUE); | ^^^ @@ -32,7 +32,7 @@ LL | vec.push(VALUE); = help: try using vec![VALUE;SIZE] or vec.resize(NEW_SIZE, VALUE) error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:45:9 + --> $DIR/same_item_push.rs:49:9 | LL | vec.push(item); | ^^^ diff --git a/tests/ui/same_name_method.rs b/tests/ui/same_name_method.rs index f31a7e33c4b9e..1c166a19b0ad7 100644 --- a/tests/ui/same_name_method.rs +++ b/tests/ui/same_name_method.rs @@ -19,6 +19,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S { @@ -33,6 +34,7 @@ mod should_lint { impl S { fn clone() {} + //~^ ERROR: method's name is the same as an existing method in a trait } } @@ -43,6 +45,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S { @@ -57,6 +60,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S {} @@ -69,6 +73,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S {} diff --git a/tests/ui/same_name_method.stderr b/tests/ui/same_name_method.stderr index 0c6908c09593f..b31d2537eadfc 100644 --- a/tests/ui/same_name_method.stderr +++ b/tests/ui/same_name_method.stderr @@ -5,57 +5,57 @@ LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:25:13 + --> $DIR/same_name_method.rs:26:13 | LL | fn foo() {} | ^^^^^^^^^^^ = note: `-D clippy::same-name-method` implied by `-D warnings` error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:35:13 + --> $DIR/same_name_method.rs:36:13 | LL | fn clone() {} | ^^^^^^^^^^^^^ | note: existing `clone` defined here - --> $DIR/same_name_method.rs:31:18 + --> $DIR/same_name_method.rs:32:18 | LL | #[derive(Clone)] | ^^^^^ = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:45:13 + --> $DIR/same_name_method.rs:47:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:49:13 + --> $DIR/same_name_method.rs:52:13 | LL | fn foo() {} | ^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:59:13 + --> $DIR/same_name_method.rs:62:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:62:9 + --> $DIR/same_name_method.rs:66:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:71:13 + --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:74:9 + --> $DIR/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/self_assignment.rs b/tests/ui/self_assignment.rs index a7f9fbaae7cf6..213bca6c45158 100644 --- a/tests/ui/self_assignment.rs +++ b/tests/ui/self_assignment.rs @@ -11,18 +11,30 @@ pub struct S<'a> { pub fn positives(mut a: usize, b: &mut u32, mut s: S) { a = a; + //~^ ERROR: self-assignment of `a` to `a` + //~| NOTE: `-D clippy::self-assignment` implied by `-D warnings` *b = *b; + //~^ ERROR: self-assignment of `*b` to `*b` s = s; + //~^ ERROR: self-assignment of `s` to `s` s.a = s.a; + //~^ ERROR: self-assignment of `s.a` to `s.a` s.b[9] = s.b[5 + 4]; + //~^ ERROR: self-assignment of `s.b[5 + 4]` to `s.b[9]` s.c[0][1] = s.c[0][1]; + //~^ ERROR: self-assignment of `s.c[0][1]` to `s.c[0][1]` s.b[a] = s.b[a]; + //~^ ERROR: self-assignment of `s.b[a]` to `s.b[a]` *s.e = *s.e; + //~^ ERROR: self-assignment of `*s.e` to `*s.e` s.b[a + 10] = s.b[10 + a]; + //~^ ERROR: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` let mut t = (0, 1); t.1 = t.1; + //~^ ERROR: self-assignment of `t.1` to `t.1` t.0 = (t.0); + //~^ ERROR: self-assignment of `(t.0)` to `t.0` } pub fn negatives_not_equal(mut a: usize, b: &mut usize, mut s: S) { diff --git a/tests/ui/self_assignment.stderr b/tests/ui/self_assignment.stderr index 25b8569fa3d0a..ecb62f96a93a6 100644 --- a/tests/ui/self_assignment.stderr +++ b/tests/ui/self_assignment.stderr @@ -7,61 +7,61 @@ LL | a = a; = note: `-D clippy::self-assignment` implied by `-D warnings` error: self-assignment of `*b` to `*b` - --> $DIR/self_assignment.rs:14:5 + --> $DIR/self_assignment.rs:16:5 | LL | *b = *b; | ^^^^^^^ error: self-assignment of `s` to `s` - --> $DIR/self_assignment.rs:15:5 + --> $DIR/self_assignment.rs:18:5 | LL | s = s; | ^^^^^ error: self-assignment of `s.a` to `s.a` - --> $DIR/self_assignment.rs:16:5 + --> $DIR/self_assignment.rs:20:5 | LL | s.a = s.a; | ^^^^^^^^^ error: self-assignment of `s.b[5 + 4]` to `s.b[9]` - --> $DIR/self_assignment.rs:17:5 + --> $DIR/self_assignment.rs:22:5 | LL | s.b[9] = s.b[5 + 4]; | ^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.c[0][1]` to `s.c[0][1]` - --> $DIR/self_assignment.rs:18:5 + --> $DIR/self_assignment.rs:24:5 | LL | s.c[0][1] = s.c[0][1]; | ^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.b[a]` to `s.b[a]` - --> $DIR/self_assignment.rs:19:5 + --> $DIR/self_assignment.rs:26:5 | LL | s.b[a] = s.b[a]; | ^^^^^^^^^^^^^^^ error: self-assignment of `*s.e` to `*s.e` - --> $DIR/self_assignment.rs:20:5 + --> $DIR/self_assignment.rs:28:5 | LL | *s.e = *s.e; | ^^^^^^^^^^^ error: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` - --> $DIR/self_assignment.rs:21:5 + --> $DIR/self_assignment.rs:30:5 | LL | s.b[a + 10] = s.b[10 + a]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `t.1` to `t.1` - --> $DIR/self_assignment.rs:24:5 + --> $DIR/self_assignment.rs:34:5 | LL | t.1 = t.1; | ^^^^^^^^^ error: self-assignment of `(t.0)` to `t.0` - --> $DIR/self_assignment.rs:25:5 + --> $DIR/self_assignment.rs:36:5 | LL | t.0 = (t.0); | ^^^^^^^^^^^ diff --git a/tests/ui/self_named_constructors.rs b/tests/ui/self_named_constructors.rs index 356f701c98544..dc326b399481c 100644 --- a/tests/ui/self_named_constructors.rs +++ b/tests/ui/self_named_constructors.rs @@ -5,6 +5,8 @@ struct ShouldNotSpawn; impl ShouldSpawn { pub fn should_spawn() -> ShouldSpawn { + //~^ ERROR: constructor `should_spawn` has the same name as the type + //~| NOTE: `-D clippy::self-named-constructors` implied by `-D warnings` ShouldSpawn } diff --git a/tests/ui/self_named_constructors.stderr b/tests/ui/self_named_constructors.stderr index ba989f06dc80d..2024d86f91fcc 100644 --- a/tests/ui/self_named_constructors.stderr +++ b/tests/ui/self_named_constructors.stderr @@ -2,6 +2,8 @@ error: constructor `should_spawn` has the same name as the type --> $DIR/self_named_constructors.rs:7:5 | LL | / pub fn should_spawn() -> ShouldSpawn { +LL | | +LL | | LL | | ShouldSpawn LL | | } | |_____^ diff --git a/tests/ui/serde.rs b/tests/ui/serde.rs index 5843344eba89a..610a50020ec56 100644 --- a/tests/ui/serde.rs +++ b/tests/ui/serde.rs @@ -37,6 +37,8 @@ impl<'de> serde::de::Visitor<'de> for B { } fn visit_string(self, _v: String) -> Result + //~^ ERROR: you should not implement `visit_string` without also implementing `visit_s + //~| NOTE: `-D clippy::serde-api-misuse` implied by `-D warnings` where E: serde::de::Error, { diff --git a/tests/ui/serde.stderr b/tests/ui/serde.stderr index 760c9c9908a6f..a0d8217010e93 100644 --- a/tests/ui/serde.stderr +++ b/tests/ui/serde.stderr @@ -2,9 +2,10 @@ error: you should not implement `visit_string` without also implementing `visit_ --> $DIR/serde.rs:39:5 | LL | / fn visit_string(self, _v: String) -> Result +LL | | +LL | | LL | | where -LL | | E: serde::de::Error, -LL | | { +... | LL | | unimplemented!() LL | | } | |_____^ diff --git a/tests/ui/should_impl_trait/method_list_1.rs b/tests/ui/should_impl_trait/method_list_1.rs index 20d49f5a97634..85eed3f06f64a 100644 --- a/tests/ui/should_impl_trait/method_list_1.rs +++ b/tests/ui/should_impl_trait/method_list_1.rs @@ -23,62 +23,77 @@ impl T { // trait method list part 1, should lint all // ***************************************** pub fn add(self, other: T) -> T { + //~^ ERROR: method `add` can be confused for the standard trait method `std::ops::Add: unimplemented!() } pub fn as_mut(&mut self) -> &mut T { + //~^ ERROR: method `as_mut` can be confused for the standard trait method `std::conver unimplemented!() } pub fn as_ref(&self) -> &T { + //~^ ERROR: method `as_ref` can be confused for the standard trait method `std::conver unimplemented!() } pub fn bitand(self, rhs: T) -> T { + //~^ ERROR: method `bitand` can be confused for the standard trait method `std::ops::B unimplemented!() } pub fn bitor(self, rhs: Self) -> Self { + //~^ ERROR: method `bitor` can be confused for the standard trait method `std::ops::Bi unimplemented!() } pub fn bitxor(self, rhs: Self) -> Self { + //~^ ERROR: method `bitxor` can be confused for the standard trait method `std::ops::B unimplemented!() } pub fn borrow(&self) -> &str { + //~^ ERROR: method `borrow` can be confused for the standard trait method `std::borrow unimplemented!() } pub fn borrow_mut(&mut self) -> &mut str { + //~^ ERROR: method `borrow_mut` can be confused for the standard trait method `std::bo unimplemented!() } pub fn clone(&self) -> Self { + //~^ ERROR: method `clone` can be confused for the standard trait method `std::clone:: unimplemented!() } pub fn cmp(&self, other: &Self) -> Self { + //~^ ERROR: method `cmp` can be confused for the standard trait method `std::cmp::Ord: unimplemented!() } pub fn default() -> Self { + //~^ ERROR: method `default` can be confused for the standard trait method `std::defau unimplemented!() } pub fn deref(&self) -> &Self { + //~^ ERROR: method `deref` can be confused for the standard trait method `std::ops::De unimplemented!() } pub fn deref_mut(&mut self) -> &mut Self { + //~^ ERROR: method `deref_mut` can be confused for the standard trait method `std::ops unimplemented!() } pub fn div(self, rhs: Self) -> Self { + //~^ ERROR: method `div` can be confused for the standard trait method `std::ops::Div: unimplemented!() } pub fn drop(&mut self) { + //~^ ERROR: method `drop` can be confused for the standard trait method `std::ops::Dro unimplemented!() } // ********** diff --git a/tests/ui/should_impl_trait/method_list_1.stderr b/tests/ui/should_impl_trait/method_list_1.stderr index 161dd66b086ee..7ad00d14d0cda 100644 --- a/tests/ui/should_impl_trait/method_list_1.stderr +++ b/tests/ui/should_impl_trait/method_list_1.stderr @@ -2,6 +2,7 @@ error: method `add` can be confused for the standard trait method `std::ops::Add --> $DIR/method_list_1.rs:25:5 | LL | / pub fn add(self, other: T) -> T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -10,9 +11,10 @@ LL | | } = note: `-D clippy::should-implement-trait` implied by `-D warnings` error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut` - --> $DIR/method_list_1.rs:29:5 + --> $DIR/method_list_1.rs:30:5 | LL | / pub fn as_mut(&mut self) -> &mut T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -20,9 +22,10 @@ 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` - --> $DIR/method_list_1.rs:33:5 + --> $DIR/method_list_1.rs:35:5 | LL | / pub fn as_ref(&self) -> &T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -30,9 +33,10 @@ 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` - --> $DIR/method_list_1.rs:37:5 + --> $DIR/method_list_1.rs:40:5 | LL | / pub fn bitand(self, rhs: T) -> T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -40,9 +44,10 @@ 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` - --> $DIR/method_list_1.rs:41:5 + --> $DIR/method_list_1.rs:45:5 | LL | / pub fn bitor(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -50,9 +55,10 @@ 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` - --> $DIR/method_list_1.rs:45:5 + --> $DIR/method_list_1.rs:50:5 | LL | / pub fn bitxor(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -60,9 +66,10 @@ 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` - --> $DIR/method_list_1.rs:49:5 + --> $DIR/method_list_1.rs:55:5 | LL | / pub fn borrow(&self) -> &str { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -70,9 +77,10 @@ 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` - --> $DIR/method_list_1.rs:53:5 + --> $DIR/method_list_1.rs:60:5 | LL | / pub fn borrow_mut(&mut self) -> &mut str { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -80,9 +88,10 @@ 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` - --> $DIR/method_list_1.rs:57:5 + --> $DIR/method_list_1.rs:65:5 | LL | / pub fn clone(&self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -90,9 +99,10 @@ 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` - --> $DIR/method_list_1.rs:61:5 + --> $DIR/method_list_1.rs:70:5 | LL | / pub fn cmp(&self, other: &Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -100,9 +110,10 @@ 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` - --> $DIR/method_list_1.rs:65:5 + --> $DIR/method_list_1.rs:75:5 | LL | / pub fn default() -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -110,9 +121,10 @@ 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` - --> $DIR/method_list_1.rs:69:5 + --> $DIR/method_list_1.rs:80:5 | LL | / pub fn deref(&self) -> &Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -120,9 +132,10 @@ 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` - --> $DIR/method_list_1.rs:73:5 + --> $DIR/method_list_1.rs:85:5 | LL | / pub fn deref_mut(&mut self) -> &mut Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -130,9 +143,10 @@ 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` - --> $DIR/method_list_1.rs:77:5 + --> $DIR/method_list_1.rs:90:5 | LL | / pub fn div(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -140,9 +154,10 @@ 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` - --> $DIR/method_list_1.rs:81:5 + --> $DIR/method_list_1.rs:95:5 | LL | / pub fn drop(&mut self) { +LL | | LL | | unimplemented!() LL | | } | |_____^ diff --git a/tests/ui/should_impl_trait/method_list_2.rs b/tests/ui/should_impl_trait/method_list_2.rs index 27a66f2ed188f..550ec00726817 100644 --- a/tests/ui/should_impl_trait/method_list_2.rs +++ b/tests/ui/should_impl_trait/method_list_2.rs @@ -24,62 +24,79 @@ impl T { // ***************************************** pub fn eq(&self, other: &Self) -> bool { + //~^ ERROR: method `eq` can be confused for the standard trait method `std::cmp::Parti unimplemented!() } pub fn from_iter(iter: T) -> Self { + //~^ ERROR: method `from_iter` can be confused for the standard trait method `std::ite unimplemented!() } pub fn from_str(s: &str) -> Result { + //~^ ERROR: method `from_str` can be confused for the standard trait method `std::str: unimplemented!() } pub fn hash(&self, state: &mut T) { + //~^ ERROR: method `hash` can be confused for the standard trait method `std::hash::Ha + //~| ERROR: this argument is a mutable reference, but not used mutably + //~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` unimplemented!() } pub fn index(&self, index: usize) -> &Self { + //~^ ERROR: method `index` can be confused for the standard trait method `std::ops::In unimplemented!() } pub fn index_mut(&mut self, index: usize) -> &mut Self { + //~^ ERROR: method `index_mut` can be confused for the standard trait method `std::ops unimplemented!() } pub fn into_iter(self) -> Self { + //~^ ERROR: method `into_iter` can be confused for the standard trait method `std::ite unimplemented!() } pub fn mul(self, rhs: Self) -> Self { + //~^ ERROR: method `mul` can be confused for the standard trait method `std::ops::Mul: unimplemented!() } pub fn neg(self) -> Self { + //~^ ERROR: method `neg` can be confused for the standard trait method `std::ops::Neg: unimplemented!() } pub fn next(&mut self) -> Option { + //~^ ERROR: method `next` can be confused for the standard trait method `std::iter::It unimplemented!() } pub fn not(self) -> Self { + //~^ ERROR: method `not` can be confused for the standard trait method `std::ops::Not: unimplemented!() } pub fn rem(self, rhs: Self) -> Self { + //~^ ERROR: method `rem` can be confused for the standard trait method `std::ops::Rem: unimplemented!() } pub fn shl(self, rhs: Self) -> Self { + //~^ ERROR: method `shl` can be confused for the standard trait method `std::ops::Shl: unimplemented!() } pub fn shr(self, rhs: Self) -> Self { + //~^ ERROR: method `shr` can be confused for the standard trait method `std::ops::Shr: unimplemented!() } pub fn sub(self, rhs: Self) -> Self { + //~^ ERROR: method `sub` can be confused for the standard trait method `std::ops::Sub: unimplemented!() } // ********** diff --git a/tests/ui/should_impl_trait/method_list_2.stderr b/tests/ui/should_impl_trait/method_list_2.stderr index a3bb05bf176ba..0073c899813f7 100644 --- a/tests/ui/should_impl_trait/method_list_2.stderr +++ b/tests/ui/should_impl_trait/method_list_2.stderr @@ -2,6 +2,7 @@ error: method `eq` can be confused for the standard trait method `std::cmp::Part --> $DIR/method_list_2.rs:26:5 | LL | / pub fn eq(&self, other: &Self) -> bool { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -10,9 +11,10 @@ LL | | } = note: `-D clippy::should-implement-trait` implied by `-D warnings` error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter` - --> $DIR/method_list_2.rs:30:5 + --> $DIR/method_list_2.rs:31:5 | LL | / pub fn from_iter(iter: T) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -20,9 +22,10 @@ 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` - --> $DIR/method_list_2.rs:34:5 + --> $DIR/method_list_2.rs:36:5 | LL | / pub fn from_str(s: &str) -> Result { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -30,9 +33,12 @@ 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` - --> $DIR/method_list_2.rs:38:5 + --> $DIR/method_list_2.rs:41:5 | LL | / pub fn hash(&self, state: &mut T) { +LL | | +LL | | +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -40,9 +46,10 @@ 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` - --> $DIR/method_list_2.rs:42:5 + --> $DIR/method_list_2.rs:48:5 | LL | / pub fn index(&self, index: usize) -> &Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -50,9 +57,10 @@ 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` - --> $DIR/method_list_2.rs:46:5 + --> $DIR/method_list_2.rs:53:5 | LL | / pub fn index_mut(&mut self, index: usize) -> &mut Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -60,9 +68,10 @@ 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` - --> $DIR/method_list_2.rs:50:5 + --> $DIR/method_list_2.rs:58:5 | LL | / pub fn into_iter(self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -70,9 +79,10 @@ 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` - --> $DIR/method_list_2.rs:54:5 + --> $DIR/method_list_2.rs:63:5 | LL | / pub fn mul(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -80,9 +90,10 @@ 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` - --> $DIR/method_list_2.rs:58:5 + --> $DIR/method_list_2.rs:68:5 | LL | / pub fn neg(self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -90,9 +101,10 @@ 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` - --> $DIR/method_list_2.rs:62:5 + --> $DIR/method_list_2.rs:73:5 | LL | / pub fn next(&mut self) -> Option { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -100,9 +112,10 @@ 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` - --> $DIR/method_list_2.rs:66:5 + --> $DIR/method_list_2.rs:78:5 | LL | / pub fn not(self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -110,9 +123,10 @@ 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` - --> $DIR/method_list_2.rs:70:5 + --> $DIR/method_list_2.rs:83:5 | LL | / pub fn rem(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -120,9 +134,10 @@ 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` - --> $DIR/method_list_2.rs:74:5 + --> $DIR/method_list_2.rs:88:5 | LL | / pub fn shl(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -130,9 +145,10 @@ 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` - --> $DIR/method_list_2.rs:78:5 + --> $DIR/method_list_2.rs:93:5 | LL | / pub fn shr(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -140,9 +156,10 @@ 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` - --> $DIR/method_list_2.rs:82:5 + --> $DIR/method_list_2.rs:98:5 | LL | / pub fn sub(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -150,7 +167,7 @@ LL | | } = help: consider implementing the trait `std::ops::Sub` or choosing a less ambiguous method name error: this argument is a mutable reference, but not used mutably - --> $DIR/method_list_2.rs:38:31 + --> $DIR/method_list_2.rs:41:31 | LL | pub fn hash(&self, state: &mut T) { | ^^^^^^ help: consider changing to: `&T` diff --git a/tests/ui/significant_drop_in_scrutinee.rs b/tests/ui/significant_drop_in_scrutinee.rs index 0dcf4b804cf8b..0305d895fc585 100644 --- a/tests/ui/significant_drop_in_scrutinee.rs +++ b/tests/ui/significant_drop_in_scrutinee.rs @@ -53,6 +53,8 @@ fn should_trigger_lint_with_mutex_guard_in_match_scrutinee() { // is preserved until the end of the match, but there is no clear indication that this is the // case. match mutex.lock().unwrap().foo() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex.lock().unwrap().bar(); }, @@ -139,6 +141,8 @@ fn should_trigger_lint_with_wrapped_mutex() { // lifetime is not obvious. Additionally, it is not obvious from looking at the scrutinee that // the temporary contains such a type, making it potentially even more surprising. match s.lock_m().get_the_value() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -160,6 +164,8 @@ fn should_trigger_lint_with_double_wrapped_mutex() { // looking at the scrutinee that the temporary contains such a type, making it potentially even // more surprising. match s.lock_m_m().get_the_value() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -208,6 +214,8 @@ fn should_trigger_lint_for_vec() { // which have significant drops. The types with significant drops are also non-obvious when // reading the expression in the scrutinee. match counter.temp_increment().len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 2 => { let current_count = counter.i.load(Ordering::Relaxed); println!("Current count {}", current_count); @@ -231,6 +239,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { { match (mutex1.lock().unwrap().s.len(), true) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -240,6 +250,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { }; match (true, mutex1.lock().unwrap().s.len(), true) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (_, 3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -250,6 +262,10 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior + //~| ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (3, _, 3) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -261,6 +277,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { let mutex3 = Mutex::new(StateWithField { s: "three".to_owned() }); match mutex3.lock().unwrap().s.as_str() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior "three" => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -271,6 +289,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { }; match (true, mutex3.lock().unwrap().s.as_str()) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (_, "three") => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -290,6 +310,8 @@ fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { let mutex = Mutex::new(StateWithField { s: "state".to_owned() }); match mutex.lock().unwrap().s.len() > 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex.lock().unwrap().s.len(); }, @@ -297,6 +319,8 @@ fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { }; match 1 < mutex.lock().unwrap().s.len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex.lock().unwrap().s.len(); }, @@ -315,6 +339,8 @@ fn should_trigger_lint_for_accessing_fields_in_mutex_in_both_sides_of_binary_op( }); match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { println!( "{} < {}", @@ -326,6 +352,8 @@ fn should_trigger_lint_for_accessing_fields_in_mutex_in_both_sides_of_binary_op( }; match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { println!( "{} >= {}", @@ -361,6 +389,8 @@ fn should_trigger_lint_for_return_from_closure_in_scrutinee() { // Should trigger lint because the temporary with a significant drop is returned from the // closure but not used directly in any match arms, so it has a potentially surprising lifetime. match get_mutex_guard().s.len() > 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex1.lock().unwrap().s.len(); }, @@ -378,6 +408,8 @@ fn should_trigger_lint_for_return_from_match_in_scrutinee() { // significant drop is but not used directly in any match arms, so it has a potentially // surprising lifetime. match match i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 100 => mutex1.lock().unwrap(), _ => mutex2.lock().unwrap(), } @@ -404,6 +436,8 @@ fn should_trigger_lint_for_return_from_if_in_scrutinee() { // with a significant drop is but not used directly in any match arms, so it has a potentially // surprising lifetime. match if i > 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior mutex1.lock().unwrap() } else { mutex2.lock().unwrap() @@ -458,6 +492,8 @@ fn should_trigger_lint_for_boxed_mutex_guard() { // Should trigger lint because a temporary Box holding a type with a significant drop in a match // scrutinee may have a potentially surprising lifetime. match s.lock().deref().deref() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 0 | 1 => println!("Value was less than 2"), _ => println!("Value is {}", s.lock().deref()), }; @@ -486,6 +522,8 @@ fn should_trigger_lint_for_boxed_mutex_guard_holding_string() { // Should trigger lint because a temporary Box holding a type with a significant drop in a match // scrutinee may have a potentially surprising lifetime. match s.lock().deref().deref() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior matcher => println!("Value is {}", s.lock().deref()), _ => println!("Value was not a match"), }; @@ -505,24 +543,32 @@ fn should_trigger_lint_in_assign_expr() { let mut i = 100; match mutex.lock().unwrap().i = i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, }; match i = mutex.lock().unwrap().i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, }; match mutex.lock().unwrap().i += 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, }; match i += mutex.lock().unwrap().i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, @@ -586,6 +632,8 @@ impl ResultReturner { fn should_trigger_lint_for_non_ref_move_and_clone_suggestion() { let rwlock = RwLock::::new(ResultReturner { s: "1".to_string() }); match rwlock.read().unwrap().to_number() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior Ok(n) => println!("Converted to number: {}", n), Err(e) => println!("Could not convert {} to number", e), }; @@ -596,6 +644,8 @@ fn should_trigger_lint_for_read_write_lock_for_loop() { // designed to look for. let rwlock = RwLock::>::new(vec!["1".to_string()]); for s in rwlock.read().unwrap().iter() { + //~^ ERROR: temporary with significant `Drop` in `for` loop condition will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior println!("{}", s); } } @@ -611,6 +661,8 @@ fn should_trigger_lint_without_significant_drop_in_arm() { // is preserved until the end of the match, but there is no clear indication that this is the // case. match mutex.lock().unwrap().foo() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => do_bar(&mutex), false => {}, }; diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr index b56ace200a8ba..6ead59b072580 100644 --- a/tests/ui/significant_drop_in_scrutinee.stderr +++ b/tests/ui/significant_drop_in_scrutinee.stderr @@ -3,7 +3,7 @@ error: temporary with significant `Drop` in `match` scrutinee will live until th | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex.lock().unwrap().bar(); | --------------------- another value with significant `Drop` created here ... @@ -19,7 +19,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:141:11 + --> $DIR/significant_drop_in_scrutinee.rs:143:11 | LL | match s.lock_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:162:11 + --> $DIR/significant_drop_in_scrutinee.rs:166:11 | LL | match s.lock_m_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:210:11 + --> $DIR/significant_drop_in_scrutinee.rs:216:11 | LL | match counter.temp_increment().len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:233:16 + --> $DIR/significant_drop_in_scrutinee.rs:241:16 | LL | match (mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL ~ match (value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:242:22 + --> $DIR/significant_drop_in_scrutinee.rs:252:22 | LL | match (true, mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +111,7 @@ LL ~ match (true, value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:252:16 + --> $DIR/significant_drop_in_scrutinee.rs:264:16 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,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 - --> $DIR/significant_drop_in_scrutinee.rs:252:54 + --> $DIR/significant_drop_in_scrutinee.rs:264:54 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -153,7 +153,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 - --> $DIR/significant_drop_in_scrutinee.rs:263:15 + --> $DIR/significant_drop_in_scrutinee.rs:279:15 | LL | match mutex3.lock().unwrap().s.as_str() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,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 - --> $DIR/significant_drop_in_scrutinee.rs:273:22 + --> $DIR/significant_drop_in_scrutinee.rs:291:22 | LL | match (true, mutex3.lock().unwrap().s.as_str()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -185,11 +185,11 @@ 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 - --> $DIR/significant_drop_in_scrutinee.rs:292:11 + --> $DIR/significant_drop_in_scrutinee.rs:312:11 | LL | match mutex.lock().unwrap().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex.lock().unwrap().s.len(); | --------------------- another value with significant `Drop` created here ... @@ -204,11 +204,11 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:299:11 + --> $DIR/significant_drop_in_scrutinee.rs:321:11 | LL | match 1 < mutex.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex.lock().unwrap().s.len(); | --------------------- another value with significant `Drop` created here ... @@ -223,7 +223,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:317:11 + --> $DIR/significant_drop_in_scrutinee.rs:341:11 | LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -244,7 +244,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:328:11 + --> $DIR/significant_drop_in_scrutinee.rs:354:11 | LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,11 +265,11 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:363:11 + --> $DIR/significant_drop_in_scrutinee.rs:391:11 | LL | match get_mutex_guard().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex1.lock().unwrap().s.len(); | ---------------------- another value with significant `Drop` created here ... @@ -284,14 +284,14 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:380:11 + --> $DIR/significant_drop_in_scrutinee.rs:410:11 | LL | match match i { | ___________^ +LL | | +LL | | LL | | 100 => mutex1.lock().unwrap(), -LL | | _ => mutex2.lock().unwrap(), -LL | | } -LL | | .s +... | LL | | .len() LL | | > 1 | |___________^ @@ -306,6 +306,8 @@ LL | }; help: try moving the temporary above the match | LL ~ let value = match i { +LL + +LL + LL + 100 => mutex1.lock().unwrap(), LL + _ => mutex2.lock().unwrap(), LL + } @@ -316,13 +318,13 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:406:11 + --> $DIR/significant_drop_in_scrutinee.rs:438:11 | LL | match if i > 1 { | ___________^ +LL | | +LL | | LL | | mutex1.lock().unwrap() -LL | | } else { -LL | | mutex2.lock().unwrap() ... | LL | | .len() LL | | > 1 @@ -338,6 +340,8 @@ LL | }; help: try moving the temporary above the match | LL ~ let value = if i > 1 { +LL + +LL + LL + mutex1.lock().unwrap() LL + } else { LL + mutex2.lock().unwrap() @@ -349,11 +353,11 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:460:11 + --> $DIR/significant_drop_in_scrutinee.rs:494:11 | LL | match s.lock().deref().deref() { | ^^^^^^^^^^^^^^^^^^^^^^^^ -LL | 0 | 1 => println!("Value was less than 2"), +... LL | _ => println!("Value is {}", s.lock().deref()), | ---------------- another value with significant `Drop` created here LL | }; @@ -367,10 +371,11 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:488:11 + --> $DIR/significant_drop_in_scrutinee.rs:524:11 | LL | match s.lock().deref().deref() { | ^^^^^^^^^^^^^^^^^^^^^^^^ +... LL | matcher => println!("Value is {}", s.lock().deref()), | ---------------- another value with significant `Drop` created here LL | _ => println!("Value was not a match"), @@ -380,11 +385,11 @@ 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 - --> $DIR/significant_drop_in_scrutinee.rs:507:11 + --> $DIR/significant_drop_in_scrutinee.rs:545:11 | LL | match mutex.lock().unwrap().i = i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -399,11 +404,11 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:513:11 + --> $DIR/significant_drop_in_scrutinee.rs:553:11 | LL | match i = mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -418,11 +423,11 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:519:11 + --> $DIR/significant_drop_in_scrutinee.rs:561:11 | LL | match mutex.lock().unwrap().i += 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -437,11 +442,11 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:525:11 + --> $DIR/significant_drop_in_scrutinee.rs:569:11 | LL | match i += mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -456,7 +461,7 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:588:11 + --> $DIR/significant_drop_in_scrutinee.rs:634:11 | LL | match rwlock.read().unwrap().to_number() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -467,18 +472,18 @@ LL | }; = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression - --> $DIR/significant_drop_in_scrutinee.rs:598:14 + --> $DIR/significant_drop_in_scrutinee.rs:646:14 | LL | for s in rwlock.read().unwrap().iter() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | println!("{}", s); +... LL | } | - temporary lives until here | = 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 - --> $DIR/significant_drop_in_scrutinee.rs:613:11 + --> $DIR/significant_drop_in_scrutinee.rs:663:11 | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/similar_names.rs b/tests/ui/similar_names.rs index c21225d153bd6..c5a941316da30 100644 --- a/tests/ui/similar_names.rs +++ b/tests/ui/similar_names.rs @@ -19,8 +19,10 @@ fn main() { let apple: i32; let bpple: i32; + //~^ ERROR: binding's name is too similar to existing binding let cpple: i32; + //~^ ERROR: binding's name is too similar to existing binding let a_bar: i32; let b_bar: i32; @@ -45,10 +47,12 @@ fn main() { let blubx: i32; let bluby: i32; + //~^ ERROR: binding's name is too similar to existing binding let cake: i32; let cakes: i32; let coke: i32; + //~^ ERROR: binding's name is too similar to existing binding match 5 { cheese @ 1 => {}, @@ -67,10 +71,12 @@ fn main() { let xyz1abc: i32; let xyz2abc: i32; let xyzeabc: i32; + //~^ ERROR: binding's name is too similar to existing binding let parser: i32; let parsed: i32; let parsee: i32; + //~^ ERROR: binding's name is too similar to existing binding let setter: i32; let getter: i32; @@ -92,6 +98,7 @@ fn foo() { let Foo { apple: spring, bpple: sprang, + //~^ ERROR: binding's name is too similar to existing binding } = unimplemented!(); } diff --git a/tests/ui/similar_names.stderr b/tests/ui/similar_names.stderr index 43c5cee4b4577..059e26d589113 100644 --- a/tests/ui/similar_names.stderr +++ b/tests/ui/similar_names.stderr @@ -12,7 +12,7 @@ LL | let apple: i32; = note: `-D clippy::similar-names` implied by `-D warnings` error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:23:9 + --> $DIR/similar_names.rs:24:9 | LL | let cpple: i32; | ^^^^^ @@ -24,61 +24,61 @@ LL | let apple: i32; | ^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:47:9 + --> $DIR/similar_names.rs:49:9 | LL | let bluby: i32; | ^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:46:9 + --> $DIR/similar_names.rs:48:9 | LL | let blubx: i32; | ^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:51:9 + --> $DIR/similar_names.rs:54:9 | LL | let coke: i32; | ^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:49:9 + --> $DIR/similar_names.rs:52:9 | LL | let cake: i32; | ^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:69:9 + --> $DIR/similar_names.rs:73:9 | LL | let xyzeabc: i32; | ^^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:67:9 + --> $DIR/similar_names.rs:71:9 | LL | let xyz1abc: i32; | ^^^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:73:9 + --> $DIR/similar_names.rs:78:9 | LL | let parsee: i32; | ^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:71:9 + --> $DIR/similar_names.rs:76:9 | LL | let parser: i32; | ^^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:94:16 + --> $DIR/similar_names.rs:100:16 | LL | bpple: sprang, | ^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:93:16 + --> $DIR/similar_names.rs:99:16 | LL | apple: spring, | ^^^^^^ diff --git a/tests/ui/single_char_lifetime_names.rs b/tests/ui/single_char_lifetime_names.rs index 69c5b236f7cf8..6731b5b13564d 100644 --- a/tests/ui/single_char_lifetime_names.rs +++ b/tests/ui/single_char_lifetime_names.rs @@ -3,6 +3,8 @@ // Lifetimes should only be linted when they're introduced struct DiagnosticCtx<'a, 'b> +//~^ ERROR: single-character lifetime names are likely uninformative +//~| ERROR: single-character lifetime names are likely uninformative where 'a: 'b, { @@ -12,6 +14,8 @@ where // Only the lifetimes on the `impl`'s generics should be linted impl<'a, 'b> DiagnosticCtx<'a, 'b> { + //~^ ERROR: single-character lifetime names are likely uninformative + //~| ERROR: single-character lifetime names are likely uninformative fn new(source: &'a str, unit: &'b ()) -> DiagnosticCtx<'a, 'b> { Self { _source: source, @@ -32,6 +36,7 @@ impl<'src, 'unit> DiagnosticCtx<'src, 'unit> { // Only 'a should be linted here fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) { + //~^ ERROR: single-character lifetime names are likely uninformative base.split_once(other) .map(|(left, right)| (left, Some(right))) .unwrap_or((base, None)) diff --git a/tests/ui/single_char_lifetime_names.stderr b/tests/ui/single_char_lifetime_names.stderr index bfe6d44b5898d..19bea0ae0c23b 100644 --- a/tests/ui/single_char_lifetime_names.stderr +++ b/tests/ui/single_char_lifetime_names.stderr @@ -16,7 +16,7 @@ LL | struct DiagnosticCtx<'a, 'b> = help: use a more informative name error: single-character lifetime names are likely uninformative - --> $DIR/single_char_lifetime_names.rs:14:6 + --> $DIR/single_char_lifetime_names.rs:16:6 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -24,7 +24,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> $DIR/single_char_lifetime_names.rs:14:10 + --> $DIR/single_char_lifetime_names.rs:16:10 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -32,7 +32,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> $DIR/single_char_lifetime_names.rs:34:15 + --> $DIR/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_component_path_imports_nested_first.rs b/tests/ui/single_component_path_imports_nested_first.rs index f9dec47e64022..b4a1ce1d6aec4 100644 --- a/tests/ui/single_component_path_imports_nested_first.rs +++ b/tests/ui/single_component_path_imports_nested_first.rs @@ -2,6 +2,8 @@ #![allow(unused_imports)] //@no-rustfix use regex; +//~^ ERROR: this import is redundant +//~| NOTE: `-D clippy::single-component-path-imports` implied by `-D warnings` use serde as edres; @@ -13,6 +15,8 @@ fn main() { mod root_nested_use_mod { use {regex, serde}; + //~^ ERROR: this import is redundant + //~| ERROR: this import is redundant #[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 ff148355e1215..b2a0521f7d143 100644 --- a/tests/ui/single_component_path_imports_nested_first.stderr +++ b/tests/ui/single_component_path_imports_nested_first.stderr @@ -7,7 +7,7 @@ LL | use regex; = note: `-D clippy::single-component-path-imports` implied by `-D warnings` error: this import is redundant - --> $DIR/single_component_path_imports_nested_first.rs:15:10 + --> $DIR/single_component_path_imports_nested_first.rs:17:10 | LL | use {regex, serde}; | ^^^^^ @@ -15,7 +15,7 @@ LL | use {regex, serde}; = help: remove this import error: this import is redundant - --> $DIR/single_component_path_imports_nested_first.rs:15:17 + --> $DIR/single_component_path_imports_nested_first.rs:17:17 | LL | use {regex, serde}; | ^^^^^ diff --git a/tests/ui/size_of_in_element_count/expressions.rs b/tests/ui/size_of_in_element_count/expressions.rs index 2594e8fa6ad3e..91b7ea3922c55 100644 --- a/tests/ui/size_of_in_element_count/expressions.rs +++ b/tests/ui/size_of_in_element_count/expressions.rs @@ -13,12 +13,15 @@ fn main() { // Count expression involving multiplication of size_of (Should trigger the lint) unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // Count expression involving nested multiplications of size_of (Should trigger the lint) unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // Count expression involving divisions of size_of (Should trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // Count expression involving divisions by size_of (Should not trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / size_of::()) }; @@ -28,6 +31,7 @@ fn main() { // Count expression involving recursive divisions by size_of (Should trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 / size_of::())) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // No size_of calls (Should not trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), SIZE) }; diff --git a/tests/ui/size_of_in_element_count/expressions.stderr b/tests/ui/size_of_in_element_count/expressions.stderr index 037f695f3ee91..0c31c3a1f4b32 100644 --- a/tests/ui/size_of_in_element_count/expressions.stderr +++ b/tests/ui/size_of_in_element_count/expressions.stderr @@ -8,7 +8,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::( = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` error: found a count of bytes instead of a count of elements of `T` - --> $DIR/expressions.rs:18:62 + --> $DIR/expressions.rs:19:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,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` - --> $DIR/expressions.rs:21:47 + --> $DIR/expressions.rs:23:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,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` - --> $DIR/expressions.rs:30:47 + --> $DIR/expressions.rs:33: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 09d08ac37dce5..3501cbdf81cfb 100644 --- a/tests/ui/size_of_in_element_count/functions.rs +++ b/tests/ui/size_of_in_element_count/functions.rs @@ -16,31 +16,52 @@ fn main() { // Count is size_of (Should trigger the lint) unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().sub(size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` y.as_ptr().wrapping_sub(size_of::()); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_ptr().add(size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` y.as_mut_ptr().wrapping_add(size_of::()); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_ptr().offset(size_of::() as isize) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` y.as_mut_ptr().wrapping_offset(size_of::() as isize); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` } diff --git a/tests/ui/size_of_in_element_count/functions.stderr b/tests/ui/size_of_in_element_count/functions.stderr index 4351e6a14fe58..4901d11736d5e 100644 --- a/tests/ui/size_of_in_element_count/functions.stderr +++ b/tests/ui/size_of_in_element_count/functions.stderr @@ -8,7 +8,7 @@ LL | unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of: = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:19:62 + --> $DIR/functions.rs:20:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; | ^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x = 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` - --> $DIR/functions.rs:21:49 + --> $DIR/functions.rs:23:49 | LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), 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` - --> $DIR/functions.rs:22:64 + --> $DIR/functions.rs:25:64 | LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of:: $DIR/functions.rs:23:51 + --> $DIR/functions.rs:27:51 | LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), 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` - --> $DIR/functions.rs:24:66 + --> $DIR/functions.rs:29:66 | LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), 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` - --> $DIR/functions.rs:26:47 + --> $DIR/functions.rs:32:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), 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` - --> $DIR/functions.rs:27:47 + --> $DIR/functions.rs:34:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; | ^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; = 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` - --> $DIR/functions.rs:29:46 + --> $DIR/functions.rs:37:46 | LL | unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; = 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` - --> $DIR/functions.rs:30:47 + --> $DIR/functions.rs:39:47 | LL | unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; = 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` - --> $DIR/functions.rs:32:66 + --> $DIR/functions.rs:42:66 | LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), 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` - --> $DIR/functions.rs:34:46 + --> $DIR/functions.rs:45:46 | LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); = 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` - --> $DIR/functions.rs:35:38 + --> $DIR/functions.rs:47:38 | LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); = 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` - --> $DIR/functions.rs:37:49 + --> $DIR/functions.rs:50:49 | LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; = 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` - --> $DIR/functions.rs:38:41 + --> $DIR/functions.rs:52:41 | LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; = 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` - --> $DIR/functions.rs:40:33 + --> $DIR/functions.rs:55:33 | LL | unsafe { y.as_mut_ptr().sub(size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -128,7 +128,7 @@ LL | unsafe { y.as_mut_ptr().sub(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` - --> $DIR/functions.rs:41:29 + --> $DIR/functions.rs:57:29 | LL | y.as_ptr().wrapping_sub(size_of::()); | ^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | y.as_ptr().wrapping_sub(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` - --> $DIR/functions.rs:42:29 + --> $DIR/functions.rs:59:29 | LL | unsafe { y.as_ptr().add(size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -144,7 +144,7 @@ LL | unsafe { y.as_ptr().add(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` - --> $DIR/functions.rs:43:33 + --> $DIR/functions.rs:61:33 | LL | y.as_mut_ptr().wrapping_add(size_of::()); | ^^^^^^^^^^^^^^^ @@ -152,7 +152,7 @@ LL | y.as_mut_ptr().wrapping_add(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` - --> $DIR/functions.rs:44:32 + --> $DIR/functions.rs:63:32 | LL | unsafe { y.as_ptr().offset(size_of::() as isize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -160,7 +160,7 @@ LL | unsafe { y.as_ptr().offset(size_of::() as isize) }; = 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` - --> $DIR/functions.rs:45:36 + --> $DIR/functions.rs:65:36 | LL | y.as_mut_ptr().wrapping_offset(size_of::() as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/size_of_ref.rs b/tests/ui/size_of_ref.rs index 1e83ab82907d3..670c6c080eca6 100644 --- a/tests/ui/size_of_ref.rs +++ b/tests/ui/size_of_ref.rs @@ -11,7 +11,9 @@ fn main() { size_of_val(y); // no lint size_of_val(&&x); + //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference size_of_val(&y); + //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference } struct S { @@ -23,5 +25,6 @@ impl S { /// Get size of object including `self`, in bytes. pub fn size(&self) -> usize { std::mem::size_of_val(&self) + (std::mem::size_of::() * self.data.capacity()) + //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference } } diff --git a/tests/ui/size_of_ref.stderr b/tests/ui/size_of_ref.stderr index d4c13ac3290b6..c7a1758825cba 100644 --- a/tests/ui/size_of_ref.stderr +++ b/tests/ui/size_of_ref.stderr @@ -8,7 +8,7 @@ LL | size_of_val(&&x); = note: `-D clippy::size-of-ref` implied by `-D warnings` error: argument to `std::mem::size_of_val()` is a reference to a reference - --> $DIR/size_of_ref.rs:14:5 + --> $DIR/size_of_ref.rs:15:5 | LL | size_of_val(&y); | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | size_of_val(&y); = help: dereference the argument to `std::mem::size_of_val()` to get the size of the value instead of the size of the reference-type error: argument to `std::mem::size_of_val()` is a reference to a reference - --> $DIR/size_of_ref.rs:25:9 + --> $DIR/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/slow_vector_initialization.rs b/tests/ui/slow_vector_initialization.rs index b152a016d9a1f..f8d85ed38cd5a 100644 --- a/tests/ui/slow_vector_initialization.rs +++ b/tests/ui/slow_vector_initialization.rs @@ -12,10 +12,13 @@ fn extend_vector() { let len = 300; let mut vec1 = Vec::with_capacity(len); vec1.extend(repeat(0).take(len)); + //~^ ERROR: slow zero-filling initialization + //~| NOTE: `-D clippy::slow-vector-initialization` implied by `-D warnings` // Extend with len expression let mut vec2 = Vec::with_capacity(len - 10); vec2.extend(repeat(0).take(len - 10)); + //~^ ERROR: slow zero-filling initialization // Extend with mismatching expression should not be warned let mut vec3 = Vec::with_capacity(24322); @@ -23,6 +26,7 @@ fn extend_vector() { let mut vec4 = Vec::with_capacity(len); vec4.extend(repeat(0).take(vec4.capacity())); + //~^ ERROR: slow zero-filling initialization } fn mixed_extend_resize_vector() { @@ -33,9 +37,11 @@ fn mixed_extend_resize_vector() { // Slow initialization let mut resized_vec = Vec::with_capacity(30); resized_vec.resize(30, 0); + //~^ ERROR: slow zero-filling initialization let mut extend_vec = Vec::with_capacity(30); extend_vec.extend(repeat(0).take(30)); + //~^ ERROR: slow zero-filling initialization } fn resize_vector() { @@ -43,6 +49,7 @@ fn resize_vector() { let len = 300; let mut vec1 = Vec::with_capacity(len); vec1.resize(len, 0); + //~^ ERROR: slow zero-filling initialization // Resize mismatch len let mut vec2 = Vec::with_capacity(200); @@ -51,13 +58,16 @@ fn resize_vector() { // Resize with len expression let mut vec3 = Vec::with_capacity(len - 10); vec3.resize(len - 10, 0); + //~^ ERROR: slow zero-filling initialization let mut vec4 = Vec::with_capacity(len); vec4.resize(vec4.capacity(), 0); + //~^ ERROR: slow zero-filling initialization // Reinitialization should be warned vec1 = Vec::with_capacity(10); vec1.resize(10, 0); + //~^ ERROR: slow zero-filling initialization } fn from_empty_vec() { @@ -65,17 +75,22 @@ fn from_empty_vec() { let len = 300; let mut vec1 = Vec::new(); vec1.resize(len, 0); + //~^ ERROR: slow zero-filling initialization // Resize with len expression let mut vec3 = Vec::new(); vec3.resize(len - 10, 0); + //~^ ERROR: slow zero-filling initialization // Reinitialization should be warned vec1 = Vec::new(); vec1.resize(10, 0); + //~^ ERROR: slow zero-filling initialization } fn do_stuff(vec: &mut [u8]) {} +//~^ ERROR: this argument is a mutable reference, but not used mutably +//~| NOTE: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` fn extend_vector_with_manipulations_between() { let len = 300; diff --git a/tests/ui/slow_vector_initialization.stderr b/tests/ui/slow_vector_initialization.stderr index 532ce4ac19113..4800e6e441862 100644 --- a/tests/ui/slow_vector_initialization.stderr +++ b/tests/ui/slow_vector_initialization.stderr @@ -9,7 +9,7 @@ LL | vec1.extend(repeat(0).take(len)); = note: `-D clippy::slow-vector-initialization` implied by `-D warnings` error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:18:5 + --> $DIR/slow_vector_initialization.rs:20:5 | LL | let mut vec2 = Vec::with_capacity(len - 10); | ---------------------------- help: consider replacing this with: `vec![0; len - 10]` @@ -17,7 +17,7 @@ LL | vec2.extend(repeat(0).take(len - 10)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:25:5 + --> $DIR/slow_vector_initialization.rs:28:5 | LL | let mut vec4 = Vec::with_capacity(len); | ----------------------- help: consider replacing this with: `vec![0; len]` @@ -25,7 +25,7 @@ LL | vec4.extend(repeat(0).take(vec4.capacity())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:35:5 + --> $DIR/slow_vector_initialization.rs:39:5 | LL | let mut resized_vec = Vec::with_capacity(30); | ---------------------- help: consider replacing this with: `vec![0; 30]` @@ -33,7 +33,7 @@ LL | resized_vec.resize(30, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:38:5 + --> $DIR/slow_vector_initialization.rs:43:5 | LL | let mut extend_vec = Vec::with_capacity(30); | ---------------------- help: consider replacing this with: `vec![0; 30]` @@ -41,7 +41,7 @@ LL | extend_vec.extend(repeat(0).take(30)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:45:5 + --> $DIR/slow_vector_initialization.rs:51:5 | LL | let mut vec1 = Vec::with_capacity(len); | ----------------------- help: consider replacing this with: `vec![0; len]` @@ -49,7 +49,7 @@ LL | vec1.resize(len, 0); | ^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:53:5 + --> $DIR/slow_vector_initialization.rs:60:5 | LL | let mut vec3 = Vec::with_capacity(len - 10); | ---------------------------- help: consider replacing this with: `vec![0; len - 10]` @@ -57,7 +57,7 @@ LL | vec3.resize(len - 10, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:56:5 + --> $DIR/slow_vector_initialization.rs:64:5 | LL | let mut vec4 = Vec::with_capacity(len); | ----------------------- help: consider replacing this with: `vec![0; len]` @@ -65,7 +65,7 @@ LL | vec4.resize(vec4.capacity(), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:60:5 + --> $DIR/slow_vector_initialization.rs:69:5 | LL | vec1 = Vec::with_capacity(10); | ---------------------- help: consider replacing this with: `vec![0; 10]` @@ -73,7 +73,7 @@ LL | vec1.resize(10, 0); | ^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:67:5 + --> $DIR/slow_vector_initialization.rs:77:5 | LL | let mut vec1 = Vec::new(); | ---------- help: consider replacing this with: `vec![0; len]` @@ -81,7 +81,7 @@ LL | vec1.resize(len, 0); | ^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:71:5 + --> $DIR/slow_vector_initialization.rs:82:5 | LL | let mut vec3 = Vec::new(); | ---------- help: consider replacing this with: `vec![0; len - 10]` @@ -89,7 +89,7 @@ LL | vec3.resize(len - 10, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:75:5 + --> $DIR/slow_vector_initialization.rs:87:5 | LL | vec1 = Vec::new(); | ---------- help: consider replacing this with: `vec![0; 10]` @@ -97,7 +97,7 @@ LL | vec1.resize(10, 0); | ^^^^^^^^^^^^^^^^^^ error: this argument is a mutable reference, but not used mutably - --> $DIR/slow_vector_initialization.rs:78:18 + --> $DIR/slow_vector_initialization.rs:91:18 | LL | fn do_stuff(vec: &mut [u8]) {} | ^^^^^^^^^ help: consider changing to: `&[u8]` diff --git a/tests/ui/std_instead_of_core.rs b/tests/ui/std_instead_of_core.rs index 75b114ba0aed9..2e44487d77e35 100644 --- a/tests/ui/std_instead_of_core.rs +++ b/tests/ui/std_instead_of_core.rs @@ -7,21 +7,29 @@ extern crate alloc; fn std_instead_of_core() { // Regular import use std::hash::Hasher; + //~^ ERROR: used import from `std` instead of `core` // Absolute path use ::std::hash::Hash; + //~^ ERROR: used import from `std` instead of `core` // Don't lint on `env` macro use std::env; // Multiple imports use std::fmt::{Debug, Result}; + //~^ ERROR: used import from `std` instead of `core` + //~| ERROR: used import from `std` instead of `core` // Function calls let ptr = std::ptr::null::(); + //~^ ERROR: used import from `std` instead of `core` let ptr_mut = ::std::ptr::null_mut::(); + //~^ ERROR: used import from `std` instead of `core` // Types let cell = std::cell::Cell::new(8u32); + //~^ ERROR: used import from `std` instead of `core` let cell_absolute = ::std::cell::Cell::new(8u32); + //~^ ERROR: used import from `std` instead of `core` let _ = std::env!("PATH"); @@ -30,18 +38,22 @@ fn std_instead_of_core() { // lint items re-exported from private modules, `core::iter::traits::iterator::Iterator` use std::iter::Iterator; + //~^ ERROR: used import from `std` instead of `core` } #[warn(clippy::std_instead_of_alloc)] fn std_instead_of_alloc() { // Only lint once. use std::vec; + //~^ ERROR: used import from `std` instead of `alloc` use std::vec::Vec; + //~^ ERROR: used import from `std` instead of `alloc` } #[warn(clippy::alloc_instead_of_core)] fn alloc_instead_of_core() { use alloc::slice::from_ref; + //~^ ERROR: used import from `alloc` instead of `core` } fn main() { diff --git a/tests/ui/std_instead_of_core.stderr b/tests/ui/std_instead_of_core.stderr index d2102497350bd..f2db81e51633a 100644 --- a/tests/ui/std_instead_of_core.stderr +++ b/tests/ui/std_instead_of_core.stderr @@ -8,7 +8,7 @@ LL | use std::hash::Hasher; = note: `-D clippy::std-instead-of-core` implied by `-D warnings` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:11:9 + --> $DIR/std_instead_of_core.rs:12:9 | LL | use ::std::hash::Hash; | ^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | use ::std::hash::Hash; = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:16:20 + --> $DIR/std_instead_of_core.rs:18:20 | LL | use std::fmt::{Debug, Result}; | ^^^^^ @@ -24,7 +24,7 @@ LL | use std::fmt::{Debug, Result}; = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:16:27 + --> $DIR/std_instead_of_core.rs:18:27 | LL | use std::fmt::{Debug, Result}; | ^^^^^^ @@ -32,7 +32,7 @@ LL | use std::fmt::{Debug, Result}; = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:19:15 + --> $DIR/std_instead_of_core.rs:23:15 | LL | let ptr = std::ptr::null::(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let ptr = std::ptr::null::(); = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:20:19 + --> $DIR/std_instead_of_core.rs:25:19 | LL | let ptr_mut = ::std::ptr::null_mut::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let ptr_mut = ::std::ptr::null_mut::(); = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:23:16 + --> $DIR/std_instead_of_core.rs:29:16 | LL | let cell = std::cell::Cell::new(8u32); | ^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | let cell = std::cell::Cell::new(8u32); = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:24:25 + --> $DIR/std_instead_of_core.rs:31:25 | LL | let cell_absolute = ::std::cell::Cell::new(8u32); | ^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | let cell_absolute = ::std::cell::Cell::new(8u32); = help: consider importing the item from `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:32:9 + --> $DIR/std_instead_of_core.rs:40:9 | LL | use std::iter::Iterator; | ^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | use std::iter::Iterator; = help: consider importing the item from `core` error: used import from `std` instead of `alloc` - --> $DIR/std_instead_of_core.rs:38:9 + --> $DIR/std_instead_of_core.rs:47:9 | LL | use std::vec; | ^^^^^^^^ @@ -81,7 +81,7 @@ LL | use std::vec; = note: `-D clippy::std-instead-of-alloc` implied by `-D warnings` error: used import from `std` instead of `alloc` - --> $DIR/std_instead_of_core.rs:39:9 + --> $DIR/std_instead_of_core.rs:49:9 | LL | use std::vec::Vec; | ^^^^^^^^^^^^^ @@ -89,7 +89,7 @@ LL | use std::vec::Vec; = help: consider importing the item from `alloc` error: used import from `alloc` instead of `core` - --> $DIR/std_instead_of_core.rs:44:9 + --> $DIR/std_instead_of_core.rs:55:9 | LL | use alloc::slice::from_ref; | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/str_to_string.rs b/tests/ui/str_to_string.rs index 08f734025181c..f93b289c29ab3 100644 --- a/tests/ui/str_to_string.rs +++ b/tests/ui/str_to_string.rs @@ -2,6 +2,8 @@ fn main() { let hello = "hello world".to_string(); + //~^ ERROR: `to_string()` called on a `&str` let msg = &hello[..]; msg.to_string(); + //~^ ERROR: `to_string()` called on a `&str` } diff --git a/tests/ui/str_to_string.stderr b/tests/ui/str_to_string.stderr index 1d47da571fa1f..25af1d376638f 100644 --- a/tests/ui/str_to_string.stderr +++ b/tests/ui/str_to_string.stderr @@ -8,7 +8,7 @@ LL | let hello = "hello world".to_string(); = note: `-D clippy::str-to-string` implied by `-D warnings` error: `to_string()` called on a `&str` - --> $DIR/str_to_string.rs:6:5 + --> $DIR/str_to_string.rs:7:5 | LL | msg.to_string(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/string_slice.rs b/tests/ui/string_slice.rs index be4dfc8816c7f..440a86b104a3d 100644 --- a/tests/ui/string_slice.rs +++ b/tests/ui/string_slice.rs @@ -3,8 +3,12 @@ fn main() { &"Ölkanne"[1..]; + //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character + //~| NOTE: `-D clippy::string-slice` implied by `-D warnings` let m = "Mötörhead"; &m[2..5]; + //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character let s = String::from(m); &s[0..2]; + //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character } diff --git a/tests/ui/string_slice.stderr b/tests/ui/string_slice.stderr index 55040bf5df2de..94dad58cd972e 100644 --- a/tests/ui/string_slice.stderr +++ b/tests/ui/string_slice.stderr @@ -7,13 +7,13 @@ LL | &"Ölkanne"[1..]; = note: `-D clippy::string-slice` implied by `-D warnings` error: indexing into a string may panic if the index is within a UTF-8 character - --> $DIR/string_slice.rs:7:6 + --> $DIR/string_slice.rs:9:6 | LL | &m[2..5]; | ^^^^^^^ error: indexing into a string may panic if the index is within a UTF-8 character - --> $DIR/string_slice.rs:9:6 + --> $DIR/string_slice.rs:12:6 | LL | &s[0..2]; | ^^^^^^^ diff --git a/tests/ui/string_to_string.rs b/tests/ui/string_to_string.rs index 4c66855f70941..007685b601797 100644 --- a/tests/ui/string_to_string.rs +++ b/tests/ui/string_to_string.rs @@ -4,4 +4,5 @@ fn main() { let mut message = String::from("Hello"); let mut v = message.to_string(); + //~^ ERROR: `to_string()` called on a `String` } diff --git a/tests/ui/struct_excessive_bools.rs b/tests/ui/struct_excessive_bools.rs index ce4fe830a0a21..8137ce7a81c51 100644 --- a/tests/ui/struct_excessive_bools.rs +++ b/tests/ui/struct_excessive_bools.rs @@ -20,6 +20,7 @@ struct Foo { } struct BadFoo { + //~^ ERROR: more than 3 bools in a struct a: bool, b: bool, c: bool, @@ -36,6 +37,7 @@ struct Bar { fn main() { struct FooFoo { + //~^ ERROR: more than 3 bools in a struct a: bool, b: bool, c: bool, diff --git a/tests/ui/struct_excessive_bools.stderr b/tests/ui/struct_excessive_bools.stderr index e4d50043acb0b..05b2363eb5680 100644 --- a/tests/ui/struct_excessive_bools.stderr +++ b/tests/ui/struct_excessive_bools.stderr @@ -2,6 +2,7 @@ error: more than 3 bools in a struct --> $DIR/struct_excessive_bools.rs:22:1 | LL | / struct BadFoo { +LL | | LL | | a: bool, LL | | b: bool, LL | | c: bool, @@ -13,9 +14,10 @@ LL | | } = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` error: more than 3 bools in a struct - --> $DIR/struct_excessive_bools.rs:38:5 + --> $DIR/struct_excessive_bools.rs:39:5 | LL | / struct FooFoo { +LL | | LL | | a: bool, LL | | b: bool, LL | | c: bool, diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs index ae253a0487cb4..1bd4cd5fb50de 100644 --- a/tests/ui/suspicious_arithmetic_impl.rs +++ b/tests/ui/suspicious_arithmetic_impl.rs @@ -11,12 +11,16 @@ impl Add for Foo { fn add(self, other: Self) -> Self { Foo(self.0 - other.0) + //~^ ERROR: suspicious use of `-` in `Add` impl + //~| NOTE: `-D clippy::suspicious-arithmetic-impl` implied by `-D warnings` } } impl AddAssign for Foo { fn add_assign(&mut self, other: Foo) { *self = *self - other; + //~^ ERROR: suspicious use of `-` in `AddAssign` impl + //~| NOTE: `-D clippy::suspicious-op-assign-impl` implied by `-D warnings` } } @@ -30,6 +34,7 @@ impl BitOrAssign for Foo { impl MulAssign for Foo { fn mul_assign(&mut self, other: Foo) { self.0 /= other.0; + //~^ ERROR: suspicious use of `/` in `MulAssign` impl } } @@ -68,6 +73,7 @@ impl Rem for Foo { fn rem(self, other: Self) -> Self { Foo(self.0 / other.0) + //~^ ERROR: suspicious use of `/` in `Rem` impl } } @@ -76,6 +82,7 @@ impl BitAnd for Foo { fn bitand(self, other: Self) -> Self { Foo(self.0 | other.0) + //~^ ERROR: suspicious use of `|` in `BitAnd` impl } } @@ -84,6 +91,7 @@ impl BitOr for Foo { fn bitor(self, other: Self) -> Self { Foo(self.0 ^ other.0) + //~^ ERROR: suspicious use of `^` in `BitOr` impl } } @@ -92,6 +100,7 @@ impl BitXor for Foo { fn bitxor(self, other: Self) -> Self { Foo(self.0 & other.0) + //~^ ERROR: suspicious use of `&` in `BitXor` impl } } @@ -100,6 +109,7 @@ impl Shl for Foo { fn shl(self, other: Self) -> Self { Foo(self.0 >> other.0) + //~^ ERROR: suspicious use of `>>` in `Shl` impl } } @@ -108,6 +118,7 @@ impl Shr for Foo { fn shr(self, other: Self) -> Self { Foo(self.0 << other.0) + //~^ ERROR: suspicious use of `<<` in `Shr` impl } } diff --git a/tests/ui/suspicious_arithmetic_impl.stderr b/tests/ui/suspicious_arithmetic_impl.stderr index ced1305874e58..4a4be0712b289 100644 --- a/tests/ui/suspicious_arithmetic_impl.stderr +++ b/tests/ui/suspicious_arithmetic_impl.stderr @@ -7,7 +7,7 @@ LL | Foo(self.0 - other.0) = note: `-D clippy::suspicious-arithmetic-impl` implied by `-D warnings` error: suspicious use of `-` in `AddAssign` impl - --> $DIR/suspicious_arithmetic_impl.rs:19:23 + --> $DIR/suspicious_arithmetic_impl.rs:21:23 | LL | *self = *self - other; | ^ @@ -15,43 +15,43 @@ LL | *self = *self - other; = note: `-D clippy::suspicious-op-assign-impl` implied by `-D warnings` error: suspicious use of `/` in `MulAssign` impl - --> $DIR/suspicious_arithmetic_impl.rs:32:16 + --> $DIR/suspicious_arithmetic_impl.rs:36:16 | LL | self.0 /= other.0; | ^^ error: suspicious use of `/` in `Rem` impl - --> $DIR/suspicious_arithmetic_impl.rs:70:20 + --> $DIR/suspicious_arithmetic_impl.rs:75:20 | LL | Foo(self.0 / other.0) | ^ error: suspicious use of `|` in `BitAnd` impl - --> $DIR/suspicious_arithmetic_impl.rs:78:20 + --> $DIR/suspicious_arithmetic_impl.rs:84:20 | LL | Foo(self.0 | other.0) | ^ error: suspicious use of `^` in `BitOr` impl - --> $DIR/suspicious_arithmetic_impl.rs:86:20 + --> $DIR/suspicious_arithmetic_impl.rs:93:20 | LL | Foo(self.0 ^ other.0) | ^ error: suspicious use of `&` in `BitXor` impl - --> $DIR/suspicious_arithmetic_impl.rs:94:20 + --> $DIR/suspicious_arithmetic_impl.rs:102:20 | LL | Foo(self.0 & other.0) | ^ error: suspicious use of `>>` in `Shl` impl - --> $DIR/suspicious_arithmetic_impl.rs:102:20 + --> $DIR/suspicious_arithmetic_impl.rs:111:20 | LL | Foo(self.0 >> other.0) | ^^ error: suspicious use of `<<` in `Shr` impl - --> $DIR/suspicious_arithmetic_impl.rs:110:20 + --> $DIR/suspicious_arithmetic_impl.rs:120:20 | LL | Foo(self.0 << other.0) | ^^ diff --git a/tests/ui/suspicious_command_arg_space.fixed b/tests/ui/suspicious_command_arg_space.fixed index 65f8c85d8d9ad..5d7b1e0c17f25 100644 --- a/tests/ui/suspicious_command_arg_space.fixed +++ b/tests/ui/suspicious_command_arg_space.fixed @@ -1,7 +1,10 @@ fn main() { // Things it should warn about: std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments + //~| NOTE: `-D clippy::suspicious-command-arg-space` implied by `-D warnings` std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments // Things it should not warn about: std::process::Command::new("echo").arg("hello world").spawn().unwrap(); diff --git a/tests/ui/suspicious_command_arg_space.rs b/tests/ui/suspicious_command_arg_space.rs index bdc6113a25001..8abd9803a0c6f 100644 --- a/tests/ui/suspicious_command_arg_space.rs +++ b/tests/ui/suspicious_command_arg_space.rs @@ -1,7 +1,10 @@ fn main() { // Things it should warn about: std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments + //~| NOTE: `-D clippy::suspicious-command-arg-space` implied by `-D warnings` std::process::Command::new("cat").arg("--number file").spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments // Things it should not warn about: std::process::Command::new("echo").arg("hello world").spawn().unwrap(); diff --git a/tests/ui/suspicious_command_arg_space.stderr b/tests/ui/suspicious_command_arg_space.stderr index 9bc0ca93aec9e..0ed4eb20ecb5b 100644 --- a/tests/ui/suspicious_command_arg_space.stderr +++ b/tests/ui/suspicious_command_arg_space.stderr @@ -11,7 +11,7 @@ LL | std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap | ~~~~ ~~~~~~~~~~~~~~~ error: single argument that looks like it should be multiple arguments - --> $DIR/suspicious_command_arg_space.rs:4:43 + --> $DIR/suspicious_command_arg_space.rs:6:43 | LL | std::process::Command::new("cat").arg("--number file").spawn().unwrap(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_doc_comments_unfixable.rs b/tests/ui/suspicious_doc_comments_unfixable.rs index 5f1980b43c40f..9e9c4775748ca 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.rs +++ b/tests/ui/suspicious_doc_comments_unfixable.rs @@ -2,12 +2,15 @@ #![warn(clippy::suspicious_doc_comments)] //@no-rustfix ///! a +//~^ ERROR: this is an outer doc comment and does not apply to the parent module or crate +//~| NOTE: `-D clippy::suspicious-doc-comments` implied by `-D warnings` ///! b /// c ///! d pub fn foo() {} ///! a +//~^ ERROR: this is an outer doc comment and does not apply to the parent module or crate ///! b /// c ///! d diff --git a/tests/ui/suspicious_doc_comments_unfixable.stderr b/tests/ui/suspicious_doc_comments_unfixable.stderr index f89146dad36e0..3a93c289fc702 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.stderr +++ b/tests/ui/suspicious_doc_comments_unfixable.stderr @@ -2,6 +2,8 @@ error: this is an outer doc comment and does not apply to the parent module or c --> $DIR/suspicious_doc_comments_unfixable.rs:4:1 | LL | / ///! a +LL | | +LL | | LL | | ///! b LL | | /// c LL | | ///! d @@ -11,15 +13,18 @@ LL | | ///! d help: use an inner doc comment to document the parent module or crate | LL + //! a +LL | +LL | LL + //! b LL | /// c LL + //! d | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments_unfixable.rs:10:1 + --> $DIR/suspicious_doc_comments_unfixable.rs:12:1 | LL | / ///! a +LL | | LL | | ///! b LL | | /// c LL | | ///! d @@ -28,6 +33,7 @@ LL | | ///! d help: use an inner doc comment to document the parent module or crate | LL + //! a +LL | LL + //! b LL | /// c LL + //! d diff --git a/tests/ui/suspicious_map.rs b/tests/ui/suspicious_map.rs index 3a2a10cf09ea5..d4247fcd9265e 100644 --- a/tests/ui/suspicious_map.rs +++ b/tests/ui/suspicious_map.rs @@ -2,9 +2,11 @@ fn main() { let _ = (0..3).map(|x| x + 2).count(); + //~^ ERROR: this call to `map()` won't have an effect on the call to `count()` let f = |x| x + 1; let _ = (0..3).map(f).count(); + //~^ ERROR: this call to `map()` won't have an effect on the call to `count()` } fn negative() { diff --git a/tests/ui/suspicious_map.stderr b/tests/ui/suspicious_map.stderr index e251674819e46..154083f99fa29 100644 --- a/tests/ui/suspicious_map.stderr +++ b/tests/ui/suspicious_map.stderr @@ -8,7 +8,7 @@ LL | let _ = (0..3).map(|x| x + 2).count(); = note: `-D clippy::suspicious-map` implied by `-D warnings` error: this call to `map()` won't have an effect on the call to `count()` - --> $DIR/suspicious_map.rs:7:13 + --> $DIR/suspicious_map.rs:8:13 | LL | let _ = (0..3).map(f).count(); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_splitn.rs b/tests/ui/suspicious_splitn.rs index 528f2ddcc8624..7aa6097062201 100644 --- a/tests/ui/suspicious_splitn.rs +++ b/tests/ui/suspicious_splitn.rs @@ -8,14 +8,32 @@ fn main() { let _ = [].splitn(0, |&x: &u32| x == 1); let _ = "a,b".splitn(0, ','); + //~^ ERROR: `splitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = "a,b".rsplitn(0, ','); + //~^ ERROR: `rsplitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = "a,b".splitn(1, ','); + //~^ ERROR: `splitn` called with `1` split + //~| NOTE: the resulting iterator will always return the entire string followed by `No let _ = [0, 1, 2].splitn(0, |&x| x == 1); + //~^ ERROR: `splitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); + //~^ ERROR: `splitn_mut` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = [0, 1, 2].splitn(1, |&x| x == 1); + //~^ ERROR: `splitn` called with `1` split + //~| NOTE: the resulting iterator will always return the entire slice followed by `Non let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); + //~^ ERROR: `rsplitn_mut` called with `1` split + //~| NOTE: the resulting iterator will always return the entire slice followed by `Non const X: usize = 0; let _ = "a,b".splitn(X + 1, ','); + //~^ ERROR: `splitn` called with `1` split + //~| NOTE: the resulting iterator will always return the entire string followed by `No let _ = "a,b".splitn(X, ','); + //~^ ERROR: `splitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` } diff --git a/tests/ui/suspicious_splitn.stderr b/tests/ui/suspicious_splitn.stderr index 55ce63d4faa8c..2bdf1043abb73 100644 --- a/tests/ui/suspicious_splitn.stderr +++ b/tests/ui/suspicious_splitn.stderr @@ -8,7 +8,7 @@ LL | let _ = "a,b".splitn(0, ','); = note: `-D clippy::suspicious-splitn` implied by `-D warnings` error: `rsplitn` called with `0` splits - --> $DIR/suspicious_splitn.rs:11:13 + --> $DIR/suspicious_splitn.rs:13:13 | LL | let _ = "a,b".rsplitn(0, ','); | ^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = "a,b".rsplitn(0, ','); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> $DIR/suspicious_splitn.rs:12:13 + --> $DIR/suspicious_splitn.rs:16:13 | LL | let _ = "a,b".splitn(1, ','); | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,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 - --> $DIR/suspicious_splitn.rs:13:13 + --> $DIR/suspicious_splitn.rs:19:13 | LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,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 - --> $DIR/suspicious_splitn.rs:14:13 + --> $DIR/suspicious_splitn.rs:22:13 | LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,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 - --> $DIR/suspicious_splitn.rs:15:13 + --> $DIR/suspicious_splitn.rs:25:13 | LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,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 - --> $DIR/suspicious_splitn.rs:16:13 + --> $DIR/suspicious_splitn.rs:28:13 | LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,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 - --> $DIR/suspicious_splitn.rs:19:13 + --> $DIR/suspicious_splitn.rs:33:13 | LL | let _ = "a,b".splitn(X + 1, ','); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,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 - --> $DIR/suspicious_splitn.rs:20:13 + --> $DIR/suspicious_splitn.rs:36:13 | LL | let _ = "a,b".splitn(X, ','); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suspicious_to_owned.rs b/tests/ui/suspicious_to_owned.rs index bf228264e23d4..f32b07d45f635 100644 --- a/tests/ui/suspicious_to_owned.rs +++ b/tests/ui/suspicious_to_owned.rs @@ -15,6 +15,8 @@ fn main() { // we expect this to be linted let cow = Cow::Borrowed(moo); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, str> itself and does not cause the + //~| NOTE: `-D clippy::suspicious-to-owned` implied by `-D warnings` // we expect no lints for this let cow = Cow::Borrowed(moo); let _ = cow.into_owned(); @@ -25,6 +27,7 @@ fn main() { // we expect this to be linted let cow = Cow::Borrowed(&moos); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cau // we expect no lints for this let cow = Cow::Borrowed(&moos); let _ = cow.into_owned(); @@ -35,6 +38,7 @@ fn main() { // we expect this to be linted let cow = Cow::Borrowed(&moos_vec); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, Vec> itself and does not cau // we expect no lints for this let cow = Cow::Borrowed(&moos_vec); let _ = cow.into_owned(); @@ -45,6 +49,7 @@ fn main() { // we expect this to be linted let cow = unsafe { CStr::from_ptr(c_moo_ptr) }.to_string_lossy(); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, str> itself and does not cause the // we expect no lints for this let cow = unsafe { CStr::from_ptr(c_moo_ptr) }.to_string_lossy(); let _ = cow.into_owned(); @@ -59,5 +64,8 @@ fn main() { // we expect implicit_clone lints for these let _ = String::from(moo).to_owned(); + //~^ ERROR: implicitly cloning a `String` by calling `to_owned` on its dereferenced ty + //~| NOTE: `-D clippy::implicit-clone` implied by `-D warnings` let _ = moos_vec.to_owned(); + //~^ ERROR: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type } diff --git a/tests/ui/suspicious_to_owned.stderr b/tests/ui/suspicious_to_owned.stderr index 1c2618e513c3d..cbda1649c629f 100644 --- a/tests/ui/suspicious_to_owned.stderr +++ b/tests/ui/suspicious_to_owned.stderr @@ -15,7 +15,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cause the Cow<'_, [char; 3]> contents to become owned - --> $DIR/suspicious_to_owned.rs:27:13 + --> $DIR/suspicious_to_owned.rs:29:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, Vec> itself and does not cause the Cow<'_, Vec> contents to become owned - --> $DIR/suspicious_to_owned.rs:37:13 + --> $DIR/suspicious_to_owned.rs:40:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned - --> $DIR/suspicious_to_owned.rs:47:13 + --> $DIR/suspicious_to_owned.rs:51:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type - --> $DIR/suspicious_to_owned.rs:61:13 + --> $DIR/suspicious_to_owned.rs:66:13 | LL | let _ = String::from(moo).to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::from(moo).clone()` @@ -68,7 +68,7 @@ LL | let _ = String::from(moo).to_owned(); = note: `-D clippy::implicit-clone` implied by `-D warnings` error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> $DIR/suspicious_to_owned.rs:62:13 + --> $DIR/suspicious_to_owned.rs:69: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 3c5ca1762fe49..a7a62154ee0f2 100644 --- a/tests/ui/suspicious_unary_op_formatting.rs +++ b/tests/ui/suspicious_unary_op_formatting.rs @@ -7,14 +7,18 @@ fn main() { let a = 42; if a >- 30 {} + //~^ ERROR: by not having a space between `>` and `-` it looks like `>-` is a single o if a >=- 30 {} + //~^ ERROR: by not having a space between `>=` and `-` it looks like `>=-` is a single let b = true; let c = false; if b &&! c {} + //~^ ERROR: by not having a space between `&&` and `!` it looks like `&&!` is a single if a >- 30 {} + //~^ ERROR: by not having a space between `>` and `-` it looks like `>-` is a single o // those are ok: if a >-30 {} diff --git a/tests/ui/suspicious_unary_op_formatting.stderr b/tests/ui/suspicious_unary_op_formatting.stderr index 52b0e99a1d3e8..c44a43ea1ec28 100644 --- a/tests/ui/suspicious_unary_op_formatting.stderr +++ b/tests/ui/suspicious_unary_op_formatting.stderr @@ -8,7 +8,7 @@ LL | if a >- 30 {} = note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings` error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:10:9 + --> $DIR/suspicious_unary_op_formatting.rs:11:9 | LL | if a >=- 30 {} | ^^^^^ @@ -16,7 +16,7 @@ LL | if a >=- 30 {} = help: put a space between `>=` and `-` and remove the space after `-` error: by not having a space between `&&` and `!` it looks like `&&!` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:15:9 + --> $DIR/suspicious_unary_op_formatting.rs:17:9 | LL | if b &&! c {} | ^^^^^ @@ -24,7 +24,7 @@ LL | if b &&! c {} = help: put a space between `&&` and `!` and remove the space after `!` error: by not having a space between `>` and `-` it looks like `>-` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:17:9 + --> $DIR/suspicious_unary_op_formatting.rs:20:9 | LL | if a >- 30 {} | ^^^^^^ diff --git a/tests/ui/suspicious_xor_used_as_pow.rs b/tests/ui/suspicious_xor_used_as_pow.rs index f7c44c9e6fa1e..a5319e1b2308e 100644 --- a/tests/ui/suspicious_xor_used_as_pow.rs +++ b/tests/ui/suspicious_xor_used_as_pow.rs @@ -17,11 +17,18 @@ macro_rules! macro_test_inside { fn main() { // Should warn: let _ = 2 ^ 5; + //~^ ERROR: `^` is not the exponentiation operator + //~| NOTE: `-D clippy::suspicious-xor-used-as-pow` implied by `-D warnings` let _ = 2i32 ^ 9i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 2i32 ^ 2i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 50i32 ^ 3i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 5i32 ^ 8i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 2i32 ^ 32i32; + //~^ ERROR: `^` is not the exponentiation operator macro_test_inside!(); // Should not warn: diff --git a/tests/ui/suspicious_xor_used_as_pow.stderr b/tests/ui/suspicious_xor_used_as_pow.stderr index d93a55ba9065c..1a260e64e77a3 100644 --- a/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/tests/ui/suspicious_xor_used_as_pow.stderr @@ -7,31 +7,31 @@ LL | let _ = 2 ^ 5; = note: `-D clippy::suspicious-xor-used-as-pow` implied by `-D warnings` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:20:13 + --> $DIR/suspicious_xor_used_as_pow.rs:22:13 | LL | let _ = 2i32 ^ 9i32; | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(9i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:21:13 + --> $DIR/suspicious_xor_used_as_pow.rs:24:13 | LL | let _ = 2i32 ^ 2i32; | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(2i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:22:13 + --> $DIR/suspicious_xor_used_as_pow.rs:26:13 | LL | let _ = 50i32 ^ 3i32; | ^^^^^^^^^^^^ help: did you mean to write: `50i32.pow(3i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:23:13 + --> $DIR/suspicious_xor_used_as_pow.rs:28:13 | LL | let _ = 5i32 ^ 8i32; | ^^^^^^^^^^^ help: did you mean to write: `5i32.pow(8i32)` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:24:13 + --> $DIR/suspicious_xor_used_as_pow.rs:30:13 | LL | let _ = 2i32 ^ 32i32; | ^^^^^^^^^^^^ help: did you mean to write: `2i32.pow(32i32)` diff --git a/tests/ui/swap_ptr_to_ref_unfixable.rs b/tests/ui/swap_ptr_to_ref_unfixable.rs index 66ea7c6529bd2..08e56a5d01b22 100644 --- a/tests/ui/swap_ptr_to_ref_unfixable.rs +++ b/tests/ui/swap_ptr_to_ref_unfixable.rs @@ -12,7 +12,11 @@ fn main() { unsafe { core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); + //~^ ERROR: call to `core::mem::swap` with a parameter derived from a raw pointer + //~| NOTE: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` core::mem::swap(&mut *y, addr_of_mut_to_ref!(x)); + //~^ ERROR: call to `core::mem::swap` with a parameter derived from a raw pointer core::mem::swap(addr_of_mut_to_ref!(x), addr_of_mut_to_ref!(x)); + //~^ ERROR: call to `core::mem::swap` with a parameter derived from a raw pointer } } diff --git a/tests/ui/swap_ptr_to_ref_unfixable.stderr b/tests/ui/swap_ptr_to_ref_unfixable.stderr index c261205d556e4..f0c1e7e7428bf 100644 --- a/tests/ui/swap_ptr_to_ref_unfixable.stderr +++ b/tests/ui/swap_ptr_to_ref_unfixable.stderr @@ -7,13 +7,13 @@ LL | core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); = note: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref_unfixable.rs:15:9 + --> $DIR/swap_ptr_to_ref_unfixable.rs:17:9 | LL | core::mem::swap(&mut *y, addr_of_mut_to_ref!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref_unfixable.rs:16:9 + --> $DIR/swap_ptr_to_ref_unfixable.rs:19:9 | LL | core::mem::swap(addr_of_mut_to_ref!(x), addr_of_mut_to_ref!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/temporary_assignment.rs b/tests/ui/temporary_assignment.rs index ac4c1bc65979f..e2b982aeaf52a 100644 --- a/tests/ui/temporary_assignment.rs +++ b/tests/ui/temporary_assignment.rs @@ -45,13 +45,18 @@ fn main() { let mut t = (0, 0); Struct { field: 0 }.field = 1; + //~^ ERROR: assignment to temporary + //~| NOTE: `-D clippy::temporary-assignment` implied by `-D warnings` MultiStruct { + //~^ ERROR: assignment to temporary structure: Struct { field: 0 }, } .structure .field = 1; ArrayStruct { array: [0] }.array[0] = 1; + //~^ ERROR: assignment to temporary (0, 0).0 = 1; + //~^ ERROR: assignment to temporary // no error s.field = 1; diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr index 7d79901a28d1b..12e2c5a2fc317 100644 --- a/tests/ui/temporary_assignment.stderr +++ b/tests/ui/temporary_assignment.stderr @@ -7,9 +7,10 @@ LL | Struct { field: 0 }.field = 1; = note: `-D clippy::temporary-assignment` implied by `-D warnings` error: assignment to temporary - --> $DIR/temporary_assignment.rs:48:5 + --> $DIR/temporary_assignment.rs:50:5 | LL | / MultiStruct { +LL | | LL | | structure: Struct { field: 0 }, LL | | } LL | | .structure @@ -17,13 +18,13 @@ LL | | .field = 1; | |______________^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:53:5 + --> $DIR/temporary_assignment.rs:56:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:54:5 + --> $DIR/temporary_assignment.rs:58: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 d53c692b78e13..0abde4a57bf77 100644 --- a/tests/ui/tests_outside_test_module.rs +++ b/tests/ui/tests_outside_test_module.rs @@ -8,6 +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)] #[cfg(test)] mod tests { diff --git a/tests/ui/trailing_empty_array.rs b/tests/ui/trailing_empty_array.rs index 928475b5f35ea..3d06c2621681d 100644 --- a/tests/ui/trailing_empty_array.rs +++ b/tests/ui/trailing_empty_array.rs @@ -3,33 +3,39 @@ // Do lint: struct RarelyUseful { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; 0], } struct OnlyField { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib first_and_last: [usize; 0], } struct GenericArrayType { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [T; 0], } #[must_use] struct OnlyAnotherAttribute { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; 0], } #[derive(Debug)] struct OnlyADeriveAttribute { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; 0], } const ZERO: usize = 0; struct ZeroSizedWithConst { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; ZERO], } @@ -39,6 +45,7 @@ const fn compute_zero() -> usize { (4 + 6) - (2 * 5) } struct ZeroSizedWithConstFunction { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; compute_zero()], } @@ -47,15 +54,19 @@ const fn compute_zero_from_arg(x: usize) -> usize { x - 1 } struct ZeroSizedWithConstFunction2 { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; compute_zero_from_arg(1)], } struct ZeroSizedArrayWrapper([usize; 0]); +//~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib struct TupleStruct(i32, [usize; 0]); +//~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib struct LotsOfFields { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib f1: u32, f2: u32, f3: u32, diff --git a/tests/ui/trailing_empty_array.stderr b/tests/ui/trailing_empty_array.stderr index 2e1484400352d..d89e77f61ce4a 100644 --- a/tests/ui/trailing_empty_array.stderr +++ b/tests/ui/trailing_empty_array.stderr @@ -2,6 +2,7 @@ error: trailing zero-sized array in a struct which is not marked with a `repr` a --> $DIR/trailing_empty_array.rs:5:1 | LL | / struct RarelyUseful { +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -11,9 +12,10 @@ LL | | } = note: `-D clippy::trailing-empty-array` implied by `-D warnings` error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:10:1 + --> $DIR/trailing_empty_array.rs:11:1 | LL | / struct OnlyField { +LL | | LL | | first_and_last: [usize; 0], LL | | } | |_^ @@ -21,9 +23,10 @@ LL | | } = help: consider annotating `OnlyField` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:14:1 + --> $DIR/trailing_empty_array.rs:16:1 | LL | / struct GenericArrayType { +LL | | LL | | field: i32, LL | | last: [T; 0], LL | | } @@ -32,9 +35,10 @@ LL | | } = help: consider annotating `GenericArrayType` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:20:1 + --> $DIR/trailing_empty_array.rs:23:1 | LL | / struct OnlyAnotherAttribute { +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -43,9 +47,10 @@ LL | | } = help: consider annotating `OnlyAnotherAttribute` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:26:1 + --> $DIR/trailing_empty_array.rs:30:1 | LL | / struct OnlyADeriveAttribute { +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -54,9 +59,10 @@ LL | | } = help: consider annotating `OnlyADeriveAttribute` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:32:1 + --> $DIR/trailing_empty_array.rs:37:1 | LL | / struct ZeroSizedWithConst { +LL | | LL | | field: i32, LL | | last: [usize; ZERO], LL | | } @@ -65,9 +71,10 @@ LL | | } = help: consider annotating `ZeroSizedWithConst` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:41:1 + --> $DIR/trailing_empty_array.rs:47:1 | LL | / struct ZeroSizedWithConstFunction { +LL | | LL | | field: i32, LL | | last: [usize; compute_zero()], LL | | } @@ -76,9 +83,10 @@ LL | | } = help: consider annotating `ZeroSizedWithConstFunction` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:49:1 + --> $DIR/trailing_empty_array.rs:56:1 | LL | / struct ZeroSizedWithConstFunction2 { +LL | | LL | | field: i32, LL | | last: [usize; compute_zero_from_arg(1)], LL | | } @@ -87,7 +95,7 @@ LL | | } = help: consider annotating `ZeroSizedWithConstFunction2` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:54:1 + --> $DIR/trailing_empty_array.rs:62:1 | LL | struct ZeroSizedArrayWrapper([usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +103,7 @@ LL | struct ZeroSizedArrayWrapper([usize; 0]); = help: consider annotating `ZeroSizedArrayWrapper` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:56:1 + --> $DIR/trailing_empty_array.rs:65:1 | LL | struct TupleStruct(i32, [usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,12 +111,12 @@ LL | struct TupleStruct(i32, [usize; 0]); = help: consider annotating `TupleStruct` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:58:1 + --> $DIR/trailing_empty_array.rs:68:1 | LL | / struct LotsOfFields { +LL | | LL | | f1: u32, LL | | f2: u32, -LL | | f3: u32, ... | LL | | last: [usize; 0], LL | | } diff --git a/tests/ui/trailing_zeros.fixed b/tests/ui/trailing_zeros.fixed index 8aceb76ddd851..f7de976f1e00e 100644 --- a/tests/ui/trailing_zeros.fixed +++ b/tests/ui/trailing_zeros.fixed @@ -4,7 +4,10 @@ fn main() { let x: i32 = 42; let _ = x.trailing_zeros() >= 4; + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` + //~| NOTE: `-D clippy::verbose-bit-mask` implied by `-D warnings` let _ = x.trailing_zeros() >= 5; + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint } diff --git a/tests/ui/trailing_zeros.rs b/tests/ui/trailing_zeros.rs index 888f0587fe348..a05b09233e212 100644 --- a/tests/ui/trailing_zeros.rs +++ b/tests/ui/trailing_zeros.rs @@ -4,7 +4,10 @@ fn main() { let x: i32 = 42; let _ = (x & 0b1111 == 0); + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` + //~| NOTE: `-D clippy::verbose-bit-mask` implied by `-D warnings` let _ = x & 0b1_1111 == 0; + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint } diff --git a/tests/ui/trailing_zeros.stderr b/tests/ui/trailing_zeros.stderr index 7c44f139c0952..fb4025a75481d 100644 --- a/tests/ui/trailing_zeros.stderr +++ b/tests/ui/trailing_zeros.stderr @@ -7,7 +7,7 @@ LL | let _ = (x & 0b1111 == 0); = note: `-D clippy::verbose-bit-mask` implied by `-D warnings` error: bit mask could be simplified with a call to `trailing_zeros` - --> $DIR/trailing_zeros.rs:7:13 + --> $DIR/trailing_zeros.rs:9:13 | LL | let _ = x & 0b1_1111 == 0; | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5` diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.rs b/tests/ui/trait_duplication_in_bounds_unfixable.rs index 5630a0345adb1..effed3a26938b 100644 --- a/tests/ui/trait_duplication_in_bounds_unfixable.rs +++ b/tests/ui/trait_duplication_in_bounds_unfixable.rs @@ -4,6 +4,8 @@ use std::collections::BTreeMap; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; fn bad_foo(arg0: T, arg1: Z) +//~^ ERROR: this trait bound is already specified in the where clause +//~| ERROR: this trait bound is already specified in the where clause where T: Clone, T: Default, @@ -33,6 +35,7 @@ trait T: Default { fn f() where Self: Default; + //~^ ERROR: this trait bound is already specified in trait declaration } trait U: Default { @@ -47,15 +50,19 @@ trait ZZ: Default { fn f() where Self: Default + Clone; + //~^ ERROR: this trait bound is already specified in trait declaration } trait BadTrait: Default + Clone { fn f() where Self: Default + Clone; + //~^ ERROR: this trait bound is already specified in trait declaration + //~| ERROR: this trait bound is already specified in trait declaration fn g() where Self: Default; + //~^ ERROR: this trait bound is already specified in trait declaration fn h() where Self: Copy; @@ -91,6 +98,7 @@ trait FooIter: Iterator { fn bar() where Self: Iterator, + //~^ ERROR: this trait bound is already specified in trait declaration { } } diff --git a/tests/ui/trait_duplication_in_bounds_unfixable.stderr b/tests/ui/trait_duplication_in_bounds_unfixable.stderr index 4d56a94646cb6..80dc7d8b6c32d 100644 --- a/tests/ui/trait_duplication_in_bounds_unfixable.stderr +++ b/tests/ui/trait_duplication_in_bounds_unfixable.stderr @@ -20,7 +20,7 @@ LL | fn bad_foo(arg0: T, arg1: Z) = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:35:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:37:15 | LL | Self: Default; | ^^^^^^^ @@ -28,7 +28,7 @@ LL | Self: Default; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:49:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:52:15 | LL | Self: Default + Clone; | ^^^^^^^ @@ -36,7 +36,7 @@ LL | Self: Default + Clone; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:55:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:59:15 | LL | Self: Default + Clone; | ^^^^^^^ @@ -44,7 +44,7 @@ LL | Self: Default + Clone; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:55:25 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:59:25 | LL | Self: Default + Clone; | ^^^^^ @@ -52,7 +52,7 @@ LL | Self: Default + Clone; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:58:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:64:15 | LL | Self: Default; | ^^^^^^^ @@ -60,7 +60,7 @@ LL | Self: Default; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:93:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:100:15 | LL | Self: Iterator, | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute.rs b/tests/ui/transmute.rs index 9bd83d089af3e..32f6027e99111 100644 --- a/tests/ui/transmute.rs +++ b/tests/ui/transmute.rs @@ -22,30 +22,41 @@ unsafe fn _generic<'a, T, U: 'a>(t: &'a T) { let _: &'a U = core::intrinsics::transmute(t); let _: *const T = core::intrinsics::transmute(t); + //~^ ERROR: transmute from a reference to a pointer + //~| NOTE: `-D clippy::useless-transmute` implied by `-D warnings` let _: *mut T = core::intrinsics::transmute(t); + //~^ ERROR: transmute from a reference to a pointer let _: *const U = core::intrinsics::transmute(t); + //~^ ERROR: transmute from a reference to a pointer } #[warn(clippy::useless_transmute)] fn useless() { unsafe { let _: Vec = core::intrinsics::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = core::mem::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = std::intrinsics::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = std::mem::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = my_transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: *const usize = std::mem::transmute(5_isize); + //~^ ERROR: transmute from an integer to a pointer let _ = 5_isize as *const usize; let _: *const usize = std::mem::transmute(1 + 1usize); + //~^ ERROR: transmute from an integer to a pointer let _ = (1 + 1_usize) as *const usize; } @@ -77,19 +88,27 @@ fn crosspointer() { unsafe { let _: Usize = core::intrinsics::transmute(int_const_ptr); + //~^ ERROR: transmute from a type (`*const Usize`) to the type that it points to ( + //~| NOTE: `-D clippy::crosspointer-transmute` implied by `-D warnings` let _: Usize = core::intrinsics::transmute(int_mut_ptr); + //~^ ERROR: transmute from a type (`*mut Usize`) to the type that it points to (`U let _: *const Usize = core::intrinsics::transmute(my_int()); + //~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*const Usi let _: *mut Usize = core::intrinsics::transmute(my_int()); + //~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize } } #[warn(clippy::transmute_int_to_char)] fn int_to_char() { let _: char = unsafe { std::mem::transmute(0_u32) }; + //~^ ERROR: transmute from a `u32` to a `char` + //~| NOTE: `-D clippy::transmute-int-to-char` implied by `-D warnings` let _: char = unsafe { std::mem::transmute(0_i32) }; + //~^ ERROR: transmute from a `i32` to a `char` // These shouldn't warn const _: char = unsafe { std::mem::transmute(0_u32) }; @@ -99,15 +118,22 @@ fn int_to_char() { #[warn(clippy::transmute_int_to_bool)] fn int_to_bool() { let _: bool = unsafe { std::mem::transmute(0_u8) }; + //~^ ERROR: transmute from a `u8` to a `bool` + //~| NOTE: `-D clippy::transmute-int-to-bool` implied by `-D warnings` } #[warn(clippy::transmute_int_to_float)] mod int_to_float { fn test() { let _: f32 = unsafe { std::mem::transmute(0_u32) }; + //~^ ERROR: transmute from a `u32` to a `f32` + //~| NOTE: `-D clippy::transmute-int-to-float` implied by `-D warnings` let _: f32 = unsafe { std::mem::transmute(0_i32) }; + //~^ ERROR: transmute from a `i32` to a `f32` let _: f64 = unsafe { std::mem::transmute(0_u64) }; + //~^ ERROR: transmute from a `u64` to a `f64` let _: f64 = unsafe { std::mem::transmute(0_i64) }; + //~^ ERROR: transmute from a `i64` to a `f64` } mod issue_5747 { @@ -128,23 +154,38 @@ mod num_to_bytes { fn test() { unsafe { let _: [u8; 1] = std::mem::transmute(0u8); + //~^ ERROR: transmute from a `u8` to a `[u8; 1]` + //~| NOTE: `-D clippy::transmute-num-to-bytes` implied by `-D warnings` let _: [u8; 4] = std::mem::transmute(0u32); + //~^ ERROR: transmute from a `u32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0u128); + //~^ ERROR: transmute from a `u128` to a `[u8; 16]` let _: [u8; 1] = std::mem::transmute(0i8); + //~^ ERROR: transmute from a `i8` to a `[u8; 1]` let _: [u8; 4] = std::mem::transmute(0i32); + //~^ ERROR: transmute from a `i32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0i128); + //~^ ERROR: transmute from a `i128` to a `[u8; 16]` let _: [u8; 4] = std::mem::transmute(0.0f32); + //~^ ERROR: transmute from a `f32` to a `[u8; 4]` let _: [u8; 8] = std::mem::transmute(0.0f64); + //~^ ERROR: transmute from a `f64` to a `[u8; 8]` } } const fn test_const() { unsafe { let _: [u8; 1] = std::mem::transmute(0u8); + //~^ ERROR: transmute from a `u8` to a `[u8; 1]` let _: [u8; 4] = std::mem::transmute(0u32); + //~^ ERROR: transmute from a `u32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0u128); + //~^ ERROR: transmute from a `u128` to a `[u8; 16]` let _: [u8; 1] = std::mem::transmute(0i8); + //~^ ERROR: transmute from a `i8` to a `[u8; 1]` let _: [u8; 4] = std::mem::transmute(0i32); + //~^ ERROR: transmute from a `i32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0i128); + //~^ ERROR: transmute from a `i128` to a `[u8; 16]` let _: [u8; 4] = std::mem::transmute(0.0f32); let _: [u8; 8] = std::mem::transmute(0.0f64); } @@ -155,8 +196,12 @@ fn bytes_to_str(mb: &mut [u8]) { const B: &[u8] = b""; let _: &str = unsafe { std::mem::transmute(B) }; + //~^ ERROR: transmute from a `&[u8]` to a `&str` + //~| NOTE: `-D clippy::transmute-bytes-to-str` implied by `-D warnings` let _: &mut str = unsafe { std::mem::transmute(mb) }; + //~^ ERROR: transmute from a `&mut [u8]` to a `&mut str` const _: &str = unsafe { std::mem::transmute(B) }; + //~^ ERROR: transmute from a `&[u8]` to a `&str` } fn main() {} diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr index 008b4a981d7e6..2765f763d6df7 100644 --- a/tests/ui/transmute.stderr +++ b/tests/ui/transmute.stderr @@ -7,61 +7,61 @@ LL | let _: *const T = core::intrinsics::transmute(t); = note: `-D clippy::useless-transmute` implied by `-D warnings` error: transmute from a reference to a pointer - --> $DIR/transmute.rs:26:21 + --> $DIR/transmute.rs:28:21 | LL | let _: *mut T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` error: transmute from a reference to a pointer - --> $DIR/transmute.rs:28:23 + --> $DIR/transmute.rs:31:23 | LL | let _: *const U = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:34:27 + --> $DIR/transmute.rs:38:27 | LL | let _: Vec = core::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:36:27 + --> $DIR/transmute.rs:41:27 | LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:38:27 + --> $DIR/transmute.rs:44:27 | LL | let _: Vec = std::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:40:27 + --> $DIR/transmute.rs:47:27 | LL | let _: Vec = std::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:42:27 + --> $DIR/transmute.rs:50:27 | LL | let _: Vec = my_transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^ error: transmute from an integer to a pointer - --> $DIR/transmute.rs:44:31 + --> $DIR/transmute.rs:53:31 | LL | let _: *const usize = std::mem::transmute(5_isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `5_isize as *const usize` error: transmute from an integer to a pointer - --> $DIR/transmute.rs:48:31 + --> $DIR/transmute.rs:58:31 | LL | let _: *const usize = std::mem::transmute(1 + 1usize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(1 + 1usize) as *const usize` error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:79:24 + --> $DIR/transmute.rs:90:24 | LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,25 +69,25 @@ LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); = note: `-D clippy::crosspointer-transmute` implied by `-D warnings` error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:81:24 + --> $DIR/transmute.rs:94:24 | LL | let _: Usize = core::intrinsics::transmute(int_mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) - --> $DIR/transmute.rs:83:31 + --> $DIR/transmute.rs:97:31 | LL | let _: *const Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) - --> $DIR/transmute.rs:85:29 + --> $DIR/transmute.rs:100:29 | LL | let _: *mut Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a `u32` to a `char` - --> $DIR/transmute.rs:91:28 + --> $DIR/transmute.rs:107:28 | LL | let _: char = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_u32).unwrap()` @@ -95,13 +95,13 @@ LL | let _: char = unsafe { std::mem::transmute(0_u32) }; = note: `-D clippy::transmute-int-to-char` implied by `-D warnings` error: transmute from a `i32` to a `char` - --> $DIR/transmute.rs:92:28 + --> $DIR/transmute.rs:110:28 | LL | let _: char = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32).unwrap()` error: transmute from a `u8` to a `bool` - --> $DIR/transmute.rs:101:28 + --> $DIR/transmute.rs:120:28 | LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` @@ -109,7 +109,7 @@ LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; = note: `-D clippy::transmute-int-to-bool` implied by `-D warnings` error: transmute from a `u32` to a `f32` - --> $DIR/transmute.rs:107:31 + --> $DIR/transmute.rs:128:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` @@ -117,25 +117,25 @@ LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; = note: `-D clippy::transmute-int-to-float` implied by `-D warnings` error: transmute from a `i32` to a `f32` - --> $DIR/transmute.rs:108:31 + --> $DIR/transmute.rs:131:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)` error: transmute from a `u64` to a `f64` - --> $DIR/transmute.rs:109:31 + --> $DIR/transmute.rs:133:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_u64)` error: transmute from a `i64` to a `f64` - --> $DIR/transmute.rs:110:31 + --> $DIR/transmute.rs:135:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` error: transmute from a `u8` to a `[u8; 1]` - --> $DIR/transmute.rs:130:30 + --> $DIR/transmute.rs:156:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` @@ -143,85 +143,85 @@ LL | let _: [u8; 1] = std::mem::transmute(0u8); = note: `-D clippy::transmute-num-to-bytes` implied by `-D warnings` error: transmute from a `u32` to a `[u8; 4]` - --> $DIR/transmute.rs:131:30 + --> $DIR/transmute.rs:159:30 | LL | let _: [u8; 4] = std::mem::transmute(0u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()` error: transmute from a `u128` to a `[u8; 16]` - --> $DIR/transmute.rs:132:31 + --> $DIR/transmute.rs:161:31 | LL | let _: [u8; 16] = std::mem::transmute(0u128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()` error: transmute from a `i8` to a `[u8; 1]` - --> $DIR/transmute.rs:133:30 + --> $DIR/transmute.rs:163:30 | LL | let _: [u8; 1] = std::mem::transmute(0i8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()` error: transmute from a `i32` to a `[u8; 4]` - --> $DIR/transmute.rs:134:30 + --> $DIR/transmute.rs:165:30 | LL | let _: [u8; 4] = std::mem::transmute(0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()` error: transmute from a `i128` to a `[u8; 16]` - --> $DIR/transmute.rs:135:31 + --> $DIR/transmute.rs:167:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `f32` to a `[u8; 4]` - --> $DIR/transmute.rs:136:30 + --> $DIR/transmute.rs:169:30 | LL | let _: [u8; 4] = std::mem::transmute(0.0f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f32.to_ne_bytes()` error: transmute from a `f64` to a `[u8; 8]` - --> $DIR/transmute.rs:137:30 + --> $DIR/transmute.rs:171:30 | LL | let _: [u8; 8] = std::mem::transmute(0.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f64.to_ne_bytes()` error: transmute from a `u8` to a `[u8; 1]` - --> $DIR/transmute.rs:142:30 + --> $DIR/transmute.rs:177:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` error: transmute from a `u32` to a `[u8; 4]` - --> $DIR/transmute.rs:143:30 + --> $DIR/transmute.rs:179:30 | LL | let _: [u8; 4] = std::mem::transmute(0u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()` error: transmute from a `u128` to a `[u8; 16]` - --> $DIR/transmute.rs:144:31 + --> $DIR/transmute.rs:181:31 | LL | let _: [u8; 16] = std::mem::transmute(0u128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()` error: transmute from a `i8` to a `[u8; 1]` - --> $DIR/transmute.rs:145:30 + --> $DIR/transmute.rs:183:30 | LL | let _: [u8; 1] = std::mem::transmute(0i8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()` error: transmute from a `i32` to a `[u8; 4]` - --> $DIR/transmute.rs:146:30 + --> $DIR/transmute.rs:185:30 | LL | let _: [u8; 4] = std::mem::transmute(0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()` error: transmute from a `i128` to a `[u8; 16]` - --> $DIR/transmute.rs:147:31 + --> $DIR/transmute.rs:187:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `&[u8]` to a `&str` - --> $DIR/transmute.rs:157:28 + --> $DIR/transmute.rs:198:28 | LL | let _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(B).unwrap()` @@ -229,13 +229,13 @@ LL | let _: &str = unsafe { std::mem::transmute(B) }; = note: `-D clippy::transmute-bytes-to-str` implied by `-D warnings` error: transmute from a `&mut [u8]` to a `&mut str` - --> $DIR/transmute.rs:158:32 + --> $DIR/transmute.rs:201: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` - --> $DIR/transmute.rs:159:30 + --> $DIR/transmute.rs:203:30 | LL | const _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_unchecked(B)` diff --git a/tests/ui/transmute_64bit.rs b/tests/ui/transmute_64bit.rs index ceecf9b279f06..767cc503a39df 100644 --- a/tests/ui/transmute_64bit.rs +++ b/tests/ui/transmute_64bit.rs @@ -4,7 +4,10 @@ fn main() { unsafe { let _: *const usize = std::mem::transmute(6.0f64); + //~^ ERROR: transmute from a `f64` to a pointer + //~| NOTE: `-D clippy::wrong-transmute` implied by `-D warnings` let _: *mut usize = std::mem::transmute(6.0f64); + //~^ ERROR: transmute from a `f64` to a pointer } } diff --git a/tests/ui/transmute_64bit.stderr b/tests/ui/transmute_64bit.stderr index d1854c009ef56..32d7e6bdf421a 100644 --- a/tests/ui/transmute_64bit.stderr +++ b/tests/ui/transmute_64bit.stderr @@ -7,7 +7,7 @@ LL | let _: *const usize = std::mem::transmute(6.0f64); = note: `-D clippy::wrong-transmute` implied by `-D warnings` error: transmute from a `f64` to a pointer - --> $DIR/transmute_64bit.rs:8:29 + --> $DIR/transmute_64bit.rs:10:29 | LL | let _: *mut usize = std::mem::transmute(6.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute_collection.rs b/tests/ui/transmute_collection.rs index 5a431bee04a45..8bf454573355f 100644 --- a/tests/ui/transmute_collection.rs +++ b/tests/ui/transmute_collection.rs @@ -7,42 +7,61 @@ fn main() { unsafe { // wrong size let _ = transmute::<_, Vec>(vec![0u8]); + //~^ ERROR: transmute from `std::vec::Vec` to `std::vec::Vec` with mismat + //~| NOTE: `-D clippy::unsound-collection-transmute` implied by `-D warnings` // wrong layout let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); + //~^ ERROR: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with m // wrong size let _ = transmute::<_, VecDeque>(VecDeque::::new()); + //~^ ERROR: transmute from `std::collections::VecDeque` to `std::collections:: // wrong layout let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collecti // wrong size let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); + //~^ ERROR: transmute from `std::collections::BinaryHeap` to `std::collections // wrong layout let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collec // wrong size let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); + //~^ ERROR: transmute from `std::collections::BTreeSet` to `std::collections:: // wrong layout let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collecti // wrong size let _ = transmute::<_, HashSet>(HashSet::::new()); + //~^ ERROR: transmute from `std::collections::HashSet` to `std::collections::H // wrong layout let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collectio // wrong size let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::collectio let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::collect // wrong layout let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::coll let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap<[u8; 4], u32>` to `std::col // wrong size let _ = transmute::<_, HashMap>(HashMap::::new()); + //~^ ERROR: transmute from `std::collections::HashMap` to `std::collection let _ = transmute::<_, HashMap>(HashMap::::new()); + //~^ ERROR: transmute from `std::collections::HashMap` to `std::collecti // wrong layout let _ = transmute::<_, HashMap>(HashMap::::new()); + //~^ ERROR: transmute from `std::collections::HashMap` to `std::colle let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); + //~^ ERROR: transmute from `std::collections::HashMap<[u8; 4], u32>` to `std::coll let _ = transmute::<_, Vec>(Vec::>::new()); let _ = transmute::<_, Vec<*mut u32>>(Vec::>::new()); diff --git a/tests/ui/transmute_collection.stderr b/tests/ui/transmute_collection.stderr index ebc05c402abf6..e4b9963be89b3 100644 --- a/tests/ui/transmute_collection.stderr +++ b/tests/ui/transmute_collection.stderr @@ -7,103 +7,103 @@ LL | let _ = transmute::<_, Vec>(vec![0u8]); = note: `-D clippy::unsound-collection-transmute` implied by `-D warnings` error: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:11:17 + --> $DIR/transmute_collection.rs:13:17 | LL | let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque` to `std::collections::VecDeque` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:14:17 + --> $DIR/transmute_collection.rs:17:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collections::VecDeque` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:16:17 + --> $DIR/transmute_collection.rs:20:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:19:17 + --> $DIR/transmute_collection.rs:24:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:21:17 + --> $DIR/transmute_collection.rs:27:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet` to `std::collections::BTreeSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:24:17 + --> $DIR/transmute_collection.rs:31:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collections::BTreeSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:26:17 + --> $DIR/transmute_collection.rs:34:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet` to `std::collections::HashSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:29:17 + --> $DIR/transmute_collection.rs:38:17 | LL | let _ = transmute::<_, HashSet>(HashSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collections::HashSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:31:17 + --> $DIR/transmute_collection.rs:41:17 | LL | let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:34:17 + --> $DIR/transmute_collection.rs:45:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:35:17 + --> $DIR/transmute_collection.rs:47:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:37:17 + --> $DIR/transmute_collection.rs:50:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap<[u8; 4], u32>` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:38:17 + --> $DIR/transmute_collection.rs:52:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:41:17 + --> $DIR/transmute_collection.rs:56:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:42:17 + --> $DIR/transmute_collection.rs:58:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:44:17 + --> $DIR/transmute_collection.rs:61:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap<[u8; 4], u32>` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:45:17 + --> $DIR/transmute_collection.rs:63:17 | LL | let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmute_float_to_int.fixed b/tests/ui/transmute_float_to_int.fixed index 37dbb9141da3a..cef0bcfa623ae 100644 --- a/tests/ui/transmute_float_to_int.fixed +++ b/tests/ui/transmute_float_to_int.fixed @@ -2,11 +2,18 @@ fn float_to_int() { let _: u32 = unsafe { 1f32.to_bits() }; + //~^ ERROR: transmute from a `f32` to a `u32` + //~| NOTE: `-D clippy::transmute-float-to-int` implied by `-D warnings` let _: i32 = unsafe { 1f32.to_bits() as i32 }; + //~^ ERROR: transmute from a `f32` to a `i32` let _: u64 = unsafe { 1f64.to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: i64 = unsafe { 1f64.to_bits() as i64 }; + //~^ ERROR: transmute from a `f64` to a `i64` let _: u64 = unsafe { 1.0f64.to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: u64 = unsafe { (-1.0f64).to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` } mod issue_5747 { diff --git a/tests/ui/transmute_float_to_int.rs b/tests/ui/transmute_float_to_int.rs index 806b2d77dc77d..3d95bec2a20a9 100644 --- a/tests/ui/transmute_float_to_int.rs +++ b/tests/ui/transmute_float_to_int.rs @@ -2,11 +2,18 @@ fn float_to_int() { let _: u32 = unsafe { std::mem::transmute(1f32) }; + //~^ ERROR: transmute from a `f32` to a `u32` + //~| NOTE: `-D clippy::transmute-float-to-int` implied by `-D warnings` let _: i32 = unsafe { std::mem::transmute(1f32) }; + //~^ ERROR: transmute from a `f32` to a `i32` let _: u64 = unsafe { std::mem::transmute(1f64) }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: i64 = unsafe { std::mem::transmute(1f64) }; + //~^ ERROR: transmute from a `f64` to a `i64` let _: u64 = unsafe { std::mem::transmute(1.0) }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: u64 = unsafe { std::mem::transmute(-1.0) }; + //~^ ERROR: transmute from a `f64` to a `u64` } mod issue_5747 { diff --git a/tests/ui/transmute_float_to_int.stderr b/tests/ui/transmute_float_to_int.stderr index eb786bb39f95a..dd21c0cde2c42 100644 --- a/tests/ui/transmute_float_to_int.stderr +++ b/tests/ui/transmute_float_to_int.stderr @@ -7,31 +7,31 @@ LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; = note: `-D clippy::transmute-float-to-int` implied by `-D warnings` error: transmute from a `f32` to a `i32` - --> $DIR/transmute_float_to_int.rs:5:27 + --> $DIR/transmute_float_to_int.rs:7:27 | LL | let _: i32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:6:27 + --> $DIR/transmute_float_to_int.rs:9:27 | LL | let _: u64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` error: transmute from a `f64` to a `i64` - --> $DIR/transmute_float_to_int.rs:7:27 + --> $DIR/transmute_float_to_int.rs:11:27 | LL | let _: i64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits() as i64` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:8:27 + --> $DIR/transmute_float_to_int.rs:13:27 | LL | let _: u64 = unsafe { std::mem::transmute(1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.0f64.to_bits()` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:9:27 + --> $DIR/transmute_float_to_int.rs:15:27 | LL | let _: u64 = unsafe { std::mem::transmute(-1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()` diff --git a/tests/ui/transmute_int_to_non_zero.fixed b/tests/ui/transmute_int_to_non_zero.fixed index b055a7c31c29b..866c0bbf1271e 100644 --- a/tests/ui/transmute_int_to_non_zero.fixed +++ b/tests/ui/transmute_int_to_non_zero.fixed @@ -16,16 +16,27 @@ fn main() { let int_i128: i128 = 1; let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; + //~^ ERROR: transmute from a `u8` to a `NonZeroU8` + //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; + //~^ ERROR: transmute from a `u16` to a `NonZeroU16` let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) }; + //~^ ERROR: transmute from a `u32` to a `NonZeroU32` let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) }; + //~^ ERROR: transmute from a `u64` to a `NonZeroU64` let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) }; + //~^ ERROR: transmute from a `u128` to a `NonZeroU128` let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) }; + //~^ ERROR: transmute from a `i8` to a `NonZeroI8` let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) }; + //~^ ERROR: transmute from a `i16` to a `NonZeroI16` let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) }; + //~^ ERROR: transmute from a `i32` to a `NonZeroI32` let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) }; + //~^ ERROR: transmute from a `i64` to a `NonZeroI64` let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) }; + //~^ ERROR: transmute from a `i128` to a `NonZeroI128` let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; diff --git a/tests/ui/transmute_int_to_non_zero.rs b/tests/ui/transmute_int_to_non_zero.rs index a384067825068..803c4945c755a 100644 --- a/tests/ui/transmute_int_to_non_zero.rs +++ b/tests/ui/transmute_int_to_non_zero.rs @@ -16,16 +16,27 @@ fn main() { let int_i128: i128 = 1; let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) }; + //~^ ERROR: transmute from a `u8` to a `NonZeroU8` + //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) }; + //~^ ERROR: transmute from a `u16` to a `NonZeroU16` let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) }; + //~^ ERROR: transmute from a `u32` to a `NonZeroU32` let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) }; + //~^ ERROR: transmute from a `u64` to a `NonZeroU64` let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) }; + //~^ ERROR: transmute from a `u128` to a `NonZeroU128` let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) }; + //~^ ERROR: transmute from a `i8` to a `NonZeroI8` let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) }; + //~^ ERROR: transmute from a `i16` to a `NonZeroI16` let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) }; + //~^ ERROR: transmute from a `i32` to a `NonZeroI32` let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) }; + //~^ ERROR: transmute from a `i64` to a `NonZeroI64` let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) }; + //~^ ERROR: transmute from a `i128` to a `NonZeroI128` let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; diff --git a/tests/ui/transmute_int_to_non_zero.stderr b/tests/ui/transmute_int_to_non_zero.stderr index 33f8ce79ea780..9efba88f38f6b 100644 --- a/tests/ui/transmute_int_to_non_zero.stderr +++ b/tests/ui/transmute_int_to_non_zero.stderr @@ -7,55 +7,55 @@ LL | let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) }; = note: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` error: transmute from a `u16` to a `NonZeroU16` - --> $DIR/transmute_int_to_non_zero.rs:19:34 + --> $DIR/transmute_int_to_non_zero.rs:21:34 | LL | let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU16::new_unchecked(int_u16)` error: transmute from a `u32` to a `NonZeroU32` - --> $DIR/transmute_int_to_non_zero.rs:20:34 + --> $DIR/transmute_int_to_non_zero.rs:23:34 | LL | let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU32::new_unchecked(int_u32)` error: transmute from a `u64` to a `NonZeroU64` - --> $DIR/transmute_int_to_non_zero.rs:21:34 + --> $DIR/transmute_int_to_non_zero.rs:25:34 | LL | let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU64::new_unchecked(int_u64)` error: transmute from a `u128` to a `NonZeroU128` - --> $DIR/transmute_int_to_non_zero.rs:22:35 + --> $DIR/transmute_int_to_non_zero.rs:27:35 | LL | let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU128::new_unchecked(int_u128)` error: transmute from a `i8` to a `NonZeroI8` - --> $DIR/transmute_int_to_non_zero.rs:24:33 + --> $DIR/transmute_int_to_non_zero.rs:30:33 | LL | let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI8::new_unchecked(int_i8)` error: transmute from a `i16` to a `NonZeroI16` - --> $DIR/transmute_int_to_non_zero.rs:25:34 + --> $DIR/transmute_int_to_non_zero.rs:32:34 | LL | let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI16::new_unchecked(int_i16)` error: transmute from a `i32` to a `NonZeroI32` - --> $DIR/transmute_int_to_non_zero.rs:26:34 + --> $DIR/transmute_int_to_non_zero.rs:34:34 | LL | let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI32::new_unchecked(int_i32)` error: transmute from a `i64` to a `NonZeroI64` - --> $DIR/transmute_int_to_non_zero.rs:27:34 + --> $DIR/transmute_int_to_non_zero.rs:36:34 | LL | let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI64::new_unchecked(int_i64)` error: transmute from a `i128` to a `NonZeroI128` - --> $DIR/transmute_int_to_non_zero.rs:28:35 + --> $DIR/transmute_int_to_non_zero.rs:38:35 | LL | let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI128::new_unchecked(int_i128)` diff --git a/tests/ui/transmute_null_to_fn.rs b/tests/ui/transmute_null_to_fn.rs index b3ea3d9039e08..7d780c803ffd5 100644 --- a/tests/ui/transmute_null_to_fn.rs +++ b/tests/ui/transmute_null_to_fn.rs @@ -6,7 +6,9 @@ fn one_liners() { unsafe { let _: fn() = std::mem::transmute(0 as *const ()); + //~^ ERROR: transmuting a known null pointer into a function pointer let _: fn() = std::mem::transmute(std::ptr::null::<()>()); + //~^ ERROR: transmuting a known null pointer into a function pointer } } @@ -17,6 +19,7 @@ fn transmute_const() { unsafe { // Should raise a lint. let _: fn() = std::mem::transmute(ZPTR); + //~^ ERROR: transmuting a known null pointer into a function pointer // Should NOT raise a lint. let _: fn() = std::mem::transmute(NOT_ZPTR); } diff --git a/tests/ui/transmute_null_to_fn.stderr b/tests/ui/transmute_null_to_fn.stderr index f0c65497d750e..6278f51dde25d 100644 --- a/tests/ui/transmute_null_to_fn.stderr +++ b/tests/ui/transmute_null_to_fn.stderr @@ -8,7 +8,7 @@ LL | let _: fn() = std::mem::transmute(0 as *const ()); = note: `-D clippy::transmute-null-to-fn` implied by `-D warnings` error: transmuting a known null pointer into a function pointer - --> $DIR/transmute_null_to_fn.rs:9:23 + --> $DIR/transmute_null_to_fn.rs:10:23 | LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -16,7 +16,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 - --> $DIR/transmute_null_to_fn.rs:19:23 + --> $DIR/transmute_null_to_fn.rs:21:23 | LL | let _: fn() = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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 5380c49b96a12..19abced98bb85 100644 --- a/tests/ui/transmute_ptr_to_ptr.fixed +++ b/tests/ui/transmute_ptr_to_ptr.fixed @@ -28,14 +28,21 @@ fn transmute_ptr_to_ptr() { unsafe { // pointer-to-pointer transmutes; bad let _: *const f32 = ptr as *const f32; + //~^ ERROR: transmute from a pointer to a pointer + //~| NOTE: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` let _: *mut f32 = mut_ptr as *mut f32; + //~^ ERROR: transmute from a pointer to a pointer // ref-ref transmutes; bad let _: &f32 = &*(&1u32 as *const u32 as *const f32); + //~^ ERROR: transmute from a reference to a reference let _: &f64 = &*(&1f32 as *const f32 as *const f64); + //~^ ERROR: transmute from a reference to a reference //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not // the same type let _: &mut f32 = &mut *(&mut 1u32 as *mut u32 as *mut f32); + //~^ ERROR: transmute from a reference to a reference let _: &GenericParam = &*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam); + //~^ ERROR: transmute from a reference to a reference } // these are recommendations for solving the above; if these lint we need to update diff --git a/tests/ui/transmute_ptr_to_ptr.rs b/tests/ui/transmute_ptr_to_ptr.rs index 61a6c98ed5ac7..abba2b8e5244d 100644 --- a/tests/ui/transmute_ptr_to_ptr.rs +++ b/tests/ui/transmute_ptr_to_ptr.rs @@ -28,14 +28,21 @@ fn transmute_ptr_to_ptr() { unsafe { // pointer-to-pointer transmutes; bad let _: *const f32 = std::mem::transmute(ptr); + //~^ ERROR: transmute from a pointer to a pointer + //~| NOTE: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` let _: *mut f32 = std::mem::transmute(mut_ptr); + //~^ ERROR: transmute from a pointer to a pointer // ref-ref transmutes; bad let _: &f32 = std::mem::transmute(&1u32); + //~^ ERROR: transmute from a reference to a reference let _: &f64 = std::mem::transmute(&1f32); + //~^ ERROR: transmute from a reference to a reference //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not // the same type let _: &mut f32 = std::mem::transmute(&mut 1u32); + //~^ ERROR: transmute from a reference to a reference let _: &GenericParam = std::mem::transmute(&GenericParam { t: 1u32 }); + //~^ ERROR: transmute from a reference to a reference } // these are recommendations for solving the above; if these lint we need to update diff --git a/tests/ui/transmute_ptr_to_ptr.stderr b/tests/ui/transmute_ptr_to_ptr.stderr index 49a8a3347e404..ee414e46bb748 100644 --- a/tests/ui/transmute_ptr_to_ptr.stderr +++ b/tests/ui/transmute_ptr_to_ptr.stderr @@ -7,31 +7,31 @@ LL | let _: *const f32 = std::mem::transmute(ptr); = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` error: transmute from a pointer to a pointer - --> $DIR/transmute_ptr_to_ptr.rs:31:27 + --> $DIR/transmute_ptr_to_ptr.rs:33:27 | LL | let _: *mut f32 = std::mem::transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `mut_ptr as *mut f32` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:33:23 + --> $DIR/transmute_ptr_to_ptr.rs:36:23 | LL | let _: &f32 = std::mem::transmute(&1u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1u32 as *const u32 as *const f32)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:34:23 + --> $DIR/transmute_ptr_to_ptr.rs:38:23 | LL | let _: &f64 = std::mem::transmute(&1f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f32 as *const f32 as *const f64)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:37:27 + --> $DIR/transmute_ptr_to_ptr.rs:42:27 | LL | let _: &mut f32 = std::mem::transmute(&mut 1u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(&mut 1u32 as *mut u32 as *mut f32)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:38:37 + --> $DIR/transmute_ptr_to_ptr.rs:44:37 | LL | let _: &GenericParam = std::mem::transmute(&GenericParam { t: 1u32 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam)` diff --git a/tests/ui/transmute_undefined_repr.rs b/tests/ui/transmute_undefined_repr.rs index 6afb1915e7e58..a087d09c1202a 100644 --- a/tests/ui/transmute_undefined_repr.rs +++ b/tests/ui/transmute_undefined_repr.rs @@ -27,8 +27,11 @@ fn main() { // Lint, Ty2 is unordered let _: Ty2C = transmute(value::>()); + //~^ ERROR: transmute from `Ty2` which has an undefined layout + //~| NOTE: `-D clippy::transmute-undefined-repr` implied by `-D warnings` // Lint, Ty2 is unordered let _: Ty2 = transmute(value::>()); + //~^ ERROR: transmute into `Ty2` which has an undefined layout // Ok, Ty2 types are the same let _: Ty2 = transmute(value::>>()); @@ -37,16 +40,24 @@ fn main() { // Lint, different Ty2 instances let _: Ty2 = transmute(value::>>()); + //~^ ERROR: transmute from `Ty>` to `Ty2`, both of which h + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Lint, different Ty2 instances let _: Ty> = transmute(value::>()); + //~^ ERROR: transmute from `Ty2` to `Ty>`, both of which h + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou let _: Ty<&()> = transmute(value::<&()>()); let _: &() = transmute(value::>()); // Lint, different Ty2 instances let _: &Ty2 = transmute(value::>>()); + //~^ ERROR: transmute from `Ty<&Ty2>` to `&Ty2`, both of which + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Lint, different Ty2 instances let _: Ty<&Ty2> = transmute(value::<&Ty2>()); + //~^ ERROR: transmute from `&Ty2` to `Ty<&Ty2>`, both of which + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Ok, pointer to usize conversion let _: Ty = transmute(value::<&Ty2>()); @@ -75,8 +86,12 @@ fn main() { // Lint, different Ty2 instances let _: &'static mut Ty2 = transmute(value::>>()); + //~^ ERROR: transmute from `std::boxed::Box>` to `&mut Ty2 + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Lint, different Ty2 instances let _: Box> = transmute(value::<&'static mut Ty2>()); + //~^ ERROR: transmute from `&mut Ty2` to `std::boxed::Box> + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou // Ok, type erasure let _: *const () = transmute(value::>>()); @@ -172,8 +187,12 @@ fn main() { // Err let _: *const Ty2 = transmute(value::<*const Ty2C>>()); + //~^ ERROR: transmute into `*const Ty2` which has an undefined layout + //~| NOTE: the contained type `Ty2` has an undefined layout // Err let _: *const Ty2C> = transmute(value::<*const Ty2>()); + //~^ ERROR: transmute from `*const Ty2` which has an undefined layout + //~| NOTE: the contained type `Ty2` has an undefined layout // Ok let _: NonNull = transmute(value::>()); @@ -219,8 +238,12 @@ fn _with_generics() { // Err let _: Vec> = transmute(value::>>()); + //~^ ERROR: transmute from `std::vec::Vec>` to `std::vec::Vec> = transmute(value::>>()); + //~^ ERROR: transmute from `std::vec::Vec>` to `std::vec::Vec>()); diff --git a/tests/ui/transmute_undefined_repr.stderr b/tests/ui/transmute_undefined_repr.stderr index 220bcb5b528dc..3618213ecd505 100644 --- a/tests/ui/transmute_undefined_repr.stderr +++ b/tests/ui/transmute_undefined_repr.stderr @@ -7,13 +7,13 @@ LL | let _: Ty2C = transmute(value::>()); = note: `-D clippy::transmute-undefined-repr` implied by `-D warnings` error: transmute into `Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:31:32 + --> $DIR/transmute_undefined_repr.rs:33:32 | LL | let _: Ty2 = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `Ty>` to `Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:39:32 + --> $DIR/transmute_undefined_repr.rs:42:32 | LL | let _: Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,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 - --> $DIR/transmute_undefined_repr.rs:41:36 + --> $DIR/transmute_undefined_repr.rs:46:36 | LL | let _: Ty> = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,7 +29,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 - --> $DIR/transmute_undefined_repr.rs:47:33 + --> $DIR/transmute_undefined_repr.rs:54:33 | LL | let _: &Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,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 - --> $DIR/transmute_undefined_repr.rs:49:37 + --> $DIR/transmute_undefined_repr.rs:58:37 | LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,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 - --> $DIR/transmute_undefined_repr.rs:77:45 + --> $DIR/transmute_undefined_repr.rs:88:45 | LL | let _: &'static mut Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL | let _: &'static mut Ty2 = transmute(value::` to `std::boxed::Box>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:79:37 + --> $DIR/transmute_undefined_repr.rs:92:37 | LL | let _: Box> = transmute(value::<&'static mut Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL | let _: Box> = transmute(value::<&'static mut Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:174:39 + --> $DIR/transmute_undefined_repr.rs:189:39 | LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +69,7 @@ LL | let _: *const Ty2 = transmute(value::<*const Ty2C` has an undefined layout error: transmute from `*const Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:176:50 + --> $DIR/transmute_undefined_repr.rs:193:50 | LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +77,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 - --> $DIR/transmute_undefined_repr.rs:221:35 + --> $DIR/transmute_undefined_repr.rs:240:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,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 - --> $DIR/transmute_undefined_repr.rs:223:35 + --> $DIR/transmute_undefined_repr.rs:244:35 | LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/transmuting_null.rs b/tests/ui/transmuting_null.rs index ea3ee8edc81b1..88b8c9965237d 100644 --- a/tests/ui/transmuting_null.rs +++ b/tests/ui/transmuting_null.rs @@ -8,7 +8,10 @@ fn one_liners() { unsafe { let _: &u64 = std::mem::transmute(0 as *const u64); + //~^ ERROR: transmuting a known null pointer into a reference + //~| NOTE: `-D clippy::transmuting-null` implied by `-D warnings` let _: &u64 = std::mem::transmute(std::ptr::null::()); + //~^ ERROR: transmuting a known null pointer into a reference } } @@ -19,6 +22,7 @@ fn transmute_const() { unsafe { // Should raise a lint. let _: &u64 = std::mem::transmute(ZPTR); + //~^ ERROR: transmuting a known null pointer into a reference // Should NOT raise a lint. let _: &u64 = std::mem::transmute(NOT_ZPTR); } diff --git a/tests/ui/transmuting_null.stderr b/tests/ui/transmuting_null.stderr index 1848fc2490a00..a8de01ec15dc4 100644 --- a/tests/ui/transmuting_null.stderr +++ b/tests/ui/transmuting_null.stderr @@ -7,13 +7,13 @@ LL | let _: &u64 = std::mem::transmute(0 as *const u64); = note: `-D clippy::transmuting-null` implied by `-D warnings` error: transmuting a known null pointer into a reference - --> $DIR/transmuting_null.rs:11:23 + --> $DIR/transmuting_null.rs:13:23 | LL | let _: &u64 = std::mem::transmute(std::ptr::null::()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> $DIR/transmuting_null.rs:21:23 + --> $DIR/transmuting_null.rs:24:23 | LL | let _: &u64 = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type_complexity.rs b/tests/ui/type_complexity.rs index 816950110b201..be28ee2da0cd4 100644 --- a/tests/ui/type_complexity.rs +++ b/tests/ui/type_complexity.rs @@ -5,29 +5,42 @@ type Alias = Vec>>; // no warning here const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions +//~| NOTE: `-D clippy::type-complexity` implied by `-D warnings` static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions struct S { f: Vec>>, + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } struct Ts(Vec>>); +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions enum E { Tuple(Vec>>), + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions Struct { f: Vec>> }, + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } impl S { const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn impl_method(&self, p: Vec>>) {} + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } trait T { const A: Vec>>; + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions type B = Vec>>; + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn method(&self, p: Vec>>); + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn def_method(&self, p: Vec>>) {} + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } // Should not warn since there is likely no way to simplify this (#1013) @@ -40,13 +53,16 @@ impl T for () { } fn test1() -> Vec>> { + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions vec![] } fn test2(_x: Vec>>) {} +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn test3() { let _y: Vec>> = vec![]; + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } #[repr(C)] diff --git a/tests/ui/type_complexity.stderr b/tests/ui/type_complexity.stderr index 9da7edb1c3b74..496dacfbfde61 100644 --- a/tests/ui/type_complexity.stderr +++ b/tests/ui/type_complexity.stderr @@ -7,85 +7,85 @@ LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); = note: `-D clippy::type-complexity` implied by `-D warnings` error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:8:12 + --> $DIR/type_complexity.rs:10:12 | LL | static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:11:8 + --> $DIR/type_complexity.rs:14:8 | LL | f: Vec>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:14:11 + --> $DIR/type_complexity.rs:18:11 | LL | struct Ts(Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:17:11 + --> $DIR/type_complexity.rs:22:11 | LL | Tuple(Vec>>), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:18:17 + --> $DIR/type_complexity.rs:24:17 | LL | Struct { f: Vec>> }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:22:14 + --> $DIR/type_complexity.rs:29:14 | LL | const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:23:30 + --> $DIR/type_complexity.rs:31:30 | LL | fn impl_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:27:14 + --> $DIR/type_complexity.rs:36:14 | LL | const A: Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:28:14 + --> $DIR/type_complexity.rs:38:14 | LL | type B = Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:29:25 + --> $DIR/type_complexity.rs:40:25 | LL | fn method(&self, p: Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:30:29 + --> $DIR/type_complexity.rs:42:29 | LL | fn def_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:42:15 + --> $DIR/type_complexity.rs:55:15 | LL | fn test1() -> Vec>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:46:14 + --> $DIR/type_complexity.rs:60:14 | LL | fn test2(_x: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:49:13 + --> $DIR/type_complexity.rs:64:13 | LL | let _y: Vec>> = vec![]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type_repetition_in_bounds.rs b/tests/ui/type_repetition_in_bounds.rs index 874d97f7a46c7..504a003940502 100644 --- a/tests/ui/type_repetition_in_bounds.rs +++ b/tests/ui/type_repetition_in_bounds.rs @@ -8,6 +8,7 @@ pub fn foo(_t: T) where T: Copy, T: Clone, + //~^ ERROR: this type has already been used as a bound predicate { unimplemented!(); } @@ -25,6 +26,7 @@ trait LintBounds where Self: Clone, Self: Copy + Default + Ord, + //~^ ERROR: this type has already been used as a bound predicate Self: Add + AddAssign + Sub + SubAssign, Self: Mul + MulAssign + Div + DivAssign, { @@ -99,11 +101,13 @@ where pub fn f() where T: Clone, + //~^ ERROR: this type has already been used as a bound predicate { } pub fn g() where T: ?Sized, + //~^ ERROR: this type has already been used as a bound predicate { } @@ -129,6 +133,7 @@ mod issue8772_pass { pub fn f(arg: usize) where T: Trait, Box<[String]>, bool> + 'static, + //~^ ERROR: this type has already been used as a bound predicate U: Clone + Sync + 'static, { } diff --git a/tests/ui/type_repetition_in_bounds.stderr b/tests/ui/type_repetition_in_bounds.stderr index 54973c5bda572..607cd1fbf6a7b 100644 --- a/tests/ui/type_repetition_in_bounds.stderr +++ b/tests/ui/type_repetition_in_bounds.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::type_repetition_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:27:5 + --> $DIR/type_repetition_in_bounds.rs:28:5 | LL | Self: Copy + Default + Ord, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | Self: Copy + Default + Ord, = help: consider combining the bounds: `Self: Clone + Copy + Default + Ord` error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:101:5 + --> $DIR/type_repetition_in_bounds.rs:103:5 | LL | T: Clone, | ^^^^^^^^ @@ -28,7 +28,7 @@ LL | T: Clone, = help: consider combining the bounds: `T: ?Sized + Clone` error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:106:5 + --> $DIR/type_repetition_in_bounds.rs:109:5 | LL | T: ?Sized, | ^^^^^^^^^ @@ -36,7 +36,7 @@ LL | T: ?Sized, = help: consider combining the bounds: `T: Clone + ?Sized` error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:131:9 + --> $DIR/type_repetition_in_bounds.rs:135:9 | LL | T: Trait, Box<[String]>, bool> + 'static, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninit.rs b/tests/ui/uninit.rs index 2d567630e15de..10a4c22b5b91c 100644 --- a/tests/ui/uninit.rs +++ b/tests/ui/uninit.rs @@ -10,6 +10,8 @@ union MyOwnMaybeUninit { fn main() { let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; + //~^ ERROR: this call for this type may be undefined behavior + //~| NOTE: `#[deny(clippy::uninit_assumed_init)]` on by default // This is OK, because ZSTs do not contain data. let _: () = unsafe { MaybeUninit::uninit().assume_init() }; @@ -31,6 +33,7 @@ fn main() { // Was a false negative. let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; + //~^ ERROR: this call for this type may be undefined behavior polymorphic::<()>(); polymorphic_maybe_uninit_array::<10>(); @@ -39,6 +42,7 @@ fn main() { fn polymorphic() { // We are conservative around polymorphic types. let _: T = unsafe { MaybeUninit::uninit().assume_init() }; + //~^ ERROR: this call for this type may be undefined behavior } fn polymorphic_maybe_uninit_array() { diff --git a/tests/ui/uninit.stderr b/tests/ui/uninit.stderr index 248de56da76cb..1cc27ffe70d5d 100644 --- a/tests/ui/uninit.stderr +++ b/tests/ui/uninit.stderr @@ -7,13 +7,13 @@ LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; = note: `#[deny(clippy::uninit_assumed_init)]` on by default error: this call for this type may be undefined behavior - --> $DIR/uninit.rs:33:29 + --> $DIR/uninit.rs:35:29 | LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call for this type may be undefined behavior - --> $DIR/uninit.rs:41:29 + --> $DIR/uninit.rs:44:29 | LL | let _: T = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/uninit_vec.rs b/tests/ui/uninit_vec.rs index 79effc82fdf7c..c069b9adf2d96 100644 --- a/tests/ui/uninit_vec.rs +++ b/tests/ui/uninit_vec.rs @@ -15,29 +15,34 @@ union MyOwnMaybeUninit { fn main() { // with_capacity() -> set_len() should be detected let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { vec.set_len(200); } // reserve() -> set_len() should be detected vec.reserve(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { vec.set_len(200); } // new() -> set_len() should be detected let mut vec: Vec = Vec::new(); + //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values unsafe { vec.set_len(200); } // default() -> set_len() should be detected let mut vec: Vec = Default::default(); + //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values unsafe { vec.set_len(200); } let mut vec: Vec = Vec::default(); + //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values unsafe { vec.set_len(200); } @@ -45,13 +50,16 @@ fn main() { // test when both calls are enclosed in the same unsafe block unsafe { let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini vec.set_len(200); vec.reserve(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini vec.set_len(200); } let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { // test the case where there are other statements in the following unsafe block vec.set_len(200); @@ -61,11 +69,13 @@ fn main() { // handle vec stored in the field of a struct let mut my_vec = MyVec::default(); my_vec.vec.reserve(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { my_vec.vec.set_len(200); } my_vec.vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { my_vec.vec.set_len(200); } @@ -120,6 +130,7 @@ fn main() { fn polymorphic() { // We are conservative around polymorphic types. let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini unsafe { vec.set_len(10); } diff --git a/tests/ui/uninit_vec.stderr b/tests/ui/uninit_vec.stderr index 9cdf0c95ad9f1..1ffea9f8730de 100644 --- a/tests/ui/uninit_vec.stderr +++ b/tests/ui/uninit_vec.stderr @@ -3,7 +3,7 @@ error: calling `set_len()` immediately after reserving a buffer creates uninitia | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | @@ -11,45 +11,45 @@ LL | vec.set_len(200); = note: `-D clippy::uninit-vec` implied by `-D warnings` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:23:5 + --> $DIR/uninit_vec.rs:24:5 | LL | vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> $DIR/uninit_vec.rs:29:5 + --> $DIR/uninit_vec.rs:31:5 | LL | let mut vec: Vec = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> $DIR/uninit_vec.rs:35:5 + --> $DIR/uninit_vec.rs:38:5 | LL | let mut vec: Vec = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> $DIR/uninit_vec.rs:40:5 + --> $DIR/uninit_vec.rs:44:5 | LL | let mut vec: Vec = Vec::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:54:5 + --> $DIR/uninit_vec.rs:61:5 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,53 +60,55 @@ LL | vec.set_len(200); = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:63:5 + --> $DIR/uninit_vec.rs:71:5 | LL | my_vec.vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | my_vec.vec.set_len(200); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:68:5 + --> $DIR/uninit_vec.rs:77:5 | LL | my_vec.vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | my_vec.vec.set_len(200); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:47:9 + --> $DIR/uninit_vec.rs:52:9 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:50:9 + --> $DIR/uninit_vec.rs:56:9 | LL | vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^ +LL | LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:122:9 + --> $DIR/uninit_vec.rs:132:9 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(10); | ^^^^^^^^^^^^^^^ | diff --git a/tests/ui/unit_cmp.rs b/tests/ui/unit_cmp.rs index fc75f548a1bcc..cea89026da6f1 100644 --- a/tests/ui/unit_cmp.rs +++ b/tests/ui/unit_cmp.rs @@ -15,18 +15,22 @@ fn main() { // this warns if { + //~^ ERROR: ==-comparison of unit values detected. This will always be true + //~| NOTE: `-D clippy::unit-cmp` implied by `-D warnings` true; } == { false; } {} if { + //~^ ERROR: >-comparison of unit values detected. This will always be false true; } > { false; } {} assert_eq!( + //~^ ERROR: `assert_eq` of unit values detected. This will always succeed { true; }, @@ -35,6 +39,7 @@ fn main() { } ); debug_assert_eq!( + //~^ ERROR: `debug_assert_eq` of unit values detected. This will always succeed { true; }, @@ -44,6 +49,7 @@ fn main() { ); assert_ne!( + //~^ ERROR: `assert_ne` of unit values detected. This will always fail { true; }, @@ -52,6 +58,7 @@ fn main() { } ); debug_assert_ne!( + //~^ ERROR: `debug_assert_ne` of unit values detected. This will always fail { true; }, diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr index 79c890d644cd4..38618c59180c1 100644 --- a/tests/ui/unit_cmp.stderr +++ b/tests/ui/unit_cmp.stderr @@ -3,6 +3,8 @@ error: ==-comparison of unit values detected. This will always be true | LL | if { | ________^ +LL | | +LL | | LL | | true; LL | | } == { LL | | false; @@ -12,10 +14,11 @@ LL | | } {} = note: `-D clippy::unit-cmp` implied by `-D warnings` error: >-comparison of unit values detected. This will always be false - --> $DIR/unit_cmp.rs:23:8 + --> $DIR/unit_cmp.rs:25:8 | LL | if { | ________^ +LL | | LL | | true; LL | | } > { LL | | false; @@ -23,48 +26,48 @@ LL | | } {} | |_____^ error: `assert_eq` of unit values detected. This will always succeed - --> $DIR/unit_cmp.rs:29:5 + --> $DIR/unit_cmp.rs:32:5 | LL | / assert_eq!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); | |_____^ error: `debug_assert_eq` of unit values detected. This will always succeed - --> $DIR/unit_cmp.rs:37:5 + --> $DIR/unit_cmp.rs:41:5 | LL | / debug_assert_eq!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); | |_____^ error: `assert_ne` of unit values detected. This will always fail - --> $DIR/unit_cmp.rs:46:5 + --> $DIR/unit_cmp.rs:51:5 | LL | / assert_ne!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); | |_____^ error: `debug_assert_ne` of unit values detected. This will always fail - --> $DIR/unit_cmp.rs:54:5 + --> $DIR/unit_cmp.rs:60:5 | LL | / debug_assert_ne!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); diff --git a/tests/ui/unit_hash.fixed b/tests/ui/unit_hash.fixed index 18d39dc3fc531..ed0facf1b9635 100644 --- a/tests/ui/unit_hash.fixed +++ b/tests/ui/unit_hash.fixed @@ -17,12 +17,18 @@ fn main() { match my_enum { Foo::Empty => 0_u8.hash(&mut state), + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op Foo::WithValue(x) => x.hash(&mut state), } let res = (); 0_u8.hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op #[allow(clippy::unit_arg)] 0_u8.hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op } diff --git a/tests/ui/unit_hash.rs b/tests/ui/unit_hash.rs index 43eb54eff477b..f3636d1644da9 100644 --- a/tests/ui/unit_hash.rs +++ b/tests/ui/unit_hash.rs @@ -17,12 +17,18 @@ fn main() { match my_enum { Foo::Empty => ().hash(&mut state), + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op Foo::WithValue(x) => x.hash(&mut state), } let res = (); res.hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op #[allow(clippy::unit_arg)] do_nothing().hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op } diff --git a/tests/ui/unit_hash.stderr b/tests/ui/unit_hash.stderr index 089d1212dd17a..eeb48cf7f37fb 100644 --- a/tests/ui/unit_hash.stderr +++ b/tests/ui/unit_hash.stderr @@ -8,7 +8,7 @@ LL | Foo::Empty => ().hash(&mut state), = note: `-D clippy::unit-hash` implied by `-D warnings` error: this call to `hash` on the unit type will do nothing - --> $DIR/unit_hash.rs:24:5 + --> $DIR/unit_hash.rs:26:5 | LL | res.hash(&mut state); | ^^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` @@ -16,7 +16,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 - --> $DIR/unit_hash.rs:27:5 + --> $DIR/unit_hash.rs:31: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 f2a9694f99e5b..59b2f7e355b34 100644 --- a/tests/ui/unit_return_expecting_ord.rs +++ b/tests/ui/unit_return_expecting_ord.rs @@ -17,13 +17,16 @@ fn unit(_i: isize) {} fn main() { let mut structs = vec![Struct { field: 2 }, Struct { field: 1 }]; structs.sort_by_key(|s| { + //~^ ERROR: this closure returns the unit type which also implements Ord double(s.field); }); structs.sort_by_key(|s| double(s.field)); structs.is_sorted_by_key(|s| { + //~^ ERROR: this closure returns the unit type which also implements PartialOrd double(s.field); }); structs.is_sorted_by_key(|s| { + //~^ ERROR: this closure returns the unit type which also implements PartialOrd if s.field > 0 { () } else { @@ -34,4 +37,5 @@ fn main() { return double(s.field); }); structs.sort_by_key(|s| unit(s.field)); + //~^ ERROR: this closure returns the unit type which also implements Ord } diff --git a/tests/ui/unit_return_expecting_ord.stderr b/tests/ui/unit_return_expecting_ord.stderr index 3a295af55eac9..74e6d6b126297 100644 --- a/tests/ui/unit_return_expecting_ord.stderr +++ b/tests/ui/unit_return_expecting_ord.stderr @@ -5,32 +5,32 @@ LL | structs.sort_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> $DIR/unit_return_expecting_ord.rs:20:24 + --> $DIR/unit_return_expecting_ord.rs:21:24 | LL | double(s.field); | ^ = note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings` error: this closure returns the unit type which also implements PartialOrd - --> $DIR/unit_return_expecting_ord.rs:23:30 + --> $DIR/unit_return_expecting_ord.rs:24:30 | LL | structs.is_sorted_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> $DIR/unit_return_expecting_ord.rs:24:24 + --> $DIR/unit_return_expecting_ord.rs:26:24 | LL | double(s.field); | ^ error: this closure returns the unit type which also implements PartialOrd - --> $DIR/unit_return_expecting_ord.rs:26:30 + --> $DIR/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 - --> $DIR/unit_return_expecting_ord.rs:36:25 + --> $DIR/unit_return_expecting_ord.rs:39:25 | LL | structs.sort_by_key(|s| unit(s.field)); | ^^^ diff --git a/tests/ui/unknown_attribute.rs b/tests/ui/unknown_attribute.rs index e993e63f8ed86..932f284d5b713 100644 --- a/tests/ui/unknown_attribute.rs +++ b/tests/ui/unknown_attribute.rs @@ -1,3 +1,4 @@ #[clippy::unknown] +//~^ ERROR: usage of unknown attribute #[clippy::cognitive_complexity = "1"] fn main() {} diff --git a/tests/ui/unnecessary_box_returns.rs b/tests/ui/unnecessary_box_returns.rs index bbe52d3735464..bcdaca33b6449 100644 --- a/tests/ui/unnecessary_box_returns.rs +++ b/tests/ui/unnecessary_box_returns.rs @@ -3,6 +3,7 @@ trait Bar { // lint fn baz(&self) -> Box; + //~^ ERROR: boxed return of the sized type `usize` } pub struct Foo {} @@ -16,6 +17,7 @@ impl Bar for Foo { impl Foo { fn baz(&self) -> Box { + //~^ ERROR: boxed return of the sized type `usize` // lint Box::new(13) } @@ -23,11 +25,13 @@ impl Foo { // lint fn bxed_usize() -> Box { + //~^ ERROR: boxed return of the sized type `usize` Box::new(5) } // lint fn _bxed_foo() -> Box { + //~^ ERROR: boxed return of the sized type `Foo` Box::new(Foo {}) } diff --git a/tests/ui/unnecessary_box_returns.stderr b/tests/ui/unnecessary_box_returns.stderr index b17512c10a177..8909dbcdd9855 100644 --- a/tests/ui/unnecessary_box_returns.stderr +++ b/tests/ui/unnecessary_box_returns.stderr @@ -8,7 +8,7 @@ LL | fn baz(&self) -> Box; = note: `-D clippy::unnecessary-box-returns` implied by `-D warnings` error: boxed return of the sized type `usize` - --> $DIR/unnecessary_box_returns.rs:18:22 + --> $DIR/unnecessary_box_returns.rs:19:22 | LL | fn baz(&self) -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -16,7 +16,7 @@ LL | fn baz(&self) -> Box { = help: changing this also requires a change to the return expressions in this function error: boxed return of the sized type `usize` - --> $DIR/unnecessary_box_returns.rs:25:20 + --> $DIR/unnecessary_box_returns.rs:27:20 | LL | fn bxed_usize() -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -24,7 +24,7 @@ LL | fn bxed_usize() -> Box { = help: changing this also requires a change to the return expressions in this function error: boxed return of the sized type `Foo` - --> $DIR/unnecessary_box_returns.rs:30:19 + --> $DIR/unnecessary_box_returns.rs:33:19 | LL | fn _bxed_foo() -> Box { | ^^^^^^^^ help: try: `Foo` diff --git a/tests/ui/unnecessary_cast_unfixable.rs b/tests/ui/unnecessary_cast_unfixable.rs index 89a50314fbcbf..36adf19c91ca7 100644 --- a/tests/ui/unnecessary_cast_unfixable.rs +++ b/tests/ui/unnecessary_cast_unfixable.rs @@ -2,6 +2,8 @@ //@no-rustfix fn main() { let _ = std::ptr::null() as *const u8; + //~^ ERROR: casting raw pointers to the same type and constness is unnecessary (`*cons + //~| NOTE: `-D clippy::unnecessary-cast` implied by `-D warnings` } mod issue11113 { @@ -17,6 +19,7 @@ mod issue11113 { impl TearOff { unsafe fn query(&self) { ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() + //~^ ERROR: casting raw pointers to the same type and constness is unnecessary } } } diff --git a/tests/ui/unnecessary_cast_unfixable.stderr b/tests/ui/unnecessary_cast_unfixable.stderr index eecf245686a84..ef3632db9f1d4 100644 --- a/tests/ui/unnecessary_cast_unfixable.stderr +++ b/tests/ui/unnecessary_cast_unfixable.stderr @@ -7,7 +7,7 @@ LL | let _ = std::ptr::null() as *const u8; = note: `-D clippy::unnecessary-cast` implied by `-D warnings` error: casting raw pointers to the same type and constness is unnecessary (`*mut issue11113::Vtbl` -> `*mut issue11113::Vtbl`) - --> $DIR/unnecessary_cast_unfixable.rs:19:16 + --> $DIR/unnecessary_cast_unfixable.rs:21:16 | LL | ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*(self.object as *mut *mut _)` diff --git a/tests/ui/unnecessary_clone.rs b/tests/ui/unnecessary_clone.rs index 90dd65a1d42fb..12ac96aa64caa 100644 --- a/tests/ui/unnecessary_clone.rs +++ b/tests/ui/unnecessary_clone.rs @@ -21,25 +21,34 @@ fn clone_on_ref_ptr() { let arc_weak = Arc::downgrade(&arc); rc.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer + //~| NOTE: `-D clippy::clone-on-ref-ptr` implied by `-D warnings` Rc::clone(&rc); arc.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer Arc::clone(&arc); rcweak.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer rc::Weak::clone(&rcweak); arc_weak.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer sync::Weak::clone(&arc_weak); let x = Arc::new(SomeImpl); let _: Arc = x.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer } fn clone_on_copy_generic(t: T) { t.clone(); + //~^ ERROR: using `clone` on type `T` which implements the `Copy` trait + //~| NOTE: `-D clippy::clone-on-copy` implied by `-D warnings` Some(t).clone(); + //~^ ERROR: using `clone` on type `Option` which implements the `Copy` trait } mod many_derefs { @@ -74,6 +83,7 @@ mod many_derefs { fn go1() { let a = A; let _: E = a.clone(); + //~^ ERROR: using `clone` on type `E` which implements the `Copy` trait let _: E = *****a; } } @@ -93,5 +103,6 @@ mod issue2076 { fn func() -> Option> { let rc = Rc::new(42); Some(try_opt!(Some(rc)).clone()) + //~^ ERROR: using `.clone()` on a ref-counted pointer } } diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index 23639f6d41a04..da387e8bb7c3c 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -7,31 +7,31 @@ LL | rc.clone(); = note: `-D clippy::clone-on-ref-ptr` implied by `-D warnings` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:26:5 + --> $DIR/unnecessary_clone.rs:28:5 | LL | arc.clone(); | ^^^^^^^^^^^ help: try: `Arc::::clone(&arc)` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:29:5 + --> $DIR/unnecessary_clone.rs:32:5 | LL | rcweak.clone(); | ^^^^^^^^^^^^^^ help: try: `Weak::::clone(&rcweak)` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:32:5 + --> $DIR/unnecessary_clone.rs:36:5 | LL | arc_weak.clone(); | ^^^^^^^^^^^^^^^^ help: try: `Weak::::clone(&arc_weak)` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:36:33 + --> $DIR/unnecessary_clone.rs:41:33 | LL | let _: Arc = x.clone(); | ^^^^^^^^^ help: try: `Arc::::clone(&x)` error: using `clone` on type `T` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:40:5 + --> $DIR/unnecessary_clone.rs:46:5 | LL | t.clone(); | ^^^^^^^^^ help: try removing the `clone` call: `t` @@ -39,19 +39,19 @@ LL | t.clone(); = note: `-D clippy::clone-on-copy` implied by `-D warnings` error: using `clone` on type `Option` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:42:5 + --> $DIR/unnecessary_clone.rs:50:5 | LL | Some(t).clone(); | ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)` error: using `clone` on type `E` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:76:20 + --> $DIR/unnecessary_clone.rs:85:20 | LL | let _: E = a.clone(); | ^^^^^^^^^ help: try dereferencing it: `*****a` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:95:14 + --> $DIR/unnecessary_clone.rs:105:14 | LL | Some(try_opt!(Some(rc)).clone()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc::::clone(&try_opt!(Some(rc)))` diff --git a/tests/ui/unnecessary_filter_map.rs b/tests/ui/unnecessary_filter_map.rs index 3c8c6ec94c1b6..1e0d7d12965c2 100644 --- a/tests/ui/unnecessary_filter_map.rs +++ b/tests/ui/unnecessary_filter_map.rs @@ -2,18 +2,23 @@ fn main() { let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); + //~^ ERROR: this `.filter_map` can be written more simply using `.filter` + //~| NOTE: `-D clippy::unnecessary-filter-map` implied by `-D warnings` let _ = (0..4).filter_map(|x| { + //~^ ERROR: this `.filter_map` can be written more simply using `.filter` if x > 1 { return Some(x); }; None }); let _ = (0..4).filter_map(|x| match x { + //~^ ERROR: this `.filter_map` can be written more simply using `.filter` 0 | 1 => None, _ => Some(x), }); let _ = (0..4).filter_map(|x| Some(x + 1)); + //~^ ERROR: this `.filter_map` can be written more simply using `.map` let _ = (0..4).filter_map(i32::checked_abs); } diff --git a/tests/ui/unnecessary_filter_map.stderr b/tests/ui/unnecessary_filter_map.stderr index 2d5403ce39444..f34acdc8d7e62 100644 --- a/tests/ui/unnecessary_filter_map.stderr +++ b/tests/ui/unnecessary_filter_map.stderr @@ -7,10 +7,11 @@ LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); = note: `-D clippy::unnecessary-filter-map` implied by `-D warnings` error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:5:13 + --> $DIR/unnecessary_filter_map.rs:7:13 | LL | let _ = (0..4).filter_map(|x| { | _____________^ +LL | | LL | | if x > 1 { LL | | return Some(x); LL | | }; @@ -19,23 +20,24 @@ LL | | }); | |______^ error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:11:13 + --> $DIR/unnecessary_filter_map.rs:14:13 | LL | let _ = (0..4).filter_map(|x| match x { | _____________^ +LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ error: this `.filter_map` can be written more simply using `.map` - --> $DIR/unnecessary_filter_map.rs:16:13 + --> $DIR/unnecessary_filter_map.rs:20:13 | LL | let _ = (0..4).filter_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:155:14 + --> $DIR/unnecessary_filter_map.rs:160:14 | LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_find_map.rs b/tests/ui/unnecessary_find_map.rs index 2c228fbbc9597..9972b68092abf 100644 --- a/tests/ui/unnecessary_find_map.rs +++ b/tests/ui/unnecessary_find_map.rs @@ -2,18 +2,23 @@ fn main() { let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); + //~^ ERROR: this `.find_map` can be written more simply using `.find` + //~| NOTE: `-D clippy::unnecessary-find-map` implied by `-D warnings` let _ = (0..4).find_map(|x| { + //~^ ERROR: this `.find_map` can be written more simply using `.find` if x > 1 { return Some(x); }; None }); let _ = (0..4).find_map(|x| match x { + //~^ ERROR: this `.find_map` can be written more simply using `.find` 0 | 1 => None, _ => Some(x), }); let _ = (0..4).find_map(|x| Some(x + 1)); + //~^ ERROR: this `.find_map` can be written more simply using `.map(..).next()` let _ = (0..4).find_map(i32::checked_abs); } diff --git a/tests/ui/unnecessary_find_map.stderr b/tests/ui/unnecessary_find_map.stderr index 3a995b41b179e..9acbd6650024a 100644 --- a/tests/ui/unnecessary_find_map.stderr +++ b/tests/ui/unnecessary_find_map.stderr @@ -7,10 +7,11 @@ LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); = note: `-D clippy::unnecessary-find-map` implied by `-D warnings` error: this `.find_map` can be written more simply using `.find` - --> $DIR/unnecessary_find_map.rs:5:13 + --> $DIR/unnecessary_find_map.rs:7:13 | LL | let _ = (0..4).find_map(|x| { | _____________^ +LL | | LL | | if x > 1 { LL | | return Some(x); LL | | }; @@ -19,23 +20,24 @@ LL | | }); | |______^ error: this `.find_map` can be written more simply using `.find` - --> $DIR/unnecessary_find_map.rs:11:13 + --> $DIR/unnecessary_find_map.rs:14:13 | LL | let _ = (0..4).find_map(|x| match x { | _____________^ +LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ error: this `.find_map` can be written more simply using `.map(..).next()` - --> $DIR/unnecessary_find_map.rs:16:13 + --> $DIR/unnecessary_find_map.rs:20:13 | LL | let _ = (0..4).find_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `.find_map` can be written more simply using `.find` - --> $DIR/unnecessary_find_map.rs:27:14 + --> $DIR/unnecessary_find_map.rs:32:14 | LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.rs b/tests/ui/unnecessary_lazy_eval_unfixable.rs index d529cd3109cfe..33685bfb738b0 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.rs +++ b/tests/ui/unnecessary_lazy_eval_unfixable.rs @@ -11,11 +11,15 @@ struct SomeStruct { fn main() { // fix will break type inference let _ = Ok(1).unwrap_or_else(|()| 2); + //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` + //~| NOTE: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` mod e { pub struct E; } let _ = Ok(1).unwrap_or_else(|e::E| 2); + //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); + //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` // Fix #6343 let arr = [(Some(1),)]; diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/tests/ui/unnecessary_lazy_eval_unfixable.stderr index 7f353ba06982a..8bff2a6377935 100644 --- a/tests/ui/unnecessary_lazy_eval_unfixable.stderr +++ b/tests/ui/unnecessary_lazy_eval_unfixable.stderr @@ -9,7 +9,7 @@ LL | let _ = Ok(1).unwrap_or_else(|()| 2); = note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13 + --> $DIR/unnecessary_lazy_eval_unfixable.rs:19:13 | LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | ^^^^^^------------------------ @@ -17,7 +17,7 @@ LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval_unfixable.rs:18:13 + --> $DIR/unnecessary_lazy_eval_unfixable.rs:21:13 | LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); | ^^^^^^------------------------------------- diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/tests/ui/unnecessary_literal_unwrap_unfixable.rs index 2671ecf678124..61058b7988a2d 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.rs +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs @@ -5,102 +5,154 @@ fn unwrap_option_some() { let val = Some(1); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Some` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Some` value } fn unwrap_option_some_context() { let _val = Some::([1, 2, 3].iter().sum()).unwrap(); + //~^ ERROR: used `unwrap()` on `Some` value let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); + //~^ ERROR: used `expect()` on `Some` value let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Some` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Some` value } fn unwrap_option_none() { let val = None::<()>; let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `None` value let _val2 = val.expect("this always happens"); + //~^ ERROR: used `expect()` on `None` value let _val3: u8 = None.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `None` value None::<()>.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `None` value } fn unwrap_result_ok() { let val = Ok::<_, ()>(1); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Ok` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Ok` value let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Ok` value let _val2 = val.expect_err("this always happens"); + //~^ ERROR: used `expect_err()` on `Ok` value } fn unwrap_result_ok_context() { let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); + //~^ ERROR: used `unwrap()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); + //~^ ERROR: used `expect()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); + //~^ ERROR: used `expect_err()` on `Ok` value let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Ok` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Ok` value let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Ok` value let _val2 = val.expect_err("this always happens"); + //~^ ERROR: used `expect_err()` on `Ok` value } fn unwrap_result_err() { let val = Err::<(), _>(1); let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Err` value let _val2 = val.expect_err("this never happens"); + //~^ ERROR: used `expect_err()` on `Err` value let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Err` value let _val2 = val.expect("this always happens"); + //~^ ERROR: used `expect()` on `Err` value } fn unwrap_result_err_context() { let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Err` value let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); + //~^ ERROR: used `expect_err()` on `Err` value let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); + //~^ ERROR: used `unwrap()` on `Err` value let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); + //~^ ERROR: used `expect()` on `Err` value let val = Err::<(), usize>([1, 2, 3].iter().sum()); let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Err` value let _val2 = val.expect_err("this never happens"); + //~^ ERROR: used `expect_err()` on `Err` value let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Err` value let _val2 = val.expect("this always happens"); + //~^ ERROR: used `expect()` on `Err` value } fn unwrap_methods_option() { let val = Some(1); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Some` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Some` value let _val2 = val.unwrap_or_else(|| 2); + //~^ ERROR: used `unwrap_or_else()` on `Some` value } fn unwrap_methods_option_context() { let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Some` value let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Some` value let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); + //~^ ERROR: used `unwrap_or_else()` on `Some` value let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Some` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Some` value let _val2 = val.unwrap_or_else(|| 2); + //~^ ERROR: used `unwrap_or_else()` on `Some` value } fn unwrap_methods_result() { let val = Ok::<_, ()>(1); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Ok` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Ok` value let _val2 = val.unwrap_or_else(|_| 2); + //~^ ERROR: used `unwrap_or_else()` on `Ok` value } fn unwrap_methods_result_context() { let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); + //~^ ERROR: used `unwrap_or_else()` on `Ok` value let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Ok` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Ok` value let _val2 = val.unwrap_or_else(|_| 2); + //~^ ERROR: used `unwrap_or_else()` on `Ok` value } fn main() { diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr index 2d1270d47174f..2a60896c0a3c7 100644 --- a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr +++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr @@ -12,7 +12,7 @@ LL | let val = Some(1); = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings` error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:8:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:9:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,589 +24,589 @@ LL | let val = Some(1); | ^^^^^^^ error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:14:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:14:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:20:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:19:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:17:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:19:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:28:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `None` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `expect()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:23:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `None` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:24:21 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:32:21 | LL | let _val3: u8 = None.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()` error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:25:5 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:34:5 | LL | None::<()>.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()` error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:31:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:32:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:33:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:46:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:55:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:55:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:57:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:57:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:43:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:45:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:65:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:46:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:67:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:73:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:52:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:75:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:77:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:54:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:58:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:58:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:59:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:86:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:59:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:86:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:88:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:88:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:64:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:94:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:65:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:66:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:67:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:106:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:105:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:73:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:108:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:105:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:74:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:110:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:105:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:115:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:115:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:117:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:117:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:119:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:119:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:83:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:123:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:122:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:125:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:122:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:85:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:127:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:122:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:133:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:132:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:91:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:135:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:132:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:92:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:137:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:132:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:142:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:142:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:144:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:144:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:146:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:146:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:101:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:150:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:102:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:152:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:103:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:154:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_safety_comment.rs b/tests/ui/unnecessary_safety_comment.rs index d858701ae8ac5..d9a7ad8e56c57 100644 --- a/tests/ui/unnecessary_safety_comment.rs +++ b/tests/ui/unnecessary_safety_comment.rs @@ -4,14 +4,19 @@ mod unsafe_items_invalid_comment { // SAFETY: const CONST: u32 = 0; + //~^ ERROR: constant item has unnecessary safety comment // SAFETY: static STATIC: u32 = 0; + //~^ ERROR: static item has unnecessary safety comment // SAFETY: struct Struct; + //~^ ERROR: struct has unnecessary safety comment // SAFETY: enum Enum {} + //~^ ERROR: enum has unnecessary safety comment // SAFETY: mod module {} + //~^ ERROR: module has unnecessary safety comment } mod unnecessary_from_macro { @@ -40,12 +45,15 @@ mod unnecessary_from_macro { fn unnecessary_on_stmt_and_expr() -> u32 { // SAFETY: unnecessary let num = 42; + //~^ ERROR: statement has unnecessary safety comment // SAFETY: unnecessary if num > 24 {} + //~^ ERROR: statement has unnecessary safety comment // SAFETY: unnecessary 24 + //~^ ERROR: expression has unnecessary safety comment } mod issue_10084 { diff --git a/tests/ui/unnecessary_safety_comment.stderr b/tests/ui/unnecessary_safety_comment.stderr index 7b2af67d64c7b..d97048e270367 100644 --- a/tests/ui/unnecessary_safety_comment.stderr +++ b/tests/ui/unnecessary_safety_comment.stderr @@ -12,55 +12,55 @@ LL | // SAFETY: = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` error: static item has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:8:5 + --> $DIR/unnecessary_safety_comment.rs:9:5 | LL | static STATIC: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:7:5 + --> $DIR/unnecessary_safety_comment.rs:8:5 | LL | // SAFETY: | ^^^^^^^^^^ error: struct has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:10:5 + --> $DIR/unnecessary_safety_comment.rs:12:5 | LL | struct Struct; | ^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:9:5 + --> $DIR/unnecessary_safety_comment.rs:11:5 | LL | // SAFETY: | ^^^^^^^^^^ error: enum has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:12:5 + --> $DIR/unnecessary_safety_comment.rs:15:5 | LL | enum Enum {} | ^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:11:5 + --> $DIR/unnecessary_safety_comment.rs:14:5 | LL | // SAFETY: | ^^^^^^^^^^ error: module has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:14:5 + --> $DIR/unnecessary_safety_comment.rs:18:5 | LL | mod module {} | ^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:13:5 + --> $DIR/unnecessary_safety_comment.rs:17:5 | LL | // SAFETY: | ^^^^^^^^^^ error: impl has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:33:13 + --> $DIR/unnecessary_safety_comment.rs:38:13 | LL | impl T for $t {} | ^^^^^^^^^^^^^^^^ @@ -69,44 +69,44 @@ LL | with_safety_comment!(i32); | ------------------------- in this macro invocation | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:32:13 + --> $DIR/unnecessary_safety_comment.rs:37:13 | LL | // Safety: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `with_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: expression has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:48:5 + --> $DIR/unnecessary_safety_comment.rs:55:5 | LL | 24 | ^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:47:5 + --> $DIR/unnecessary_safety_comment.rs:54:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:42:5 + --> $DIR/unnecessary_safety_comment.rs:47:5 | LL | let num = 42; | ^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:41:5 + --> $DIR/unnecessary_safety_comment.rs:46:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:45:5 + --> $DIR/unnecessary_safety_comment.rs:51:5 | LL | if num > 24 {} | ^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:44:5 + --> $DIR/unnecessary_safety_comment.rs:50:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs index fa92143e980dd..200aefff1bbf4 100644 --- a/tests/ui/unnecessary_wraps.rs +++ b/tests/ui/unnecessary_wraps.rs @@ -7,6 +7,8 @@ // should be linted fn func1(a: bool, b: bool) -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` + //~| NOTE: `-D clippy::unnecessary-wraps` implied by `-D warnings` if a && b { return Some(42); } @@ -20,6 +22,7 @@ fn func1(a: bool, b: bool) -> Option { // should be linted fn func2(a: bool, b: bool) -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` if a && b { return Some(10); } @@ -38,6 +41,7 @@ fn func4(a: bool) -> Option { // should be linted fn func5() -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` Some(1) } @@ -48,6 +52,7 @@ fn func6() -> Option { // should be linted fn func7() -> Result { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Result` Ok(1) } @@ -76,6 +81,7 @@ impl A { // should be linted fn func12() -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` Some(1) } } @@ -103,6 +109,7 @@ fn issue_6384(s: &str) -> Option<&str> { // should be linted fn issue_6640_1(a: bool, b: bool) -> Option<()> { + //~^ ERROR: this function's return value is unnecessary if a && b { return Some(()); } @@ -116,6 +123,7 @@ fn issue_6640_1(a: bool, b: bool) -> Option<()> { // should be linted fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { + //~^ ERROR: this function's return value is unnecessary if a && b { return Ok(()); } diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr index d29235165359d..01340a0abddf4 100644 --- a/tests/ui/unnecessary_wraps.stderr +++ b/tests/ui/unnecessary_wraps.stderr @@ -2,9 +2,9 @@ error: this function's return value is unnecessarily wrapped by `Option` --> $DIR/unnecessary_wraps.rs:9:1 | LL | / fn func1(a: bool, b: bool) -> Option { +LL | | +LL | | LL | | if a && b { -LL | | return Some(42); -LL | | } ... | LL | | } LL | | } @@ -27,9 +27,10 @@ LL ~ return 1337; | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:22:1 + --> $DIR/unnecessary_wraps.rs:24:1 | LL | / fn func2(a: bool, b: bool) -> Option { +LL | | LL | | if a && b { LL | | return Some(10); LL | | } @@ -49,9 +50,10 @@ LL ~ if a { 20 } else { 30 } | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:40:1 + --> $DIR/unnecessary_wraps.rs:43:1 | LL | / fn func5() -> Option { +LL | | LL | | Some(1) LL | | } | |_^ @@ -66,9 +68,10 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Result` - --> $DIR/unnecessary_wraps.rs:50:1 + --> $DIR/unnecessary_wraps.rs:54:1 | LL | / fn func7() -> Result { +LL | | LL | | Ok(1) LL | | } | |_^ @@ -83,9 +86,10 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:78:5 + --> $DIR/unnecessary_wraps.rs:83:5 | LL | / fn func12() -> Option { +LL | | LL | | Some(1) LL | | } | |_____^ @@ -100,12 +104,12 @@ LL | 1 | error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:105:1 + --> $DIR/unnecessary_wraps.rs:111:1 | LL | / fn issue_6640_1(a: bool, b: bool) -> Option<()> { +LL | | LL | | if a && b { LL | | return Some(()); -LL | | } ... | LL | | } LL | | } @@ -127,12 +131,12 @@ LL ~ return ; | error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:118:1 + --> $DIR/unnecessary_wraps.rs:125:1 | LL | / fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { +LL | | LL | | if a && b { LL | | return Ok(()); -LL | | } ... | LL | | } LL | | } diff --git a/tests/ui/unsafe_derive_deserialize.rs b/tests/ui/unsafe_derive_deserialize.rs index bafca91917aa4..70dcaa3afa455 100644 --- a/tests/ui/unsafe_derive_deserialize.rs +++ b/tests/ui/unsafe_derive_deserialize.rs @@ -6,6 +6,7 @@ extern crate serde; use serde::Deserialize; #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct A; impl A { pub unsafe fn new(_a: i32, _b: i32) -> Self { @@ -14,12 +15,14 @@ impl A { } #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct B; impl B { pub unsafe fn unsafe_method(&self) {} } #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct C; impl C { pub fn unsafe_block(&self) { @@ -28,6 +31,7 @@ impl C { } #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct D; impl D { pub fn inner_unsafe_fn(&self) { diff --git a/tests/ui/unsafe_derive_deserialize.stderr b/tests/ui/unsafe_derive_deserialize.stderr index 8aaae2d7fff48..7b96500fd115a 100644 --- a/tests/ui/unsafe_derive_deserialize.stderr +++ b/tests/ui/unsafe_derive_deserialize.stderr @@ -9,7 +9,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:16:10 + --> $DIR/unsafe_derive_deserialize.rs:17:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:22:10 + --> $DIR/unsafe_derive_deserialize.rs:24:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:30:10 + --> $DIR/unsafe_derive_deserialize.rs:33:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ diff --git a/tests/ui/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs index 04f6ef29a9a15..e0e0ded140fc0 100644 --- a/tests/ui/unsafe_removed_from_name.rs +++ b/tests/ui/unsafe_removed_from_name.rs @@ -3,8 +3,11 @@ #![warn(clippy::unsafe_removed_from_name)] use std::cell::UnsafeCell as TotallySafeCell; +//~^ ERROR: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCell` +//~| NOTE: `-D clippy::unsafe-removed-from-name` implied by `-D warnings` use std::cell::UnsafeCell as TotallySafeCellAgain; +//~^ ERROR: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain // Shouldn't error use std::cell::RefCell as ProbablyNotUnsafe; @@ -23,9 +26,12 @@ mod mod_with_some_unsafe_things { } use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; +//~^ ERROR: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` // merged imports use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; +//~^ ERROR: removed `unsafe` from the name of `Unsafe` in use as `A` +//~| ERROR: removed `unsafe` from the name of `Unsafe` in use as `B` // Shouldn't error use mod_with_some_unsafe_things::Safe as IPromiseItsSafeThisTime; diff --git a/tests/ui/unsafe_removed_from_name.stderr b/tests/ui/unsafe_removed_from_name.stderr index 090d917bd3846..5daa69e1fb4d1 100644 --- a/tests/ui/unsafe_removed_from_name.stderr +++ b/tests/ui/unsafe_removed_from_name.stderr @@ -7,25 +7,25 @@ LL | use std::cell::UnsafeCell as TotallySafeCell; = note: `-D clippy::unsafe-removed-from-name` implied by `-D warnings` error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` - --> $DIR/unsafe_removed_from_name.rs:7:1 + --> $DIR/unsafe_removed_from_name.rs:9:1 | LL | use std::cell::UnsafeCell as TotallySafeCellAgain; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` - --> $DIR/unsafe_removed_from_name.rs:25:1 + --> $DIR/unsafe_removed_from_name.rs:28:1 | LL | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `A` - --> $DIR/unsafe_removed_from_name.rs:28:1 + --> $DIR/unsafe_removed_from_name.rs:32: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` - --> $DIR/unsafe_removed_from_name.rs:28:1 + --> $DIR/unsafe_removed_from_name.rs:32:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_async.rs b/tests/ui/unused_async.rs index 1d188025e418d..71722e9afd0b8 100644 --- a/tests/ui/unused_async.rs +++ b/tests/ui/unused_async.rs @@ -11,6 +11,7 @@ mod issue10800 { use std::future::ready; async fn async_block_await() { + //~^ ERROR: unused `async` for function with no await statements async { ready(()).await; }; @@ -43,6 +44,7 @@ mod issue9695 { async fn f() {} async fn f2() {} async fn f3() {} + //~^ ERROR: unused `async` for function with no await statements fn needs_async_fn>(_: fn() -> F) {} @@ -55,6 +57,7 @@ mod issue9695 { } async fn foo() -> i32 { + //~^ ERROR: unused `async` for function with no await statements 4 } @@ -66,6 +69,7 @@ struct S; impl S { async fn unused(&self) -> i32 { + //~^ ERROR: unused `async` for function with no await statements 1 } diff --git a/tests/ui/unused_async.stderr b/tests/ui/unused_async.stderr index 8d9b72c4886c2..06944f8f8d8d6 100644 --- a/tests/ui/unused_async.stderr +++ b/tests/ui/unused_async.stderr @@ -2,6 +2,7 @@ error: unused `async` for function with no await statements --> $DIR/unused_async.rs:13:5 | LL | / async fn async_block_await() { +LL | | LL | | async { LL | | ready(()).await; LL | | }; @@ -10,14 +11,14 @@ 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` - --> $DIR/unused_async.rs:15:23 + --> $DIR/unused_async.rs:16:23 | LL | ready(()).await; | ^^^^^ = note: `-D clippy::unused-async` implied by `-D warnings` error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:45:5 + --> $DIR/unused_async.rs:46:5 | LL | async fn f3() {} | ^^^^^^^^^^^^^^^^ @@ -25,9 +26,10 @@ LL | async fn f3() {} = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:57:1 + --> $DIR/unused_async.rs:59:1 | LL | / async fn foo() -> i32 { +LL | | LL | | 4 LL | | } | |_^ @@ -35,9 +37,10 @@ LL | | } = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:68:5 + --> $DIR/unused_async.rs:71:5 | LL | / async fn unused(&self) -> i32 { +LL | | LL | | 1 LL | | } | |_____^ diff --git a/tests/ui/unused_format_specs_unfixable.rs b/tests/ui/unused_format_specs_unfixable.rs index c10cff1b55e6a..be991935366fe 100644 --- a/tests/ui/unused_format_specs_unfixable.rs +++ b/tests/ui/unused_format_specs_unfixable.rs @@ -10,13 +10,18 @@ macro_rules! format_args_from_macro { fn main() { // prints `.`, not ` .` println!("{:5}.", format_args!("")); + //~^ ERROR: format specifiers have no effect on `format_args!()` + //~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings` //prints `abcde`, not `abc` println!("{:.3}", format_args!("abcde")); + //~^ ERROR: format specifiers have no effect on `format_args!()` println!("{:5}.", format_args_from_macro!()); + //~^ ERROR: format specifiers have no effect on `format_args!()` let args = format_args!(""); println!("{args:5}"); + //~^ ERROR: format specifiers have no effect on `format_args!()` } fn should_not_lint() { diff --git a/tests/ui/unused_format_specs_unfixable.stderr b/tests/ui/unused_format_specs_unfixable.stderr index cb7156b6baf0d..e9145ff382a73 100644 --- a/tests/ui/unused_format_specs_unfixable.stderr +++ b/tests/ui/unused_format_specs_unfixable.stderr @@ -16,7 +16,7 @@ LL + println!("{}.", format_args!("")); | error: format specifiers have no effect on `format_args!()` - --> $DIR/unused_format_specs_unfixable.rs:14:15 + --> $DIR/unused_format_specs_unfixable.rs:16:15 | LL | println!("{:.3}", format_args!("abcde")); | ^^^^^ @@ -32,7 +32,7 @@ LL + println!("{}", format_args!("abcde")); | error: format specifiers have no effect on `format_args!()` - --> $DIR/unused_format_specs_unfixable.rs:16:15 + --> $DIR/unused_format_specs_unfixable.rs:19:15 | LL | println!("{:5}.", format_args_from_macro!()); | ^^^^ @@ -45,7 +45,7 @@ LL + println!("{}.", format_args_from_macro!()); | error: format specifiers have no effect on `format_args!()` - --> $DIR/unused_format_specs_unfixable.rs:19:15 + --> $DIR/unused_format_specs_unfixable.rs:23:15 | LL | println!("{args:5}"); | ^^^^^^^^ diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index e9d1eeb31612c..62aec6e9eafca 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -7,20 +7,26 @@ use std::io::{self, Read}; fn question_mark(s: &mut T) -> io::Result<()> { s.write(b"test")?; + //~^ ERROR: written amount is not handled let mut buf = [0u8; 4]; s.read(&mut buf)?; + //~^ ERROR: read amount is not handled Ok(()) } fn unwrap(s: &mut T) { s.write(b"test").unwrap(); + //~^ ERROR: written amount is not handled let mut buf = [0u8; 4]; s.read(&mut buf).unwrap(); + //~^ ERROR: read amount is not handled } fn vectored(s: &mut T) -> io::Result<()> { s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; + //~^ ERROR: read amount is not handled s.write_vectored(&[io::IoSlice::new(&[])])?; + //~^ ERROR: written amount is not handled Ok(()) } @@ -28,6 +34,7 @@ fn ok(file: &str) -> Option<()> { let mut reader = std::fs::File::open(file).ok()?; let mut result = [0u8; 0]; reader.read(&mut result).ok()?; + //~^ ERROR: read amount is not handled Some(()) } @@ -37,6 +44,7 @@ fn or_else(file: &str) -> io::Result<()> { let mut reader = std::fs::File::open(file)?; let mut result = [0u8; 0]; reader.read(&mut result).or_else(|err| Err(err))?; + //~^ ERROR: read amount is not handled Ok(()) } @@ -49,6 +57,7 @@ fn or(file: &str) -> Result<(), Error> { let mut reader = std::fs::File::open(file).unwrap(); let mut result = [0u8; 0]; reader.read(&mut result).or(Err(Error::Kind))?; + //~^ ERROR: read amount is not handled Ok(()) } @@ -56,6 +65,7 @@ fn combine_or(file: &str) -> Result<(), Error> { let mut reader = std::fs::File::open(file).unwrap(); let mut result = [0u8; 0]; reader + //~^ ERROR: read amount is not handled .read(&mut result) .or(Err(Error::Kind)) .or(Err(Error::Kind)) @@ -65,19 +75,25 @@ fn combine_or(file: &str) -> Result<(), Error> { fn is_ok_err(s: &mut T) { s.write(b"ok").is_ok(); + //~^ ERROR: written amount is not handled s.write(b"err").is_err(); + //~^ ERROR: written amount is not handled let mut buf = [0u8; 0]; s.read(&mut buf).is_ok(); + //~^ ERROR: read amount is not handled s.read(&mut buf).is_err(); + //~^ ERROR: read amount is not handled } async fn bad_async_write(w: &mut W) { w.write(b"hello world").await.unwrap(); + //~^ ERROR: written amount is not handled } async fn bad_async_read(r: &mut R) { let mut buf = [0u8; 0]; r.read(&mut buf[..]).await.unwrap(); + //~^ ERROR: read amount is not handled } async fn io_not_ignored_async_write(mut w: W) { @@ -91,6 +107,7 @@ fn bad_async_write_closure(w: W) -> impl future let mut w = w; async move { w.write(b"hello world").await?; + //~^ ERROR: written amount is not handled Ok(()) } } @@ -99,6 +116,7 @@ async fn async_read_nested_or(r: &mut R, do_it: bool) -> R let mut buf = [0u8; 1]; if do_it { r.read(&mut buf[..]).await.or(Err(Error::Kind))?; + //~^ ERROR: read amount is not handled } Ok(buf) } @@ -107,11 +125,13 @@ use tokio::io::{AsyncRead as TokioAsyncRead, AsyncReadExt as _, AsyncWrite as To async fn bad_async_write_tokio(w: &mut W) { w.write(b"hello world").await.unwrap(); + //~^ ERROR: written amount is not handled } async fn bad_async_read_tokio(r: &mut R) { let mut buf = [0u8; 0]; r.read(&mut buf[..]).await.unwrap(); + //~^ ERROR: read amount is not handled } async fn undetected_bad_async_write(w: &mut W) { diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr index 0865c5213f687..c729a0b90166d 100644 --- a/tests/ui/unused_io_amount.stderr +++ b/tests/ui/unused_io_amount.stderr @@ -8,7 +8,7 @@ LL | s.write(b"test")?; = note: `-D clippy::unused-io-amount` implied by `-D warnings` error: read amount is not handled - --> $DIR/unused_io_amount.rs:11:5 + --> $DIR/unused_io_amount.rs:12:5 | LL | s.read(&mut buf)?; | ^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | s.read(&mut buf)?; = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:16:5 + --> $DIR/unused_io_amount.rs:18:5 | LL | s.write(b"test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | s.write(b"test").unwrap(); = help: use `Write::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:18:5 + --> $DIR/unused_io_amount.rs:21:5 | LL | s.read(&mut buf).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,19 +32,19 @@ LL | s.read(&mut buf).unwrap(); = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:22:5 + --> $DIR/unused_io_amount.rs:26:5 | LL | s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: written amount is not handled - --> $DIR/unused_io_amount.rs:23:5 + --> $DIR/unused_io_amount.rs:28:5 | LL | s.write_vectored(&[io::IoSlice::new(&[])])?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: read amount is not handled - --> $DIR/unused_io_amount.rs:30:5 + --> $DIR/unused_io_amount.rs:36:5 | LL | reader.read(&mut result).ok()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | reader.read(&mut result).ok()?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:39:5 + --> $DIR/unused_io_amount.rs:46:5 | LL | reader.read(&mut result).or_else(|err| Err(err))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,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 - --> $DIR/unused_io_amount.rs:51:5 + --> $DIR/unused_io_amount.rs:59:5 | LL | reader.read(&mut result).or(Err(Error::Kind))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -68,9 +68,10 @@ 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 - --> $DIR/unused_io_amount.rs:58:5 + --> $DIR/unused_io_amount.rs:67:5 | LL | / reader +LL | | LL | | .read(&mut result) LL | | .or(Err(Error::Kind)) LL | | .or(Err(Error::Kind)) @@ -80,7 +81,7 @@ LL | | .expect("error"); = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:67:5 + --> $DIR/unused_io_amount.rs:77:5 | LL | s.write(b"ok").is_ok(); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +89,7 @@ LL | s.write(b"ok").is_ok(); = help: use `Write::write_all` instead, or handle partial writes error: written amount is not handled - --> $DIR/unused_io_amount.rs:68:5 + --> $DIR/unused_io_amount.rs:79:5 | LL | s.write(b"err").is_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +97,7 @@ LL | s.write(b"err").is_err(); = help: use `Write::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:70:5 + --> $DIR/unused_io_amount.rs:82:5 | LL | s.read(&mut buf).is_ok(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +105,7 @@ LL | s.read(&mut buf).is_ok(); = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:71:5 + --> $DIR/unused_io_amount.rs:84:5 | LL | s.read(&mut buf).is_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +113,7 @@ LL | s.read(&mut buf).is_err(); = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:75:5 + --> $DIR/unused_io_amount.rs:89:5 | LL | w.write(b"hello world").await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +121,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 - --> $DIR/unused_io_amount.rs:80:5 + --> $DIR/unused_io_amount.rs:95:5 | LL | r.read(&mut buf[..]).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -128,7 +129,7 @@ LL | r.read(&mut buf[..]).await.unwrap(); = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:93:9 + --> $DIR/unused_io_amount.rs:109:9 | LL | w.write(b"hello world").await?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +137,7 @@ LL | w.write(b"hello world").await?; = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:101:9 + --> $DIR/unused_io_amount.rs:118:9 | LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +145,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 - --> $DIR/unused_io_amount.rs:109:5 + --> $DIR/unused_io_amount.rs:127:5 | LL | w.write(b"hello world").await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -152,7 +153,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 - --> $DIR/unused_io_amount.rs:114:5 + --> $DIR/unused_io_amount.rs:133:5 | LL | r.read(&mut buf[..]).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_peekable.rs b/tests/ui/unused_peekable.rs index b227f8660f53c..131b51e01b6f0 100644 --- a/tests/ui/unused_peekable.rs +++ b/tests/ui/unused_peekable.rs @@ -11,14 +11,17 @@ fn main() { #[allow(clippy::unused_unit)] fn invalid() { let peekable = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator // Only lint `new_local` let old_local = std::iter::empty::().peekable(); let new_local = old_local; + //~^ ERROR: `peek` never called on `Peekable` iterator // Behind mut ref let mut by_mut_ref_test = std::iter::empty::().peekable(); let by_mut_ref = &mut by_mut_ref_test; + //~^ ERROR: `peek` never called on `Peekable` iterator // Explicitly returns `Peekable` fn returns_peekable() -> Peekable> { @@ -26,21 +29,26 @@ fn invalid() { } let peekable_from_fn = returns_peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator // Using a method not exclusive to `Peekable` let mut peekable_using_iterator_method = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator peekable_using_iterator_method.next(); // Passed by ref to another function fn takes_ref(_peek: &Peekable>) {} let passed_along_ref = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator takes_ref(&passed_along_ref); // `by_ref` without `peek` let mut by_ref_test = std::iter::empty::().peekable(); let _by_ref = by_ref_test.by_ref(); + //~^ ERROR: `peek` never called on `Peekable` iterator let mut peekable_in_for_loop = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator for x in peekable_in_for_loop {} } diff --git a/tests/ui/unused_peekable.stderr b/tests/ui/unused_peekable.stderr index d969232fdf3b1..896ca49d710c9 100644 --- a/tests/ui/unused_peekable.stderr +++ b/tests/ui/unused_peekable.stderr @@ -8,7 +8,7 @@ LL | let peekable = std::iter::empty::().peekable(); = note: `-D clippy::unused-peekable` implied by `-D warnings` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:17:9 + --> $DIR/unused_peekable.rs:18:9 | LL | let new_local = old_local; | ^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let new_local = old_local; = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:21:9 + --> $DIR/unused_peekable.rs:23:9 | LL | let by_mut_ref = &mut by_mut_ref_test; | ^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let by_mut_ref = &mut by_mut_ref_test; = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:28:9 + --> $DIR/unused_peekable.rs:31:9 | LL | let peekable_from_fn = returns_peekable(); | ^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let peekable_from_fn = returns_peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:31:13 + --> $DIR/unused_peekable.rs:35:13 | LL | let mut peekable_using_iterator_method = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let mut peekable_using_iterator_method = std::iter::empty::().peek = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:36:9 + --> $DIR/unused_peekable.rs:41:9 | LL | let passed_along_ref = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | let passed_along_ref = std::iter::empty::().peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:41:9 + --> $DIR/unused_peekable.rs:47:9 | LL | let _by_ref = by_ref_test.by_ref(); | ^^^^^^^ @@ -56,7 +56,7 @@ LL | let _by_ref = by_ref_test.by_ref(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:43:13 + --> $DIR/unused_peekable.rs:50:13 | LL | let mut peekable_in_for_loop = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unused_self.rs b/tests/ui/unused_self.rs index 55bd5607185c6..d3d06037cb494 100644 --- a/tests/ui/unused_self.rs +++ b/tests/ui/unused_self.rs @@ -9,16 +9,25 @@ mod unused_self { impl A { fn unused_self_move(self) {} + //~^ ERROR: unused `self` argument fn unused_self_ref(&self) {} + //~^ ERROR: unused `self` argument fn unused_self_mut_ref(&mut self) {} + //~^ ERROR: unused `self` argument fn unused_self_pin_ref(self: Pin<&Self>) {} + //~^ ERROR: unused `self` argument fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} + //~^ ERROR: unused `self` argument fn unused_self_pin_nested(self: Pin>) {} + //~^ ERROR: unused `self` argument fn unused_self_box(self: Box) {} + //~^ ERROR: unused `self` argument fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { + //~^ ERROR: unused `self` argument x + y } fn unused_self_class_method(&self) { + //~^ ERROR: unused `self` argument Self::static_method(); } diff --git a/tests/ui/unused_self.stderr b/tests/ui/unused_self.stderr index 919f9b6efdab8..5cf15c00b1b6f 100644 --- a/tests/ui/unused_self.stderr +++ b/tests/ui/unused_self.stderr @@ -8,7 +8,7 @@ LL | fn unused_self_move(self) {} = note: `-D clippy::unused-self` implied by `-D warnings` error: unused `self` argument - --> $DIR/unused_self.rs:12:28 + --> $DIR/unused_self.rs:13:28 | LL | fn unused_self_ref(&self) {} | ^^^^^ @@ -16,7 +16,7 @@ LL | fn unused_self_ref(&self) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:13:32 + --> $DIR/unused_self.rs:15:32 | LL | fn unused_self_mut_ref(&mut self) {} | ^^^^^^^^^ @@ -24,7 +24,7 @@ LL | fn unused_self_mut_ref(&mut self) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:14:32 + --> $DIR/unused_self.rs:17:32 | LL | fn unused_self_pin_ref(self: Pin<&Self>) {} | ^^^^ @@ -32,7 +32,7 @@ LL | fn unused_self_pin_ref(self: Pin<&Self>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:15:36 + --> $DIR/unused_self.rs:19:36 | LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} | ^^^^ @@ -40,7 +40,7 @@ LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:16:35 + --> $DIR/unused_self.rs:21:35 | LL | fn unused_self_pin_nested(self: Pin>) {} | ^^^^ @@ -48,7 +48,7 @@ LL | fn unused_self_pin_nested(self: Pin>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:17:28 + --> $DIR/unused_self.rs:23:28 | LL | fn unused_self_box(self: Box) {} | ^^^^ @@ -56,7 +56,7 @@ LL | fn unused_self_box(self: Box) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:18:40 + --> $DIR/unused_self.rs:25:40 | LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { | ^^^^^ @@ -64,7 +64,7 @@ LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:21:37 + --> $DIR/unused_self.rs:29:37 | LL | fn unused_self_class_method(&self) { | ^^^^^ diff --git a/tests/ui/unwrap.rs b/tests/ui/unwrap.rs index 64d6437834e6b..8ad7e98503bfc 100644 --- a/tests/ui/unwrap.rs +++ b/tests/ui/unwrap.rs @@ -4,12 +4,15 @@ fn unwrap_option() { let opt = Some(0); let _ = opt.unwrap(); + //~^ ERROR: used `unwrap()` on an `Option` value } fn unwrap_result() { let res: Result = Ok(0); let _ = res.unwrap(); + //~^ ERROR: used `unwrap()` on a `Result` value let _ = res.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on a `Result` value } fn main() { diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr index 41db819f6fb75..38904858a3239 100644 --- a/tests/ui/unwrap.stderr +++ b/tests/ui/unwrap.stderr @@ -9,7 +9,7 @@ LL | let _ = opt.unwrap(); = note: `-D clippy::unwrap-used` implied by `-D warnings` error: used `unwrap()` on a `Result` value - --> $DIR/unwrap.rs:11:13 + --> $DIR/unwrap.rs:12:13 | LL | let _ = res.unwrap(); | ^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | let _ = res.unwrap(); = help: consider using `expect()` to provide a better panic message error: used `unwrap_err()` on a `Result` value - --> $DIR/unwrap.rs:12:13 + --> $DIR/unwrap.rs:14:13 | LL | let _ = res.unwrap_err(); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_expect_used.rs b/tests/ui/unwrap_expect_used.rs index 26f92ccdefaa3..96368a0705361 100644 --- a/tests/ui/unwrap_expect_used.rs +++ b/tests/ui/unwrap_expect_used.rs @@ -25,7 +25,9 @@ impl OptionExt for Option { fn main() { Some(3).unwrap(); + //~^ ERROR: used `unwrap()` on an `Option` value Some(3).expect("Hello world!"); + //~^ ERROR: used `expect()` on an `Option` value // Don't trigger on unwrap_err on an option Some(3).unwrap_err(); @@ -41,7 +43,11 @@ fn main() { let a: Result = Ok(3); a.unwrap(); + //~^ ERROR: used `unwrap()` on a `Result` value a.expect("Hello world!"); + //~^ ERROR: used `expect()` on a `Result` value a.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on a `Result` value a.expect_err("Hello error!"); + //~^ ERROR: used `expect_err()` on a `Result` value } diff --git a/tests/ui/unwrap_expect_used.stderr b/tests/ui/unwrap_expect_used.stderr index f66e47612add4..0b43f5727455f 100644 --- a/tests/ui/unwrap_expect_used.stderr +++ b/tests/ui/unwrap_expect_used.stderr @@ -8,7 +8,7 @@ LL | Some(3).unwrap(); = note: `-D clippy::unwrap-used` implied by `-D warnings` error: used `expect()` on an `Option` value - --> $DIR/unwrap_expect_used.rs:28:5 + --> $DIR/unwrap_expect_used.rs:29:5 | LL | Some(3).expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | Some(3).expect("Hello world!"); = note: `-D clippy::expect-used` implied by `-D warnings` error: used `unwrap()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:43:5 + --> $DIR/unwrap_expect_used.rs:45:5 | LL | a.unwrap(); | ^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | a.unwrap(); = note: if this value is an `Err`, it will panic error: used `expect()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:44:5 + --> $DIR/unwrap_expect_used.rs:47:5 | LL | a.expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | a.expect("Hello world!"); = note: if this value is an `Err`, it will panic error: used `unwrap_err()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:45:5 + --> $DIR/unwrap_expect_used.rs:49:5 | LL | a.unwrap_err(); | ^^^^^^^^^^^^^^ @@ -41,7 +41,7 @@ LL | a.unwrap_err(); = note: if this value is an `Ok`, it will panic error: used `expect_err()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:46:5 + --> $DIR/unwrap_expect_used.rs:51:5 | LL | a.expect_err("Hello error!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_in_result.rs b/tests/ui/unwrap_in_result.rs index 2aa842adc8560..a19db46c667d0 100644 --- a/tests/ui/unwrap_in_result.rs +++ b/tests/ui/unwrap_in_result.rs @@ -20,6 +20,7 @@ impl A { // should be detected fn bad_divisible_by_3(i_str: String) -> Result { + //~^ ERROR: used unwrap or expect in a function that returns result or option // checks whether a string represents a number divisible by 3 let i = i_str.parse::().unwrap(); if i % 3 == 0 { @@ -30,6 +31,7 @@ impl A { } fn example_option_expect(i_str: String) -> Option { + //~^ ERROR: used unwrap or expect in a function that returns result or option let i = i_str.parse::().expect("not a number"); if i % 3 == 0 { return Some(true); diff --git a/tests/ui/unwrap_in_result.stderr b/tests/ui/unwrap_in_result.stderr index 40e6bfe087e7d..a394da272a869 100644 --- a/tests/ui/unwrap_in_result.stderr +++ b/tests/ui/unwrap_in_result.stderr @@ -2,9 +2,9 @@ error: used unwrap or expect in a function that returns result or option --> $DIR/unwrap_in_result.rs:22:5 | LL | / fn bad_divisible_by_3(i_str: String) -> Result { +LL | | LL | | // checks whether a string represents a number divisible by 3 LL | | let i = i_str.parse::().unwrap(); -LL | | if i % 3 == 0 { ... | LL | | } LL | | } @@ -12,27 +12,27 @@ LL | | } | = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) - --> $DIR/unwrap_in_result.rs:24:17 + --> $DIR/unwrap_in_result.rs:25:17 | LL | let i = i_str.parse::().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::unwrap-in-result` implied by `-D warnings` error: used unwrap or expect in a function that returns result or option - --> $DIR/unwrap_in_result.rs:32:5 + --> $DIR/unwrap_in_result.rs:33:5 | LL | / fn example_option_expect(i_str: String) -> Option { +LL | | LL | | let i = i_str.parse::().expect("not a number"); LL | | if i % 3 == 0 { -LL | | return Some(true); -LL | | } +... | LL | | None LL | | } | |_____^ | = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) - --> $DIR/unwrap_in_result.rs:33:17 + --> $DIR/unwrap_in_result.rs:35:17 | LL | let i = i_str.parse::().expect("not a number"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unwrap_or.fixed b/tests/ui/unwrap_or.fixed index cc0a4fa05beb7..e1a47fc7bd940 100644 --- a/tests/ui/unwrap_or.fixed +++ b/tests/ui/unwrap_or.fixed @@ -3,8 +3,11 @@ fn main() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call + //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` } fn new_lines() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call } diff --git a/tests/ui/unwrap_or.rs b/tests/ui/unwrap_or.rs index 5bea85e669249..914bfb939b888 100644 --- a/tests/ui/unwrap_or.rs +++ b/tests/ui/unwrap_or.rs @@ -3,8 +3,11 @@ fn main() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call + //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` } fn new_lines() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call } diff --git a/tests/ui/unwrap_or.stderr b/tests/ui/unwrap_or.stderr index e384bbbb01557..8992092bc58fb 100644 --- a/tests/ui/unwrap_or.stderr +++ b/tests/ui/unwrap_or.stderr @@ -7,7 +7,7 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()) = note: `-D clippy::or-fun-call` implied by `-D warnings` error: use of `unwrap_or` followed by a function call - --> $DIR/unwrap_or.rs:9:47 + --> $DIR/unwrap_or.rs:11:47 | LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| "Fail".to_string())` diff --git a/tests/ui/upper_case_acronyms.fixed b/tests/ui/upper_case_acronyms.fixed index f416e7f25ba78..460567b097e53 100644 --- a/tests/ui/upper_case_acronyms.fixed +++ b/tests/ui/upper_case_acronyms.fixed @@ -7,13 +7,22 @@ struct CString; // not linted enum Flags { NS, // not linted Cwr, + //~^ ERROR: name `CWR` contains a capitalized acronym + //~| NOTE: `-D clippy::upper-case-acronyms` implied by `-D warnings` Ece, + //~^ ERROR: name `ECE` contains a capitalized acronym Urg, + //~^ ERROR: name `URG` contains a capitalized acronym Ack, + //~^ ERROR: name `ACK` contains a capitalized acronym Psh, + //~^ ERROR: name `PSH` contains a capitalized acronym Rst, + //~^ ERROR: name `RST` contains a capitalized acronym Syn, + //~^ ERROR: name `SYN` contains a capitalized acronym Fin, + //~^ ERROR: name `FIN` contains a capitalized acronym } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of @@ -34,15 +43,18 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { Wasd(u8), + //~^ ERROR: name `WASD` contains a capitalized acronym Utf8(std::string::FromUtf8Error), Parse(T, String), } // do lint here struct Json; +//~^ ERROR: name `JSON` contains a capitalized acronym // do lint here enum Yaml { + //~^ ERROR: name `YAML` contains a capitalized acronym Num(u32), Str(String), } diff --git a/tests/ui/upper_case_acronyms.rs b/tests/ui/upper_case_acronyms.rs index 9b7c2f28e1cfc..6a20aee62dce7 100644 --- a/tests/ui/upper_case_acronyms.rs +++ b/tests/ui/upper_case_acronyms.rs @@ -7,13 +7,22 @@ struct CString; // not linted enum Flags { NS, // not linted CWR, + //~^ ERROR: name `CWR` contains a capitalized acronym + //~| NOTE: `-D clippy::upper-case-acronyms` implied by `-D warnings` ECE, + //~^ ERROR: name `ECE` contains a capitalized acronym URG, + //~^ ERROR: name `URG` contains a capitalized acronym ACK, + //~^ ERROR: name `ACK` contains a capitalized acronym PSH, + //~^ ERROR: name `PSH` contains a capitalized acronym RST, + //~^ ERROR: name `RST` contains a capitalized acronym SYN, + //~^ ERROR: name `SYN` contains a capitalized acronym FIN, + //~^ ERROR: name `FIN` contains a capitalized acronym } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of @@ -34,15 +43,18 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { WASD(u8), + //~^ ERROR: name `WASD` contains a capitalized acronym Utf8(std::string::FromUtf8Error), Parse(T, String), } // do lint here struct JSON; +//~^ ERROR: name `JSON` contains a capitalized acronym // do lint here enum YAML { + //~^ ERROR: name `YAML` contains a capitalized acronym Num(u32), Str(String), } diff --git a/tests/ui/upper_case_acronyms.stderr b/tests/ui/upper_case_acronyms.stderr index 74082ec16dd45..9be1bb304eced 100644 --- a/tests/ui/upper_case_acronyms.stderr +++ b/tests/ui/upper_case_acronyms.stderr @@ -7,61 +7,61 @@ LL | CWR, = note: `-D clippy::upper-case-acronyms` implied by `-D warnings` error: name `ECE` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:10:5 + --> $DIR/upper_case_acronyms.rs:12:5 | LL | ECE, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Ece` error: name `URG` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:11:5 + --> $DIR/upper_case_acronyms.rs:14:5 | LL | URG, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Urg` error: name `ACK` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:12:5 + --> $DIR/upper_case_acronyms.rs:16:5 | LL | ACK, | ^^^ help: consider making the acronym lowercase, except the initial letter (notice the capitalization): `Ack` error: name `PSH` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:13:5 + --> $DIR/upper_case_acronyms.rs:18:5 | LL | PSH, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Psh` error: name `RST` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:14:5 + --> $DIR/upper_case_acronyms.rs:20:5 | LL | RST, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Rst` error: name `SYN` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:15:5 + --> $DIR/upper_case_acronyms.rs:22:5 | LL | SYN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Syn` error: name `FIN` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:16:5 + --> $DIR/upper_case_acronyms.rs:24:5 | LL | FIN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin` error: name `WASD` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:36:5 + --> $DIR/upper_case_acronyms.rs:45:5 | LL | WASD(u8), | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd` error: name `JSON` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:42:8 + --> $DIR/upper_case_acronyms.rs:52:8 | LL | struct JSON; | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Json` error: name `YAML` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:45:6 + --> $DIR/upper_case_acronyms.rs:56:6 | LL | enum YAML { | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Yaml` diff --git a/tests/ui/useless_conversion_try.rs b/tests/ui/useless_conversion_try.rs index ec0512ce210b6..a5feefbe0f099 100644 --- a/tests/ui/useless_conversion_try.rs +++ b/tests/ui/useless_conversion_try.rs @@ -3,7 +3,9 @@ fn test_generic(val: T) -> T { let _ = T::try_from(val).unwrap(); + //~^ ERROR: useless conversion to the same type: `T` val.try_into().unwrap() + //~^ ERROR: useless conversion to the same type: `T` } fn test_generic2 + Into, U: From>(val: T) { @@ -26,12 +28,19 @@ fn main() { let _: String = "foo".try_into().unwrap(); } let _: String = "foo".to_string().try_into().unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = TryFrom::try_from("foo".to_string()).unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _ = String::try_from("foo".to_string()).unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = format!("Hello {}", "world").try_into().unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = String::new().try_into().unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = match String::from("_").try_into() { + //~^ ERROR: useless conversion to the same type: `std::string::String` Ok(a) => a, Err(_) => String::new(), }; diff --git a/tests/ui/useless_conversion_try.stderr b/tests/ui/useless_conversion_try.stderr index 54189f8d28606..938bfb5237bba 100644 --- a/tests/ui/useless_conversion_try.stderr +++ b/tests/ui/useless_conversion_try.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::useless_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: useless conversion to the same type: `T` - --> $DIR/useless_conversion_try.rs:6:5 + --> $DIR/useless_conversion_try.rs:7:5 | LL | val.try_into().unwrap() | ^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | val.try_into().unwrap() = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:28:21 + --> $DIR/useless_conversion_try.rs:30:21 | LL | let _: String = "foo".to_string().try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | let _: String = "foo".to_string().try_into().unwrap(); = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:29:21 + --> $DIR/useless_conversion_try.rs:32:21 | LL | let _: String = TryFrom::try_from("foo".to_string()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | let _: String = TryFrom::try_from("foo".to_string()).unwrap(); = help: consider removing `TryFrom::try_from()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:30:13 + --> $DIR/useless_conversion_try.rs:34:13 | LL | let _ = String::try_from("foo".to_string()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | let _ = String::try_from("foo".to_string()).unwrap(); = help: consider removing `String::try_from()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:31:13 + --> $DIR/useless_conversion_try.rs:36:13 | LL | let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); = help: consider removing `String::try_from()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:32:21 + --> $DIR/useless_conversion_try.rs:38:21 | LL | let _: String = format!("Hello {}", "world").try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | let _: String = format!("Hello {}", "world").try_into().unwrap(); = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:33:21 + --> $DIR/useless_conversion_try.rs:40:21 | LL | let _: String = String::new().try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -68,7 +68,7 @@ LL | let _: String = String::new().try_into().unwrap(); = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:34:27 + --> $DIR/useless_conversion_try.rs:42:27 | LL | let _: String = match String::from("_").try_into() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/vec_init_then_push.rs b/tests/ui/vec_init_then_push.rs index edca17eef14b1..1c60a75c56ae0 100644 --- a/tests/ui/vec_init_then_push.rs +++ b/tests/ui/vec_init_then_push.rs @@ -3,12 +3,16 @@ //@no-rustfix fn main() { let mut def_err: Vec = Default::default(); + //~^ ERROR: calls to `push` immediately after creation + //~| NOTE: `-D clippy::vec-init-then-push` implied by `-D warnings` def_err.push(0); let mut new_err = Vec::::new(); + //~^ ERROR: calls to `push` immediately after creation new_err.push(1); let mut cap_err = Vec::with_capacity(2); + //~^ ERROR: calls to `push` immediately after creation cap_err.push(0); cap_err.push(1); cap_err.push(2); @@ -21,6 +25,7 @@ fn main() { cap_ok.push(0); new_err = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation new_err.push(0); let mut vec = Vec::new(); @@ -71,6 +76,7 @@ fn _cond_push(x: bool) -> Vec { fn _push_then_edit(x: u32) -> Vec { let mut v = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v.push(x); v.push(1); v[0] = v[1] + 5; @@ -79,6 +85,7 @@ fn _push_then_edit(x: u32) -> Vec { fn _cond_push_with_large_start(x: bool) -> Vec { let mut v = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v.push(0); v.push(1); v.push(0); @@ -92,6 +99,7 @@ fn _cond_push_with_large_start(x: bool) -> Vec { } let mut v2 = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v2.push(0); v2.push(1); v2.push(0); @@ -107,6 +115,7 @@ fn _cond_push_with_large_start(x: bool) -> Vec { fn f() { let mut v = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v.push((0i32, 0i32)); let y = v[0].0.abs(); } diff --git a/tests/ui/vec_init_then_push.stderr b/tests/ui/vec_init_then_push.stderr index a9da1c520197d..9ad793d979b77 100644 --- a/tests/ui/vec_init_then_push.stderr +++ b/tests/ui/vec_init_then_push.stderr @@ -2,70 +2,77 @@ error: calls to `push` immediately after creation --> $DIR/vec_init_then_push.rs:5:5 | LL | / let mut def_err: Vec = Default::default(); +LL | | +LL | | LL | | def_err.push(0); | |____________________^ help: consider using the `vec![]` macro: `let def_err: Vec = vec![..];` | = note: `-D clippy::vec-init-then-push` implied by `-D warnings` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:8:5 + --> $DIR/vec_init_then_push.rs:10:5 | LL | / let mut new_err = Vec::::new(); +LL | | LL | | new_err.push(1); | |____________________^ help: consider using the `vec![]` macro: `let mut new_err = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:11:5 + --> $DIR/vec_init_then_push.rs:14:5 | LL | / let mut cap_err = Vec::with_capacity(2); +LL | | LL | | cap_err.push(0); LL | | cap_err.push(1); LL | | cap_err.push(2); | |____________________^ help: consider using the `vec![]` macro: `let mut cap_err = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:23:5 + --> $DIR/vec_init_then_push.rs:27:5 | LL | / new_err = Vec::new(); +LL | | LL | | new_err.push(0); | |____________________^ help: consider using the `vec![]` macro: `new_err = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:73:5 + --> $DIR/vec_init_then_push.rs:78:5 | LL | / let mut v = Vec::new(); +LL | | LL | | v.push(x); LL | | v.push(1); | |______________^ help: consider using the `vec![]` macro: `let mut v = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:81:5 + --> $DIR/vec_init_then_push.rs:87:5 | LL | / let mut v = Vec::new(); +LL | | LL | | v.push(0); LL | | v.push(1); -LL | | v.push(0); ... | LL | | v.push(1); LL | | v.push(0); | |______________^ help: consider using the `vec![]` macro: `let mut v = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:94:5 + --> $DIR/vec_init_then_push.rs:101:5 | LL | / let mut v2 = Vec::new(); +LL | | LL | | v2.push(0); LL | | v2.push(1); -LL | | v2.push(0); ... | LL | | v2.push(1); LL | | v2.push(0); | |_______________^ help: consider using the `vec![]` macro: `let mut v2 = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:109:5 + --> $DIR/vec_init_then_push.rs:117:5 | LL | / let mut v = Vec::new(); +LL | | LL | | v.push((0i32, 0i32)); | |_________________________^ help: consider using the `vec![]` macro: `let v = vec![..];` diff --git a/tests/ui/vec_resize_to_zero.fixed b/tests/ui/vec_resize_to_zero.fixed index 2c12c5a9a915f..b4c2d8209e763 100644 --- a/tests/ui/vec_resize_to_zero.fixed +++ b/tests/ui/vec_resize_to_zero.fixed @@ -5,6 +5,7 @@ fn main() { // applicable here v.clear(); + //~^ ERROR: emptying a vector with `resize` // not applicable v.resize(2, 5); diff --git a/tests/ui/vec_resize_to_zero.rs b/tests/ui/vec_resize_to_zero.rs index a8307e741cf17..5b11c940f21a7 100644 --- a/tests/ui/vec_resize_to_zero.rs +++ b/tests/ui/vec_resize_to_zero.rs @@ -5,6 +5,7 @@ fn main() { // applicable here v.resize(0, 5); + //~^ ERROR: emptying a vector with `resize` // not applicable v.resize(2, 5); diff --git a/tests/ui/verbose_file_reads.rs b/tests/ui/verbose_file_reads.rs index df267e9872a0a..9dd4f4e1d9bef 100644 --- a/tests/ui/verbose_file_reads.rs +++ b/tests/ui/verbose_file_reads.rs @@ -21,8 +21,10 @@ fn main() -> std::io::Result<()> { let mut f = File::open(path)?; let mut buffer = Vec::new(); f.read_to_end(&mut buffer)?; + //~^ ERROR: use of `File::read_to_end` // ...and this let mut string_buffer = String::new(); f.read_to_string(&mut string_buffer)?; + //~^ ERROR: use of `File::read_to_string` Ok(()) } diff --git a/tests/ui/verbose_file_reads.stderr b/tests/ui/verbose_file_reads.stderr index 44266c7c01f39..592a7984305d4 100644 --- a/tests/ui/verbose_file_reads.stderr +++ b/tests/ui/verbose_file_reads.stderr @@ -8,7 +8,7 @@ LL | f.read_to_end(&mut buffer)?; = note: `-D clippy::verbose-file-reads` implied by `-D warnings` error: use of `File::read_to_string` - --> $DIR/verbose_file_reads.rs:26:5 + --> $DIR/verbose_file_reads.rs:27:5 | LL | f.read_to_string(&mut string_buffer)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/vtable_address_comparisons.rs b/tests/ui/vtable_address_comparisons.rs index 99c3f468f04a7..75647c027e146 100644 --- a/tests/ui/vtable_address_comparisons.rs +++ b/tests/ui/vtable_address_comparisons.rs @@ -12,16 +12,24 @@ fn main() { // These should fail: let _ = a == b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a != b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a < b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a <= b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a > b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a >= b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address ptr::eq(a, b); + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let a = &1 as &dyn Debug; let b = &1 as &dyn Debug; ptr::eq(a, b); + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address // These should be fine: let a = &1; diff --git a/tests/ui/vtable_address_comparisons.stderr b/tests/ui/vtable_address_comparisons.stderr index 7b866d274d586..91490afce3626 100644 --- a/tests/ui/vtable_address_comparisons.stderr +++ b/tests/ui/vtable_address_comparisons.stderr @@ -8,7 +8,7 @@ LL | let _ = a == b; = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings` error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:15:13 + --> $DIR/vtable_address_comparisons.rs:16:13 | LL | let _ = a != b; | ^^^^^^ @@ -16,7 +16,7 @@ LL | let _ = a != b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:16:13 + --> $DIR/vtable_address_comparisons.rs:18:13 | LL | let _ = a < b; | ^^^^^ @@ -24,7 +24,7 @@ LL | let _ = a < b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:17:13 + --> $DIR/vtable_address_comparisons.rs:20:13 | LL | let _ = a <= b; | ^^^^^^ @@ -32,7 +32,7 @@ LL | let _ = a <= b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:18:13 + --> $DIR/vtable_address_comparisons.rs:22:13 | LL | let _ = a > b; | ^^^^^ @@ -40,7 +40,7 @@ LL | let _ = a > b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:19:13 + --> $DIR/vtable_address_comparisons.rs:24:13 | LL | let _ = a >= b; | ^^^^^^ @@ -48,7 +48,7 @@ LL | let _ = a >= b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:20:5 + --> $DIR/vtable_address_comparisons.rs:26:5 | LL | ptr::eq(a, b); | ^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | ptr::eq(a, b); = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:24:5 + --> $DIR/vtable_address_comparisons.rs:31:5 | LL | ptr::eq(a, b); | ^^^^^^^^^^^^^ diff --git a/tests/ui/while_let_loop.rs b/tests/ui/while_let_loop.rs index c563a142919d3..fa5325bebffaf 100644 --- a/tests/ui/while_let_loop.rs +++ b/tests/ui/while_let_loop.rs @@ -4,6 +4,8 @@ fn main() { let y = Some(true); loop { + //~^ ERROR: this loop could be written as a `while let` loop + //~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings` if let Some(_x) = y { let _v = 1; } else { @@ -21,6 +23,7 @@ fn main() { } loop { + //~^ ERROR: this loop could be written as a `while let` loop match y { Some(_x) => true, None => break, @@ -28,6 +31,7 @@ fn main() { } loop { + //~^ ERROR: this loop could be written as a `while let` loop let x = match y { Some(x) => x, None => break, @@ -37,6 +41,7 @@ fn main() { } loop { + //~^ ERROR: this loop could be written as a `while let` loop let x = match y { Some(x) => x, None => break, @@ -67,6 +72,7 @@ fn main() { // #675, this used to have a wrong suggestion loop { + //~^ ERROR: this loop could be written as a `while let` loop let (e, l) = match "".split_whitespace().next() { Some(word) => (word.is_empty(), word.len()), None => break, diff --git a/tests/ui/while_let_loop.stderr b/tests/ui/while_let_loop.stderr index 04808c0b3adaf..00411172141c3 100644 --- a/tests/ui/while_let_loop.stderr +++ b/tests/ui/while_let_loop.stderr @@ -2,10 +2,10 @@ error: this loop could be written as a `while let` loop --> $DIR/while_let_loop.rs:6:5 | LL | / loop { +LL | | +LL | | LL | | if let Some(_x) = y { -LL | | let _v = 1; -LL | | } else { -LL | | break; +... | LL | | } LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` @@ -13,9 +13,10 @@ LL | | } = note: `-D clippy::while-let-loop` implied by `-D warnings` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:23:5 + --> $DIR/while_let_loop.rs:25:5 | LL | / loop { +LL | | LL | | match y { LL | | Some(_x) => true, LL | | None => break, @@ -24,36 +25,36 @@ LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:30:5 + --> $DIR/while_let_loop.rs:33:5 | LL | / loop { +LL | | LL | | let x = match y { LL | | Some(x) => x, -LL | | None => break, ... | LL | | let _str = "foo"; LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:39:5 + --> $DIR/while_let_loop.rs:43:5 | LL | / loop { +LL | | LL | | let x = match y { LL | | Some(x) => x, -LL | | None => break, ... | LL | | } LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:69:5 + --> $DIR/while_let_loop.rs:74:5 | LL | / loop { +LL | | LL | | let (e, l) = match "".split_whitespace().next() { LL | | Some(word) => (word.is_empty(), word.len()), -LL | | None => break, ... | LL | | let _ = (e, l); LL | | } diff --git a/tests/ui/wild_in_or_pats.rs b/tests/ui/wild_in_or_pats.rs index ad600f125772f..f8bb31b83c48b 100644 --- a/tests/ui/wild_in_or_pats.rs +++ b/tests/ui/wild_in_or_pats.rs @@ -6,6 +6,7 @@ fn main() { dbg!("matched a"); }, "bar" | _ => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or) wild"); }, }; @@ -14,6 +15,7 @@ fn main() { dbg!("matched a"); }, "bar" | "bar2" | _ => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or bar2 or) wild"); }, }; @@ -22,6 +24,7 @@ fn main() { dbg!("matched a"); }, _ | "bar" | _ => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or) wild"); }, }; @@ -30,6 +33,7 @@ fn main() { dbg!("matched a"); }, _ | "bar" => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or) wild"); }, }; diff --git a/tests/ui/wild_in_or_pats.stderr b/tests/ui/wild_in_or_pats.stderr index bd5860f45ca68..5d9ab78bbb4d8 100644 --- a/tests/ui/wild_in_or_pats.stderr +++ b/tests/ui/wild_in_or_pats.stderr @@ -8,7 +8,7 @@ LL | "bar" | _ => { = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` error: wildcard pattern covers any other pattern as it will match anyway - --> $DIR/wild_in_or_pats.rs:16:9 + --> $DIR/wild_in_or_pats.rs:17:9 | LL | "bar" | "bar2" | _ => { | ^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | "bar" | "bar2" | _ => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> $DIR/wild_in_or_pats.rs:24:9 + --> $DIR/wild_in_or_pats.rs:26:9 | LL | _ | "bar" | _ => { | ^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | _ | "bar" | _ => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> $DIR/wild_in_or_pats.rs:32:9 + --> $DIR/wild_in_or_pats.rs:35:9 | LL | _ | "bar" => { | ^^^^^^^^^ diff --git a/tests/ui/write_literal.fixed b/tests/ui/write_literal.fixed index b6708453bdeb9..ee577574d2898 100644 --- a/tests/ui/write_literal.fixed +++ b/tests/ui/write_literal.fixed @@ -29,17 +29,30 @@ fn main() { // these should throw warnings write!(v, "Hello world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::write-literal` implied by `-D warnings` writeln!(v, "Hello {} world", world); + //~^ ERROR: literal with an empty format string writeln!(v, "Hello world"); + //~^ ERROR: literal with an empty format string writeln!(v, "a literal {:.4}", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning writeln!(v, "hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either writeln!(v, "hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string } diff --git a/tests/ui/write_literal.rs b/tests/ui/write_literal.rs index 218385ea12966..588e8fd413a48 100644 --- a/tests/ui/write_literal.rs +++ b/tests/ui/write_literal.rs @@ -29,17 +29,30 @@ fn main() { // these should throw warnings write!(v, "Hello {}", "world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::write-literal` implied by `-D warnings` writeln!(v, "Hello {} {}", world, "world"); + //~^ ERROR: literal with an empty format string writeln!(v, "Hello {}", "world"); + //~^ ERROR: literal with an empty format string writeln!(v, "{} {:.4}", "a literal", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning writeln!(v, "{0} {1}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "{1} {0}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string } diff --git a/tests/ui/write_literal.stderr b/tests/ui/write_literal.stderr index 8b72c8bd28231..f0a09074bc654 100644 --- a/tests/ui/write_literal.stderr +++ b/tests/ui/write_literal.stderr @@ -12,7 +12,7 @@ LL + write!(v, "Hello world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:32:39 + --> $DIR/write_literal.rs:34:39 | LL | writeln!(v, "Hello {} {}", world, "world"); | ^^^^^^^ @@ -24,7 +24,7 @@ LL + writeln!(v, "Hello {} world", world); | error: literal with an empty format string - --> $DIR/write_literal.rs:33:29 + --> $DIR/write_literal.rs:36:29 | LL | writeln!(v, "Hello {}", "world"); | ^^^^^^^ @@ -36,7 +36,7 @@ LL + writeln!(v, "Hello world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:34:29 + --> $DIR/write_literal.rs:38:29 | LL | writeln!(v, "{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + writeln!(v, "a literal {:.4}", 5); | error: literal with an empty format string - --> $DIR/write_literal.rs:39:28 + --> $DIR/write_literal.rs:44:28 | LL | writeln!(v, "{0} {1}", "hello", "world"); | ^^^^^^^ @@ -60,7 +60,7 @@ LL + writeln!(v, "hello {1}", "world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:39:37 + --> $DIR/write_literal.rs:44:37 | LL | writeln!(v, "{0} {1}", "hello", "world"); | ^^^^^^^ @@ -72,7 +72,7 @@ LL + writeln!(v, "{0} world", "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:40:37 + --> $DIR/write_literal.rs:47:37 | LL | writeln!(v, "{1} {0}", "hello", "world"); | ^^^^^^^ @@ -84,7 +84,7 @@ LL + writeln!(v, "world {0}", "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:40:28 + --> $DIR/write_literal.rs:47:28 | LL | writeln!(v, "{1} {0}", "hello", "world"); | ^^^^^^^ @@ -96,7 +96,7 @@ LL + writeln!(v, "{1} hello", "world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:43:38 + --> $DIR/write_literal.rs:52:38 | LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -108,7 +108,7 @@ LL + writeln!(v, "hello {bar}", bar = "world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:43:53 + --> $DIR/write_literal.rs:52:53 | LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -120,7 +120,7 @@ LL + writeln!(v, "{foo} world", foo = "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:44:53 + --> $DIR/write_literal.rs:55:53 | LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -132,7 +132,7 @@ LL + writeln!(v, "world {foo}", foo = "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:44:38 + --> $DIR/write_literal.rs:55:38 | LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ diff --git a/tests/ui/write_literal_2.rs b/tests/ui/write_literal_2.rs index c71a4cb6f7a7f..aa0c13c134080 100644 --- a/tests/ui/write_literal_2.rs +++ b/tests/ui/write_literal_2.rs @@ -8,30 +8,50 @@ fn main() { let mut v = Vec::new(); writeln!(v, "{}", "{hello}"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::write-literal` implied by `-D warnings` writeln!(v, r"{}", r"{hello}"); + //~^ ERROR: unnecessary raw string literal + //~| NOTE: `-D clippy::needless-raw-strings` implied by `-D warnings` + //~| ERROR: literal with an empty format string writeln!(v, "{}", '\''); + //~^ ERROR: literal with an empty format string writeln!(v, "{}", '"'); + //~^ ERROR: literal with an empty format string writeln!(v, r"{}", '"'); + //~^ ERROR: literal with an empty format string writeln!(v, r"{}", '\''); + //~^ ERROR: literal with an empty format string writeln!( v, "some {}", "hello \ + //~^ ERROR: literal with an empty format string world!" ); writeln!( v, "some {}\ {} \\ {}", - "1", "2", "3", + "1", + "2", + "3", + //~^ ERROR: literal with an empty format string ); writeln!(v, "{}", "\\"); + //~^ ERROR: literal with an empty format string writeln!(v, r"{}", "\\"); + //~^ ERROR: literal with an empty format string writeln!(v, r#"{}"#, "\\"); + //~^ ERROR: literal with an empty format string writeln!(v, "{}", r"\"); + //~^ ERROR: literal with an empty format string writeln!(v, "{}", "\r"); + //~^ ERROR: literal with an empty format string // hard mode writeln!(v, r#"{}{}"#, '#', '"'); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // should not lint writeln!(v, r"{}", "\r"); } diff --git a/tests/ui/write_literal_2.stderr b/tests/ui/write_literal_2.stderr index c78a92f56eeff..84b302d8d3b4e 100644 --- a/tests/ui/write_literal_2.stderr +++ b/tests/ui/write_literal_2.stderr @@ -1,5 +1,5 @@ error: unnecessary raw string literal - --> $DIR/write_literal_2.rs:11:24 + --> $DIR/write_literal_2.rs:13:24 | LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ help: try: `"{hello}"` @@ -20,7 +20,7 @@ LL + writeln!(v, "{{hello}}"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:11:24 + --> $DIR/write_literal_2.rs:13:24 | LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ @@ -32,7 +32,7 @@ LL + writeln!(v, r"{{hello}}"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:12:23 + --> $DIR/write_literal_2.rs:17:23 | LL | writeln!(v, "{}", '\''); | ^^^^ @@ -44,7 +44,7 @@ LL + writeln!(v, "'"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:13:23 + --> $DIR/write_literal_2.rs:19:23 | LL | writeln!(v, "{}", '"'); | ^^^ @@ -56,13 +56,13 @@ LL + writeln!(v, "\""); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:14:24 + --> $DIR/write_literal_2.rs:21:24 | LL | writeln!(v, r"{}", '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:15:24 + --> $DIR/write_literal_2.rs:23:24 | LL | writeln!(v, r"{}", '\''); | ^^^^ @@ -74,56 +74,59 @@ LL + writeln!(v, r"'"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:19:9 + --> $DIR/write_literal_2.rs:28:9 | LL | / "hello \ +LL | | LL | | world!" | |_______________^ | help: try | LL ~ "some hello \ +LL + LL ~ world!" | error: literal with an empty format string - --> $DIR/write_literal_2.rs:26:9 + --> $DIR/write_literal_2.rs:36:9 | -LL | "1", "2", "3", +LL | "1", | ^^^ | help: try | LL ~ "some 1\ -LL ~ {} \\ {}", "2", "3", +LL ~ {} \\ {}", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:26:14 + --> $DIR/write_literal_2.rs:37:9 | -LL | "1", "2", "3", - | ^^^ +LL | "2", + | ^^^ | help: try | LL ~ 2 \\ {}", -LL ~ "1", "3", +LL ~ "1", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:26:19 + --> $DIR/write_literal_2.rs:38:9 | -LL | "1", "2", "3", - | ^^^ +LL | "3", + | ^^^ | help: try | LL ~ {} \\ 3", -LL ~ "1", "2", +LL | "1", +LL ~ "2", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:28:23 + --> $DIR/write_literal_2.rs:41:23 | LL | writeln!(v, "{}", "\\"); | ^^^^ @@ -135,7 +138,7 @@ LL + writeln!(v, "\\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:29:24 + --> $DIR/write_literal_2.rs:43:24 | LL | writeln!(v, r"{}", "\\"); | ^^^^ @@ -147,7 +150,7 @@ LL + writeln!(v, r"\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:30:26 + --> $DIR/write_literal_2.rs:45:26 | LL | writeln!(v, r#"{}"#, "\\"); | ^^^^ @@ -159,7 +162,7 @@ LL + writeln!(v, r#"\"#); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:31:23 + --> $DIR/write_literal_2.rs:47:23 | LL | writeln!(v, "{}", r"\"); | ^^^^ @@ -171,7 +174,7 @@ LL + writeln!(v, "\\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:32:23 + --> $DIR/write_literal_2.rs:49:23 | LL | writeln!(v, "{}", "\r"); | ^^^^ @@ -183,13 +186,13 @@ LL + writeln!(v, "\r"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:34:28 + --> $DIR/write_literal_2.rs:52:28 | LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:34:33 + --> $DIR/write_literal_2.rs:52:33 | LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ diff --git a/tests/ui/write_with_newline.fixed b/tests/ui/write_with_newline.fixed index c0e6c2a826405..82afff5c81f54 100644 --- a/tests/ui/write_with_newline.fixed +++ b/tests/ui/write_with_newline.fixed @@ -10,10 +10,16 @@ fn main() { // These should fail writeln!(v, "Hello"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::write-with-newline` implied by `-D warnings` writeln!(v, "Hello {}", "world"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline writeln!(v, "Hello {} {}", "world", "#2"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline writeln!(v, "{}", 1265); + //~^ ERROR: using `write!()` with a format string that ends in a single newline writeln!(v); + //~^ ERROR: using `write!()` with a format string that ends in a single newline // These should be fine write!(v, ""); @@ -36,6 +42,7 @@ fn main() { // #3514 write!(v, "\\n"); writeln!(v, "\\"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "\\\\n"); // Raw strings @@ -44,9 +51,11 @@ fn main() { // Literal newlines should also fail writeln!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v ); writeln!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v ); @@ -54,6 +63,7 @@ fn main() { write!(v, "\r\n"); write!(v, "foo\r\n"); writeln!(v, "\\r"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/write_with_newline.rs b/tests/ui/write_with_newline.rs index bacafdc8ad4ea..96e4bf0fbc4bd 100644 --- a/tests/ui/write_with_newline.rs +++ b/tests/ui/write_with_newline.rs @@ -10,10 +10,16 @@ fn main() { // These should fail write!(v, "Hello\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::write-with-newline` implied by `-D warnings` write!(v, "Hello {}\n", "world"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "Hello {} {}\n", "world", "#2"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "{}\n", 1265); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline // These should be fine write!(v, ""); @@ -36,6 +42,7 @@ fn main() { // #3514 write!(v, "\\n"); write!(v, "\\\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "\\\\n"); // Raw strings @@ -44,11 +51,13 @@ fn main() { // Literal newlines should also fail write!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v, " " ); write!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v, r" " @@ -58,6 +67,7 @@ fn main() { write!(v, "\r\n"); write!(v, "foo\r\n"); write!(v, "\\r\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "foo\rbar\n"); // Ignore expanded format strings diff --git a/tests/ui/write_with_newline.stderr b/tests/ui/write_with_newline.stderr index 4ab6919b6b214..d84d57d84f5b5 100644 --- a/tests/ui/write_with_newline.stderr +++ b/tests/ui/write_with_newline.stderr @@ -12,7 +12,7 @@ LL + writeln!(v, "Hello"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:13:5 + --> $DIR/write_with_newline.rs:15:5 | LL | write!(v, "Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + writeln!(v, "Hello {}", "world"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:14:5 + --> $DIR/write_with_newline.rs:17:5 | LL | write!(v, "Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + writeln!(v, "Hello {} {}", "world", "#2"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:15:5 + --> $DIR/write_with_newline.rs:19:5 | LL | write!(v, "{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + writeln!(v, "{}", 1265); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:16:5 + --> $DIR/write_with_newline.rs:21:5 | LL | write!(v, "\n"); | ^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + writeln!(v); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:38:5 + --> $DIR/write_with_newline.rs:44:5 | LL | write!(v, "\\\n"); | ^^^^^^^^^^^^^^^^^ @@ -72,9 +72,10 @@ LL + writeln!(v, "\\"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:46:5 + --> $DIR/write_with_newline.rs:53:5 | LL | / write!( +LL | | LL | | v, LL | | " LL | | " @@ -84,13 +85,15 @@ LL | | ); help: use `writeln!` instead | LL ~ writeln!( +LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:51:5 + --> $DIR/write_with_newline.rs:59:5 | LL | / write!( +LL | | LL | | v, LL | | r" LL | | " @@ -100,11 +103,12 @@ LL | | ); help: use `writeln!` instead | LL ~ writeln!( +LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:60:5 + --> $DIR/write_with_newline.rs:69:5 | LL | write!(v, "\\r\n"); | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs index e3cc90ee222ad..d7ed883b767c3 100644 --- a/tests/ui/wrong_self_convention.rs +++ b/tests/ui/wrong_self_convention.rs @@ -14,12 +14,14 @@ impl Foo { fn is_u32(&self) {} fn to_i32(self) {} fn from_i32(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` pub fn as_i64(self) {} pub fn into_i64(self) {} pub fn is_i64(self) {} pub fn to_i64(self) {} pub fn from_i64(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] pub fn from_cake(self) {} @@ -32,20 +34,30 @@ struct Bar; impl Bar { fn as_i32(self) {} + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl fn as_u32(&self) {} fn into_i32(&self) {} + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self) {} fn is_i32(self) {} + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `self` b fn is_u32(&self) {} fn to_i32(self) {} + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is not fn to_u32(&self) {} fn from_i32(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` pub fn as_i64(self) {} + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl pub fn into_i64(&self) {} + //~^ ERROR: methods called `into_*` usually take `self` by value pub fn is_i64(self) {} + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `self` b pub fn to_i64(self) {} + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is not pub fn from_i64(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` // test for false positives fn as_(self) {} @@ -91,15 +103,19 @@ mod issue4037 { mod issue6307 { trait T: Sized { fn as_i32(self) {} + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mu fn as_u32(&self) {} fn into_i32(self) {} fn into_i32_ref(&self) {} + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self) {} fn is_i32(self) {} + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `sel fn is_u32(&self) {} fn to_i32(self) {} fn to_u32(&self) {} fn from_i32(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self) {} @@ -115,15 +131,19 @@ mod issue6307 { trait U { fn as_i32(self); + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mu fn as_u32(&self); fn into_i32(self); fn into_i32_ref(&self); + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self); fn is_i32(self); + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `sel fn is_u32(&self); fn to_i32(self); fn to_u32(&self); fn from_i32(self); + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self); @@ -142,12 +162,14 @@ mod issue6307 { fn as_u32(&self); fn into_i32(self); fn into_i32_ref(&self); + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self); fn is_i32(self); fn is_u32(&self); fn to_i32(self); fn to_u32(&self); fn from_i32(self); + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self); @@ -172,6 +194,7 @@ mod issue6727 { } // trigger lint fn to_u64_v2(&self) -> u64 { + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is 1 } } @@ -181,6 +204,7 @@ mod issue6727 { impl FooNoCopy { // trigger lint fn to_u64(self) -> u64 { + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is 2 } fn to_u64_v2(&self) -> u64 { diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr index d002e55c57086..2d52b64c81274 100644 --- a/tests/ui/wrong_self_convention.stderr +++ b/tests/ui/wrong_self_convention.stderr @@ -8,7 +8,7 @@ LL | fn from_i32(self) {} = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:22:21 + --> $DIR/wrong_self_convention.rs:23:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -16,7 +16,7 @@ LL | pub fn from_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:34:15 + --> $DIR/wrong_self_convention.rs:36:15 | LL | fn as_i32(self) {} | ^^^^ @@ -24,7 +24,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:36:17 + --> $DIR/wrong_self_convention.rs:39:17 | LL | fn into_i32(&self) {} | ^^^^^ @@ -32,7 +32,7 @@ LL | fn into_i32(&self) {} = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:38:15 + --> $DIR/wrong_self_convention.rs:42:15 | LL | fn is_i32(self) {} | ^^^^ @@ -40,7 +40,7 @@ LL | fn is_i32(self) {} = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference - --> $DIR/wrong_self_convention.rs:40:15 + --> $DIR/wrong_self_convention.rs:45:15 | LL | fn to_i32(self) {} | ^^^^ @@ -48,7 +48,7 @@ LL | fn to_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:42:17 + --> $DIR/wrong_self_convention.rs:48:17 | LL | fn from_i32(self) {} | ^^^^ @@ -56,7 +56,7 @@ LL | fn from_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:44:19 + --> $DIR/wrong_self_convention.rs:51:19 | LL | pub fn as_i64(self) {} | ^^^^ @@ -64,7 +64,7 @@ LL | pub fn as_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:45:21 + --> $DIR/wrong_self_convention.rs:53:21 | LL | pub fn into_i64(&self) {} | ^^^^^ @@ -72,7 +72,7 @@ LL | pub fn into_i64(&self) {} = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:46:19 + --> $DIR/wrong_self_convention.rs:55:19 | LL | pub fn is_i64(self) {} | ^^^^ @@ -80,7 +80,7 @@ LL | pub fn is_i64(self) {} = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference - --> $DIR/wrong_self_convention.rs:47:19 + --> $DIR/wrong_self_convention.rs:57:19 | LL | pub fn to_i64(self) {} | ^^^^ @@ -88,7 +88,7 @@ LL | pub fn to_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:48:21 + --> $DIR/wrong_self_convention.rs:59:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -96,7 +96,7 @@ LL | pub fn from_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:93:19 + --> $DIR/wrong_self_convention.rs:105:19 | LL | fn as_i32(self) {} | ^^^^ @@ -104,7 +104,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:96:25 + --> $DIR/wrong_self_convention.rs:109:25 | LL | fn into_i32_ref(&self) {} | ^^^^^ @@ -112,7 +112,7 @@ LL | fn into_i32_ref(&self) {} = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:98:19 + --> $DIR/wrong_self_convention.rs:112:19 | LL | fn is_i32(self) {} | ^^^^ @@ -120,7 +120,7 @@ LL | fn is_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:102:21 + --> $DIR/wrong_self_convention.rs:117:21 | LL | fn from_i32(self) {} | ^^^^ @@ -128,7 +128,7 @@ LL | fn from_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:117:19 + --> $DIR/wrong_self_convention.rs:133:19 | LL | fn as_i32(self); | ^^^^ @@ -136,7 +136,7 @@ LL | fn as_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:120:25 + --> $DIR/wrong_self_convention.rs:137:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -144,7 +144,7 @@ LL | fn into_i32_ref(&self); = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:122:19 + --> $DIR/wrong_self_convention.rs:140:19 | LL | fn is_i32(self); | ^^^^ @@ -152,7 +152,7 @@ LL | fn is_i32(self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:126:21 + --> $DIR/wrong_self_convention.rs:145:21 | LL | fn from_i32(self); | ^^^^ @@ -160,7 +160,7 @@ LL | fn from_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:144:25 + --> $DIR/wrong_self_convention.rs:164:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -168,7 +168,7 @@ LL | fn into_i32_ref(&self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:150:21 + --> $DIR/wrong_self_convention.rs:171:21 | LL | fn from_i32(self); | ^^^^ @@ -176,7 +176,7 @@ LL | fn from_i32(self); = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value - --> $DIR/wrong_self_convention.rs:174:22 + --> $DIR/wrong_self_convention.rs:196:22 | LL | fn to_u64_v2(&self) -> u64 { | ^^^^^ @@ -184,7 +184,7 @@ LL | fn to_u64_v2(&self) -> u64 { = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference - --> $DIR/wrong_self_convention.rs:183:19 + --> $DIR/wrong_self_convention.rs:206:19 | LL | fn to_u64(self) -> u64 { | ^^^^ diff --git a/tests/ui/wrong_self_convention2.rs b/tests/ui/wrong_self_convention2.rs index 0dcf4743e8b8d..44b70f877be4d 100644 --- a/tests/ui/wrong_self_convention2.rs +++ b/tests/ui/wrong_self_convention2.rs @@ -52,6 +52,7 @@ mod issue7179 { // lint pub fn from_be_self(self) -> Self { + //~^ ERROR: methods called `from_*` usually take no `self` S(i32::from_be(self.0)) } } @@ -61,6 +62,7 @@ mod issue7179 { fn from_be(s: Self) -> Self; // lint fn from_be_self(self) -> Self; + //~^ ERROR: methods called `from_*` usually take no `self` } trait Foo: Sized { diff --git a/tests/ui/wrong_self_convention2.stderr b/tests/ui/wrong_self_convention2.stderr index 8de10e7be69c0..0069059203bf9 100644 --- a/tests/ui/wrong_self_convention2.stderr +++ b/tests/ui/wrong_self_convention2.stderr @@ -8,7 +8,7 @@ LL | pub fn from_be_self(self) -> Self { = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention2.rs:63:25 + --> $DIR/wrong_self_convention2.rs:64:25 | LL | fn from_be_self(self) -> Self; | ^^^^ diff --git a/tests/ui/wrong_self_conventions_mut.rs b/tests/ui/wrong_self_conventions_mut.rs index 5bb2116bd339a..9169fc6d71f6a 100644 --- a/tests/ui/wrong_self_conventions_mut.rs +++ b/tests/ui/wrong_self_conventions_mut.rs @@ -12,6 +12,7 @@ mod issue6758 { impl Test { // If a method starts with `to_` and not ends with `_mut` it should expect `&self` pub fn to_many(&mut self) -> Option<&mut [T]> { + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is match self { Self::Many(data) => Some(data), _ => None, @@ -20,6 +21,7 @@ mod issue6758 { // If a method starts with `to_` and ends with `_mut` it should expect `&mut self` pub fn to_many_mut(&self) -> Option<&[T]> { + //~^ ERROR: methods with the following characteristics: (`to_*` and `*_mut`) usual match self { Self::Many(data) => Some(data), _ => None, diff --git a/tests/ui/wrong_self_conventions_mut.stderr b/tests/ui/wrong_self_conventions_mut.stderr index 3d009083cee3e..cd7a9aae144e2 100644 --- a/tests/ui/wrong_self_conventions_mut.stderr +++ b/tests/ui/wrong_self_conventions_mut.stderr @@ -8,7 +8,7 @@ LL | pub fn to_many(&mut self) -> Option<&mut [T]> { = note: `-D clippy::wrong-self-convention` implied by `-D warnings` error: methods with the following characteristics: (`to_*` and `*_mut`) usually take `self` by mutable reference - --> $DIR/wrong_self_conventions_mut.rs:22:28 + --> $DIR/wrong_self_conventions_mut.rs:23:28 | LL | pub fn to_many_mut(&self) -> Option<&[T]> { | ^^^^^ diff --git a/tests/ui/zero_div_zero.rs b/tests/ui/zero_div_zero.rs index 968c58f40aefa..340ed5ef1339d 100644 --- a/tests/ui/zero_div_zero.rs +++ b/tests/ui/zero_div_zero.rs @@ -2,9 +2,13 @@ #[warn(clippy::zero_divided_by_zero)] fn main() { let nan = 0.0 / 0.0; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let f64_nan = 0.0 / 0.0f64; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let other_f64_nan = 0.0f64 / 0.0; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let one_more_f64_nan = 0.0f64 / 0.0f64; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let zero = 0.0; let other_zero = 0.0; let other_nan = zero / other_zero; // fine - this lint doesn't propagate constants. diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr index 2793d16064459..cde6bc907c683 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -8,7 +8,7 @@ LL | let nan = 0.0 / 0.0; = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings` error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:5:19 + --> $DIR/zero_div_zero.rs:6:19 | LL | let f64_nan = 0.0 / 0.0f64; | ^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let f64_nan = 0.0 / 0.0f64; = help: consider using `f64::NAN` if you would like a constant representing NaN error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:6:25 + --> $DIR/zero_div_zero.rs:8:25 | LL | let other_f64_nan = 0.0f64 / 0.0; | ^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let other_f64_nan = 0.0f64 / 0.0; = help: consider using `f64::NAN` if you would like a constant representing NaN error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:7:28 + --> $DIR/zero_div_zero.rs:10:28 | LL | let one_more_f64_nan = 0.0f64 / 0.0f64; | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/zero_offset.rs b/tests/ui/zero_offset.rs index fd9ac1fa7663b..c7a69dee4b2de 100644 --- a/tests/ui/zero_offset.rs +++ b/tests/ui/zero_offset.rs @@ -3,15 +3,24 @@ fn main() { unsafe { let m = &mut () as *mut (); m.offset(0); + //~^ ERROR: offset calculation on zero-sized value + //~| NOTE: `#[deny(clippy::zst_offset)]` on by default m.wrapping_add(0); + //~^ ERROR: offset calculation on zero-sized value m.sub(0); + //~^ ERROR: offset calculation on zero-sized value m.wrapping_sub(0); + //~^ ERROR: offset calculation on zero-sized value let c = &() as *const (); c.offset(0); + //~^ ERROR: offset calculation on zero-sized value c.wrapping_add(0); + //~^ ERROR: offset calculation on zero-sized value c.sub(0); + //~^ ERROR: offset calculation on zero-sized value c.wrapping_sub(0); + //~^ ERROR: offset calculation on zero-sized value let sized = &1 as *const i32; sized.offset(0); diff --git a/tests/ui/zero_offset.stderr b/tests/ui/zero_offset.stderr index 481a446571ab0..bb616f456ae14 100644 --- a/tests/ui/zero_offset.stderr +++ b/tests/ui/zero_offset.stderr @@ -7,43 +7,43 @@ LL | m.offset(0); = note: `#[deny(clippy::zst_offset)]` on by default error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:6:9 + --> $DIR/zero_offset.rs:8:9 | LL | m.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:7:9 + --> $DIR/zero_offset.rs:10:9 | LL | m.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:8:9 + --> $DIR/zero_offset.rs:12:9 | LL | m.wrapping_sub(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:11:9 + --> $DIR/zero_offset.rs:16:9 | LL | c.offset(0); | ^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:12:9 + --> $DIR/zero_offset.rs:18:9 | LL | c.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:13:9 + --> $DIR/zero_offset.rs:20:9 | LL | c.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:14:9 + --> $DIR/zero_offset.rs:22:9 | LL | c.wrapping_sub(0); | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/zero_sized_btreemap_values.rs b/tests/ui/zero_sized_btreemap_values.rs index 5cd254787d834..565f639201ff7 100644 --- a/tests/ui/zero_sized_btreemap_values.rs +++ b/tests/ui/zero_sized_btreemap_values.rs @@ -3,23 +3,28 @@ use std::collections::BTreeMap; const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type type OkMap = BTreeMap; type NotOkMap = BTreeMap; +//~^ ERROR: map with zero-sized value type enum TestEnum { Ok(BTreeMap), NotOk(BTreeMap), + //~^ ERROR: map with zero-sized value type } struct Test { ok: BTreeMap, not_ok: BTreeMap, - + //~^ ERROR: map with zero-sized value type also_not_ok: Vec>, + //~^ ERROR: map with zero-sized value type } trait TestTrait { @@ -28,6 +33,7 @@ trait TestTrait { fn produce_output() -> Self::Output; fn weird_map(&self, map: BTreeMap); + //~^ ERROR: map with zero-sized value type } impl Test { @@ -36,6 +42,7 @@ impl Test { } fn not_ok(&self) -> BTreeMap { + //~^ ERROR: map with zero-sized value type todo!() } } @@ -53,6 +60,8 @@ impl TestTrait for Test { } fn test(map: BTreeMap, key: &str) -> BTreeMap { + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type todo!(); } @@ -62,7 +71,10 @@ fn test2(map: BTreeMap, key: &str) -> BTreeMap { fn main() { let _: BTreeMap = BTreeMap::new(); + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type let _: BTreeMap = BTreeMap::new(); let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); + //~^ ERROR: map with zero-sized value type } diff --git a/tests/ui/zero_sized_btreemap_values.stderr b/tests/ui/zero_sized_btreemap_values.stderr index c6ba6fa76f057..de122473fd26d 100644 --- a/tests/ui/zero_sized_btreemap_values.stderr +++ b/tests/ui/zero_sized_btreemap_values.stderr @@ -8,7 +8,7 @@ LL | const CONST_NOT_OK: Option> = None; = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:8:30 + --> $DIR/zero_sized_btreemap_values.rs:9:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:11:17 + --> $DIR/zero_sized_btreemap_values.rs:13:17 | LL | type NotOkMap = BTreeMap; | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | type NotOkMap = BTreeMap; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:15:11 + --> $DIR/zero_sized_btreemap_values.rs:18:11 | LL | NotOk(BTreeMap), | ^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | NotOk(BTreeMap), = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:20:13 + --> $DIR/zero_sized_btreemap_values.rs:24:13 | LL | not_ok: BTreeMap, | ^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | not_ok: BTreeMap, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:22:22 + --> $DIR/zero_sized_btreemap_values.rs:26:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:30:30 + --> $DIR/zero_sized_btreemap_values.rs:35:30 | LL | fn weird_map(&self, map: BTreeMap); | ^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | fn weird_map(&self, map: BTreeMap); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:38:25 + --> $DIR/zero_sized_btreemap_values.rs:44:25 | LL | fn not_ok(&self) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | fn not_ok(&self) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:55:14 + --> $DIR/zero_sized_btreemap_values.rs:62:14 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:55:50 + --> $DIR/zero_sized_btreemap_values.rs:62:50 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:64:35 + --> $DIR/zero_sized_btreemap_values.rs:73:35 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^ @@ -88,7 +88,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:64:12 + --> $DIR/zero_sized_btreemap_values.rs:73:12 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:67:12 + --> $DIR/zero_sized_btreemap_values.rs:78:12 | LL | let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); | ^^^^^^^^^^^^^^ diff --git a/tests/ui/zero_sized_hashmap_values.rs b/tests/ui/zero_sized_hashmap_values.rs index a1608d863fb52..5498261ee95a0 100644 --- a/tests/ui/zero_sized_hashmap_values.rs +++ b/tests/ui/zero_sized_hashmap_values.rs @@ -3,23 +3,28 @@ use std::collections::HashMap; const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type type OkMap = HashMap; type NotOkMap = HashMap; +//~^ ERROR: map with zero-sized value type enum TestEnum { Ok(HashMap), NotOk(HashMap), + //~^ ERROR: map with zero-sized value type } struct Test { ok: HashMap, not_ok: HashMap, - + //~^ ERROR: map with zero-sized value type also_not_ok: Vec>, + //~^ ERROR: map with zero-sized value type } trait TestTrait { @@ -28,6 +33,7 @@ trait TestTrait { fn produce_output() -> Self::Output; fn weird_map(&self, map: HashMap); + //~^ ERROR: map with zero-sized value type } impl Test { @@ -36,6 +42,7 @@ impl Test { } fn not_ok(&self) -> HashMap { + //~^ ERROR: map with zero-sized value type todo!() } } @@ -53,6 +60,8 @@ impl TestTrait for Test { } fn test(map: HashMap, key: &str) -> HashMap { + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type todo!(); } @@ -62,7 +71,10 @@ fn test2(map: HashMap, key: &str) -> HashMap { fn main() { let _: HashMap = HashMap::new(); + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type let _: HashMap = HashMap::new(); let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); + //~^ ERROR: map with zero-sized value type } diff --git a/tests/ui/zero_sized_hashmap_values.stderr b/tests/ui/zero_sized_hashmap_values.stderr index 75bdeb42ec0d4..0d489f45aca16 100644 --- a/tests/ui/zero_sized_hashmap_values.stderr +++ b/tests/ui/zero_sized_hashmap_values.stderr @@ -8,7 +8,7 @@ LL | const CONST_NOT_OK: Option> = None; = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:8:30 + --> $DIR/zero_sized_hashmap_values.rs:9:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:11:17 + --> $DIR/zero_sized_hashmap_values.rs:13:17 | LL | type NotOkMap = HashMap; | ^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | type NotOkMap = HashMap; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:15:11 + --> $DIR/zero_sized_hashmap_values.rs:18:11 | LL | NotOk(HashMap), | ^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | NotOk(HashMap), = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:20:13 + --> $DIR/zero_sized_hashmap_values.rs:24:13 | LL | not_ok: HashMap, | ^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | not_ok: HashMap, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:22:22 + --> $DIR/zero_sized_hashmap_values.rs:26:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:30:30 + --> $DIR/zero_sized_hashmap_values.rs:35:30 | LL | fn weird_map(&self, map: HashMap); | ^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | fn weird_map(&self, map: HashMap); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:38:25 + --> $DIR/zero_sized_hashmap_values.rs:44:25 | LL | fn not_ok(&self) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | fn not_ok(&self) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:55:14 + --> $DIR/zero_sized_hashmap_values.rs:62:14 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:55:49 + --> $DIR/zero_sized_hashmap_values.rs:62:49 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:64:34 + --> $DIR/zero_sized_hashmap_values.rs:73:34 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^ @@ -88,7 +88,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:64:12 + --> $DIR/zero_sized_hashmap_values.rs:73:12 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:67:12 + --> $DIR/zero_sized_hashmap_values.rs:78:12 | LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); | ^^^^^^^^^^^^^ From f4670121d54bb8eb40a69cc75ce96194d4af4b98 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 11 Aug 2023 13:53:23 +0200 Subject: [PATCH 63/79] Move code comments to prevent having weird clippy fmt issues --- tests/ui/const_comparisons.rs | 39 +++++++++----- tests/ui/const_comparisons.stderr | 86 +++++++++++++++---------------- 2 files changed, 69 insertions(+), 56 deletions(-) diff --git a/tests/ui/const_comparisons.rs b/tests/ui/const_comparisons.rs index c0403758f1bb9..0898b4ebd4657 100644 --- a/tests/ui/const_comparisons.rs +++ b/tests/ui/const_comparisons.rs @@ -40,7 +40,8 @@ fn main() { let status_code = 500; // Value doesn't matter for the lint let status = Status { code: status_code }; - status_code >= 400 && status_code < 500; // Correct + // Correct + status_code >= 400 && status_code < 500; status_code <= 400 && status_code > 500; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `400` < `500`, the expression evaluates to false for any value of `st @@ -80,22 +81,30 @@ fn main() { //~| NOTE: `status` cannot simultaneously be greater than and less than `STATUS_SERVER // Yoda conditions - 500 <= status_code && 600 > status_code; // Correct - 500 <= status_code && status_code <= 600; // Correct - 500 >= status_code && 600 < status_code; // Incorrect + // Correct + 500 <= status_code && 600 > status_code; + // Correct + 500 <= status_code && status_code <= 600; + // Incorrect + 500 >= status_code && 600 < status_code; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st - 500 >= status_code && status_code > 600; // Incorrect + // Incorrect + 500 >= status_code && status_code > 600; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st // Yoda conditions, comparing two different types - 500 <= status && 600 > status; // Correct - 500 <= status && status <= 600; // Correct - 500 >= status && 600 < status; // Incorrect + // Correct + 500 <= status && 600 > status; + // Correct + 500 <= status && status <= 600; + // Incorrect + 500 >= status && 600 < status; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st - 500 >= status && status > 600; // Incorrect + // Incorrect + 500 >= status && status > 600; //~^ ERROR: boolean expression will never evaluate to 'true' //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st @@ -105,13 +114,17 @@ fn main() { status_code > 200 && status_code >= 299; //~^ ERROR: left-hand side of `&&` operator has no effect - status_code >= 500 && status_code > 500; // Useless left + // Useless left + status_code >= 500 && status_code > 500; //~^ ERROR: left-hand side of `&&` operator has no effect - status_code > 500 && status_code >= 500; // Useless right + // Useless right + status_code > 500 && status_code >= 500; //~^ ERROR: right-hand side of `&&` operator has no effect - status_code <= 500 && status_code < 500; // Useless left + // Useless left + status_code <= 500 && status_code < 500; //~^ ERROR: left-hand side of `&&` operator has no effect - status_code < 500 && status_code <= 500; // Useless right + // Useless right + status_code < 500 && status_code <= 500; //~^ ERROR: right-hand side of `&&` operator has no effect // Other types diff --git a/tests/ui/const_comparisons.stderr b/tests/ui/const_comparisons.stderr index e319ce8d17b89..8c920d36896d6 100644 --- a/tests/ui/const_comparisons.stderr +++ b/tests/ui/const_comparisons.stderr @@ -1,5 +1,5 @@ error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:44:5 + --> $DIR/const_comparisons.rs:45:5 | LL | status_code <= 400 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | status_code <= 400 && status_code > 500; = note: `-D clippy::impossible-comparisons` implied by `-D warnings` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:47:5 + --> $DIR/const_comparisons.rs:48:5 | LL | status_code > 500 && status_code < 400; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | status_code > 500 && status_code < 400; = note: since `500` > `400`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:50:5 + --> $DIR/const_comparisons.rs:51:5 | LL | status_code < 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | status_code < 500 && status_code > 500; = note: `status_code` cannot simultaneously be greater than and less than `500` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:55:5 + --> $DIR/const_comparisons.rs:56:5 | LL | status_code < { 400 } && status_code > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | status_code < { 400 } && status_code > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:58:5 + --> $DIR/const_comparisons.rs:59:5 | LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:61:5 + --> $DIR/const_comparisons.rs:62:5 | LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:64:5 + --> $DIR/const_comparisons.rs:65:5 | LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; = note: `status_code` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:69:5 + --> $DIR/const_comparisons.rs:70:5 | LL | status < { 400 } && status > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | status < { 400 } && status > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:72:5 + --> $DIR/const_comparisons.rs:73:5 | LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:75:5 + --> $DIR/const_comparisons.rs:76:5 | LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:78:5 + --> $DIR/const_comparisons.rs:79:5 | LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,112 +88,112 @@ LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; = note: `status` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:85:5 + --> $DIR/const_comparisons.rs:89:5 | -LL | 500 >= status_code && 600 < status_code; // Incorrect +LL | 500 >= status_code && 600 < status_code; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:88:5 + --> $DIR/const_comparisons.rs:93:5 | -LL | 500 >= status_code && status_code > 600; // Incorrect +LL | 500 >= status_code && status_code > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:95:5 + --> $DIR/const_comparisons.rs:103:5 | -LL | 500 >= status && 600 < status; // Incorrect +LL | 500 >= status && 600 < status; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:98:5 + --> $DIR/const_comparisons.rs:107:5 | -LL | 500 >= status && status > 600; // Incorrect +LL | 500 >= status && status > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:103:5 + --> $DIR/const_comparisons.rs:112:5 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 200` evaluates to true, status_code <= 299` will always evaluate to true as well - --> $DIR/const_comparisons.rs:103:23 + --> $DIR/const_comparisons.rs:112:23 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-comparisons` implied by `-D warnings` error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:105:5 + --> $DIR/const_comparisons.rs:114:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code >= 299` evaluates to true, status_code > 200` will always evaluate to true as well - --> $DIR/const_comparisons.rs:105:5 + --> $DIR/const_comparisons.rs:114:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:108:5 + --> $DIR/const_comparisons.rs:118:5 | -LL | status_code >= 500 && status_code > 500; // Useless left +LL | status_code >= 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:108:5 + --> $DIR/const_comparisons.rs:118:5 | -LL | status_code >= 500 && status_code > 500; // Useless left +LL | status_code >= 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:110:5 + --> $DIR/const_comparisons.rs:121:5 | -LL | status_code > 500 && status_code >= 500; // Useless right +LL | status_code > 500 && status_code >= 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:110:23 + --> $DIR/const_comparisons.rs:121:23 | -LL | status_code > 500 && status_code >= 500; // Useless right +LL | status_code > 500 && status_code >= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:112:5 + --> $DIR/const_comparisons.rs:124:5 | -LL | status_code <= 500 && status_code < 500; // Useless left +LL | status_code <= 500 && status_code < 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:112:5 + --> $DIR/const_comparisons.rs:124:5 | -LL | status_code <= 500 && status_code < 500; // Useless left +LL | status_code <= 500 && status_code < 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:114:5 + --> $DIR/const_comparisons.rs:127:5 | -LL | status_code < 500 && status_code <= 500; // Useless right +LL | status_code < 500 && status_code <= 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:114:23 + --> $DIR/const_comparisons.rs:127:23 | -LL | status_code < 500 && status_code <= 500; // Useless right +LL | status_code < 500 && status_code <= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:119:5 + --> $DIR/const_comparisons.rs:132:5 | LL | name < "Jennifer" && name > "Shannon"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -201,7 +201,7 @@ LL | name < "Jennifer" && name > "Shannon"; = note: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any value of `name` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:124:5 + --> $DIR/const_comparisons.rs:137:5 | LL | numbers < [3, 4] && numbers > [5, 6]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | numbers < [3, 4] && numbers > [5, 6]; = note: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value of `numbers` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:129:5 + --> $DIR/const_comparisons.rs:142:5 | LL | letter < 'b' && letter > 'c'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL | letter < 'b' && letter > 'c'; = note: since `'b'` < `'c'`, the expression evaluates to false for any value of `letter` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:134:5 + --> $DIR/const_comparisons.rs:147:5 | LL | area < std::f32::consts::E && area > std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From df8bb47f1711d0db0dd6e9e8446b15b394721126 Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Tue, 22 Aug 2023 18:46:16 +0200 Subject: [PATCH 64/79] Improved snippets and added tests --- .../src/reserve_after_initialization.rs | 36 ++++++------- tests/ui/reserve_after_initialization.fixed | 51 +++++++++++++++--- tests/ui/reserve_after_initialization.rs | 52 ++++++++++++++++--- tests/ui/reserve_after_initialization.stderr | 21 +++++--- 4 files changed, 122 insertions(+), 38 deletions(-) diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index d530d5758b1f5..17ca9c8aab87f 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -2,7 +2,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::higher::{get_vec_init_kind, VecInitKind}; use clippy_utils::path_to_local_id; use clippy_utils::source::snippet; -//use rustc_ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Local, PatKind, QPath, Stmt, StmtKind}; @@ -16,7 +15,7 @@ declare_clippy_lint! { /// Informs the user about a more concise way to create a vector with a known capacity. /// /// ### Why is this bad? - /// The `Vec::with_capacity` constructor is easier to understand. + /// The `Vec::with_capacity` constructor is less complex. /// /// ### Example /// ```rust @@ -51,14 +50,14 @@ impl VecReserveSearcher { return; } - let s = format!("{} = Vec::with_capacity({});", self.init_part, self.space_hint); + let s = format!("{}Vec::with_capacity({});", self.init_part, self.space_hint); span_lint_and_sugg( cx, RESERVE_AFTER_INITIALIZATION, self.err_span, - "calls to `reverse` immediately after creation", - "consider using `Vec::with_capacity(space_hint)`", + "call to `reserve` immediately after creation", + "consider using `Vec::with_capacity(/* Space hint */)`", s, Applicability::HasPlaceholders, ); @@ -72,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { if let Some(init_expr) = local.init - && let PatKind::Binding(BindingAnnotation::MUT, id, _name, None) = local.pat.kind + && let PatKind::Binding(BindingAnnotation::MUT, id, _, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) && let Some(init) = get_vec_init_kind(cx, init_expr) && !matches!(init, VecInitKind::WithExprCapacity(_)) @@ -81,12 +80,9 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { self.searcher = Some(VecReserveSearcher { local_id: id, err_span: local.span, - init_part: format!("let {}: {}", - snippet(cx, local.pat.span, ""), - match local.ty { - Some(type_inference) => snippet(cx, type_inference.span, "").to_string(), - None => String::new() - }), + init_part: snippet(cx, local.span.shrink_to_lo() + .to(init_expr.span.source_callsite().shrink_to_lo()), "..") + .into_owned(), space_hint: String::new() }); } @@ -96,17 +92,20 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { if self.searcher.is_none() && let ExprKind::Assign(left, right, _) = expr.kind && let ExprKind::Path(QPath::Resolved(None, path)) = left.kind - && let [_name] = &path.segments + && let [_] = &path.segments && let Res::Local(id) = path.res && !in_external_macro(cx.sess(), expr.span) && let Some(init) = get_vec_init_kind(cx, right) - && !matches!(init, VecInitKind::WithExprCapacity(_)) - && !matches!(init, VecInitKind::WithConstCapacity(_)) + && !matches!(init, VecInitKind::WithExprCapacity(_) + | VecInitKind::WithConstCapacity(_) + ) { self.searcher = Some(VecReserveSearcher { local_id: id, err_span: expr.span, - init_part: snippet(cx, left.span, "").to_string(), + init_part: snippet(cx, left.span.shrink_to_lo() + .to(right.span.source_callsite().shrink_to_lo()), "..") + .into_owned(), // see `assign_expression` test space_hint: String::new() }); } @@ -115,14 +114,13 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { 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 - && let ExprKind::MethodCall(name, self_arg, other_args, _) = expr.kind - && other_args.len() == 1 + && let ExprKind::MethodCall(name, self_arg, [space_hint], _) = expr.kind && path_to_local_id(self_arg, searcher.local_id) && name.ident.as_str() == "reserve" { self.searcher = Some(VecReserveSearcher { err_span: searcher.err_span.to(stmt.span), - space_hint: snippet(cx, other_args[0].span, "").to_string(), + space_hint: snippet(cx, space_hint.span, "..").to_string(), .. searcher }); } else { diff --git a/tests/ui/reserve_after_initialization.fixed b/tests/ui/reserve_after_initialization.fixed index e7dd8f6b14fbb..5ef848ed8cf43 100644 --- a/tests/ui/reserve_after_initialization.fixed +++ b/tests/ui/reserve_after_initialization.fixed @@ -1,17 +1,56 @@ #![warn(clippy::reserve_after_initialization)] +#![no_main] -fn main() { - // Should lint +// Should lint +fn standard() { let mut v1: Vec = Vec::with_capacity(10); +} - // Should lint +// Should lint +fn capacity_as_expr() { let capacity = 10; let mut v2: Vec = Vec::with_capacity(capacity); +} - // Shouldn't lint +// Shouldn't lint +fn vec_init_with_argument() { let mut v3 = vec![1]; v3.reserve(10); +} + +// Shouldn't lint +fn called_with_capacity() { + let _v4: Vec = Vec::with_capacity(10); +} - // Shouldn't lint - let mut v4: Vec = Vec::with_capacity(10); +// Should lint +fn assign_expression() { + let mut v5: Vec = Vec::new(); + v5 = Vec::with_capacity(10); } + +/*fn in_macros() { + external! { + // Should lint + let mut v1: Vec = vec![]; + v1.reserve(10); + + // Should lint + let capacity = 10; + let mut v2: Vec = vec![]; + v2.reserve(capacity); + } + + with_span! { + span + + // Should lint + let mut v1: Vec = vec![]; + v1.reserve(10); + + // Should lint + let capacity = 10; + let mut v2: Vec = vec![]; + v2.reserve(capacity); + } +}*/ diff --git a/tests/ui/reserve_after_initialization.rs b/tests/ui/reserve_after_initialization.rs index 07f9377dbfe20..eba7bc8dab333 100644 --- a/tests/ui/reserve_after_initialization.rs +++ b/tests/ui/reserve_after_initialization.rs @@ -1,19 +1,59 @@ #![warn(clippy::reserve_after_initialization)] +#![no_main] -fn main() { - // Should lint +// Should lint +fn standard() { let mut v1: Vec = vec![]; v1.reserve(10); +} - // Should lint +// Should lint +fn capacity_as_expr() { let capacity = 10; let mut v2: Vec = vec![]; v2.reserve(capacity); +} - // Shouldn't lint +// Shouldn't lint +fn vec_init_with_argument() { let mut v3 = vec![1]; v3.reserve(10); +} + +// Shouldn't lint +fn called_with_capacity() { + let _v4: Vec = Vec::with_capacity(10); +} - // Shouldn't lint - let mut v4: Vec = Vec::with_capacity(10); +// Should lint +fn assign_expression() { + let mut v5: Vec = Vec::new(); + v5 = Vec::new(); + v5.reserve(10); } + +/*fn in_macros() { + external! { + // Should lint + let mut v1: Vec = vec![]; + v1.reserve(10); + + // Should lint + let capacity = 10; + let mut v2: Vec = vec![]; + v2.reserve(capacity); + } + + with_span! { + span + + // Should lint + let mut v1: Vec = vec![]; + v1.reserve(10); + + // Should lint + let capacity = 10; + let mut v2: Vec = vec![]; + v2.reserve(capacity); + } +}*/ diff --git a/tests/ui/reserve_after_initialization.stderr b/tests/ui/reserve_after_initialization.stderr index ab2753cdd6005..e50a8a065ba6e 100644 --- a/tests/ui/reserve_after_initialization.stderr +++ b/tests/ui/reserve_after_initialization.stderr @@ -1,18 +1,25 @@ -error: calls to `reverse` immediately after creation - --> $DIR/reserve_after_initialization.rs:5:5 +error: call to `reserve` immediately after creation + --> $DIR/reserve_after_initialization.rs:6:5 | LL | / let mut v1: Vec = vec![]; LL | | v1.reserve(10); - | |___________________^ help: consider using `Vec::with_capacity(space_hint)`: `let mut v1: Vec = Vec::with_capacity(10);` + | |___________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v1: Vec = Vec::with_capacity(10);` | = note: `-D clippy::reserve-after-initialization` implied by `-D warnings` -error: calls to `reverse` immediately after creation - --> $DIR/reserve_after_initialization.rs:10:5 +error: call to `reserve` immediately after creation + --> $DIR/reserve_after_initialization.rs:13:5 | LL | / let mut v2: Vec = vec![]; LL | | v2.reserve(capacity); - | |_________________________^ help: consider using `Vec::with_capacity(space_hint)`: `let mut v2: Vec = Vec::with_capacity(capacity);` + | |_________________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v2: Vec = Vec::with_capacity(capacity);` -error: aborting due to 2 previous errors +error: call to `reserve` immediately after creation + --> $DIR/reserve_after_initialization.rs:31:5 + | +LL | / v5 = Vec::new(); +LL | | v5.reserve(10); + | |___________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `v5 = Vec::with_capacity(10);` + +error: aborting due to 3 previous errors From 7977d209b27c14769c8e50b5f189cd27a716be3e Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Tue, 22 Aug 2023 19:36:58 +0200 Subject: [PATCH 65/79] Do not lint inside macros --- .../src/reserve_after_initialization.rs | 8 ++++-- tests/ui/reserve_after_initialization.fixed | 28 +++++++------------ tests/ui/reserve_after_initialization.rs | 28 +++++++------------ tests/ui/reserve_after_initialization.stderr | 6 ++-- 4 files changed, 28 insertions(+), 42 deletions(-) diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index 17ca9c8aab87f..15f8c5da10606 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::higher::{get_vec_init_kind, VecInitKind}; -use clippy_utils::path_to_local_id; use clippy_utils::source::snippet; +use clippy_utils::{is_from_proc_macro, path_to_local_id}; use rustc_errors::Applicability; use rustc_hir::def::Res; use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Local, PatKind, QPath, Stmt, StmtKind}; @@ -74,8 +74,9 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { && let PatKind::Binding(BindingAnnotation::MUT, id, _, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) && let Some(init) = get_vec_init_kind(cx, init_expr) - && !matches!(init, VecInitKind::WithExprCapacity(_)) - && !matches!(init, VecInitKind::WithConstCapacity(_)) + && !matches!(init, VecInitKind::WithExprCapacity(_) + | VecInitKind::WithConstCapacity(_) + ) { self.searcher = Some(VecReserveSearcher { local_id: id, @@ -116,6 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind && let ExprKind::MethodCall(name, self_arg, [space_hint], _) = expr.kind && path_to_local_id(self_arg, searcher.local_id) + && !is_from_proc_macro(cx, expr) && name.ident.as_str() == "reserve" { self.searcher = Some(VecReserveSearcher { diff --git a/tests/ui/reserve_after_initialization.fixed b/tests/ui/reserve_after_initialization.fixed index 5ef848ed8cf43..0675277849ad7 100644 --- a/tests/ui/reserve_after_initialization.fixed +++ b/tests/ui/reserve_after_initialization.fixed @@ -1,6 +1,10 @@ +//@aux-build:proc_macros.rs #![warn(clippy::reserve_after_initialization)] #![no_main] +extern crate proc_macros; +use proc_macros::{external, with_span}; + // Should lint fn standard() { let mut v1: Vec = Vec::with_capacity(10); @@ -29,28 +33,16 @@ fn assign_expression() { v5 = Vec::with_capacity(10); } -/*fn in_macros() { +fn in_macros() { external! { - // Should lint - let mut v1: Vec = vec![]; - v1.reserve(10); - - // Should lint - let capacity = 10; - let mut v2: Vec = vec![]; - v2.reserve(capacity); + let mut v: Vec = vec![]; + v.reserve(10); } with_span! { span - // Should lint - let mut v1: Vec = vec![]; - v1.reserve(10); - - // Should lint - let capacity = 10; - let mut v2: Vec = vec![]; - v2.reserve(capacity); + let mut v: Vec = vec![]; + v.reserve(10); } -}*/ +} diff --git a/tests/ui/reserve_after_initialization.rs b/tests/ui/reserve_after_initialization.rs index eba7bc8dab333..b57a8e162c539 100644 --- a/tests/ui/reserve_after_initialization.rs +++ b/tests/ui/reserve_after_initialization.rs @@ -1,6 +1,10 @@ +//@aux-build:proc_macros.rs #![warn(clippy::reserve_after_initialization)] #![no_main] +extern crate proc_macros; +use proc_macros::{external, with_span}; + // Should lint fn standard() { let mut v1: Vec = vec![]; @@ -32,28 +36,16 @@ fn assign_expression() { v5.reserve(10); } -/*fn in_macros() { +fn in_macros() { external! { - // Should lint - let mut v1: Vec = vec![]; - v1.reserve(10); - - // Should lint - let capacity = 10; - let mut v2: Vec = vec![]; - v2.reserve(capacity); + let mut v: Vec = vec![]; + v.reserve(10); } with_span! { span - // Should lint - let mut v1: Vec = vec![]; - v1.reserve(10); - - // Should lint - let capacity = 10; - let mut v2: Vec = vec![]; - v2.reserve(capacity); + let mut v: Vec = vec![]; + v.reserve(10); } -}*/ +} diff --git a/tests/ui/reserve_after_initialization.stderr b/tests/ui/reserve_after_initialization.stderr index e50a8a065ba6e..4a6164d8ebc94 100644 --- a/tests/ui/reserve_after_initialization.stderr +++ b/tests/ui/reserve_after_initialization.stderr @@ -1,5 +1,5 @@ error: call to `reserve` immediately after creation - --> $DIR/reserve_after_initialization.rs:6:5 + --> $DIR/reserve_after_initialization.rs:10:5 | LL | / let mut v1: Vec = vec![]; LL | | v1.reserve(10); @@ -8,14 +8,14 @@ LL | | v1.reserve(10); = note: `-D clippy::reserve-after-initialization` implied by `-D warnings` error: call to `reserve` immediately after creation - --> $DIR/reserve_after_initialization.rs:13:5 + --> $DIR/reserve_after_initialization.rs:17:5 | LL | / let mut v2: Vec = vec![]; LL | | v2.reserve(capacity); | |_________________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v2: Vec = Vec::with_capacity(capacity);` error: call to `reserve` immediately after creation - --> $DIR/reserve_after_initialization.rs:31:5 + --> $DIR/reserve_after_initialization.rs:35:5 | LL | / v5 = Vec::new(); LL | | v5.reserve(10); From e9a222beb5153024c0c0f2491274272ab00c7d7a Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Tue, 22 Aug 2023 23:41:06 +0200 Subject: [PATCH 66/79] Minor changes --- clippy_lints/src/reserve_after_initialization.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index 15f8c5da10606..7ba10c975950f 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -74,9 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { && let PatKind::Binding(BindingAnnotation::MUT, id, _, None) = local.pat.kind && !in_external_macro(cx.sess(), local.span) && let Some(init) = get_vec_init_kind(cx, init_expr) - && !matches!(init, VecInitKind::WithExprCapacity(_) - | VecInitKind::WithConstCapacity(_) - ) + && !matches!(init, VecInitKind::WithExprCapacity(_) | VecInitKind::WithConstCapacity(_)) { self.searcher = Some(VecReserveSearcher { local_id: id, @@ -93,13 +91,10 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { if self.searcher.is_none() && let ExprKind::Assign(left, right, _) = expr.kind && let ExprKind::Path(QPath::Resolved(None, path)) = left.kind - && let [_] = &path.segments && let Res::Local(id) = path.res && !in_external_macro(cx.sess(), expr.span) && let Some(init) = get_vec_init_kind(cx, right) - && !matches!(init, VecInitKind::WithExprCapacity(_) - | VecInitKind::WithConstCapacity(_) - ) + && !matches!(init, VecInitKind::WithExprCapacity(_) | VecInitKind::WithConstCapacity(_)) { self.searcher = Some(VecReserveSearcher { local_id: id, @@ -122,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { { self.searcher = Some(VecReserveSearcher { err_span: searcher.err_span.to(stmt.span), - space_hint: snippet(cx, space_hint.span, "..").to_string(), + space_hint: snippet(cx, space_hint.span, "..").into_owned(), .. searcher }); } else { From 32eecd4b884dd2901aad05d66d78ea643a896e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 23 Aug 2023 00:58:09 +0000 Subject: [PATCH 67/79] Fix clippy lint for identical `if`/`else` contraining `?` expressions Follow up to #114819. --- clippy_utils/src/hir_utils.rs | 3 ++- tests/ui/if_same_then_else2.rs | 2 +- tests/ui/if_same_then_else2.stderr | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index fdc35cd4ddf8b..98441e83eb4ad 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -10,6 +10,7 @@ use rustc_hir::{ GenericArgs, Guard, HirId, HirIdMap, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; +use rustc_hir::MatchSource::TryDesugar; use rustc_lexer::{tokenize, TokenKind}; use rustc_lint::LateContext; use rustc_middle::ty::TypeckResults; @@ -311,7 +312,7 @@ impl HirEqInterExpr<'_, '_, '_> { lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name) }, (&ExprKind::Match(le, la, ref ls), &ExprKind::Match(re, ra, ref rs)) => { - ls == rs + (ls == rs || (matches!((ls, rs), (TryDesugar(_), TryDesugar(_))))) && self.eq_expr(le, re) && over(la, ra, |l, r| { self.eq_pat(l.pat, r.pat) diff --git a/tests/ui/if_same_then_else2.rs b/tests/ui/if_same_then_else2.rs index c545434efe5b5..0b171f21d0cc4 100644 --- a/tests/ui/if_same_then_else2.rs +++ b/tests/ui/if_same_then_else2.rs @@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> { }; if true { - // FIXME: should emit "this `if` has identical blocks" + //~^ ERROR: this `if` has identical blocks Ok("foo")?; } else { Ok("foo")?; diff --git a/tests/ui/if_same_then_else2.stderr b/tests/ui/if_same_then_else2.stderr index 37fe787d1de3a..56e5f3e45b22c 100644 --- a/tests/ui/if_same_then_else2.stderr +++ b/tests/ui/if_same_then_else2.stderr @@ -82,6 +82,25 @@ LL | | f32::NAN LL | | }; | |_____^ +error: this `if` has identical blocks + --> $DIR/if_same_then_else2.rs:100:13 + | +LL | if true { + | _____________^ +LL | | +LL | | Ok("foo")?; +LL | | } else { + | |_____^ + | +note: same as this + --> $DIR/if_same_then_else2.rs:103:12 + | +LL | } else { + | ____________^ +LL | | Ok("foo")?; +LL | | } + | |_____^ + error: this `if` has identical blocks --> $DIR/if_same_then_else2.rs:124:20 | @@ -103,5 +122,5 @@ LL | | return Ok(&foo[0..]); LL | | } | |_____^ -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors From f0eaa662632c8e85b07063507930dc77fdd3e1e3 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Wed, 23 Aug 2023 09:54:50 +0400 Subject: [PATCH 68/79] Add a test for tuple_array_conversion --- tests/ui/tuple_array_conversions.rs | 5 +++++ tests/ui/tuple_array_conversions.stderr | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/ui/tuple_array_conversions.rs b/tests/ui/tuple_array_conversions.rs index ed21ee668e3a0..ca79cc104f223 100644 --- a/tests/ui/tuple_array_conversions.rs +++ b/tests/ui/tuple_array_conversions.rs @@ -82,6 +82,11 @@ fn main() { [a, c]; let [[a, b], [c, d]] = [[1, 2], [3, 4]]; (a, c); + // Array length is not usize (#11144) + fn generic_array_length() { + let src = [0; N]; + let dest: (u8,) = (src[0],); + } } #[clippy::msrv = "1.70.0"] diff --git a/tests/ui/tuple_array_conversions.stderr b/tests/ui/tuple_array_conversions.stderr index 50bdcf29d1fad..70c13d10fd875 100644 --- a/tests/ui/tuple_array_conversions.stderr +++ b/tests/ui/tuple_array_conversions.stderr @@ -64,7 +64,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 - --> $DIR/tuple_array_conversions.rs:99:13 + --> $DIR/tuple_array_conversions.rs:104:13 | LL | let x = (x[0], x[1]); | ^^^^^^^^^^^^ @@ -72,7 +72,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 - --> $DIR/tuple_array_conversions.rs:100:13 + --> $DIR/tuple_array_conversions.rs:105:13 | LL | let x = [x.0, x.1]; | ^^^^^^^^^^ From f3c58773026bf042142be2bf8ed1e8b8797a4f68 Mon Sep 17 00:00:00 2001 From: Red Rapious Date: Wed, 23 Aug 2023 13:46:12 +0200 Subject: [PATCH 69/79] Put `is_from_proc_macro` last --- clippy_lints/src/reserve_after_initialization.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/reserve_after_initialization.rs b/clippy_lints/src/reserve_after_initialization.rs index 7ba10c975950f..0c8c904e37454 100644 --- a/clippy_lints/src/reserve_after_initialization.rs +++ b/clippy_lints/src/reserve_after_initialization.rs @@ -112,8 +112,8 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization { if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind && let ExprKind::MethodCall(name, self_arg, [space_hint], _) = expr.kind && path_to_local_id(self_arg, searcher.local_id) - && !is_from_proc_macro(cx, expr) && name.ident.as_str() == "reserve" + && !is_from_proc_macro(cx, expr) { self.searcher = Some(VecReserveSearcher { err_span: searcher.err_span.to(stmt.span), From 42bd6d7af3b12366b6d063c2f5220323aee62efc Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Sun, 20 Aug 2023 01:20:29 +0200 Subject: [PATCH 70/79] new lint: `implied_bounds_in_impl` --- CHANGELOG.md | 1 + clippy_lints/src/declared_lints.rs | 1 + clippy_lints/src/implied_bounds_in_impl.rs | 96 ++++++++++++++++++++++ clippy_lints/src/lib.rs | 2 + tests/ui/implied_bounds_in_impl.rs | 45 ++++++++++ tests/ui/implied_bounds_in_impl.stderr | 16 ++++ 6 files changed, 161 insertions(+) create mode 100644 clippy_lints/src/implied_bounds_in_impl.rs create mode 100644 tests/ui/implied_bounds_in_impl.rs create mode 100644 tests/ui/implied_bounds_in_impl.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e33cb7b45707..1ae44c502dbb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4985,6 +4985,7 @@ Released 2018-09-13 [`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return [`implicit_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_add [`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub +[`implied_bounds_in_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#implied_bounds_in_impl [`impossible_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#impossible_comparisons [`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops [`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 1be9720fbbf8d..ea8d804b423d1 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -209,6 +209,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::implicit_return::IMPLICIT_RETURN_INFO, crate::implicit_saturating_add::IMPLICIT_SATURATING_ADD_INFO, crate::implicit_saturating_sub::IMPLICIT_SATURATING_SUB_INFO, + crate::implied_bounds_in_impl::IMPLIED_BOUNDS_IN_IMPL_INFO, crate::inconsistent_struct_constructor::INCONSISTENT_STRUCT_CONSTRUCTOR_INFO, crate::incorrect_impls::INCORRECT_CLONE_IMPL_ON_COPY_TYPE_INFO, crate::incorrect_impls::INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE_INFO, diff --git a/clippy_lints/src/implied_bounds_in_impl.rs b/clippy_lints/src/implied_bounds_in_impl.rs new file mode 100644 index 0000000000000..c83153e5350fb --- /dev/null +++ b/clippy_lints/src/implied_bounds_in_impl.rs @@ -0,0 +1,96 @@ +use clippy_utils::diagnostics::span_lint; +use rustc_hir::def_id::LocalDefId; +use rustc_hir::intravisit::FnKind; +use rustc_hir::{Body, FnDecl, FnRetTy, GenericArgs, GenericBound, ItemKind, TraitBoundModifier, TyKind}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::ClauseKind; +use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::Span; + +declare_clippy_lint! { + /// ### What it does + /// Looks for bounds in `impl Trait` in return position that are implied by other bounds. + /// This is usually the case when a supertrait is explicitly specified, when it is already implied + /// by a subtrait (e.g. `DerefMut: Deref`, so specifying `Deref` is unnecessary when `DerefMut` is specified). + /// + /// ### Why is this bad? + /// Unnecessary complexity. + /// + /// ### Known problems + /// This lint currently does not work with generic traits (i.e. will not lint even if redundant). + /// + /// ### Example + /// ```rust + /// fn f() -> impl Deref + DerefMut { + /// // ^^^^^^^^^^^^^^^^^^^ unnecessary bound, already implied by the `DerefMut` trait bound + /// Box::new(123) + /// } + /// ``` + /// Use instead: + /// ```rust + /// fn f() -> impl DerefMut { + /// Box::new(123) + /// } + /// ``` + #[clippy::version = "1.73.0"] + pub IMPLIED_BOUNDS_IN_IMPL, + complexity, + "specifying bounds that are implied by other bounds in `impl Trait` type" +} +declare_lint_pass!(ImpliedBoundsInImpl => [IMPLIED_BOUNDS_IN_IMPL]); + +impl LateLintPass<'_> for ImpliedBoundsInImpl { + fn check_fn( + &mut self, + cx: &LateContext<'_>, + _: FnKind<'_>, + decl: &FnDecl<'_>, + _: &Body<'_>, + _: Span, + _: LocalDefId, + ) { + if let FnRetTy::Return(ty) = decl.output { + if let TyKind::OpaqueDef(item_id, ..) = ty.kind + && let item = cx.tcx.hir().item(item_id) + && let ItemKind::OpaqueTy(opaque_ty) = item.kind + { + // Get all `DefId`s of (implied) trait predicates in all the bounds. + // For `impl Deref + DerefMut` this will contain [`Deref`]. + // The implied `Deref` comes from `DerefMut` because `trait DerefMut: Deref {}`. + + // N.B. Generic args on trait bounds are currently ignored and (G)ATs are fine to disregard, + // because they must be the same for all of its supertraits. Example: + // `impl Deref + DerefMut` is not allowed. + // `DerefMut::Target` needs to match `Deref::Target` + let implied_bounds = opaque_ty.bounds.iter().flat_map(|bound| { + if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound + && let [.., path] = poly_trait.trait_ref.path.segments + && poly_trait.bound_generic_params.is_empty() + && path.args.map_or(true, GenericArgs::is_empty) + && let Some(trait_def_id) = path.res.opt_def_id() + { + cx.tcx.implied_predicates_of(trait_def_id).predicates + } else { + &[] + } + }).collect::>(); + + // Lint all bounds in the `impl Trait` type that are also in the `implied_bounds` vec. + for bound in opaque_ty.bounds { + if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound + && let Some(def_id) = poly_trait.trait_ref.path.res.opt_def_id() + && implied_bounds.iter().any(|(clause, _)| { + if let ClauseKind::Trait(tr) = clause.kind().skip_binder() { + tr.def_id() == def_id + } else { + false + } + }) + { + span_lint(cx, IMPLIED_BOUNDS_IN_IMPL, poly_trait.span, "this bound is implied by another bound and can be removed"); + } + } + } + } + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index f50019f3cf766..d4fcddc66c5c4 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -152,6 +152,7 @@ mod implicit_hasher; mod implicit_return; mod implicit_saturating_add; mod implicit_saturating_sub; +mod implied_bounds_in_impl; mod inconsistent_struct_constructor; mod incorrect_impls; mod index_refutable_slice; @@ -1097,6 +1098,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|_| Box::new(redundant_locals::RedundantLocals)); store.register_late_pass(|_| Box::new(ignored_unit_patterns::IgnoredUnitPatterns)); store.register_late_pass(|_| Box::::default()); + store.register_late_pass(|_| Box::new(implied_bounds_in_impl::ImpliedBoundsInImpl)); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/tests/ui/implied_bounds_in_impl.rs b/tests/ui/implied_bounds_in_impl.rs new file mode 100644 index 0000000000000..516f21fc795bf --- /dev/null +++ b/tests/ui/implied_bounds_in_impl.rs @@ -0,0 +1,45 @@ +#![warn(clippy::implied_bounds_in_impl)] +#![allow(dead_code)] + +use std::ops::{Deref, DerefMut}; + +trait Trait1 {} +// T is intentionally at a different position in Trait2 than in Trait1, +// since that also needs to be taken into account when making this lint work with generics +trait Trait2: Trait1 {} +impl Trait1 for () {} +impl Trait1 for () {} +impl Trait2 for () {} +impl Trait2 for () {} + +// Deref implied by DerefMut +fn deref_derefmut(x: T) -> impl Deref + DerefMut { + Box::new(x) +} + +// Note: no test for different associated types needed since that isn't allowed in the first place. +// E.g. `-> impl Deref + DerefMut` is a compile error. + +// DefIds of the traits match, but the generics do not, so it's *not* redundant. +// `Trait2: Trait` holds, but not `Trait2<_, String>: Trait1`. +// (Generic traits are currently not linted anyway but once/if ever implemented this should not +// warn.) +fn different_generics() -> impl Trait1 + Trait2 { + /* () */ +} + +trait NonGenericTrait1 {} +trait NonGenericTrait2: NonGenericTrait1 {} +impl NonGenericTrait1 for i32 {} +impl NonGenericTrait2 for i32 {} + +// Only one bound. Nothing to lint. +fn normal1() -> impl NonGenericTrait1 { + 1 +} + +fn normal2() -> impl NonGenericTrait1 + NonGenericTrait2 { + 1 +} + +fn main() {} diff --git a/tests/ui/implied_bounds_in_impl.stderr b/tests/ui/implied_bounds_in_impl.stderr new file mode 100644 index 0000000000000..2709f727acc9a --- /dev/null +++ b/tests/ui/implied_bounds_in_impl.stderr @@ -0,0 +1,16 @@ +error: this bound is implied by another bound and can be removed + --> $DIR/implied_bounds_in_impl.rs:16:36 + | +LL | fn deref_derefmut(x: T) -> impl Deref + DerefMut { + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::implied-bounds-in-impl` implied by `-D warnings` + +error: this bound is implied by another bound and can be removed + --> $DIR/implied_bounds_in_impl.rs:41:22 + | +LL | fn normal2() -> impl NonGenericTrait1 + NonGenericTrait2 { + | ^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + From 2ebff58969988d1b45b19d0dd50a8058aa26eb37 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Sun, 20 Aug 2023 05:25:35 +0200 Subject: [PATCH 71/79] make generics work fix compile error in doc example --- clippy_lints/src/implied_bounds_in_impl.rs | 99 ++++++++++++++++++---- tests/ui/implied_bounds_in_impl.rs | 56 ++++++------ tests/ui/implied_bounds_in_impl.stderr | 40 +++++++-- 3 files changed, 146 insertions(+), 49 deletions(-) diff --git a/clippy_lints/src/implied_bounds_in_impl.rs b/clippy_lints/src/implied_bounds_in_impl.rs index c83153e5350fb..3f9f5daa6a467 100644 --- a/clippy_lints/src/implied_bounds_in_impl.rs +++ b/clippy_lints/src/implied_bounds_in_impl.rs @@ -1,9 +1,10 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, FnDecl, FnRetTy, GenericArgs, GenericBound, ItemKind, TraitBoundModifier, TyKind}; +use rustc_hir::{Body, FnDecl, FnRetTy, GenericArg, GenericBound, ItemKind, TraitBoundModifier, TyKind}; +use rustc_hir_analysis::hir_ty_to_ty; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::ClauseKind; +use rustc_middle::ty::{self, ClauseKind, TyCtxt}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; @@ -17,10 +18,11 @@ declare_clippy_lint! { /// Unnecessary complexity. /// /// ### Known problems - /// This lint currently does not work with generic traits (i.e. will not lint even if redundant). + /// This lint does not transitively look for implied bounds past the first supertrait. /// /// ### Example /// ```rust + /// # use std::ops::{Deref,DerefMut}; /// fn f() -> impl Deref + DerefMut { /// // ^^^^^^^^^^^^^^^^^^^ unnecessary bound, already implied by the `DerefMut` trait bound /// Box::new(123) @@ -28,6 +30,7 @@ declare_clippy_lint! { /// ``` /// Use instead: /// ```rust + /// # use std::ops::{Deref,DerefMut}; /// fn f() -> impl DerefMut { /// Box::new(123) /// } @@ -39,6 +42,53 @@ declare_clippy_lint! { } declare_lint_pass!(ImpliedBoundsInImpl => [IMPLIED_BOUNDS_IN_IMPL]); +/// This function tries to, for all type parameters in a supertype predicate `GenericTrait`, +/// check if the substituted type in the implied-by bound matches with what's subtituted in the +/// implied type. +/// +/// Consider this example function. +/// ```rust,ignore +/// trait GenericTrait {} +/// trait GenericSubTrait: GenericTrait {} +/// ^ trait_predicate_args: [Self#0, U#2] +/// impl GenericTrait for () {} +/// impl GenericSubTrait<(), i32, ()> for () {} +/// impl GenericSubTrait<(), [u8; 8], ()> for () {} +/// +/// fn f() -> impl GenericTrait + GenericSubTrait<(), [u8; 8], ()> { +/// ^^^ implied_args ^^^^^^^^^^^^^^^ implied_by_args +/// (we are interested in `[u8; 8]` specifically, as that +/// is what `U` in `GenericTrait` is substituted with) +/// () +/// } +/// ``` +/// Here i32 != [u8; 8], so this will return false. +fn is_same_generics( + tcx: TyCtxt<'_>, + trait_predicate_args: &[ty::GenericArg<'_>], + implied_by_args: &[GenericArg<'_>], + implied_args: &[GenericArg<'_>], +) -> bool { + trait_predicate_args + .iter() + .enumerate() + .skip(1) // skip `Self` implicit arg + .all(|(arg_index, arg)| { + if let Some(ty) = arg.as_type() + && let &ty::Param(ty::ParamTy{ index, .. }) = ty.kind() + // Since `trait_predicate_args` and type params in traits start with `Self=0` + // and generic argument lists `GenericTrait` don't have `Self`, + // we need to subtract 1 from the index. + && let GenericArg::Type(ty_a) = implied_by_args[index as usize - 1] + && let GenericArg::Type(ty_b) = implied_args[arg_index - 1] + { + hir_ty_to_ty(tcx, ty_a) == hir_ty_to_ty(tcx, ty_b) + } else { + false + } + }) +} + impl LateLintPass<'_> for ImpliedBoundsInImpl { fn check_fn( &mut self, @@ -54,37 +104,52 @@ impl LateLintPass<'_> for ImpliedBoundsInImpl { && let item = cx.tcx.hir().item(item_id) && let ItemKind::OpaqueTy(opaque_ty) = item.kind { - // Get all `DefId`s of (implied) trait predicates in all the bounds. + // Very often there is only a single bound, e.g. `impl Deref<..>`, in which case + // we can avoid doing a bunch of stuff unnecessarily. + if opaque_ty.bounds.is_empty() { + return; + } + + // Get all the (implied) trait predicates in the bounds. // For `impl Deref + DerefMut` this will contain [`Deref`]. // The implied `Deref` comes from `DerefMut` because `trait DerefMut: Deref {}`. - // N.B. Generic args on trait bounds are currently ignored and (G)ATs are fine to disregard, - // because they must be the same for all of its supertraits. Example: + // N.B. (G)ATs are fine to disregard, because they must be the same for all of its supertraits. + // Example: // `impl Deref + DerefMut` is not allowed. // `DerefMut::Target` needs to match `Deref::Target` - let implied_bounds = opaque_ty.bounds.iter().flat_map(|bound| { + let implied_bounds: Vec<_> = opaque_ty.bounds.iter().filter_map(|bound| { if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound && let [.., path] = poly_trait.trait_ref.path.segments && poly_trait.bound_generic_params.is_empty() - && path.args.map_or(true, GenericArgs::is_empty) && let Some(trait_def_id) = path.res.opt_def_id() + && let predicates = cx.tcx.super_predicates_of(trait_def_id).predicates + && !predicates.is_empty() // If the trait has no supertrait, there is nothing to add. { - cx.tcx.implied_predicates_of(trait_def_id).predicates + Some((path.args.map_or([].as_slice(), |a| a.args), predicates)) } else { - &[] + None } - }).collect::>(); + }).collect(); // Lint all bounds in the `impl Trait` type that are also in the `implied_bounds` vec. + // This involves some extra logic when generic arguments are present, since + // simply comparing trait `DefId`s won't be enough. We also need to compare the generics. for bound in opaque_ty.bounds { if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound + && let [.., path] = poly_trait.trait_ref.path.segments + && let implied_args = path.args.map_or([].as_slice(), |a| a.args) && let Some(def_id) = poly_trait.trait_ref.path.res.opt_def_id() - && implied_bounds.iter().any(|(clause, _)| { - if let ClauseKind::Trait(tr) = clause.kind().skip_binder() { - tr.def_id() == def_id - } else { - false - } + && implied_bounds.iter().any(|(implied_by_args, preds)| { + preds.iter().any(|(clause, _)| { + if let ClauseKind::Trait(tr) = clause.kind().skip_binder() + && tr.def_id() == def_id + { + is_same_generics(cx.tcx, tr.trait_ref.args, implied_by_args, implied_args) + } else { + false + } + }) }) { span_lint(cx, IMPLIED_BOUNDS_IN_IMPL, poly_trait.span, "this bound is implied by another bound and can be removed"); diff --git a/tests/ui/implied_bounds_in_impl.rs b/tests/ui/implied_bounds_in_impl.rs index 516f21fc795bf..0bc4b193d5338 100644 --- a/tests/ui/implied_bounds_in_impl.rs +++ b/tests/ui/implied_bounds_in_impl.rs @@ -3,43 +3,45 @@ use std::ops::{Deref, DerefMut}; -trait Trait1 {} -// T is intentionally at a different position in Trait2 than in Trait1, -// since that also needs to be taken into account when making this lint work with generics -trait Trait2: Trait1 {} -impl Trait1 for () {} -impl Trait1 for () {} -impl Trait2 for () {} -impl Trait2 for () {} +// Only one bound, nothing to lint. +fn normal_deref(x: T) -> impl Deref { + Box::new(x) +} // Deref implied by DerefMut fn deref_derefmut(x: T) -> impl Deref + DerefMut { Box::new(x) } -// Note: no test for different associated types needed since that isn't allowed in the first place. -// E.g. `-> impl Deref + DerefMut` is a compile error. - -// DefIds of the traits match, but the generics do not, so it's *not* redundant. -// `Trait2: Trait` holds, but not `Trait2<_, String>: Trait1`. -// (Generic traits are currently not linted anyway but once/if ever implemented this should not -// warn.) -fn different_generics() -> impl Trait1 + Trait2 { - /* () */ +trait GenericTrait {} +trait GenericTrait2 {} +// U is intentionally at a different "index" in GenericSubtrait than `T` is in GenericTrait +trait GenericSubtrait: GenericTrait + GenericTrait2 {} + +impl GenericTrait for () {} +impl GenericTrait for () {} +impl GenericTrait2 for () {} +impl GenericSubtrait<(), i32, V> for () {} +impl GenericSubtrait<(), i64, V> for () {} + +fn generics_implied() -> impl GenericTrait + GenericSubtrait<(), T, ()> +where + (): GenericSubtrait<(), T, ()>, +{ } -trait NonGenericTrait1 {} -trait NonGenericTrait2: NonGenericTrait1 {} -impl NonGenericTrait1 for i32 {} -impl NonGenericTrait2 for i32 {} +fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} -// Only one bound. Nothing to lint. -fn normal1() -> impl NonGenericTrait1 { - 1 +fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> +where + (): GenericSubtrait<(), T, V> + GenericTrait, +{ } -fn normal2() -> impl NonGenericTrait1 + NonGenericTrait2 { - 1 -} +// i32 != i64, GenericSubtrait<_, i64, _> does not imply GenericTrait, don't lint +fn generics_different() -> impl GenericTrait + GenericSubtrait<(), i64, ()> {} + +// i32 == i32, GenericSubtrait<_, i32, _> does imply GenericTrait, lint +fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} fn main() {} diff --git a/tests/ui/implied_bounds_in_impl.stderr b/tests/ui/implied_bounds_in_impl.stderr index 2709f727acc9a..92d412e784f31 100644 --- a/tests/ui/implied_bounds_in_impl.stderr +++ b/tests/ui/implied_bounds_in_impl.stderr @@ -1,5 +1,5 @@ error: this bound is implied by another bound and can be removed - --> $DIR/implied_bounds_in_impl.rs:16:36 + --> $DIR/implied_bounds_in_impl.rs:12:36 | LL | fn deref_derefmut(x: T) -> impl Deref + DerefMut { | ^^^^^^^^^^^^^^^^^ @@ -7,10 +7,40 @@ LL | fn deref_derefmut(x: T) -> impl Deref + DerefMut = note: `-D clippy::implied-bounds-in-impl` implied by `-D warnings` error: this bound is implied by another bound and can be removed - --> $DIR/implied_bounds_in_impl.rs:41:22 + --> $DIR/implied_bounds_in_impl.rs:27:34 | -LL | fn normal2() -> impl NonGenericTrait1 + NonGenericTrait2 { - | ^^^^^^^^^^^^^^^^ +LL | fn generics_implied() -> impl GenericTrait + GenericSubtrait<(), T, ()> + | ^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: this bound is implied by another bound and can be removed + --> $DIR/implied_bounds_in_impl.rs:33:40 + | +LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} + | ^^^^^^^^^^^^^^^^^ + +error: this bound is implied by another bound and can be removed + --> $DIR/implied_bounds_in_impl.rs:33:60 + | +LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} + | ^^^^^^^^^^^^^^^^ + +error: this bound is implied by another bound and can be removed + --> $DIR/implied_bounds_in_impl.rs:35:44 + | +LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> + | ^^^^^^^^^^^^^^^ + +error: this bound is implied by another bound and can be removed + --> $DIR/implied_bounds_in_impl.rs:35:62 + | +LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> + | ^^^^^^^^^^^^^^^^ + +error: this bound is implied by another bound and can be removed + --> $DIR/implied_bounds_in_impl.rs:45:28 + | +LL | fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors From 09506f49c13630765f636cf8a1ac58f95658dd68 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:48:26 +0200 Subject: [PATCH 72/79] rename lint, docs, improve diagnostics --- CHANGELOG.md | 2 +- clippy_lints/src/declared_lints.rs | 2 +- clippy_lints/src/implied_bounds_in_impl.rs | 161 --------------- clippy_lints/src/implied_bounds_in_impls.rs | 185 ++++++++++++++++++ clippy_lints/src/lib.rs | 4 +- tests/ui/implied_bounds_in_impl.stderr | 46 ----- tests/ui/implied_bounds_in_impls.fixed | 70 +++++++ ..._in_impl.rs => implied_bounds_in_impls.rs} | 31 ++- tests/ui/implied_bounds_in_impls.stderr | 99 ++++++++++ 9 files changed, 385 insertions(+), 215 deletions(-) delete mode 100644 clippy_lints/src/implied_bounds_in_impl.rs create mode 100644 clippy_lints/src/implied_bounds_in_impls.rs delete mode 100644 tests/ui/implied_bounds_in_impl.stderr create mode 100644 tests/ui/implied_bounds_in_impls.fixed rename tests/ui/{implied_bounds_in_impl.rs => implied_bounds_in_impls.rs} (62%) create mode 100644 tests/ui/implied_bounds_in_impls.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ae44c502dbb0..583bc6754fb1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4985,7 +4985,7 @@ Released 2018-09-13 [`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return [`implicit_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_add [`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub -[`implied_bounds_in_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#implied_bounds_in_impl +[`implied_bounds_in_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#implied_bounds_in_impls [`impossible_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#impossible_comparisons [`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops [`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index ea8d804b423d1..f73f1ed18f8b6 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -209,7 +209,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::implicit_return::IMPLICIT_RETURN_INFO, crate::implicit_saturating_add::IMPLICIT_SATURATING_ADD_INFO, crate::implicit_saturating_sub::IMPLICIT_SATURATING_SUB_INFO, - crate::implied_bounds_in_impl::IMPLIED_BOUNDS_IN_IMPL_INFO, + crate::implied_bounds_in_impls::IMPLIED_BOUNDS_IN_IMPLS_INFO, crate::inconsistent_struct_constructor::INCONSISTENT_STRUCT_CONSTRUCTOR_INFO, crate::incorrect_impls::INCORRECT_CLONE_IMPL_ON_COPY_TYPE_INFO, crate::incorrect_impls::INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE_INFO, diff --git a/clippy_lints/src/implied_bounds_in_impl.rs b/clippy_lints/src/implied_bounds_in_impl.rs deleted file mode 100644 index 3f9f5daa6a467..0000000000000 --- a/clippy_lints/src/implied_bounds_in_impl.rs +++ /dev/null @@ -1,161 +0,0 @@ -use clippy_utils::diagnostics::span_lint; -use rustc_hir::def_id::LocalDefId; -use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, FnDecl, FnRetTy, GenericArg, GenericBound, ItemKind, TraitBoundModifier, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, ClauseKind, TyCtxt}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::Span; - -declare_clippy_lint! { - /// ### What it does - /// Looks for bounds in `impl Trait` in return position that are implied by other bounds. - /// This is usually the case when a supertrait is explicitly specified, when it is already implied - /// by a subtrait (e.g. `DerefMut: Deref`, so specifying `Deref` is unnecessary when `DerefMut` is specified). - /// - /// ### Why is this bad? - /// Unnecessary complexity. - /// - /// ### Known problems - /// This lint does not transitively look for implied bounds past the first supertrait. - /// - /// ### Example - /// ```rust - /// # use std::ops::{Deref,DerefMut}; - /// fn f() -> impl Deref + DerefMut { - /// // ^^^^^^^^^^^^^^^^^^^ unnecessary bound, already implied by the `DerefMut` trait bound - /// Box::new(123) - /// } - /// ``` - /// Use instead: - /// ```rust - /// # use std::ops::{Deref,DerefMut}; - /// fn f() -> impl DerefMut { - /// Box::new(123) - /// } - /// ``` - #[clippy::version = "1.73.0"] - pub IMPLIED_BOUNDS_IN_IMPL, - complexity, - "specifying bounds that are implied by other bounds in `impl Trait` type" -} -declare_lint_pass!(ImpliedBoundsInImpl => [IMPLIED_BOUNDS_IN_IMPL]); - -/// This function tries to, for all type parameters in a supertype predicate `GenericTrait`, -/// check if the substituted type in the implied-by bound matches with what's subtituted in the -/// implied type. -/// -/// Consider this example function. -/// ```rust,ignore -/// trait GenericTrait {} -/// trait GenericSubTrait: GenericTrait {} -/// ^ trait_predicate_args: [Self#0, U#2] -/// impl GenericTrait for () {} -/// impl GenericSubTrait<(), i32, ()> for () {} -/// impl GenericSubTrait<(), [u8; 8], ()> for () {} -/// -/// fn f() -> impl GenericTrait + GenericSubTrait<(), [u8; 8], ()> { -/// ^^^ implied_args ^^^^^^^^^^^^^^^ implied_by_args -/// (we are interested in `[u8; 8]` specifically, as that -/// is what `U` in `GenericTrait` is substituted with) -/// () -/// } -/// ``` -/// Here i32 != [u8; 8], so this will return false. -fn is_same_generics( - tcx: TyCtxt<'_>, - trait_predicate_args: &[ty::GenericArg<'_>], - implied_by_args: &[GenericArg<'_>], - implied_args: &[GenericArg<'_>], -) -> bool { - trait_predicate_args - .iter() - .enumerate() - .skip(1) // skip `Self` implicit arg - .all(|(arg_index, arg)| { - if let Some(ty) = arg.as_type() - && let &ty::Param(ty::ParamTy{ index, .. }) = ty.kind() - // Since `trait_predicate_args` and type params in traits start with `Self=0` - // and generic argument lists `GenericTrait` don't have `Self`, - // we need to subtract 1 from the index. - && let GenericArg::Type(ty_a) = implied_by_args[index as usize - 1] - && let GenericArg::Type(ty_b) = implied_args[arg_index - 1] - { - hir_ty_to_ty(tcx, ty_a) == hir_ty_to_ty(tcx, ty_b) - } else { - false - } - }) -} - -impl LateLintPass<'_> for ImpliedBoundsInImpl { - fn check_fn( - &mut self, - cx: &LateContext<'_>, - _: FnKind<'_>, - decl: &FnDecl<'_>, - _: &Body<'_>, - _: Span, - _: LocalDefId, - ) { - if let FnRetTy::Return(ty) = decl.output { - if let TyKind::OpaqueDef(item_id, ..) = ty.kind - && let item = cx.tcx.hir().item(item_id) - && let ItemKind::OpaqueTy(opaque_ty) = item.kind - { - // Very often there is only a single bound, e.g. `impl Deref<..>`, in which case - // we can avoid doing a bunch of stuff unnecessarily. - if opaque_ty.bounds.is_empty() { - return; - } - - // Get all the (implied) trait predicates in the bounds. - // For `impl Deref + DerefMut` this will contain [`Deref`]. - // The implied `Deref` comes from `DerefMut` because `trait DerefMut: Deref {}`. - - // N.B. (G)ATs are fine to disregard, because they must be the same for all of its supertraits. - // Example: - // `impl Deref + DerefMut` is not allowed. - // `DerefMut::Target` needs to match `Deref::Target` - let implied_bounds: Vec<_> = opaque_ty.bounds.iter().filter_map(|bound| { - if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound - && let [.., path] = poly_trait.trait_ref.path.segments - && poly_trait.bound_generic_params.is_empty() - && let Some(trait_def_id) = path.res.opt_def_id() - && let predicates = cx.tcx.super_predicates_of(trait_def_id).predicates - && !predicates.is_empty() // If the trait has no supertrait, there is nothing to add. - { - Some((path.args.map_or([].as_slice(), |a| a.args), predicates)) - } else { - None - } - }).collect(); - - // Lint all bounds in the `impl Trait` type that are also in the `implied_bounds` vec. - // This involves some extra logic when generic arguments are present, since - // simply comparing trait `DefId`s won't be enough. We also need to compare the generics. - for bound in opaque_ty.bounds { - if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound - && let [.., path] = poly_trait.trait_ref.path.segments - && let implied_args = path.args.map_or([].as_slice(), |a| a.args) - && let Some(def_id) = poly_trait.trait_ref.path.res.opt_def_id() - && implied_bounds.iter().any(|(implied_by_args, preds)| { - preds.iter().any(|(clause, _)| { - if let ClauseKind::Trait(tr) = clause.kind().skip_binder() - && tr.def_id() == def_id - { - is_same_generics(cx.tcx, tr.trait_ref.args, implied_by_args, implied_args) - } else { - false - } - }) - }) - { - span_lint(cx, IMPLIED_BOUNDS_IN_IMPL, poly_trait.span, "this bound is implied by another bound and can be removed"); - } - } - } - } - } -} diff --git a/clippy_lints/src/implied_bounds_in_impls.rs b/clippy_lints/src/implied_bounds_in_impls.rs new file mode 100644 index 0000000000000..7ba467a3e06cc --- /dev/null +++ b/clippy_lints/src/implied_bounds_in_impls.rs @@ -0,0 +1,185 @@ +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::source::snippet; +use rustc_hir::def_id::LocalDefId; +use rustc_hir::intravisit::FnKind; +use rustc_hir::{Body, FnDecl, FnRetTy, GenericArg, GenericBound, ItemKind, TraitBoundModifier, TyKind}; +use rustc_hir_analysis::hir_ty_to_ty; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_errors::{Applicability, SuggestionStyle}; +use rustc_middle::ty::{self, ClauseKind, TyCtxt}; +use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::Span; + +declare_clippy_lint! { + /// ### What it does + /// Looks for bounds in `impl Trait` in return position that are implied by other bounds. + /// This can happen when a trait is specified that another trait already has as a supertrait + /// (e.g. `fn() -> impl Deref + DerefMut` has an unnecessary `Deref` bound, + /// because `Deref` is a supertrait of `DerefMut`) + /// + /// ### Why is this bad? + /// Specifying more bounds than necessary adds needless complexity for the reader. + /// + /// ### Limitations + /// This lint does not check for implied bounds transitively. Meaning that + /// it does't check for implied bounds from supertraits of supertraits + /// (e.g. `trait A {} trait B: A {} trait C: B {}`, then having an `fn() -> impl A + C`) + /// + /// ### Example + /// ```rust + /// # use std::ops::{Deref,DerefMut}; + /// fn f() -> impl Deref + DerefMut { + /// // ^^^^^^^^^^^^^^^^^^^ unnecessary bound, already implied by the `DerefMut` trait bound + /// Box::new(123) + /// } + /// ``` + /// Use instead: + /// ```rust + /// # use std::ops::{Deref,DerefMut}; + /// fn f() -> impl DerefMut { + /// Box::new(123) + /// } + /// ``` + #[clippy::version = "1.73.0"] + pub IMPLIED_BOUNDS_IN_IMPLS, + complexity, + "specifying bounds that are implied by other bounds in `impl Trait` type" +} +declare_lint_pass!(ImpliedBoundsInImpls => [IMPLIED_BOUNDS_IN_IMPLS]); + +/// This function tries to, for all type parameters in a supertype predicate `GenericTrait`, +/// check if the substituted type in the implied-by bound matches with what's subtituted in the +/// implied type. +/// +/// Consider this example. +/// ```rust,ignore +/// trait GenericTrait {} +/// trait GenericSubTrait: GenericTrait {} +/// ^ trait_predicate_args: [Self#0, U#2] +/// impl GenericTrait for () {} +/// impl GenericSubTrait<(), i32, ()> for () {} +/// impl GenericSubTrait<(), [u8; 8], ()> for () {} +/// +/// fn f() -> impl GenericTrait + GenericSubTrait<(), [u8; 8], ()> { +/// ^^^ implied_args ^^^^^^^^^^^^^^^ implied_by_args +/// (we are interested in `[u8; 8]` specifically, as that +/// is what `U` in `GenericTrait` is substituted with) +/// () +/// } +/// ``` +/// Here i32 != [u8; 8], so this will return false. +fn is_same_generics( + tcx: TyCtxt<'_>, + trait_predicate_args: &[ty::GenericArg<'_>], + implied_by_args: &[GenericArg<'_>], + implied_args: &[GenericArg<'_>], +) -> bool { + trait_predicate_args + .iter() + .enumerate() + .skip(1) // skip `Self` implicit arg + .all(|(arg_index, arg)| { + if let Some(ty) = arg.as_type() + && let &ty::Param(ty::ParamTy{ index, .. }) = ty.kind() + // Since `trait_predicate_args` and type params in traits start with `Self=0` + // and generic argument lists `GenericTrait` don't have `Self`, + // we need to subtract 1 from the index. + && let GenericArg::Type(ty_a) = implied_by_args[index as usize - 1] + && let GenericArg::Type(ty_b) = implied_args[arg_index - 1] + { + hir_ty_to_ty(tcx, ty_a) == hir_ty_to_ty(tcx, ty_b) + } else { + false + } + }) +} + +impl LateLintPass<'_> for ImpliedBoundsInImpls { + fn check_fn( + &mut self, + cx: &LateContext<'_>, + _: FnKind<'_>, + decl: &FnDecl<'_>, + _: &Body<'_>, + _: Span, + _: LocalDefId, + ) { + if let FnRetTy::Return(ty) = decl.output + &&let TyKind::OpaqueDef(item_id, ..) = ty.kind + && let item = cx.tcx.hir().item(item_id) + && let ItemKind::OpaqueTy(opaque_ty) = item.kind + // Very often there is only a single bound, e.g. `impl Deref<..>`, in which case + // we can avoid doing a bunch of stuff unnecessarily. + && opaque_ty.bounds.len() > 1 + { + // Get all the (implied) trait predicates in the bounds. + // For `impl Deref + DerefMut` this will contain [`Deref`]. + // The implied `Deref` comes from `DerefMut` because `trait DerefMut: Deref {}`. + // N.B. (G)ATs are fine to disregard, because they must be the same for all of its supertraits. + // Example: + // `impl Deref + DerefMut` is not allowed. + // `DerefMut::Target` needs to match `Deref::Target`. + let implied_bounds: Vec<_> = opaque_ty.bounds.iter().filter_map(|bound| { + if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound + && let [.., path] = poly_trait.trait_ref.path.segments + && poly_trait.bound_generic_params.is_empty() + && let Some(trait_def_id) = path.res.opt_def_id() + && let predicates = cx.tcx.super_predicates_of(trait_def_id).predicates + && !predicates.is_empty() // If the trait has no supertrait, there is nothing to add. + { + Some((bound.span(), path.args.map_or([].as_slice(), |a| a.args), predicates)) + } else { + None + } + }).collect(); + + // Lint all bounds in the `impl Trait` type that are also in the `implied_bounds` vec. + // This involves some extra logic when generic arguments are present, since + // simply comparing trait `DefId`s won't be enough. We also need to compare the generics. + for (index, bound) in opaque_ty.bounds.iter().enumerate() { + if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound + && let [.., path] = poly_trait.trait_ref.path.segments + && let implied_args = path.args.map_or([].as_slice(), |a| a.args) + && let Some(def_id) = poly_trait.trait_ref.path.res.opt_def_id() + && let Some(implied_by_span) = implied_bounds.iter().find_map(|&(span, implied_by_args, preds)| { + preds.iter().find_map(|(clause, _)| { + if let ClauseKind::Trait(tr) = clause.kind().skip_binder() + && tr.def_id() == def_id + && is_same_generics(cx.tcx, tr.trait_ref.args, implied_by_args, implied_args) + { + Some(span) + } else { + None + } + }) + }) + { + let implied_by = snippet(cx, implied_by_span, ".."); + span_lint_and_then( + cx, IMPLIED_BOUNDS_IN_IMPLS, + poly_trait.span, + &format!("this bound is already specified as the supertrait of `{}`", implied_by), + |diag| { + // If we suggest removing a bound, we may also need extend the span + // to include the `+` token, so we don't end up with something like `impl + B` + + let implied_span_extended = if let Some(next_bound) = opaque_ty.bounds.get(index + 1) { + poly_trait.span.to(next_bound.span().shrink_to_lo()) + } else { + poly_trait.span + }; + + diag.span_suggestion_with_style( + implied_span_extended, + "try removing this bound", + "", + Applicability::MachineApplicable, + SuggestionStyle::ShowAlways + ); + } + ); + } + } + } + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d4fcddc66c5c4..ab71bfbdc587e 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -152,7 +152,7 @@ mod implicit_hasher; mod implicit_return; mod implicit_saturating_add; mod implicit_saturating_sub; -mod implied_bounds_in_impl; +mod implied_bounds_in_impls; mod inconsistent_struct_constructor; mod incorrect_impls; mod index_refutable_slice; @@ -1098,7 +1098,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|_| Box::new(redundant_locals::RedundantLocals)); store.register_late_pass(|_| Box::new(ignored_unit_patterns::IgnoredUnitPatterns)); store.register_late_pass(|_| Box::::default()); - store.register_late_pass(|_| Box::new(implied_bounds_in_impl::ImpliedBoundsInImpl)); + store.register_late_pass(|_| Box::new(implied_bounds_in_impls::ImpliedBoundsInImpls)); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/tests/ui/implied_bounds_in_impl.stderr b/tests/ui/implied_bounds_in_impl.stderr deleted file mode 100644 index 92d412e784f31..0000000000000 --- a/tests/ui/implied_bounds_in_impl.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: this bound is implied by another bound and can be removed - --> $DIR/implied_bounds_in_impl.rs:12:36 - | -LL | fn deref_derefmut(x: T) -> impl Deref + DerefMut { - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::implied-bounds-in-impl` implied by `-D warnings` - -error: this bound is implied by another bound and can be removed - --> $DIR/implied_bounds_in_impl.rs:27:34 - | -LL | fn generics_implied() -> impl GenericTrait + GenericSubtrait<(), T, ()> - | ^^^^^^^^^^^^^^^ - -error: this bound is implied by another bound and can be removed - --> $DIR/implied_bounds_in_impl.rs:33:40 - | -LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} - | ^^^^^^^^^^^^^^^^^ - -error: this bound is implied by another bound and can be removed - --> $DIR/implied_bounds_in_impl.rs:33:60 - | -LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} - | ^^^^^^^^^^^^^^^^ - -error: this bound is implied by another bound and can be removed - --> $DIR/implied_bounds_in_impl.rs:35:44 - | -LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> - | ^^^^^^^^^^^^^^^ - -error: this bound is implied by another bound and can be removed - --> $DIR/implied_bounds_in_impl.rs:35:62 - | -LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> - | ^^^^^^^^^^^^^^^^ - -error: this bound is implied by another bound and can be removed - --> $DIR/implied_bounds_in_impl.rs:45:28 - | -LL | fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} - | ^^^^^^^^^^^^^^^^^ - -error: aborting due to 7 previous errors - diff --git a/tests/ui/implied_bounds_in_impls.fixed b/tests/ui/implied_bounds_in_impls.fixed new file mode 100644 index 0000000000000..72239afae4a3d --- /dev/null +++ b/tests/ui/implied_bounds_in_impls.fixed @@ -0,0 +1,70 @@ +#![warn(clippy::implied_bounds_in_impls)] +#![allow(dead_code)] +#![feature(return_position_impl_trait_in_trait)] + +use std::ops::{Deref, DerefMut}; + +// Only one bound, nothing to lint. +fn normal_deref(x: T) -> impl Deref { + Box::new(x) +} + +// Deref implied by DerefMut +fn deref_derefmut(x: T) -> impl DerefMut { + Box::new(x) +} + +trait GenericTrait {} +trait GenericTrait2 {} +// U is intentionally at a different "index" in GenericSubtrait than `T` is in GenericTrait, +// so this can be a good test to make sure that the calculations are right (no off-by-one errors, +// ...) +trait GenericSubtrait: GenericTrait + GenericTrait2 {} + +impl GenericTrait for () {} +impl GenericTrait for () {} +impl GenericTrait2 for () {} +impl GenericSubtrait<(), i32, V> for () {} +impl GenericSubtrait<(), i64, V> for () {} + +fn generics_implied() -> impl GenericSubtrait +where + (): GenericSubtrait, +{ +} + +fn generics_implied_multi() -> impl GenericSubtrait<(), i32, V> {} + +fn generics_implied_multi2() -> impl GenericSubtrait<(), T, V> +where + (): GenericSubtrait<(), T, V> + GenericTrait, +{ +} + +// i32 != i64, GenericSubtrait<_, i64, _> does not imply GenericTrait, don't lint +fn generics_different() -> impl GenericTrait + GenericSubtrait<(), i64, ()> {} + +// i32 == i32, GenericSubtrait<_, i32, _> does imply GenericTrait, lint +fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} + +trait SomeTrait { + // Check that it works in trait declarations. + fn f() -> impl DerefMut { + Box::new(0) + } +} +struct SomeStruct; +impl SomeStruct { + // Check that it works in inherent impl blocks. + fn f() -> impl DerefMut { + Box::new(123) + } +} +impl SomeTrait for SomeStruct { + // Check that it works in trait impls. + fn f() -> impl DerefMut { + Box::new(42) + } +} + +fn main() {} diff --git a/tests/ui/implied_bounds_in_impl.rs b/tests/ui/implied_bounds_in_impls.rs similarity index 62% rename from tests/ui/implied_bounds_in_impl.rs rename to tests/ui/implied_bounds_in_impls.rs index 0bc4b193d5338..d59241d9ad13c 100644 --- a/tests/ui/implied_bounds_in_impl.rs +++ b/tests/ui/implied_bounds_in_impls.rs @@ -1,5 +1,6 @@ -#![warn(clippy::implied_bounds_in_impl)] +#![warn(clippy::implied_bounds_in_impls)] #![allow(dead_code)] +#![feature(return_position_impl_trait_in_trait)] use std::ops::{Deref, DerefMut}; @@ -15,7 +16,9 @@ fn deref_derefmut(x: T) -> impl Deref + DerefMut { trait GenericTrait {} trait GenericTrait2 {} -// U is intentionally at a different "index" in GenericSubtrait than `T` is in GenericTrait +// U is intentionally at a different "index" in GenericSubtrait than `T` is in GenericTrait, +// so this can be a good test to make sure that the calculations are right (no off-by-one errors, +// ...) trait GenericSubtrait: GenericTrait + GenericTrait2 {} impl GenericTrait for () {} @@ -24,9 +27,9 @@ impl GenericTrait2 for () {} impl GenericSubtrait<(), i32, V> for () {} impl GenericSubtrait<(), i64, V> for () {} -fn generics_implied() -> impl GenericTrait + GenericSubtrait<(), T, ()> +fn generics_implied() -> impl GenericTrait + GenericSubtrait where - (): GenericSubtrait<(), T, ()>, + (): GenericSubtrait, { } @@ -44,4 +47,24 @@ fn generics_different() -> impl GenericTrait + GenericSubtrait<(), i64, ()> // i32 == i32, GenericSubtrait<_, i32, _> does imply GenericTrait, lint fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} +trait SomeTrait { + // Check that it works in trait declarations. + fn f() -> impl Deref + DerefMut { + Box::new(0) + } +} +struct SomeStruct; +impl SomeStruct { + // Check that it works in inherent impl blocks. + fn f() -> impl DerefMut { + Box::new(123) + } +} +impl SomeTrait for SomeStruct { + // Check that it works in trait impls. + fn f() -> impl DerefMut { + Box::new(42) + } +} + fn main() {} diff --git a/tests/ui/implied_bounds_in_impls.stderr b/tests/ui/implied_bounds_in_impls.stderr new file mode 100644 index 0000000000000..86ce64a47fd15 --- /dev/null +++ b/tests/ui/implied_bounds_in_impls.stderr @@ -0,0 +1,99 @@ +error: this bound is already specified as the supertrait of `DerefMut` + --> $DIR/implied_bounds_in_impls.rs:13:36 + | +LL | fn deref_derefmut(x: T) -> impl Deref + DerefMut { + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::implied-bounds-in-impls` implied by `-D warnings` +help: try removing this bound + | +LL - fn deref_derefmut(x: T) -> impl Deref + DerefMut { +LL + fn deref_derefmut(x: T) -> impl DerefMut { + | + +error: this bound is already specified as the supertrait of `GenericSubtrait` + --> $DIR/implied_bounds_in_impls.rs:30:37 + | +LL | fn generics_implied() -> impl GenericTrait + GenericSubtrait + | ^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied() -> impl GenericTrait + GenericSubtrait +LL + fn generics_implied() -> impl GenericSubtrait + | + +error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>` + --> $DIR/implied_bounds_in_impls.rs:36:40 + | +LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} + | ^^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} +LL + fn generics_implied_multi() -> impl GenericTrait2 + GenericSubtrait<(), i32, V> {} + | + +error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>` + --> $DIR/implied_bounds_in_impls.rs:36:60 + | +LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} + | ^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} +LL + fn generics_implied_multi() -> impl GenericTrait + GenericSubtrait<(), i32, V> {} + | + +error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` + --> $DIR/implied_bounds_in_impls.rs:38:44 + | +LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> + | ^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> +LL + fn generics_implied_multi2() -> impl GenericTrait2 + GenericSubtrait<(), T, V> + | + +error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` + --> $DIR/implied_bounds_in_impls.rs:38:62 + | +LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> + | ^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> +LL + fn generics_implied_multi2() -> impl GenericTrait + GenericSubtrait<(), T, V> + | + +error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, ()>` + --> $DIR/implied_bounds_in_impls.rs:48:28 + | +LL | fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} + | ^^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} +LL + fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} + | + +error: this bound is already specified as the supertrait of `DerefMut` + --> $DIR/implied_bounds_in_impls.rs:52:20 + | +LL | fn f() -> impl Deref + DerefMut { + | ^^^^^ + | +help: try removing this bound + | +LL - fn f() -> impl Deref + DerefMut { +LL + fn f() -> impl DerefMut { + | + +error: aborting due to 8 previous errors + From 12275713d5e1540ddde6a6854b106c537270e9de Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Wed, 23 Aug 2023 16:48:12 +0200 Subject: [PATCH 73/79] support inherent impls and trait impls --- clippy_lints/src/implied_bounds_in_impls.rs | 173 +++++++++++--------- tests/ui/implied_bounds_in_impls.fixed | 4 +- tests/ui/implied_bounds_in_impls.rs | 8 +- tests/ui/implied_bounds_in_impls.stderr | 26 ++- 4 files changed, 124 insertions(+), 87 deletions(-) diff --git a/clippy_lints/src/implied_bounds_in_impls.rs b/clippy_lints/src/implied_bounds_in_impls.rs index 7ba467a3e06cc..c6d1acad3a0f1 100644 --- a/clippy_lints/src/implied_bounds_in_impls.rs +++ b/clippy_lints/src/implied_bounds_in_impls.rs @@ -1,11 +1,14 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::snippet; +use rustc_errors::{Applicability, SuggestionStyle}; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, FnDecl, FnRetTy, GenericArg, GenericBound, ItemKind, TraitBoundModifier, TyKind}; +use rustc_hir::{ + Body, FnDecl, FnRetTy, GenericArg, GenericBound, ImplItem, ImplItemKind, ItemKind, TraitBoundModifier, TraitItem, + TraitItemKind, TyKind, +}; use rustc_hir_analysis::hir_ty_to_ty; use rustc_lint::{LateContext, LateLintPass}; -use rustc_errors::{Applicability, SuggestionStyle}; use rustc_middle::ty::{self, ClauseKind, TyCtxt}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; @@ -94,6 +97,86 @@ fn is_same_generics( }) } +fn check(cx: &LateContext<'_>, decl: &FnDecl<'_>) { + if let FnRetTy::Return(ty) = decl.output + &&let TyKind::OpaqueDef(item_id, ..) = ty.kind + && let item = cx.tcx.hir().item(item_id) + && let ItemKind::OpaqueTy(opaque_ty) = item.kind + // Very often there is only a single bound, e.g. `impl Deref<..>`, in which case + // we can avoid doing a bunch of stuff unnecessarily. + && opaque_ty.bounds.len() > 1 + { + // Get all the (implied) trait predicates in the bounds. + // For `impl Deref + DerefMut` this will contain [`Deref`]. + // The implied `Deref` comes from `DerefMut` because `trait DerefMut: Deref {}`. + // N.B. (G)ATs are fine to disregard, because they must be the same for all of its supertraits. + // Example: + // `impl Deref + DerefMut` is not allowed. + // `DerefMut::Target` needs to match `Deref::Target`. + let implied_bounds: Vec<_> = opaque_ty.bounds.iter().filter_map(|bound| { + if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound + && let [.., path] = poly_trait.trait_ref.path.segments + && poly_trait.bound_generic_params.is_empty() + && let Some(trait_def_id) = path.res.opt_def_id() + && let predicates = cx.tcx.super_predicates_of(trait_def_id).predicates + && !predicates.is_empty() // If the trait has no supertrait, there is nothing to add. + { + Some((bound.span(), path.args.map_or([].as_slice(), |a| a.args), predicates)) + } else { + None + } + }).collect(); + + // Lint all bounds in the `impl Trait` type that are also in the `implied_bounds` vec. + // This involves some extra logic when generic arguments are present, since + // simply comparing trait `DefId`s won't be enough. We also need to compare the generics. + for (index, bound) in opaque_ty.bounds.iter().enumerate() { + if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound + && let [.., path] = poly_trait.trait_ref.path.segments + && let implied_args = path.args.map_or([].as_slice(), |a| a.args) + && let Some(def_id) = poly_trait.trait_ref.path.res.opt_def_id() + && let Some(implied_by_span) = implied_bounds.iter().find_map(|&(span, implied_by_args, preds)| { + preds.iter().find_map(|(clause, _)| { + if let ClauseKind::Trait(tr) = clause.kind().skip_binder() + && tr.def_id() == def_id + && is_same_generics(cx.tcx, tr.trait_ref.args, implied_by_args, implied_args) + { + Some(span) + } else { + None + } + }) + }) + { + let implied_by = snippet(cx, implied_by_span, ".."); + span_lint_and_then( + cx, IMPLIED_BOUNDS_IN_IMPLS, + poly_trait.span, + &format!("this bound is already specified as the supertrait of `{implied_by}`"), + |diag| { + // If we suggest removing a bound, we may also need extend the span + // to include the `+` token, so we don't end up with something like `impl + B` + + let implied_span_extended = if let Some(next_bound) = opaque_ty.bounds.get(index + 1) { + poly_trait.span.to(next_bound.span().shrink_to_lo()) + } else { + poly_trait.span + }; + + diag.span_suggestion_with_style( + implied_span_extended, + "try removing this bound", + "", + Applicability::MachineApplicable, + SuggestionStyle::ShowAlways + ); + } + ); + } + } + } +} + impl LateLintPass<'_> for ImpliedBoundsInImpls { fn check_fn( &mut self, @@ -104,82 +187,16 @@ impl LateLintPass<'_> for ImpliedBoundsInImpls { _: Span, _: LocalDefId, ) { - if let FnRetTy::Return(ty) = decl.output - &&let TyKind::OpaqueDef(item_id, ..) = ty.kind - && let item = cx.tcx.hir().item(item_id) - && let ItemKind::OpaqueTy(opaque_ty) = item.kind - // Very often there is only a single bound, e.g. `impl Deref<..>`, in which case - // we can avoid doing a bunch of stuff unnecessarily. - && opaque_ty.bounds.len() > 1 - { - // Get all the (implied) trait predicates in the bounds. - // For `impl Deref + DerefMut` this will contain [`Deref`]. - // The implied `Deref` comes from `DerefMut` because `trait DerefMut: Deref {}`. - // N.B. (G)ATs are fine to disregard, because they must be the same for all of its supertraits. - // Example: - // `impl Deref + DerefMut` is not allowed. - // `DerefMut::Target` needs to match `Deref::Target`. - let implied_bounds: Vec<_> = opaque_ty.bounds.iter().filter_map(|bound| { - if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound - && let [.., path] = poly_trait.trait_ref.path.segments - && poly_trait.bound_generic_params.is_empty() - && let Some(trait_def_id) = path.res.opt_def_id() - && let predicates = cx.tcx.super_predicates_of(trait_def_id).predicates - && !predicates.is_empty() // If the trait has no supertrait, there is nothing to add. - { - Some((bound.span(), path.args.map_or([].as_slice(), |a| a.args), predicates)) - } else { - None - } - }).collect(); - - // Lint all bounds in the `impl Trait` type that are also in the `implied_bounds` vec. - // This involves some extra logic when generic arguments are present, since - // simply comparing trait `DefId`s won't be enough. We also need to compare the generics. - for (index, bound) in opaque_ty.bounds.iter().enumerate() { - if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound - && let [.., path] = poly_trait.trait_ref.path.segments - && let implied_args = path.args.map_or([].as_slice(), |a| a.args) - && let Some(def_id) = poly_trait.trait_ref.path.res.opt_def_id() - && let Some(implied_by_span) = implied_bounds.iter().find_map(|&(span, implied_by_args, preds)| { - preds.iter().find_map(|(clause, _)| { - if let ClauseKind::Trait(tr) = clause.kind().skip_binder() - && tr.def_id() == def_id - && is_same_generics(cx.tcx, tr.trait_ref.args, implied_by_args, implied_args) - { - Some(span) - } else { - None - } - }) - }) - { - let implied_by = snippet(cx, implied_by_span, ".."); - span_lint_and_then( - cx, IMPLIED_BOUNDS_IN_IMPLS, - poly_trait.span, - &format!("this bound is already specified as the supertrait of `{}`", implied_by), - |diag| { - // If we suggest removing a bound, we may also need extend the span - // to include the `+` token, so we don't end up with something like `impl + B` - - let implied_span_extended = if let Some(next_bound) = opaque_ty.bounds.get(index + 1) { - poly_trait.span.to(next_bound.span().shrink_to_lo()) - } else { - poly_trait.span - }; - - diag.span_suggestion_with_style( - implied_span_extended, - "try removing this bound", - "", - Applicability::MachineApplicable, - SuggestionStyle::ShowAlways - ); - } - ); - } - } + check(cx, decl); + } + fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) { + if let TraitItemKind::Fn(sig, ..) = &item.kind { + check(cx, sig.decl); + } + } + fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &ImplItem<'_>) { + if let ImplItemKind::Fn(sig, ..) = &item.kind { + check(cx, sig.decl); } } } diff --git a/tests/ui/implied_bounds_in_impls.fixed b/tests/ui/implied_bounds_in_impls.fixed index 72239afae4a3d..952c2b70619bb 100644 --- a/tests/ui/implied_bounds_in_impls.fixed +++ b/tests/ui/implied_bounds_in_impls.fixed @@ -49,9 +49,7 @@ fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} trait SomeTrait { // Check that it works in trait declarations. - fn f() -> impl DerefMut { - Box::new(0) - } + fn f() -> impl DerefMut; } struct SomeStruct; impl SomeStruct { diff --git a/tests/ui/implied_bounds_in_impls.rs b/tests/ui/implied_bounds_in_impls.rs index d59241d9ad13c..475f2621bbf62 100644 --- a/tests/ui/implied_bounds_in_impls.rs +++ b/tests/ui/implied_bounds_in_impls.rs @@ -49,20 +49,18 @@ fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} trait SomeTrait { // Check that it works in trait declarations. - fn f() -> impl Deref + DerefMut { - Box::new(0) - } + fn f() -> impl Deref + DerefMut; } struct SomeStruct; impl SomeStruct { // Check that it works in inherent impl blocks. - fn f() -> impl DerefMut { + fn f() -> impl Deref + DerefMut { Box::new(123) } } impl SomeTrait for SomeStruct { // Check that it works in trait impls. - fn f() -> impl DerefMut { + fn f() -> impl Deref + DerefMut { Box::new(42) } } diff --git a/tests/ui/implied_bounds_in_impls.stderr b/tests/ui/implied_bounds_in_impls.stderr index 86ce64a47fd15..8dffc674444d7 100644 --- a/tests/ui/implied_bounds_in_impls.stderr +++ b/tests/ui/implied_bounds_in_impls.stderr @@ -86,6 +86,30 @@ LL + fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} error: this bound is already specified as the supertrait of `DerefMut` --> $DIR/implied_bounds_in_impls.rs:52:20 | +LL | fn f() -> impl Deref + DerefMut; + | ^^^^^ + | +help: try removing this bound + | +LL - fn f() -> impl Deref + DerefMut; +LL + fn f() -> impl DerefMut; + | + +error: this bound is already specified as the supertrait of `DerefMut` + --> $DIR/implied_bounds_in_impls.rs:57:20 + | +LL | fn f() -> impl Deref + DerefMut { + | ^^^^^ + | +help: try removing this bound + | +LL - fn f() -> impl Deref + DerefMut { +LL + fn f() -> impl DerefMut { + | + +error: this bound is already specified as the supertrait of `DerefMut` + --> $DIR/implied_bounds_in_impls.rs:63:20 + | LL | fn f() -> impl Deref + DerefMut { | ^^^^^ | @@ -95,5 +119,5 @@ LL - fn f() -> impl Deref + DerefMut { LL + fn f() -> impl DerefMut { | -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors From fe38aaad66a26fd5835d561ec1a50e77185c58f3 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Thu, 24 Aug 2023 20:41:26 +0200 Subject: [PATCH 74/79] Update changelog stable note --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 583bc6754fb1e..92cc19edb0505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ document. ## Rust 1.72 -Current beta, released 2023-08-24 +Current stable, released 2023-08-24 [View all 131 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-05-22T14%3A53%3A59Z..2023-07-01T22%3A57%3A20Z+base%3Amaster) @@ -101,7 +101,7 @@ Current beta, released 2023-08-24 ## Rust 1.71 -Current stable, released 2023-07-13 +Released 2023-07-13 Note: Clippy will use a shorter changelog format from now on, if you want a detailed list of all changes, please check out the list of merged pull requests. From e1ec41b2179e89a657bae77c6a4ed15da65ad040 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 24 Aug 2023 21:06:18 +0200 Subject: [PATCH 75/79] Fix dogfood issues --- clippy_lints/src/casts/cast_ptr_alignment.rs | 6 +++-- clippy_lints/src/ptr.rs | 25 +++++++++++++++----- clippy_utils/src/paths.rs | 3 --- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 5bf467efa0f14..1de69122101c5 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -5,6 +5,7 @@ use rustc_hir::{Expr, ExprKind, GenericArg}; use rustc_lint::LateContext; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Ty}; +use rustc_span::sym; use super::CAST_PTR_ALIGNMENT; @@ -76,13 +77,14 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { ExprKind::Call(func, [arg, ..]) if arg.hir_id == e.hir_id => { static PATHS: &[&[&str]] = &[ paths::PTR_READ_UNALIGNED.as_slice(), - paths::PTR_WRITE_UNALIGNED.as_slice(), paths::PTR_UNALIGNED_VOLATILE_LOAD.as_slice(), paths::PTR_UNALIGNED_VOLATILE_STORE.as_slice(), ]; + if let ExprKind::Path(path) = &func.kind && let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id() - && match_any_def_paths(cx, def_id, PATHS).is_some() + && (match_any_def_paths(cx, def_id, PATHS).is_some() + || cx.tcx.is_diagnostic_item(sym::ptr_write_unaligned, def_id)) { true } else { diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 8009b00b4b9cb..bf031ac84549d 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -278,7 +278,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // (fn_path, arg_indices) - `arg_indices` are the `arg` positions where null would cause U.B. - const INVALID_NULL_PTR_USAGE_TABLE: [(&[&str], &[usize]); 16] = [ + const INVALID_NULL_PTR_USAGE_TABLE: [(&[&str], &[usize]); 13] = [ (&paths::SLICE_FROM_RAW_PARTS, &[0]), (&paths::SLICE_FROM_RAW_PARTS_MUT, &[0]), (&paths::PTR_COPY, &[0, 1]), @@ -291,20 +291,33 @@ fn check_invalid_ptr_usage<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { (&paths::PTR_SLICE_FROM_RAW_PARTS_MUT, &[0]), (&paths::PTR_SWAP, &[0, 1]), (&paths::PTR_SWAP_NONOVERLAPPING, &[0, 1]), - (&paths::PTR_WRITE, &[0]), - (&paths::PTR_WRITE_UNALIGNED, &[0]), - (&paths::PTR_WRITE_VOLATILE, &[0]), (&paths::PTR_WRITE_BYTES, &[0]), ]; + let invalid_null_ptr_usage_table_diag_items: [(Option, &[usize]); 3] = [ + (cx.tcx.get_diagnostic_item(sym::ptr_write), &[0]), + (cx.tcx.get_diagnostic_item(sym::ptr_write_unaligned), &[0]), + (cx.tcx.get_diagnostic_item(sym::ptr_write_volatile), &[0]), + ]; if_chain! { if let ExprKind::Call(fun, args) = expr.kind; if let ExprKind::Path(ref qpath) = fun.kind; if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id(); let fun_def_path = cx.get_def_path(fun_def_id).into_iter().map(Symbol::to_ident_string).collect::>(); - if let Some(&(_, arg_indices)) = INVALID_NULL_PTR_USAGE_TABLE + if let Some(arg_indices) = INVALID_NULL_PTR_USAGE_TABLE .iter() - .find(|&&(fn_path, _)| fn_path == fun_def_path); + .find_map(|&(fn_path, indices)| if fn_path == fun_def_path { Some(indices) } else { None }) + .or_else(|| { + invalid_null_ptr_usage_table_diag_items + .iter() + .find_map(|&(def_id, indices)| { + if def_id == Some(fun_def_id) { + Some(indices) + } else { + None + } + }) + }); then { for &arg_idx in arg_indices { if let Some(arg) = args.get(arg_idx).filter(|arg| is_null_path(cx, arg)) { diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index e72d063cfd9b4..a567c5cbdc92a 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -87,10 +87,7 @@ pub const PTR_REPLACE: [&str; 3] = ["core", "ptr", "replace"]; pub const PTR_SWAP: [&str; 3] = ["core", "ptr", "swap"]; pub const PTR_UNALIGNED_VOLATILE_LOAD: [&str; 3] = ["core", "intrinsics", "unaligned_volatile_load"]; pub const PTR_UNALIGNED_VOLATILE_STORE: [&str; 3] = ["core", "intrinsics", "unaligned_volatile_store"]; -pub const PTR_WRITE: [&str; 3] = ["core", "ptr", "write"]; pub const PTR_WRITE_BYTES: [&str; 3] = ["core", "intrinsics", "write_bytes"]; -pub const PTR_WRITE_UNALIGNED: [&str; 3] = ["core", "ptr", "write_unaligned"]; -pub const PTR_WRITE_VOLATILE: [&str; 3] = ["core", "ptr", "write_volatile"]; pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"]; pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"]; pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"]; From da06825124db87d4e3b7194197eeeadd53849d56 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 24 Aug 2023 21:06:31 +0200 Subject: [PATCH 76/79] Bump Clippy version -> 0.1.74 --- Cargo.toml | 2 +- clippy_lints/Cargo.toml | 2 +- clippy_utils/Cargo.toml | 2 +- declare_clippy_lint/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ab6d7e118f1b..cd04c78ef9eeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.1.73" +version = "0.1.74" description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 11136867ff0aa..c0a9f466e7b0e 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_lints" -version = "0.1.73" +version = "0.1.74" description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index 3926b954ec8cd..1596bb773976a 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_utils" -version = "0.1.73" +version = "0.1.74" edition = "2021" publish = false diff --git a/declare_clippy_lint/Cargo.toml b/declare_clippy_lint/Cargo.toml index 3633ed31d739f..1470da61fac0c 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.73" +version = "0.1.74" edition = "2021" publish = false From 9334e5d5c0226a48d04c263ed54af556208b9fe7 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 24 Aug 2023 21:06:43 +0200 Subject: [PATCH 77/79] Bump nightly version -> 2023-08-24 --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 8b3f819f0cde1..19c09b58b9862 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-08-10" +channel = "nightly-2023-08-24" components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] From ac25a7387c7a371df2a75fd6f959d5c61ca51e39 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 24 Aug 2023 21:33:17 +0200 Subject: [PATCH 78/79] Update Cargo.lock (ui_test update) --- Cargo.lock | 239 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 208 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7337901bc3a59..190aa8ba79bda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,6 +107,15 @@ dependencies = [ "yansi-term", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anstream" version = "0.3.2" @@ -143,7 +152,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -153,7 +162,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -502,7 +511,7 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" [[package]] name = "clippy" -version = "0.1.73" +version = "0.1.74" dependencies = [ "clippy_lints", "clippy_utils", @@ -522,7 +531,7 @@ dependencies = [ "tester", "tokio", "toml 0.7.5", - "ui_test", + "ui_test 0.17.0", "walkdir", ] @@ -541,7 +550,7 @@ dependencies = [ [[package]] name = "clippy_lints" -version = "0.1.73" +version = "0.1.74" dependencies = [ "arrayvec", "cargo_metadata", @@ -566,7 +575,7 @@ dependencies = [ [[package]] name = "clippy_utils" -version = "0.1.73" +version = "0.1.74" dependencies = [ "arrayvec", "if_chain", @@ -628,6 +637,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "comma" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335" + [[package]] name = "compiler_builtins" version = "0.1.100" @@ -664,6 +679,19 @@ dependencies = [ "windows", ] +[[package]] +name = "console" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.45.0", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -786,7 +814,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a011bbe2c35ce9c1f143b7af6f94f29a167beb4cd1d29e6740ce836f723120e" dependencies = [ "nix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -862,7 +890,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69" [[package]] name = "declare_clippy_lint" -version = "0.1.73" +version = "0.1.74" dependencies = [ "itertools", "quote", @@ -988,6 +1016,12 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "210ec60ae7d710bed8683e333e9d2855a8a56a3e9892b38bad3bb0d4d29b0d5e" +[[package]] +name = "distance" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d9d8664cf849d7d0f3114a3a387d2f5e4303176d746d5a951aaddc66dfe9240" + [[package]] name = "dlmalloc" version = "0.2.4" @@ -1035,6 +1069,12 @@ dependencies = [ "log", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.32" @@ -1097,7 +1137,7 @@ checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1180,7 +1220,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall 0.2.16", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1824,6 +1864,19 @@ dependencies = [ "serde", ] +[[package]] +name = "indicatif" +version = "0.17.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b297dc40733f23a0e52728a58fa9489a5b7638a324932de16b41adc3ef80730" +dependencies = [ + "console", + "instant", + "number_prefix", + "portable-atomic", + "unicode-width", +] + [[package]] name = "indoc" version = "1.0.9" @@ -1880,7 +1933,7 @@ checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi 0.3.2", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1897,7 +1950,7 @@ checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" dependencies = [ "hermit-abi 0.3.2", "rustix 0.38.2", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2290,7 +2343,7 @@ checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2299,7 +2352,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "359f76430b20a79f9e20e115b3428614e654f04fab314482fc0fda0ebd3c6044" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2321,7 +2374,7 @@ dependencies = [ "rustc_version", "serde", "smallvec", - "ui_test", + "ui_test 0.11.7", ] [[package]] @@ -2415,6 +2468,12 @@ dependencies = [ "libc", ] +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + [[package]] name = "object" version = "0.32.0" @@ -2546,6 +2605,15 @@ dependencies = [ "libm 0.1.4", ] +[[package]] +name = "pad" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ad9b889f1b12e0b9ee24db044b5129150d5eada288edc800f789928dc8c0e3" +dependencies = [ + "unicode-width", +] + [[package]] name = "panic_abort" version = "0.0.0" @@ -2614,7 +2682,7 @@ dependencies = [ "libc", "redox_syscall 0.3.5", "smallvec", - "windows-targets", + "windows-targets 0.48.1", ] [[package]] @@ -2749,6 +2817,12 @@ dependencies = [ "rustc-hash", ] +[[package]] +name = "portable-atomic" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f32154ba0af3a075eefa1eda8bb414ee928f62303a54ea85b8d6638ff1a6ee9e" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2761,6 +2835,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "prettydiff" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ff1fec61082821f8236cf6c0c14e8172b62ce8a72a0eedc30d3b247bb68dc11" +dependencies = [ + "ansi_term", + "pad", +] + [[package]] name = "proc-macro-hack" version = "0.5.20+deprecated" @@ -4534,7 +4618,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys 0.3.8", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -4547,7 +4631,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.3", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -4588,7 +4672,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -5017,7 +5101,7 @@ dependencies = [ "fastrand", "redox_syscall 0.3.5", "rustix 0.37.22", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -5058,7 +5142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237" dependencies = [ "rustix 0.37.22", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -5257,7 +5341,7 @@ dependencies = [ "num_cpus", "pin-project-lite", "socket2", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -5494,6 +5578,33 @@ dependencies = [ "tempfile", ] +[[package]] +name = "ui_test" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7823f926a62629304c4a47c23949925f6faa0d4f14ddbce4405d55dbaeab324" +dependencies = [ + "annotate-snippets", + "anyhow", + "bstr", + "cargo-platform", + "cargo_metadata", + "color-eyre", + "colored", + "comma", + "crossbeam-channel", + "distance", + "indicatif", + "lazy_static", + "prettydiff", + "regex", + "rustc_version", + "rustfix", + "serde", + "serde_json", + "tempfile", +] + [[package]] name = "unic-langid" version = "0.9.1" @@ -5846,7 +5957,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets", + "windows-targets 0.48.1", ] [[package]] @@ -5865,13 +5976,37 @@ version = "0.49.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f5bca94a32bf1e6a376522b6601275a3b611ee885ec0f1b6a05f17e8cfd3385" +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.1", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", ] [[package]] @@ -5880,13 +6015,13 @@ version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -5895,42 +6030,84 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b34c9a3b28cb41db7385546f7f9a8179348dffc89923dde66857b1ba5312f6b4" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.0" From 4fdb4edf9b19e61edfd952afa945de9d659eeab6 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Aug 2023 13:28:53 +0000 Subject: [PATCH 79/79] Bump ui_test --- Cargo.lock | 20 +++++++++---------- src/tools/clippy/Cargo.toml | 2 +- src/tools/clippy/tests/compile-test.rs | 4 ++-- src/tools/clippy/tests/ui/derive.stderr | 20 +++++++++---------- .../tests/ui/temporary_assignment.stderr | 8 ++++---- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 190aa8ba79bda..cd74f589f0797 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -531,7 +531,7 @@ dependencies = [ "tester", "tokio", "toml 0.7.5", - "ui_test 0.17.0", + "ui_test 0.18.1", "walkdir", ] @@ -1016,12 +1016,6 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "210ec60ae7d710bed8683e333e9d2855a8a56a3e9892b38bad3bb0d4d29b0d5e" -[[package]] -name = "distance" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d9d8664cf849d7d0f3114a3a387d2f5e4303176d746d5a951aaddc66dfe9240" - [[package]] name = "dlmalloc" version = "0.2.4" @@ -2047,6 +2041,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" +[[package]] +name = "levenshtein" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" + [[package]] name = "libc" version = "0.2.147" @@ -5580,9 +5580,9 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.17.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7823f926a62629304c4a47c23949925f6faa0d4f14ddbce4405d55dbaeab324" +checksum = "640159421816683e558867ffc0e60ed3a3ed97ec6ccb22c03adb41bf87c5cfa4" dependencies = [ "annotate-snippets", "anyhow", @@ -5593,9 +5593,9 @@ dependencies = [ "colored", "comma", "crossbeam-channel", - "distance", "indicatif", "lazy_static", + "levenshtein", "prettydiff", "regex", "rustc_version", diff --git a/src/tools/clippy/Cargo.toml b/src/tools/clippy/Cargo.toml index cd04c78ef9eeb..7c78beb5ddef9 100644 --- a/src/tools/clippy/Cargo.toml +++ b/src/tools/clippy/Cargo.toml @@ -27,7 +27,7 @@ tempfile = { version = "3.2", optional = true } termize = "0.1" [dev-dependencies] -ui_test = "0.17.0" +ui_test = "0.18.1" tester = "0.9" regex = "1.5" toml = "0.7.3" diff --git a/src/tools/clippy/tests/compile-test.rs b/src/tools/clippy/tests/compile-test.rs index 844e66728f253..e329a94ff6a1d 100644 --- a/src/tools/clippy/tests/compile-test.rs +++ b/src/tools/clippy/tests/compile-test.rs @@ -4,7 +4,7 @@ #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(unused_extern_crates)] -use ui_test::{status_emitter, Args, CommandBuilder, Config, Match, Mode, OutputConflictHandling}; +use ui_test::{status_emitter, Args, CommandBuilder, Config, Match, Mode, OutputConflictHandling, RustfixMode}; use std::collections::BTreeMap; use std::env::{self, set_var, var_os}; @@ -130,7 +130,7 @@ fn base_config(test_dir: &str) -> (Config, Args) { }; let mut config = Config { - mode: Mode::Yolo { rustfix: true }, + mode: Mode::Yolo { rustfix: RustfixMode::Everything }, stderr_filters: vec![(Match::PathBackslash, b"/")], stdout_filters: vec![], output_conflict_handling: if bless { diff --git a/src/tools/clippy/tests/ui/derive.stderr b/src/tools/clippy/tests/ui/derive.stderr index cf8e90cd844e6..2986296bcaf77 100644 --- a/src/tools/clippy/tests/ui/derive.stderr +++ b/src/tools/clippy/tests/ui/derive.stderr @@ -1,5 +1,5 @@ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:11:1 + --> $DIR/derive.rs:12:1 | LL | / impl Clone for Qux { LL | | @@ -10,7 +10,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:11:1 + --> $DIR/derive.rs:12:1 | LL | / impl Clone for Qux { LL | | @@ -22,7 +22,7 @@ LL | | } = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:36:1 + --> $DIR/derive.rs:37:1 | LL | / impl<'a> Clone for Lt<'a> { LL | | @@ -33,7 +33,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:36:1 + --> $DIR/derive.rs:37:1 | LL | / impl<'a> Clone for Lt<'a> { LL | | @@ -44,7 +44,7 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:48:1 + --> $DIR/derive.rs:49:1 | LL | / impl Clone for BigArray { LL | | @@ -55,7 +55,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:48:1 + --> $DIR/derive.rs:49:1 | LL | / impl Clone for BigArray { LL | | @@ -66,7 +66,7 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:60:1 + --> $DIR/derive.rs:61:1 | LL | / impl Clone for FnPtr { LL | | @@ -77,7 +77,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:60:1 + --> $DIR/derive.rs:61:1 | LL | / impl Clone for FnPtr { LL | | @@ -88,7 +88,7 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:81:1 + --> $DIR/derive.rs:82:1 | LL | / impl Clone for Generic2 { LL | | @@ -99,7 +99,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:81:1 + --> $DIR/derive.rs:82:1 | LL | / impl Clone for Generic2 { LL | | diff --git a/src/tools/clippy/tests/ui/temporary_assignment.stderr b/src/tools/clippy/tests/ui/temporary_assignment.stderr index 12e2c5a2fc317..241abc2c5c7cb 100644 --- a/src/tools/clippy/tests/ui/temporary_assignment.stderr +++ b/src/tools/clippy/tests/ui/temporary_assignment.stderr @@ -1,5 +1,5 @@ error: assignment to temporary - --> $DIR/temporary_assignment.rs:47:5 + --> $DIR/temporary_assignment.rs:48:5 | LL | Struct { field: 0 }.field = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | Struct { field: 0 }.field = 1; = note: `-D clippy::temporary-assignment` implied by `-D warnings` error: assignment to temporary - --> $DIR/temporary_assignment.rs:50:5 + --> $DIR/temporary_assignment.rs:51:5 | LL | / MultiStruct { LL | | @@ -18,13 +18,13 @@ LL | | .field = 1; | |______________^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:56:5 + --> $DIR/temporary_assignment.rs:57:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:58:5 + --> $DIR/temporary_assignment.rs:59:5 | LL | (0, 0).0 = 1; | ^^^^^^^^^^^^